Search in sources :

Example 31 with CommandInputError

use of io.cdap.cdap.cli.exception.CommandInputError in project cdap by caskdata.

the class GetWorkflowLocalDatasetsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream printStream) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    ProgramRunId programRunId = cliConfig.getCurrentNamespace().app(programIdParts[0]).workflow(programIdParts[1]).run(arguments.get(ArgumentName.RUN_ID.toString()));
    Table table = getWorkflowLocalDatasets(programRunId);
    cliConfig.getTableRenderer().render(cliConfig, printStream, table);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) Table(io.cdap.cdap.cli.util.table.Table) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId)

Example 32 with CommandInputError

use of io.cdap.cdap.cli.exception.CommandInputError in project cdap by cdapio.

the class DeleteWorkflowLocalDatasetsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream printStream) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    ProgramRunId programRunId = new ProgramRunId(cliConfig.getCurrentNamespace().getNamespace(), programIdParts[0], ProgramType.WORKFLOW, programIdParts[1], arguments.get(ArgumentName.RUN_ID.toString()));
    workflowClient.deleteWorkflowLocalDatasets(programRunId);
    printStream.printf("Successfully deleted local datasets associated with the workflow run.");
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId)

Example 33 with CommandInputError

use of io.cdap.cdap.cli.exception.CommandInputError in project cdap by cdapio.

the class CallServiceCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String method = arguments.get(ArgumentName.HTTP_METHOD.toString());
    String path = arguments.get(ArgumentName.ENDPOINT.toString());
    path = path.startsWith("/") ? path.substring(1) : path;
    String headers = arguments.getOptional(ArgumentName.HEADERS.toString(), "");
    String bodyString = arguments.getOptional(ArgumentName.HTTP_BODY.toString(), "");
    String bodyFile = arguments.getOptional(ArgumentName.LOCAL_FILE_PATH.toString(), "");
    Preconditions.checkNotNull(bodyString);
    Preconditions.checkNotNull(bodyFile);
    if (!bodyString.isEmpty() && !bodyFile.isEmpty()) {
        String message = String.format("Please provide either [body <%s>] or [body:file <%s>], " + "but not both", ArgumentName.HTTP_BODY.toString(), ArgumentName.LOCAL_FILE_PATH.toString());
        throw new CommandInputError(this, message);
    }
    Map<String, String> headerMap = GSON.fromJson(headers, new TypeToken<Map<String, String>>() {
    }.getType());
    ServiceId service = new ServiceId(parseProgramId(arguments, ElementType.SERVICE));
    URL url = arguments.hasArgument(ArgumentName.APP_VERSION.getName()) ? new URL(serviceClient.getVersionedServiceURL(service), path) : new URL(serviceClient.getServiceURL(service), path);
    HttpMethod httpMethod = HttpMethod.valueOf(method);
    HttpRequest.Builder builder = HttpRequest.builder(httpMethod, url).addHeaders(headerMap);
    if (httpMethod == HttpMethod.GET && (!bodyFile.isEmpty() || !bodyString.isEmpty())) {
        throw new UnsupportedOperationException("Sending body in a GET request is not supported");
    }
    if (!bodyFile.isEmpty()) {
        builder.withBody(filePathResolver.resolvePathToFile(bodyFile));
    } else if (!bodyString.isEmpty()) {
        builder.withBody(bodyString);
    }
    HttpResponse response = restClient.execute(builder.build(), clientConfig.getAccessToken());
    output.printf("< %s %s\n", response.getResponseCode(), response.getResponseMessage());
    for (Map.Entry<String, String> header : response.getHeaders().entries()) {
        output.printf("< %s: %s\n", header.getKey(), header.getValue());
    }
    output.print(response.getResponseBodyAsString());
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL) ServiceId(io.cdap.cdap.proto.id.ServiceId) TypeToken(com.google.common.reflect.TypeToken) Map(java.util.Map) HttpMethod(io.cdap.common.http.HttpMethod)

Example 34 with CommandInputError

use of io.cdap.cdap.cli.exception.CommandInputError in project cdap by cdapio.

the class GetProgramStatusCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    String appId = programIdParts[0];
    String programName = programIdParts[1];
    ProgramId programId = cliConfig.getCurrentNamespace().app(appId).program(elementType.getProgramType(), programName);
    String status = programClient.getStatus(programId);
    output.println(status);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 35 with CommandInputError

use of io.cdap.cdap.cli.exception.CommandInputError in project cdap by cdapio.

the class GetWorkflowTokenCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    ApplicationId appId = cliConfig.getCurrentNamespace().app(programIdParts[0]);
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    ProgramId workflowId = appId.workflow(programIdParts[1]);
    ProgramRunId runId = workflowId.run(arguments.get(ArgumentName.RUN_ID.toString()));
    WorkflowToken.Scope workflowTokenScope = null;
    if (arguments.hasArgument(ArgumentName.WORKFLOW_TOKEN_SCOPE.toString())) {
        String scope = arguments.get(ArgumentName.WORKFLOW_TOKEN_SCOPE.toString()).toUpperCase();
        workflowTokenScope = WorkflowToken.Scope.valueOf(scope);
    }
    String key = null;
    if (arguments.hasArgument(ArgumentName.WORKFLOW_TOKEN_KEY.toString())) {
        key = arguments.get(ArgumentName.WORKFLOW_TOKEN_KEY.toString());
    }
    Table table;
    if (arguments.hasArgument(ArgumentName.WORKFLOW_NODE.toString())) {
        table = getWorkflowToken(runId, workflowTokenScope, key, arguments.get(ArgumentName.WORKFLOW_NODE.toString()));
    } else {
        table = getWorkflowToken(runId, workflowTokenScope, key);
    }
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) Table(io.cdap.cdap.cli.util.table.Table) WorkflowToken(io.cdap.cdap.api.workflow.WorkflowToken) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Aggregations

CommandInputError (io.cdap.cdap.cli.exception.CommandInputError)40 ProgramId (io.cdap.cdap.proto.id.ProgramId)16 Table (io.cdap.cdap.cli.util.table.Table)12 ScheduleId (io.cdap.cdap.proto.id.ScheduleId)12 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)10 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)8 RowMaker (io.cdap.cdap.cli.util.RowMaker)6 ScheduleDetail (io.cdap.cdap.proto.ScheduleDetail)6 ScheduleProgramInfo (io.cdap.cdap.api.workflow.ScheduleProgramInfo)4 Constraint (io.cdap.cdap.internal.schedule.constraint.Constraint)4 ProtoConstraint (io.cdap.cdap.proto.ProtoConstraint)4 ProtoTrigger (io.cdap.cdap.proto.ProtoTrigger)4 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)4 ServiceId (io.cdap.cdap.proto.id.ServiceId)4 TypeToken (com.google.common.reflect.TypeToken)2 WorkflowToken (io.cdap.cdap.api.workflow.WorkflowToken)2 Containers (io.cdap.cdap.proto.Containers)2 DistributedProgramLiveInfo (io.cdap.cdap.proto.DistributedProgramLiveInfo)2 RunRecord (io.cdap.cdap.proto.RunRecord)2 WorkflowId (io.cdap.cdap.proto.id.WorkflowId)2