Skip to content

Commit

Permalink
Merge pull request #251 from jfdenise/enabled-cloud
Browse files Browse the repository at this point in the history
Fix for Issue #249, Add boolean flag to enable/disable cloud support
  • Loading branch information
jfdenise authored Jun 29, 2021
2 parents 702a540 + 02f12f4 commit c8dc934
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/guide/intro/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ CLI configuration example:
The configuration item ```<cloud></cloud>``` allows to build a bootable JAR for cloud environment. By default the server is configured to run inside an OpenShift context.
Set the cloud child element ```<type>openshift|kubernetes</type>``` to select the targeted cloud platform.

Adding the ```<cloud/>``` element to the plugin configuration automatically enables the cloud support. Set the cloud child element ```<enabled>false</enabled>``` to disable the cloud support.

The sever configuration is updated in order to properly operate in a cloud environment:

* If no Galleon layers are provisioned, the provisioned configuration is ```standalone-microprofile-ha.xml``` instead of ```standalone-microprofile.xml```.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public class CloudConfig {
//Can be openshift or kubernetes
String type = OPENSHIFT;

private boolean enabled = true;

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public boolean isEnabled() {
return enabled;
}

public boolean getEnableJGroupsPassword() {
return enableJgroupsPassword;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class BuildBootableJarMojo extends AbstractBuildBootableJarMojo {

/**
* To enable cloud support. When cloud support is enabled, the created bootable JAR will operate properly in context such as openshift.
* Adding the &lt;cloud/&gt; element to the plugin configuration automatically enables the cloud support.
* You can set the cloud child element &lt;enabled&gt;false&lt;/enabled&gt; to disable the cloud support.
* <br/>
* In order to enable authenticated cluster jgroups protocol,
* set &lt;enable-jgroups-password&gt;true&lt;/enable-jgroups-password&gt;. The environment variable JGROUPS_CLUSTER_PASSWORD
Expand All @@ -45,14 +47,18 @@ public class BuildBootableJarMojo extends AbstractBuildBootableJarMojo {
@Parameter(alias = "cloud")
CloudConfig cloud;

boolean isCloudEnabled() {
return cloud != null && cloud.isEnabled();
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().debug(String.format("Skipping run of %s:%s", project.getGroupId(), project.getArtifactId()));
return;
}
if (!isPackageDev()) {
if (cloud != null) {
if (isCloudEnabled()) {
getLog().info("Cloud support is enabled");
cloud.validate();
for (String layer : cloud.getExtraLayers(this)) {
Expand All @@ -65,7 +71,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

@Override
protected void configureCli(List<String> commands) {
if (cloud != null) {
if (isCloudEnabled()) {
try {
cloud.addCLICommands(this, commands);
} catch (Exception ex) {
Expand All @@ -76,7 +82,7 @@ protected void configureCli(List<String> commands) {

@Override
protected ConfigId getDefaultConfig() {
if(cloud == null) {
if(!isCloudEnabled()) {
return super.getDefaultConfig();
} else {
return new ConfigId("standalone", "standalone-microprofile-ha.xml");
Expand All @@ -85,7 +91,7 @@ protected ConfigId getDefaultConfig() {

@Override
protected void copyExtraContentInternal(Path wildflyDir, Path contentDir) throws Exception {
if (cloud != null) {
if (isCloudEnabled()) {
cloud.copyExtraContent(this, wildflyDir, contentDir);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void testOpenshiftConfiguration() throws Exception {
assertNotNull(mojo);
assertFalse(mojo.layers.isEmpty());
assertNotNull(mojo.cloud);
assertTrue(mojo.cloud.isEnabled());
assertEquals(1, mojo.layers.size());
assertEquals("jaxrs", mojo.layers.get(0));
mojo.recordState = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates
* and other 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.plugins.bootablejar.maven.goals;

import java.nio.file.Path;

import org.junit.Test;

/**
* @author jdenise
*/
public class OpenShiftDisabledConfigurationTestCase extends AbstractBootableJarMojoTestCase {

public OpenShiftDisabledConfigurationTestCase() {
super("test-cloud-disabled-pom.xml", true, null);
}

@Test
public void testOpenshiftConfiguration() throws Exception {
BuildBootableJarMojo mojo = lookupMojo("package");
assertNotNull(mojo);
assertFalse(mojo.layers.isEmpty());
assertNotNull(mojo.cloud);
assertFalse(mojo.cloud.isEnabled());
assertEquals(2, mojo.layers.size());
assertEquals("jaxrs", mojo.layers.get(0));
assertEquals("management", mojo.layers.get(1));
mojo.recordState = true;
mojo.execute();
String[] layers = {"jaxrs", "management"};
final Path dir = getTestDir();
checkJar(dir, true, true, layers, null);
checkDeployment(dir, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void testOpenshiftConfiguration() throws Exception {
assertNotNull(mojo);
assertFalse(mojo.layers.isEmpty());
assertNotNull(mojo.cloud);
assertTrue(mojo.cloud.isEnabled());
assertEquals(1, mojo.layers.size());
assertEquals("jaxrs", mojo.layers.get(0));
mojo.recordState = true;
Expand Down
33 changes: 33 additions & 0 deletions tests/src/test/resources/poms/test-cloud-disabled-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>org.wildfly.plugins.tests</groupId>
<version>1.0.0.Final-SNAPSHOT</version>
<artifactId>test2</artifactId>
<packaging>war</packaging>

<name>WildFly bootable jar Example for tests</name>

<build>
<finalName>test</finalName>
<plugins>
<plugin>
<artifactId>wildfly-jar-maven-plugin</artifactId>
<configuration>
<feature-pack-location>TEST_REPLACE</feature-pack-location>
<layers>
<layer>jaxrs</layer>
<layer>management</layer>
</layers>
<excluded-layers>
<layer>deployment-scanner</layer>
</excluded-layers>
<cloud><enabled>false</enabled></cloud>
</configuration>

</plugin>
</plugins>
</build>
</project>
2 changes: 1 addition & 1 deletion tests/src/test/resources/poms/test-servermode5-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<layer>deployment-scanner</layer>
</excluded-layers>
<server/>
<cloud></cloud>
<cloud><enabled>true</enabled></cloud>
</configuration>

</plugin>
Expand Down

0 comments on commit c8dc934

Please sign in to comment.