use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class DefaultStoreTest method testStopBeforeStart.
@Test(expected = RuntimeException.class)
public void testStopBeforeStart() throws RuntimeException {
ProgramId programId = new ProgramId("account1", "invalidApp", ProgramType.FLOW, "InvalidFlowOperation");
long now = System.currentTimeMillis();
store.setStop(programId, "runx", now, ProgramController.State.ERROR.getRunStatus());
}
use of co.cask.cdap.proto.id.ProgramId 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 FLOWLET:
if (programIdParts.length < 3) {
throw new CommandInputError(this);
}
String flowId = programIdParts[1];
String flowletName = programIdParts[2];
FlowletId flowletId = appId.flow(flowId).flowlet(flowletName);
programClient.setFlowletInstances(flowletId, numInstances);
output.printf("Successfully set flowlet '%s' of flow '%s' of app '%s' to %d instances\n", flowId, flowletId, appId.getEntityName(), numInstances);
break;
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 co.cask.cdap.proto.id.ProgramId 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 = GSON.toJson(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 co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class StopProgramCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
ProgramId programId = parseProgramId(arguments, elementType);
String appName = programId.getApplication();
String appVersion = programId.getVersion();
String programName = programId.getProgram();
programClient.stop(programId);
output.printf("Successfully stopped %s '%s' of application '%s.%s'\n", elementType.getName(), programName, appName, appVersion);
}
use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class ProgramClient method stopAll.
/**
* Stops all currently running programs.
*/
public void stopAll(NamespaceId namespace) throws IOException, UnauthenticatedException, InterruptedException, TimeoutException, UnauthorizedException, ApplicationNotFoundException {
List<ApplicationRecord> allApps = applicationClient.list(namespace);
for (ApplicationRecord applicationRecord : allApps) {
ApplicationId appId = new ApplicationId(namespace.getNamespace(), applicationRecord.getName(), applicationRecord.getAppVersion());
List<ProgramRecord> programRecords = applicationClient.listPrograms(appId);
for (ProgramRecord programRecord : programRecords) {
try {
ProgramId program = appId.program(programRecord.getType(), programRecord.getName());
String status = this.getStatus(program);
if (!status.equals("STOPPED")) {
try {
this.stop(program);
} catch (IOException ioe) {
// which can be due to the program already being stopped when calling stop on it.
if (!"STOPPED".equals(getStatus(program))) {
throw ioe;
}
// Most likely, there was a race condition that the program stopped between the time we checked its
// status and calling the stop method.
LOG.warn("Program {} is already stopped, proceeding even though the following exception is raised.", program, ioe);
}
this.waitForStatus(program, ProgramStatus.STOPPED, 60, TimeUnit.SECONDS);
}
} catch (ProgramNotFoundException e) {
// IGNORE
}
}
}
}
Aggregations