public static void addCatalogItemsAsOsgiInUsualWay(ManagementContext mgmt, String catalogYaml, VersionedName bundleName, boolean force) { try { BundleMaker bundleMaker = new BundleMaker(mgmt); File bf = bundleMaker.createTempZip("test", MutableMap.of( new ZipEntry(BasicBrooklynCatalog.CATALOG_BOM), new ByteArrayInputStream(catalogYaml.getBytes()))); if (bundleName!=null) { bf = bundleMaker.copyAddingManifest(bf, MutableMap.of( "Manifest-Version", "2.0", Constants.BUNDLE_SYMBOLICNAME, bundleName.getSymbolicName(), Constants.BUNDLE_VERSION, bundleName.getOsgiVersion().toString())); } ReferenceWithError<OsgiBundleInstallationResult> b = ((ManagementContextInternal)mgmt).getOsgiManager().get().install( new FileInputStream(bf) ); b.checkNoError(); } catch (Exception e) { throw Exceptions.propagate(e); } }
public static void addCatalogItemsAsOsgiWithoutStartingBundles(ManagementContext mgmt, String catalogYaml, VersionedName bundleName, boolean force) { try { BundleMaker bundleMaker = new BundleMaker(mgmt); File bf = bundleMaker.createTempZip("test", MutableMap.of( new ZipEntry(BasicBrooklynCatalog.CATALOG_BOM), new ByteArrayInputStream(catalogYaml.getBytes()))); ReferenceWithError<OsgiBundleInstallationResult> b = ((ManagementContextInternal)mgmt).getOsgiManager().get().installDeferredStart( new BasicManagedBundle(bundleName.getSymbolicName(), bundleName.getVersionString(), null), new FileInputStream(bf), false); // bundle not started (no need, and can break), and BOM not installed nor validated above; // do BOM install and validation below manually to test the type registry approach // but skipping the rollback / uninstall mgmt.getCatalog().addTypesFromBundleBom(catalogYaml, b.get().getMetadata(), force, null); Map<RegisteredType, Collection<Throwable>> validation = mgmt.getCatalog().validateTypes( mgmt.getTypeRegistry().getMatching(RegisteredTypePredicates.containingBundle(b.get().getVersionedName())) ); if (!validation.isEmpty()) { throw Exceptions.propagate("Brooklyn failed to load types (in tests, skipping rollback): "+validation.keySet(), Iterables.concat(validation.values())); } } catch (Exception e) { throw Exceptions.propagate(e); } }