static Map<String, UniverseFeaturePackInstaller> load() throws ProvisioningException { final ServiceLoader<UniverseFeaturePackInstaller> loader = ServiceLoader.load(UniverseFeaturePackInstaller.class); Map<String, UniverseFeaturePackInstaller> universeInstallers = Collections.emptyMap(); for(UniverseFeaturePackInstaller uCreator : loader) { if(universeInstallers.isEmpty()) { universeInstallers = Collections.singletonMap(uCreator.getUniverseFactoryId(), uCreator); continue; } if(universeInstallers.containsKey(uCreator.getUniverseFactoryId())) { throw new IllegalStateException("Only one universe feature-pack installer is allowed per repository type " + uCreator.getUniverseFactoryId() + " but found " + uCreator + " and " + universeInstallers.get(uCreator.getUniverseFactoryId())); } if(universeInstallers.size() == 1) { final HashMap<String, UniverseFeaturePackInstaller> tmp = new HashMap<>(2); tmp.putAll(universeInstallers); universeInstallers = tmp; } universeInstallers.put(uCreator.getUniverseFactoryId(), uCreator); } return CollectionUtils.unmodifiable(universeInstallers); }
/** * Adds feature-pack archive to the local provisioning feature-pack cache. * Optionally, installs the feature-pack archive to the universe repository. * * @param featurePack feature-pack archive * @param installInUniverse whether to install the feature-pack into the universe repository * @return feature-pack location which was added to the local cache * @throws ProvisioningException in case of a failure */ public synchronized FeaturePackLocation addLocal(Path featurePack, boolean installInUniverse) throws ProvisioningException { final FPID fpid = FeaturePackDescriber.readSpec(featurePack).getFPID(); cacheManager.put(featurePack, fpid); if(!installInUniverse) { return fpid.getLocation(); } if(universeInstallers == null) { universeInstallers = UniverseFeaturePackInstaller.load(); } final Universe<?> universe = universeResolver.getUniverse(fpid.getUniverse()); final UniverseFeaturePackInstaller fpInstaller = universeInstallers.get(universe.getFactoryId()); if(fpInstaller == null) { throw new ProvisioningException(Errors.featurePackInstallerNotFound(universe.getFactoryId(), universeInstallers.keySet())); } fpInstaller.install(universe, fpid, featurePack); return fpid.getLocation(); }
public void install() throws ProvisioningException { ufpInstallers = UniverseFeaturePackInstaller.load(); universeResolver = buildUniverseResolver(); try { for (FeaturePackBuilder fp : fps) { fp.build(); } } finally { if (workDir != null) { IoUtils.recursiveDelete(workDir); } } }
void install(FeaturePackLocation.FPID fpid, Path fpContentDir) throws ProvisioningException { Universe<?> universe = null; UniverseFeaturePackInstaller ufpInstaller = null; if (universeResolution) { universe = universeResolver.getUniverse(fpid.getLocation().getUniverse()); ufpInstaller = ufpInstallers.get(universe.getFactoryId()); if (ufpInstaller == null) { throw new ProvisioningException(Errors.featurePackInstallerNotFound(universe.getFactoryId(), ufpInstallers.keySet())); } } final Path fpZip = getBuildDir().resolve(LayoutUtils.ensureValidFileName(fpid.toString())); try { ZipUtils.zip(fpContentDir, fpZip); } catch (IOException e) { throw new ProvisioningException("Failed to create feature-pack archive", e); } if (ufpInstaller != null) { ufpInstaller.install(universe, fpid, fpZip); } }