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;
}
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);
}
}
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);
}
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();
}
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);
}
Aggregations