/** * Walks the contents of a ManagementContext, to create a corresponding memento. * * @deprecated since 0.7.0; will be moved to test code; generate each entity/location memento * separately */ @Deprecated public static BrooklynMemento newBrooklynMemento(ManagementContext managementContext) { BrooklynMementoImpl.Builder builder = BrooklynMementoImpl.builder(); for (Application app : managementContext.getApplications()) { builder.applicationIds.add(app.getId()); } for (Entity entity : managementContext.getEntityManager().getEntities()) { builder.entities.put( entity.getId(), ((EntityInternal) entity).getRebindSupport().getMemento()); for (Location location : entity.getLocations()) { if (!builder.locations.containsKey(location.getId())) { for (Location locationInHierarchy : TreeUtils.findLocationsInHierarchy(location)) { if (!builder.locations.containsKey(locationInHierarchy.getId())) { builder.locations.put( locationInHierarchy.getId(), ((LocationInternal) locationInHierarchy).getRebindSupport().getMemento()); } } } } } for (LocationMemento memento : builder.locations.values()) { if (memento.getParent() == null) { builder.topLevelLocationIds.add(memento.getId()); } } BrooklynMemento result = builder.build(); MementoValidators.validateMemento(result); return result; }
/** @deprecated since 0.7.0; use {@link #newBasicMemento(BrooklynObject)} instead */ @Deprecated public static BasicLocationMemento.Builder newLocationMementoBuilder(Location location) { BasicLocationMemento.Builder builder = BasicLocationMemento.builder(); populateBrooklynObjectMementoBuilder(location, builder); Set<String> nonPersistableFlagNames = MutableMap.<String, Object>builder() .putAll(FlagUtils.getFieldsWithFlagsWithModifiers(location, Modifier.TRANSIENT)) .putAll(FlagUtils.getFieldsWithFlagsWithModifiers(location, Modifier.STATIC)) .put("id", String.class) .filterValues(Predicates.not(Predicates.instanceOf(ConfigKey.class))) .build() .keySet(); Map<String, Object> persistableFlags = MutableMap.<String, Object>builder() .putAll( FlagUtils.getFieldsWithFlagsExcludingModifiers( location, Modifier.STATIC ^ Modifier.TRANSIENT)) .removeAll(nonPersistableFlagNames) .build(); ConfigBag persistableConfig = new ConfigBag() .copy(((LocationInternal) location).config().getLocalBag()) .removeAll(nonPersistableFlagNames); builder.copyConfig(persistableConfig); builder.locationConfig.putAll(persistableFlags); Location parentLocation = location.getParent(); builder.parent = (parentLocation != null) ? parentLocation.getId() : null; for (Location child : location.getChildren()) { builder.children.add(child.getId()); } return builder; }
private void assertNotOwned(Location loc) { NamedStringTag ownerEntityTag = BrooklynTags.findFirst(BrooklynTags.OWNER_ENTITY_ID, loc.tags().getTags()); Assert.assertNull(ownerEntityTag); }
private void assertOwned(BasicApplication app, Location loc) { NamedStringTag ownerEntityTag = BrooklynTags.findFirst(BrooklynTags.OWNER_ENTITY_ID, loc.tags().getTags()); Assert.assertNotNull(ownerEntityTag); Assert.assertEquals(ownerEntityTag.getContents(), app.getId()); }
/** @deprecated since 0.7.0; use {@link #newBasicMemento(BrooklynObject)} instead */ @Deprecated public static BasicEntityMemento.Builder newEntityMementoBuilder(Entity entityRaw) { EntityInternal entity = (EntityInternal) entityRaw; BasicEntityMemento.Builder builder = BasicEntityMemento.builder(); populateBrooklynObjectMementoBuilder(entity, builder); EntityDynamicType definedType = BrooklynTypes.getDefinedEntityType(entity.getClass()); // TODO the dynamic attributeKeys and configKeys are computed in the BasicEntityMemento // whereas effectors are computed here -- should be consistent! // (probably best to compute attrKeys and configKeys here) builder.effectors.addAll(entity.getEntityType().getEffectors()); builder.effectors.removeAll(definedType.getEffectors().values()); builder.isTopLevelApp = (entity instanceof Application && entity.getParent() == null); Map<ConfigKey<?>, Object> localConfig = entity.getConfigMap().getLocalConfig(); for (Map.Entry<ConfigKey<?>, Object> entry : localConfig.entrySet()) { ConfigKey<?> key = checkNotNull(entry.getKey(), localConfig); Object value = configValueToPersistable(entry.getValue()); builder.config.put(key, value); } Map<String, Object> localConfigUnmatched = MutableMap.copyOf(entity.getConfigMap().getLocalConfigBag().getAllConfig()); for (ConfigKey<?> key : localConfig.keySet()) { localConfigUnmatched.remove(key.getName()); } for (Map.Entry<String, Object> entry : localConfigUnmatched.entrySet()) { String key = checkNotNull(entry.getKey(), localConfig); Object value = entry.getValue(); // TODO Not transforming; that code is deleted in another pending PR anyway! builder.configUnmatched.put(key, value); } @SuppressWarnings("rawtypes") Map<AttributeSensor, Object> allAttributes = entity.getAllAttributes(); for (@SuppressWarnings("rawtypes") Map.Entry<AttributeSensor, Object> entry : allAttributes.entrySet()) { AttributeSensor<?> key = checkNotNull(entry.getKey(), allAttributes); if (key.getPersistenceMode() != SensorPersistenceMode.NONE) { Object value = entry.getValue(); builder.attributes.put((AttributeSensor<?>) key, value); } } for (Location location : entity.getLocations()) { builder.locations.add(location.getId()); } for (Entity child : entity.getChildren()) { builder.children.add(child.getId()); } for (Policy policy : entity.getPolicies()) { builder.policies.add(policy.getId()); } for (Enricher enricher : entity.getEnrichers()) { builder.enrichers.add(enricher.getId()); } for (Feed feed : entity.feeds().getFeeds()) { builder.feeds.add(feed.getId()); } Entity parentEntity = entity.getParent(); builder.parent = (parentEntity != null) ? parentEntity.getId() : null; if (entity instanceof Group) { for (Entity member : ((Group) entity).getMembers()) { builder.members.add(member.getId()); } } return builder; }