Search in sources :

Example 6 with CommandInputError

use of co.cask.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(co.cask.cdap.cli.exception.CommandInputError) Table(co.cask.cdap.cli.util.table.Table) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId)

Example 7 with CommandInputError

use of co.cask.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(co.cask.cdap.cli.exception.CommandInputError) Table(co.cask.cdap.cli.util.table.Table) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId)

Example 8 with CommandInputError

use of co.cask.cdap.cli.exception.CommandInputError in project cdap by caskdata.

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(co.cask.cdap.cli.exception.CommandInputError) Table(co.cask.cdap.cli.util.table.Table) WorkflowToken(co.cask.cdap.api.workflow.WorkflowToken) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId)

Example 9 with CommandInputError

use of co.cask.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", "start", "stop").setRows(records, new RowMaker<RunRecord>() {

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

Example 10 with CommandInputError

use of co.cask.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(co.cask.cdap.cli.exception.CommandInputError) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId)

Aggregations

CommandInputError (co.cask.cdap.cli.exception.CommandInputError)21 ProgramId (co.cask.cdap.proto.id.ProgramId)8 Table (co.cask.cdap.cli.util.table.Table)7 ApplicationId (co.cask.cdap.proto.id.ApplicationId)6 ScheduleId (co.cask.cdap.proto.id.ScheduleId)6 RowMaker (co.cask.cdap.cli.util.RowMaker)4 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)4 Schedule (co.cask.cdap.api.schedule.Schedule)2 Schedules (co.cask.cdap.api.schedule.Schedules)2 ScheduleInstanceConfiguration (co.cask.cdap.proto.ScheduleInstanceConfiguration)2 FlowletId (co.cask.cdap.proto.id.FlowletId)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 ServiceId (co.cask.cdap.proto.id.ServiceId)2 WorkflowActionNode (co.cask.cdap.api.workflow.WorkflowActionNode)1 WorkflowToken (co.cask.cdap.api.workflow.WorkflowToken)1 Containers (co.cask.cdap.proto.Containers)1 DistributedProgramLiveInfo (co.cask.cdap.proto.DistributedProgramLiveInfo)1 RunRecord (co.cask.cdap.proto.RunRecord)1 ScheduleDetail (co.cask.cdap.proto.ScheduleDetail)1 WorkflowId (co.cask.cdap.proto.id.WorkflowId)1