use of io.cdap.cdap.cli.exception.CommandInputError in project cdap by caskdata.
the class SetProgramInstancesCommand 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]);
int numInstances = arguments.getInt(ArgumentName.NUM_INSTANCES.toString());
switch(elementType) {
case WORKER:
if (programIdParts.length < 2) {
throw new CommandInputError(this);
}
String workerName = programIdParts[1];
ProgramId workerId = appId.worker(workerName);
programClient.setWorkerInstances(workerId, numInstances);
output.printf("Successfully set worker '%s' of app '%s' to %d instances\n", workerName, appId.getEntityName(), numInstances);
break;
case SERVICE:
if (programIdParts.length < 2) {
throw new CommandInputError(this);
}
String serviceName = programIdParts[1];
ServiceId service = appId.service(serviceName);
programClient.setServiceInstances(service, numInstances);
output.printf("Successfully set service '%s' of app '%s' to %d instances\n", serviceName, appId.getEntityName(), numInstances);
break;
default:
// TODO: remove this
throw new IllegalArgumentException("Unrecognized program element type for scaling: " + elementType);
}
}
use of io.cdap.cdap.cli.exception.CommandInputError in project cdap by caskdata.
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);
}
}
use of io.cdap.cdap.cli.exception.CommandInputError in project cdap by caskdata.
the class ResumeScheduleCommand 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 schedule = cliConfig.getCurrentNamespace().app(appId).schedule(scheduleName);
scheduleClient.resume(schedule);
printStream.printf("Successfully resumed schedule '%s' in app '%s'\n", scheduleName, appId);
}
use of io.cdap.cdap.cli.exception.CommandInputError in project cdap by caskdata.
the class UpdateTimeScheduleCommand 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.update(scheduleId, scheduleDetail);
printStream.printf("Successfully updated schedule '%s' in app '%s'\n", scheduleName, appId);
}
use of io.cdap.cdap.cli.exception.CommandInputError in project cdap by caskdata.
the class DeleteScheduleCommand 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 schedule = cliConfig.getCurrentNamespace().app(appId).schedule(scheduleName);
scheduleClient.delete(schedule);
printStream.printf("Successfully deleted schedule '%s' in app '%s'\n", scheduleName, appId);
}
Aggregations