From 9f17b55d2dfdc825da48726fe70b9db1694f4891 Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Wed, 10 Apr 2024 18:01:37 +0200 Subject: [PATCH] Some stability and WildFly 32 Beta1 related fixes. Removed dependency on wildfly-core --- .../glow/cli/ExecutionExceptionHandler.java | 7 +- .../glow/cli/commands/ScanCommand.java | 42 +++++---- core/pom.xml | 4 - .../main/java/org/wildfly/glow/Arguments.java | 13 ++- .../wildfly/glow/BaseArgumentsBuilder.java | 5 +- .../java/org/wildfly/glow/GlowSession.java | 31 ++++--- .../java/org/wildfly/glow/ScanArguments.java | 9 +- .../org/wildfly/glow/ScanResultsPrinter.java | 57 ++++++------ .../org/wildfly/glow/StabilitySupport.java | 53 +++++++++++ .../openshift/api/OpenShiftSupport.java | 90 +++++++++++++------ pom.xml | 19 +--- 11 files changed, 207 insertions(+), 123 deletions(-) create mode 100644 core/src/main/java/org/wildfly/glow/StabilitySupport.java diff --git a/cli/src/main/java/org/wildfly/glow/cli/ExecutionExceptionHandler.java b/cli/src/main/java/org/wildfly/glow/cli/ExecutionExceptionHandler.java index 41cacb69..98903fd6 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/ExecutionExceptionHandler.java +++ b/cli/src/main/java/org/wildfly/glow/cli/ExecutionExceptionHandler.java @@ -17,6 +17,7 @@ package org.wildfly.glow.cli; +import java.lang.reflect.InvocationTargetException; import org.wildfly.glow.cli.commands.AbstractCommand; import picocli.CommandLine; @@ -37,7 +38,11 @@ public ExecutionExceptionHandler(boolean isVerbose, AbstractCommand command) { @Override public int handleExecutionException(Exception ex, CommandLine commandLine, CommandLine.ParseResult parseResult) throws Exception { - command.printError("ERROR: %s", ex.getLocalizedMessage()); + String msg = ex.getLocalizedMessage(); + if (ex instanceof InvocationTargetException) { + msg = ex.getCause().getLocalizedMessage(); + } + command.printError("ERROR: %s", msg); if(isVerbose) { ex.printStackTrace(command.getStderr()); } diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java index 4da96ea1..2b3c2038 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java @@ -35,6 +35,7 @@ import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -42,7 +43,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import org.jboss.as.version.Stability; import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; import org.wildfly.channel.ChannelSession; @@ -55,6 +55,7 @@ import static org.wildfly.glow.OutputFormat.BOOTABLE_JAR; import static org.wildfly.glow.OutputFormat.DOCKER_IMAGE; import static org.wildfly.glow.OutputFormat.OPENSHIFT; +import org.wildfly.glow.StabilitySupport; import org.wildfly.glow.maven.ChannelMavenArtifactRepositoryManager; @CommandLine.Command( @@ -63,13 +64,6 @@ ) public class ScanCommand extends AbstractCommand { - private static class StabilityConverter implements CommandLine.ITypeConverter { - - @Override - public Stability convert(String value) throws Exception { - return Stability.fromString(value); - } - } private static class ProvisionConverter implements CommandLine.ITypeConverter { @Override @@ -122,14 +116,14 @@ public OutputFormat convert(String value) throws Exception { split = ",", paramLabel = Constants.EXCLUDE_ARCHIVES_FROM_SCAN_OPTION_LABEL) Set excludeArchivesFromScan = new HashSet<>(); - @CommandLine.Option(converter = StabilityConverter.class, names = {Constants.STABILITY_OPTION, Constants.STABILITY_OPTION_SHORT}, paramLabel = Constants.STABILITY_LABEL) - Optional stability; + @CommandLine.Option(names = {Constants.STABILITY_OPTION, Constants.STABILITY_OPTION_SHORT}, paramLabel = Constants.STABILITY_LABEL) + Optional stability; - @CommandLine.Option(converter = StabilityConverter.class, names = {Constants.PACKAGE_STABILITY_OPTION, Constants.PACKAGE_STABILITY_OPTION_SHORT}, paramLabel = Constants.STABILITY_LABEL) - Optional packageStability; + @CommandLine.Option(names = {Constants.PACKAGE_STABILITY_OPTION, Constants.PACKAGE_STABILITY_OPTION_SHORT}, paramLabel = Constants.STABILITY_LABEL) + Optional packageStability; - @CommandLine.Option(converter = StabilityConverter.class, names = {Constants.CONFIG_STABILITY_OPTION, Constants.CONFIG_STABILITY_OPTION_SHORT}, paramLabel = Constants.STABILITY_LABEL) - Optional configStability; + @CommandLine.Option(names = {Constants.CONFIG_STABILITY_OPTION, Constants.CONFIG_STABILITY_OPTION_SHORT}, paramLabel = Constants.STABILITY_LABEL) + Optional configStability; @CommandLine.Option(names = {Constants.ENV_FILE_OPTION_SHORT, Constants.ENV_FILE_OPTION}, paramLabel = Constants.ENV_FILE_OPTION_LABEL) Optional envFile; @@ -289,6 +283,10 @@ public Integer call() throws Exception { builder.setExecutionContext(CLOUD_EXECUTION_CONTEXT); } builder.setExcludeArchivesFromScan(excludeArchivesFromScan); + + // Enforce community stability level. Doing so, any discovered features at a lower level are advertised + String userSetConfigStability = null; + builder.setConfigStability(org.jboss.galleon.Constants.STABILITY_COMMUNITY); if (stability.isPresent()) { if (configStability.isPresent()) { throw new Exception(Constants.CONFIG_STABILITY_OPTION + " can't be set when " + Constants.STABILITY_OPTION + " is set"); @@ -296,13 +294,18 @@ public Integer call() throws Exception { if (packageStability.isPresent()) { throw new Exception(Constants.PACKAGE_STABILITY_OPTION + " can't be set when " + Constants.STABILITY_OPTION + " is set"); } + StabilitySupport.checkStability(stability.get()); + userSetConfigStability = stability.get(); builder.setConfigStability(stability.get()); builder.setPackageStability(stability.get()); } if (configStability.isPresent()) { + StabilitySupport.checkStability(configStability.get()); + userSetConfigStability = configStability.get(); builder.setConfigStability(configStability.get()); } if (packageStability.isPresent()) { + StabilitySupport.checkStability(packageStability.get()); builder.setPackageStability(packageStability.get()); } if (dockerImageName.isPresent()) { @@ -316,7 +319,7 @@ public Integer call() throws Exception { ConfigurationResolver configurationResolver = new ConfigurationResolver() { @Override public ResolvedEnvs getResolvedEnvs(Layer layer, Set input) throws Exception { - if(provision.get().equals(OPENSHIFT)) { + if(provision.isPresent() && provision.get().equals(OPENSHIFT)) { return OpenShiftSupport.getResolvedEnvs(layer, input, disableDeployers); } return null; @@ -435,7 +438,7 @@ public ResolvedEnvs getResolvedEnvs(Layer layer, Set input) throws Exceptio if (cloud.orElse(false)) { completedMessage = "@|bold To run the server call: 'JBOSS_HOME=" + rel + " sh " + rel + "/bin/openshift-launch.sh'|@"; } else { - completedMessage = "@|bold To run the server call: 'sh " + rel + "/bin/standalone.sh'|@"; + completedMessage = "@|bold To run the server call: 'sh " + rel + "/bin/standalone.sh" + (userSetConfigStability == null ? "" : " --stability=" + userSetConfigStability) + "'|@"; } break; } @@ -456,6 +459,9 @@ public ResolvedEnvs getResolvedEnvs(Layer layer, Set input) throws Exceptio envMap.put(env.getName(), env.getDescription()); } } + // We need the latest plugin, + // To be removed once WildFly Maven Plugin is released. + buildExtraEnv.put("PROVISIONING_MAVEN_PLUGIN_VERSION", "5.0.0.Beta5"); OpenShiftSupport.deploy(GlowMessageWriter.DEFAULT, target, name.isEmpty() ? "app-from-glow" : name.toLowerCase(), envMap, @@ -469,7 +475,9 @@ public ResolvedEnvs getResolvedEnvs(Layer layer, Set input) throws Exceptio initScriptFile.orElse(null), cliScriptFile.orElse(null), new OpenShiftConfiguration.Builder().build(), - directMavenResolver); + directMavenResolver, + userSetConfigStability, + Collections.emptyMap()); print("@|bold \nOpenshift build and deploy DONE.|@"); } else { if (content.getDockerImageName() != null) { diff --git a/core/pom.xml b/core/pom.xml index 32cc77ba..687dc40e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -54,10 +54,6 @@ org.jboss.galleon galleon-api - - org.wildfly.core - wildfly-version - org.wildfly.channel channel-core diff --git a/core/src/main/java/org/wildfly/glow/Arguments.java b/core/src/main/java/org/wildfly/glow/Arguments.java index 79f7b2a1..45b3a8d9 100644 --- a/core/src/main/java/org/wildfly/glow/Arguments.java +++ b/core/src/main/java/org/wildfly/glow/Arguments.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.Set; import java.util.regex.Pattern; -import org.jboss.as.version.Stability; import org.wildfly.channel.ChannelSession; public class Arguments implements GoOfflineArguments, ScanArguments { @@ -34,8 +33,8 @@ public class Arguments implements GoOfflineArguments, ScanArguments { private final boolean verbose; private final boolean techPreview; private final Set excludeArchivesFromScan; - private final Stability configStability; - private final Stability packageStability; + private final String configStability; + private final String packageStability; private final boolean isCli; private final ChannelSession channelSession; @@ -53,8 +52,8 @@ protected Arguments( boolean verbose, boolean techPreview, Set excludeArchivesFromScan, - Stability configStability, - Stability packageStability, + String configStability, + String packageStability, boolean isCli, ChannelSession channelSession) { this.executionProfiles = executionProfiles; @@ -189,12 +188,12 @@ public Set getExcludeArchivesFromScan() { } @Override - public Stability getConfigStability() { + public String getConfigStability() { return configStability; } @Override - public Stability getPackageStability() { + public String getPackageStability() { return packageStability; } diff --git a/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java b/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java index 8bfef38f..20d0b8ff 100644 --- a/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java +++ b/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java @@ -23,7 +23,6 @@ import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.jboss.as.version.Stability; import org.wildfly.channel.ChannelSession; public class BaseArgumentsBuilder { @@ -41,8 +40,8 @@ public class BaseArgumentsBuilder { protected boolean techPreview; protected Set excludeJarsFromScan = Collections.emptySet(); - protected Stability packageStability; - protected Stability configStability; + protected String packageStability; + protected String configStability; protected boolean isCli; protected ChannelSession channelSession; diff --git a/core/src/main/java/org/wildfly/glow/GlowSession.java b/core/src/main/java/org/wildfly/glow/GlowSession.java index 770cbe86..c9b2ba86 100644 --- a/core/src/main/java/org/wildfly/glow/GlowSession.java +++ b/core/src/main/java/org/wildfly/glow/GlowSession.java @@ -45,7 +45,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; -import org.jboss.as.version.Stability; import org.jboss.galleon.MessageWriter; import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec; import static org.wildfly.glow.OutputFormat.BOOTABLE_JAR; @@ -153,16 +152,17 @@ public ScanResults scan() throws Exception { provider.addArtifactResolver(resolver); Provisioning provisioning = null; GalleonProvisioningConfig config = Utils.buildOfflineProvisioningConfig(provider, writer); + Path fakeHome = Files.createTempDirectory("wildfly-glow"); try { if (config == null) { Path provisioningXML = arguments.getProvisioningXML(); if (provisioningXML == null) { provisioningXML = FeaturePacks.getFeaturePacks(arguments.getVersion(), arguments.getExecutionContext(), arguments.isTechPreview()); } - provisioning = provider.newProvisioningBuilder(provisioningXML).build(); + provisioning = provider.newProvisioningBuilder(provisioningXML).setInstallationHome(fakeHome).build(); config = provisioning.loadProvisioningConfig(provisioningXML); } else { - provisioning = provider.newProvisioningBuilder(config).build(); + provisioning = provider.newProvisioningBuilder(config).setInstallationHome(fakeHome).build(); } GalleonProvisioningConfig inputConfig = config; // Channel handling @@ -539,7 +539,7 @@ public ScanResults scan() throws Exception { for (Layer layer : checkLayers) { try { GalleonConfigurationWithLayers configLayers = GalleonConfigurationWithLayersBuilder.builder("standalone", "standalone.xml").includeLayer(layer.getName()).build(); - GalleonProvisioningConfig.Builder config2Builder = GalleonProvisioningConfig.builder().addConfig(configLayers); + GalleonProvisioningConfig.Builder config2Builder = GalleonProvisioningConfig.builder().addConfig(configLayers).addOption(Constants.CONFIG_STABILITY_LEVEL, Constants.STABILITY_EXPERIMENTAL); for (GalleonFeaturePackConfig fp : activeConfig.getFeaturePackDeps()) { config2Builder.addFeaturePackDep(GalleonFeaturePackConfig. builder(fp.getLocation(), false).setInheritConfigs(false).build()); @@ -549,8 +549,8 @@ public ScanResults scan() throws Exception { try (GalleonProvisioningRuntime rt = provisioning.getProvisioningRuntime(config2)) { List lst = rt.getAllFeatures(); for (GalleonFeatureSpec spec : lst) { - Stability stab = spec.getStability() == null ? null : Stability.fromString(spec.getStability()); - if (stab != null && !arguments.getConfigStability().enables(stab)) { + String stab = spec.getStability(); + if (stab != null && !StabilitySupport.enables(arguments.getConfigStability(), stab)) { Set set = excludedFeatures.get(layer); if (set == null) { set = new HashSet<>(); @@ -559,8 +559,8 @@ public ScanResults scan() throws Exception { set.add(spec.getName() + "[stability=" + spec.getStability() + "]"); } for (GalleonFeatureParamSpec pspec : spec.getParams()) { - Stability pstab = pspec.getStability() == null ? null : Stability.fromString(pspec.getStability()); - if (pstab != null && !arguments.getConfigStability().enables(pstab)) { + String pstab = pspec.getStability(); + if (pstab != null && !StabilitySupport.enables(arguments.getConfigStability(), pstab)) { Set set = excludedFeatures.get(layer); if (set == null) { set = new HashSet<>(); @@ -578,13 +578,17 @@ public ScanResults scan() throws Exception { } if(arguments.getPackageStability() != null) { // We must disable the stability to see all packages in the runtime - GalleonProvisioningConfig config2 = GalleonProvisioningConfig.builder(activeConfig).removeOption(Constants.STABILITY_LEVEL).build(); + GalleonProvisioningConfig config2 = GalleonProvisioningConfig.builder(activeConfig). + removeOption(Constants.STABILITY_LEVEL). + removeOption(Constants.CONFIG_STABILITY_LEVEL). + removeOption(Constants.PACKAGE_STABILITY_LEVEL). + addOption(Constants.STABILITY_LEVEL, arguments.getConfigStability() == null ? Constants.STABILITY_EXPERIMENTAL : arguments.getConfigStability()).build(); try (GalleonProvisioningRuntime rt = provisioning.getProvisioningRuntime(config2)) { for (GalleonFeaturePackRuntime fpr : rt.getGalleonFeaturePacks()) { for (GalleonPackageRuntime prt : fpr.getGalleonPackages()) { - Stability packageStability = prt.getStability() == null ? null : Stability.fromString(prt.getStability()); - if (packageStability != null && !arguments.getPackageStability().enables(packageStability)) { - excludedPackages.add(prt.getName() + "[stability="+packageStability.toString()+"]"); + String packageStability = prt.getStability(); + if (packageStability != null && !StabilitySupport.enables(arguments.getPackageStability(), packageStability)) { + excludedPackages.add(prt.getName() + "[stability="+packageStability+"]"); } } } @@ -613,6 +617,7 @@ public ScanResults scan() throws Exception { return scanResults; } finally { IoUtils.recursiveDelete(OFFLINE_CONTENT); + IoUtils.recursiveDelete(fakeHome); } } @@ -949,7 +954,7 @@ private static GalleonProvisioningConfig buildProvisioningConfig(GalleonProvisio Set decorators, Set excludedLayers, Map> fpDependencies, - String configName, Stability configStability, Stability packageStability) throws ProvisioningException { + String configName, String configStability, String packageStability) throws ProvisioningException { Map map = new HashMap<>(); Map universeToGav = new HashMap<>(); for (GalleonFeaturePackConfig cfg : input.getFeaturePackDeps()) { diff --git a/core/src/main/java/org/wildfly/glow/ScanArguments.java b/core/src/main/java/org/wildfly/glow/ScanArguments.java index c84a445e..74345aa0 100644 --- a/core/src/main/java/org/wildfly/glow/ScanArguments.java +++ b/core/src/main/java/org/wildfly/glow/ScanArguments.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Set; import java.util.regex.Pattern; -import org.jboss.as.version.Stability; import org.wildfly.channel.ChannelSession; public interface ScanArguments { @@ -75,8 +74,8 @@ public interface ScanArguments { Set getExcludeArchivesFromScan(); - Stability getConfigStability(); - Stability getPackageStability(); + String getConfigStability(); + String getPackageStability(); boolean isCli(); ChannelSession getChannelSession(); @@ -158,11 +157,11 @@ public Builder setExcludeArchivesFromScan(Set archives) { return this; } - public Builder setPackageStability(Stability stability) { + public Builder setPackageStability(String stability) { this.packageStability = stability; return this; } - public Builder setConfigStability(Stability stability) { + public Builder setConfigStability(String stability) { this.configStability = stability; return this; } diff --git a/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java b/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java index b3c46340..37472d11 100644 --- a/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java +++ b/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java @@ -143,36 +143,6 @@ private void detailed(ScanArguments arguments, ScanResults scanResults) throws E } writer.info(disabledBuilder); } - if (arguments.getConfigStability() != null || arguments.getPackageStability() != null) { - boolean needCR = false; - if (!scanResults.getExcludedFeatures().isEmpty()) { - writer.info("The following features would be disabled if provisioning a server at the '" - + arguments.getConfigStability().toString() + "' stability level for configs:"); - needCR = true; - } - if(!scanResults.getExcludedPackages().isEmpty()) { - writer.info("The following packages would be disabled if provisioning a server at the '" - + arguments.getPackageStability().toString() + "' stability level for packages:"); - needCR = true; - } - if (!scanResults.getExcludedFeatures().isEmpty()) { - for (Layer l : scanResults.getExcludedFeatures().keySet()) { - writer.info(l.getName() + " features:"); - for (String f : scanResults.getExcludedFeatures().get(l)) { - writer.info("- " + f); - } - } - } - if (!scanResults.getExcludedPackages().isEmpty()) { - writer.info("packages:"); - for (String p : scanResults.getExcludedPackages()) { - writer.info("- " + p); - } - } - if (needCR) { - writer.info(""); - } - } List fixBuilders = new ArrayList<>(); List errorBuilders = new ArrayList<>(); List warnBuilders = new ArrayList<>(); @@ -234,7 +204,32 @@ private void detailed(ScanArguments arguments, ScanResults scanResults) throws E } writer.warn(""); } - + if (arguments.getConfigStability() != null || arguments.getPackageStability() != null) { + boolean needCR = false; + if (!scanResults.getExcludedFeatures().isEmpty()) { + writer.warn("The following features would be disabled if provisioning a server at the '" + + arguments.getConfigStability() + "' stability level. Make sure to set the '--config-stability-level=' option:"); + needCR = true; + for (Layer l : scanResults.getExcludedFeatures().keySet()) { + writer.warn(l.getName() + " features:"); + for (String f : scanResults.getExcludedFeatures().get(l)) { + writer.warn("- " + f); + } + } + } + if (!scanResults.getExcludedPackages().isEmpty()) { + writer.warn("The following packages would be disabled if provisioning a server at the '" + + arguments.getPackageStability() + "' stability level for packages:"); + needCR = true; + writer.warn("packages:"); + for (String p : scanResults.getExcludedPackages()) { + writer.warn("- " + p); + } + } + if (needCR) { + writer.info(""); + } + } String suggestedConfigs = buildSuggestions(scanResults.getSuggestions().getSuggestedConfigurations()); String suggestedBuildTimeConfigs = buildSuggestions(scanResults.getSuggestions().getBuildTimeConfigurations()); diff --git a/core/src/main/java/org/wildfly/glow/StabilitySupport.java b/core/src/main/java/org/wildfly/glow/StabilitySupport.java new file mode 100644 index 00000000..b48b2a62 --- /dev/null +++ b/core/src/main/java/org/wildfly/glow/StabilitySupport.java @@ -0,0 +1,53 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wildfly.glow; + +import java.lang.reflect.Method; +import java.net.URLClassLoader; +import org.jboss.galleon.api.APIVersion; +import org.jboss.galleon.api.GalleonBuilder; + +/** + * + * @author jdenise + */ +public class StabilitySupport { + + private static final String STABILITY_CLASS_NAME = "org.jboss.galleon.Stability"; + private static final String STABILITY_FROM_METHOD = "fromString"; + private static final String STABILITY_ENABLES_METHOD = "enables"; + + public static boolean enables(String stability1, String stability2) throws Exception { + GalleonBuilder builder = new GalleonBuilder(); + URLClassLoader loader = builder.getCoreClassLoader(APIVersion.getVersion()); + Class clazz = loader.loadClass(STABILITY_CLASS_NAME); + Method m = clazz.getMethod(STABILITY_FROM_METHOD, String.class); + Object stab1 = m.invoke(null, stability1); + Object stab2 = m.invoke(null, stability2); + Method enables = clazz.getMethod(STABILITY_ENABLES_METHOD, clazz); + Boolean b = (Boolean) enables.invoke(stab1, stab2); + return b; + } + + public static void checkStability(String stability) throws Exception { + GalleonBuilder builder = new GalleonBuilder(); + URLClassLoader loader = builder.getCoreClassLoader(APIVersion.getVersion()); + Class clazz = loader.loadClass(STABILITY_CLASS_NAME); + Method from = clazz.getMethod(STABILITY_FROM_METHOD, String.class); + from.invoke(null, stability); + } +} diff --git a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java index d7de7f4e..ca88cf4c 100644 --- a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java +++ b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java @@ -124,9 +124,10 @@ boolean isFailed() { public void close() throws Exception { } } - private static void createAppDeployment(GlowMessageWriter writer, Path target, OpenShiftClient osClient, String name, Map env, boolean ha) throws Exception { - Map labels = new HashMap<>(); - labels.put(Deployer.LABEL, name); + private static void createAppDeployment(GlowMessageWriter writer, Path target, + OpenShiftClient osClient, String name, Map env, boolean ha, OpenShiftConfiguration config) throws Exception { + Map matchLabels = new HashMap<>(); + matchLabels.put(Deployer.LABEL, name); ContainerPort port = new ContainerPort(); port.setContainerPort(8080); port.setName("http"); @@ -146,12 +147,9 @@ private static void createAppDeployment(GlowMessageWriter writer, Path target, O } if (ha) { writer.info("\n HA enabled, 2 replicas will be started."); - vars.add(new EnvVar().toBuilder().withName("JGROUPS_PING_PROTOCOL").withValue("DNS_PING").build()); - vars.add(new EnvVar().toBuilder().withName("OPENSHIFT_DNS_PING_SERVICE_PORT").withValue("8888").build()); - vars.add(new EnvVar().toBuilder().withName("OPENSHIFT_DNS_PING_SERVICE_NAME").withValue(name + "-ping").build()); IntOrString v = new IntOrString(); v.setValue(8888); - Service pingService = new ServiceBuilder().withNewMetadata().withName(name + "-ping").endMetadata(). + Service pingService = new ServiceBuilder().withNewMetadata().withLabels(createCommonLabels(config)).withName(name + "-ping").endMetadata(). withNewSpec().withPorts(new ServicePort().toBuilder().withProtocol("TCP"). withPort(8888). withName("ping"). @@ -159,7 +157,7 @@ private static void createAppDeployment(GlowMessageWriter writer, Path target, O withClusterIP("None").withPublishNotReadyAddresses().withIpFamilies("IPv4"). withInternalTrafficPolicy("Cluster").withClusterIPs("None"). withType("ClusterIP").withIpFamilyPolicy("SingleStack"). - withSessionAffinity("None").withSelector(labels).endSpec().build(); + withSessionAffinity("None").withSelector(matchLabels).endSpec().build(); osClient.services().resource(pingService).createOr(NonDeletingOperation::update); Utils.persistResource(target, pingService, name + "-ping-service.yaml"); } @@ -197,9 +195,11 @@ private static void createAppDeployment(GlowMessageWriter writer, Path target, O livenessProbe.setFailureThreshold(3); container.setLivenessProbe(livenessProbe); - Deployment deployment = new DeploymentBuilder().withNewMetadata().withName(name).endMetadata(). + Map labels = createCommonLabels(config); + labels.putAll(matchLabels); + Deployment deployment = new DeploymentBuilder().withNewMetadata().withLabels(labels).withName(name).endMetadata(). withNewSpec().withReplicas(ha ? 2 : 1). - withNewSelector().withMatchLabels(labels).endSelector(). + withNewSelector().withMatchLabels(matchLabels).endSelector(). withNewTemplate().withNewMetadata().withLabels(labels).endMetadata().withNewSpec(). withContainers(container).withRestartPolicy("Always"). endSpec().endTemplate().withNewStrategy().withType("RollingUpdate").endStrategy().endSpec().build(); @@ -207,10 +207,10 @@ private static void createAppDeployment(GlowMessageWriter writer, Path target, O Utils.persistResource(target, deployment, name + "-deployment.yaml"); IntOrString v = new IntOrString(); v.setValue(8080); - Service service = new ServiceBuilder().withNewMetadata().withName(name).endMetadata(). + Service service = new ServiceBuilder().withNewMetadata().withLabels(createCommonLabels(config)).withName(name).endMetadata(). withNewSpec().withPorts(new ServicePort().toBuilder().withProtocol("TCP"). withPort(8080). - withTargetPort(v).build()).withType("ClusterIP").withSessionAffinity("None").withSelector(labels).endSpec().build(); + withTargetPort(v).build()).withType("ClusterIP").withSessionAffinity("None").withSelector(matchLabels).endSpec().build(); osClient.services().resource(service).createOr(NonDeletingOperation::update); Utils.persistResource(target, service, name + "-service.yaml"); @@ -270,7 +270,9 @@ public static void deploy(GlowMessageWriter writer, Path initScript, Path cliScript, OpenShiftConfiguration config, - MavenRepoManager mvnResolver) throws Exception { + MavenRepoManager mvnResolver, + String stability, + Map serverImageBuildLabels) throws Exception { Set allLayers = new LinkedHashSet<>(); allLayers.addAll(layers); allLayers.addAll(metadataOnlyLayers); @@ -279,7 +281,7 @@ public static void deploy(GlowMessageWriter writer, OpenShiftClient osClient = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class); writer.info("\nConnected to OpenShift cluster"); // First create the future route to the application, can be needed by deployers - Route route = new RouteBuilder().withNewMetadata().withName(appName). + Route route = new RouteBuilder().withNewMetadata().withLabels(createCommonLabels(config)).withName(appName). endMetadata().withNewSpec(). withTo(new RouteTargetReference("Service", appName, 100)). withTls(new TLSConfig().toBuilder().withTermination("edge"). @@ -315,19 +317,41 @@ public static void deploy(GlowMessageWriter writer, } actualEnv.put("APPLICATION_ROUTE_HOST", host); actualEnv.putAll(extraEnv); + if (stability != null) { + String val = actualEnv.get("SERVER_ARGS"); + String stabilityOption = "--stability=" + stability; + boolean alreadySet = false; + if (val == null) { + val = stabilityOption; + } else { + if (val.contains("--stability")) { + alreadySet = true; + } else { + val += " --stability" + stability; + } + } + if (!alreadySet) { + actualEnv.put("SERVER_ARGS", val); + } + } if (!disabledDeployers.isEmpty()) { writer.warn("The following environment variables will be set in the " + appName + " deployment. Make sure that the required env variables for the disabled deployer(s) have been set:\n"); } else { writer.warn("The following environment variables will be set in the " + appName + " deployment:\n"); } + if (ha) { + actualEnv.put("JGROUPS_PING_PROTOCOL", "openshift.DNS_PING"); + actualEnv.put("OPENSHIFT_DNS_PING_SERVICE_PORT", "8888"); + actualEnv.put("OPENSHIFT_DNS_PING_SERVICE_NAME", appName + "-ping"); + } for (Entry entry : actualEnv.entrySet()) { writer.warn(entry.getKey() + "=" + entry.getValue()); } // Can be overriden by user actualBuildEnv.putAll(buildExtraEnv); - createBuild(writer, target, osClient, appName, initScript, cliScript, actualBuildEnv, config); + createBuild(writer, target, osClient, appName, initScript, cliScript, actualBuildEnv, config, serverImageBuildLabels); writer.info("Deploying application image on OpenShift"); - createAppDeployment(writer, target, osClient, appName, actualEnv, ha); + createAppDeployment(writer, target, osClient, appName, actualEnv, ha, config); writer.info("Application route: https://" + host + ("ROOT.war".equals(appName) ? "" : "/" + appName)); } @@ -338,8 +362,9 @@ private static void createBuild(GlowMessageWriter writer, Path initScript, Path cliScript, Map buildExtraEnv, - OpenShiftConfiguration config) throws Exception { - String serverImageName = doServerImageBuild(writer, target, osClient, buildExtraEnv, config); + OpenShiftConfiguration config, + Map serverImageBuildLabels) throws Exception { + String serverImageName = doServerImageBuild(writer, target, osClient, buildExtraEnv, config, serverImageBuildLabels); doAppImageBuild(serverImageName, writer, target, osClient, name, initScript, cliScript, config); } @@ -384,7 +409,14 @@ private static String bytesToHex(byte[] hash) { return hexString.toString(); } - private static Map createLabels(Path target, Path provisioning, OpenShiftConfiguration osConfig) throws Exception { + private static Map createCommonLabels(OpenShiftConfiguration osConfig) throws Exception { + Map labels = new HashMap<>(); + labels.put(osConfig.getLabelRadical(), ""); + return labels; + } + + private static Map createServerImageLabels(Path target, Path provisioning, OpenShiftConfiguration osConfig, + Map serverImageBuildLabels) throws Exception { GalleonBuilder provider = new GalleonBuilder(); Path dir = target.resolve("tmp").resolve("tmpHome"); Files.createDirectory(dir); @@ -410,15 +442,21 @@ private static Map createLabels(Path target, Path provisioning, producerName = producerName.substring(i + 1); } producerName = producerName.replaceAll(":", "-"); - labels.put(osConfig.getLabelRadical() + ".feature-pack." + producerName, ""); + labels.put(osConfig.getLabelRadical() + ".feature-pack." + producerName, gfpc.getLocation().getBuild()); } } + + for (Entry entry : serverImageBuildLabels.entrySet()) { + labels.put(entry.getKey(), entry.getValue()); + } + labels.putAll(createCommonLabels(osConfig)); return labels; } private static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShiftClient osClient, Map buildExtraEnv, - OpenShiftConfiguration config) throws Exception { + OpenShiftConfiguration config, + Map serverImageBuildLabels) throws Exception { // To compute a hash we need build time env variables StringBuilder contentBuilder = new StringBuilder(); Path provisioning = target.resolve("galleon").resolve("provisioning.xml"); @@ -431,7 +469,7 @@ private static String doServerImageBuild(GlowMessageWriter writer, Path target, String key = bytesToHex(encodedhash); String serverImageName = config.getServerImageNameRadical() + key; - ImageStream stream = new ImageStreamBuilder().withNewMetadata().withName(serverImageName). + ImageStream stream = new ImageStreamBuilder().withNewMetadata().withLabels(createCommonLabels(config)).withName(serverImageName). endMetadata().withNewSpec().withLookupPolicy(new ImageLookupPolicy(Boolean.TRUE)).endSpec().build(); // check if it exists ImageStream existingStream = osClient.imageStreams().resource(stream).get(); @@ -447,7 +485,7 @@ private static String doServerImageBuild(GlowMessageWriter writer, Path target, Files.createDirectories(stepOne); IoUtils.copy(target.resolve("galleon"), stepOne.resolve("galleon")); ZipUtils.zip(stepOne, file); - stream = stream.toBuilder().editOrNewMetadata().withLabels(createLabels(target, provisioning, config)).endMetadata().build(); + stream = stream.toBuilder().editOrNewMetadata().withLabels(createServerImageLabels(target, provisioning, config, serverImageBuildLabels)).endMetadata().build(); osClient.imageStreams().resource(stream).createOr(NonDeletingOperation::update); Utils.persistResource(target, stream, serverImageName + "-image-stream.yaml"); BuildConfigBuilder builder = new BuildConfigBuilder(); @@ -465,7 +503,7 @@ private static String doServerImageBuild(GlowMessageWriter writer, Path target, } } BuildConfig buildConfig = builder. - withNewMetadata().withName(serverImageName + "-build").endMetadata().withNewSpec(). + withNewMetadata().withLabels(createCommonLabels(config)).withName(serverImageName + "-build").endMetadata().withNewSpec(). withNewOutput(). withNewTo(). withKind("ImageStreamTag"). @@ -523,7 +561,7 @@ private static void doAppImageBuild(String serverImageName, } ZipUtils.zip(stepTwo, file2); writer.info("\nBuilding application image..."); - ImageStream appStream = new ImageStreamBuilder().withNewMetadata().withName(name). + ImageStream appStream = new ImageStreamBuilder().withNewMetadata().withLabels(createCommonLabels(config)).withName(name). endMetadata().withNewSpec().withLookupPolicy(new ImageLookupPolicy(Boolean.TRUE)).endSpec().build(); osClient.imageStreams().resource(appStream).createOr(NonDeletingOperation::update); BuildConfigBuilder builder = new BuildConfigBuilder(); @@ -533,7 +571,7 @@ private static void doAppImageBuild(String serverImageName, ImageSourcePath srcPath = new ImageSourcePathBuilder().withSourcePath("/opt/server").withDestinationDir(".").build(); ImageSource imageSource = new ImageSourceBuilder().withFrom(ref).withPaths(srcPath).build(); BuildConfig buildConfig2 = builder. - withNewMetadata().withName(name + "-build").endMetadata().withNewSpec(). + withNewMetadata().withLabels(createCommonLabels(config)).withName(name + "-build").endMetadata().withNewSpec(). withNewOutput(). withNewTo(). withKind("ImageStreamTag"). diff --git a/pom.xml b/pom.xml index 18221b9b..d17c42c0 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 4.7.5 9.5 6.4.0 - 1.0.0.Beta2 + 1.0.0.Final 1.7.0.Final 8.18 2.14.2 @@ -29,9 +29,8 @@ 3.8.6 3.0.0 1.6.3 - 6.0.0.Beta6 + 6.0.0.Final 1.0.5.Final - 24.0.0.Beta1 1.2.1.Final 2.0 3.12.0 @@ -57,7 +56,7 @@ true - 7.0.0.Beta7 + 7.0.0.Final 2.1.1 4.0.1 4.0.1 @@ -297,18 +296,6 @@ wildfly-common ${version.org.wildfly.common.wildfly-common} - - - org.wildfly.core - wildfly-version - ${version.org.wildfly.core} - - - * - * - - - org.wildfly.galleon-plugins wildfly-galleon-plugins