@Override public void unmanage(Location item, ManagementTransitionMode info) { if (isInitialManagementContextReal()) { ((LocationManagerInternal)initialManagementContext.getLocationManager()).unmanage(item, info); } else { throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation"); } }
private void registerLocationResolver() { // Doesn't matter if the resolver is already registered through ServiceLoader. // It just overwrite the existing registration (if any). // TODO Register separate resolvers for each infrastructure instance, unregister on unmanage. LocationRegistry registry = getManagementContext().getLocationRegistry(); DockerResolver dockerResolver = new DockerResolver(); ((BasicLocationRegistry) registry).registerResolver(dockerResolver); if (LOG.isDebugEnabled()) LOG.debug("Explicitly registered docker resolver: " + dockerResolver); }
@Override protected T customReadBody(String type, Map<Object, Object> values, JsonParser jp, DeserializationContext ctxt) throws IOException { Optional<String> entityId = Optional.fromNullable((String) values.get("entityId")); Optional<Entity> entity = Optional.fromNullable(entityId.isPresent() ? null: mgmt.getEntityManager().getEntity(entityId.get())); String id = (String) values.get("id"); return getInstanceFromId(entity, id); } protected Optional<String> getEntityId(T value) {
public static boolean isOsgiCacheForCleaning(ManagementContext mgmt, File cacheDir) { StringConfigMap brooklynProperties = mgmt.getConfig(); Boolean clean = brooklynProperties.getConfig(BrooklynServerConfig.OSGI_CACHE_CLEAN); if (clean==null) { // as per javadoc on key, clean defaults to iff it is a node-id-specific directory clean = cacheDir.getName().contains(mgmt.getManagementNodeId()); } return clean; }
public static boolean isManaged(Location loc) { ManagementContext mgmt = ((LocationInternal)loc).getManagementContext(); return (mgmt != null) && mgmt.isRunning() && mgmt.getLocationManager().isManaged(loc); }
@VisibleForTesting public static void addNamedLocationLocalhost(ManagementContext mgmt) { if (!mgmt.getConfig().getConfig(LocalhostLocationResolver.LOCALHOST_ENABLED)) { throw new IllegalStateException("Localhost is disabled."); } // ensure localhost is added (even on windows, it's just for testing) LocationDefinition l = mgmt.getLocationRegistry().getDefinedLocationByName("localhost"); if (l==null) mgmt.getLocationRegistry().updateDefinedLocation( BasicLocationRegistry.localhost(Identifiers.makeRandomId(8)) ); }
@Override public Void apply(ManagementContext mgmt) { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); SshMachineLocation loc = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); SshMachineLocation loc2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); app.addLocations(ImmutableList.of(loc)); appToKeep.set(app); locToKeep.set(loc); locToDelete.set(loc2); return null; }});
/** @deprecated since 0.7.0 use {@link BrooklynServerPaths#newMainPersistencePathResolver(ManagementContext)} */ @Deprecated public static String getPersistenceDir(ManagementContext mgmt) { return getPersistenceDir(mgmt.getConfig()); } /** @deprecated since 0.7.0 use {@link BrooklynServerPaths#newMainPersistencePathResolver(ManagementContext)} */
@Beta public Iterable<RegisteredType> uninstallCatalogItemsFromBundle(VersionedName bundle) { List<RegisteredType> thingsFromHere = ImmutableList.copyOf(getTypesFromBundle( bundle )); log.debug("Uninstalling items from bundle "+bundle+": "+thingsFromHere); for (RegisteredType t: thingsFromHere) { mgmt.getCatalog().deleteCatalogItem(t.getSymbolicName(), t.getVersion()); } return thingsFromHere; }
public static BrooklynMementoRawData newStateMemento(ManagementContext mgmt, MementoCopyMode source) { switch (source) { case LOCAL: return newStateMementoFromLocal(mgmt); case REMOTE: return mgmt.getRebindManager().retrieveMementoRawData(); case AUTO: throw new IllegalStateException("Copy mode AUTO not supported here"); } throw new IllegalStateException("Should not come here, unknown mode "+source); }
@SuppressWarnings({ "rawtypes" }) private void assertAdded(String symbolicName, String expectedJavaType) { RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION); assertEquals(item.getSymbolicName(), symbolicName); Assert.assertTrue(RegisteredTypes.isSubtypeOf(item, Location.class), "Expected Location, not "+item.getSuperTypes()); assertEquals(countCatalogLocations(), 1); // Item added to catalog should automatically be available in location registry LocationDefinition def = mgmt().getLocationRegistry().getDefinedLocationByName(symbolicName); assertEquals(def.getName(), symbolicName); LocationSpec spec = mgmt().getTypeRegistry().createSpec(item, null, LocationSpec.class); assertEquals(spec.getType().getName(), expectedJavaType); }
@Override protected Task<?> customReadBody(String type, Map<Object, Object> values, JsonParser jp, DeserializationContext ctxt) throws IOException { return mgmt.getExecutionManager().getTask((String) values.get("id")); } }
@Override public Collection<Application> get() { return mgmt.getApplications(); } }
@Test(groups={"Integration", "WIP", "Broken"}) public void testJavaWebWithMemberSpecRebind() throws Exception { Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("test-java-web-app-spec-and-db-with-function.yaml")); AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); final Application app = (Application) mgmt().getEntityManager().getEntity(assembly.getId()); Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app); for (Task<?> t: tasks) t.blockUntilEnded(); Entities.dumpInfo(app); Application app2 = rebind(app); Assert.assertEquals(app2.getChildren().size(), 2); }
@Override public void onManagementStopped() { super.onManagementStopped(); if (getManagementContext().isRunning()) { recordApplicationEvent(Lifecycle.DESTROYED); } }
@SuppressWarnings("deprecation") static RegisteredType addCatalogItemWithNameAndType(ManagementContext mgmt, String symName, String version, String type, String ...libraries) { OsgiTestBase.preinstallLibrariesLowLevelToPreventCatalogBomParsing(mgmt, libraries); CatalogEntityItemDto c1 = newCatalogItemWithNameAndType(symName, version, type, libraries); mgmt.getCatalog().addItem(c1); RegisteredType c2 = mgmt.getTypeRegistry().get(symName, version); Preconditions.checkNotNull(c2, "Item "+type+":"+version+" was not found after adding it"); return c2; }
@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()); }
@Override public boolean isUp() { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SERVER_STATUS, null)) throw WebResourceUtils.forbidden("User '%s' is not authorized for this operation", Entitlements.getEntitlementContext().user()); Maybe<ManagementContext> mm = mgmtMaybe(); return !mm.isAbsent() && mm.get().isStartupComplete() && mm.get().isRunning(); }
@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(); }
/** Returns a string describing the problem if mgmt is null or not running; returns absent if no problems */ public static Maybe<String> getProblemMessageIfServerNotRunning(ManagementContext mgmt) { if (mgmt==null) return Maybe.of("no management context available"); if (!mgmt.isRunning()) return Maybe.of("server no longer running"); if (!mgmt.isStartupComplete()) return Maybe.of("server not in required startup-completed state"); return Maybe.absent(); }