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; }
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; }
private static Map<String, Map<String, Set<String>>> getAllLayers(ProvisioningLayout<FeaturePackLayout> pLayout, boolean includeDependencies) throws ProvisioningException, IOException { Map<String, Map<String, Set<String>>> layersMap = new HashMap<>(); for (FeaturePackLayout fp : pLayout.getOrderedFeaturePacks()) { for (ConfigId layer : fp.loadLayers()) { String model = layer.getModel(); Map<String, Set<String>> names = layersMap.get(model); if (names == null) { names = new HashMap<>(); layersMap.put(model, names); } Set<String> dependencies = new TreeSet<>(); if (includeDependencies) { ConfigLayerSpec spec = fp.loadConfigLayerSpec(model, layer.getName()); for (ConfigLayerDependency dep : spec.getLayerDeps()) { dependencies.add(dep.getName()); } } names.put(layer.getName(), dependencies); } } return layersMap; }
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); }
fpl = layoutFactory.getUniverseResolver().resolveLatestBuild(fpl); final FeaturePackSpec fpSpec = layoutFactory.resolveFeaturePack(fpl, FeaturePackLayout.DIRECT_DEP, fpFactory).getSpec(); 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()); if(installedFp.isTransitiveDep() == fpConfig.isTransitive()) { return configBuilder.updateFeaturePackDep(fpConfig); if(installedFp.isTransitiveDep()) {
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); layout(p.getSpec(), branch, FeaturePackLayout.TRANSITIVE_DEP); handle.copyResources(p.getDir()); ordered.add(p);
final List<F> patches = fpPatches.get(f.getFPID()); if(patches == null) { final Path fpResources = f.getDir().resolve(Constants.RESOURCES); if (Files.exists(fpResources)) { patchDir(getResources(), fpResources); final Path fpPlugins = f.getDir().resolve(Constants.PLUGINS); if (Files.exists(fpPlugins)) { patchDir(getPluginsDir(), fpPlugins); 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); final Path patchDir = patch.getDir(); patchFpDir(fpDir, patchDir, Constants.PACKAGES); patchFpDir(fpDir, patchDir, Constants.FEATURES);
private boolean dependsOn(F f, ProducerSpec dep, Set<ProducerSpec> visitedFps) throws ProvisioningException { final FeaturePackSpec spec = f.getSpec(); if(!spec.hasFeaturePackDeps()) { return false; } if(spec.hasFeaturePackDep(dep) || spec.hasTransitiveDep(dep)) { return true; } for(FeaturePackConfig fpConfig : spec.getFeaturePackDeps()) { final ProducerSpec producer = fpConfig.getLocation().getProducer(); if(!visitedFps.add(producer)) { continue; } if(dependsOn(featurePacks.get(producer), dep, visitedFps)) { return true; } visitedFps.remove(producer); } return false; }
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(); }
public Set<ConfigId> loadLayers() throws ProvisioningException, IOException { Path layersDir = getDir().resolve(Constants.LAYERS); if (!Files.exists(layersDir)) { return Collections.emptySet(); } Set<ConfigId> layers = new HashSet<>(); Files.walkFileTree(layersDir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().equals(Constants.LAYER_SPEC_XML)) { ConfigId id; Path rootDir = file.getParent().getParent(); // No model if (rootDir.equals(layersDir)) { id = new ConfigId(null, file.getParent().getFileName().toString()); } else { id = new ConfigId(rootDir.getFileName().toString(), file.getParent().getFileName().toString()); } layers.add(id); } return FileVisitResult.CONTINUE; } }); return layers; }
= invoc.getPmSession().getLayoutFactory().newConfigLayout(provisioning)) { for (FeaturePackLayout l : layout.getOrderedFeaturePacks()) { layers.addAll(l.loadLayers());
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; }
private void loadPatch(FPID patchId) throws ProvisioningException { final F patchFp = layoutFactory.resolveFeaturePack(patchId.getLocation(), FeaturePackLayout.PATCH, fpFactory); final FeaturePackSpec spec = patchFp.getSpec(); if(!spec.isPatch()) { throw new ProvisioningDescriptionException(patchId + " is not a patch but listed as one"); } allPatches = CollectionUtils.put(allPatches, patchId, patchFp); if(spec.hasFeaturePackDeps()) { for(FeaturePackConfig patchDep : spec.getFeaturePackDeps()) { final FPID patchDepId = patchDep.getLocation().getFPID(); if(allPatches.containsKey(patchDepId)) { continue; } loadPatch(patchDepId); } } final FPID patchFor = spec.getPatchFor(); List<F> patchList = fpPatches.get(patchFor); if(patchList == null) { fpPatches = CollectionUtils.put(fpPatches, patchFor, Collections.singletonList(patchFp)); } else if(patchList.size() == 1) { final List<F> tmp = new ArrayList<>(2); tmp.add(patchList.get(0)); tmp.add(patchFp); fpPatches = CollectionUtils.put(fpPatches, patchFor, tmp); } else { patchList.add(patchFp); } }
public ConfigLayerSpec loadConfigLayerSpec(String model, String name) throws ProvisioningException { final Path specXml; if (model == null) { specXml = getDir().resolve(Constants.LAYERS).resolve(name).resolve(Constants.LAYER_SPEC_XML); } else { specXml = getDir().resolve(Constants.LAYERS).resolve(model).resolve(name).resolve(Constants.LAYER_SPEC_XML); } if (!Files.exists(specXml)) { return null; } try (BufferedReader reader = Files.newBufferedReader(specXml)) { return ConfigLayerSpecXmlParser.getInstance().parse(reader); } catch (Exception e) { throw new ProvisioningDescriptionException(Errors.parseXml(specXml), e); } }
private ProvisioningConfig.Builder uninstall(FPID fpid, ProvisioningConfig.Builder configBuilder) throws ProvisioningException { if(allPatches.containsKey(fpid)) { final F patchFp = allPatches.get(fpid); final ProducerSpec patchTarget = patchFp.getSpec().getPatchFor().getProducer(); FeaturePackConfig targetConfig = config.getFeaturePackDep(patchTarget); if(targetConfig == null) { throw new ProvisioningException(Errors.unknownFeaturePack(fpid)); if(fpid.getBuild() != null && !installedFp.getFPID().getBuild().equals(fpid.getBuild())) { throw new ProvisioningException(Errors.unknownFeaturePack(fpid));
/** * 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())); }
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())); final FPID patchFor = product.getSpec().getPatchFor(); if (patchFor != null) { commandInvocation.println("");
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); } } } }