public ClassLoader getCatalogClassLoader() { return mgmt.getCatalogClassLoader(); }
public BrooklynMementoPersisterToObjectStore(PersistenceObjectStore objectStore, ManagementContext mgmt) { this(objectStore, mgmt, mgmt.getCatalogClassLoader()); }
private ClassLoader getClassLoader() { if (loader != null) return loader; if (mgmt!=null) return mgmt.getCatalogClassLoader(); return JavaBrooklynClassLoadingContext.class.getClassLoader(); }
public UrlsExternalConfigSupplier(ManagementContext managementContext, String name, Map<String, String> config) throws IOException { super(managementContext, name); this.config = config; resourceUtils = ResourceUtils.create( managementContext.getCatalogClassLoader(), this, UrlsExternalConfigSupplier.class.getSimpleName()+"("+getName()+")"); Map<String, String> missing = Maps.newLinkedHashMap(); for (Map.Entry<String, String> entry : config.entrySet()) { String target = entry.getValue(); if (!resourceUtils.doesUrlExist(target)) { missing.put(entry.getKey(), entry.getValue()); } } if (missing.size() > 0) { throw new IllegalStateException("URLs for external config '"+getName()+"' not found: "+missing); } }
protected void findServices() { Iterable<LocationResolver> loader = FrameworkLookup.lookupAll(LocationResolver.class, mgmt.getCatalogClassLoader()); MutableList<LocationResolver> loadedResolvers; try { loadedResolvers = MutableList.copyOf(loader); } catch (Throwable e) { log.warn("Error loading resolvers (rethrowing): "+e); throw Exceptions.propagate(e); } for (LocationResolver r: loadedResolvers) { registerResolver(r); } if (log.isDebugEnabled()) log.debug("Location resolvers are: "+resolvers); if (resolvers.isEmpty()) log.warn("No location resolvers detected: is src/main/resources correctly included?"); }
public static void writeManagerMemento(ManagementContext managementContext, ManagementPlaneSyncRecord optionalPlaneRecord, PersistenceObjectStore destinationObjectStore) { if (optionalPlaneRecord != null) { ManagementPlaneSyncRecordPersisterToObjectStore managementPersister = new ManagementPlaneSyncRecordPersisterToObjectStore( managementContext, destinationObjectStore, managementContext.getCatalogClassLoader()); try { managementPersister.checkpoint(optionalPlaneRecord); } finally { managementPersister.stop(); } } }
private void startPersistenceWithoutHA() { RebindManager rebindManager = managementContext.getRebindManager(); if (Strings.isNonBlank(persistenceLocation)) LOG.info("Management node (no HA) rebinding to entities at "+persistenceLocation+" in "+persistenceDir); else LOG.info("Management node (no HA) rebinding to entities on file system in "+persistenceDir); ClassLoader classLoader = managementContext.getCatalogClassLoader(); try { rebindManager.rebind(classLoader, null, ManagementNodeState.MASTER); } catch (Exception e) { Exceptions.propagateIfFatal(e); LOG.debug("Error rebinding to persisted state (rethrowing): "+e, e); throw new FatalRuntimeException("Error rebinding to persisted state: "+ Exceptions.collapseText(e), e); } rebindManager.startPersistence(); }
@Test public void testRenamedOsgiClassMovedBundle() throws Exception { String bundlePath = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH; String bundleUrl = "classpath:" + bundlePath; String classname = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_OBJECT; TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), bundlePath); mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build(); Bundle bundle = installBundle(mgmt, bundleUrl); String oldBundlePrefix = "com.old.symbolicname"; String bundlePrefix = bundle.getSymbolicName(); Class<?> osgiObjectClazz = bundle.loadClass(classname); Object obj = Reflections.invokeConstructorFromArgs(osgiObjectClazz, "myval").get(); serializer = new XmlMementoSerializer<Object>(mgmt.getCatalogClassLoader(), ImmutableMap.of(oldBundlePrefix + ":" + classname, bundlePrefix + ":" + classname)); serializer.setLookupContext(newEmptyLookupManagementContext(mgmt, true)); // i.e. prepended with bundle name String serializedForm = Joiner.on("\n").join( "<"+bundlePrefix+":"+classname+">", " <val>myval</val>", "</"+bundlePrefix+":"+classname+">"); runRenamed(serializedForm, obj, ImmutableMap.<String, String>of( bundlePrefix + ":" + classname, oldBundlePrefix + ":" + classname)); }
@Test public void testRenamedOsgiClassWithoutBundlePrefixInRename() throws Exception { String bundlePath = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH; String bundleUrl = "classpath:" + bundlePath; String classname = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_OBJECT; String oldClassname = "com.old.package.name.OldClassName"; TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), bundlePath); mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build(); Bundle bundle = installBundle(mgmt, bundleUrl); String bundlePrefix = bundle.getSymbolicName(); Class<?> osgiObjectClazz = bundle.loadClass(classname); Object obj = Reflections.invokeConstructorFromArgs(osgiObjectClazz, "myval").get(); serializer = new XmlMementoSerializer<Object>(mgmt.getCatalogClassLoader(), ImmutableMap.of(oldClassname, classname)); serializer.setLookupContext(newEmptyLookupManagementContext(mgmt, true)); // i.e. prepended with bundle name String serializedForm = Joiner.on("\n").join( "<"+bundlePrefix+":"+classname+">", " <val>myval</val>", "</"+bundlePrefix+":"+classname+">"); runRenamed(serializedForm, obj, ImmutableMap.<String, String>of( bundlePrefix + ":" + classname, bundlePrefix + ":" + oldClassname)); }
@Test public void testNoRenameOsgiClass() throws Exception { String bundlePath = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH; String bundleUrl = "classpath:" + bundlePath; String classname = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_OBJECT; TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), bundlePath); mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build(); Bundle bundle = installBundle(mgmt, bundleUrl); String bundlePrefix = bundle.getSymbolicName(); Class<?> osgiObjectClazz = bundle.loadClass(classname); Object obj = Reflections.invokeConstructorFromArgs(osgiObjectClazz, "myval").get(); serializer = new XmlMementoSerializer<Object>(mgmt.getCatalogClassLoader(), ImmutableMap.<String,String>of()); serializer.setLookupContext(newEmptyLookupManagementContext(mgmt, true)); // i.e. prepended with bundle name String serializedForm = Joiner.on("\n").join( "<"+bundlePrefix+":"+classname+">", " <val>myval</val>", "</"+bundlePrefix+":"+classname+">"); runRenamed(serializedForm, obj, ImmutableMap.<String, String>of()); }
new ManagementPlaneSyncRecordPersisterToObjectStore(managementContext, objectStore, managementContext.getCatalogClassLoader()); ((HighAvailabilityManagerImpl)haManager).setHeartbeatTimeout(haHeartbeatTimeoutOverride); ((HighAvailabilityManagerImpl)haManager).setPollPeriod(haHeartbeatPeriodOverride);
cls = dispatcher.tryLoadFrom(mgmt.getCatalogClassLoader(), className); if (cls.isPresent()) { return cls;