Skip to content
Snippets Groups Projects
Commit 5115f06a authored by Jesper Fyhr Knudsen's avatar Jesper Fyhr Knudsen
Browse files

Minor refactoring in CLI entrypoint

parent a772b953
No related branches found
No related tags found
No related merge requests found
......@@ -17,47 +17,17 @@
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
<profile default="false" name="Annotation profile for octopus-daemon" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="true" />
<module name="octopus-daemon" />
</profile>
<profile default="false" name="Annotation profile for octopus-agent" enabled="true">
<profile default="false" name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="true" />
<module name="octopus-agent" />
</profile>
<profile default="false" name="Annotation profile for octopus-server" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="true" />
<module name="octopus-server" />
</profile>
<profile default="false" name="Annotation profile for octopus-integrationtests" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="true" />
<module name="octopus-integrationtests" />
</profile>
<profile default="false" name="Annotation profile for octopus-cli" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="true" />
<module name="octopus-cli" />
</profile>
<profile default="false" name="Annotation profile for octopus-commons" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="true" />
<module name="octopus-commons" />
<module name="octopus-daemon" />
<module name="octopus-integrationtests" />
<module name="octopus-server" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel target="1.7">
......
......@@ -3,19 +3,12 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/octopus-agent/octopus-agent.iml" filepath="$PROJECT_DIR$/octopus-agent/octopus-agent.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-agent/octopus-agent.iml" filepath="$PROJECT_DIR$/octopus-agent/octopus-agent.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-cli/octopus-cli.iml" filepath="$PROJECT_DIR$/octopus-cli/octopus-cli.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-cli/octopus-cli.iml" filepath="$PROJECT_DIR$/octopus-cli/octopus-cli.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-commons/octopus-commons.iml" filepath="$PROJECT_DIR$/octopus-commons/octopus-commons.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-commons/octopus-commons.iml" filepath="$PROJECT_DIR$/octopus-commons/octopus-commons.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-daemon/octopus-daemon.iml" filepath="$PROJECT_DIR$/octopus-daemon/octopus-daemon.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-daemon/octopus-daemon.iml" filepath="$PROJECT_DIR$/octopus-daemon/octopus-daemon.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-integrationtests/octopus-integrationtests.iml" filepath="$PROJECT_DIR$/octopus-integrationtests/octopus-integrationtests.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-integrationtests/octopus-integrationtests.iml" filepath="$PROJECT_DIR$/octopus-integrationtests/octopus-integrationtests.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-server/octopus-server.iml" filepath="$PROJECT_DIR$/octopus-server/octopus-server.iml" />
<module fileurl="file://$PROJECT_DIR$/octopus-server/octopus-server.iml" filepath="$PROJECT_DIR$/octopus-server/octopus-server.iml" />
<module fileurl="file://$PROJECT_DIR$/parent-project.iml" filepath="$PROJECT_DIR$/parent-project.iml" />
<module fileurl="file://$PROJECT_DIR$/parent-project.iml" filepath="$PROJECT_DIR$/parent-project.iml" />
</modules>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -11,90 +11,76 @@ import org.apache.commons.cli.*;
import java.io.*;
public class Program
{
public static void main(String[] args) throws IOException
{
public class Program {
public static void main(String[] args) throws IOException, ParseException {
Options options = createOptions();
CommandLineParser parser = new BasicParser();
try
{
CommandLine cmd = parser.parse(options, args);
if (!cmd.hasOption("d"))
{
System.setOut(createPrintStreamNullObject());
}
if(cmd.hasOption("h"))
{
if (cmd.hasOption("h")) {
HelpFormatter help = new HelpFormatter();
help.printHelp("octopus-cli [OPTION]... [FILE]...", options);
help.printHelp("octopus-cli [OPTION]", options);
}
executeJob(cmd);
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
int port = Integer.parseInt(cmd.getOptionValue("p", "44000"));
String orchestratorAddress = cmd.getOptionValue("oa", "localhost");
if (cmd.hasOption("op")) {
System.out.println("Starting Agent");
int orchestratorport = Integer.parseInt(cmd.getOptionValue("op"));
instanciateAgent(port, orchestratorAddress, orchestratorport);
} else{
System.out.println("Starting Orchestrator");
instanciateOrcestrator(port);
}
private static PrintStream createPrintStreamNullObject()
{
return new PrintStream(new OutputStream()
{
@Override
public void write(int b) throws IOException
{
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
private static void executeJob(CommandLine cmd) throws Exception
{
CommandLineFileHelper fileHelper = new CommandLineFileHelper(cmd);
try(OrchestratorImpl leader = new OrchestratorImpl(56541);
Agent agent = new Agent("localhost", 56541, 56541 +1))
{
private static void instanciateAgent(int port, String orchestratorAddress, int orchestratorport) {
try (Agent agent = new Agent(orchestratorAddress, orchestratorport, port)) {
agent.addPlugin(new TestPlugin());
agent.addPlugin(new CommandLinePlugin());
agent.addPlugin(new ChaosPlugin());
leader.open();
agent.open();
try(BufferedReader reader = fileHelper.getStream())
{
Gson gson = new Gson();
Job job = gson.fromJson(reader, Job.class);
if(job.validate())
{
leader.enqueue(job);
waitForJobToComplete(job);
} catch (Exception e) {
e.printStackTrace();
}
else
System.err.println("The job format is not valid, ensure all steps contain tasks");
}
private static void instanciateOrcestrator(int port) {
try (OrchestratorImpl leader = new OrchestratorImpl(56541)) {
leader.open();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void waitForJobToComplete(Job job) throws InterruptedException
{
while(!job.isComplete())
{
Thread.sleep(10);
private static PrintStream createPrintStreamNullObject() {
return new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
}
});
}
private static Options createOptions()
{
private static Options createOptions() {
Options options = new Options();
options.addOption("p", "port", false, "Specify the listening port [44000]");
options.addOption("oa", "orchestrator-address", false, "Specify the IP address/hostname of the Orchestrator");
options.addOption("op", "orchestrator-port", false, "Specify the port of the Orchestrator");
options.addOption("d", "debug", false, "Prints debug message to stdout");
options.addOption("h", "help", false, "Print help");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment