@Override public Collection<Application> get() { return mgmt.getApplications(); } }
private boolean hasStoppableApps(ManagementContext mgmt) { for (Application app : mgmt.getApplications()) { if (app instanceof StartableApplication) { Lifecycle state = app.getAttribute(Attributes.SERVICE_STATE_ACTUAL); if (state != Lifecycle.STOPPING && state != Lifecycle.STOPPED) { log.warn("Shutting down, expecting all apps to be in stopping state, but found application " + app + " to be in state " + state + ". Just started?"); } return true; } } return false; }
public Map<Location, Integer> countLeafEntitiesByLocatedLocations() { Map<Location, Integer> result = new LinkedHashMap<Location, Integer>(); for (Entity e: context.getApplications()) { countLeafEntitiesByLocatedLocations(e, null, result); } return result; }
private void assertNoApps(ManagementContext managementContext) { if (!managementContext.getApplications().isEmpty()) log.warn("FAILED assertion (rethrowing), apps="+managementContext.getApplications()); assertTrue(managementContext.getApplications().isEmpty(), "apps="+managementContext.getApplications()); }
private void assertOnlyApp(ManagementContext managementContext, Class<? extends Application> expectedType) { assertEquals(managementContext.getApplications().size(), 1, "apps="+managementContext.getApplications()); assertNotNull(Iterables.find(managementContext.getApplications(), Predicates.instanceOf(TestApplication.class), null), "apps="+managementContext.getApplications()); }
protected void assertOnlyApp(ManagementContext managementContext, Class<? extends Application> expectedType) { assertEquals(managementContext.getApplications().size(), 1, "apps="+managementContext.getApplications()); assertNotNull(Iterables.find(managementContext.getApplications(), Predicates.instanceOf(TestApplication.class), null), "apps="+managementContext.getApplications()); }
@Override public Boolean call() throws Exception { return l.getManagementContext().getApplications().size() == 3; } }).limitTimeTo(Duration.TEN_SECONDS).runRequiringTrue();
@Override public List<ApplicationSummary> list(String typeRegex) { if (Strings.isBlank(typeRegex)) { typeRegex = ".*"; } return FluentIterable .from(mgmt().getApplications()) .filter(EntitlementPredicates.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY)) .filter(EntityPredicates.hasInterfaceMatching(typeRegex)) .transform(ApplicationTransformer.fromApplication(ui.getBaseUriBuilder())) .toList(); }
@AfterClass(alwaysRun = true) public void tearDown() throws Exception { for (Application app : getManagementContext().getApplications()) { try { ((StartableApplication) app).stop(); } catch (Exception e) { log.warn("Error stopping app " + app + " during test teardown: " + e); } } }
@Test public void testUnentitledDeploy() throws Exception { final Set<Application> initialApps = ImmutableSet.copyOf(mgmt.getApplications()); final String bp = "services:\n- type: " + StartRecordingEntity.class.getName(); StaticDelegatingEntitlementManager.setDelegate(new InvokeEffector(false)); httpPost("myCustom", "/v1/applications", bp.getBytes(), ImmutableMap.of("Content-Type", "text/yaml")); // Check the app wasn't started Sets.SetView<Application> afterApps = Sets.difference(ImmutableSet.copyOf(mgmt.getApplications()), initialApps); assertEquals(afterApps.size(), 1, "expected one element: " + afterApps); Application newApp = afterApps.iterator().next(); assertFalse(newApp.sensors().get(Attributes.SERVICE_UP)); assertFalse(INDICATOR.get()); }
@Test(groups = "Integration") public void testDeployRedisApplication() throws Exception { Response response = api.getApplicationApi().createPoly(redisSpec.getBytes()); assertEquals(response.getStatus(), 201); assertEquals(getManagementContext().getApplications().size(), 1); final String entityId = getManagementContext().getApplications().iterator().next().getChildren().iterator().next().getId(); assertServiceStateEventually("redis-app", entityId, Lifecycle.RUNNING, LONG_WAIT); }
@Test(groups = "Integration", dependsOnMethods = {"testListSensorsRedis", "testListEntities"}) public void testTriggerRedisStopEffector() throws Exception { final String entityId = getManagementContext().getApplications().iterator().next().getChildren().iterator().next().getId(); Response response = api.getEffectorApi().invoke("redis-app", entityId, "stop", "5000", ImmutableMap.<String, Object>of()); assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); assertServiceStateEventually("redis-app", entityId, Lifecycle.STOPPED, LONG_WAIT); }
@Test(groups = "Integration", dependsOnMethods = "testDeployRedisApplication") public void testListSensorsRedis() throws Exception { String entityId = getManagementContext().getApplications().iterator().next().getChildren().iterator().next().getId(); Collection<SensorSummary> sensors = api.getSensorApi().list("redis-app", entityId); assertTrue(sensors.size() > 0); SensorSummary uptime = Iterables.find(sensors, new Predicate<SensorSummary>() { @Override public boolean apply(SensorSummary sensorSummary) { return sensorSummary.getName().equals("redis.uptime"); } }); assertEquals(uptime.getType(), "java.lang.Integer"); }
@Test public void testRebindWhenPreviousAppDestroyedHasNoApp() throws Exception { origApp.stop(); RebindTestUtils.waitForPersisted(origManagementContext); newManagementContext = RebindTestUtils.newPersistingManagementContextUnstarted(mementoDir, classLoader); List<Application> newApps = newManagementContext.getRebindManager().rebind(classLoader, null, ManagementNodeState.MASTER); newManagementContext.getRebindManager().startPersistence(); assertEquals(newApps.size(), 0, "apps="+newApps); assertEquals(newManagementContext.getApplications().size(), 0, "apps="+newManagementContext.getApplications()); }
@Test public void testCleanDoesNotRebindToExistingApp() throws Exception { EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class); populatePersistenceDir(persistenceDir, appSpec); // Auto will rebind if the dir exists newLauncherDefault(PersistMode.CLEAN).start(); assertTrue(lastMgmt().getApplications().isEmpty(), "apps="+lastMgmt().getApplications()); }
@AfterClass(alwaysRun = true) public void tearDown() throws Exception { for (Application app : getManagementContext().getApplications()) { try { ((StartableApplication) app).stop(); } catch (Exception e) { log.warn("Error stopping app " + app + " during test teardown: " + e); } } Entities.destroyAll(getManagementContext()); server.stop(); }
@Test public void testRebindsToExistingApp() throws Exception { populatePersistenceDir(persistenceDir, EntitySpec.create(TestApplication.class).displayName("myorig")); // Rebind to the app we just started last time newLauncherDefault(PersistMode.REBIND).start(); assertOnlyApp(lastMgmt(), TestApplication.class); assertNotNull(Iterables.find(lastMgmt().getApplications(), EntityPredicates.displayNameEqualTo("myorig"), null), "apps="+lastMgmt().getApplications()); }
@Test public void testRebindCanAddNewApps() throws Exception { populatePersistenceDir(persistenceDir, EntitySpec.create(TestApplication.class).displayName("myorig")); // Rebind to the app we started last time newLauncherDefault(PersistMode.REBIND) .application(EntitySpec.create(TestApplication.class).displayName("mynew")) .start(); // New app was added, and orig app was rebound assertEquals(lastMgmt().getApplications().size(), 2, "apps="+lastMgmt().getApplications()); assertNotNull(Iterables.find(lastMgmt().getApplications(), EntityPredicates.displayNameEqualTo("mynew"), null), "apps="+lastMgmt().getApplications()); // And subsequently can create new apps StartableApplication app3 = lastMgmt().getEntityManager().createEntity( EntitySpec.create(TestApplication.class).displayName("mynew2")); app3.start(ImmutableList.<Location>of()); }
@AfterMethod(alwaysRun = true) public void cleanUpButKeepMgmt() throws Exception { for (Application app: MutableList.copyOf(mgmt().getApplications())) { Entities.destroy(app); } for (Bundle b: bundlesToRemove) { ((ManagementContextInternal)mgmt()).getOsgiManager().get().uninstallUploadedBundle( ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundle(new VersionedName(b))); } bundlesToRemove.clear(); }
protected Application rebind(RebindOptions options) throws Exception { ManagementContext origMgmt = mgmt; ManagementContext newMgmt = createNewManagementContext(); Collection<Application> origApps = origMgmt.getApplications(); options = RebindOptions.create(options); if (options.classLoader == null) options.classLoader(classLoader); if (options.mementoDir == null) options.mementoDir(mementoDir); if (options.origManagementContext == null) options.origManagementContext(origMgmt); if (options.newManagementContext == null) options.newManagementContext(newMgmt); for (Application origApp : origApps) { RebindTestUtils.stopPersistence(origApp); } mgmt = options.newManagementContext; Application newApp = RebindTestUtils.rebind(options); return newApp; }