private int getIndexForDepToInstall(ProvisioningConfig.Builder configBuilder, ProducerSpec producer) throws ProvisioningException { int index = Integer.MAX_VALUE; final Set<ProducerSpec> visitedFps = new HashSet<>(featurePacks.size()); visitedFps.add(producer); for(F f : featurePacks.values()) { if(!f.isTransitiveDep() && dependsOn(f, producer, visitedFps)) { index = Math.min(index, configBuilder.getFeaturePackDepIndex(f.getFPID().getLocation())); } } return index; }
private <O extends FeaturePackLayout> ProvisioningLayout(ProvisioningLayout<O> other, FeaturePackLayoutFactory<F> fpFactory, FeaturePackLayoutTransformer<F, O> transformer) throws ProvisioningException { this.layoutFactory = other.layoutFactory; this.fpFactory = fpFactory; this.config = other.config; this.options = CollectionUtils.clone(other.options); // feature-packs are processed in the reverse order and then re-ordered again // this is necessary to properly analyze and include optional package and their external dependencies int i = other.ordered.size(); ordered.ensureCapacity(i); while(--i >= 0) { final O otherFp = other.ordered.get(i); final F fp = transformer.transform(otherFp); featurePacks.put(fp.getFPID().getProducer(), fp); ordered.add(fp); } Collections.reverse(ordered); if(!other.fpPatches.isEmpty()) { fpPatches = new HashMap<>(other.fpPatches.size()); for (Map.Entry<FPID, List<O>> patchEntry : other.fpPatches.entrySet()) { final List<O> patches = patchEntry.getValue(); final List<F> convertedPatches = new ArrayList<>(patches.size()); for(O o : patches) { convertedPatches.add(transformer.transform(o)); } fpPatches.put(patchEntry.getKey(), convertedPatches); } } this.handle = other.handle; handle.incrementRefs(); }
/** * Query for available version update and patches for the specific producer. * * @param producer the producer to check the updates for * @return available updates for the producer * @throws ProvisioningException in case of a failure */ public FeaturePackUpdatePlan getFeaturePackUpdate(ProducerSpec producer) throws ProvisioningException { final F f = featurePacks.get(producer); if(f == null) { throw new ProvisioningException(Errors.unknownFeaturePack(producer.getLocation().getFPID())); } final FeaturePackLocation fpl = f.getFPID().getLocation(); final Universe<?> universe = layoutFactory.getUniverseResolver().getUniverse(fpl.getUniverse()); final Channel channel = universe.getProducer(fpl.getProducerName()).getChannel(fpl.getChannelName()); final List<F> patches = fpPatches.get(fpl.getFPID()); final Set<FPID> patchIds; if (patches == null || patches.isEmpty()) { patchIds = Collections.emptySet(); } else if (patches.size() == 1) { patchIds = Collections.singleton(patches.get(0).getFPID()); } else { final Set<FPID> tmp = new HashSet<>(patches.size()); for (F p : patches) { tmp.add(p.getFPID()); } patchIds = CollectionUtils.unmodifiable(tmp); } return channel.getUpdatePlan(FeaturePackUpdatePlan.request(fpl, patchIds, f.isTransitiveDep())); }
private static String buildDependencies(PmCommandInvocation invoc, ProvisioningLayout<FeaturePackLayout> layout) throws ProvisioningException { Map<FPID, FeaturePackConfig> configs = new HashMap<>(); List<FeaturePackLocation> dependencies = new ArrayList<>(); for (FeaturePackLayout fpLayout : layout.getOrderedFeaturePacks()) { boolean isProduct = true; for (FeaturePackLayout fpLayout2 : layout.getOrderedFeaturePacks()) { if (fpLayout2.getSpec().hasTransitiveDep(fpLayout.getFPID().getProducer()) || fpLayout2.getSpec().getFeaturePackDep(fpLayout.getFPID().getProducer()) != null) { isProduct = false; break; } } if (!isProduct) { FeaturePackLocation loc = invoc.getPmSession().getExposedLocation(null, fpLayout.getFPID().getLocation()); dependencies.add(loc); FeaturePackConfig transitiveConfig = layout.getConfig().getTransitiveDep(fpLayout.getFPID().getProducer()); configs.put(loc.getFPID(), transitiveConfig); } } return buildDependencies(dependencies, configs); }
public static List<FeaturePackLocation> getInstallationLocations(Path installation, PmSession session, boolean transitive, boolean patches) { List<FeaturePackLocation> items = new ArrayList<>(); try { PathsUtils.assertInstallationDir(installation); ProvisioningManager mgr = session. newProvisioningManager(installation, false); try (ProvisioningLayout<FeaturePackLayout> layout = mgr.getLayoutFactory().newConfigLayout(mgr.getProvisioningConfig())) { for (FeaturePackLayout fp : layout.getOrderedFeaturePacks()) { if (fp.isDirectDep() || (fp.isTransitiveDep() && transitive)) { items.add(fp.getFPID().getLocation()); } if (patches) { List<FeaturePackLayout> appliedPatches = layout.getPatches(fp.getFPID()); for (FeaturePackLayout patch : appliedPatches) { items.add(patch.getFPID().getLocation()); } } } } } catch (Exception ex) { CliLogging.completionException(ex); } return items; }
@Override public F transform(O other) throws ProvisioningException { return fpFactory.newFeaturePack(other.getFPID().getLocation(), other.getSpec(), other.getDir(), other.getType()); } });
public static String buildPatches(PmCommandInvocation invoc, ProvisioningLayout<FeaturePackLayout> layout) throws ProvisioningException { if (!layout.hasPatches()) { return null; } Table table = new Table(Headers.PATCH, Headers.PATCH_FOR, Headers.UPDATE_CHANNEL); for (FeaturePackLayout fpLayout : layout.getOrderedFeaturePacks()) { List<FeaturePackLayout> patches = layout.getPatches(fpLayout.getFPID()); for (FeaturePackLayout patch : patches) { FeaturePackLocation loc = invoc.getPmSession().getExposedLocation(null, patch.getFPID().getLocation()); FPID patchFor = patch.getSpec().getPatchFor(); table.addLine(patch.getFPID().getBuild(), patchFor.getProducer().getName() + FeaturePackLocation.BUILD_START + patchFor.getBuild(), formatChannel(loc)); } } if (!table.isEmpty()) { table.sort(Table.SortType.ASCENDANT); return table.build(); } return null; }
if(branchId == null && !fpl.getBuild().equals(fp.getFPID().getBuild())) { Set<FPID> versions = conflicts.get(fp.getFPID().getProducer()); if(versions != null) { versions.add(fpl.getFPID()); versions.add(fp.getFPID()); versions.add(fpl.getFPID()); conflicts = CollectionUtils.putLinked(conflicts, fpl.getProducer(), versions);
final List<F> patches = fpPatches.get(f.getFPID()); if(patches == null) { final Path fpResources = f.getDir().resolve(Constants.RESOURCES); final Path fpDir = LayoutUtils.getFeaturePackDir(handle.getPatchedDir(), f.getFPID(), false); try { Files.createDirectories(fpDir); IoUtils.copy(f.getDir(), fpDir); } catch (IOException e) { throw new ProvisioningException("Failed to patch feature-pack dir for " + f.getFPID(), e);
private static void addCustomUpdates(ProvisioningPlan plan, List<FeaturePackLocation> custom, ProvisioningManager mgr) throws ProvisioningException { try (ProvisioningLayout<?> layout = mgr.getLayoutFactory().newConfigLayout(mgr.getProvisioningConfig())) { for (FeaturePackLocation loc : custom) { FeaturePackLayout fpl = layout.getFeaturePack(loc.getProducer()); FeaturePackLocation current = fpl.getFPID().getLocation(); FeaturePackUpdatePlan fpPlan = FeaturePackUpdatePlan.request(current, fpl.isTransitiveDep()).setNewLocation(loc).buildPlan(); if (fpPlan.hasNewLocation()) { plan.update(fpPlan); } } } }
throw new ProvisioningException(Errors.unknownFeaturePack(fpid)); if(fpid.getBuild() != null && !installedFp.getFPID().getBuild().equals(fpid.getBuild())) { throw new ProvisioningException(Errors.unknownFeaturePack(fpid));
if(fpSpec.isPatch()) { F patchTarget = featurePacks.get(fpSpec.getPatchFor().getProducer()); if(patchTarget == null || !patchTarget.getFPID().equals(fpSpec.getPatchFor())) { throw new ProvisioningException(Errors.patchNotApplicable(fpid, fpSpec.getPatchFor())); FeaturePackConfig.transitiveBuilder(patchTarget.getFPID().getLocation()).addPatch(fpid).build());
boolean isProduct = true; for (FeaturePackLayout fpLayout2 : layout.getOrderedFeaturePacks()) { if (fpLayout2.getSpec().hasTransitiveDep(fpLayout.getFPID().getProducer()) || fpLayout2.getSpec().getFeaturePackDep(fpLayout.getFPID().getProducer()) != null) { isProduct = false; break; product = fpLayout; } else { dependencies.add(session.getExposedLocation(null, fpLayout.getFPID().getLocation())); session.getExposedLocation(null, product.getFPID().getLocation()));