Search in sources :

Example 36 with CommandInputError

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

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

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

the class StartProgramCommand 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);
    }
    ProgramId programId = parseProgramId(arguments, elementType);
    String appName = programId.getApplication();
    String appVersion = programId.getVersion();
    String programName = programId.getProgram();
    String runtimeArgsString = arguments.getOptional(ArgumentName.RUNTIME_ARGS.toString(), "");
    if (runtimeArgsString == null || runtimeArgsString.isEmpty()) {
        // run with stored runtime args
        programClient.start(programId, isDebug, null);
        runtimeArgsString = SPACE_EQUALS_JOINER.join(programClient.getRuntimeArgs(programId));
        output.printf("Successfully started %s '%s' of application '%s.%s' with stored runtime arguments '%s'\n", elementType.getName(), programName, appName, appVersion, runtimeArgsString);
    } else {
        // run with user-provided runtime args
        Map<String, String> runtimeArgs = ArgumentParser.parseMap(runtimeArgsString, ArgumentName.RUNTIME_ARGS.toString());
        programClient.start(programId, isDebug, runtimeArgs);
        output.printf("Successfully started %s '%s' of application '%s.%s' with provided runtime arguments '%s'\n", elementType.getName(), programName, appName, appVersion, runtimeArgsString);
    }
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 38 with CommandInputError

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

the class AddTimeScheduleCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream printStream) throws Exception {
    String scheduleName = arguments.get(ArgumentName.SCHEDULE_NAME.toString());
    String[] programIdParts = arguments.get(ArgumentName.PROGRAM.toString()).split("\\.");
    String version = arguments.getOptional(ArgumentName.APP_VERSION.toString());
    String scheduleDescription = arguments.getOptional(ArgumentName.DESCRIPTION.toString(), "");
    String cronExpression = arguments.get(ArgumentName.CRON_EXPRESSION.toString());
    String schedulePropertiesString = arguments.getOptional(ArgumentName.SCHEDULE_PROPERTIES.toString(), "");
    String scheduleRunConcurrencyString = arguments.getOptional(ArgumentName.CONCURRENCY.toString(), null);
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    String appId = programIdParts[0];
    NamespaceId namespaceId = cliConfig.getCurrentNamespace();
    ApplicationId applicationId = (version == null) ? namespaceId.app(appId) : namespaceId.app(appId, version);
    ScheduleId scheduleId = applicationId.schedule(scheduleName);
    String description = scheduleDescription == null ? null : scheduleDescription;
    ScheduleProgramInfo programInfo = new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, programIdParts[1]);
    List<Constraint> constraints = scheduleRunConcurrencyString == null ? ImmutableList.of() : ImmutableList.of(new ProtoConstraint.ConcurrencyConstraint(Integer.valueOf(scheduleRunConcurrencyString)));
    Map<String, String> propertiesMap = ArgumentParser.parseMap(schedulePropertiesString, ArgumentName.SCHEDULE_PROPERTIES.toString());
    ScheduleDetail scheduleDetail = new ScheduleDetail(scheduleName, description, programInfo, propertiesMap, new ProtoTrigger.TimeTrigger(cronExpression), constraints, null);
    scheduleClient.add(scheduleId, scheduleDetail);
    printStream.printf("Successfully added schedule '%s' in app '%s'\n", scheduleName, appId);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ProtoConstraint(io.cdap.cdap.proto.ProtoConstraint) Constraint(io.cdap.cdap.internal.schedule.constraint.Constraint) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) ProtoTrigger(io.cdap.cdap.proto.ProtoTrigger) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ScheduleProgramInfo(io.cdap.cdap.api.workflow.ScheduleProgramInfo)

Example 39 with CommandInputError

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

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

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

the class AbstractCommand method getTimestamp.

/**
 * Returns a timestamp in milliseconds.
 *
 * @param arg The string argument user provided.
 * @param base The base timestamp to relative from if the time format provided is a relative time.
 * @return Timestamp in milliseconds
 * @throws io.cdap.cdap.cli.exception.CommandInputError if failed to parse input.
 */
protected long getTimestamp(String arg, long base) {
    try {
        if (arg.startsWith("+") || arg.startsWith("-")) {
            int dir = arg.startsWith("+") ? 1 : -1;
            char type = arg.charAt(arg.length() - 1);
            int offset = Integer.parseInt(arg.substring(1, arg.length() - 1));
            switch(type) {
                case 's':
                    return base + dir * TimeUnit.SECONDS.toMillis(offset);
                case 'm':
                    return base + dir * TimeUnit.MINUTES.toMillis(offset);
                case 'h':
                    return base + dir * TimeUnit.HOURS.toMillis(offset);
                case 'd':
                    return base + dir * TimeUnit.DAYS.toMillis(offset);
                default:
                    throw new CommandInputError(this, "Unsupported relative time format: " + type);
            }
        }
        if (arg.equalsIgnoreCase("min")) {
            return 0L;
        }
        if (arg.equalsIgnoreCase("max")) {
            return Long.MAX_VALUE;
        }
        return Long.parseLong(arg);
    } catch (NumberFormatException e) {
        throw new CommandInputError(this, "Invalid number value: " + arg + ". Reason: " + e.getMessage());
    }
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError)

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