private void discoverManifestFromCatalogBom(boolean isCatalogBomRequired) { discoveredManifest = new BundleMaker(mgmt()).getManifest(zipFile); ZipFile zf = null; try {
File zf2 = new BundleMaker(mgmt()).copyAddingManifest(zipFile, discoveredManifest); zipFile.delete(); zipFile = zf2;
private String copyResourcePathToTempPath(String resourcePath) { BundleMaker bm = new BundleMaker(ResourceUtils.create(this)); bm.setDefaultClassForLoading(CleanOrphanedLocationsIntegrationTest.class); File jar = bm.createJarFromClasspathDir(resourcePath); File output = Os.newTempDir("brooklyn-test-resouce-from-"+resourcePath); try { ArchiveUtils.extractZip(new ZipFile(jar), output.getAbsolutePath()); return output.getAbsolutePath(); } catch (Exception e) { throw Exceptions.propagate(e); } }
mf.getMainAttributes().putValue(BROOKLYN_WRAPPED_BOM_BUNDLE, Boolean.TRUE.toString()); BundleMaker bm = new BundleMaker(mgmt); File bf = bm.createTempBundle(vn.getSymbolicName(), mf, MutableMap.of( new ZipEntry(CATALOG_BOM), (InputStream) new ByteArrayInputStream(yaml.getBytes())) );
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build(); super.setUp(); bundleMaker = new BundleMaker(mgmt); emptyJar = createEmptyJarFile(); }
@BeforeClass(alwaysRun = true) public void setUp() throws Exception { super.setUp(); bm = new BundleMaker( ((LocalManagementContext)mgmt()).getOsgiManager().get().getFramework(), ResourceUtils.create(this) ); }
static void installJavaScanningMoreEntitiesV2(ManagementContext mgmt, Object context) throws FileNotFoundException { // scanning bundle functionality added in 0.12.0, relatively new compared to non-osgi scanning TestResourceUnavailableException.throwIfResourceUnavailable(context.getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH); TestResourceUnavailableException.throwIfResourceUnavailable(context.getClass(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH); CampYamlLiteTest.installWithoutCatalogBom(mgmt, OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH); BundleMaker bm = new BundleMaker(mgmt); File f = Os.newTempFile(context.getClass(), "jar"); Streams.copy(ResourceUtils.create(context).getResourceFromUrl(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH), new FileOutputStream(f)); f = bm.copyRemoving(f, MutableSet.of("catalog.bom")); f = bm.copyAdding(f, MutableMap.of(new ZipEntry("catalog.bom"), new ByteArrayInputStream( Strings.lines( "brooklyn.catalog:", " scanJavaAnnotations: true").getBytes() ) )); ((ManagementContextInternal)mgmt).getOsgiManager().get().install(new FileInputStream(f)).checkNoError(); }
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); } }