JetCommandLine implements Runnable { @Override public void run() { } JetCommandLine(Function<ClientConfig, JetInstance> jetClientFn, PrintStream out, PrintStream err); static void main(String[] args); @Override void run(); @Command(description = "Submits a job to the cluster") void submit(
            @Mixin(name = "verbosity") Verbosity verbosity,
            @Mixin(name = "targets") TargetsMixin targets,
            @Option(names = {"-s", "--snapshot"},
                    paramLabel = "<snapshot name>",
                    description = "Name of the initial snapshot to start the job from"
            ) String snapshotName,
            @Option(names = {"-n", "--name"},
                    paramLabel = "<name>",
                    description = "Name of the job"
            ) String name,
            @Option(names = {"-c", "--class"},
                    paramLabel = "<class>",
                    description = "Fully qualified name of the main class inside the JAR file"
            ) String mainClass,
            @Parameters(index = "0",
                    paramLabel = "<jar file>",
                    description = "The jar file to submit"
            ) File file,
            @Parameters(index = "1..*",
                    paramLabel = "<arguments>",
                    description = "Arguments to pass to the supplied jar file"
            ) List<String> params
    ); @Command(description = "Suspends a running job") void suspend(
            @Mixin(name = "verbosity") Verbosity verbosity,
            @Mixin(name = "targets") TargetsMixin targets,
            @Parameters(index = "0",
                    paramLabel = "<job name or id>",
                    description = "Name of the job to suspend"
            ) String name
    ); @Command( description = "Cancels a running job" ) void cancel(
            @Mixin(name = "verbosity") Verbosity verbosity,
            @Mixin(name = "targets") TargetsMixin targets,
            @Parameters(index = "0",
                    paramLabel = "<job name or id>",
                    description = "Name of the job to cancel"
            ) String name
    ); @Command( name = "save-snapshot", description = "Exports a named snapshot from a job and optionally cancels it" ) void saveSnapshot(
            @Mixin(name = "verbosity") Verbosity verbosity,
            @Mixin(name = "targets") TargetsMixin targets,
            @Parameters(index = "0",
                    paramLabel = "<job name or id>",
                    description = "Name of the job to take the snapshot from")
                    String jobName,
            @Parameters(index = "1",
                    paramLabel = "<snapshot name>",
                    description = "Name of the snapshot")
                    String snapshotName,
            @Option(names = {"-C", "--cancel"},
                    description = "Cancel the job after taking the snapshot")
                    boolean isTerminal
    ); @Command( name = "delete-snapshot", description = "Deletes a named snapshot" ) void deleteSnapshot(
            @Mixin(name = "verbosity") Verbosity verbosity,
            @Mixin(name = "targets") TargetsMixin targets,
            @Parameters(index = "0",
                    paramLabel = "<snapshot name>",
                    description = "Name of the snapshot")
                    String snapshotName
    ); @Command( description = "Restarts a running job" ) void restart(
            @Mixin(name = "verbosity") Verbosity verbosity,
            @Mixin(name = "targets") TargetsMixin targets,
            @Parameters(index = "0",
                    paramLabel = "<job name or id>",
                    description = "Name of the job to restart")
                    String name
    ); @Command( description = "Resumes a suspended job" ) void resume(
            @Mixin(name = "verbosity") Verbosity verbosity,
            @Mixin(name = "targets") TargetsMixin targets,
            @Parameters(index = "0",
                    paramLabel = "<job name or id>",
                    description = "Name of the job to resume")
                    String name
    ); @Command( name = "list-jobs", description = "Lists running jobs on the cluster" ) void listJobs(
            @Mixin(name = "verbosity") Verbosity verbosity,
            @Mixin(name = "targets") TargetsMixin targets,
            @Option(names = {"-a", "--all"},
                    description = "Lists all jobs including completed and failed ones")
                    boolean listAll
    ); @Command( name = "list-snapshots", description = "Lists exported snapshots on the cluster" ) void listSnapshots(
            @Mixin(name = "verbosity") Verbosity verbosity,
            @Mixin(name = "targets") TargetsMixin targets,
            @Option(names = {"-F", "--full-job-name"},
                    description = "Don't trim job name to fit, can break layout")
                    boolean fullJobName); @Command( description = "Shows current cluster state and information about members" ) void cluster(
            @Mixin(name = "verbosity") Verbosity verbosity,
            @Mixin(name = "targets") TargetsMixin targets
    );  }
@Test public void test_listJobs() { Job job = newJob(); run("list-jobs"); String actual = captureOut(); assertContains(actual, job.getName()); assertContains(actual, job.getIdString()); assertContains(actual, job.getStatus().toString()); }
@Test public void test_listJobs_dirtyName() { String jobName = "job\n\tname\u0000"; Job job = newJob(jobName); run("list-jobs"); String actual = captureOut(); assertContains(actual, jobName); assertContains(actual, job.getIdString()); assertContains(actual, job.getStatus().toString()); }
@Test public void test_cancelJob_byJobName() { Job job = newJob(); run("cancel", job.getName()); assertJobStatusEventually(job, JobStatus.FAILED); }
@Test public void test_cancelJob_byJobId() { Job job = newJob(); run("cancel", job.getIdString()); assertJobStatusEventually(job, JobStatus.FAILED); }
@Test public void test_cancelJob_invalidNameOrId() { exception.expectMessage("No job with name or id 'invalid' was found"); run("cancel", "invalid"); }
@Test public void test_suspendJob_byJobName() { Job job = newJob(); run("suspend", job.getName()); assertJobStatusEventually(job, JobStatus.SUSPENDED); }
@Test public void test_suspendJob_byJobId() { Job job = newJob(); run("suspend", job.getIdString()); assertJobStatusEventually(job, JobStatus.SUSPENDED); }
@Test public void test_suspendJob_invalidNameOrId() { exception.expectMessage("No job with name or id 'invalid' was found"); run("cancel", "invalid"); }
@Test public void test_resumeJob_invalidNameOrId() { exception.expectMessage("No job with name or id 'invalid' was found"); run("resume", "invalid"); }
@Test public void test_resumeJob_jobNotSuspended() { Job job = newJob(); assertJobStatusEventually(job, JobStatus.RUNNING); exception.expectMessage("is not suspended"); run("resume", job.getName()); }
@Test public void test_restartJob_byJobName() { Job job = newJob(); assertTrueEventually(() -> assertEquals(ITEM_COUNT, sinkList.size())); run("restart", job.getName()); assertTrueEventually(() -> assertEquals(ITEM_COUNT * 2, sinkList.size())); }
@Test public void test_restartJob_byJobId() { Job job = newJob(); assertTrueEventually(() -> assertEquals(ITEM_COUNT, sinkList.size())); run("restart", job.getIdString()); assertTrueEventually(() -> assertEquals(ITEM_COUNT * 2, sinkList.size())); }
@Test public void test_restartJob_invalidNameOrId() { exception.expectMessage("No job with name or id 'invalid' was found"); run("restart", "invalid"); }
@Test public void test_saveSnapshot_invalidNameOrId() { exception.expectMessage("No job with name or id 'invalid' was found"); run("save-snapshot", "invalid", "my-snapshot"); }
@Test public void test_listSnapshots() { run("list-snapshots"); String actual = captureOut(); assertTrue("output should contain one line (the table header), but contains:\n" + actual, actual.trim().indexOf('\n') < 0 && !actual.isEmpty()); }
@Test public void test_cluster() { run("cluster"); String actual = captureOut(); assertContains(actual, jet.getCluster().getLocalMember().getUuid().toString()); assertContains(actual, "ACTIVE"); }
@Test public void test_submit() { run("submit", testJobJarFile.toString()); assertTrueEventually(() -> assertEquals(1, jet.getJobs().size())); Job job = jet.getJobs().get(0); assertJobStatusEventually(job, JobStatus.RUNNING); assertNull(job.getName()); }
@Test public void test_submit_clientShutdownWhenDone() { run("submit", testJobJarFile.toString()); assertTrueEventually(() -> assertEquals(1, jet.getJobs().size())); Job job = jet.getJobs().get(0); assertJobStatusEventually(job, JobStatus.RUNNING); assertFalse("Instance should be shut down", client.getHazelcastInstance().getLifecycleService().isRunning()); }
@Test public void test_submit_nameUsed() { run("submit", "-n", "fooName", testJobJarFile.toString()); assertTrueEventually(() -> assertEquals(1, jet.getJobs().size()), 5); Job job = jet.getJobs().get(0); assertEquals("fooName", job.getName()); }
@Test public void test_submit_withClassname() { run("submit", "--class", "com.hazelcast.jet.testjob.TestJob", testJobJarFile.toString()); assertTrueEventually(() -> assertEquals(1, jet.getJobs().size()), 5); Job job = jet.getJobs().get(0); assertJobStatusEventually(job, JobStatus.RUNNING); assertNull(job.getName()); }
@Test public void test_submit_withWrongClassname() { exception.expectMessage("ClassNotFoundException"); run("submit", "--class", "com.hazelcast.jet.testjob.NonExisting", testJobJarFile.toString()); }
@Test public void test_submit_argsPassing() { run("submit", testJobJarFile.toString(), "--jobOption", "fooValue"); IList<String> args = jet.getList("args"); assertTrueEventually(() -> assertContains(captureOut(), " with arguments [--jobOption, fooValue]")); }
@Test public void testTargetsInvalidValue() { run("submit", "-t", "@", testJobJarFile.toString()); String actual = captureErr(); assertContains(actual, "Invalid value for option '--targets':"); }