use of io.cdap.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 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.proto.id.ProgramId in project cdap by caskdata.
the class SetProgramRuntimeArgsCommand 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();
String runtimeArgsString = arguments.get(ArgumentName.RUNTIME_ARGS.toString());
Map<String, String> runtimeArgs = ArgumentParser.parseMap(runtimeArgsString, ArgumentName.RUNTIME_ARGS.toString());
programClient.setRuntimeArgs(programId, runtimeArgs);
output.printf("Successfully set runtime args of %s '%s' of application '%s.%s' to '%s'\n", elementType.getName(), programName, appName, appVersion, runtimeArgsString);
}
use of io.cdap.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 = 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.proto.id.ProgramId in project cdap by caskdata.
the class LogHttpHandlerTest method testFilterWithEmptyResult.
@Test
public void testFilterWithEmptyResult() throws Exception {
String appId = "testTemplate1";
String entityType = "workflows";
String entityId = "testWorkflow1";
String namespace = NamespaceId.DEFAULT.getEntityName();
ProgramId programId = new NamespaceId(namespace).app(appId).program(ProgramType.valueOfCategoryName(entityType), entityId);
RunRecord runRecord = mockLogReader.getRunRecord(programId);
String logsUrl = String.format("apps/%s/%s/%s/runs/%s/logs?format=json&filter=MDC:asdf=nothing", appId, entityType, entityId, runRecord.getPid());
HttpResponse response = doGet(getVersionedAPIPath(logsUrl, namespace));
verifyLogs(response, entityId, "json", true, true, true, 0, 0);
}
use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.
the class LogHttpHandlerTest method testNativeMethodField.
// Verify the Json returned for logs has isNativeMethod set correctly
@Test
public void testNativeMethodField() throws Exception {
ProgramId programId = new NamespaceId(MockLogReader.TEST_NAMESPACE).app("testTemplate1").program(ProgramType.valueOfCategoryName("workflows"), "testWorkflow1");
RunRecord runRecord = mockLogReader.getRunRecord(programId);
String logsUrl = String.format("apps/%s/%s/%s/runs/%s/logs/next?format=json", "testTemplate1", "workflows", "testWorkflow1", runRecord.getPid());
HttpResponse response = doGet(getVersionedAPIPath(logsUrl, MockLogReader.TEST_NAMESPACE));
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
List<LogDataOffset> logDataOffsetList = GSON.fromJson(response.getResponseBodyAsString(), LIST_LOGDATA_OFFSET_TYPE);
Assert.assertEquals(logDataOffsetList.size(), 15);
Assert.assertTrue(logDataOffsetList.get(0).getLog().getNativeMethod());
Assert.assertFalse(logDataOffsetList.get(1).getLog().getNativeMethod());
Assert.assertFalse(logDataOffsetList.get(2).getLog().getNativeMethod());
}
Aggregations