private void resolveFeature(ConfigModelStack configStack, FeatureConfig fc) throws ProvisioningException { final FeaturePackRuntimeBuilder originalOrigin = currentOrigin; final ResolvedFeatureSpec spec = getFeatureSpec(fc.getSpecId().getName(), true); final ResolvedFeature originalParent = parentFeature; try { final ResolvedFeatureId resolvedId = parentFeature == null ? spec.resolveFeatureId(fc.getParams()) : spec.resolveIdFromForeignKey(parentFeature.id, fc.getParentRef(), fc.getParams()); if (configStack.isFilteredOut(spec.id, resolvedId)) { return; } parentFeature = resolveFeatureDepsAndRefs(configStack, spec, resolvedId, spec.resolveNonIdParams(parentFeature == null ? null : parentFeature.id, fc.getParentRef(), fc.getParams()), fc.getFeatureDeps()); if (fc.hasUnsetParams()) { parentFeature.unsetAllParams(fc.getUnsetParams(), true); } if (fc.hasResetParams()) { parentFeature.resetAllParams(fc.getResetParams()); } } finally { currentOrigin = originalOrigin; } processConfigItemContainer(fc); parentFeature = originalParent; }
public static FeatureConfig newConfig(FeatureId id) throws ProvisioningDescriptionException { final FeatureConfig config = new FeatureConfig(id.getSpec()); for(Map.Entry<String, String> param : id.getParams().entrySet()) { config.setParam(param.getKey(), param.getValue()); } return config; }
public FeatureConfig addFeatureDep(FeatureId featureId) throws ProvisioningDescriptionException { return addFeatureDep(FeatureDependencySpec.create(featureId)); }
private Map<ResolvedFeatureId, FeatureConfig> resolveIncludedIds(Map<ResolvedFeatureId, FeatureConfig> includedFeatures, Map<FeatureId, FeatureConfig> features) throws ProvisioningException { for (Map.Entry<FeatureId, FeatureConfig> included : features.entrySet()) { final FeatureConfig fc = new FeatureConfig(included.getValue()); final ResolvedFeatureSpec resolvedSpec = getFeatureSpec(fc.getSpecId().getName()); if (parentFeature != null) { includedFeatures = CollectionUtils.put(includedFeatures, resolvedSpec.resolveIdFromForeignKey(parentFeature.id, fc.getParentRef(), fc.getParams()), fc); } else { includedFeatures = CollectionUtils.put(includedFeatures, resolvedSpec.resolveFeatureId(fc.getParams()), fc); } } return includedFeatures; }
case SPEC: try { config.setSpecName(reader.getAttributeValue(i)); } catch (ProvisioningDescriptionException e) { throw new XMLStreamException("Failed to parse config", e); config.setParentRef(reader.getAttributeValue(i)); break; default: if (config.getSpecId() == null) { throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.SPEC)); break; case FEATURE: final FeatureConfig child = new FeatureConfig(); readFeatureConfig(reader, child); config.addFeature(child); break; case FEATURE_GROUP: config.addFeatureGroup(readFeatureGroupDependency(null, reader)); break; case ORIGIN: break; case RESET_PARAM: config.resetParam(readParamAttr(reader)); break; case UNSET_PARAM:
private static void addFeatureConfigBody(ElementNode fcE, FeatureId id, FeatureConfig fc, String ns) { if(fc.hasFeatureDeps()) { for(FeatureDependencySpec depSpec : fc.getFeatureDeps()) { final ElementNode depE = addElement(fcE, Element.DEPENDS.getLocalName(), ns); if(depSpec.getOrigin() != null) { if(fc.hasParams()) { for(Map.Entry<String, String> param : fc.getParams().entrySet()) { final String name = param.getKey(); if(id != null && id.hasParam(name)) { if(fc.hasResetParams()) { for(String param : fc.getResetParams()) { final ElementNode paramE = addElement(fcE, Element.RESET_PARAM.getLocalName(), ns); addAttribute(paramE, Attribute.PARAM, param); if(fc.hasUnsetParams()) { for(String param : fc.getUnsetParams()) { final ElementNode paramE = addElement(fcE, Element.UNSET_PARAM.getLocalName(), ns); addAttribute(paramE, Attribute.PARAM, param);
final FeatureConfig fc = new FeatureConfig(); fc.setOrigin(origin); fc.setParentRef(parentRef); break; case FEATURE: final FeatureConfig nested = new FeatureConfig(); readFeatureConfig(reader, nested); fc.addFeature(nested); break; case RESET_PARAM: fc.resetParam(readParamAttr(reader)); break; case UNSET_PARAM: fc.unsetParam(readParamAttr(reader)); break; default:
@SuppressWarnings("unchecked") public B removeFeature(FeatureId id) throws ProvisioningDescriptionException { int index = -1; // Although that is a list, we have a single ConfigModel for a given ConfigId for (int i = 0; i < items.size(); i++) { ConfigItem ci = items.get(i); if (ci instanceof FeatureConfig) { FeatureConfig conf = (FeatureConfig) ci; if (conf.getSpecId().equals(id.getSpec())) { boolean eq = true; for (Entry<String, String> entry : id.getParams().entrySet()) { String val = conf.getParam(entry.getKey()); if (val == null || !val.equals(entry.getValue())) { eq = false; break; } } if (eq) { index = i; break; } } } } if (index == -1) { throw new ProvisioningDescriptionException("Feature " + id + " is not added"); } items = CollectionUtils.remove(items, index); return (B) this; }
final ProvisionedFeature actual = feature[1]; final FeatureSpec fSpec = layout.getFeaturePack(actual.getSpecId().getProducer()).getFeatureSpec(actual.getSpecId().getName()).getSpec(); final FeatureConfig config = new FeatureConfig(fSpec.getName()); config.setOrigin(provisionedConfig.originOf(actual.getSpecId().getProducer())); if(!actualParams.remove(paramName)) { if(pSpec.isNillable() && pSpec.hasDefaultValue() && !Constants.GLN_UNDEFINED.equals(pSpec.getDefaultValue())) { config.unsetParam(paramName); if(actualValue != null) { if(!pSpec.isFeatureId() && !actualValue.equals(originalValue) && !actualValue.equals(pSpec.getDefaultValue())) { config.setParam(paramName, actualValue); config.unsetParam(paramName); config.setParam(paramName, actual.getConfigParam(paramName)); final FeatureConfig config = new FeatureConfig(feature.getSpecId().getName()); for(String name : feature.getParamNames()) { config.setParam(name, feature.getConfigParam(name));
@SuppressWarnings("unchecked") public B includeFeature(FeatureId featureId, FeatureConfig feature) throws ProvisioningDescriptionException { if(feature != null && feature.getOrigin() != null) { final String origin = feature.getOrigin(); feature.setOrigin(null); getExternalFgConfig(origin).includeFeature(featureId, feature); return (B) this; } if(excludedFeatures.containsKey(featureId)) { throw new ProvisioningDescriptionException(featureId + " has been explicitly excluded"); } if(feature == null) { feature = new FeatureConfig(featureId.getSpec()); } else if(feature.specId == null) { feature.specId = featureId.getSpec(); } for (Map.Entry<String, String> idEntry : featureId.getParams().entrySet()) { final String prevValue = feature.putParam(idEntry.getKey(), idEntry.getValue()); if (prevValue != null && !prevValue.equals(idEntry.getValue())) { throw new ProvisioningDescriptionException("Parameter " + idEntry.getKey() + " has value '" + idEntry.getValue() + "' in feature ID and value '" + prevValue + "' in the feature body"); } } includedFeatures = CollectionUtils.putLinked(includedFeatures, featureId, feature); return (B) this; }
public static void addFeatureConfig(ElementNode parentE, FeatureConfig fc, String ns) { final ElementNode fcE = addElement(parentE, Element.FEATURE.getLocalName(), ns); addAttribute(fcE, Attribute.SPEC, fc.getSpecId().toString()); if(fc.getParentRef() != null) { addAttribute(fcE, Attribute.PARENT_REF, fc.getParentRef()); } addFeatureConfigBody(fcE, null, fc, ns); } }
void attachSpecInfo(FeatureSpecInfo specInfo) { this.specInfo = specInfo; if (featureConfig != null) { for (Map.Entry<String, Object> p : feature.getResolvedParams().entrySet()) { if (!specInfo.getSpec().getParams().get(p.getKey()).isFeatureId()) { featureConfig.setParam(p.getKey(), p.getValue().toString()); } } } } public FeatureId getFeatureId() {
break; case FEATURE: final FeatureConfig nested = new FeatureConfig().setOrigin(origin); readFeatureConfig(reader, nested); groupBuilder.addFeature(nested);
public static FeatureConfig newConfig(String specName) throws ProvisioningDescriptionException { return new FeatureConfig(specName); }
private static FeatureConfig getExistingFeature(ConfigModel cm, FeatureId featId) { for (ConfigItem ci : cm.getItems()) { if (ci instanceof FeatureConfig) { FeatureConfig fi = (FeatureConfig) ci; if (fi.getSpecId().equals(featId.getSpec())) { boolean eq = true; for (String name : featId.getParamNames()) { String p = fi.getParam(name); if (p == null || !p.equals(featId.getParam(name))) { eq = false; break; } } if (eq) { return fi; } } } } return null; }
config.setParam(name, value);
break; case FEATURE: final FeatureConfig nested = new FeatureConfig(); nested.setOrigin(origin); readFeatureConfig(reader, nested); builder.addFeature(nested);
@Override public FeatureConfig parse(final Reader input) throws XMLStreamException { final FeatureConfig config = new FeatureConfig(); XmlParsers.parse(input, config); return config; } }