Search in sources :

Example 1 with ApplicationNotFoundException

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);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) ProgramType(io.cdap.cdap.proto.ProgramType) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException)

Example 2 with ApplicationNotFoundException

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));
}
Also used : ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with ApplicationNotFoundException

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());
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)

Example 4 with ApplicationNotFoundException

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));
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException)

Example 5 with ApplicationNotFoundException

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);
    }
}
Also used : ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) File(java.io.File) ServiceId(io.cdap.cdap.proto.id.ServiceId) Test(org.junit.Test)

Aggregations

ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)17 HttpResponse (io.cdap.common.http.HttpResponse)8 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)6 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)5 ProgramNotFoundException (io.cdap.cdap.common.ProgramNotFoundException)4 NotFoundException (io.cdap.cdap.common.NotFoundException)3 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)3 ProgramId (io.cdap.cdap.proto.id.ProgramId)3 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)3 HttpRequest (io.cdap.common.http.HttpRequest)3 URL (java.net.URL)3 TypeToken (com.google.common.reflect.TypeToken)2 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)2 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)2 InstanceNotFoundException (io.cdap.cdap.api.dataset.InstanceNotFoundException)2 WorkflowSpecification (io.cdap.cdap.api.workflow.WorkflowSpecification)2 BadRequestException (io.cdap.cdap.common.BadRequestException)2 ApplicationDetail (io.cdap.cdap.proto.ApplicationDetail)2 HashMap (java.util.HashMap)2 GET (javax.ws.rs.GET)2