@Override public boolean apply(Entity entity) { if (entity==null) return false; return (entity.getEntityType().getName().matches(typeRegex)); } });
@Override public boolean apply(@Nullable Entity input) { return input.getEntityType().getName().equalsIgnoreCase(entity.getEntityType().getName()) || input.getEntityType().getSimpleName().equalsIgnoreCase(entity.getEntityType().getSimpleName()); } };
@Override public boolean apply(@Nullable Entity input) { return input.getEntityType().getName().equalsIgnoreCase(parameter) || input.getEntityType().getSimpleName().equalsIgnoreCase(parameter); } };
@Override protected <T> ConfigKey<?> getKeyAtContainerImpl(Entity container, ConfigKey<T> queryKey) { if (queryKey==null) return null; return container.getEntityType().getConfigKey(queryKey.getName()); }
/** @return provisioning flags for the given entity */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected Map<String,Object> obtainProvisioningFlags(Entity entity, MachineProvisioningLocation location) { Map<String,Object> result = Maps.newLinkedHashMap(); result.putAll(Maps.newLinkedHashMap(location.getProvisioningFlags(ImmutableList.of(entity.getEntityType().getName())))); result.putAll(entity.getConfig(SameServerEntity.PROVISIONING_PROPERTIES)); for (Entity child : entity.getChildren()) { result.putAll(obtainProvisioningFlags(child, location)); } return result; }
private ConfigKey<?> findConfig(Entity entity, String configKeyName) { ConfigKey<?> ck = entity.getEntityType().getConfigKey(configKeyName); if (ck == null) ck = new BasicConfigKey<Object>(Object.class, configKeyName); return ck; }
public static void apply(Entity entity) { for (Sensor<?> it : entity.getEntityType().getSensors()) { if (it instanceof AttributeSensorAndConfigKey) { apply(entity, (AttributeSensorAndConfigKey<?,?>)it); } } }
@Override Iterable<ConfigKey<?>> getBrooklynObjectTypeConfigKeys() { return getBrooklynObject().getEntityType().getConfigKeys(); } }
@SuppressWarnings("unchecked") @Override public ConfigKey<T> apply(Entity entity) { return entity!=null ? (ConfigKey<T>)elvis(entity.getEntityType().getConfigKey(queryKey.getName()), defaultValue) : defaultValue; } }
protected ConfigKey<?> findKey(Entity entity, String keyName) { ConfigKey<?> key = entity.getEntityType().getConfigKey(keyName); assertNotNull(key, "No key '"+keyName+"'; keys="+entity.getEntityType().getConfigKeys()); return key; } }
/** Checks if the SDN provider is of the specified type. */ public static final boolean isSdnProvider(Entity entity, String providerName) { if (entity.config().get(SdnAttributes.SDN_ENABLE)) { Entity sdn = entity.sensors().get(SdnAttributes.SDN_PROVIDER); if (sdn == null) return false; return sdn.getEntityType().getSimpleName().equalsIgnoreCase(providerName); } else return false; }
private void checkChildEntitySpec(Entity app, String entityName) { Collection<Entity> children = app.getChildren(); Assert.assertEquals(children.size(), 1); Entity child = Iterables.getOnlyElement(children); Assert.assertEquals(child.getDisplayName(), entityName); Assert.assertEquals(child.getEntityType().getName(), BasicEntity.class.getName()); } }
@Override public AttributeSensor apply(final String input) { Entity entity = BrooklynTaskTags.getContextEntity(Tasks.current()); if (entity!=null) { Sensor<?> result = entity.getEntityType().getSensor(input); if (result instanceof AttributeSensor) return (AttributeSensor) result; } return Sensors.newSensor(Object.class, input); } });
@Test public void testReferenceAppYamlAsPlatformComponent() throws Exception { Entity app = createAndStartApplication( "services:", "- name: Reference child name", " type: classpath://yaml-ref-app.yaml"); Assert.assertEquals(app.getChildren().size(), 0); Assert.assertEquals(app.getDisplayName(), "Reference child name"); //child is a proxy so equality test won't do Assert.assertEquals(app.getEntityType().getName(), BasicApplication.class.getName()); }
protected <T> void assertKeyEquals(Entity entity, String keyName, String expectedDescription, Class<T> expectedType, T expectedDefaultVal, T expectedEntityVal) { ConfigKey<?> key = entity.getEntityType().getConfigKey(keyName); assertNotNull(key, "No key '"+keyName+"'; keys="+entity.getEntityType().getConfigKeys()); assertEquals(key.getName(), keyName); assertEquals(key.getDescription(), expectedDescription); assertEquals(key.getType(), expectedType); assertEquals(key.getDefaultValue(), expectedDefaultVal); assertEquals(entity.config().get(key), expectedEntityVal); }
@Test public void testLaunchApplicationUnversionedCatalogReference() throws Exception { String symbolicName = "myitem"; addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName()); Entity app = createAndStartApplication( "services:", "- type: "+symbolicName); Entity entity = Iterables.getOnlyElement(app.getChildren()); assertEquals(entity.getEntityType().getName(), TestEntity.class.getName()); deleteCatalogEntity(symbolicName); }
@Test public void testLaunchApplicationReferencingCatalog() throws Exception { String symbolicName = "myitem"; addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName()); Entity app = createAndStartApplication( "services:", "- type: "+ver(symbolicName, TEST_VERSION)); Entity entity = Iterables.getOnlyElement(app.getChildren()); assertEquals(entity.getEntityType().getName(), TestEntity.class.getName()); deleteCatalogEntity(symbolicName); }
private void registerAndLaunchAndAssertSimpleEntity(String symbolicName, String serviceType) throws Exception { addCatalogOSGiEntity(symbolicName, serviceType); String yaml = "name: simple-app-yaml\n" + "location: localhost\n" + "services: \n" + " - serviceType: "+ver(symbolicName); Entity app = createAndStartApplication(yaml); Entity simpleEntity = Iterables.getOnlyElement(app.getChildren()); assertEquals(simpleEntity.getEntityType().getName(), SIMPLE_ENTITY_TYPE); deleteCatalogEntity(symbolicName); }
protected static Effector<?> assertHasInitializers(Entity entity, String effectorName) { Maybe<Effector<?>> effectorMaybe = entity.getEntityType().getEffectorByName(effectorName); assertFalse(effectorMaybe.isAbsent()); return effectorMaybe.get(); }
protected static Effector<?> assertHasInitializers(Entity entity, String effectorName) { Maybe<Effector<?>> effectorMaybe = entity.getEntityType().getEffectorByName(effectorName); assertFalse(effectorMaybe.isAbsent()); return effectorMaybe.get(); }