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.");
});
}
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);
});
}
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.");
});
}
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);
});
});
}
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());
});
});
}
Aggregations