/** * @deprecated since 0.7.0; only used for legacy brooklyn types where constructor is called * directly */ @Override @Deprecated @SuppressWarnings({"unchecked", "rawtypes"}) public AbstractEntityAdjunct configure(Map flags) { // TODO only set on first time through boolean isFirstTime = true; // allow config keys, and fields, to be set from these flags if they have a SetFromFlag // annotation // or if the value is a config key for (Iterator<Map.Entry> iter = flags.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = iter.next(); if (entry.getKey() instanceof ConfigKey) { ConfigKey key = (ConfigKey) entry.getKey(); if (adjunctType.getConfigKeys().contains(key)) { setConfig(key, entry.getValue()); } else { log.warn("Unknown configuration key {} for policy {}; ignoring", key, this); iter.remove(); } } } ConfigBag bag = new ConfigBag().putAll(flags); FlagUtils.setFieldsFromFlags(this, bag, isFirstTime); FlagUtils.setAllConfigKeys(this, bag, false); leftoverProperties.putAll(bag.getUnusedConfig()); // replace properties _contents_ with leftovers so subclasses see leftovers only flags.clear(); flags.putAll(leftoverProperties); leftoverProperties = flags; if (!truth(name) && flags.containsKey("displayName")) { // TODO inconsistent with entity and location, where name is legacy and displayName is // encouraged! // 'displayName' is a legacy way to refer to a policy's name Preconditions.checkArgument( flags.get("displayName") instanceof CharSequence, "'displayName' property should be a string"); setDisplayName(flags.remove("displayName").toString()); } // set leftover flags should as config items; particularly useful when these have come from a // brooklyn.config map for (Object flag : flags.keySet()) { ConfigKey<Object> key = ConfigKeys.newConfigKey(Object.class, Strings.toString(flag)); if (config().getRaw(key).isPresent()) { log.warn("Config '" + flag + "' on " + this + " conflicts with key already set; ignoring"); } else { config().set(key, flags.get(flag)); } } return this; }
/** * Given an enricher, extracts its state for serialization. * * @deprecated since 0.7.0, see {@link #newBasicMemento(BrooklynObject)} */ @Deprecated public static EnricherMemento newEnricherMemento(Enricher enricher) { BasicEnricherMemento.Builder builder = BasicEnricherMemento.builder(); populateBrooklynObjectMementoBuilder(enricher, builder); // TODO persist config keys as well? Or only support those defined on policy class; // current code will lose the ConfigKey type on rebind for anything not defined on class. // Whereas entities support that. // TODO Do we need the "nonPersistableFlagNames" that locations use? Map<ConfigKey<?>, Object> config = ((AbstractEnricher) enricher).getConfigMap().getAllConfig(); for (Map.Entry<ConfigKey<?>, Object> entry : config.entrySet()) { ConfigKey<?> key = checkNotNull(entry.getKey(), "config=%s", config); Object value = configValueToPersistable(entry.getValue()); builder.config.put(key.getName(), value); } Map<String, Object> persistableFlags = MutableMap.<String, Object>builder() .putAll( FlagUtils.getFieldsWithFlagsExcludingModifiers( enricher, Modifier.STATIC ^ Modifier.TRANSIENT)) .remove("id") .remove("name") .build(); builder.config.putAll(persistableFlags); return builder.build(); }
/** @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; }
public AbstractEntityAdjunct(@SuppressWarnings("rawtypes") Map properties) { super(properties); _legacyNoConstructionInit = (properties != null) && Boolean.TRUE.equals(properties.get("noConstructionInit")); if (isLegacyConstruction()) { AbstractBrooklynObject checkWeGetThis = configure(properties); assert this.equals(checkWeGetThis) : this + " configure method does not return itself; returns " + checkWeGetThis + " instead of " + this; boolean deferConstructionChecks = (properties.containsKey("deferConstructionChecks") && TypeCoercions.coerce(properties.get("deferConstructionChecks"), Boolean.class)); if (!deferConstructionChecks) { FlagUtils.checkRequiredFields(this); } } }
@Override protected AbstractBrooklynObject configure(Map<?, ?> flags) { FlagUtils.setFieldsFromFlags(flags, this); return this; }