Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for GAL-358, Introduce package and config stability #342

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common-api/src/main/java/org/jboss/galleon/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public interface Constants {
String PASSIVE_PLUS = "passive+";

String STABILITY_LEVEL = "stability-level";
String CONFIG_STABILITY_LEVEL = "config-stability-level";
String PACKAGE_STABILITY_LEVEL = "package-stability-level";
String STABILITY_EXPERIMENTAL = "experimental";
String STABILITY_PREVIEW = "preview";
String STABILITY_COMMUNITY = "community";
Expand Down
16 changes: 15 additions & 1 deletion core/src/main/java/org/jboss/galleon/ProvisioningOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,23 @@ public class ProvisioningOption {
.addToValueSet(Constants.STABILITY_DEFAULT)
.build();

public static final ProvisioningOption CONFIG_STABILITY_LEVEL = ProvisioningOption.builder(Constants.CONFIG_STABILITY_LEVEL)
.addToValueSet(Constants.STABILITY_EXPERIMENTAL)
.addToValueSet(Constants.STABILITY_PREVIEW)
.addToValueSet(Constants.STABILITY_COMMUNITY)
.addToValueSet(Constants.STABILITY_DEFAULT)
.build();

public static final ProvisioningOption PACKAGE_STABILITY_LEVEL = ProvisioningOption.builder(Constants.PACKAGE_STABILITY_LEVEL)
.addToValueSet(Constants.STABILITY_EXPERIMENTAL)
.addToValueSet(Constants.STABILITY_PREVIEW)
.addToValueSet(Constants.STABILITY_COMMUNITY)
.addToValueSet(Constants.STABILITY_DEFAULT)
.build();

private static final List<ProvisioningOption> stdOptions = Arrays
.asList(new ProvisioningOption[] { IGNORE_NOT_EXCLUDED_LAYERS, OPTIONAL_PACKAGES, VERSION_CONVERGENCE, PRINT_ONLY_CONFLICTS,
STORE_INPUT_PROVISIONING_CONFIG, EXPORT_SYSTEM_PATHS, STABILITY_LEVEL});
STORE_INPUT_PROVISIONING_CONFIG, EXPORT_SYSTEM_PATHS, CONFIG_STABILITY_LEVEL, PACKAGE_STABILITY_LEVEL, STABILITY_LEVEL});

public static List<ProvisioningOption> getStandardList() {
return stdOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,13 @@ private static void ensureDir(Path dir) throws IOException {
}
}

public FeaturePackBuilder setMinStability(String stability) {
fpBuilder.setMinStability(stability);
public FeaturePackBuilder setConfigStability(String stability) {
fpBuilder.setConfigStability(stability);
return this;
}

public FeaturePackBuilder setPackageStability(String stability) {
fpBuilder.setPackageStability(stability);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,8 @@ private F resolveFeaturePack(FeaturePackLocation fpl, int type, boolean translat
}
if(rebuilder != null) {
rebuilder.setGalleonMinVersion(fpSpec.getGalleonMinVersion());
rebuilder.setMinStability(fpSpec.getMinStability());
rebuilder.setConfigStability(fpSpec.getConfigStability());
rebuilder.setPackageStability(fpSpec.getPackageStability());
final FeaturePackSpec spec = rebuilder.build();
fp = fpFactory.newFeaturePack(spec.getFPID().getLocation(), spec, fp.getDir(), fp.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class FeaturePackRuntime extends FeaturePackLayout implements FeaturePack
}
// Filter out the packages that are not at the right stability level
final Map<String, PackageRuntime> filteredPackages = new LinkedHashMap<>(tmpPackages.size());
Stability minStability= rt.getMinStability(getSpec().getMinStability());
Stability minStability= rt.getMinPackageStability(getSpec().getPackageStability());
for(Map.Entry<String, PackageRuntime> entry : tmpPackages.entrySet()) {
Stability stability = entry.getValue().getSpec().getStability() == null ? Stability.DEFAULT : entry.getValue().getSpec().getStability();
if (minStability.enables(stability)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public List<GalleonFeatureSpec> getDiscoveredFeatures() {
private final MessageWriter messageWriter;
private Boolean emptyStagedDir;
private final boolean recordState;
private Stability lowestStability;
private Stability lowestConfigStability;
private List<ProvisionedConfig> configs = Collections.emptyList();

ProvisioningRuntime(final ProvisioningRuntimeBuilder builder, final MessageWriter messageWriter) throws ProvisioningException {
this.startTime = builder.startTime;
this.config = builder.config;
this.lowestStability = builder.lowestStability == null ? null : builder.lowestStability;
this.lowestConfigStability = builder.lowestConfigStability == null ? null : builder.lowestConfigStability;
this.layout = builder.layout.transform(new FeaturePackLayoutTransformer<FeaturePackRuntime, FeaturePackRuntimeBuilder>() {
@Override
public FeaturePackRuntime transform(FeaturePackRuntimeBuilder other) throws ProvisioningException {
Expand Down Expand Up @@ -131,8 +131,8 @@ public FeaturePackRuntime transform(FeaturePackRuntimeBuilder other) throws Prov
this.messageWriter = messageWriter;
}

public String getLowestStability() {
return lowestStability.toString();
public String getLowestConfigStability() {
return lowestConfigStability.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ public static ProvisioningRuntimeBuilder newInstance(final MessageWriter message
Path stagedDir;
boolean recordState;
FsDiff fsDiff;
Stability userStability;
Stability userConfigStability;
Stability userPackageStability;
// Can be needed by Galleon plugins.
Stability lowestStability;
Stability lowestConfigStability;
private final MessageWriter messageWriter;

Map<String, ConfigModelStack> nameOnlyConfigs = Collections.emptyMap();
Expand Down Expand Up @@ -186,25 +187,46 @@ private ProvisioningRuntime doBuild() throws ProvisioningException {
config = layout.getConfig();
fpConfigStack = new FpStack(config);
String stabilityOption = layout.getOptionValue(ProvisioningOption.STABILITY_LEVEL);
if (stabilityOption == null) {
String configStabilityOption = layout.getOptionValue(ProvisioningOption.CONFIG_STABILITY_LEVEL);
String packageStabilityOption = layout.getOptionValue(ProvisioningOption.PACKAGE_STABILITY_LEVEL);
if(stabilityOption != null) {
if(configStabilityOption != null) {
throw new ProvisioningException(ProvisioningOption.STABILITY_LEVEL.getName() + " option can't be set when " +
ProvisioningOption.CONFIG_STABILITY_LEVEL.getName() + " is set.");
}
if (packageStabilityOption != null) {
throw new ProvisioningException(ProvisioningOption.STABILITY_LEVEL.getName() + " option can't be set when "
+ ProvisioningOption.PACKAGE_STABILITY_LEVEL.getName() + " is set.");
}
configStabilityOption = stabilityOption;
packageStabilityOption = stabilityOption;
}
if (configStabilityOption == null) {
Stability stability = Stability.DEFAULT;
for (FeaturePackRuntimeBuilder fp : layout.getOrderedFeaturePacks()) {
Stability fpStability = fp.getSpec().getMinStability();
Stability fpStability = fp.getSpec().getConfigStability();
if (stability == null || (fpStability.ordinal() > stability.ordinal())) {
stability = fpStability;
}
}
lowestStability = stability;
lowestConfigStability = stability;
if (messageWriter.isVerboseEnabled()) {
messageWriter.verbose("No stability level provided, minimum stability of each feature-pack will be used. "
+ "The lowest stability is " + lowestStability);
messageWriter.verbose("No config stability level provided, config stability of each feature-pack will be used. "
+ "The lowest stability is " + lowestConfigStability);
}
} else {
userStability = Stability.fromString(stabilityOption);
lowestStability = userStability;
userConfigStability = Stability.fromString(configStabilityOption);
lowestConfigStability = userConfigStability;
if (messageWriter.isVerboseEnabled()) {
messageWriter.verbose("Stability level " + userStability + " has been provided. "
+ "It constrains all feature-packs. The lowest stability is " + lowestStability);
messageWriter.verbose("Stability level " + userConfigStability + " has been provided. "
+ "It constrains all feature-packs. The lowest config stability is " + lowestConfigStability);
}
}
if (packageStabilityOption != null) {
userPackageStability = Stability.fromString(packageStabilityOption);
if (messageWriter.isVerboseEnabled()) {
messageWriter.verbose("Stability level " + userPackageStability + " has been provided. "
+ "It constrains all feature-packs. The lowest package stability is " + lowestConfigStability);
}
}

Expand Down Expand Up @@ -260,21 +282,39 @@ private ProvisioningRuntime doBuild() throws ProvisioningException {
}

/**
* The min stability is constrained by the feature-pack stability that is the minimal for a
* The min config stability is constrained by the feature-pack stability that is the minimal for a
* given feature-pack. The stability set by the user can only reduce the scope.
*/
public Stability getMinStability(Stability featurePackStability) {
public Stability getMinConfigStability(Stability featurePackStability) {
Stability minStability= featurePackStability;
if (getUserStability() != null) {
if (minStability.enables(getUserStability())) {
minStability = getUserStability();
if (getUserConfigStability() != null) {
if (minStability.enables(getUserConfigStability())) {
minStability = getUserConfigStability();
}
}
return minStability;
}

public Stability getUserStability() {
return userStability;
/**
* The min package stability is constrained by the feature-pack stability that is the minimal for a
* given feature-pack. The stability set by the user can only reduce the scope.
*/
public Stability getMinPackageStability(Stability featurePackStability) {
Stability minStability= featurePackStability;
if (getUserPackageStability() != null) {
if (minStability.enables(getUserPackageStability())) {
minStability = getUserPackageStability();
}
}
return minStability;
}

public Stability getUserConfigStability() {
return userConfigStability;
}

public Stability getUserPackageStability() {
return userPackageStability;
}

private void mergeModelOnlyConfigs() throws ProvisioningException {
Expand Down Expand Up @@ -925,10 +965,10 @@ private void processConfigItemContainer(ConfigItemContainer ciContainer) throws
Stability fpStability = null;
for (FeaturePackRuntimeBuilder fp : layout.getOrderedFeaturePacks()) {
if (fp.producer.equals(spec.getId().getProducer())) {
fpStability = fp.getSpec().getMinStability();
fpStability = fp.getSpec().getConfigStability();
}
}
Stability minStability = getMinStability(fpStability);
Stability minStability = getMinConfigStability(fpStability);
if (!minStability.enables(featureStability)) {
if (messageWriter.isVerboseEnabled()) {
messageWriter.verbose(configStack.id + ". Excluding feature '" + fconfig.getSpecId().getName() + "'. Its stability '" + featureStability + "' is lower than the expected '" + minStability +"' stability");
Expand Down
47 changes: 35 additions & 12 deletions core/src/main/java/org/jboss/galleon/spec/FeaturePackSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static class Builder extends FeaturePackDepsConfigBuilder<Builder> {
private Map<String, FeaturePackPlugin> plugins = Collections.emptyMap();
private Set<String> systemPaths = Collections.emptySet();
private String galleonMinVersion;
private Stability minStability;
private Stability configStability;
private Stability packageStability;

protected Builder() {
}
Expand All @@ -63,20 +64,36 @@ public String getGalleonMinVersion() {
return galleonMinVersion;
}

public Builder setMinStability(String minLevel) {
if (minLevel != null) {
this.minStability = Stability.fromString(minLevel);
public Builder setConfigStability(String configLevel) {
if (configLevel != null) {
this.configStability = Stability.fromString(configLevel);
}
return this;
}

public Builder setMinStability(Stability minLevel) {
this.minStability = minLevel;
public Builder setConfigStability(Stability configLevel) {
this.configStability = configLevel;
return this;
}

public Stability getMinStability() {
return minStability;
public Stability getConfigStability() {
return configStability;
}

public Builder setPackageStability(String packageLevel) {
if (packageLevel != null) {
this.packageStability = Stability.fromString(packageLevel);
}
return this;
}

public Builder setPackageStability(Stability packageLevel) {
this.packageStability = packageLevel;
return this;
}

public Stability getPackageStability() {
return packageStability;
}

public FPID getFPID() {
Expand Down Expand Up @@ -152,7 +169,8 @@ public static Builder builder(FPID fpid) {
private final FPID patchFor;
private final Set<String> systemPaths;
private final String galleonMinVersion;
private final Stability minStability;
private final Stability configStability;
private final Stability packageStability;

protected FeaturePackSpec(Builder builder) throws ProvisioningDescriptionException {
super(builder);
Expand All @@ -162,15 +180,20 @@ protected FeaturePackSpec(Builder builder) throws ProvisioningDescriptionExcepti
this.patchFor = builder.patchFor;
this.systemPaths = CollectionUtils.unmodifiable(builder.systemPaths);
this.galleonMinVersion = builder.galleonMinVersion;
this.minStability = builder.minStability == null ? Stability.DEFAULT : builder.minStability;
this.configStability = builder.configStability == null ? Stability.DEFAULT : builder.configStability;
this.packageStability = builder.packageStability == null ? Stability.DEFAULT : builder.packageStability;
}

public String getGalleonMinVersion() {
return galleonMinVersion;
}

public Stability getMinStability() {
return minStability;
public Stability getConfigStability() {
return configStability;
}

public Stability getPackageStability() {
return packageStability;
}

public FPID getFPID() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ enum Attribute implements XmlNameProvider {
INHERIT("inherit"),
LOCATION("location"),
GALLEON_MIN_VERSION("galleon-min-version"),
MIN_STABILITY_LEVEL("min-stability-level"),
CONFIG_STABILITY_LEVEL("config-stability-level"),
PACKAGE_STABILITY_LEVEL("package-stability-level"),
MODEL("model"),
NAMED_CONFIGS_ONLY("named-configs-only"),
NAME("name"),
Expand All @@ -152,7 +153,8 @@ enum Attribute implements XmlNameProvider {
attributes.put(INHERIT.getLocalName(), INHERIT);
attributes.put(LOCATION.getLocalName(), LOCATION);
attributes.put(GALLEON_MIN_VERSION.getLocalName(), GALLEON_MIN_VERSION);
attributes.put(MIN_STABILITY_LEVEL.getLocalName(), MIN_STABILITY_LEVEL);
attributes.put(CONFIG_STABILITY_LEVEL.getLocalName(), CONFIG_STABILITY_LEVEL);
attributes.put(PACKAGE_STABILITY_LEVEL.getLocalName(), PACKAGE_STABILITY_LEVEL);
attributes.put(MODEL.getLocalName(), MODEL);
attributes.put(NAME.getLocalName(), NAME);
attributes.put(PATH.getLocalName(), PATH);
Expand Down Expand Up @@ -307,7 +309,8 @@ private String readSystemPathValue(XMLExtendedStreamReader reader) throws XMLStr
private void readRootElement(XMLExtendedStreamReader reader, Builder builder) throws XMLStreamException {
FeaturePackLocation location = null;
String version = null;
String stability = null;
String configStability = null;
String packageStability = null;
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final Attribute attribute = Attribute.of(reader.getAttributeName(i).getLocalPart());
Expand All @@ -326,9 +329,16 @@ private void readRootElement(XMLExtendedStreamReader reader, Builder builder) th
throw new XMLStreamException(ParsingUtils.error("Failed to parse feature-pack location", reader.getLocation()), e);
}
break;
case MIN_STABILITY_LEVEL:
case CONFIG_STABILITY_LEVEL:
try {
stability = reader.getAttributeValue(i);
configStability = reader.getAttributeValue(i);
} catch (IllegalArgumentException e) {
throw new XMLStreamException(ParsingUtils.error("Failed to parse feature-pack location", reader.getLocation()), e);
}
break;
case PACKAGE_STABILITY_LEVEL:
try {
packageStability = reader.getAttributeValue(i);
} catch (IllegalArgumentException e) {
throw new XMLStreamException(ParsingUtils.error("Failed to parse feature-pack location", reader.getLocation()), e);
}
Expand All @@ -341,7 +351,8 @@ private void readRootElement(XMLExtendedStreamReader reader, Builder builder) th
throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.LOCATION));
}
builder.setGalleonMinVersion(version);
builder.setMinStability(stability);
builder.setConfigStability(configStability);
builder.setPackageStability(packageStability);
builder.setFPID(location.getFPID());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ protected ElementNode toElement(FeaturePackSpec fpSpec) {
final ElementNode fp = addElement(null, Element.FEATURE_PACK);
addAttribute(fp, Attribute.LOCATION, fpSpec.getFPID().toString());
addAttribute(fp, Attribute.GALLEON_MIN_VERSION, CoreVersion.getVersion());
if (fpSpec.getMinStability() != null) {
addAttribute(fp, Attribute.MIN_STABILITY_LEVEL, fpSpec.getMinStability().toString());
if (fpSpec.getConfigStability() != null) {
addAttribute(fp, Attribute.CONFIG_STABILITY_LEVEL, fpSpec.getConfigStability().toString());
}
if (fpSpec.getPackageStability() != null) {
addAttribute(fp, Attribute.PACKAGE_STABILITY_LEVEL, fpSpec.getPackageStability().toString());
}
ProvisioningXmlWriter.writeUniverseSpecs(fpSpec, fp);

Expand Down
Loading
Loading