Search in sources :

Example 36 with ApplicationDetail

use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.

the class LocalApplicationDetailFetcher method list.

/**
 * Get a list of {@link ApplicationDetail} for all applications in the given namespace
 *
 * @param namespace the name of the namespace to get the list of applications
 * @return a list of {@link ApplicationDetail} for all applications in the given namespace
 * @throws IOException if failed to get the list of {@link ApplicationDetail}
 * @throws NamespaceNotFoundException if the given namespace doesn't exit
 */
@Override
public List<ApplicationDetail> list(String namespace) throws IOException, NamespaceNotFoundException {
    NamespaceId namespaceId = new NamespaceId(namespace);
    List<ApplicationDetail> detailList = Collections.emptyList();
    try {
        // the existence of the namespace. Does a check here to explicitly throw an exception if nonexistent.
        if (!namespaceQueryAdmin.exists(namespaceId)) {
            throw new NamespaceNotFoundException(namespaceId);
        }
        detailList = applicationLifecycleService.getApps(namespaceId);
    } catch (Exception e) {
        Throwables.propagateIfPossible(e, NamespaceNotFoundException.class, IOException.class);
        throw new IOException(e);
    }
    return detailList;
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) IOException(java.io.IOException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) IOException(java.io.IOException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException)

Example 37 with ApplicationDetail

use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.

the class CapabilityApplierTest method testGetAppsWithCapability.

@Test
public void testGetAppsWithCapability() throws Exception {
    // Deploy application with capability
    Class<CapabilityAppWithWorkflow> appWithWorkflowClass = CapabilityAppWithWorkflow.class;
    Requirements declaredAnnotation = appWithWorkflowClass.getDeclaredAnnotation(Requirements.class);
    // verify this app has capabilities
    Assert.assertTrue(declaredAnnotation.capabilities().length > 0);
    String appNameWithCapabilities = appWithWorkflowClass.getSimpleName() + UUID.randomUUID();
    for (String capability : declaredAnnotation.capabilities()) {
        CapabilityConfig capabilityConfig = new CapabilityConfig("Enable", CapabilityStatus.ENABLED, capability, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
        capabilityWriter.addOrUpdateCapability(capability, CapabilityStatus.ENABLED, capabilityConfig);
    }
    deployArtifactAndApp(appWithWorkflowClass, appNameWithCapabilities);
    // Deploy application without capability
    Class<WorkflowAppWithFork> appNoCapabilityClass = WorkflowAppWithFork.class;
    Requirements declaredAnnotation1 = appNoCapabilityClass.getDeclaredAnnotation(Requirements.class);
    // verify this app has no capabilities
    Assert.assertNull(declaredAnnotation1);
    String appNameWithoutCapability = appNoCapabilityClass.getSimpleName() + UUID.randomUUID();
    deployArtifactAndApp(appNoCapabilityClass, appNameWithoutCapability);
    // verify that list applications return the application tagged with capability only
    for (String capability : declaredAnnotation.capabilities()) {
        EntityResult<ApplicationId> appsForCapability = capabilityApplier.getApplications(NamespaceId.DEFAULT, capability, null, 0, 10);
        Set<ApplicationId> applicationIds = new HashSet<>(appsForCapability.getEntities());
        List<ApplicationDetail> appsReturned = new ArrayList<>(applicationLifecycleService.getAppDetails(applicationIds).values());
        appsReturned.forEach(applicationDetail -> Assert.assertEquals(appNameWithCapabilities, applicationDetail.getArtifact().getName()));
    }
    // delete the app and verify nothing is returned.
    applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithCapabilities, TEST_VERSION));
    for (String capability : declaredAnnotation.capabilities()) {
        Set<ApplicationId> applicationIds = new HashSet<>(capabilityApplier.getApplications(NamespaceId.DEFAULT, capability, null, 0, 10).getEntities());
        List<ApplicationDetail> appsReturned = new ArrayList<>(applicationLifecycleService.getAppDetails(applicationIds).values());
        Assert.assertTrue(appsReturned.isEmpty());
    }
    applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithoutCapability, TEST_VERSION));
    artifactRepository.deleteArtifact(Id.Artifact.from(new Id.Namespace(NamespaceId.DEFAULT.getNamespace()), appNameWithoutCapability, TEST_VERSION));
    for (String capability : declaredAnnotation.capabilities()) {
        capabilityWriter.deleteCapability(capability);
    }
}
Also used : WorkflowAppWithFork(io.cdap.cdap.WorkflowAppWithFork) ArrayList(java.util.ArrayList) Requirements(io.cdap.cdap.api.annotation.Requirements) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) CapabilityAppWithWorkflow(io.cdap.cdap.CapabilityAppWithWorkflow) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with ApplicationDetail

use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.

the class CapabilityManagementServiceTest method reset.

@After
public void reset() throws Exception {
    // Reset all relevant stores.
    for (ApplicationDetail appDetail : applicationLifecycleService.getApps(NamespaceId.SYSTEM)) {
        programLifecycleService.stopAll(new ApplicationId(NamespaceId.SYSTEM.getNamespace(), appDetail.getName(), appDetail.getAppVersion()));
    }
    for (ApplicationDetail appDetail : applicationLifecycleService.getApps(NamespaceId.DEFAULT)) {
        programLifecycleService.stopAll(new ApplicationId(NamespaceId.DEFAULT.getNamespace(), appDetail.getName(), appDetail.getAppVersion()));
    }
    applicationLifecycleService.removeAll(NamespaceId.SYSTEM);
    applicationLifecycleService.removeAll(NamespaceId.DEFAULT);
    artifactRepository.clear(NamespaceId.SYSTEM);
    artifactRepository.clear(NamespaceId.DEFAULT);
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) After(org.junit.After)

Example 39 with ApplicationDetail

use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.

the class ApplicationClient method get.

/**
 * Get details about the specified application.
 *
 * @param appId the id of the application to get
 * @return details about the specified application
 * @throws ApplicationNotFoundException if the application with the given ID was not found
 * @throws IOException if a network error occurred
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public ApplicationDetail get(ApplicationId appId) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
    String path = String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion());
    HttpResponse response = restClient.execute(HttpMethod.GET, config.resolveNamespacedURLV3(appId.getParent(), path), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ApplicationNotFoundException(appId);
    }
    return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject();
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) HttpResponse(io.cdap.common.http.HttpResponse)

Example 40 with ApplicationDetail

use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.

the class ApplicationLifecycleServiceTest method testScanApplications.

@Test
public void testScanApplications() throws Exception {
    createNamespace("ns1");
    createNamespace("ns2");
    createNamespace("ns3");
    deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns1");
    deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns2");
    deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns3");
    List<ApplicationDetail> appDetails = new ArrayList<>();
    applicationLifecycleService.scanApplications(new NamespaceId("ns1"), ImmutableSet.of(), null, d -> appDetails.add(d));
    Assert.assertEquals(appDetails.size(), 1);
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) ArrayList(java.util.ArrayList) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Aggregations

ApplicationDetail (io.cdap.cdap.proto.ApplicationDetail)52 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)30 Test (org.junit.Test)30 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)26 File (java.io.File)20 ArrayList (java.util.ArrayList)20 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)16 HttpResponse (io.cdap.common.http.HttpResponse)16 HashSet (java.util.HashSet)16 Gson (com.google.gson.Gson)14 Constants (io.cdap.cdap.common.conf.Constants)14 ProgramId (io.cdap.cdap.proto.id.ProgramId)14 HashMap (java.util.HashMap)14 List (java.util.List)14 Map (java.util.Map)14 Assert (org.junit.Assert)14 ImmutableMap (com.google.common.collect.ImmutableMap)12 ImmutableSet (com.google.common.collect.ImmutableSet)12 RunRecord (io.cdap.cdap.proto.RunRecord)12 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)12