use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class DefaultPreviewStoreTest method testPreviewInfo.
@Test
public void testPreviewInfo() throws IOException {
// test non existing preview
ApplicationId nonexist = new ApplicationId("ns1", "nonexist");
Assert.assertNull(store.getProgramRunId(nonexist));
Assert.assertNull(store.getPreviewStatus(nonexist));
// test put and get
ApplicationId applicationId = new ApplicationId("ns1", "app1");
ProgramRunId runId = new ProgramRunId("ns1", "app1", ProgramType.WORKFLOW, "test", RunIds.generate().getId());
PreviewStatus status = new PreviewStatus(PreviewStatus.Status.COMPLETED, System.currentTimeMillis(), null, 0L, System.currentTimeMillis());
store.setProgramId(runId);
store.setPreviewStatus(applicationId, status);
Assert.assertEquals(runId, store.getProgramRunId(applicationId));
Assert.assertEquals(status, store.getPreviewStatus(applicationId));
}
use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class BaseBatchCommand method readArgs.
/**
* Reads arguments to get app id, program types, and list of input programs.
*/
protected Args<T> readArgs(Arguments arguments) throws ApplicationNotFoundException, UnauthenticatedException, IOException, UnauthorizedException {
String appName = arguments.get(ArgumentName.APP.getName());
ApplicationId appId = cliConfig.getCurrentNamespace().app(appName);
Set<ProgramType> programTypes = getDefaultProgramTypes();
if (arguments.hasArgument(ArgumentName.PROGRAM_TYPES.getName())) {
programTypes.clear();
String programTypesStr = arguments.get(ArgumentName.PROGRAM_TYPES.getName());
for (String programTypeStr : Splitter.on(',').trimResults().split(programTypesStr)) {
ProgramType programType = ProgramType.valueOf(programTypeStr.toUpperCase());
programTypes.add(programType);
}
}
List<T> programs = new ArrayList<>();
Map<ProgramType, List<ProgramRecord>> appPrograms = appClient.listProgramsByType(appId);
for (ProgramType programType : programTypes) {
List<ProgramRecord> programRecords = appPrograms.get(programType);
if (programRecords != null) {
for (ProgramRecord programRecord : programRecords) {
programs.add(createProgram(programRecord));
}
}
}
return new Args<>(appId, programTypes, programs);
}
use of io.cdap.cdap.proto.id.ApplicationId 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.ApplicationId in project cdap by caskdata.
the class ProgramExistenceVerifier method ensureExists.
@Override
public void ensureExists(ProgramId programId) throws ApplicationNotFoundException, ProgramNotFoundException {
ApplicationId appId = programId.getParent();
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
ProgramType programType = programId.getType();
Set<String> programNames = null;
if (programType == ProgramType.MAPREDUCE && appSpec.getMapReduce() != null) {
programNames = appSpec.getMapReduce().keySet();
} else if (programType == ProgramType.WORKFLOW && appSpec.getWorkflows() != null) {
programNames = appSpec.getWorkflows().keySet();
} else if (programType == ProgramType.SERVICE && appSpec.getServices() != null) {
programNames = appSpec.getServices().keySet();
} else if (programType == ProgramType.SPARK && appSpec.getSpark() != null) {
programNames = appSpec.getSpark().keySet();
} else if (programType == ProgramType.WORKER && appSpec.getWorkers() != null) {
programNames = appSpec.getWorkers().keySet();
}
if (programNames != null) {
if (programNames.contains(programId.getProgram())) {
// is valid.
return;
}
}
throw new ProgramNotFoundException(programId);
}
use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class LocalPreferencesFetcherInternal method get.
/**
* Get preferences for the given identify
*/
public PreferencesDetail get(EntityId entityId, boolean resolved) {
final PreferencesService service = preferencesService;
PreferencesDetail detail = null;
switch(entityId.getEntityType()) {
case INSTANCE:
detail = resolved ? service.getResolvedPreferences() : service.getPreferences();
break;
case NAMESPACE:
NamespaceId namespaceId = (NamespaceId) entityId;
detail = resolved ? service.getResolvedPreferences(namespaceId) : service.getPreferences(namespaceId);
break;
case APPLICATION:
ApplicationId appId = (ApplicationId) entityId;
detail = resolved ? service.getResolvedPreferences(appId) : service.getPreferences(appId);
break;
case PROGRAM:
ProgramId programId = (ProgramId) entityId;
detail = resolved ? service.getResolvedPreferences(programId) : service.getPreferences(programId);
break;
default:
throw new UnsupportedOperationException(String.format("Preferences cannot be used on this entity type: %s", entityId.getEntityType()));
}
return detail;
}
Aggregations