Search in sources :

Example 26 with CommandInputError

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

the class GetScheduleStatusCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream printStream) throws Exception {
    String[] programIdParts = arguments.get(ElementType.SCHEDULE.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    String appId = programIdParts[0];
    String scheduleName = programIdParts[1];
    ScheduleId scheduleId = cliConfig.getCurrentNamespace().app(appId).schedule(scheduleName);
    printStream.println(scheduleClient.getStatus(scheduleId));
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ScheduleId(io.cdap.cdap.proto.id.ScheduleId)

Example 27 with CommandInputError

use of io.cdap.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(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)

Example 28 with CommandInputError

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

the class GetProgramInstancesCommand method perform.

@Override
@SuppressWarnings("deprecation")
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    ApplicationId appId = cliConfig.getCurrentNamespace().app(programIdParts[0]);
    int instances;
    switch(elementType) {
        case WORKER:
            if (programIdParts.length < 2) {
                throw new CommandInputError(this);
            }
            String workerId = programIdParts[1];
            ProgramId worker = appId.worker(workerId);
            instances = programClient.getWorkerInstances(worker);
            break;
        case SERVICE:
            if (programIdParts.length < 2) {
                throw new CommandInputError(this);
            }
            String serviceName = programIdParts[1];
            instances = programClient.getServiceInstances(appId.service(serviceName));
            break;
        default:
            // TODO: remove this
            throw new IllegalArgumentException("Unrecognized program element type for scaling: " + elementType);
    }
    output.println(instances);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 29 with CommandInputError

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

the class GetProgramLiveInfoCommand 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 program = cliConfig.getCurrentNamespace().app(appId).program(elementType.getProgramType(), programName);
    DistributedProgramLiveInfo liveInfo = programClient.getLiveInfo(program);
    if (liveInfo == null) {
        output.println("No live info found");
        return;
    }
    Table table = Table.builder().setHeader("app", "type", "id", "runtime", "yarn app id").setRows(ImmutableList.of(liveInfo), new RowMaker<DistributedProgramLiveInfo>() {

        @Override
        public List<?> makeRow(DistributedProgramLiveInfo object) {
            return Lists.newArrayList(object.getApp(), object.getType(), object.getName(), object.getRuntime(), object.getYarnAppId());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
    if (liveInfo.getContainers() != null) {
        Table containersTable = Table.builder().setHeader("containers", "instance", "host", "container", "memory", "virtual cores", "debug port").setRows(liveInfo.getContainers(), new RowMaker<Containers.ContainerInfo>() {

            @Override
            public List<?> makeRow(Containers.ContainerInfo object) {
                return Lists.newArrayList("", object.getInstance(), object.getHost(), object.getContainer(), object.getMemory(), object.getVirtualCores(), object.getDebugPort());
            }
        }).build();
        cliConfig.getTableRenderer().render(cliConfig, output, containersTable);
    }
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) Table(io.cdap.cdap.cli.util.table.Table) DistributedProgramLiveInfo(io.cdap.cdap.proto.DistributedProgramLiveInfo) RowMaker(io.cdap.cdap.cli.util.RowMaker) Containers(io.cdap.cdap.proto.Containers) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 30 with CommandInputError

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

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)

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