Skip to content

Commit

Permalink
Merge pull request #217 from laDok8/singleServerDomainAzure
Browse files Browse the repository at this point in the history
[#211] Option to specify servers in Azure domain mode
  • Loading branch information
istraka authored Feb 19, 2024
2 parents 10568d4 + bd017b4 commit 5b9990b
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
import sunstone.annotation.DomainMode;
import sunstone.annotation.WildFly;
import sunstone.core.SunstoneConfig;
import sunstone.core.WildFlyConfig;
import sunstone.core.api.SunstoneArchiveDeployer;
import sunstone.core.exceptions.IllegalArgumentSunstoneException;
import sunstone.core.exceptions.SunstoneException;
Expand All @@ -25,13 +23,10 @@
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Optional;

import static java.lang.String.format;
import static sunstone.aws.impl.AwsWFIdentifiableSunstoneResource.*;
import static sunstone.core.SunstoneConfig.isExpression;

import static sunstone.core.CreaperUtils.setDomainServers;

/**
* Purpose: handle deploy operation to WildFly.
Expand Down Expand Up @@ -68,23 +63,7 @@ static void deployToEc2Instance(String deploymentName, Identification resourceId
//no further configuration needed for standalone mode,
//in domain mode, we need to specify server groups
if (domainMode != null) {
if (wildFly.domain().serverGroups() == null) {
throw new RuntimeException(WildFlyConfig.DOMAIN_SERVER_GROUPS + " is not set");
}
String[] serverGroupsParams = wildFly.domain().serverGroups();
boolean deployedToNone = true;

for (String sgParam : serverGroupsParams) {
Optional<String[]> serverGroups = isExpression(sgParam) ? SunstoneConfig.resolveOptionalExpression(sgParam, String[].class) : Optional.of(new String[]{sgParam});
if (serverGroups.isPresent()) {
deployedToNone = false;
serverGroups.ifPresent(groups -> Arrays.stream(groups).forEach(builder::toServerGroups));
}
}
//groups may not be set -> deploy to all groups
if (deployedToNone) {
builder.toAllServerGroups();
}
setDomainServers(builder,domainMode);
}
try (OnlineManagementClient client = AwsWFIdentifiableSunstoneResourceUtils.resolveOnlineManagementClient(resourceIdentification, wildFly, store)) {
client.apply(builder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.wildfly.extras.creaper.commands.deployments.Undeploy;
import org.wildfly.extras.creaper.core.CommandFailedException;
import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
import sunstone.annotation.DomainMode;
import sunstone.annotation.WildFly;
import sunstone.azure.impl.AzureWFIdentifiableSunstoneResource.Identification;
import sunstone.core.api.SunstoneArchiveDeployer;
Expand All @@ -32,6 +33,7 @@
import java.nio.file.StandardCopyOption;

import static java.lang.String.format;
import static sunstone.core.CreaperUtils.setDomainServers;


/**
Expand Down Expand Up @@ -88,11 +90,16 @@ static void undeployFromWebApp(Identification resourceIdentification, AzureSunst
}

static void deployToVmInstance(String deploymentName, Identification resourceIdentification, WildFly wildFly, InputStream is, AzureSunstoneStore store) throws SunstoneException {
Deploy.Builder builder = new Deploy.Builder(is, deploymentName, false);
DomainMode domainMode = wildFly.domain();
//no further configuration needed for standalone mode,
//in domain mode, we need to specify server groups
if (domainMode != null) {
setDomainServers(builder,domainMode);
}
try (OnlineManagementClient client = AzureWFIdentifiableSunstoneResourceUtils.resolveOnlineManagementClient(resourceIdentification, wildFly, store)){
client.apply(new Deploy.Builder(is, deploymentName, false).build());
} catch (CommandFailedException e) {
throw new RuntimeException(e);
} catch (IOException e) {
client.apply(builder.build());
} catch (CommandFailedException | IOException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class AzureTestConstants {

public static final String VNET_NAME_2 = "sunstoneVnet2";

public static final String IMAGE_REF = "${image.ref:/subscriptions/7dee6f21-9f05-414e-99fa-08d3215fb420/resourceGroups/istraka-test/providers/Microsoft.Compute/images/eap-test-image}";
public static final String instanceName = "${sunstone.test.instance.name}";

public static final String deployGroup = "${"+ AzureConfig.GROUP + "}";
Expand All @@ -19,4 +18,10 @@ public class AzureTestConstants {
public static final String mgmtPort = "${non.existing:9990}";
public static final String mgmtHost = "${non.existing:master}";
public static final String mgmtProfile = "${non.existing:default}";
public static final String IMAGE_MARKETPLACE_PLAN = "${ts.azure.eap.image.plan.name}";
public static final String IMAGE_MARKETPLACE_PUBLISHER = "${ts.azure.eap.image.publisher}";
public static final String IMAGE_MARKETPLACE_PRODUCT = "${ts.azure.eap.image.product}";
public static final String IMAGE_MARKETPLACE_OFFER = "${ts.azure.eap.image.offer}";
public static final String IMAGE_MARKETPLACE_SKU = "${ts.azure.eap.image.sku}";
public static final String IMAGE_MARKETPLACE_VERSION = "${ts.azure.eap.image.version}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@

@WithAzureArmTemplate(parameters = {
@Parameter(k = "virtualMachineName", v = AzureTestConstants.instanceName),
@Parameter(k = "imageRefId", v = AzureTestConstants.IMAGE_REF)
@Parameter(k = "planName", v = AzureTestConstants.IMAGE_MARKETPLACE_PLAN),
@Parameter(k = "publisher", v = AzureTestConstants.IMAGE_MARKETPLACE_PUBLISHER),
@Parameter(k = "product", v = AzureTestConstants.IMAGE_MARKETPLACE_PRODUCT),
@Parameter(k = "offer", v = AzureTestConstants.IMAGE_MARKETPLACE_OFFER),
@Parameter(k = "sku", v = AzureTestConstants.IMAGE_MARKETPLACE_SKU),
@Parameter(k = "version", v = AzureTestConstants.IMAGE_MARKETPLACE_VERSION),
},
template = "sunstone/azure/armTemplates/eap.json", group = VmDeploySuiteTests.groupName, perSuite = true)
public class AzureVmDeployFirstTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
*/
@WithAzureArmTemplate(parameters = {
@Parameter(k = "virtualMachineName", v = AzureTestConstants.instanceName),
@Parameter(k = "imageRefId", v = AzureTestConstants.IMAGE_REF)
@Parameter(k = "planName", v = AzureTestConstants.IMAGE_MARKETPLACE_PLAN),
@Parameter(k = "publisher", v = AzureTestConstants.IMAGE_MARKETPLACE_PUBLISHER),
@Parameter(k = "product", v = AzureTestConstants.IMAGE_MARKETPLACE_PRODUCT),
@Parameter(k = "offer", v = AzureTestConstants.IMAGE_MARKETPLACE_OFFER),
@Parameter(k = "sku", v = AzureTestConstants.IMAGE_MARKETPLACE_SKU),
@Parameter(k = "version", v = AzureTestConstants.IMAGE_MARKETPLACE_VERSION),
},
template = "sunstone/azure/armTemplates/eap.json", group = VmDeploySuiteTests.groupName, perSuite = true)
public class AzureVmUndeployedSecondTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@

@WithAzureArmTemplate(parameters = {
@Parameter(k = "virtualMachineName", v = AzureTestConstants.instanceName),
@Parameter(k = "imageRefId", v = AzureTestConstants.IMAGE_REF)
@Parameter(k = "planName", v = AzureTestConstants.IMAGE_MARKETPLACE_PLAN),
@Parameter(k = "publisher", v = AzureTestConstants.IMAGE_MARKETPLACE_PUBLISHER),
@Parameter(k = "product", v = AzureTestConstants.IMAGE_MARKETPLACE_PRODUCT),
@Parameter(k = "offer", v = AzureTestConstants.IMAGE_MARKETPLACE_OFFER),
@Parameter(k = "sku", v = AzureTestConstants.IMAGE_MARKETPLACE_SKU),
@Parameter(k = "version", v = AzureTestConstants.IMAGE_MARKETPLACE_VERSION),
},
template = "sunstone/azure/armTemplates/eapDomain.json", group = VmDomainDeploySuiteTests.groupName, perSuite = true)
public class AzureDomainVmDeployFirstTest {
Expand All @@ -39,11 +44,11 @@ static WebArchive deploy() {
Hostname hostname;

@Test
public void test() throws IOException {
public void deployedAllTest() throws IOException {
OkHttpClient client = new OkHttpClient();

//check all servers in group
int[] ports = {8080,8230};
int[] ports = {8080,8230,8330};
for (int port : ports) {
Request request = new Request.Builder()
.url("http://" + hostname.get() + ":" + port + "/testapp")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import okhttp3.Request;
import okhttp3.Response;
import org.assertj.core.api.Assertions;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.jupiter.api.Test;
import sunstone.annotation.Deployment;
import sunstone.annotation.DomainMode;
import sunstone.annotation.OperatingMode;
import sunstone.annotation.Parameter;
import sunstone.annotation.WildFly;
Expand All @@ -21,20 +26,47 @@
*/
@WithAzureArmTemplate(parameters = {
@Parameter(k = "virtualMachineName", v = AzureTestConstants.instanceName),
@Parameter(k = "imageRefId", v = AzureTestConstants.IMAGE_REF)
@Parameter(k = "planName", v = AzureTestConstants.IMAGE_MARKETPLACE_PLAN),
@Parameter(k = "publisher", v = AzureTestConstants.IMAGE_MARKETPLACE_PUBLISHER),
@Parameter(k = "product", v = AzureTestConstants.IMAGE_MARKETPLACE_PRODUCT),
@Parameter(k = "offer", v = AzureTestConstants.IMAGE_MARKETPLACE_OFFER),
@Parameter(k = "sku", v = AzureTestConstants.IMAGE_MARKETPLACE_SKU),
@Parameter(k = "version", v = AzureTestConstants.IMAGE_MARKETPLACE_VERSION),
},
template = "sunstone/azure/armTemplates/eapDomain.json", group = VmDomainDeploySuiteTests.groupName, perSuite = true)
public class AzureDomainVmUndeployedSecondTest {
@AzureVirtualMachine(name = AzureTestConstants.instanceName, group = VmDomainDeploySuiteTests.groupName)
@WildFly(mode = OperatingMode.DOMAIN)
Hostname hostname;

@Deployment(name = "testapp.war")
@AzureVirtualMachine(name = AzureTestConstants.instanceName, group = VmDomainDeploySuiteTests.groupName)
@WildFly(mode = OperatingMode.DOMAIN, domain = @DomainMode(serverGroups = "other-server-group"))
static WebArchive deploy() {
return ShrinkWrap.create(WebArchive.class)
.addAsWebResource(new StringAsset("Hello World"), "index.jsp");
}

@Test
public void deployedOtherTest() throws IOException {
OkHttpClient client = new OkHttpClient();

int OTHER_SG_PORT = 8330;
//check deployment on other-server-group
Request request = new Request.Builder()
.url("http://" + hostname.get() + ":" + OTHER_SG_PORT + "/testapp")
.method("GET", null)
.build();
Response response = client.newCall(request).execute();
Assertions.assertThat(response.body().string()).isEqualTo("Hello World");
}

@Test
public void test() throws IOException {
public void undeployedMainTest() throws IOException {
OkHttpClient client = new OkHttpClient();

//check all servers in group
int[] ports = {8080,8230};
//check undeployment on main-server-group
int[] ports = {8080, 8230};
for (int port : ports) {
Request request = new Request.Builder()
.url("http://" + hostname.get() + ":" + port + "/testapp")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@

@WithAzureArmTemplate(
parameters = {
@Parameter(k = "virtualMachineName", v = AzureTestConstants.instanceName),
@Parameter(k = "imageRefId", v = AzureTestConstants.IMAGE_REF)
@Parameter(k = "virtualMachineName", v = AzureTestConstants.instanceName),
@Parameter(k = "planName", v = AzureTestConstants.IMAGE_MARKETPLACE_PLAN),
@Parameter(k = "publisher", v = AzureTestConstants.IMAGE_MARKETPLACE_PUBLISHER),
@Parameter(k = "product", v = AzureTestConstants.IMAGE_MARKETPLACE_PRODUCT),
@Parameter(k = "offer", v = AzureTestConstants.IMAGE_MARKETPLACE_OFFER),
@Parameter(k = "sku", v = AzureTestConstants.IMAGE_MARKETPLACE_SKU),
@Parameter(k = "version", v = AzureTestConstants.IMAGE_MARKETPLACE_VERSION),
},
template = "sunstone/azure/armTemplates/eapDomain.json", group = AzDomainManagementClientTests.groupName)
public class AzDomainManagementClientTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@

@WithAzureArmTemplate(parameters = {
@Parameter(k = "virtualMachineName", v = AzureTestConstants.instanceName),
@Parameter(k = "imageRefId", v = AzureTestConstants.IMAGE_REF)
@Parameter(k = "planName", v = AzureTestConstants.IMAGE_MARKETPLACE_PLAN),
@Parameter(k = "publisher", v = AzureTestConstants.IMAGE_MARKETPLACE_PUBLISHER),
@Parameter(k = "product", v = AzureTestConstants.IMAGE_MARKETPLACE_PRODUCT),
@Parameter(k = "offer", v = AzureTestConstants.IMAGE_MARKETPLACE_OFFER),
@Parameter(k = "sku", v = AzureTestConstants.IMAGE_MARKETPLACE_SKU),
@Parameter(k = "version", v = AzureTestConstants.IMAGE_MARKETPLACE_VERSION),
},
template = "sunstone/azure/armTemplates/eap.json", group = AzStandaloneManagementClientTests.groupName)
public class AzStandaloneManagementClientTests {
Expand Down
7 changes: 7 additions & 0 deletions azure-wildfly/src/test/resources/sunstone.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ sunstone.wildfly.mgmt.connection.timeout=120000
sunstone.wildfly.mgmt.host=master
sunstone.wildfly.mgmt.profile=default

ts.azure.eap.image.plan.name=${azure.image.plan.name:rh-jboss-eap74-rhel8}
ts.azure.eap.image.publisher=${azure.image.publisher:redhat}
ts.azure.eap.image.product=${azure.image.product:rh-jboss-eap}
ts.azure.eap.image.offer=${azure.image.offer:rh-jboss-eap}
ts.azure.eap.image.sku=${azure.image.sku:rh-jboss-eap74-rhel8}
ts.azure.eap.image.version=${azure.image.version:latest}

ts.test.run=defaultrun
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,33 @@
"type": "string",
"defaultValue": "sunstoneVM"
},
"imageRefId": {
"type": "string",
"defaultValue": "/subscriptions/7dee6f21-9f05-414e-99fa-08d3215fb420/resourceGroups/istraka-test/providers/Microsoft.Compute/images/eap-test-image"
},
"adminUsername": {
"type": "string",
"defaultValue": "sunstone"
},
"planName": {
"type": "string",
"defaultValue": "none"
},
"publisher": {
"type": "string",
"defaultValue": "none"
},
"product": {
"type": "string",
"defaultValue": "none"
},
"offer": {
"type": "string",
"defaultValue": "none"
},
"sku": {
"type": "string",
"defaultValue": "none"
},
"version": {
"type": "string",
"defaultValue": "none"
}
},
"variables": {
Expand Down Expand Up @@ -137,7 +157,10 @@
"deleteOption": "Detach"
},
"imageReference": {
"id": "[parameters('imageRefId')]"
"publisher": "[parameters('publisher')]",
"offer": "[parameters('offer')]",
"sku": "[parameters('sku')]",
"version": "[parameters('version')]"
}
},
"networkProfile": {
Expand All @@ -160,7 +183,7 @@
"publicKeys": [
{
"path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]",
"keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCbWLyxmSBH8XhikEs61USmxJHsUPIHEkrUc1HQoaw6AS0+DBIyLMBSDoGozC9Hp8hkZwMVqqrg+9ylMHyewm5Ta1Vbe8w/HDSl9Q+XY0cl3HaHTnmCmOBRGZTVNuHwYIba3PC2nd2wXUAEzyIwGM5No5QLw0XfzipzwkR6je6mBn8RzepaS+SJjwhZuJOcBzUtfLk6f3/ADgS3ENuAMecqBN6fclizl089STKLlBhnYo7xJNYOtbskWDuAB9XeuVO2cXDWXc6y77PptFC/8jHlZf/OFI4gTFlIbewC43ADaytA2Y4XKDyJDIRmpto8x3JIMyfKk0fyIYYx2XehfeIVrt63v/RaZ6qgSG4EN1j0hj7eGY+wO3CVbDoCvK/54vr2I+ZuPF77pDxoyU5BL3WWo2Ta1KXiTwb4lARS/Nl0oz3hm3/V6v6zsPTS9sCtQc/Q9XcB8amjaYr9Rznpkk/rgQUpvSsqHeA51CVJIxJRYTYztvgOG7fsRl75I3vFk9k= generated-by-azure"
"keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCJXDQ9nvcaUQz8wAamVsQD509M3+b7kFPfYkMZj1bIiMRYvDYAV9bNhumzwO195eA8207IWmTQvh9kPAEsu3jxPaPlF2q6VnNngR2lIbNHGUfPo1OlwJhoXXHaFPciwn38lp+Br2vXSDJXf1zjjV+6eiDAENll/mcp1q83tq7qbqta57ZeT7j3N97kDREB2EGFzK3H13qoSWrWwhYCxDK2cOcpqDvarFJpxcBnPnc1Qyvi289PvGHYA+GpXcic5RW6u6vIOR25NOjX7rePBUZzRTftt4jWz8c2A7viBkIrCr6sjbnx0wKntY+QuCN+u7//dcgFkZxDzoUIY1D+RMrb jclouds-jenkins"
}
]
},
Expand All @@ -179,6 +202,11 @@
"enabled": true
}
}
},
"plan": {
"name": "[parameters('planName')]",
"publisher": "[parameters('publisher')]",
"product": "[parameters('product')]"
}
}
],
Expand Down
Loading

0 comments on commit 5b9990b

Please sign in to comment.