ApplicationResource extends AbstractBrooklynRestResource implements ApplicationApi { @Override public Response delete(String application) { Application app = brooklyn().getApplication(application); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.INVOKE_EFFECTOR, Entitlements.EntityAndItem.of(app, StringAndArgument.of(Entitlements.LifecycleEffectors.DELETE, null)))) { throw WebResourceUtils.forbidden("User '%s' is not authorized to delete application %s", Entitlements.getEntitlementContext().user(), app); } Task<?> t = brooklyn().destroy(app); TaskSummary ts = TaskTransformer.fromTask(ui.getBaseUriBuilder()).apply(t); return status(ACCEPTED).entity(ts).build(); }  @Override List<EntityDetail> fetch(String entityIds, String extraSensorsS); @Override List<EntitySummary> details(String entityIds, boolean includeAllApps, String extraSensorsGlobsS, String extraConfigGlobsS, int depth); @Override List<ApplicationSummary> list(String typeRegex); @Override ApplicationSummary get(String application); @Override Response createFromYaml(String yaml); @Override Response createFromYamlWithAppId(String yaml, String appId); @Override Response createPoly(byte[] inputToAutodetectType); @Override Response createFromForm(String contents); @Override Response delete(String application); @Override List<EntitySummary> getDescendants(String application, String typeRegex); @Override Map<String, Object> getDescendantsSensor(String application, String sensor, String typeRegex); static Map<String, Object> getSensorMap(String sensor, Iterable<Entity> descs);  }
@Test(dependsOnMethods = {"testListEffectors", "testFetchApplicationsAndEntity", "testApplicationDetailsAndEntity", "testTriggerSampleEffector", "testListApplications","testReadEachSensor","testPolicyWhichCapitalizes","testLocatedLocation"}) public void testDeleteApplication() throws TimeoutException, InterruptedException { waitForPageFoundResponse("/applications/simple-app", ApplicationSummary.class); Collection<Application> apps = getManagementContext().getApplications(); log.info("Deleting simple-app from " + apps); int size = apps.size(); Response response = client().path("/applications/simple-app") .delete(); assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); TaskSummary task = response.readEntity(TaskSummary.class); assertTrue(task.getDescription().toLowerCase().contains("destroy"), task.getDescription()); assertTrue(task.getDescription().toLowerCase().contains("simple-app"), task.getDescription()); waitForPageNotFoundResponse("/applications/simple-app", ApplicationSummary.class); log.info("App appears gone, apps are: " + getManagementContext().getApplications()); Asserts.eventually( EntityFunctions.applications(getManagementContext()), Predicates.compose(Predicates.equalTo(size-1), CollectionFunctionals.sizeFunction()) ); }
@Test public void testDisabledApplicationCatalog() throws TimeoutException, InterruptedException { String itemSymbolicName = "my.catalog.item.id.for.disabling"; String itemVersion = "1.0"; String serviceType = "org.apache.brooklyn.entity.stock.BasicApplication"; CatalogItemSummary itemSummary = testTemplateItem(itemSymbolicName, itemVersion, serviceType); String itemVersionedId = String.format("%s:%s", itemSummary.getSymbolicName(), itemSummary.getVersion()); assertEquals(itemSummary.getId(), itemVersionedId); try { String yaml = "{ name: my-app, location: localhost, services: [ { type: \""+itemVersionedId+"\" } ] }"; Response response = client().path("/applications") .post(Entity.entity(yaml, "application/x-yaml")); HttpAsserts.assertHealthyStatusCode(response.getStatus()); waitForPageFoundResponse("/applications/my-app", ApplicationSummary.class); deprecateCatalogItem(itemSymbolicName, itemVersion, true); String yaml2 = "{ name: my-app2, location: localhost, services: [ { type: \""+itemVersionedId+"\" } ] }"; Response response2 = client().path("/applications") .post(Entity.entity(yaml2, "application/x-yaml")); HttpAsserts.assertHealthyStatusCode(response2.getStatus()); waitForPageFoundResponse("/applications/my-app2", ApplicationSummary.class); disableCatalogItem(itemSymbolicName, itemVersion, true); String yaml3 = "{ name: my-app3, location: localhost, services: [ { type: \""+itemVersionedId+"\" } ] }"; Response response3 = client().path("/applications") .post(Entity.entity(yaml3, "application/x-yaml")); HttpAsserts.assertClientErrorStatusCode(response3.getStatus()); assertTrue(response3.readEntity(String.class).toLowerCase().contains("unable to match")); waitForPageNotFoundResponse("/applications/my-app3", ApplicationSummary.class); } finally { client().path("/applications/my-app") .delete(); client().path("/applications/my-app2") .delete(); client().path("/applications/my-app3") .delete(); client().path("/catalog/entities/"+itemVersionedId+"/"+itemVersion) .delete(); } }