public Collection<? extends OsgiBundleWithUrl> getBundles() { if (_bundles!=null || !hasBundles) return _bundles; RegisteredType item = mgmt.getTypeRegistry().get(catalogItemId); if (item==null) { throw new IllegalStateException("Catalog item not found for "+catalogItemId+"; cannot create loading context"); } _bundles = item.getLibraries(); return _bundles; }
@SuppressWarnings("unchecked") public static EntitySpec<? extends Application> createEntitySpecForApplication(ManagementContext mgmt, final String plan) { return mgmt.getTypeRegistry().createSpecFromPlan(null, plan, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class); }
@Override @Deprecated public CatalogItem<?,?> getCatalogItem(String symbolicName, String version) { CatalogItem<?,?> legacy = getCatalogItemLegacy(symbolicName, version); if (legacy!=null) return legacy; RegisteredType rt = mgmt.getTypeRegistry().get(symbolicName, version); if (rt!=null) return RegisteredTypes.toPartialCatalogItem(rt); return null; } @Override @Deprecated
@Override public Map<String, LocationDefinition> getDefinedLocations(boolean includeThingsWeAreFacadeFor) { Map<String, LocationDefinition> result = MutableMap.of(); synchronized (definedLocations) { result.putAll(definedLocations); } for (RegisteredType rt: mgmt.getTypeRegistry().getMatching(RegisteredTypePredicates.IS_LOCATION)) { result.put(rt.getId(), newDefinedLocation(rt)); } return result; }
@Override public LocationSpec<? extends Location> newLocationSpecFromString(String spec, Map<?, ?> locationFlags, LocationRegistry registry) { String id = spec.substring(NAME.length()+1); RegisteredType item = managementContext.getTypeRegistry().get(id); if (item.isDisabled()) { throw new IllegalStateException("Illegal use of disabled catalog item "+item.getSymbolicName()+":"+item.getVersion()); } else if (item.isDeprecated()) { log.warn("Use of deprecated catalog item "+item.getSymbolicName()+":"+item.getVersion()); } LocationSpec<?> origLocSpec = managementContext.getTypeRegistry().createSpec(item, null, LocationSpec.class); return LocationSpec.create(origLocSpec).configure(locationFlags); }
@Override protected boolean canResolve(String type, BrooklynClassLoadingContext loader) { String localType = getLocalType(type); RegisteredType item = mgmt.getTypeRegistry().get(localType); if (item==null) return false; //Keeps behaviour of previous functionality, but caller might be interested if item is disabled if (item.isDisabled()) return false; return true; }
public static boolean isBestVersion(ManagementContext mgmt, RegisteredType item) { if (item==null) return false; Iterable<RegisteredType> matches = mgmt.getTypeRegistry().getMatching( RegisteredTypePredicates.symbolicName(item.getSymbolicName()) ); if (!matches.iterator().hasNext()) return false; RegisteredType best = RegisteredTypes.getBestVersion(matches); return (best.getVersion().equals(item.getVersion())); }
public static boolean isBestVersion(ManagementContext mgmt, CatalogItem<?,?> item) { RegisteredType best = RegisteredTypes.getBestVersion(mgmt.getTypeRegistry().getMatching( RegisteredTypePredicates.symbolicName(item.getSymbolicName()))); if (best==null) return false; return (best.getVersion().equals(item.getVersion())); }
@Override @BeforeMethod(alwaysRun = true) public void setUp() throws Exception { super.setUp(); types = mgmt().getTypeRegistry(); }
@Test public void testAddCatalogItemTopLevelLegacySyntax() throws Exception { assertEquals(countCatalogPolicies(), 0); String symbolicName = "my.catalog.policy.id.load"; addCatalogPolicyLegacySyntax(symbolicName, POLICY_TYPE); RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION); assertEquals(item.getSymbolicName(), symbolicName); assertEquals(countCatalogPolicies(), 1); deleteCatalogEntity(symbolicName); }
@Test public void testAddOsgiCatalogItem() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); String symbolicName = "my.catalog.app.id.load"; addCatalogOSGiEntity(symbolicName); RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION); assertEquals(item.getSymbolicName(), symbolicName); deleteCatalogEntity(symbolicName); }
private void assertHasBasic1() { RegisteredType basic1T = mgmt().getTypeRegistry().get("basic1"); Asserts.assertNotNull(basic1T, "basic1 not in catalog"); }
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.getId(), symbolicName+":"+TEST_VERSION); assertEquals(def.getName(), symbolicName); LocationSpec<?> spec = mgmt().getTypeRegistry().createSpec(item, null, LocationSpec.class); assertEquals(spec.getType().getName(), expectedJavaType); }
@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); }
@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; }
public static String getIconUrl(BrooklynObject object) { if (object==null) return null; NamedStringTag fromTag = BrooklynTags.findFirst(BrooklynTags.ICON_URL, object.tags().getTags()); if (fromTag!=null) return fromTag.getContents(); ManagementContext mgmt = ((BrooklynObjectInternal)object).getManagementContext(); if (mgmt==null) return null; BrooklynTypeRegistry registry = mgmt.getTypeRegistry(); if (registry==null) return null; RegisteredType item = registry.get( object.getCatalogItemId() ); if (item==null) return null; return item.getIconUrl(); }
@Override public Response getIcon(String itemId, String version) { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_CATALOG_ITEM, itemId+(Strings.isBlank(version)?"":":"+version))) { throw WebResourceUtils.forbidden("User '%s' is not authorized to see catalog entry", Entitlements.getEntitlementContext().user()); } version = processVersion(version); return getCatalogItemIcon(mgmt().getTypeRegistry().get(itemId, version)); }
@AfterMethod(alwaysRun=true) @Override public void tearDown() throws Exception { try { for (RegisteredType ci : mgmt().getTypeRegistry().getMatching(RegisteredTypePredicates.IS_LOCATION)) { mgmt().getCatalog().deleteCatalogItem(ci.getSymbolicName(), ci.getVersion()); } } finally { super.tearDown(); } }
protected Entity createAndStartApplication(String input, Map<String,?> startParameters) throws Exception { EntitySpec<?> spec = mgmt().getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT, input, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class); final Entity app = mgmt().getEntityManager().createEntity(spec); getLogger().info("Test created app, and will now start " + app); // start the app (happens automatically if we use camp to instantiate, but not if we use crate spec approach) app.invoke(Startable.START, startParameters).get(); return app; }
@Test public void testEntitySpecFromOsgi() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V1_PATH); mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build(); RegisteredType ci = OsgiVersionMoreEntityTest.addMoreEntityV1(mgmt, "1.0"); EntitySpec<DynamicCluster> spec = EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.INITIAL_SIZE, 1) .configure(DynamicCluster.MEMBER_SPEC, mgmt.getTypeRegistry().createSpec(ci, null, EntitySpec.class)); serializer.setLookupContext(newEmptyLookupManagementContext(mgmt, true)); assertSerializeAndDeserialize(spec); }