diff --git a/aws/src/main/java/sunstone/aws/impl/AwsIdentifiableSunstoneResource.java b/aws/src/main/java/sunstone/aws/impl/AwsIdentifiableSunstoneResource.java index a3d66069..4cc5dedc 100644 --- a/aws/src/main/java/sunstone/aws/impl/AwsIdentifiableSunstoneResource.java +++ b/aws/src/main/java/sunstone/aws/impl/AwsIdentifiableSunstoneResource.java @@ -9,7 +9,7 @@ import sunstone.aws.annotation.AwsAutoResolve; import sunstone.aws.annotation.AwsEc2Instance; import sunstone.aws.annotation.AwsRds; -import sunstone.core.SunstoneConfig; +import sunstone.core.SunstoneConfigResolver; import sunstone.core.exceptions.IllegalArgumentSunstoneException; import sunstone.core.exceptions.SunstoneCloudResourceException; import sunstone.core.exceptions.SunstoneException; @@ -76,8 +76,8 @@ T get(Annotation injectionAnnotation, AwsSunstoneStore store, Class clazz getRepresentedInjectionAnnotation().getName(), injectionAnnotation.annotationType().getName())); } AwsEc2Instance vm = (AwsEc2Instance) injectionAnnotation; - String vmNameTag = SunstoneConfig.resolveExpressionToString(vm.nameTag()); - String region = SunstoneConfig.resolveExpressionToString(vm.region()); + String vmNameTag = SunstoneConfigResolver.resolveExpressionToString(vm.nameTag()); + String region = SunstoneConfigResolver.resolveExpressionToString(vm.region()); Optional awsEc2 = AwsUtils.findEc2InstanceByNameTag(store.getAwsEc2ClientOrCreate(region), vmNameTag); return clazz.cast(awsEc2.orElseThrow(() -> new SunstoneCloudResourceException(format("Unable to find '%s' AWS EC2 instance in '%s' region.", vmNameTag, region)))); } @@ -98,8 +98,8 @@ T get(Annotation injectionAnnotation, AwsSunstoneStore store, Class clazz getRepresentedInjectionAnnotation().getName(), injectionAnnotation.annotationType().getName())); } AwsRds rds = (AwsRds) injectionAnnotation; - String vmNameTag = SunstoneConfig.resolveExpressionToString(rds.name()); - String region = SunstoneConfig.resolveExpressionToString(rds.region()); + String vmNameTag = SunstoneConfigResolver.resolveExpressionToString(rds.name()); + String region = SunstoneConfigResolver.resolveExpressionToString(rds.region()); Optional awsRds = AwsUtils.findRdsInstanceByNameTag(store.getAwsRdsClientOrCreate(region), vmNameTag); return clazz.cast(awsRds.orElseThrow(() -> new SunstoneCloudResourceException(format("Unable to find '%s' AWS RDS instance in '%s' region.", vmNameTag, region)))); } diff --git a/aws/src/main/java/sunstone/aws/impl/AwsSunstoneDeployer.java b/aws/src/main/java/sunstone/aws/impl/AwsSunstoneDeployer.java index 23c90397..627bfa49 100644 --- a/aws/src/main/java/sunstone/aws/impl/AwsSunstoneDeployer.java +++ b/aws/src/main/java/sunstone/aws/impl/AwsSunstoneDeployer.java @@ -6,7 +6,7 @@ import sunstone.aws.annotation.WithAwsCfTemplate; import sunstone.aws.annotation.WithAwsCfTemplateRepeatable; import sunstone.core.AbstractSunstoneCloudDeployer; -import sunstone.core.SunstoneConfig; +import sunstone.core.SunstoneConfigResolver; import sunstone.core.SunstoneExtension; import sunstone.core.exceptions.IllegalArgumentSunstoneException; import sunstone.core.exceptions.SunstoneException; @@ -53,9 +53,9 @@ private void deployCfTemplate(WithAwsCfTemplate awsTemplateDefinition, AwsSunsto AwsCloudFormationCloudDeploymentManager deploymentManager = store.getAwsCfDemploymentManagerOrCreate(); try { - String content = getResourceContent(SunstoneConfig.resolveExpressionToString(awsTemplateDefinition.template())); + String content = getResourceContent(SunstoneConfigResolver.resolveExpressionToString(awsTemplateDefinition.template())); Map parameters = getParameters(awsTemplateDefinition.parameters()); - String region = SunstoneConfig.resolveExpressionToString(awsTemplateDefinition.region()); + String region = SunstoneConfigResolver.resolveExpressionToString(awsTemplateDefinition.region()); if (region == null) { throw new IllegalArgumentSunstoneException("Region for AWS template is not defined. It must be specified either " + "in the annotation or as Sunstone Config property."); diff --git a/aws/src/main/java/sunstone/aws/impl/AwsSunstoneResourceInjector.java b/aws/src/main/java/sunstone/aws/impl/AwsSunstoneResourceInjector.java index d294bc41..27e47329 100644 --- a/aws/src/main/java/sunstone/aws/impl/AwsSunstoneResourceInjector.java +++ b/aws/src/main/java/sunstone/aws/impl/AwsSunstoneResourceInjector.java @@ -9,7 +9,7 @@ import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.utils.SdkAutoCloseable; import sunstone.aws.annotation.AwsAutoResolve; -import sunstone.core.SunstoneConfig; +import sunstone.core.SunstoneConfigResolver; import sunstone.core.api.SunstoneResourceInjector; import sunstone.core.exceptions.IllegalArgumentSunstoneException; import sunstone.core.exceptions.SunstoneException; @@ -46,7 +46,7 @@ static Ec2Client resolveEc2ClientDI(AwsIdentifiableSunstoneResource.Identificati Ec2Client client; if (identification.type == AwsIdentifiableSunstoneResource.AUTO) { AwsAutoResolve annotation = (AwsAutoResolve) identification.identification; - client = AwsUtils.getEC2Client(SunstoneConfig.resolveExpressionToString(annotation.region())); + client = AwsUtils.getEC2Client(SunstoneConfigResolver.resolveExpressionToString(annotation.region())); } else { throw new UnsupportedSunstoneOperationException("EC2 Client may be injected only with " + AwsIdentifiableSunstoneResource.AUTO); } @@ -57,7 +57,7 @@ static S3Client resolveS3ClientDI(AwsIdentifiableSunstoneResource.Identification S3Client client; if (identification.type == AwsIdentifiableSunstoneResource.AUTO) { AwsAutoResolve annotation = (AwsAutoResolve) identification.identification; - client = AwsUtils.getS3Client(SunstoneConfig.resolveExpressionToString(annotation.region())); + client = AwsUtils.getS3Client(SunstoneConfigResolver.resolveExpressionToString(annotation.region())); } else { throw new UnsupportedSunstoneOperationException("EC2 Client may be injected only with " + AwsIdentifiableSunstoneResource.AUTO); } @@ -69,7 +69,7 @@ private RdsClient resolveRdsClientDI(AwsIdentifiableSunstoneResource.Identificat RdsClient client; if (identification.type == AwsIdentifiableSunstoneResource.AUTO) { AwsAutoResolve annotation = (AwsAutoResolve) identification.identification; - client = AwsUtils.getRdsClient(SunstoneConfig.resolveExpressionToString(annotation.region())); + client = AwsUtils.getRdsClient(SunstoneConfigResolver.resolveExpressionToString(annotation.region())); } else { throw new UnsupportedSunstoneOperationException("RDS Client may be injected only with " + AwsIdentifiableSunstoneResource.AUTO); } diff --git a/aws/src/main/java/sunstone/aws/impl/AwsUtils.java b/aws/src/main/java/sunstone/aws/impl/AwsUtils.java index 0ab3d7b7..68a65018 100644 --- a/aws/src/main/java/sunstone/aws/impl/AwsUtils.java +++ b/aws/src/main/java/sunstone/aws/impl/AwsUtils.java @@ -19,20 +19,20 @@ import software.amazon.awssdk.services.rds.model.DescribeDbInstancesResponse; import software.amazon.awssdk.services.s3.S3Client; -import sunstone.core.SunstoneConfig; +import sunstone.core.SunstoneConfigResolver; import java.util.Optional; class AwsUtils { private static AwsCredentialsProvider getCredentialsProvider() { - AwsBasicCredentials credentials = AwsBasicCredentials.create(SunstoneConfig.getString(AwsConfig.ACCESS_KEY_ID), SunstoneConfig.getString(AwsConfig.SECRET_ACCESS_KEY)); + AwsBasicCredentials credentials = AwsBasicCredentials.create(SunstoneConfigResolver.getString(AwsConfig.ACCESS_KEY_ID), SunstoneConfigResolver.getString(AwsConfig.SECRET_ACCESS_KEY)); return StaticCredentialsProvider.create(credentials); } static boolean propertiesForAwsClientArePresent() { - return SunstoneConfig.unwrap().isPropertyPresent(AwsConfig.ACCESS_KEY_ID) - && SunstoneConfig.unwrap().isPropertyPresent(AwsConfig.SECRET_ACCESS_KEY); + return SunstoneConfigResolver.unwrap().isPropertyPresent(AwsConfig.ACCESS_KEY_ID) + && SunstoneConfigResolver.unwrap().isPropertyPresent(AwsConfig.SECRET_ACCESS_KEY); } static Region getAndCheckRegion(String regionStr) { diff --git a/aws/src/test/java/aws/cloudformation/AwsTestUtils.java b/aws/src/test/java/aws/cloudformation/AwsTestUtils.java index dfd2e6da..a07fc734 100644 --- a/aws/src/test/java/aws/cloudformation/AwsTestUtils.java +++ b/aws/src/test/java/aws/cloudformation/AwsTestUtils.java @@ -11,7 +11,7 @@ import software.amazon.awssdk.services.ec2.model.Filter; import software.amazon.awssdk.services.ec2.model.KeyPairInfo; import sunstone.aws.impl.AwsConfig; -import sunstone.core.SunstoneConfig; +import sunstone.core.SunstoneConfigResolver; import java.util.List; @@ -19,7 +19,7 @@ public class AwsTestUtils { private static AwsCredentialsProvider getCredentialsProvider() { - AwsBasicCredentials credentials = AwsBasicCredentials.create(SunstoneConfig.getString(AwsConfig.ACCESS_KEY_ID), SunstoneConfig.getString(AwsConfig.SECRET_ACCESS_KEY)); + AwsBasicCredentials credentials = AwsBasicCredentials.create(SunstoneConfigResolver.getString(AwsConfig.ACCESS_KEY_ID), SunstoneConfigResolver.getString(AwsConfig.SECRET_ACCESS_KEY)); return StaticCredentialsProvider.create(credentials); } @@ -33,7 +33,7 @@ static Region getAndCheckRegion(String regionStr) { public static Ec2Client getEC2Client() { Ec2Client ec2Client = Ec2Client.builder() - .region(Region.of(SunstoneConfig.getString(AwsConfig.REGION))) + .region(Region.of(SunstoneConfigResolver.getString(AwsConfig.REGION))) .credentialsProvider(getCredentialsProvider()) .build(); return ec2Client; diff --git a/azure/src/main/java/sunstone/azure/impl/AzureArmTemplateCloudDeploymentManager.java b/azure/src/main/java/sunstone/azure/impl/AzureArmTemplateCloudDeploymentManager.java index 40afa36d..60c5a23e 100644 --- a/azure/src/main/java/sunstone/azure/impl/AzureArmTemplateCloudDeploymentManager.java +++ b/azure/src/main/java/sunstone/azure/impl/AzureArmTemplateCloudDeploymentManager.java @@ -24,7 +24,7 @@ import java.util.Set; import java.util.UUID; -import static sunstone.core.SunstoneConfig.getValue; +import static sunstone.core.SunstoneConfigResolver.getValue; /** * Purpose: the class handles Azure template - deploy and undeploy the template to and from a stack. diff --git a/azure/src/main/java/sunstone/azure/impl/AzureIdentifiableSunstoneResource.java b/azure/src/main/java/sunstone/azure/impl/AzureIdentifiableSunstoneResource.java index 4c798ff7..285de261 100644 --- a/azure/src/main/java/sunstone/azure/impl/AzureIdentifiableSunstoneResource.java +++ b/azure/src/main/java/sunstone/azure/impl/AzureIdentifiableSunstoneResource.java @@ -12,7 +12,7 @@ import sunstone.azure.annotation.AzurePgSqlServer; import sunstone.azure.annotation.AzureVirtualMachine; import sunstone.azure.annotation.AzureWebApplication; -import sunstone.core.SunstoneConfig; +import sunstone.core.SunstoneConfigResolver; import sunstone.core.exceptions.IllegalArgumentSunstoneException; import sunstone.core.exceptions.SunstoneCloudResourceException; import sunstone.core.exceptions.SunstoneException; @@ -78,8 +78,8 @@ T get(Annotation injectionAnnotation, AzureSunstoneStore store, Class cla getRepresentedInjectionAnnotation().getName(), injectionAnnotation.annotationType().getName())); } AzureVirtualMachine vm = (AzureVirtualMachine) injectionAnnotation; - String vmName = SunstoneConfig.resolveExpressionToString(vm.name()); - String vmGroup = SunstoneConfig.resolveExpressionToString(vm.group()); + String vmName = SunstoneConfigResolver.resolveExpressionToString(vm.name()); + String vmGroup = SunstoneConfigResolver.resolveExpressionToString(vm.group()); Optional azureVM = AzureUtils.findAzureVM(store.getAzureArmClientOrCreate(), vmName, vmGroup); return clazz.cast(azureVM.orElseThrow(() -> new SunstoneCloudResourceException(format("Unable to find '%s' Azure VM in '%s' resource group.", vmName, vmGroup)))); } @@ -106,8 +106,8 @@ T get(Annotation injectionAnnotation, AzureSunstoneStore store, Class cla getRepresentedInjectionAnnotation().getName(), injectionAnnotation.annotationType().getName())); } AzureWebApplication webApp = (AzureWebApplication) injectionAnnotation; - String appName = SunstoneConfig.resolveExpressionToString(webApp.name()); - String appGroup = SunstoneConfig.resolveExpressionToString(webApp.group()); + String appName = SunstoneConfigResolver.resolveExpressionToString(webApp.name()); + String appGroup = SunstoneConfigResolver.resolveExpressionToString(webApp.group()); Optional azureWebApp = AzureUtils.findAzureWebApp(store.getAzureArmClientOrCreate(), appName, appGroup); return clazz.cast(azureWebApp.orElseThrow(() -> new SunstoneCloudResourceException(format("Unable to find '%s' Azure Web App in '%s' resource group.", appName, appGroup)))); } @@ -133,8 +133,8 @@ T get(Annotation injectionAnnotation, AzureSunstoneStore store, Class cla getRepresentedInjectionAnnotation().getName(), injectionAnnotation.annotationType().getName())); } AzureAppServicePlan plan = (AzureAppServicePlan) injectionAnnotation; - String planName = SunstoneConfig.resolveExpressionToString(plan.name()); - String planGroup = SunstoneConfig.resolveExpressionToString(plan.group()); + String planName = SunstoneConfigResolver.resolveExpressionToString(plan.name()); + String planGroup = SunstoneConfigResolver.resolveExpressionToString(plan.group()); Optional azureWebApp = AzureUtils.findAzureAppServicePlan(store.getAzureArmClientOrCreate(), planName, planGroup); return clazz.cast(azureWebApp.orElseThrow(() -> new SunstoneCloudResourceException(format("Unable to find '%s' Azure App Service plan in '%s' resource group.", planName, planGroup)))); } @@ -159,8 +159,8 @@ T get(Annotation injectionAnnotation, AzureSunstoneStore store, Class cla getRepresentedInjectionAnnotation().getName(), injectionAnnotation.annotationType().getName())); } AzurePgSqlServer pgsqlServer = (AzurePgSqlServer) injectionAnnotation; - String serverName = SunstoneConfig.resolveExpressionToString(pgsqlServer.name()); - String serverGroup = SunstoneConfig.resolveExpressionToString(pgsqlServer.group()); + String serverName = SunstoneConfigResolver.resolveExpressionToString(pgsqlServer.name()); + String serverGroup = SunstoneConfigResolver.resolveExpressionToString(pgsqlServer.group()); Optional azureWebApp = AzureUtils.findAzurePgSqlServer(store.getAzurePgSqlManagerOrCreate(), serverName, serverGroup); return clazz.cast(azureWebApp.orElseThrow(() -> new SunstoneCloudResourceException(format("Unable to find '%s' Azure PostgreSql Server in '%s' resource group.", serverName, serverGroup)))); } diff --git a/azure/src/main/java/sunstone/azure/impl/AzureSunstoneDeployer.java b/azure/src/main/java/sunstone/azure/impl/AzureSunstoneDeployer.java index 5cfb1664..f08a858f 100644 --- a/azure/src/main/java/sunstone/azure/impl/AzureSunstoneDeployer.java +++ b/azure/src/main/java/sunstone/azure/impl/AzureSunstoneDeployer.java @@ -5,7 +5,7 @@ import sunstone.azure.annotation.WithAzureArmTemplate; import sunstone.azure.annotation.WithAzureArmTemplateRepeatable; import sunstone.core.AbstractSunstoneCloudDeployer; -import sunstone.core.SunstoneConfig; +import sunstone.core.SunstoneConfigResolver; import sunstone.core.SunstoneExtension; import sunstone.core.exceptions.IllegalArgumentSunstoneException; import sunstone.core.exceptions.SunstoneException; @@ -51,13 +51,13 @@ private void deployArmTemplate(WithAzureArmTemplate armTemplateDefinition, Azure String content = null; try { - content = getResourceContent(SunstoneConfig.resolveExpressionToString(armTemplateDefinition.template())); - String group = SunstoneConfig.resolveExpressionToString(armTemplateDefinition.group()); + content = getResourceContent(SunstoneConfigResolver.resolveExpressionToString(armTemplateDefinition.template())); + String group = SunstoneConfigResolver.resolveExpressionToString(armTemplateDefinition.group()); if (group == null) { throw new IllegalArgumentSunstoneException("Resource group for Azure ARM template is not defined. " + "It must be specified either in the annotation or as Sunstone Config property."); } - String region = SunstoneConfig.resolveExpressionToString(armTemplateDefinition.region()); + String region = SunstoneConfigResolver.resolveExpressionToString(armTemplateDefinition.region()); if (region == null) { throw new IllegalArgumentSunstoneException("Region for Azure ARM template is not defined. It must be specified either " + "in the annotation or as Sunstone Config property."); diff --git a/azure/src/main/java/sunstone/azure/impl/AzureUtils.java b/azure/src/main/java/sunstone/azure/impl/AzureUtils.java index b3c1dcb0..28075018 100644 --- a/azure/src/main/java/sunstone/azure/impl/AzureUtils.java +++ b/azure/src/main/java/sunstone/azure/impl/AzureUtils.java @@ -15,7 +15,7 @@ import com.azure.resourcemanager.postgresqlflexibleserver.PostgreSqlManager; import com.azure.resourcemanager.postgresqlflexibleserver.models.Server; import org.slf4j.Logger; -import sunstone.core.SunstoneConfig; +import sunstone.core.SunstoneConfigResolver; import java.io.IOException; import java.nio.file.Files; @@ -26,33 +26,33 @@ import java.util.Optional; import java.util.stream.Collectors; -import static sunstone.core.SunstoneConfig.getValue; +import static sunstone.core.SunstoneConfigResolver.getValue; public class AzureUtils { static Logger LOGGER = AzureLogger.DEFAULT; static AzureResourceManager getResourceManager() { return AzureResourceManager .authenticate(getCredentials(), new AzureProfile(AzureEnvironment.AZURE)) - .withSubscription(SunstoneConfig.getString(AzureConfig.SUBSCRIPTION_ID)); + .withSubscription(SunstoneConfigResolver.getString(AzureConfig.SUBSCRIPTION_ID)); } static PostgreSqlManager getPgsqlManager() { return PostgreSqlManager - .authenticate(getCredentials(), new AzureProfile(SunstoneConfig.getString(AzureConfig.TENANT_ID), SunstoneConfig.getString(AzureConfig.SUBSCRIPTION_ID), AzureEnvironment.AZURE)); + .authenticate(getCredentials(), new AzureProfile(SunstoneConfigResolver.getString(AzureConfig.TENANT_ID), SunstoneConfigResolver.getString(AzureConfig.SUBSCRIPTION_ID), AzureEnvironment.AZURE)); } private static TokenCredential getCredentials() { return new ClientSecretCredentialBuilder() - .tenantId(SunstoneConfig.getString(AzureConfig.TENANT_ID)) - .clientId(SunstoneConfig.getString(AzureConfig.APPLICATION_ID)) - .clientSecret(SunstoneConfig.getString(AzureConfig.PASSWORD)) + .tenantId(SunstoneConfigResolver.getString(AzureConfig.TENANT_ID)) + .clientId(SunstoneConfigResolver.getString(AzureConfig.APPLICATION_ID)) + .clientSecret(SunstoneConfigResolver.getString(AzureConfig.PASSWORD)) .build(); } static boolean propertiesForArmClientArePresent() { - return SunstoneConfig.unwrap().isPropertyPresent(AzureConfig.SUBSCRIPTION_ID) - && SunstoneConfig.unwrap().isPropertyPresent(AzureConfig.TENANT_ID) - && SunstoneConfig.unwrap().isPropertyPresent(AzureConfig.APPLICATION_ID) - && SunstoneConfig.unwrap().isPropertyPresent(AzureConfig.PASSWORD); + return SunstoneConfigResolver.unwrap().isPropertyPresent(AzureConfig.SUBSCRIPTION_ID) + && SunstoneConfigResolver.unwrap().isPropertyPresent(AzureConfig.TENANT_ID) + && SunstoneConfigResolver.unwrap().isPropertyPresent(AzureConfig.APPLICATION_ID) + && SunstoneConfigResolver.unwrap().isPropertyPresent(AzureConfig.PASSWORD); } static Optional findAzureVM(AzureResourceManager arm, String name, String resourceGroup) { diff --git a/azure/src/test/java/sunstone/azure/armTemplates/AzureTestUtils.java b/azure/src/test/java/sunstone/azure/armTemplates/AzureTestUtils.java index e653df72..d3e4a87f 100644 --- a/azure/src/test/java/sunstone/azure/armTemplates/AzureTestUtils.java +++ b/azure/src/test/java/sunstone/azure/armTemplates/AzureTestUtils.java @@ -7,20 +7,20 @@ import com.azure.identity.ClientSecretCredentialBuilder; import com.azure.resourcemanager.AzureResourceManager; import sunstone.azure.impl.AzureConfig; -import sunstone.core.SunstoneConfig; +import sunstone.core.SunstoneConfigResolver; public class AzureTestUtils { public static AzureResourceManager getResourceManager() { return AzureResourceManager .authenticate(getCredentials(), new AzureProfile(AzureEnvironment.AZURE)) - .withSubscription(SunstoneConfig.getString(AzureConfig.SUBSCRIPTION_ID)); + .withSubscription(SunstoneConfigResolver.getString(AzureConfig.SUBSCRIPTION_ID)); } private static TokenCredential getCredentials() { return new ClientSecretCredentialBuilder() - .tenantId(SunstoneConfig.getString(AzureConfig.TENANT_ID)) - .clientId(SunstoneConfig.getString(AzureConfig.APPLICATION_ID)) - .clientSecret(SunstoneConfig.getString(AzureConfig.PASSWORD)) + .tenantId(SunstoneConfigResolver.getString(AzureConfig.TENANT_ID)) + .clientId(SunstoneConfigResolver.getString(AzureConfig.APPLICATION_ID)) + .clientSecret(SunstoneConfigResolver.getString(AzureConfig.PASSWORD)) .build(); } } diff --git a/core-wildfly/src/main/java/sunstone/core/CreaperUtils.java b/core-wildfly/src/main/java/sunstone/core/CreaperUtils.java index fabeffd7..69579ffb 100644 --- a/core-wildfly/src/main/java/sunstone/core/CreaperUtils.java +++ b/core-wildfly/src/main/java/sunstone/core/CreaperUtils.java @@ -16,10 +16,10 @@ import java.util.Arrays; import java.util.Optional; -import static sunstone.core.SunstoneConfig.getString; -import static sunstone.core.SunstoneConfig.getValue; -import static sunstone.core.SunstoneConfig.isExpression; -import static sunstone.core.SunstoneConfig.resolveExpressionToString; +import static sunstone.core.SunstoneConfigResolver.getString; +import static sunstone.core.SunstoneConfigResolver.getValue; +import static sunstone.core.SunstoneConfigResolver.isExpression; +import static sunstone.core.SunstoneConfigResolver.resolveExpressionToString; public class CreaperUtils { static Logger LOGGER = WildFlyLogger.DEFAULT; @@ -27,7 +27,7 @@ public class CreaperUtils { public static OnlineManagementClient createStandaloneManagementClient(String hostname, StandaloneMode standaloneMode) throws IOException, SunstoneException { try { - int port = isExpression(standaloneMode.port()) ? SunstoneConfig.resolveExpression(standaloneMode.port(), Integer.class) : Integer.parseInt(standaloneMode.port()); + int port = isExpression(standaloneMode.port()) ? SunstoneConfigResolver.resolveExpression(standaloneMode.port(), Integer.class) : Integer.parseInt(standaloneMode.port()); String user = isExpression(standaloneMode.user()) ? resolveExpressionToString(standaloneMode.user()) : standaloneMode.user(); String pass = isExpression(standaloneMode.password()) ? resolveExpressionToString(standaloneMode.password()) : standaloneMode.password(); int timeout = (int) TimeoutUtils.adjust(getValue(WildFlyConfig.MGMT_CONNECTION_TIMEOUT, 120000)); @@ -46,7 +46,7 @@ public static OnlineManagementClient createStandaloneManagementClient(String hos public static OnlineManagementClient createDomainManagementClient(String hostname, DomainMode domainMode) throws IOException, SunstoneException { try { - int port = isExpression(domainMode.port()) ? SunstoneConfig.resolveExpression(domainMode.port(), Integer.class) : Integer.parseInt(domainMode.port()); + int port = isExpression(domainMode.port()) ? SunstoneConfigResolver.resolveExpression(domainMode.port(), Integer.class) : Integer.parseInt(domainMode.port()); String user = isExpression(domainMode.user()) ? resolveExpressionToString(domainMode.user()) : getString(domainMode.user()); String pass = isExpression(domainMode.password()) ? resolveExpressionToString(domainMode.password()) : domainMode.password(); int timeout = (int) TimeoutUtils.adjust(getValue(WildFlyConfig.MGMT_CONNECTION_TIMEOUT, 120000)); @@ -77,7 +77,7 @@ public static void setDomainServers(Deploy.Builder builder, DomainMode domainMod boolean deployedToNone = true; for (String sgParam : serverGroupsParams) { - Optional serverGroups = isExpression(sgParam) ? SunstoneConfig.resolveOptionalExpression(sgParam, String[].class) : Optional.of(new String[]{sgParam}); + Optional serverGroups = isExpression(sgParam) ? SunstoneConfigResolver.resolveOptionalExpression(sgParam, String[].class) : Optional.of(new String[]{sgParam}); if (serverGroups.isPresent()) { deployedToNone = false; serverGroups.ifPresent(groups -> Arrays.stream(groups).forEach(builder::toServerGroups)); diff --git a/core/src/main/java/sunstone/core/AbstractSunstoneCloudDeployer.java b/core/src/main/java/sunstone/core/AbstractSunstoneCloudDeployer.java index f46acc8e..0879760d 100644 --- a/core/src/main/java/sunstone/core/AbstractSunstoneCloudDeployer.java +++ b/core/src/main/java/sunstone/core/AbstractSunstoneCloudDeployer.java @@ -12,8 +12,8 @@ import java.util.HashMap; import java.util.Map; -import static sunstone.core.SunstoneConfig.resolveExpression; -import static sunstone.core.SunstoneConfig.resolveOptionalExpression; +import static sunstone.core.SunstoneConfigResolver.resolveExpression; +import static sunstone.core.SunstoneConfigResolver.resolveOptionalExpression; /** * Abstract class for providing common functionality for deploy operation to clouds. Tha class focuses on utilizing diff --git a/core/src/main/java/sunstone/core/ConfigProperties.java b/core/src/main/java/sunstone/core/CoreConfig.java similarity index 76% rename from core/src/main/java/sunstone/core/ConfigProperties.java rename to core/src/main/java/sunstone/core/CoreConfig.java index 00274af0..5e92ab61 100644 --- a/core/src/main/java/sunstone/core/ConfigProperties.java +++ b/core/src/main/java/sunstone/core/CoreConfig.java @@ -1,7 +1,7 @@ package sunstone.core; -public class ConfigProperties { +public class CoreConfig { public static final String TIMEOUT_FACTOR = "sunstone.timeout.factor"; } diff --git a/core/src/main/java/sunstone/core/CoreSunstoneResourceInjector.java b/core/src/main/java/sunstone/core/CoreSunstoneResourceInjector.java index 793abaf2..c253090f 100644 --- a/core/src/main/java/sunstone/core/CoreSunstoneResourceInjector.java +++ b/core/src/main/java/sunstone/core/CoreSunstoneResourceInjector.java @@ -31,10 +31,10 @@ public Object getResource(ExtensionContext ctx) throws SunstoneException { } SunstoneProperty sunstoneProperty = SunstoneProperty.class.cast(identification); if (!StringUtils.isBlank(sunstoneProperty.value())) { - return SunstoneConfig.getValue(sunstoneProperty.value(), fieldType); + return SunstoneConfigResolver.getValue(sunstoneProperty.value(), fieldType); } if (!StringUtils.isBlank(sunstoneProperty.expression())) { - return SunstoneConfig.resolveExpression(sunstoneProperty.expression(), fieldType); + return SunstoneConfigResolver.resolveExpression(sunstoneProperty.expression(), fieldType); } throw new IllegalArgumentSunstoneException("Both value and expression in @SunstoneProperty are blank, which is not allowed."); } diff --git a/core/src/main/java/sunstone/core/SunstoneConfig.java b/core/src/main/java/sunstone/core/SunstoneConfigResolver.java similarity index 99% rename from core/src/main/java/sunstone/core/SunstoneConfig.java rename to core/src/main/java/sunstone/core/SunstoneConfigResolver.java index 46076801..4fa6b70a 100644 --- a/core/src/main/java/sunstone/core/SunstoneConfig.java +++ b/core/src/main/java/sunstone/core/SunstoneConfigResolver.java @@ -17,7 +17,7 @@ /** * The class wraps and configure SmallRyeConfig so that it can resolve bare expressions and read sunstone.properties */ -public class SunstoneConfig { +public class SunstoneConfigResolver { static final SmallRyeConfig config = new SmallRyeConfigBuilder() .addDefaultInterceptors() diff --git a/core/src/main/java/sunstone/core/SunstoneExtension.java b/core/src/main/java/sunstone/core/SunstoneExtension.java index abc09a04..b7b68616 100644 --- a/core/src/main/java/sunstone/core/SunstoneExtension.java +++ b/core/src/main/java/sunstone/core/SunstoneExtension.java @@ -192,7 +192,7 @@ static void performDeploymentOperation(ExtensionContext ctx) throws SunstoneExce throw new IllegalArgumentSunstoneException("Deployment method must have 0 parameters"); } Deployment annotation = method.getAnnotation(Deployment.class); - String deploymentName = StringUtils.isBlank(annotation.name()) ? "" : SunstoneConfig.resolveExpressionToString(annotation.name()); + String deploymentName = StringUtils.isBlank(annotation.name()) ? "" : SunstoneConfigResolver.resolveExpressionToString(annotation.name()); method.setAccessible(true); Object invoke = method.invoke(null); diff --git a/core/src/main/java/sunstone/core/TimeoutUtils.java b/core/src/main/java/sunstone/core/TimeoutUtils.java index fe574fee..665b7975 100644 --- a/core/src/main/java/sunstone/core/TimeoutUtils.java +++ b/core/src/main/java/sunstone/core/TimeoutUtils.java @@ -2,7 +2,7 @@ public class TimeoutUtils { - private static double factor = SunstoneConfig.getValue(ConfigProperties.TIMEOUT_FACTOR, 1.0); + private static double factor = SunstoneConfigResolver.getValue(CoreConfig.TIMEOUT_FACTOR, 1.0); public static long adjust(long amount) { if (amount < 0) { diff --git a/core/src/test/java/sunstone/core/SunstoneConfigResolverTest.java b/core/src/test/java/sunstone/core/SunstoneConfigResolverTest.java new file mode 100644 index 00000000..0ce4074f --- /dev/null +++ b/core/src/test/java/sunstone/core/SunstoneConfigResolverTest.java @@ -0,0 +1,73 @@ +package sunstone.core; + + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class SunstoneConfigResolverTest { + + @BeforeAll + static void setup() { + System.setProperty("sunstone.test.system", "valueSet"); + } + + @AfterAll + static void tearDown() { + System.clearProperty("sunstone.test.system"); + } + + @BeforeEach + public void cleanup(){ + SunstoneConfigResolver.SunstoneExpressionSource.expressions.clear(); + } + + @Test + public void fromPropertyFileSimple() { + Assertions.assertThat(SunstoneConfigResolver.getValue("property", String.class)).isEqualTo("value"); + } + + @Test + public void fromPropertyFileExpressionResolvedToDefault() { + Assertions.assertThat(SunstoneConfigResolver.getValue("expressionToDefault", String.class)).isEqualTo("expressionDefaultValue"); + } + + @Test + public void fromPropertyFileExpressionResolvedToSystemProperty() { + Assertions.assertThat(SunstoneConfigResolver.getValue("expressionToSystemProperty", String.class)).isEqualTo("valueSet"); + } + + @Test + public void expressionResolved() { + Assertions.assertThat(SunstoneConfigResolver.resolveExpression("${expressionToSystemProperty}", String.class)).isEqualTo("valueSet"); + Assertions.assertThat(SunstoneConfigResolver.resolveExpression("${expressionToSystemProperty}", String.class)).isEqualTo("valueSet"); + Assertions.assertThat(SunstoneConfigResolver.resolveExpression("${sunstone.test.system}", String.class)).isEqualTo("valueSet"); + Assertions.assertThat(SunstoneConfigResolver.SunstoneExpressionSource.expressions.size()).isEqualTo(2); + } + + @Test + public void nestedExpressionResolved() { + Assertions.assertThat(SunstoneConfigResolver.resolveExpression("prefix-${expressionToSystemProperty}-${expressionToSystemProperty}-suffix", String.class)).isEqualTo("prefix-valueSet-valueSet-suffix"); + Assertions.assertThat(SunstoneConfigResolver.resolveExpression("prefix-${expressionToSystemProperty}-${expressionToSystemProperty}-suffix", String.class)).isEqualTo("prefix-valueSet-valueSet-suffix"); + Assertions.assertThat(SunstoneConfigResolver.resolveExpression("prefix-${sunstone.test.system}-${sunstone.test.system}-suffix", String.class)).isEqualTo("prefix-valueSet-valueSet-suffix"); + Assertions.assertThat(SunstoneConfigResolver.SunstoneExpressionSource.expressions.size()).isEqualTo(2); + } + + @Test + public void resolveNotExpression() { + Assertions.assertThat(SunstoneConfigResolver.resolveExpression("not.a.expression", String.class)).isEqualTo("not.a.expression"); + } + + @Test + public void isExpressionTest() { + Assertions.assertThat(SunstoneConfigResolver.isExpression("${expression}")).isTrue(); + Assertions.assertThat(SunstoneConfigResolver.isExpression("xyz-${expression}-qwerty")).isTrue(); + Assertions.assertThat(SunstoneConfigResolver.isExpression("notexpression")).isFalse(); + Assertions.assertThat(SunstoneConfigResolver.isExpression("${notexpression")).isFalse(); + Assertions.assertThat(SunstoneConfigResolver.isExpression("not${expression")).isFalse(); + Assertions.assertThat(SunstoneConfigResolver.isExpression("not}expression")).isFalse(); + Assertions.assertThat(SunstoneConfigResolver.isExpression("")).isFalse(); + } +} diff --git a/core/src/test/java/sunstone/core/SunstoneConfigTest.java b/core/src/test/java/sunstone/core/SunstoneConfigTest.java deleted file mode 100644 index d7170ec2..00000000 --- a/core/src/test/java/sunstone/core/SunstoneConfigTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package sunstone.core; - - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class SunstoneConfigTest { - - @BeforeAll - static void setup() { - System.setProperty("sunstone.test.system", "valueSet"); - } - - @AfterAll - static void tearDown() { - System.clearProperty("sunstone.test.system"); - } - - @BeforeEach - public void cleanup(){ - SunstoneConfig.SunstoneExpressionSource.expressions.clear(); - } - - @Test - public void fromPropertyFileSimple() { - Assertions.assertThat(SunstoneConfig.getValue("property", String.class)).isEqualTo("value"); - } - - @Test - public void fromPropertyFileExpressionResolvedToDefault() { - Assertions.assertThat(SunstoneConfig.getValue("expressionToDefault", String.class)).isEqualTo("expressionDefaultValue"); - } - - @Test - public void fromPropertyFileExpressionResolvedToSystemProperty() { - Assertions.assertThat(SunstoneConfig.getValue("expressionToSystemProperty", String.class)).isEqualTo("valueSet"); - } - - @Test - public void expressionResolved() { - Assertions.assertThat(SunstoneConfig.resolveExpression("${expressionToSystemProperty}", String.class)).isEqualTo("valueSet"); - Assertions.assertThat(SunstoneConfig.resolveExpression("${expressionToSystemProperty}", String.class)).isEqualTo("valueSet"); - Assertions.assertThat(SunstoneConfig.resolveExpression("${sunstone.test.system}", String.class)).isEqualTo("valueSet"); - Assertions.assertThat(SunstoneConfig.SunstoneExpressionSource.expressions.size()).isEqualTo(2); - } - - @Test - public void nestedExpressionResolved() { - Assertions.assertThat(SunstoneConfig.resolveExpression("prefix-${expressionToSystemProperty}-${expressionToSystemProperty}-suffix", String.class)).isEqualTo("prefix-valueSet-valueSet-suffix"); - Assertions.assertThat(SunstoneConfig.resolveExpression("prefix-${expressionToSystemProperty}-${expressionToSystemProperty}-suffix", String.class)).isEqualTo("prefix-valueSet-valueSet-suffix"); - Assertions.assertThat(SunstoneConfig.resolveExpression("prefix-${sunstone.test.system}-${sunstone.test.system}-suffix", String.class)).isEqualTo("prefix-valueSet-valueSet-suffix"); - Assertions.assertThat(SunstoneConfig.SunstoneExpressionSource.expressions.size()).isEqualTo(2); - } - - @Test - public void resolveNotExpression() { - Assertions.assertThat(SunstoneConfig.resolveExpression("not.a.expression", String.class)).isEqualTo("not.a.expression"); - } - - @Test - public void isExpressionTest() { - Assertions.assertThat(SunstoneConfig.isExpression("${expression}")).isTrue(); - Assertions.assertThat(SunstoneConfig.isExpression("xyz-${expression}-qwerty")).isTrue(); - Assertions.assertThat(SunstoneConfig.isExpression("notexpression")).isFalse(); - Assertions.assertThat(SunstoneConfig.isExpression("${notexpression")).isFalse(); - Assertions.assertThat(SunstoneConfig.isExpression("not${expression")).isFalse(); - Assertions.assertThat(SunstoneConfig.isExpression("not}expression")).isFalse(); - Assertions.assertThat(SunstoneConfig.isExpression("")).isFalse(); - } -}