From 7b5bbf9e59de32ac157db07042d2aced270e6328 Mon Sep 17 00:00:00 2001 From: Ladislav Dokoupil Date: Tue, 23 Jan 2024 15:23:43 +0100 Subject: [PATCH 1/3] Option to specify servers in azure domain mode --- .../azure/impl/AzureWFArchiveDeployer.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/azure-wildfly/src/main/java/sunstone/azure/impl/AzureWFArchiveDeployer.java b/azure-wildfly/src/main/java/sunstone/azure/impl/AzureWFArchiveDeployer.java index 966f0b1e..bcfb9792 100644 --- a/azure-wildfly/src/main/java/sunstone/azure/impl/AzureWFArchiveDeployer.java +++ b/azure-wildfly/src/main/java/sunstone/azure/impl/AzureWFArchiveDeployer.java @@ -14,8 +14,11 @@ 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.SunstoneConfig; +import sunstone.core.WildFlyConfig; import sunstone.core.api.SunstoneArchiveDeployer; import sunstone.core.exceptions.IllegalArgumentSunstoneException; import sunstone.core.exceptions.SunstoneException; @@ -30,8 +33,11 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.util.Arrays; +import java.util.Optional; import static java.lang.String.format; +import static sunstone.core.SunstoneConfig.isExpression; /** @@ -88,11 +94,32 @@ 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) { + 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 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(); + } + } 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); } } From 034aaa10eb777d7d4021c13820c596196e667651 Mon Sep 17 00:00:00 2001 From: Ladislav Dokoupil Date: Thu, 25 Jan 2024 12:46:55 +0100 Subject: [PATCH 2/3] tests for azure specified SG deployment --- .../armTemplates/AzureTestConstants.java | 6 + .../AzureDomainVmDeployFirstTest.java | 13 +- .../AzureDomainVmUndeployedSecondTest.java | 42 ++- .../di/AzDomainManagementClientTests.java | 2 +- .../src/test/resources/sunstone.properties | 8 + .../sunstone/azure/armTemplates/eap.json | 2 +- ...Domain.json => eapDomain-customImage.json} | 28 +- .../eapDomain-marketplaceImage.json | 241 ++++++++++++++++++ .../sunstone/azure/armTemplates/eap.json | 2 +- 9 files changed, 330 insertions(+), 14 deletions(-) rename azure-wildfly/src/test/resources/sunstone/azure/armTemplates/{eapDomain.json => eapDomain-customImage.json} (80%) create mode 100644 azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-marketplaceImage.json diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java index 7b6beb9b..58f19746 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java @@ -19,4 +19,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}"; } diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmDeployFirstTest.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmDeployFirstTest.java index 644eabdf..5938852f 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmDeployFirstTest.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmDeployFirstTest.java @@ -22,9 +22,14 @@ @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) + template = "sunstone/azure/armTemplates/eapDomain-marketplaceImage.json", group = VmDomainDeploySuiteTests.groupName, perSuite = true) public class AzureDomainVmDeployFirstTest { @Deployment(name = "testapp.war") @AzureVirtualMachine(name = AzureTestConstants.instanceName, group = VmDomainDeploySuiteTests.groupName) @@ -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") diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmUndeployedSecondTest.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmUndeployedSecondTest.java index b2e3635c..fb3f7bb4 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmUndeployedSecondTest.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmUndeployedSecondTest.java @@ -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; @@ -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) + template = "sunstone/azure/armTemplates/eapDomain-marketplaceImage.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") diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzDomainManagementClientTests.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzDomainManagementClientTests.java index 63f793dd..ce57a8c7 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzDomainManagementClientTests.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzDomainManagementClientTests.java @@ -19,7 +19,7 @@ @Parameter(k = "virtualMachineName", v = AzureTestConstants.instanceName), @Parameter(k = "imageRefId", v = AzureTestConstants.IMAGE_REF) }, - template = "sunstone/azure/armTemplates/eapDomain.json", group = AzDomainManagementClientTests.groupName) + template = "sunstone/azure/armTemplates/eapDomain-customImage.json", group = AzDomainManagementClientTests.groupName) public class AzDomainManagementClientTests { static final String groupName = "AzDomainManagementClientTests-" + AzureTestConstants.deployGroup; diff --git a/azure-wildfly/src/test/resources/sunstone.properties b/azure-wildfly/src/test/resources/sunstone.properties index 6054869f..c85b7de8 100644 --- a/azure-wildfly/src/test/resources/sunstone.properties +++ b/azure-wildfly/src/test/resources/sunstone.properties @@ -13,4 +13,12 @@ sunstone.wildfly.mgmt.connection.timeout=120000 sunstone.wildfly.mgmt.host=master sunstone.wildfly.mgmt.profile=default +# valid for marketplace-image profile +ts.azure.eap.image.plan.name=${azure.image.plan.name} +ts.azure.eap.image.publisher=${azure.image.publisher} +ts.azure.eap.image.product=${azure.image.product} +ts.azure.eap.image.offer=${azure.image.offer} +ts.azure.eap.image.sku=${azure.image.sku} +ts.azure.eap.image.version=${azure.image.version} + ts.test.run=defaultrun diff --git a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eap.json b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eap.json index f6f0fb29..a6746b3e 100644 --- a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eap.json +++ b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eap.json @@ -160,7 +160,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" } ] }, diff --git a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain.json b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-customImage.json similarity index 80% rename from azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain.json rename to azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-customImage.json index 4a3ed43c..63cd6ceb 100644 --- a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain.json +++ b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-customImage.json @@ -13,10 +13,34 @@ "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": { - "customData": "#cloud-config\nruncmd:\n - touch /log\n - JBOSS_HOME=/opt/rh/eap7/root/usr/share/wildfly \n - echo 'Setting JAVA_OPTS' >> /log\n - echo -e 'JAVA_OPTS=\"$JAVA_OPTS -Djboss.bind.address.management=0.0.0.0\"' >> ${JBOSS_HOME}/bin/domain.conf 2>/log\n - echo -e \"JAVA_OPTS=\\\"\\$JAVA_OPTS -Djboss.bind.address.private=$(hostname -I)\\\"\" >> ${JBOSS_HOME}/bin/domain.conf 2>/log\n - echo -e 'JAVA_OPTS=\"$JAVA_OPTS -Djboss.bind.address=0.0.0.0\"' >> ${JBOSS_HOME}/bin/domain.conf 2>/log\n - echo 'HOST_CONTROLLER_JAVA_OPTS=\"$HOST_CONTROLLER_JAVA_OPTS $JAVA_OPTS\"' >> ${JBOSS_HOME}/bin/domain.conf 2>/log\n - echo 'Enabling & restarting eap7-domain service' >> /log\n - systemctl enable eap7-domain.service >> /log 2>&1\n - systemctl restart eap7-domain.service >> /log 2>&1\n - echo 'Stopping the firewall' >> /log\n - systemctl stop firewalld >> /log 2>&1\n - echo 'Setting up EAP' >> /log\n - ${JBOSS_HOME}/bin/add-user.sh -u admin -p pass.1234 -r ManagementRealm -g SuperUser -e >> /log 2>&1", + "customData": "#cloud-config\nruncmd:\n - touch /log\n - JBOSS_HOME=/opt/rh/eap7/root/usr/share/wildfly \n - echo 'Setting JAVA_OPTS' >> /log\n - echo -e 'JAVA_OPTS=\"$JAVA_OPTS -Djboss.bind.address.management=0.0.0.0\"' >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - echo -e \"JAVA_OPTS=\\\"\\$JAVA_OPTS -Djboss.bind.address.private=$(hostname -I)\\\"\" >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - echo -e 'JAVA_OPTS=\"$JAVA_OPTS -Djboss.bind.address=0.0.0.0\"' >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - echo 'HOST_CONTROLLER_JAVA_OPTS=\"$HOST_CONTROLLER_JAVA_OPTS $JAVA_OPTS\"' >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - sed -i 's/auto-start=\"false\"/auto-start=\"true\"/' ${JBOSS_HOME}/domain/configuration/host.xml /dev/null 2>>/log\n - echo 'Enabling & restarting eap7-domain service' >> /log\n - systemctl enable eap7-domain.service >> /log 2>&1\n - systemctl restart eap7-domain.service >> /log 2>&1\n - echo 'Stopping the firewall' >> /log\n - systemctl stop firewalld >> /log 2>&1\n - echo 'Setting up EAP' >> /log\n - ${JBOSS_HOME}/bin/add-user.sh -u admin -p pass.1234 -r ManagementRealm -g SuperUser -e >> /log 2>&1", "networkInterfaceName": "sunstoneInterface", "networkSecurityGroupName": "sunstone-nsg", "nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]", @@ -160,7 +184,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" } ] }, diff --git a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-marketplaceImage.json b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-marketplaceImage.json new file mode 100644 index 00000000..1ad2b501 --- /dev/null +++ b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-marketplaceImage.json @@ -0,0 +1,241 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "virtualMachineName": { + "type": "string", + "defaultValue": "sunstoneVM" + }, + "imageRefId": { + "type": "string", + "defaultValue": "none" + }, + "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": { + "customData": "#cloud-config\nruncmd:\n - touch /log\n - JBOSS_HOME=/opt/rh/eap7/root/usr/share/wildfly \n - echo 'Setting JAVA_OPTS' >> /log\n - echo -e 'JAVA_OPTS=\"$JAVA_OPTS -Djboss.bind.address.management=0.0.0.0\"' >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - echo -e \"JAVA_OPTS=\\\"\\$JAVA_OPTS -Djboss.bind.address.private=$(hostname -I)\\\"\" >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - echo -e 'JAVA_OPTS=\"$JAVA_OPTS -Djboss.bind.address=0.0.0.0\"' >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - echo 'HOST_CONTROLLER_JAVA_OPTS=\"$HOST_CONTROLLER_JAVA_OPTS $JAVA_OPTS\"' >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - sed -i 's/auto-start=\"false\"/auto-start=\"true\"/' ${JBOSS_HOME}/domain/configuration/host.xml /dev/null 2>>/log\n - echo 'Enabling & restarting eap7-domain service' >> /log\n - systemctl enable eap7-domain.service >> /log 2>&1\n - systemctl restart eap7-domain.service >> /log 2>&1\n - echo 'Stopping the firewall' >> /log\n - systemctl stop firewalld >> /log 2>&1\n - echo 'Setting up EAP' >> /log\n - ${JBOSS_HOME}/bin/add-user.sh -u admin -p pass.1234 -r ManagementRealm -g SuperUser -e >> /log 2>&1", + "networkInterfaceName": "sunstoneInterface", + "networkSecurityGroupName": "sunstone-nsg", + "nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]", + "subnetName": "default", + "vnetName": "sunstoneVnet", + "publicIpAddressName": "sunstone-ip", + "vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', variables('vnetName'))]", + "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]" + }, + "resources": [ + { + "name": "[variables('networkSecurityGroupName')]", + "type": "Microsoft.Network/networkSecurityGroups", + "apiVersion": "2019-02-01", + "location": "[resourceGroup().location]", + "properties": { + "securityRules": [ + { + "name": "any", + "properties": { + "priority": 100, + "protocol": "TCP", + "access": "Allow", + "direction": "Inbound", + "sourceAddressPrefix": "*", + "sourcePortRange": "*", + "destinationAddressPrefix": "*", + "destinationPortRange": "*" + } + } + ] + } + }, + { + "name": "[variables('networkInterfaceName')]", + "type": "Microsoft.Network/networkInterfaces", + "apiVersion": "2021-08-01", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]", + "[concat('Microsoft.Network/virtualNetworks/', variables('vnetName'))]", + "[concat('Microsoft.Network/publicIpAddresses/', variables('publicIpAddressName'))]" + ], + "properties": { + "ipConfigurations": [ + { + "name": "ipconfig1", + "properties": { + "subnet": { + "id": "[variables('subnetRef')]" + }, + "privateIPAllocationMethod": "Dynamic", + "publicIpAddress": { + "id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', variables('publicIpAddressName'))]", + "properties": { + "deleteOption": "Detach" + } + } + } + } + ], + "networkSecurityGroup": { + "id": "[variables('nsgId')]" + } + } + }, + { + "name": "[variables('vnetName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2021-01-01", + "location": "[resourceGroup().location]", + "properties": { + "addressSpace": { + "addressPrefixes": [ + "10.1.0.0/16" + ] + }, + "subnets": [ + { + "name": "[variables('subnetName')]", + "properties": { + "addressPrefix": "10.1.0.0/24" + } + } + ] + } + }, + { + "name": "[variables('publicIpAddressName')]", + "type": "Microsoft.Network/publicIpAddresses", + "apiVersion": "2020-08-01", + "location": "[resourceGroup().location]", + "properties": { + "publicIpAllocationMethod": "Static" + }, + "sku": { + "name": "Standard" + } + }, + { + "name": "[parameters('virtualMachineName')]", + "type": "Microsoft.Compute/virtualMachines", + "apiVersion": "2022-03-01", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]" + ], + "properties": { + "hardwareProfile": { + "vmSize": "Standard_B2s" + }, + "storageProfile": { + "osDisk": { + "createOption": "fromImage", + "managedDisk": { + "storageAccountType": "Premium_LRS" + }, + "deleteOption": "Detach" + }, + "imageReference": { + "publisher": "[parameters('publisher')]", + "offer": "[parameters('offer')]", + "sku": "[parameters('sku')]", + "version": "[parameters('version')]" + } + }, + "networkProfile": { + "networkInterfaces": [ + { + "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]", + "properties": { + "deleteOption": "Detach" + } + } + ] + }, + "osProfile": { + "computerName": "[parameters('virtualMachineName')]", + "adminUsername": "[parameters('adminUsername')]", + "customData": "[base64(variables('customData'))]", + "linuxConfiguration": { + "disablePasswordAuthentication": true, + "ssh": { + "publicKeys": [ + { + "path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]", + "keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCJXDQ9nvcaUQz8wAamVsQD509M3+b7kFPfYkMZj1bIiMRYvDYAV9bNhumzwO195eA8207IWmTQvh9kPAEsu3jxPaPlF2q6VnNngR2lIbNHGUfPo1OlwJhoXXHaFPciwn38lp+Br2vXSDJXf1zjjV+6eiDAENll/mcp1q83tq7qbqta57ZeT7j3N97kDREB2EGFzK3H13qoSWrWwhYCxDK2cOcpqDvarFJpxcBnPnc1Qyvi289PvGHYA+GpXcic5RW6u6vIOR25NOjX7rePBUZzRTftt4jWz8c2A7viBkIrCr6sjbnx0wKntY+QuCN+u7//dcgFkZxDzoUIY1D+RMrb jclouds-jenkins" + } + ] + }, + "provisionVMAgent": true, + "patchSettings": { + "patchMode": "ImageDefault", + "assessmentMode": "ImageDefault" + }, + "enableVMAgentPlatformUpdates": false + }, + "secrets": [], + "allowExtensionOperations": true + }, + "diagnosticsProfile": { + "bootDiagnostics": { + "enabled": true + } + } + }, + "plan": { + "name": "[parameters('planName')]", + "publisher": "[parameters('publisher')]", + "product": "[parameters('product')]" + } + }, + { + "type": "Microsoft.Compute/virtualMachines/extensions", + "name": "[concat(parameters('virtualMachineName'),'/CustomScript')]", + "apiVersion": "2022-03-01", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]" + ], + "properties": { + "publisher": "Microsoft.Azure.Extensions", + "type": "CustomScript", + "typeHandlerVersion": "2.1", + "autoUpgradeMinorVersion": true, + "protectedSettings": { + "commandToExecute": "RET_VAL=1; for i in {1..9}; do sleep 10; status=$(/opt/rh/eap7/root/usr/share/wildfly/bin/jboss-cli.sh --connect --output-json --command=\"/host=master/server=server-one:read-attribute(name=server-state)\" 2>&1); fgrep result <<< $status | fgrep -q running && RET_VAL=0 && break; done; exit ${RET_VAL}" + } + } + } + ], + "outputs": { + "adminUsername": { + "type": "string", + "value": "[parameters('adminUsername')]" + } + } +} \ No newline at end of file diff --git a/azure/src/test/resources/sunstone/azure/armTemplates/eap.json b/azure/src/test/resources/sunstone/azure/armTemplates/eap.json index f6f0fb29..a6746b3e 100644 --- a/azure/src/test/resources/sunstone/azure/armTemplates/eap.json +++ b/azure/src/test/resources/sunstone/azure/armTemplates/eap.json @@ -160,7 +160,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" } ] }, From bd017b457fc3e5f237cb44136bbd03868b9c849c Mon Sep 17 00:00:00 2001 From: Ladislav Dokoupil Date: Tue, 30 Jan 2024 18:14:13 +0100 Subject: [PATCH 3/3] refractor duplicated code --- .../aws/impl/AwsWFArchiveDeployer.java | 25 +- .../azure/impl/AzureWFArchiveDeployer.java | 24 +- .../armTemplates/AzureTestConstants.java | 1 - .../vm/suitetests/AzureVmDeployFirstTest.java | 7 +- .../AzureVmUndeployedSecondTest.java | 7 +- .../AzureDomainVmDeployFirstTest.java | 2 +- .../AzureDomainVmUndeployedSecondTest.java | 2 +- .../di/AzDomainManagementClientTests.java | 11 +- .../di/AzStandaloneManagementClientTests.java | 7 +- .../src/test/resources/sunstone.properties | 13 +- .../sunstone/azure/armTemplates/eap.json | 38 ++- .../armTemplates/eapDomain-customImage.json | 233 ------------------ ...n-marketplaceImage.json => eapDomain.json} | 4 - .../armTemplates/AzureTestConstants.java | 7 +- .../azure/armTemplates/di/AzVmTests.java | 7 +- azure/src/test/resources/sunstone.properties | 7 + .../sunstone/azure/armTemplates/eap.json | 42 +++- .../main/java/sunstone/core/CreaperUtils.java | 23 ++ 18 files changed, 148 insertions(+), 312 deletions(-) delete mode 100644 azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-customImage.json rename azure-wildfly/src/test/resources/sunstone/azure/armTemplates/{eapDomain-marketplaceImage.json => eapDomain.json} (99%) diff --git a/aws-wildfly/src/main/java/sunstone/aws/impl/AwsWFArchiveDeployer.java b/aws-wildfly/src/main/java/sunstone/aws/impl/AwsWFArchiveDeployer.java index c3a9d14e..a7bc10b6 100644 --- a/aws-wildfly/src/main/java/sunstone/aws/impl/AwsWFArchiveDeployer.java +++ b/aws-wildfly/src/main/java/sunstone/aws/impl/AwsWFArchiveDeployer.java @@ -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; @@ -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. @@ -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 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()); diff --git a/azure-wildfly/src/main/java/sunstone/azure/impl/AzureWFArchiveDeployer.java b/azure-wildfly/src/main/java/sunstone/azure/impl/AzureWFArchiveDeployer.java index bcfb9792..b0aa1317 100644 --- a/azure-wildfly/src/main/java/sunstone/azure/impl/AzureWFArchiveDeployer.java +++ b/azure-wildfly/src/main/java/sunstone/azure/impl/AzureWFArchiveDeployer.java @@ -17,8 +17,6 @@ import sunstone.annotation.DomainMode; import sunstone.annotation.WildFly; import sunstone.azure.impl.AzureWFIdentifiableSunstoneResource.Identification; -import sunstone.core.SunstoneConfig; -import sunstone.core.WildFlyConfig; import sunstone.core.api.SunstoneArchiveDeployer; import sunstone.core.exceptions.IllegalArgumentSunstoneException; import sunstone.core.exceptions.SunstoneException; @@ -33,11 +31,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import java.util.Arrays; -import java.util.Optional; import static java.lang.String.format; -import static sunstone.core.SunstoneConfig.isExpression; +import static sunstone.core.CreaperUtils.setDomainServers; /** @@ -99,23 +95,7 @@ static void deployToVmInstance(String deploymentName, Identification resourceIde //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 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 = AzureWFIdentifiableSunstoneResourceUtils.resolveOnlineManagementClient(resourceIdentification, wildFly, store)){ client.apply(builder.build()); diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java index 58f19746..495f6470 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java @@ -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 + "}"; diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vm/suitetests/AzureVmDeployFirstTest.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vm/suitetests/AzureVmDeployFirstTest.java index 3e8e60ed..d2cf3b6c 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vm/suitetests/AzureVmDeployFirstTest.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vm/suitetests/AzureVmDeployFirstTest.java @@ -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 { diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vm/suitetests/AzureVmUndeployedSecondTest.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vm/suitetests/AzureVmUndeployedSecondTest.java index 54364035..78a9167d 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vm/suitetests/AzureVmUndeployedSecondTest.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vm/suitetests/AzureVmUndeployedSecondTest.java @@ -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 { diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmDeployFirstTest.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmDeployFirstTest.java index 5938852f..cc87ebf5 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmDeployFirstTest.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmDeployFirstTest.java @@ -29,7 +29,7 @@ @Parameter(k = "sku", v = AzureTestConstants.IMAGE_MARKETPLACE_SKU), @Parameter(k = "version", v = AzureTestConstants.IMAGE_MARKETPLACE_VERSION), }, - template = "sunstone/azure/armTemplates/eapDomain-marketplaceImage.json", group = VmDomainDeploySuiteTests.groupName, perSuite = true) + template = "sunstone/azure/armTemplates/eapDomain.json", group = VmDomainDeploySuiteTests.groupName, perSuite = true) public class AzureDomainVmDeployFirstTest { @Deployment(name = "testapp.war") @AzureVirtualMachine(name = AzureTestConstants.instanceName, group = VmDomainDeploySuiteTests.groupName) diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmUndeployedSecondTest.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmUndeployedSecondTest.java index fb3f7bb4..157e4052 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmUndeployedSecondTest.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/archiveDeploy/vmDomain/suitetests/AzureDomainVmUndeployedSecondTest.java @@ -33,7 +33,7 @@ @Parameter(k = "sku", v = AzureTestConstants.IMAGE_MARKETPLACE_SKU), @Parameter(k = "version", v = AzureTestConstants.IMAGE_MARKETPLACE_VERSION), }, - template = "sunstone/azure/armTemplates/eapDomain-marketplaceImage.json", group = VmDomainDeploySuiteTests.groupName, perSuite = true) + 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) diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzDomainManagementClientTests.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzDomainManagementClientTests.java index ce57a8c7..b9b33d91 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzDomainManagementClientTests.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzDomainManagementClientTests.java @@ -16,10 +16,15 @@ @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-customImage.json", group = AzDomainManagementClientTests.groupName) + template = "sunstone/azure/armTemplates/eapDomain.json", group = AzDomainManagementClientTests.groupName) public class AzDomainManagementClientTests { static final String groupName = "AzDomainManagementClientTests-" + AzureTestConstants.deployGroup; diff --git a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzStandaloneManagementClientTests.java b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzStandaloneManagementClientTests.java index 0a734801..bb4972db 100644 --- a/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzStandaloneManagementClientTests.java +++ b/azure-wildfly/src/test/java/sunstone/azure/armTemplates/di/AzStandaloneManagementClientTests.java @@ -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 { diff --git a/azure-wildfly/src/test/resources/sunstone.properties b/azure-wildfly/src/test/resources/sunstone.properties index c85b7de8..2bd64286 100644 --- a/azure-wildfly/src/test/resources/sunstone.properties +++ b/azure-wildfly/src/test/resources/sunstone.properties @@ -13,12 +13,11 @@ sunstone.wildfly.mgmt.connection.timeout=120000 sunstone.wildfly.mgmt.host=master sunstone.wildfly.mgmt.profile=default -# valid for marketplace-image profile -ts.azure.eap.image.plan.name=${azure.image.plan.name} -ts.azure.eap.image.publisher=${azure.image.publisher} -ts.azure.eap.image.product=${azure.image.product} -ts.azure.eap.image.offer=${azure.image.offer} -ts.azure.eap.image.sku=${azure.image.sku} -ts.azure.eap.image.version=${azure.image.version} +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 diff --git a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eap.json b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eap.json index a6746b3e..4bc1399b 100644 --- a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eap.json +++ b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eap.json @@ -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": { @@ -137,7 +157,10 @@ "deleteOption": "Detach" }, "imageReference": { - "id": "[parameters('imageRefId')]" + "publisher": "[parameters('publisher')]", + "offer": "[parameters('offer')]", + "sku": "[parameters('sku')]", + "version": "[parameters('version')]" } }, "networkProfile": { @@ -179,6 +202,11 @@ "enabled": true } } + }, + "plan": { + "name": "[parameters('planName')]", + "publisher": "[parameters('publisher')]", + "product": "[parameters('product')]" } } ], diff --git a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-customImage.json b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-customImage.json deleted file mode 100644 index 63cd6ceb..00000000 --- a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-customImage.json +++ /dev/null @@ -1,233 +0,0 @@ -{ - "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "virtualMachineName": { - "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": { - "customData": "#cloud-config\nruncmd:\n - touch /log\n - JBOSS_HOME=/opt/rh/eap7/root/usr/share/wildfly \n - echo 'Setting JAVA_OPTS' >> /log\n - echo -e 'JAVA_OPTS=\"$JAVA_OPTS -Djboss.bind.address.management=0.0.0.0\"' >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - echo -e \"JAVA_OPTS=\\\"\\$JAVA_OPTS -Djboss.bind.address.private=$(hostname -I)\\\"\" >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - echo -e 'JAVA_OPTS=\"$JAVA_OPTS -Djboss.bind.address=0.0.0.0\"' >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - echo 'HOST_CONTROLLER_JAVA_OPTS=\"$HOST_CONTROLLER_JAVA_OPTS $JAVA_OPTS\"' >> ${JBOSS_HOME}/bin/domain.conf 2>>/log\n - sed -i 's/auto-start=\"false\"/auto-start=\"true\"/' ${JBOSS_HOME}/domain/configuration/host.xml /dev/null 2>>/log\n - echo 'Enabling & restarting eap7-domain service' >> /log\n - systemctl enable eap7-domain.service >> /log 2>&1\n - systemctl restart eap7-domain.service >> /log 2>&1\n - echo 'Stopping the firewall' >> /log\n - systemctl stop firewalld >> /log 2>&1\n - echo 'Setting up EAP' >> /log\n - ${JBOSS_HOME}/bin/add-user.sh -u admin -p pass.1234 -r ManagementRealm -g SuperUser -e >> /log 2>&1", - "networkInterfaceName": "sunstoneInterface", - "networkSecurityGroupName": "sunstone-nsg", - "nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]", - "subnetName": "default", - "vnetName": "sunstoneVnet", - "publicIpAddressName": "sunstone-ip", - "vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', variables('vnetName'))]", - "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]" - }, - "resources": [ - { - "name": "[variables('networkSecurityGroupName')]", - "type": "Microsoft.Network/networkSecurityGroups", - "apiVersion": "2019-02-01", - "location": "[resourceGroup().location]", - "properties": { - "securityRules": [ - { - "name": "any", - "properties": { - "priority": 100, - "protocol": "TCP", - "access": "Allow", - "direction": "Inbound", - "sourceAddressPrefix": "*", - "sourcePortRange": "*", - "destinationAddressPrefix": "*", - "destinationPortRange": "*" - } - } - ] - } - }, - { - "name": "[variables('networkInterfaceName')]", - "type": "Microsoft.Network/networkInterfaces", - "apiVersion": "2021-08-01", - "location": "[resourceGroup().location]", - "dependsOn": [ - "[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]", - "[concat('Microsoft.Network/virtualNetworks/', variables('vnetName'))]", - "[concat('Microsoft.Network/publicIpAddresses/', variables('publicIpAddressName'))]" - ], - "properties": { - "ipConfigurations": [ - { - "name": "ipconfig1", - "properties": { - "subnet": { - "id": "[variables('subnetRef')]" - }, - "privateIPAllocationMethod": "Dynamic", - "publicIpAddress": { - "id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', variables('publicIpAddressName'))]", - "properties": { - "deleteOption": "Detach" - } - } - } - } - ], - "networkSecurityGroup": { - "id": "[variables('nsgId')]" - } - } - }, - { - "name": "[variables('vnetName')]", - "type": "Microsoft.Network/virtualNetworks", - "apiVersion": "2021-01-01", - "location": "[resourceGroup().location]", - "properties": { - "addressSpace": { - "addressPrefixes": [ - "10.1.0.0/16" - ] - }, - "subnets": [ - { - "name": "[variables('subnetName')]", - "properties": { - "addressPrefix": "10.1.0.0/24" - } - } - ] - } - }, - { - "name": "[variables('publicIpAddressName')]", - "type": "Microsoft.Network/publicIpAddresses", - "apiVersion": "2020-08-01", - "location": "[resourceGroup().location]", - "properties": { - "publicIpAllocationMethod": "Static" - }, - "sku": { - "name": "Standard" - } - }, - { - "name": "[parameters('virtualMachineName')]", - "type": "Microsoft.Compute/virtualMachines", - "apiVersion": "2022-03-01", - "location": "[resourceGroup().location]", - "dependsOn": [ - "[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]" - ], - "properties": { - "hardwareProfile": { - "vmSize": "Standard_B2s" - }, - "storageProfile": { - "osDisk": { - "createOption": "fromImage", - "managedDisk": { - "storageAccountType": "Premium_LRS" - }, - "deleteOption": "Detach" - }, - "imageReference": { - "id": "[parameters('imageRefId')]" - } - }, - "networkProfile": { - "networkInterfaces": [ - { - "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]", - "properties": { - "deleteOption": "Detach" - } - } - ] - }, - "osProfile": { - "computerName": "[parameters('virtualMachineName')]", - "adminUsername": "[parameters('adminUsername')]", - "customData": "[base64(variables('customData'))]", - "linuxConfiguration": { - "disablePasswordAuthentication": true, - "ssh": { - "publicKeys": [ - { - "path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]", - "keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCJXDQ9nvcaUQz8wAamVsQD509M3+b7kFPfYkMZj1bIiMRYvDYAV9bNhumzwO195eA8207IWmTQvh9kPAEsu3jxPaPlF2q6VnNngR2lIbNHGUfPo1OlwJhoXXHaFPciwn38lp+Br2vXSDJXf1zjjV+6eiDAENll/mcp1q83tq7qbqta57ZeT7j3N97kDREB2EGFzK3H13qoSWrWwhYCxDK2cOcpqDvarFJpxcBnPnc1Qyvi289PvGHYA+GpXcic5RW6u6vIOR25NOjX7rePBUZzRTftt4jWz8c2A7viBkIrCr6sjbnx0wKntY+QuCN+u7//dcgFkZxDzoUIY1D+RMrb jclouds-jenkins" - } - ] - }, - "provisionVMAgent": true, - "patchSettings": { - "patchMode": "ImageDefault", - "assessmentMode": "ImageDefault" - }, - "enableVMAgentPlatformUpdates": false - }, - "secrets": [], - "allowExtensionOperations": true - }, - "diagnosticsProfile": { - "bootDiagnostics": { - "enabled": true - } - } - } - }, - { - "type": "Microsoft.Compute/virtualMachines/extensions", - "name": "[concat(parameters('virtualMachineName'),'/CustomScript')]", - "apiVersion": "2022-03-01", - "location": "[resourceGroup().location]", - "dependsOn": [ - "[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]" - ], - "properties": { - "publisher": "Microsoft.Azure.Extensions", - "type": "CustomScript", - "typeHandlerVersion": "2.1", - "autoUpgradeMinorVersion": true, - "protectedSettings": { - "commandToExecute": "for server in {\"server-one\",\"server-two\"}; do for i in {1..9}; do sleep 10;RET_VAL=1; /opt/rh/eap7/root/usr/share/wildfly/bin/jboss-cli.sh --connect --output-json --command=\"/host=master/server=${server}:read-attribute(name=server-state)\" | jq -r .result | grep -Fxq running && RET_VAL=$? && break; done; if [ ${RET_VAL} -ne 0 ]; then exit 1; fi; done" - } - } - } - ], - "outputs": { - "adminUsername": { - "type": "string", - "value": "[parameters('adminUsername')]" - } - } -} diff --git a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-marketplaceImage.json b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain.json similarity index 99% rename from azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-marketplaceImage.json rename to azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain.json index 1ad2b501..74201d60 100644 --- a/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain-marketplaceImage.json +++ b/azure-wildfly/src/test/resources/sunstone/azure/armTemplates/eapDomain.json @@ -6,10 +6,6 @@ "type": "string", "defaultValue": "sunstoneVM" }, - "imageRefId": { - "type": "string", - "defaultValue": "none" - }, "adminUsername": { "type": "string", "defaultValue": "sunstone" diff --git a/azure/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java b/azure/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java index 6690a28a..c021d2ce 100644 --- a/azure/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java +++ b/azure/src/test/java/sunstone/azure/armTemplates/AzureTestConstants.java @@ -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 + "}"; @@ -18,4 +17,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}"; } diff --git a/azure/src/test/java/sunstone/azure/armTemplates/di/AzVmTests.java b/azure/src/test/java/sunstone/azure/armTemplates/di/AzVmTests.java index 4989aa40..ffb6133f 100644 --- a/azure/src/test/java/sunstone/azure/armTemplates/di/AzVmTests.java +++ b/azure/src/test/java/sunstone/azure/armTemplates/di/AzVmTests.java @@ -16,7 +16,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 = AzVmTests.groupName) public class AzVmTests { diff --git a/azure/src/test/resources/sunstone.properties b/azure/src/test/resources/sunstone.properties index 6054869f..2bd64286 100644 --- a/azure/src/test/resources/sunstone.properties +++ b/azure/src/test/resources/sunstone.properties @@ -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 diff --git a/azure/src/test/resources/sunstone/azure/armTemplates/eap.json b/azure/src/test/resources/sunstone/azure/armTemplates/eap.json index a6746b3e..14e62250 100644 --- a/azure/src/test/resources/sunstone/azure/armTemplates/eap.json +++ b/azure/src/test/resources/sunstone/azure/armTemplates/eap.json @@ -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": { @@ -91,8 +111,8 @@ "properties": { "addressSpace": { "addressPrefixes": [ - "10.1.0.0/16" - ] + "10.1.0.0/16" + ] }, "subnets": [ { @@ -137,7 +157,10 @@ "deleteOption": "Detach" }, "imageReference": { - "id": "[parameters('imageRefId')]" + "publisher": "[parameters('publisher')]", + "offer": "[parameters('offer')]", + "sku": "[parameters('sku')]", + "version": "[parameters('version')]" } }, "networkProfile": { @@ -179,6 +202,11 @@ "enabled": true } } + }, + "plan": { + "name": "[parameters('planName')]", + "publisher": "[parameters('publisher')]", + "product": "[parameters('product')]" } } ], diff --git a/core-wildfly/src/main/java/sunstone/core/CreaperUtils.java b/core-wildfly/src/main/java/sunstone/core/CreaperUtils.java index 34b2b0e1..fabeffd7 100644 --- a/core-wildfly/src/main/java/sunstone/core/CreaperUtils.java +++ b/core-wildfly/src/main/java/sunstone/core/CreaperUtils.java @@ -2,6 +2,7 @@ import org.slf4j.Logger; +import org.wildfly.extras.creaper.commands.deployments.Deploy; import org.wildfly.extras.creaper.core.ManagementClient; import org.wildfly.extras.creaper.core.online.ManagementProtocol; import org.wildfly.extras.creaper.core.online.OnlineManagementClient; @@ -12,6 +13,8 @@ import sunstone.core.exceptions.SunstoneException; import java.io.IOException; +import java.util.Arrays; +import java.util.Optional; import static sunstone.core.SunstoneConfig.getString; import static sunstone.core.SunstoneConfig.getValue; @@ -65,4 +68,24 @@ public static OnlineManagementClient createDomainManagementClient(String hostnam throw new IllegalArgumentSunstoneException("Port is not a number.", e); } } + + public static void setDomainServers(Deploy.Builder builder, DomainMode domainMode) { + if (domainMode == null || domainMode.serverGroups() == null) { + throw new RuntimeException(WildFlyConfig.DOMAIN_SERVER_GROUPS + " is not set"); + } + String[] serverGroupsParams = domainMode.serverGroups(); + boolean deployedToNone = true; + + for (String sgParam : serverGroupsParams) { + Optional 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(); + } + } }