Skip to content

Commit

Permalink
refractor duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
laDok8 committed Feb 14, 2024
1 parent 034aaa1 commit bd017b4
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 312 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 @@ -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;
Expand All @@ -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;


/**
Expand Down Expand Up @@ -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<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 = AzureWFIdentifiableSunstoneResourceUtils.resolveOnlineManagementClient(resourceIdentification, wildFly, store)){
client.apply(builder.build());
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 Down
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 @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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
13 changes: 6 additions & 7 deletions azure-wildfly/src/test/resources/sunstone.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 Down Expand Up @@ -179,6 +202,11 @@
"enabled": true
}
}
},
"plan": {
"name": "[parameters('planName')]",
"publisher": "[parameters('publisher')]",
"product": "[parameters('product')]"
}
}
],
Expand Down
Loading

0 comments on commit bd017b4

Please sign in to comment.