Search in sources :

Example 1 with ProjectExportStatus

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;
        }
    });
}
Also used : Command(org.rundeck.toolbelt.Command) CommandOutput(org.rundeck.toolbelt.CommandOutput) CommandLineInterface(com.lexicalscope.jewel.cli.CommandLineInterface) ProjectExportStatus(org.rundeck.client.api.model.ProjectExportStatus) ProjectImportStatus(org.rundeck.client.api.model.ProjectImportStatus) Util(org.rundeck.client.util.Util) Option(com.lexicalscope.jewel.cli.Option) AppCommand(org.rundeck.client.tool.commands.AppCommand) ProjectNameOptions(org.rundeck.client.tool.options.ProjectNameOptions) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) Client(org.rundeck.client.util.Client) IOException(java.io.IOException) File(java.io.File) RequestBody(okhttp3.RequestBody) BooleanSupplier(java.util.function.BooleanSupplier) HashSet(java.util.HashSet) InputError(org.rundeck.client.tool.InputError) RdApp(org.rundeck.client.tool.RdApp) List(java.util.List) ServiceClient(org.rundeck.client.util.ServiceClient) RundeckApi(org.rundeck.client.api.RundeckApi) ResponseBody(okhttp3.ResponseBody) InputStream(java.io.InputStream) InputError(org.rundeck.client.tool.InputError) ProjectExportStatus(org.rundeck.client.api.model.ProjectExportStatus) Command(org.rundeck.toolbelt.Command) AppCommand(org.rundeck.client.tool.commands.AppCommand)

Example 2 with ProjectExportStatus

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;
}
Also used : Command(org.rundeck.toolbelt.Command) CommandOutput(org.rundeck.toolbelt.CommandOutput) CommandLineInterface(com.lexicalscope.jewel.cli.CommandLineInterface) ProjectExportStatus(org.rundeck.client.api.model.ProjectExportStatus) ProjectImportStatus(org.rundeck.client.api.model.ProjectImportStatus) Util(org.rundeck.client.util.Util) Option(com.lexicalscope.jewel.cli.Option) AppCommand(org.rundeck.client.tool.commands.AppCommand) ProjectNameOptions(org.rundeck.client.tool.options.ProjectNameOptions) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) Client(org.rundeck.client.util.Client) IOException(java.io.IOException) File(java.io.File) RequestBody(okhttp3.RequestBody) BooleanSupplier(java.util.function.BooleanSupplier) HashSet(java.util.HashSet) InputError(org.rundeck.client.tool.InputError) RdApp(org.rundeck.client.tool.RdApp) List(java.util.List) ServiceClient(org.rundeck.client.util.ServiceClient) RundeckApi(org.rundeck.client.api.RundeckApi) ResponseBody(okhttp3.ResponseBody) InputStream(java.io.InputStream) ProjectExportStatus(org.rundeck.client.api.model.ProjectExportStatus)

Aggregations

CommandLineInterface (com.lexicalscope.jewel.cli.CommandLineInterface)2 Option (com.lexicalscope.jewel.cli.Option)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 BooleanSupplier (java.util.function.BooleanSupplier)2 RequestBody (okhttp3.RequestBody)2 ResponseBody (okhttp3.ResponseBody)2 RundeckApi (org.rundeck.client.api.RundeckApi)2 ProjectExportStatus (org.rundeck.client.api.model.ProjectExportStatus)2 ProjectImportStatus (org.rundeck.client.api.model.ProjectImportStatus)2 InputError (org.rundeck.client.tool.InputError)2 RdApp (org.rundeck.client.tool.RdApp)2 AppCommand (org.rundeck.client.tool.commands.AppCommand)2 ProjectNameOptions (org.rundeck.client.tool.options.ProjectNameOptions)2 Client (org.rundeck.client.util.Client)2