use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.
the class ProvisioningLayoutFactory method resolveFeaturePack.
public <F extends FeaturePackLayout> F resolveFeaturePack(FeaturePackLocation location, int type, FeaturePackLayoutFactory<F> factory) throws ProvisioningException {
final Path fpDir = resolveFeaturePackDir(location);
final Path fpXml = fpDir.resolve(Constants.FEATURE_PACK_XML);
if (!Files.exists(fpXml)) {
throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(fpXml));
}
try (BufferedReader reader = Files.newBufferedReader(fpXml)) {
final FeaturePackSpec fpSpec = FeaturePackXmlParser.getInstance().parse(reader);
if (location.isMavenCoordinates()) {
final FPID specId = fpSpec.getFPID();
final FeaturePackLocation fpl = new FeaturePackLocation(specId.getUniverse(), specId.getProducer().getName(), specId.getChannel().getName(), location.getFrequency(), specId.getBuild());
synchronized (this) {
cachedPacks.put(fpl.getFPID(), cachedPacks.get(location.getFPID()));
}
location = fpl;
}
return factory.newFeaturePack(location, fpSpec, fpDir, type);
} catch (IOException | XMLStreamException e) {
throw new ProvisioningException(Errors.parseXml(fpXml), e);
}
}
use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.
the class ProvisioningLayout method uninstall.
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) {
targetConfig = config.getTransitiveDep(patchTarget);
if (targetConfig == null) {
throw new ProvisioningException("Target feature-pack for patch " + fpid + " could not be found");
}
}
return configBuilder.updateFeaturePackDep(FeaturePackConfig.builder(targetConfig).removePatch(fpid).build());
}
final F installedFp = featurePacks.get(fpid.getProducer());
if (installedFp == null) {
throw new ProvisioningException(Errors.unknownFeaturePack(fpid));
}
if (fpid.getBuild() != null && !installedFp.getFPID().getBuild().equals(fpid.getBuild())) {
throw new ProvisioningException(Errors.unknownFeaturePack(fpid));
}
final FeaturePackConfig fpConfig = config.getFeaturePackDep(fpid.getProducer());
if (fpConfig == null) {
throw new ProvisioningException(Errors.unsatisfiedFeaturePackDep(fpid.getProducer()));
}
configBuilder.removeFeaturePackDep(fpid.getLocation());
if (!configBuilder.hasFeaturePackDeps()) {
configBuilder.clearFeaturePackDeps();
configBuilder.clearOptions();
}
return configBuilder;
}
use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.
the class ProvisioningLayout method apply.
public void apply(ProvisioningPlan plan, Map<String, String> pluginOptions) throws ProvisioningException {
if (plan.isEmpty()) {
return;
}
final ProvisioningConfig.Builder configBuilder = ProvisioningConfig.builder(config);
if (plan.hasUpdates()) {
Map<ProducerSpec, FeaturePackUpdatePlan> updates = plan.getUpdateMap();
Set<ProducerSpec> processed = new HashSet<>(updates.size());
for (FeaturePackConfig fpConfig : config.getFeaturePackDeps()) {
final ProducerSpec producer = fpConfig.getLocation().getProducer();
final FeaturePackUpdatePlan fpPlan = updates.get(producer);
if (fpPlan != null && !fpPlan.isEmpty()) {
if (!fpPlan.getInstalledLocation().equals(fpConfig.getLocation())) {
throw new ProvisioningException("Location in the update plan " + fpPlan.getInstalledLocation() + " does not match the installed location " + fpConfig.getLocation());
}
final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.builder(fpPlan.getNewLocation()).init(fpConfig);
if (fpPlan.hasNewPatches()) {
for (FPID patchId : fpPlan.getNewPatches()) {
fpBuilder.addPatch(patchId);
}
}
configBuilder.updateFeaturePackDep(fpBuilder.build());
processed.add(producer);
}
}
for (FeaturePackConfig fpConfig : config.getTransitiveDeps()) {
final ProducerSpec producer = fpConfig.getLocation().getProducer();
final FeaturePackUpdatePlan fpPlan = updates.get(producer);
if (fpPlan != null && !fpPlan.isEmpty()) {
if (fpConfig.getLocation().getBuild() != null && !fpPlan.getInstalledLocation().equals(fpConfig.getLocation())) {
throw new ProvisioningException("Update plan build " + fpPlan.getInstalledLocation() + " does not match the installed build " + fpConfig.getLocation());
}
final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.transitiveBuilder(fpPlan.getNewLocation()).init(fpConfig);
if (fpPlan.hasNewPatches()) {
for (FPID patchId : fpPlan.getNewPatches()) {
fpBuilder.addPatch(patchId);
}
}
configBuilder.updateFeaturePackDep(fpBuilder.build());
processed.add(producer);
}
}
if (processed.size() < updates.size()) {
for (Map.Entry<ProducerSpec, FeaturePackUpdatePlan> entry : updates.entrySet()) {
if (processed.contains(entry.getKey())) {
continue;
}
final FeaturePackUpdatePlan update = entry.getValue();
final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.transitiveBuilder(update.getNewLocation());
if (update.hasNewPatches()) {
for (FPID patchId : update.getNewPatches()) {
fpBuilder.addPatch(patchId);
}
}
configBuilder.addFeaturePackDep(fpBuilder.build());
}
}
}
if (plan.hasInstall()) {
for (FeaturePackConfig fpConfig : plan.getInstall()) {
install(fpConfig, configBuilder);
}
}
if (plan.hasUninstall()) {
for (ProducerSpec producer : plan.getUninstall()) {
uninstall(producer.getLocation().getFPID(), configBuilder);
}
}
final ProvisioningConfig config = configBuilder.build();
initBuiltInOptions(config, pluginOptions);
rebuild(config, true);
initPluginOptions(pluginOptions, plan.hasUninstall());
}
use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.
the class ProvisioningLayout method processOptions.
private void processOptions(Iterable<? extends ProvisioningOption> pluginOptions, Map<String, String> extraOptions, final Map<String, ProvisioningOption> recognizedOptions, final List<ProvisioningOption> overridenOptions) throws ProvisioningException {
for (ProvisioningOption pluginOption : pluginOptions) {
final String optionName = pluginOption.getName();
if (!options.containsKey(optionName)) {
if (pluginOption.isRequired()) {
throw new ProvisioningException(Errors.pluginOptionRequired(optionName));
}
continue;
}
final ProvisioningOption existing = recognizedOptions.put(optionName, pluginOption);
// doesn't override a persistent one
if (existing != null && existing.isPersistent() && !pluginOption.isPersistent()) {
recognizedOptions.put(existing.getName(), existing);
} else if (pluginOption.isPersistent() || extraOptions.containsKey(optionName) && config.hasOption(optionName)) {
overridenOptions.add(pluginOption);
}
}
}
use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.
the class ResolvedFeatureSpec method resolveIdFromForeignKey.
ResolvedFeatureId resolveIdFromForeignKey(ResolvedFeatureId parentId, String parentRef, Map<String, String> params) throws ProvisioningException {
if (!xmlSpec.hasId()) {
return null;
}
if (parentId == null) {
final StringBuilder buf = new StringBuilder();
buf.append("Failed to initialize foreign key parameters of ").append(id).append(": the referenced feature has not ID ");
throw new ProvisioningException(buf.toString());
}
if (parentRef == null) {
parentRef = parentId.specId.name;
}
final List<FeatureParameterSpec> idParamSpecs = xmlSpec.getIdParams();
final Map<String, Object> resolvedParams = new HashMap<>(idParamSpecs.size());
final FeatureReferenceSpec refSpec = xmlSpec.getFeatureRef(parentRef);
try {
if (refSpec.hasMappedParams()) {
for (Map.Entry<String, String> mapping : refSpec.getMappedParams().entrySet()) {
final FeatureParameterSpec param = xmlSpec.getParam(mapping.getKey());
if (!param.isFeatureId()) {
continue;
}
final Object idValue = parentId.params.get(mapping.getValue());
if (idValue == null) {
throw new ProvisioningDescriptionException(id + " expects ID parameter '" + mapping.getValue() + "' in " + parentId);
}
resolvedParams.put(mapping.getKey(), idValue);
}
for (FeatureParameterSpec idParamSpec : idParamSpecs) {
String configValue = params.get(idParamSpec.getName());
if (configValue != null) {
final Object childValue = paramFromString(idParamSpec.getName(), configValue);
final Object idValue = resolvedParams.put(idParamSpec.getName(), childValue);
if (idValue != null && !idValue.equals(childValue)) {
throw new ProvisioningDescriptionException(Errors.idParamForeignKeyInitConflict(id, idParamSpec.getName(), childValue, idValue));
}
continue;
}
if (resolvedParams.containsKey(idParamSpec.getName())) {
continue;
}
final Object childValue = getResolvedParam(idParamSpec.getName()).defaultValue;
if (childValue == null) {
throw new ProvisioningDescriptionException(Errors.nonNillableParameterIsNull(id, idParamSpec.getName()));
}
resolvedParams.put(idParamSpec.getName(), childValue);
}
} else {
for (FeatureParameterSpec idParamSpec : idParamSpecs) {
final Object parentValue = parentId.params.get(idParamSpec.getName());
String configValue = params.get(idParamSpec.getName());
if (configValue != null) {
final Object childValue = paramFromString(idParamSpec.getName(), configValue);
if (parentValue != null && !parentValue.equals(childValue)) {
throw new ProvisioningDescriptionException(Errors.idParamForeignKeyInitConflict(id, idParamSpec.getName(), childValue, parentValue));
}
resolvedParams.put(idParamSpec.getName(), childValue);
continue;
}
if (parentValue != null) {
resolvedParams.put(idParamSpec.getName(), parentValue);
continue;
}
final Object childValue = getResolvedParam(idParamSpec.getName()).defaultValue;
if (childValue == null) {
throw new ProvisioningDescriptionException(Errors.nonNillableParameterIsNull(id, idParamSpec.getName()));
}
resolvedParams.put(idParamSpec.getName(), childValue);
}
}
return new ResolvedFeatureId(id, resolvedParams);
} catch (ProvisioningException e) {
final StringBuilder buf = new StringBuilder();
buf.append("Failed to initialize foreign key parameters of ").append(id).append(" spec referencing feature ").append(parentId).append(" with parameters ");
StringUtils.append(buf, params.entrySet());
throw new ProvisioningException(Errors.failedToInitializeForeignKeyParams(id, parentId, params), e);
}
}
Aggregations