use of io.cdap.cdap.common.ApplicationNotFoundException 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.common.ApplicationNotFoundException in project cdap by caskdata.
the class AppLifecycleHttpHandler method listAppVersions.
/**
* Returns the list of versions of the application.
*/
@GET
@Path("/apps/{app-id}/versions")
public void listAppVersions(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") final String namespaceId, @PathParam("app-id") final String appId) throws Exception {
ApplicationId applicationId = validateApplicationId(namespaceId, appId);
Collection<String> versions = applicationLifecycleService.getAppVersions(namespaceId, appId);
if (versions.isEmpty()) {
throw new ApplicationNotFoundException(applicationId);
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(versions));
}
use of io.cdap.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class CapabilityApplier method shouldDeployApp.
// Returns true if capability applier should try to deploy this application. 2 conditions when it returns true:
// 1. Either the application is not deployed before.
// 2. If application is deployed before then the app artifact of the deployed application is not the latest one
// available.
private boolean shouldDeployApp(ApplicationId applicationId, SystemApplication application) throws Exception {
ApplicationDetail currAppDetail;
try {
currAppDetail = applicationLifecycleService.getAppDetail(applicationId);
} catch (ApplicationNotFoundException exception) {
return true;
}
// Compare if the app artifact version of currently deployed application with highest version of app artifact
// available. If it's not same, capability applier should redeploy application.
ArtifactSummary summary = application.getArtifact();
NamespaceId artifactNamespace = ArtifactScope.SYSTEM.equals(summary.getScope()) ? NamespaceId.SYSTEM : applicationId.getParent();
ArtifactRange range = new ArtifactRange(artifactNamespace.getNamespace(), summary.getName(), ArtifactVersionRange.parse(summary.getVersion()));
// this method will not throw ArtifactNotFoundException, if no artifacts in the range, we are expecting an empty
// collection returned.
List<ArtifactDetail> artifactDetail = artifactRepository.getArtifactDetails(range, 1, ArtifactSortOrder.DESC);
if (artifactDetail.isEmpty()) {
throw new ArtifactNotFoundException(range.getNamespace(), range.getName());
}
ArtifactId latestArtifactId = artifactDetail.get(0).getDescriptor().getArtifactId();
// same artifact. If same means no need to deploy the application again.
return !currAppDetail.getArtifact().getVersion().equals(latestArtifactId.getVersion().getVersion());
}
use of io.cdap.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class ApplicationLifecycleService method getAppDetail.
/**
* Get detail about the specified application
*
* @param appId the id of the application to get
* @return detail about the specified application
* @throws ApplicationNotFoundException if the specified application does not exist
*/
public ApplicationDetail getAppDetail(ApplicationId appId) throws Exception {
// TODO: CDAP-12473: filter based on the entity visibility in the app detail
// user needs to pass the visibility check to get the app detail
accessEnforcer.enforce(appId, authenticationContext.getPrincipal(), StandardPermission.GET);
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
String ownerPrincipal = ownerAdmin.getOwnerPrincipal(appId);
return enforceApplicationDetailAccess(appId, ApplicationDetail.fromSpec(appSpec, ownerPrincipal));
}
use of io.cdap.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class PreferencesClientTestRun method testPreferences.
@Test
public void testPreferences() throws Exception {
NamespaceId invalidNamespace = new NamespaceId("invalid");
namespaceClient.create(new NamespaceMeta.Builder().setName(invalidNamespace).build());
Map<String, String> propMap = client.getInstancePreferences();
Assert.assertEquals(ImmutableMap.<String, String>of(), propMap);
propMap.put("k1", "instance");
client.setInstancePreferences(propMap);
Assert.assertEquals(propMap, client.getInstancePreferences());
File jarFile = createAppJarFile(FakeApp.class);
appClient.deploy(NamespaceId.DEFAULT, jarFile);
try {
propMap.put("k1", "namespace");
client.setNamespacePreferences(NamespaceId.DEFAULT, propMap);
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, false));
Assert.assertTrue(client.getNamespacePreferences(invalidNamespace, false).isEmpty());
Assert.assertEquals("instance", client.getNamespacePreferences(invalidNamespace, true).get("k1"));
client.deleteNamespacePreferences(NamespaceId.DEFAULT);
propMap.put("k1", "instance");
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(ImmutableMap.<String, String>of(), client.getNamespacePreferences(NamespaceId.DEFAULT, false));
propMap.put("k1", "namespace");
client.setNamespacePreferences(NamespaceId.DEFAULT, propMap);
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, false));
propMap.put("k1", "application");
client.setApplicationPreferences(FAKE_APP_ID, propMap);
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, false));
propMap.put("k1", "program");
ServiceId service = FAKE_APP_ID.service(FakeApp.SERVICES.get(0));
client.setProgramPreferences(service, propMap);
Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
Assert.assertEquals(propMap, client.getProgramPreferences(service, false));
client.deleteProgramPreferences(service);
propMap.put("k1", "application");
Assert.assertTrue(client.getProgramPreferences(service, false).isEmpty());
Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
client.deleteApplicationPreferences(FAKE_APP_ID);
propMap.put("k1", "namespace");
Assert.assertTrue(client.getApplicationPreferences(FAKE_APP_ID, false).isEmpty());
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
client.deleteNamespacePreferences(NamespaceId.DEFAULT);
propMap.put("k1", "instance");
Assert.assertTrue(client.getNamespacePreferences(NamespaceId.DEFAULT, false).isEmpty());
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
client.deleteInstancePreferences();
propMap.clear();
Assert.assertEquals(propMap, client.getInstancePreferences());
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
// Test Deleting Application
propMap.put("k1", "application");
client.setApplicationPreferences(FAKE_APP_ID, propMap);
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, false));
propMap.put("k1", "program");
client.setProgramPreferences(service, propMap);
Assert.assertEquals(propMap, client.getProgramPreferences(service, false));
appClient.delete(FAKE_APP_ID);
// deleting the app should have deleted the preferences that were stored. so deploy the app and check
// if the preferences are empty. we need to deploy the app again since getting preferences of non-existent apps
// is not allowed by the API.
appClient.deploy(NamespaceId.DEFAULT, jarFile);
propMap.clear();
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, false));
Assert.assertEquals(propMap, client.getProgramPreferences(service, false));
} finally {
try {
appClient.delete(FAKE_APP_ID);
} catch (ApplicationNotFoundException e) {
// ok if this happens, means its already deleted.
}
namespaceClient.delete(invalidNamespace);
}
}
Aggregations