io.cloudsoft.tosca.a4c.brooklyn.spec.ConfigKeyModifier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brooklyn-tosca-transformer Show documentation
Show all versions of brooklyn-tosca-transformer Show documentation
TOSCA support for Brooklyn plans leveraging Alien4Cloud
The newest version!
package io.cloudsoft.tosca.a4c.brooklyn.spec;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.core.flags.FlagUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
import com.google.common.reflect.TypeToken;
import io.cloudsoft.tosca.a4c.brooklyn.ToscaApplication;
import io.cloudsoft.tosca.a4c.brooklyn.ToscaFacade;
public abstract class ConfigKeyModifier extends AbstractSpecModifier {
private static final Logger LOG = LoggerFactory.getLogger(ConfigKeyModifier.class);
public ConfigKeyModifier(ManagementContext mgmt, ToscaFacade extends ToscaApplication> alien4CloudFacade) {
super(mgmt, alien4CloudFacade);
}
protected void configureConfigKeysSpec(EntitySpec spec, ConfigBag bag) {
Set keyNamesUsed = new LinkedHashSet<>();
configureWithAllRecords(findAllFlagsAndConfigKeys(spec, bag), spec, keyNamesUsed);
setUnusedKeysAsAnonymousKeys(spec, keyNamesUsed, bag);
}
private void configureWithAllRecords(Collection records, EntitySpec spec, Set keyNamesUsed){
for (FlagUtils.FlagConfigKeyAndValueRecord r : records) {
if (r.getFlagMaybeValue().isPresent()) {
configureWithResolvedFlag(r, spec, keyNamesUsed);
}
if (r.getConfigKeyMaybeValue().isPresent()) {
configureWithResolvedConfigKey(r, spec, keyNamesUsed);
}
}
}
private void configureWithResolvedFlag(FlagUtils.FlagConfigKeyAndValueRecord r, EntitySpec spec, Set keyNamesUsed){
Optional