Skip to content

Commit

Permalink
[issue 80] - Adding WildFly Jakarta EE 8/EAP 7.z template based provi…
Browse files Browse the repository at this point in the history
…sioner
  • Loading branch information
fabiobrz committed Oct 26, 2023
1 parent 074145f commit dca6a26
Show file tree
Hide file tree
Showing 12 changed files with 563 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .ci/openshift-ci/build-root/e2e-test-prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ mvn test -Dmaven.repo.local=./local-repo-prod -pl testsuite/ -Pts.prod \
-Dintersmash.wildfly.helm.charts.name=eap8 \
-Dintersmash.eap7.image=registry.redhat.io/jboss-eap-7/eap74-openjdk17-openshift-rhel8:latest \
-Dintersmash.eap7.runtime.image=registry.redhat.io/jboss-eap-7/eap74-openjdk17-runtime-openshift-rhel8:latest \
-Dintersmash.eap7.templates.base.url=https://raw.githubusercontent.com/jboss-container-images/jboss-eap-openshift-templates/eap74/ \
-Dintersmash.eap7.templates.path=templates/ \
-Dintersmash.activemq.image=registry.redhat.io/amq7/amq-broker-rhel8:7.11.0 \
-Dintersmash.activemq.init.image=registry.redhat.io/amq7/amq-broker-init-rhel8:7.11.0 \
-Dintersmash.activemq.operators.catalog_source=redhat-operators \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.jboss.intersmash.testsuite.junit5.categories;

import org.junit.jupiter.api.Tag;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.Tag;

/**
* Mark a test that does not support community deliverables.
* Used per class.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.jboss.intersmash.testsuite.provision.openshift;

import java.util.Optional;

import org.assertj.core.api.Assertions;
import org.assertj.core.api.SoftAssertions;
import org.jboss.intersmash.testsuite.junit5.categories.NotForCommunityExecutionProfile;
import org.jboss.intersmash.tools.application.openshift.Eap7TemplateOpenShiftApplication;
import org.jboss.intersmash.tools.provision.openshift.Eap7TemplateOpenShiftProvisioner;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import cz.xtf.core.openshift.OpenShift;
import cz.xtf.core.openshift.OpenShifts;
import cz.xtf.core.openshift.PodShell;
import cz.xtf.core.openshift.PodShellOutput;
import cz.xtf.junit5.annotations.CleanBeforeAll;
import io.fabric8.openshift.api.model.BuildConfig;
import io.fabric8.openshift.api.model.GitBuildSource;

@CleanBeforeAll
@NotForCommunityExecutionProfile
public class Eap7TemplateProvisionerTestCase {
private static final OpenShift openShift = OpenShifts.master();
private static final Eap7TemplateOpenShiftApplication application = OpenShiftProvisionerTestBase
.getEap7OpenShiftTemplateApplication();
private static final Eap7TemplateOpenShiftProvisioner provisioner = new Eap7TemplateOpenShiftProvisioner(application);

@BeforeAll
public static void deploy() {
provisioner.preDeploy();
provisioner.deploy();
}

@AfterAll
public static void undeploy() {
provisioner.undeploy();
provisioner.postUndeploy();
}

@Test
public void verifyEapConfiguration() {
SoftAssertions softAssertions = new SoftAssertions();
// verify system property added via cli
PodShell rsh = new PodShell(openShift, openShift.getAnyPod(application.getName()));
PodShellOutput output = rsh
.executeWithBash(String.format("$JBOSS_HOME/bin/jboss-cli.sh -c /system-property=%s:read-resource",
OpenShiftProvisionerTestBase.WILDFLY_TEST_PROPERTY));
softAssertions.assertThat(output.getError()).as("CLI configuration check: Error should be empty").isEmpty();
softAssertions.assertThat(output.getOutput()).as("CLI configuration check: Test property was not set by CLI")
.contains("success", OpenShiftProvisionerTestBase.WILDFLY_TEST_PROPERTY);

// verify application git
Optional<BuildConfig> gitBuildConfig = openShift.buildConfigs().list().getItems().stream()
.filter(buildConfig -> buildConfig.getSpec().getSource().getType().equals("Git"))
.findFirst();
softAssertions.assertThat(gitBuildConfig.isPresent()).as("Cannot find a Git build config").isTrue();
if (gitBuildConfig.isPresent()) {
softAssertions.assertThat(gitBuildConfig.get().getMetadata().getName()).contains(application.getName());
GitBuildSource git = gitBuildConfig.get().getSpec().getSource().getGit();
softAssertions.assertThat(git.getUri()).as("Git repository check")
.isEqualTo(OpenShiftProvisionerTestBase.EAP7_TEST_APP_REPO);
softAssertions.assertThat(git.getRef()).as("Git repository reference check")
.isEqualTo(OpenShiftProvisionerTestBase.EAP7_TEST_APP_REF);
}
softAssertions.assertAll();
}

/**
* Any {@code Secret} or {@code ConfigMap} should be created as a preDeploy() operation by a provisioner.
*/
@Test
public void verifyDeployHooks() {
Assertions.assertThat(openShift.getSecret(OpenShiftProvisionerTestBase.TEST_SECRET.getMetadata().getName()))
.isNotNull();
}

@Test
public void scale() {
provisioner.scale(1, true);
openShift.waiters().areExactlyNPodsReady(1, application.getName()).waitFor();
provisioner.scale(2, true);
openShift.waiters().areExactlyNPodsReady(2, application.getName()).waitFor();
}

@Test
public void pods() {
provisioner.scale(2, true);
Assertions.assertThat(provisioner.getPods().size()).isEqualTo(2);
provisioner.scale(3, true);
Assertions.assertThat(provisioner.getPods().size()).isEqualTo(3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@
import org.jboss.intersmash.testsuite.IntersmashTestsuiteProperties;
import org.jboss.intersmash.tools.IntersmashConfig;
import org.jboss.intersmash.tools.application.openshift.BootableJarOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.Eap7ImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.Eap7TemplateOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.KafkaOperatorApplication;
import org.jboss.intersmash.tools.application.openshift.MysqlImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.PostgreSQLImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.WildflyImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.Eap7ImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.input.BinarySource;
import org.jboss.intersmash.tools.application.openshift.input.BuildInput;
import org.jboss.intersmash.tools.application.openshift.input.BuildInputBuilder;
import org.jboss.intersmash.tools.application.openshift.template.Eap7Template;
import org.jboss.intersmash.tools.util.wildfly.Eap7CliScriptBuilder;

import cz.xtf.builder.builders.SecretBuilder;
Expand Down Expand Up @@ -78,6 +80,44 @@ public class OpenShiftProvisionerTestBase {
static final String EAP7_TEST_APP_REPO = "https://github.com/openshift/openshift-jee-sample.git";
static final String EAP7_TEST_APP_REF = "master";

static Eap7TemplateOpenShiftApplication getEap7OpenShiftTemplateApplication() {
return new Eap7TemplateOpenShiftApplication() {

@Override
public List<String> getCliScript() {
Eap7CliScriptBuilder eapCliScriptBuilder = new Eap7CliScriptBuilder();
eapCliScriptBuilder.addCommand(
String.format("/system-property=%s:add(value=\"%s\")", WILDFLY_TEST_PROPERTY, WILDFLY_TEST_PROPERTY));
return eapCliScriptBuilder.build();
}

@Override
public Map<String, String> getParameters() {
Map<String, String> map = new HashMap<>();
map.put("SOURCE_REPOSITORY_URL", EAP7_TEST_APP_REPO);
map.put("SOURCE_REPOSITORY_REF", EAP7_TEST_APP_REF);
return Collections.unmodifiableMap(map);
}

@Override
public List<Secret> getSecrets() {
List<Secret> secrets = new ArrayList<>();
secrets.add(TEST_SECRET);
return Collections.unmodifiableList(secrets);
}

@Override
public Eap7Template getTemplate() {
return Eap7Template.BASIC;
}

@Override
public String getName() {
return "eap-test-app";
}
};
}

static BootableJarOpenShiftApplication getWildflyBootableJarOpenShiftApplication() {
return new BootableJarOpenShiftApplication() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public class IntersmashConfig {
// EAP 7.z (i.e. Jakarta EE 8 based WildFly)
private static final String EAP7_IMAGE_URL = "intersmash.eap7.image";
private static final String EAP7_RUNTIME_IMAGE_URL = "intersmash.eap7.runtime.image";
private static final String EAP7_TEMPLATES_BASE_URL = "intersmash.eap7.templates.base.url";
private static final String EAP7_TEMPLATES_PATH = "intersmash.eap7.templates.path";

// WildFLy Maven Plugin
private static final String WILDFLY_MAVEN_PLUGIN_GROUPID = "wildfly-maven-plugin.groupId";
Expand Down Expand Up @@ -258,10 +260,18 @@ public static String eap7RuntimeImageUrl() {
return XTFConfig.get(EAP7_RUNTIME_IMAGE_URL);
}

public static String wildflyJakartaEe8ProductCode() {
public static String eap7ProductCode() {
return getProductCode(eap7ImageURL());
}

public static String eap7Templates() {
return XTFConfig.get(EAP7_TEMPLATES_BASE_URL) + XTFConfig.get(EAP7_TEMPLATES_PATH);
}

public static String eap7ImageStreams() {
return XTFConfig.get(EAP7_TEMPLATES_BASE_URL);
}

public static String getProductCode(final String image) {
// truncates "-"
// e.g. ..fspolti/processserver64-eap70-openshift:1.3 -> processserver64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import cz.xtf.core.openshift.OpenShifts;
import io.fabric8.openshift.api.model.ImageStream;
import io.fabric8.openshift.api.model.Template;
import io.fabric8.openshift.client.dsl.TemplateResource;

/**
* Provisioner for OpenShift templates. Its goal is to unify the basic operations we need to do with OpenShift templates.
Expand Down Expand Up @@ -91,7 +90,7 @@ default Template deployTemplate(OpenShiftTemplate openShiftTemplate) {
String url = getTemplateFileUrl(openShiftTemplate);
try (InputStream is = new URL(url).openStream()) {
// workaround for the API version in the data (v1) does not match the expected API version (image.template.io/v1)
template = (Template) ((TemplateResource) openShift.templates().load(is)).get();
template = openShift.templates().load(is).item();
template.setApiVersion("template.openshift.io/v1");
if (openShift.getTemplate(template.getMetadata().getName()) == null) {
openShift.createTemplate(template);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.util.List;

import org.jboss.intersmash.tools.application.openshift.input.BuildInput;
import org.jboss.intersmash.tools.provision.openshift.Eap7ImageOpenShiftProvisioner;

import io.fabric8.kubernetes.api.model.EnvVar;
import org.jboss.intersmash.tools.provision.openshift.Eap7ImageOpenShiftProvisioner;

/**
* End user Application descriptor interface which presents a AP 7.z (i.e. Jakarta EE 8 based WildFly) application on
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jboss.intersmash.tools.application.openshift;

import org.jboss.intersmash.tools.application.openshift.template.Eap7Template;
import org.jboss.intersmash.tools.provision.openshift.Eap7TemplateOpenShiftProvisioner;

/**
* End user Application descriptor interface which presents EAP 7 template application on OpenShift Container Platform.
*
* See {@link Eap7Template} for available templates the
* application can represent.
*
* The application will be deployed by:
* <ul>
* <li>{@link Eap7TemplateOpenShiftProvisioner}</li>
* </ul>
*/
public interface Eap7TemplateOpenShiftApplication
extends WildflyOpenShiftApplication, TemplateApplication<Eap7Template> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jboss.intersmash.tools.application.openshift.template;

import org.jboss.intersmash.tools.provision.openshift.template.OpenShiftTemplate;

/**
* OpenShift template for EAP 7.z (i.e. WildFly Jakarta EE 8 <= 26.1.2) applications.
* <p>
* See e.g.: https://github.com/jboss-container-images/jboss-eap-7-openshift-image
*/
public enum Eap7Template implements OpenShiftTemplate {
AMQ_PERSISTENT("amq-persistent"),
AMQ("amq"),
BASIC("basic"),
HTTPS("https"),
SSO("sso");

private String name;

Eap7Template(String name) {
this.name = name;
}

@Override
public String getLabel() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private ApplicationBuilder getAppBuilder() {
IntersmashConfig.eap7ImageURL(),
binarySource.getArchive(),
environmentVariables.stream().collect(Collectors.toMap(EnvVar::getName, EnvVar::getValue)),
application.getName() + "-" + IntersmashConfig.wildflyJakartaEe8ProductCode());
application.getName() + "-" + IntersmashConfig.eap7ProductCode());
ManagedBuildReference reference = BuildManagers.get().deploy(build);
BuildManagers.get().hasBuildCompleted(build).level(Level.DEBUG).waitFor();

Expand Down
Loading

0 comments on commit dca6a26

Please sign in to comment.