Search in sources :

Example 1 with CommandInputError

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

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 2 with CommandInputError

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

the class GetProgramLogsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    String appId = programIdParts[0];
    String startString = arguments.getOptional(ArgumentName.START_TIME.toString(), "0");
    long start = TimeMathParser.parseTimeInSeconds(startString);
    String stopString = arguments.getOptional(ArgumentName.END_TIME.toString(), Long.toString(Integer.MAX_VALUE));
    long stop = TimeMathParser.parseTimeInSeconds(stopString);
    String logs;
    if (elementType.getProgramType() != null) {
        if (programIdParts.length < 2) {
            throw new CommandInputError(this);
        }
        String programName = programIdParts[1];
        ProgramId programId = cliConfig.getCurrentNamespace().app(appId).program(elementType.getProgramType(), programName);
        logs = programClient.getProgramLogs(programId, start, stop);
    } else {
        throw new IllegalArgumentException("Cannot get logs for " + elementType.getNamePlural());
    }
    output.println(logs);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 3 with CommandInputError

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

the class GetProgramRunsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    String appId = programIdParts[0];
    long currentTime = System.currentTimeMillis();
    long startTime = getTimestamp(arguments.getOptional(ArgumentName.START_TIME.toString(), "min"), currentTime);
    long endTime = getTimestamp(arguments.getOptional(ArgumentName.END_TIME.toString(), "max"), currentTime);
    int limit = arguments.getIntOptional(ArgumentName.LIMIT.toString(), Integer.MAX_VALUE);
    List<RunRecord> records;
    if (elementType.getProgramType() != null) {
        if (programIdParts.length < 2) {
            throw new CommandInputError(this);
        }
        String programName = programIdParts[1];
        ProgramId programId = cliConfig.getCurrentNamespace().app(appId).program(elementType.getProgramType(), programName);
        if (arguments.hasArgument(ArgumentName.RUN_STATUS.toString())) {
            records = programClient.getProgramRuns(programId, arguments.get(ArgumentName.RUN_STATUS.toString()), startTime, endTime, limit);
        } else {
            records = programClient.getAllProgramRuns(programId, startTime, endTime, limit);
        }
    } else {
        throw new IllegalArgumentException("Unrecognized program element type for history: " + elementType);
    }
    Table table = Table.builder().setHeader("pid", "end status", "init time", "start time", "stop time").setRows(records, new RowMaker<RunRecord>() {

        @Override
        public List<?> makeRow(RunRecord object) {
            return Lists.newArrayList(object.getPid(), object.getStatus(), object.getStartTs(), object.getRunTs() == null ? "" : object.getRunTs(), object.getStopTs() == null ? "" : object.getStopTs());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) RunRecord(io.cdap.cdap.proto.RunRecord) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 4 with CommandInputError

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

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 5 with CommandInputError

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

the class GetWorkflowStateCommand 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 = getWorkflowNodeStates(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)

Aggregations

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