use of org.rundeck.client.api.model.ProjectExportStatus in project rundeck-cli by rundeck.
the class Archives method export.
@Command(description = "Export a project archive")
public boolean export(ArchiveExportOpts opts, CommandOutput output) throws IOException, InputError {
if (opts.isIncludeFlags() && opts.isExecutionIds()) {
throw new InputError("Cannot use --execids/-e with --include/-i");
}
boolean apiv19 = getClient().getApiVersion() >= 19;
Set<Flags> includeFlags = opts.isIncludeFlags() ? opts.getIncludeFlags() : new HashSet<>();
if (!opts.isIncludeFlags()) {
includeFlags.add(Flags.all);
}
String project = projectOrEnv(opts);
if (!apiv19) {
if (opts.isIncludeFlags() && includeFlags.size() > 1) {
throw new InputError("Cannot use --include: " + includeFlags + " with API < 19");
}
if (opts.isIncludeFlags() && !includeFlags.contains(Flags.all)) {
throw new InputError("Cannot use --include: " + includeFlags + " with API < 19");
}
output.info(String.format("Export Archive for project: %s", project));
if (opts.isExecutionIds()) {
output.info(String.format("Contents: only execution IDs: %s", opts.getExecutionIds()));
} else {
output.info("Contents: all");
}
output.info("Begin synchronous request...");
// sync
receiveArchiveFile(output, apiCall(api -> api.exportProject(project, opts.getExecutionIds())), opts.getFile());
return true;
}
output.info(String.format("Export Archive for project: %s", project));
if (opts.isExecutionIds()) {
output.info(String.format("Contents: only execution IDs: %s", opts.getExecutionIds()));
} else {
output.info(String.format("Contents: %s", opts.getIncludeFlags()));
}
output.info("Begin asynchronous request...");
ProjectExportStatus status;
if (opts.isExecutionIds()) {
status = apiCall(api -> api.exportProjectAsync(project, opts.getExecutionIds()));
} else {
status = apiCall(api -> api.exportProjectAsync(project, includeFlags.contains(Flags.all), includeFlags.contains(Flags.jobs), includeFlags.contains(Flags.executions), includeFlags.contains(Flags.configs), includeFlags.contains(Flags.readmes), includeFlags.contains(Flags.acls), includeFlags.contains(Flags.scm)));
}
return loopStatus(getClient(), status, project, opts.getFile(), output, () -> {
try {
Thread.sleep(2000);
return true;
} catch (InterruptedException e) {
return false;
}
});
}
use of org.rundeck.client.api.model.ProjectExportStatus in project rundeck-cli by rundeck.
the class Archives method loopStatus.
public static boolean loopStatus(final ServiceClient<RundeckApi> client, final ProjectExportStatus status, String project, File outputfile, CommandOutput out, BooleanSupplier waitFunc) throws IOException {
boolean done = false;
int perc = status.getPercentage();
while (!done) {
ProjectExportStatus status1 = client.apiCall(api -> api.exportProjectStatus(project, status.getToken()));
if (status1.getPercentage() > perc) {
out.output(".");
perc = status1.getPercentage();
}
done = status1.getReady();
if (!done && !waitFunc.getAsBoolean()) {
break;
}
}
if (done) {
receiveArchiveFile(out, client.apiCall(api -> api.exportProjectDownload(project, status.getToken())), outputfile);
}
return done;
}
Aggregations