|
| 1 | +/** |
| 2 | +* Copyright (C) 2026 Red Hat, Inc. |
| 3 | +* |
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +* you may not use this file except in compliance with the License. |
| 6 | +* You may obtain a copy of the License at |
| 7 | +* |
| 8 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +* |
| 10 | +* Unless required by applicable law or agreed to in writing, software |
| 11 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +* See the License for the specific language governing permissions and |
| 14 | +* limitations under the License. |
| 15 | +*/ |
| 16 | +package org.jboss.intersmash.tests.wildfly.distributed.timers.infinispan; |
| 17 | + |
| 18 | +import com.google.common.base.Strings; |
| 19 | +import cz.xtf.builder.builders.SecretBuilder; |
| 20 | +import cz.xtf.core.openshift.OpenShifts; |
| 21 | +import io.fabric8.kubernetes.api.model.EnvVar; |
| 22 | +import io.fabric8.kubernetes.api.model.EnvVarBuilder; |
| 23 | +import io.fabric8.kubernetes.api.model.Secret; |
| 24 | +import java.io.IOException; |
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.Collections; |
| 27 | +import java.util.List; |
| 28 | +import org.jboss.intersmash.IntersmashConfig; |
| 29 | +import org.jboss.intersmash.application.input.BuildInput; |
| 30 | +import org.jboss.intersmash.application.input.BuildInputBuilder; |
| 31 | +import org.jboss.intersmash.application.openshift.WildflyImageOpenShiftApplication; |
| 32 | +import org.jboss.intersmash.tests.wildfly.WildflyApplicationConfiguration; |
| 33 | +import org.jboss.intersmash.util.CommandLineBasedKeystoreGenerator; |
| 34 | + |
| 35 | +/** |
| 36 | + * Set up a WildFly/JBoss EAP 8 application that starts a configured server, which configures Infinispan distributed |
| 37 | + * timers on a remote Infinispan cluster. |
| 38 | + */ |
| 39 | +public class WildFlyDistributedTimersApplication |
| 40 | + implements WildflyImageOpenShiftApplication, WildflyApplicationConfiguration { |
| 41 | + |
| 42 | + public static final String NAME = "distributed-ejb-timers"; |
| 43 | + private final BuildInput buildInput; |
| 44 | + final String applicationDir = "wildfly/distributed-timers-infinispan"; |
| 45 | + private final List<EnvVar> environmentVariables = new ArrayList<>(); |
| 46 | + private final List<Secret> secrets = new ArrayList<>(); |
| 47 | + |
| 48 | + public WildFlyDistributedTimersApplication() throws IOException { |
| 49 | + |
| 50 | + final String truststorePassword = CommandLineBasedKeystoreGenerator.getPassword(); |
| 51 | + // Set up client OpenShift secret for SSL |
| 52 | + secrets.add(new SecretBuilder("infinispan-client-secret") |
| 53 | + .addData("truststore.jks", CommandLineBasedKeystoreGenerator.getTruststore()) |
| 54 | + .addRawData("trustStorePassword", truststorePassword) |
| 55 | + .build()); |
| 56 | + |
| 57 | + // Set the build input |
| 58 | + buildInput = new BuildInputBuilder() |
| 59 | + .uri(IntersmashConfig.deploymentsRepositoryUrl()) |
| 60 | + .ref(IntersmashConfig.deploymentsRepositoryRef()) |
| 61 | + .build(); |
| 62 | + |
| 63 | + // configure KUBE_PING, an invalidation-cache requires a functioning JGroups cluster. |
| 64 | + environmentVariables.add(new EnvVarBuilder() |
| 65 | + .withName("KUBERNETES_NAMESPACE") |
| 66 | + .withValue(OpenShifts.master().getNamespace()) |
| 67 | + .build()); |
| 68 | + |
| 69 | + // set up environment variables |
| 70 | + environmentVariables.add(new EnvVarBuilder() |
| 71 | + .withName("JDG_HOST") |
| 72 | + .withValue("$(RHDG_SERVICE_HOST)") |
| 73 | + .build()); |
| 74 | + environmentVariables.add(new EnvVarBuilder() |
| 75 | + .withName("JDG_PORT") |
| 76 | + .withValue("$(RHDG_SERVICE_PORT)") |
| 77 | + .build()); |
| 78 | + environmentVariables.add(new EnvVarBuilder() |
| 79 | + .withName("TRUSTSTORE_PASSWORD") |
| 80 | + .withValue(truststorePassword) |
| 81 | + .build()); |
| 82 | + |
| 83 | + // credentials from Infinispan/Red Hat Data Grid custom secret |
| 84 | + environmentVariables.add(new EnvVarBuilder() |
| 85 | + .withName("CACHE_USERNAME") |
| 86 | + .withValue(InfinispanOperatorWithExternalRouteApplication.INFINISPAN_CUSTOM_CREDENTIALS_USERNAME) |
| 87 | + .build()); |
| 88 | + environmentVariables.add(new EnvVarBuilder() |
| 89 | + .withName("CACHE_PASSWORD") |
| 90 | + .withValue(InfinispanOperatorWithExternalRouteApplication.INFINISPAN_CUSTOM_CREDENTIALS_PASSWORD) |
| 91 | + .build()); |
| 92 | + environmentVariables.add(new EnvVarBuilder() |
| 93 | + .withName("TIMER_EXPIRATION_API_BASE_URL") |
| 94 | + .withValue("http://timer-expiration-store:8080").build()); |
| 95 | + |
| 96 | + // More env vars |
| 97 | + // TODO: this appears in many application descriptors that implement WildflyImageOpenShiftApplication and |
| 98 | + // WildflyApplicationConfiguration, therefore it might be refactored into a unique interface method |
| 99 | + environmentVariables.add( |
| 100 | + new EnvVarBuilder().withName("MAVEN_S2I_ARTIFACT_DIRS") |
| 101 | + .withValue(applicationDir + "/target") |
| 102 | + .build()); |
| 103 | + |
| 104 | + String mavenAdditionalArgs = generateAdditionalMavenArgs() |
| 105 | + .concat(" -pl " + applicationDir + " -am"); |
| 106 | + |
| 107 | + final String mavenMirrorUrl = this.getMavenMirrorUrl(); |
| 108 | + if (!Strings.isNullOrEmpty(mavenMirrorUrl)) { |
| 109 | + environmentVariables.add( |
| 110 | + new EnvVarBuilder().withName("MAVEN_MIRROR_URL") |
| 111 | + .withValue(mavenMirrorUrl) |
| 112 | + .build()); |
| 113 | + mavenAdditionalArgs = mavenAdditionalArgs.concat(" -Dinsecure.repositories=WARN"); |
| 114 | + } |
| 115 | + |
| 116 | + environmentVariables.add( |
| 117 | + new EnvVarBuilder().withName("MAVEN_ARGS_APPEND") |
| 118 | + .withValue(mavenAdditionalArgs) |
| 119 | + .build()); |
| 120 | + |
| 121 | + environmentVariables.add(new EnvVarBuilder() |
| 122 | + .withName("SCRIPT_DEBUG").withValue(IntersmashConfig.scriptDebug()).build()); |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + public String getName() { |
| 127 | + return NAME; |
| 128 | + } |
| 129 | + |
| 130 | + @Override |
| 131 | + public BuildInput getBuildInput() { |
| 132 | + return buildInput; |
| 133 | + } |
| 134 | + |
| 135 | + @Override |
| 136 | + public List<EnvVar> getEnvVars() { |
| 137 | + return Collections.unmodifiableList(environmentVariables); |
| 138 | + } |
| 139 | + |
| 140 | + @Override |
| 141 | + public List<Secret> getSecrets() { |
| 142 | + return secrets; |
| 143 | + } |
| 144 | +} |
0 commit comments