Search in sources :

Example 11 with CommandInputError

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

the class ListWorkflowSchedulesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(ElementType.WORKFLOW.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    final String appId = programIdParts[0];
    String workflowName = programIdParts[1];
    WorkflowId workflowId = cliConfig.getCurrentNamespace().app(appId).workflow(workflowName);
    List<ScheduleDetail> list = scheduleClient.listSchedules(workflowId);
    Table table = Table.builder().setHeader("application", "program", "program type", "name", "description", "trigger", "timeoutMillis", "properties").setRows(list, new RowMaker<ScheduleDetail>() {

        @Override
        public List<?> makeRow(ScheduleDetail object) {
            return Lists.newArrayList(appId, object.getProgram().getProgramName(), object.getProgram().getProgramType().name(), object.getName(), object.getDescription(), object.getTrigger(), object.getTimeoutMillis(), GSON.toJson(object.getProperties()));
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) WorkflowId(io.cdap.cdap.proto.id.WorkflowId)

Example 12 with CommandInputError

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

the class SuspendScheduleCommand 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);
    scheduleClient.suspend(scheduleId);
    printStream.printf("Successfully suspended schedule '%s' in app '%s'\n", scheduleName, appId);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ScheduleId(io.cdap.cdap.proto.id.ScheduleId)

Example 13 with CommandInputError

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

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)

Example 14 with CommandInputError

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

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 15 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)

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