protected Builder(FeaturePackConfig config) { this.fpl = config.getLocation(); init(config); }
private FeaturePackConfig getFpConfig(ProducerSpec producer) { for(int i = fpConfigs.size() - 1; i >= 0; --i) { final FeaturePackConfig fpConfig = fpConfigs.get(i); if(fpConfig.getLocation().getProducer().equals(producer)) { return fpConfig; } } return null; } }
@Override public void doAction(ProvisioningConfig current, ProvisioningConfig.Builder builder) throws ProvisioningException { for (Entry<FeaturePackConfig, T> entry : cf.entrySet()) { FeaturePackConfig.Builder fpBuilder = entry.getKey().getBuilder(); boolean doit = doAction(fpBuilder, entry.getValue()); // this complexity is due to the fact that some fp could already have the configuration included/excluded/... if (doit) { int index = builder.getFeaturePackDepIndex(entry.getKey().getLocation()); indexes.put(entry.getKey().getLocation().getFPID(), index); builder.removeFeaturePackDep(entry.getKey().getLocation()); builder.addFeaturePackDep(index, fpBuilder.build()); } } }
@Override public void undoAction(ProvisioningConfig.Builder builder) throws ProvisioningException { for (Entry<FeaturePackConfig, T> entry : cf.entrySet()) { Integer index = indexes.get(entry.getKey().getLocation().getFPID()); // index could be null if doAction failed or did not execute. if (index != null) { FeaturePackConfig.Builder fpBuilder = entry.getKey().getBuilder(); undoAction(fpBuilder, entry.getValue()); builder.removeFeaturePackDep(entry.getKey().getLocation()); builder.addFeaturePackDep(index, fpBuilder.build()); } } }
public ProvisioningPlan install(FeaturePackConfig fpConfig) throws ProvisioningDescriptionException { final ProducerSpec producer = fpConfig.getLocation().getProducer(); if(uninstall.contains(producer) || updates.containsKey(producer)) { throw new ProvisioningDescriptionException(producer + " has already been added to the plan"); } install = CollectionUtils.putLinked(install, producer, fpConfig); return this; }
FeaturePackRuntimeBuilder getOrigin(final String depName) throws ProvisioningException { if(Constants.THIS.equals(depName)) { if(thisOrigin == null) { throw new ProvisioningException("Feature-pack reference 'this' cannot be used in the current context."); } return thisOrigin; } final FeaturePackLocation fpl = currentOrigin == null ? config.getFeaturePackDep(depName).getLocation() : currentOrigin.getSpec().getFeaturePackDep(depName).getLocation(); return layout.getFeaturePack(fpl.getProducer()); }
public B addFeaturePackDep(String origin, FeaturePackConfig dependency) throws ProvisioningDescriptionException { final UniverseSpec configuredUniverse = getConfiguredUniverse(dependency.getLocation()); return addFeaturePackDepResolved(origin, configuredUniverse == null ? dependency : FeaturePackConfig.builder(dependency.getLocation().replaceUniverse(configuredUniverse)).init(dependency).build(), false); }
public B updateFeaturePackDep(String origin, FeaturePackConfig dependency) throws ProvisioningDescriptionException { final UniverseSpec configuredUniverse = getConfiguredUniverse(dependency.getLocation()); return addFeaturePackDepResolved(origin, configuredUniverse == null ? dependency : FeaturePackConfig.builder(dependency.getLocation().replaceUniverse(configuredUniverse)).init(dependency).build(), true); }
public State(PmSession pmSession, Path installation) throws ProvisioningException, IOException { ProvisioningConfig conf; if (Files.isRegularFile(installation)) { conf = ProvisioningXmlParser.parse(installation); } else { PathsUtils.assertInstallationDir(installation); conf = ProvisioningXmlParser.parse(PathsUtils.getProvisioningXml(installation)); } Set<FeaturePackLocation.FPID> dependencies = new HashSet<>(); for (FeaturePackConfig cf : conf.getFeaturePackDeps()) { dependencies.add(cf.getLocation().getFPID()); } builder = conf.getBuilder(); config = buildNewConfig(pmSession); path = "" + PathParser.PATH_SEPARATOR; name = installation.getFileName().toString(); }
void addFpConfig(FeaturePackConfig fpConfig) { fpConfigs = CollectionUtils.add(fpConfigs, fpConfig); if(fpConfig.isTransitive()) { transitive = CollectionUtils.put(transitive, fpConfig.getLocation().getProducer(), fpConfig); } }
@Override protected List<String> getItems(PmCompleterInvocation completerInvocation) { State session = completerInvocation.getPmSession().getState(); List<String> lst = new ArrayList<>(); if (session != null) { for (FeaturePackConfig fp : session.getConfig().getFeaturePackDeps()) { String loc = completerInvocation.getPmSession(). getExposedLocation(null, fp.getLocation()).toString(); lst.add(loc); } } return lst; }
private ConfigModelStack resolveConfigLayer(ConfigId layerId) throws ProvisioningException { ConfigModelStack layerStack = layers.get(layerId); if(layerStack == null) { layerStack = new ConfigModelStack(layerId, this); for (FeaturePackConfig fpConfig : config.getFeaturePackDeps()) { resolveConfigLayer(layout.getFeaturePack(fpConfig.getLocation().getProducer()), layerStack, layerId); } layers = CollectionUtils.put(layers, layerId, layerStack); } return layerStack; }
@SuppressWarnings("unchecked") public B removeTransitiveDep(FPID fpid) throws ProvisioningException { final FeaturePackLocation fpl = resolveUniverseSpec(fpid.getLocation()); final ProducerSpec producer = fpl.getProducer(); final FeaturePackConfig fpDep = transitiveDeps.get(producer); if(fpDep == null) { throw new ProvisioningException(Errors.unknownFeaturePack(fpid)); } if(!fpDep.getLocation().equals(fpl)) { throw new ProvisioningException(Errors.unknownFeaturePack(fpid)); } if(transitiveDeps.size() == 1) { transitiveDeps = Collections.emptyMap(); return (B) this; } else { transitiveDeps = CollectionUtils.remove(transitiveDeps, producer); } updateOriginMappings(producer); return (B) this; }
public FeaturePackConfig getProvisionedFP(PmSession session) throws CommandExecutionException { ProducerSpec channel = getProducer(session); if (channel == null) { return null; } ProvisioningConfig config = session.getState().getConfig(); for (FeaturePackConfig dep : config.getFeaturePackDeps()) { if (dep.getLocation().getProducer().equals(channel)) { return dep; } } return null; }
public void install(FeaturePackConfig fpConfig, Map<String, String> options) throws ProvisioningException { ProvisioningConfig config = getProvisioningConfig(); if(config == null) { config = ProvisioningConfig.builder().build(); } try(ProvisioningLayout<FeaturePackRuntimeBuilder> layout = getLayoutFactory().newConfigLayout(config, ProvisioningRuntimeBuilder.FP_RT_FACTORY, false)) { final UniverseSpec configuredUniverse = getConfiguredUniverse(fpConfig.getLocation()); layout.install(configuredUniverse == null ? fpConfig : FeaturePackConfig.builder(fpConfig.getLocation().replaceUniverse(configuredUniverse)).init(fpConfig).build(), options); doProvision(layout, getFsDiff(), false); } }
private Builder(ProvisioningConfig original) throws ProvisioningDescriptionException { if(original == null) { return; } if(original.hasPluginOptions()) { addOptions(original.getPluginOptions()); } for (FeaturePackConfig fp : original.getFeaturePackDeps()) { addFeaturePackDep(original.originOf(fp.getLocation().getProducer()), fp); } if (original.hasTransitiveDeps()) { for (FeaturePackConfig fp : original.getTransitiveDeps()) { addFeaturePackDep(original.originOf(fp.getLocation().getProducer()), fp); } } initUniverses(original); initConfigs(original); }
@Override protected void runCommand(PmCommandInvocation invoc, State session, FeaturePackConfig config) throws IOException, ProvisioningException, CommandExecutionException { try { session.excludePackage(invoc.getPmSession(), PackagesUtil.getPackage(invoc.getPmSession(), config.getLocation().getFPID(), getPackage()), config); } catch (Exception ex) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.excludeFailed(), ex); } }
@Override protected void runCommand(PmCommandInvocation invoc, State session, FeaturePackConfig config) throws IOException, ProvisioningException, CommandExecutionException { try { session.includePackage(invoc.getPmSession(), PackagesUtil.getPackage(invoc.getPmSession(), config.getLocation().getFPID(), getPackage()), config); } catch (Exception ex) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.includeFailed(), ex); } }
private ResolvedFeatureSpec resolveRefMapping(ProvisioningRuntimeBuilder rt, FeaturePackRuntimeBuilder origin, FeatureReferenceSpec refSpec) throws ProvisioningException { try { if(refSpec.getOrigin() != null) { origin = rt.layout.getFeaturePack(origin.getSpec().getFeaturePackDep(refSpec.getOrigin()).getLocation().getProducer()); } final ResolvedFeatureSpec resolvedRefSpec = rt.getFeatureSpec(origin, refSpec.getFeature().getName()); assertRefParamMapping(refSpec, resolvedRefSpec); return resolvedRefSpec; } catch (ProvisioningDescriptionException e) { throw new ProvisioningDescriptionException(Errors.failedToResolveFeatureReference(refSpec, id), e); } }
private void resolveConfigLayer(FeaturePackRuntimeBuilder fp, ConfigModelStack layerStack, ConfigId layerId) throws ProvisioningException { final FeaturePackRuntimeBuilder prevOrigin = currentOrigin; try { final ConfigLayerSpec configLayer = fp.getConfigLayer(layerId); if (configLayer != null) { layerStack.pushGroup(configLayer); } if(fp.getSpec().hasFeaturePackDeps()) { for(FeaturePackConfig depConfig : fp.getSpec().getFeaturePackDeps()) { resolveConfigLayer(layout.getFeaturePack(depConfig.getLocation().getProducer()), layerStack, layerId); } } if(configLayer != null) { setOrigin(fp); processConfigLayer(layerStack, popLayer(layerStack)); } } finally { setOrigin(prevOrigin); } }