use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class AppLifecycleHttpHandler method getApplicationDetails.
/**
* Gets {@link ApplicationDetail} for a set of applications. It expects a post body as a array of object, with each
* object specifying the applciation id and an optional version. E.g.
*
* <pre>
* {@code
* [
* {"appId":"XYZ", "version":"1.2.3"},
* {"appId":"ABC"},
* {"appId":"FOO", "version":"2.3.4"},
* ]
* }
* </pre>
* The response will be an array of {@link BatchApplicationDetail} object, which either indicates a success (200) or
* failure for each of the requested application in the same order as the request.
*/
@POST
@Path("/appdetail")
public void getApplicationDetails(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception {
List<ApplicationId> appIds = decodeAndValidateBatchApplication(validateNamespace(namespace), request);
Map<ApplicationId, ApplicationDetail> details = applicationLifecycleService.getAppDetails(appIds);
List<BatchApplicationDetail> result = new ArrayList<>();
for (ApplicationId appId : appIds) {
ApplicationDetail detail = details.get(appId);
if (detail == null) {
result.add(new BatchApplicationDetail(new NotFoundException(appId)));
} else {
result.add(new BatchApplicationDetail(detail));
}
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result));
}
use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class AppLifecycleHttpHandler method deleteApp.
/**
* Delete an application specified by appId.
*/
@DELETE
@Path("/apps/{app-id}")
public void deleteApp(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") final String appId) throws Exception {
ApplicationId id = validateApplicationId(namespaceId, appId);
applicationLifecycleService.removeApplication(id);
responder.sendStatus(HttpResponseStatus.OK);
}
use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class PreferencesTable method ensureSequence.
/**
* Verify that the preferences for the entity id were written with a greater or equal sequence id.
*
* @param entityId the entity id to verify
* @param afterId the sequence id to check
* @throws ConflictException if the latest version of the preferences is older than the given sequence id
*/
public void ensureSequence(EntityId entityId, long afterId) throws IOException, ConflictException {
switch(entityId.getEntityType()) {
case INSTANCE:
checkSeqId(EMPTY_NAMESPACE, INSTANCE_PREFERENCE, entityId.getEntityName(), afterId);
return;
case NAMESPACE:
NamespaceId namespaceId = (NamespaceId) entityId;
checkSeqId(namespaceId.getNamespace(), NAMESPACE_PREFERENCE, namespaceId.getNamespace(), afterId);
return;
case APPLICATION:
ApplicationId appId = (ApplicationId) entityId;
checkSeqId(appId.getNamespace(), APPLICATION_PREFERENCE, appId.getApplication(), afterId);
return;
case PROGRAM:
ProgramId programId = (ProgramId) entityId;
checkSeqId(programId.getNamespace(), PROGRAM_PREFERENCE, getProgramName(programId), afterId);
return;
default:
throw new UnsupportedOperationException(String.format("Preferences cannot be used on this entity type: %s", entityId.getEntityType()));
}
}
use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class AppCreator method execute.
@Override
public void execute(Arguments arguments) throws Exception {
ApplicationId appId = arguments.getId();
ArtifactSummary artifactSummary = arguments.getArtifact();
if (appExists(appId) && !arguments.overwrite) {
return;
}
KerberosPrincipalId ownerPrincipalId = arguments.getOwnerPrincipal() == null ? null : new KerberosPrincipalId(arguments.getOwnerPrincipal());
// if we don't null check, it gets serialized to "null"
String configString = arguments.getConfig() == null ? null : GSON.toJson(arguments.getConfig());
try {
appLifecycleService.deployApp(appId.getParent(), appId.getApplication(), appId.getVersion(), artifactSummary, configString, x -> {
}, ownerPrincipalId, arguments.canUpdateSchedules(), false, Collections.emptyMap());
} catch (NotFoundException | UnauthorizedException | InvalidArtifactException e) {
// up to the default time limit
throw e;
} catch (DatasetManagementException e) {
if (e.getCause() instanceof UnauthorizedException) {
throw (UnauthorizedException) e.getCause();
} else {
throw new RetryableException(e);
}
} catch (Exception e) {
throw new RetryableException(e);
}
}
use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class CapabilityManagementServiceTest method testCapabilityRefresh.
@Test
public void testCapabilityRefresh() throws Exception {
String externalConfigPath = tmpFolder.newFolder("capability-config-refresh").getAbsolutePath();
cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
String appName = AllProgramsApp.NAME;
String programName = AllProgramsApp.NoOpService.NAME;
Class<AllProgramsApp> appClass = AllProgramsApp.class;
String version = "1.0.0";
String namespace = NamespaceId.SYSTEM.getNamespace();
// deploy the artifact
deployTestArtifact(namespace, appName, version, appClass);
ApplicationId applicationId = new ApplicationId(namespace, appName, version);
ProgramId programId = new ProgramId(applicationId, ProgramType.SERVICE, programName);
// check that app is not available
List<JsonObject> appList = getAppList(namespace);
Assert.assertTrue(appList.isEmpty());
// enable the capability
CapabilityConfig config = getTestConfig("1.0.0");
writeConfigAsFile(externalConfigPath, config.getCapability(), config);
capabilityManagementService.runTask();
// app should show up and program should have run
appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
// Capability management service might not yet have deployed application.
// So wait till program exists and is in running state.
waitState(programId, "RUNNING");
assertProgramRuns(programId, ProgramRunStatus.RUNNING, 1);
String capability = config.getCapability();
capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
// disable capability. Program should stop, status should be disabled and app should still be present.
CapabilityConfig disabledConfig = changeConfigStatus(config, CapabilityStatus.DISABLED);
writeConfigAsFile(externalConfigPath, disabledConfig.getCapability(), disabledConfig);
capabilityManagementService.runTask();
assertProgramRuns(programId, ProgramRunStatus.KILLED, 1);
assertProgramRuns(programId, ProgramRunStatus.RUNNING, 0);
try {
capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
Assert.fail("expecting exception");
} catch (CapabilityNotAvailableException ex) {
}
appList = getAppList(namespace);
Assert.assertFalse(appList.isEmpty());
// delete capability. Program should stop, status should be disabled and app should still be present.
new File(externalConfigPath, disabledConfig.getCapability()).delete();
capabilityManagementService.runTask();
Assert.assertTrue(capabilityStatusStore.getConfigs(Collections.singleton(capability)).isEmpty());
appList = getAppList(namespace);
Assert.assertTrue(appList.isEmpty());
}
Aggregations