CatalogResource extends AbstractBrooklynRestResource implements CatalogApi { @Override @Deprecated public Response create(String yaml, boolean forceUpdate) { return createFromYaml(yaml, forceUpdate); }  @Override @Beta Response createFromUpload(byte[] item, boolean forceUpdate); @Override @Deprecated Response create(String yaml, boolean forceUpdate); @SuppressWarnings("deprecation") @Override Response createFromYaml(String yaml, boolean forceUpdate); @Override @Beta Response createFromArchive(byte[] zipInput, boolean detail, boolean forceUpdate); @Override @Deprecated void deleteApplication(String symbolicName, String version); @Override @Deprecated void deleteEntity(String symbolicName, String version); @Override @Deprecated void deletePolicy(String policyId, String version); @Override @Deprecated void deleteLocation(String locationId, String version); @Override @Deprecated List<CatalogEntitySummary> listEntities(String regex, String fragment, boolean allVersions); @Override @Deprecated List<CatalogItemSummary> listApplications(String regex, String fragment, boolean allVersions); @Override @Deprecated CatalogEntitySummary getEntity(String symbolicName, String version); @Override @Deprecated CatalogEntitySummary getApplication(String symbolicName, String version); @Override @Deprecated List<CatalogPolicySummary> listPolicies(String regex, String fragment, boolean allVersions); @Override @Deprecated CatalogPolicySummary getPolicy(String policyId, String version); @Override @Deprecated List<CatalogLocationSummary> listLocations(String regex, String fragment, boolean allVersions); @Override @Deprecated CatalogLocationSummary getLocation(String locationId, String version); @Override Response getIcon(String itemId, String version); @Override @Deprecated void setDeprecated(String itemId, boolean deprecated); @Override @Deprecated void setDisabled(String itemId, boolean disabled); @Override @Deprecated List<CatalogEnricherSummary> listEnrichers(@ApiParam(name = "regex", value = "Regular expression to search for") @DefaultValue("") String regex, @ApiParam(name = "fragment", value = "Substring case-insensitive to search for") @DefaultValue("") String fragment, @ApiParam(name = "allVersions", value = "Include all versions (defaults false, only returning the best version)") @DefaultValue("false") boolean includeAllVersions); @Override @Deprecated CatalogEnricherSummary getEnricher(@ApiParam(name = "enricherId", value = "The ID of the enricher to retrieve", required = true) String enricherId, @ApiParam(name = "version", value = "The version identifier of the enricher to retrieve", required = true) String version); @Override @Deprecated void deleteEnricher(@ApiParam(name = "enricherId", value = "The ID of the enricher to delete", required = true) String enricherId, @ApiParam(name = "version", value = "The version identifier of the enricher to delete", required = true) String version);  }
@Test public void testGetCatalogEntityIconDetails() throws IOException { String catalogItemId = "testGetCatalogEntityIconDetails"; addTestCatalogItemAsEntity(catalogItemId); Response response = client().path(URI.create("/catalog/icon/" + catalogItemId + "/" + TEST_VERSION)) .get(); response.bufferEntity(); Assert.assertEquals(response.getStatus(), 200); Assert.assertEquals(response.getMediaType(), MediaType.valueOf("image/png")); Image image = Toolkit.getDefaultToolkit().createImage(Files.readFile(response.readEntity(InputStream.class))); Assert.assertNotNull(image); }
@Test public void testOsgiBundleWithBom() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); final String bundleSymbolicName = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FULL; final String version = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_VERSION; final String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; final String itemSymbolicName = "my-entity"; BundleMaker bm = new BundleMaker(manager); File f = Os.newTempFile("osgi", "jar"); Files.copyFile(ResourceUtils.create(this).getResourceFromUrl(bundleUrl), f); String bom = Joiner.on("\n").join( "brooklyn.catalog:", " bundle: " + bundleSymbolicName, " version: " + version, " id: " + itemSymbolicName, " itemType: entity", " name: My Catalog App", " description: My description", " icon_url: classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif", " item:", " type: org.apache.brooklyn.core.test.entity.TestEntity"); f = bm.copyAdding(f, MutableMap.of(new ZipEntry("catalog.bom"), (InputStream) new ByteArrayInputStream(bom.getBytes()))); Response response = client().path("/catalog") .header(HttpHeaders.CONTENT_TYPE, "application/x-jar") .post(Streams.readFully(new FileInputStream(f))); assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); CatalogSummaryAsserts.newInstance(CatalogItemType.ENTITY, itemSymbolicName, version) .planYamlPredicate(StringPredicates.containsLiteral("org.apache.brooklyn.core.test.entity.TestEntity")) .name("My Catalog App") .description("My description") .expectedInterfaces(Reflections.getAllInterfaces(TestEntity.class)) .iconData((data) -> {assertEquals(data.length, 43); return true;}) .applyAsserts(() -> client()); RegisteredTypeAsserts.newInstance(itemSymbolicName, version) .libraryNames(new VersionedName(bundleSymbolicName, version)) .libraryUrls((String)null) .iconUrl("classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif") .applyAsserts(getManagementContext().getTypeRegistry()); }
@Test public void testOsgiBundleWithBomNotInBrooklynNamespace() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH); final String bundleSymbolicName = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_SYMBOLIC_NAME_FULL; final String version = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_VERSION; final String bundleUrl = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_URL; final String entityType = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_ENTITY; final String iconPath = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_ICON_PATH; final String itemSymbolicName = "my-item"; BundleMaker bm = new BundleMaker(manager); File f = Os.newTempFile("osgi", "jar"); Files.copyFile(ResourceUtils.create(this).getResourceFromUrl(bundleUrl), f); String bom = Joiner.on("\n").join( "brooklyn.catalog:", " bundle: " + bundleSymbolicName, " version: " + version, " id: " + itemSymbolicName, " itemType: entity", " name: My Catalog App", " description: My description", " icon_url: classpath:" + iconPath, " item:", " type: " + entityType); f = bm.copyAdding(f, MutableMap.of(new ZipEntry("catalog.bom"), (InputStream) new ByteArrayInputStream(bom.getBytes()))); Response response = client().path("/catalog") .header(HttpHeaders.CONTENT_TYPE, "application/x-zip") .post(Streams.readFully(new FileInputStream(f))); assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); CatalogSummaryAsserts.newInstance(CatalogItemType.ENTITY, itemSymbolicName, version) .planYamlPredicate(StringPredicates.containsLiteral(entityType)) .name("My Catalog App") .description("My description") .expectedInterfaces(ImmutableList.of(Entity.class, BrooklynObject.class, Identifiable.class, Configurable.class)) .iconData((data) -> {assertEquals(data.length, 43); return true;}) .applyAsserts(() -> client()); RegisteredTypeAsserts.newInstance(itemSymbolicName, version) .libraryNames(new VersionedName(bundleSymbolicName, version)) .libraryUrls((String)null) .iconUrl("classpath:"+iconPath) .applyAsserts(getManagementContext().getTypeRegistry()); String appYaml = Joiner.on("\n").join( "services:", "- type: " + itemSymbolicName + ":" + version, " name: myEntityName"); Response appResponse = client().path("/applications") .header(HttpHeaders.CONTENT_TYPE, "application/x-yaml") .post(appYaml); assertEquals(appResponse.getStatus(), Response.Status.CREATED.getStatusCode()); Entity entity = Iterables.tryFind(getManagementContext().getEntityManager().getEntities(), EntityPredicates.displayNameEqualTo("myEntityName")).get(); assertEquals(entity.getEntityType().getName(), entityType); }