Search in sources :

Example 6 with Command

use of picocli.CommandLine.Command in project hazelcast by hazelcast.

the class HazelcastCommandLine method resume.

@Command(description = "Resumes a suspended job")
public 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) {
    runWithHazelcast(targets, verbosity, false, hz -> {
        Job job = getJob(hz, name);
        if (job.getStatus() != JobStatus.SUSPENDED) {
            throw new RuntimeException("Job '" + name + "' is not suspended. Current state: " + job.getStatus());
        }
        println("Resuming job " + formatJob(job) + "...");
        job.resume();
        waitForJobStatus(job, JobStatus.RUNNING);
        println("Job resumed.");
    });
}
Also used : Job(com.hazelcast.jet.Job) HelpCommand(picocli.CommandLine.HelpCommand) Command(picocli.CommandLine.Command)

Example 7 with Command

use of picocli.CommandLine.Command in project hazelcast by hazelcast.

the class HazelcastCommandLine method saveSnapshot.

@Command(name = "save-snapshot", description = "Exports a named snapshot from a job and optionally cancels it")
public 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) {
    runWithHazelcast(targets, verbosity, false, hz -> {
        Job job = getJob(hz, jobName);
        assertJobActive(jobName, job);
        if (isTerminal) {
            printf("Saving snapshot with name '%s' from job '%s' and cancelling the job...", snapshotName, formatJob(job));
            job.cancelAndExportSnapshot(snapshotName);
            waitForJobStatus(job, JobStatus.FAILED);
        } else {
            printf("Saving snapshot with name '%s' from job '%s'...", snapshotName, formatJob(job));
            job.exportSnapshot(snapshotName);
        }
        printf("Exported snapshot '%s'.", snapshotName);
    });
}
Also used : Job(com.hazelcast.jet.Job) HelpCommand(picocli.CommandLine.HelpCommand) Command(picocli.CommandLine.Command)

Example 8 with Command

use of picocli.CommandLine.Command in project hazelcast by hazelcast.

the class HazelcastCommandLine method cancel.

@Command(description = "Cancels a running job")
public 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) {
    runWithHazelcast(targets, verbosity, false, hz -> {
        Job job = getJob(hz, name);
        assertJobActive(name, job);
        printf("Cancelling job %s", formatJob(job));
        job.cancel();
        waitForJobStatus(job, JobStatus.FAILED);
        println("Job cancelled.");
    });
}
Also used : Job(com.hazelcast.jet.Job) HelpCommand(picocli.CommandLine.HelpCommand) Command(picocli.CommandLine.Command)

Example 9 with Command

use of picocli.CommandLine.Command in project hazelcast by hazelcast.

the class HazelcastCommandLine method listJobs.

@Command(name = "list-jobs", description = "Lists running jobs on the cluster")
public 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) {
    runWithHazelcast(targets, verbosity, false, hz -> {
        JetClientInstanceImpl jetClientInstanceImpl = (JetClientInstanceImpl) hz.getJet();
        List<JobSummary> summaries = jetClientInstanceImpl.getJobSummaryList();
        String format = "%-19s %-18s %-23s %s";
        printf(format, "ID", "STATUS", "SUBMISSION TIME", "NAME");
        summaries.stream().filter(job -> listAll || isActive(job.getStatus())).forEach(job -> {
            String idString = idToString(job.getJobId());
            String name = job.getName().equals(idString) ? "N/A" : job.getName();
            printf(format, idString, job.getStatus(), toLocalDateTime(job.getSubmissionTime()), name);
        });
    });
}
Also used : JobSummary(com.hazelcast.jet.impl.JobSummary) Arrays(java.util.Arrays) BuildInfoProvider.getBuildInfo(com.hazelcast.instance.BuildInfoProvider.getBuildInfo) Parameters(picocli.CommandLine.Parameters) Member(com.hazelcast.cluster.Member) LogManager(java.util.logging.LogManager) ITypeConverter(picocli.CommandLine.ITypeConverter) JetClientInstanceImpl(com.hazelcast.jet.impl.JetClientInstanceImpl) HazelcastVersionProvider(com.hazelcast.client.console.HazelcastCommandLine.HazelcastVersionProvider) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) JobStatus(com.hazelcast.jet.core.JobStatus) CommandLine(picocli.CommandLine) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) MCClusterMetadata(com.hazelcast.client.impl.management.MCClusterMetadata) YamlClientConfigBuilder(com.hazelcast.client.config.YamlClientConfigBuilder) Collections.emptyList(java.util.Collections.emptyList) Mixin(picocli.CommandLine.Mixin) Collection(java.util.Collection) ExecutionException(picocli.CommandLine.ExecutionException) ConsumerEx(com.hazelcast.function.ConsumerEx) ClientClusterService(com.hazelcast.client.impl.spi.ClientClusterService) InvocationTargetException(java.lang.reflect.InvocationTargetException) LockSupport(java.util.concurrent.locks.LockSupport) Option(picocli.CommandLine.Option) List(java.util.List) Util.idToString(com.hazelcast.jet.Util.idToString) JobStateSnapshot(com.hazelcast.jet.JobStateSnapshot) Util.toLocalDateTime(com.hazelcast.jet.impl.util.Util.toLocalDateTime) Util.uncheckCall(com.hazelcast.jet.impl.util.Util.uncheckCall) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) RunAll(picocli.CommandLine.RunAll) JobSummary(com.hazelcast.jet.impl.JobSummary) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) FutureUtil(com.hazelcast.internal.util.FutureUtil) HelpCommand(picocli.CommandLine.HelpCommand) HazelcastClient(com.hazelcast.client.HazelcastClient) LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) MCGetClusterMetadataCodec(com.hazelcast.client.impl.protocol.codec.MCGetClusterMetadataCodec) Function(java.util.function.Function) Level(java.util.logging.Level) JetException(com.hazelcast.jet.JetException) HazelcastBootstrap(com.hazelcast.instance.impl.HazelcastBootstrap) DefaultExceptionHandler(picocli.CommandLine.DefaultExceptionHandler) ClientConfig(com.hazelcast.client.config.ClientConfig) BuildInfo(com.hazelcast.instance.BuildInfo) ParseResult(picocli.CommandLine.ParseResult) Command(picocli.CommandLine.Command) Job(com.hazelcast.jet.Job) JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException) PrintStream(java.io.PrintStream) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.cluster.Cluster) Ansi(picocli.CommandLine.Help.Ansi) IOException(java.io.IOException) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClusterState(com.hazelcast.cluster.ClusterState) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) IVersionProvider(picocli.CommandLine.IVersionProvider) Comparator(java.util.Comparator) Collections(java.util.Collections) Util(com.hazelcast.jet.Util) SECONDS(java.util.concurrent.TimeUnit.SECONDS) JetClientInstanceImpl(com.hazelcast.jet.impl.JetClientInstanceImpl) Util.idToString(com.hazelcast.jet.Util.idToString) HelpCommand(picocli.CommandLine.HelpCommand) Command(picocli.CommandLine.Command)

Example 10 with Command

use of picocli.CommandLine.Command in project hazelcast by hazelcast.

the class HazelcastCommandLine method listSnapshots.

@Command(name = "list-snapshots", description = "Lists exported snapshots on the cluster")
public 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) {
    runWithHazelcast(targets, verbosity, false, hz -> {
        Collection<JobStateSnapshot> snapshots = hz.getJet().getJobStateSnapshots();
        printf("%-23s %-15s %-24s %s", "TIME", "SIZE (bytes)", "JOB NAME", "SNAPSHOT NAME");
        snapshots.stream().sorted(Comparator.comparing(JobStateSnapshot::name)).forEach(ss -> {
            LocalDateTime creationTime = toLocalDateTime(ss.creationTime());
            String jobName = ss.jobName() == null ? Util.idToString(ss.jobId()) : ss.jobName();
            if (!fullJobName) {
                jobName = shorten(jobName);
            }
            printf("%-23s %-,15d %-24s %s", creationTime, ss.payloadSize(), jobName, ss.name());
        });
    });
}
Also used : Util.toLocalDateTime(com.hazelcast.jet.impl.util.Util.toLocalDateTime) LocalDateTime(java.time.LocalDateTime) JobStateSnapshot(com.hazelcast.jet.JobStateSnapshot) Util.idToString(com.hazelcast.jet.Util.idToString) HelpCommand(picocli.CommandLine.HelpCommand) Command(picocli.CommandLine.Command)

Aggregations

Command (picocli.CommandLine.Command)11 HelpCommand (picocli.CommandLine.HelpCommand)9 Job (com.hazelcast.jet.Job)6 JobStateSnapshot (com.hazelcast.jet.JobStateSnapshot)3 Util.idToString (com.hazelcast.jet.Util.idToString)3 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)2 MCClusterMetadata (com.hazelcast.client.impl.management.MCClusterMetadata)2 ClientClusterService (com.hazelcast.client.impl.spi.ClientClusterService)2 Cluster (com.hazelcast.cluster.Cluster)2 JetException (com.hazelcast.jet.JetException)2 Util.toLocalDateTime (com.hazelcast.jet.impl.util.Util.toLocalDateTime)2 LocalDateTime (java.time.LocalDateTime)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Option (picocli.CommandLine.Option)2 Parameters (picocli.CommandLine.Parameters)2 HazelcastClient (com.hazelcast.client.HazelcastClient)1 ClientConfig (com.hazelcast.client.config.ClientConfig)1 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)1 YamlClientConfigBuilder (com.hazelcast.client.config.YamlClientConfigBuilder)1