From 30cd213f4b027633d2a7bdc6ee35a0896cbc1969 Mon Sep 17 00:00:00 2001 From: djizatt-avio <146856310+djizatt-avio@users.noreply.github.com> Date: Fri, 8 Nov 2024 00:41:56 -0500 Subject: [PATCH] Initial Model object changes for Cloudhub V2 Deployment Fucntionality (#98) * Many updates to the CloudhubV2 and RuntimeFabric contexts and deployments requires to align with latest API * Updates to many test cases to correct issues and align with new parameters. * Added support for environmentProperty and cryptoKeyProperty to customize which properties are used for those. * Added support for properties with md. prefix in addition to muleDeploy. prefix. * If run from maven groupId, artifactId and artifactVersion are populated automatically into the params object but can be overridden. *Updated logic for determining API Layer --------- Co-authored-by: Adam DesJardin --- library/examples/muleDeploy_ch2.groovy | 5 + library/pom.xml | 1 + .../api/models/UpdateStrategy.groovy | 2 + .../api/models/WorkerSpecRequest.groovy | 116 +++--- .../deployment/AppDeploymentRequest.groovy | 9 +- .../CloudhubDeploymentRequest.groovy | 35 +- .../CloudhubV2DeploymentRequest.groovy | 6 +- .../ExchangeAppDeploymentRequest.groovy | 4 +- .../FileBasedAppDeploymentRequest.groovy | 4 +- .../deployment/OnPremDeploymentRequest.groovy | 3 +- .../RuntimeFabricDeploymentRequest.groovy | 121 +++--- .../mule/deployment/dsl/BaseContext.groovy | 4 +- .../deployment/dsl/CloudhubV2Context.groovy | 22 +- .../dsl/RuntimeFabricContext.groovy | 34 +- .../deployment/dsl/WorkerSpecV2Context.groovy | 81 +++- .../dsl/policies/PolicyListContext.groovy | 2 +- .../models/CloudhubAppProperties.groovy | 32 +- .../avioconsulting/mule/MavenInvoke.groovy | 1 + .../CloudhubV2DeploymentRequestTest.groovy | 298 ++++++++------- .../RuntimeFabricDeploymentRequestTest.groovy | 357 ++++++++++-------- .../dsl/CloudhubV2ContextTest.groovy | 86 +++-- .../deployment/dsl/OnPremContextTest.groovy | 1 + .../dsl/RuntimeFabricContextTest.groovy | 72 ++-- .../internal/TestFileBasedRequest.groovy | 2 +- .../models/CloudhubAppPropertiesTest.groovy | 4 +- .../CloudHubV2DeployerTest.groovy | 197 +++------- .../RuntimeFabricDeployerTest.groovy | 246 +++++------- .../avioconsulting/mule/maven/BaseMojo.groovy | 25 +- .../mule/maven/ParamsWrapper.groovy | 5 + pom.xml | 8 +- 30 files changed, 931 insertions(+), 852 deletions(-) diff --git a/library/examples/muleDeploy_ch2.groovy b/library/examples/muleDeploy_ch2.groovy index 9c547c03..159f1f38 100644 --- a/library/examples/muleDeploy_ch2.groovy +++ b/library/examples/muleDeploy_ch2.groovy @@ -41,6 +41,11 @@ muleDeploy { updateStrategy 'recreate' forwardSslSession 'true' publicUrl 'myapp.anypoint.com' + pathRewrite '/test' + releaseChannel 'EDGE' + javaVersion '17' + tracingEnabled 'true' + generateDefaultPublicUrl 'false' } environment 'DEV' diff --git a/library/pom.xml b/library/pom.xml index 9d61cd76..d39042c1 100644 --- a/library/pom.xml +++ b/library/pom.xml @@ -88,6 +88,7 @@ **/IntegrationTest.java + com.avioconsulting.mule.integrationtest.CloudHubV2IntegrationTest diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/UpdateStrategy.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/UpdateStrategy.groovy index f6e9f517..15b2b5c4 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/UpdateStrategy.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/UpdateStrategy.groovy @@ -11,4 +11,6 @@ enum UpdateStrategy { * Re-deployment is quicker than rolling and doesn’t require additional resources. */ recreate + + String updateStrategy } diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/WorkerSpecRequest.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/WorkerSpecRequest.groovy index 9c1b1199..fccd892f 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/WorkerSpecRequest.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/WorkerSpecRequest.groovy @@ -15,103 +15,135 @@ class WorkerSpecRequest { * Enable Last-Mile security to forward HTTPS connections to be decrypted by this application. * This requires an SSL certificate to be included in the Mule ap. Defaults to false. */ - final boolean lastMileSecurity + boolean lastMileSecurity /*** - * Enables clustering across two or more replicas of the application. Defaults to false. + * Use ObjectStore v2. Defaults to false. */ - final boolean persistentObjectStore + boolean objectStoreV2 /*** - * Use persistent ObjectStore. Defaults to false. + * Enables clustering across two or more replicas of the application. Defaults to false. */ - final boolean clustered + boolean clustered /*** * rolling: Maintains availability by updating replicas incrementally. * recreate: Terminates replicas before re-deployment. Defaults to rolling. */ - final UpdateStrategy updateStrategy + UpdateStrategy updateStrategy /*** * Enforces the deployment of replicas across different nodes. Defaults to false. */ - final boolean replicasAcrossNodes + boolean replicasAcrossNodes /*** * Enables SSL forwarding during a session. Defaults to false. */ - final boolean forwardSslSession + boolean forwardSslSession /*** * Disables forwarding applications logs to Anypoint Monitoring.. Defaults to true. */ - final boolean disableAmLogForwarding + boolean disableAmLogForwarding /*** * When this parameter is set to true, CloudHub 2.0 generates a public URL for the deployed application. Default to false */ - final boolean publicURL + boolean generateDefaultPublicUrl /** * Specifies the number of cores to allocate for each application replica. The default value is 0.5 vCores * Valid only for RTF deployment, not for CloudHub 2.0 */ - final String cpuReserved + String cpuReserved /** * Specifies the amount of memory to allocate for each application replica. The default value is 700 MB * Valid only for RTF deployment, not for CloudHub 2.0 */ - final String memoryReserved + String memoryReserved /*** * How big of a worker to use */ - final VCoresSize replicaSize + VCoresSize replicaSize /*** * How many workers, defaults to 1 */ - final int workerCount + int workerCount /** * The CloudHub 2.0 target name to deploy the app to. * Specify either a shared space or a private space available in your Deployment Target values in CloudHub 2.0 */ - final String target - + String target + /*** + * The publicUrl, this is defined when the user wishes to deploy an API with a public ingress endpoint available + */ + String publicUrl + /*** + * Overwriting the publicUrl, this is defined and publicUrl is null when a User wishes to overwrite their custom url for the API + */ + String pathRewrite + /*** + * The releaseChannel, this is either LTS or EDGE + */ + String releaseChannel + /*** + * The Java Version, this is either 8 or 17 + */ + String javaVersion + /*** + * Tracing Enabled flag, this defaults to false + */ + Boolean tracingEnabled /*** * Standard request, see properties for parameter info. */ WorkerSpecRequest(String target, - String muleVersion = null, - boolean lastMileSecurity = false, - boolean persistentObjectStore = false, - boolean clustered = false, - UpdateStrategy updateStrategy = UpdateStrategy.rolling, - boolean replicasAcrossNodes = false, - boolean publicURL = false, - VCoresSize replicaSize = VCoresSize.vCore1GB, - int workerCount = 1, - boolean forwardSslSession = false, - boolean disableAmLogForwarding = true, - int cpuReserved = 20, - int memoryReserved = 700) { - this.muleVersion = muleVersion - this.lastMileSecurity = lastMileSecurity - this.persistentObjectStore = persistentObjectStore - this.clustered = clustered - this.updateStrategy = updateStrategy - this.replicasAcrossNodes = replicasAcrossNodes - this.publicURL = publicURL - this.forwardSslSession = forwardSslSession - this.disableAmLogForwarding = disableAmLogForwarding - this.cpuReserved = "${cpuReserved}m" - this.memoryReserved = "${memoryReserved}Mi" - this.replicaSize = replicaSize - this.workerCount = workerCount + String muleVersion, + Boolean lastMileSecurity, + Boolean objectStoreV2, + Boolean clustered, + UpdateStrategy updateStrategy, + Boolean replicasAcrossNodes, + Boolean generateDefaultPublicUrl, + VCoresSize replicaSize, + Integer workerCount, + Boolean forwardSslSession, + Boolean disableAmLogForwarding, + Integer cpuReserved, + Integer memoryReserved, + String publicUrl, + String pathRewrite, + String releaseChannel, + String javaVersion, + Boolean tracingEnabled) { + + println "target: $target, muleVersion: $muleVersion, lastMileSecurity: $lastMileSecurity, objectStoreV2: $objectStoreV2, clustered: $clustered, updateStrategy: $updateStrategy, replicasAcrossNodes: $replicasAcrossNodes, generateDefaultPublicUrl: $generateDefaultPublicUrl, replicaSize: $replicaSize, workerCount: $workerCount, forwardSslSession: $forwardSslSession, disableAmLogForwarding: $disableAmLogForwarding, cpuReserved: ${cpuReserved}m, memoryReserved: ${memoryReserved}Mi, publicUrl: $publicUrl, pathRewrite: $pathRewrite, releaseChannel: $releaseChannel, javaVersion: $javaVersion, tracingEnabled: $tracingEnabled" + this.target = target + this.muleVersion = muleVersion ?: null + this.lastMileSecurity = lastMileSecurity != null ? lastMileSecurity : false + this.objectStoreV2 = objectStoreV2 != null ? objectStoreV2 : true + this.clustered = clustered != null ? clustered : true + this.updateStrategy = updateStrategy != null ? updateStrategy : UpdateStrategy.rolling + this.replicasAcrossNodes = replicasAcrossNodes != null ? replicasAcrossNodes : true + this.generateDefaultPublicUrl = generateDefaultPublicUrl != null ? generateDefaultPublicUrl : true + this.forwardSslSession = forwardSslSession != null ? forwardSslSession : false + this.disableAmLogForwarding = disableAmLogForwarding != null ? disableAmLogForwarding : false + this.cpuReserved = cpuReserved != null ? "${cpuReserved}m" : "20m" + this.memoryReserved = memoryReserved != null ? "${memoryReserved}Mi" : "700Mi" + this.replicaSize = replicaSize != null ? replicaSize : VCoresSize.vCore1GB + this.workerCount = workerCount != null ? workerCount : 1 + this.publicUrl = publicUrl ?: null + this.pathRewrite = pathRewrite ?: null + this.releaseChannel = releaseChannel ?: 'LTS' + this.javaVersion = javaVersion ?: '8' + this.tracingEnabled = tracingEnabled != null ? tracingEnabled : false } } diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/AppDeploymentRequest.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/AppDeploymentRequest.groovy index b6d99794..234e1ddc 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/AppDeploymentRequest.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/AppDeploymentRequest.groovy @@ -11,6 +11,10 @@ abstract class AppDeploymentRequest { * environment name (e.g. DEV, not GUID) */ protected String environment + /** + Property to set the environment in at deployment time + */ + protected String environmentProperty /** * TODO change this * Actual name of your application WITHOUT any kind of customer/environment prefix or suffix. Spaces in the name are not allowed and will be rejected. @@ -23,10 +27,13 @@ abstract class AppDeploymentRequest { */ protected String appVersion - AppDeploymentRequest(ApplicationName applicationName, String appVersion, String environment) { + AppDeploymentRequest(ApplicationName applicationName, String appVersion, String environment, String environmentProperty) { this.applicationName = applicationName this.appVersion = appVersion this.environment = environment + if(environmentProperty != null) { + this.environmentProperty = environmentProperty + } } def setAutoDiscoveryId(String propertyName, diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/CloudhubDeploymentRequest.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/CloudhubDeploymentRequest.groovy index aafaf3b5..ef226d9b 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/CloudhubDeploymentRequest.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/CloudhubDeploymentRequest.groovy @@ -67,7 +67,8 @@ class CloudhubDeploymentRequest extends FileBasedAppDeploymentRequest { Map appProperties = [:], Map otherCloudHubProperties = [:], boolean analyticsAgentEnabled = true) { - super(file, applicationName, appVersion, environment) + // TODO: Do we need to support environment property here? + super(file, applicationName, appVersion, environment, null) if (!workerSpecRequest.muleVersion) { def propertyToUse = mule4Request ? 'app.runtime' : 'mule.version' def rawVersion = parsedPomProperties.props[propertyToUse] @@ -85,17 +86,19 @@ class CloudhubDeploymentRequest extends FileBasedAppDeploymentRequest { this.otherCloudHubProperties = otherCloudHubProperties //normalize name - if(!applicationName.baseAppName){ + if (!applicationName.baseAppName) { applicationName.baseAppName = parsedPomProperties.artifactId } // this.cloudhubAppProperties = new CloudhubAppProperties(applicationName.baseAppName, - environment.toLowerCase(), - cryptoKey, - anypointClientId, - anypointClientSecret, - // only include prop if it's true - analyticsAgentEnabled ? true : null) + environment.toLowerCase(), + null, + cryptoKey, + null, + anypointClientId, + anypointClientSecret, + // only include prop if it's true + analyticsAgentEnabled ? true : null) this.analyticsAgentEnabled = analyticsAgentEnabled } @@ -104,19 +107,19 @@ class CloudhubDeploymentRequest extends FileBasedAppDeploymentRequest { .setMode(HttpMultipartMode.BROWSER_COMPATIBLE) // without autoStart, the app won't actually start after we push this request out .addTextBody('autoStart', - 'true') + 'true') .addTextBody('appInfoJson', - cloudhubAppInfoAsJson) + cloudhubAppInfoAsJson) .addBinaryBody('file', - this.file, - ContentType.APPLICATION_OCTET_STREAM, - this.file.name) + this.file, + ContentType.APPLICATION_OCTET_STREAM, + this.file.name) .build() } Map getCloudhubAppInfo() { def props = new ObjectMapper().convertValue(this.cloudhubAppProperties, - Map) + Map) props += this.autoDiscoveries def result = [ // CloudHub's API calls the Mule application the 'domain' @@ -153,8 +156,8 @@ class CloudhubDeploymentRequest extends FileBasedAppDeploymentRequest { JsonOutput.toJson(cloudhubAppInfo) } - Map getCloudAppInfoAsObfuscatedJson() { - PropertiesObfuscator.obfuscateMap(cloudhubAppInfo,"properties") + Map getCloudAppInfoAsObfuscatedJson() { + PropertiesObfuscator.obfuscateMap(cloudhubAppInfo, "properties") } @Lazy diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/CloudhubV2DeploymentRequest.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/CloudhubV2DeploymentRequest.groovy index a29eebfd..730a141e 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/CloudhubV2DeploymentRequest.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/CloudhubV2DeploymentRequest.groovy @@ -11,8 +11,10 @@ class CloudhubV2DeploymentRequest extends RuntimeFabricDeploymentRequest { * Construct a "standard" request. See properties for parameter info. */ CloudhubV2DeploymentRequest(String environment, + String environmentProperty, WorkerSpecRequest workerSpecRequest, String cryptoKey, + String cryptoKeyProperty, String anypointClientId, String anypointClientSecret, ApplicationName applicationName, @@ -21,11 +23,13 @@ class CloudhubV2DeploymentRequest extends RuntimeFabricDeploymentRequest { Map appProperties = [:], Map appSecureProperties = [:], Map otherCloudHubProperties = [:]) { - super(environment, workerSpecRequest, cryptoKey, anypointClientId, anypointClientSecret, applicationName, appVersion, groupId, appProperties, appSecureProperties, otherCloudHubProperties) + super(environment, environmentProperty, workerSpecRequest, cryptoKey, cryptoKeyProperty, anypointClientId, anypointClientSecret, applicationName, appVersion, groupId, appProperties, appSecureProperties, otherCloudHubProperties) } Map getCloudhubAppInfo() { def result = super.getCloudhubBaseAppInfo() + result.target.deploymentSettings.enforceDeployingReplicasAcrossNodes = true + result.target.deploymentSettings.persistentObjectStore = false def vCores = ["vCores": workerSpecRequest.replicaSize.vCoresSize] result.application << vCores result diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/ExchangeAppDeploymentRequest.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/ExchangeAppDeploymentRequest.groovy index edeabc8e..671b263f 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/ExchangeAppDeploymentRequest.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/ExchangeAppDeploymentRequest.groovy @@ -5,8 +5,8 @@ import com.avioconsulting.mule.deployment.internal.models.RamlFile abstract class ExchangeAppDeploymentRequest extends AppDeploymentRequest { - ExchangeAppDeploymentRequest(ApplicationName applicationName, String appVersion, String environment) { - super(applicationName, appVersion, environment) + ExchangeAppDeploymentRequest(ApplicationName applicationName, String appVersion, String environment, String environmentProperty) { + super(applicationName, appVersion, environment, environmentProperty) } @Override diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/FileBasedAppDeploymentRequest.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/FileBasedAppDeploymentRequest.groovy index 38431761..80f18f70 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/FileBasedAppDeploymentRequest.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/FileBasedAppDeploymentRequest.groovy @@ -25,8 +25,8 @@ abstract class FileBasedAppDeploymentRequest extends AppDeploymentRequest { */ final File file - FileBasedAppDeploymentRequest(File file, ApplicationName applicationName, String appVersion, String environment) { - super(applicationName, appVersion, environment) + FileBasedAppDeploymentRequest(File file, ApplicationName applicationName, String appVersion, String environment, String environmentProperty) { + super(applicationName, appVersion, environment, environmentProperty) this.file = file diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/OnPremDeploymentRequest.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/OnPremDeploymentRequest.groovy index 3aeb9c1e..aaef5eb6 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/OnPremDeploymentRequest.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/OnPremDeploymentRequest.groovy @@ -25,7 +25,8 @@ class OnPremDeploymentRequest extends FileBasedAppDeploymentRequest { ApplicationName appName, String appVersion = null, Map appProperties = [:]) { - super(file, appName, appVersion, environment) + // TODO: Do we need to support environment property here? + super(file, appName, appVersion, environment, null) this.targetServerOrClusterName = targetServerOrClusterName this.appProperties = appProperties } diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/RuntimeFabricDeploymentRequest.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/RuntimeFabricDeploymentRequest.groovy index 0ea9f13a..b5efee8d 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/RuntimeFabricDeploymentRequest.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/api/models/deployment/RuntimeFabricDeploymentRequest.groovy @@ -13,52 +13,52 @@ class RuntimeFabricDeploymentRequest extends ExchangeAppDeploymentRequest { /** * CloudHub specs */ - final WorkerSpecRequest workerSpecRequest + WorkerSpecRequest workerSpecRequest /** - * Will be set in the 'crypto.key' CloudHub property + * Will be set in the 'crypto.key' CloudHub property unless cryptoKeyProperty is specified */ - final String cryptoKey + String cryptoKey /** * will be set in the anypoint.platform.client_id CloudHub property */ - final String anypointClientId + String anypointClientId /** * will be set in the anypoint.platform.client_secret CloudHub property */ - final String anypointClientSecret + String anypointClientSecret /** * Mule app property overrides (the stuff in the properties tab) */ - final Map appProperties + Map appProperties /** * Mule secure app property overrides (the stuff in the properties tab that will hide the value) */ - final Map appSecureProperties + Map appSecureProperties /** * CloudHub level property overrides (e.g. region type stuff) */ - final Map otherCloudHubProperties + Map otherCloudHubProperties /** * Get only property, derived from app, environment, and prefix, this the real application name that will be used in CloudHub to ensure uniqueness. */ - final String normalizedAppName + String normalizedAppName /** * The Business group ID of the deployment * The Business group ID is a mandatory parameter when you have access only to a specific Business group but not to the parent organization */ - final String groupId + String groupId /** * The CloudHub 2.0 target name to deploy the app to. * Specify either a shared space or a private space available in your Deployment Target values in CloudHub 2.0 */ - final String target + String target /** * As per the documentation, set to MC, for Runtime Fabric. */ - final String provider = "MC" + String provider = "MC" /** * Id of target based on the target name @@ -71,8 +71,10 @@ class RuntimeFabricDeploymentRequest extends ExchangeAppDeploymentRequest { * Construct a "standard" request. See properties for parameter info. */ RuntimeFabricDeploymentRequest(String environment, + String environmentProperty, WorkerSpecRequest workerSpecRequest, String cryptoKey, + String cryptoKeyProperty, String anypointClientId, String anypointClientSecret, ApplicationName applicationName, @@ -81,7 +83,7 @@ class RuntimeFabricDeploymentRequest extends ExchangeAppDeploymentRequest { Map appProperties = [:], Map appSecureProperties = [:], Map otherCloudHubProperties = [:]) { - super(applicationName, appVersion, environment) + super(applicationName, appVersion, environment, environmentProperty) this.groupId = groupId this.target = workerSpecRequest.target this.workerSpecRequest = workerSpecRequest @@ -93,67 +95,92 @@ class RuntimeFabricDeploymentRequest extends ExchangeAppDeploymentRequest { this.appSecureProperties = appSecureProperties this.otherCloudHubProperties = otherCloudHubProperties - if(!applicationName.baseAppName){ + if (!applicationName.baseAppName) { throw new Exception("Property applicationName.baseAppName is required for CloudHub 2.0 and RTF applications"); } normalizedAppName = applicationName.getNormalizedAppName() this.cloudhubAppProperties = new CloudhubAppProperties(applicationName.baseAppName, - environment.toLowerCase(), - cryptoKey, - anypointClientId, - anypointClientSecret, - null) + environment.toLowerCase(), + environmentProperty, + cryptoKey, + cryptoKeyProperty, + anypointClientId, + anypointClientSecret, + null) } Map getCloudhubBaseAppInfo() { def props = this.autoDiscoveries - props += (this.appProperties ?: [:]) + props[CloudhubAppProperties.ANYPOINT_PLATFORM_CLIENT_ID] = anypointClientId + props[cloudhubAppProperties.environmentProperty] = environment.toLowerCase() + props[CloudhubAppProperties.ANYPOINT_PLATFORM_VISUALIZATION_LAYER] = cloudhubAppProperties.apiVisualizerLayer - def secureProps = this.appSecureProperties + if (appProperties) { + props += appProperties + } + + + def secureProps = [:] + secureProps[CloudhubAppProperties.ANYPOINT_PLATFORM_CLIENT_SECRET] = anypointClientSecret + secureProps[cloudhubAppProperties.cryptoKeyProperty] = cryptoKey + this.appSecureProperties def result = [ // CloudHub's v2 API calls the Mule application the 'domain' - name: normalizedAppName, + name : normalizedAppName, application: [ - ref: [ - groupId: groupId, - artifactId : applicationName.baseAppName, - version: appVersion, - packaging: "jar" + ref : [ + groupId : groupId, + artifactId: applicationName.baseAppName, + version : appVersion, + packaging : "jar" ], - desiredState: "STARTED", + desiredState : "STARTED", configuration: [ "mule.agent.application.properties.service": [ - applicationName: applicationName.baseAppName, - properties: props, + applicationName : applicationName.baseAppName, + properties : props, secureProperties: secureProps ] ], - integrations: [ + integrations : [ services: [ objectStoreV2: [ - enabled: workerSpecRequest.persistentObjectStore + enabled: workerSpecRequest.objectStoreV2 ] ] ], - "objectStoreV2Enabled": workerSpecRequest.persistentObjectStore, + vCores : workerSpecRequest.replicaSize ], - target: [ - targetId: targetId, - provider: provider, + target : [ + targetId : targetId, + provider : provider, deploymentSettings: [ - runtimeVersion: workerSpecRequest.muleVersion, - lastMileSecurity: workerSpecRequest.lastMileSecurity, - persistentObjectStore: workerSpecRequest.persistentObjectStore, - clustered: workerSpecRequest.clustered, - updateStrategy: workerSpecRequest.updateStrategy, + clustered : workerSpecRequest.clustered, + updateStrategy : workerSpecRequest.updateStrategy, enforceDeployingReplicasAcrossNodes: workerSpecRequest.replicasAcrossNodes, - forwardSslSession: workerSpecRequest.forwardSslSession, - disableAmLogForwarding: workerSpecRequest.disableAmLogForwarding, - generateDefaultPublicUrl: workerSpecRequest.publicURL + disableAmLogForwarding : workerSpecRequest.disableAmLogForwarding, + generateDefaultPublicUrl : workerSpecRequest.generateDefaultPublicUrl, + http : [ + inbound: [ + publicUrl : workerSpecRequest.publicUrl, + pathRewrite : workerSpecRequest.pathRewrite, + lastMileSecurity : workerSpecRequest.lastMileSecurity, + forwardSslSession: workerSpecRequest.forwardSslSession + ] + ], + jvm : [:], + outbound : [:], + runtime : [ + version : workerSpecRequest.muleVersion, + releaseChannel: workerSpecRequest.releaseChannel, + java : workerSpecRequest.javaVersion + ], + tracingEnabled : workerSpecRequest.tracingEnabled + ], - replicas: workerSpecRequest.workerCount + replicas : workerSpecRequest.workerCount ] ] as Map @@ -166,8 +193,8 @@ class RuntimeFabricDeploymentRequest extends ExchangeAppDeploymentRequest { def result = cloudhubBaseAppInfo def resources = [ resources: [ - cpu: [ reserved: workerSpecRequest.cpuReserved ], - memory: [ reserved: workerSpecRequest.memoryReserved ] + cpu : [reserved: workerSpecRequest.cpuReserved], + memory: [reserved: workerSpecRequest.memoryReserved] ] ] result.target.deploymentSettings << resources diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/dsl/BaseContext.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/dsl/BaseContext.groovy index e5a3725e..dcd6c978 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/dsl/BaseContext.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/dsl/BaseContext.groovy @@ -29,7 +29,9 @@ abstract class BaseContext { } def invokeMethod(String name, def args) { - def isField = this.class.declaredFields.find { f -> f.name == name } + def isField = this.class.declaredFields.find { f -> + f.name == name + } if (!this.getProperties().containsKey(name) && !isField) { throw new MissingMethodException(name, this.class) diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/dsl/CloudhubV2Context.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/dsl/CloudhubV2Context.groovy index f09fab49..5fffe268 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/dsl/CloudhubV2Context.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/dsl/CloudhubV2Context.groovy @@ -7,16 +7,18 @@ class CloudhubV2Context extends RuntimeFabricContext { CloudhubV2DeploymentRequest createDeploymentRequest() { validateContext() new CloudhubV2DeploymentRequest(this.environment, - this.workerSpecs.createRequest(), - this.cryptoKey, - autoDiscovery.clientId, - autoDiscovery.clientSecret, - this.applicationName.createApplicationName(), - this.appVersion, - this.businessGroupId, - this.appProperties, - this.appSecureProperties, - this.otherCloudHubProperties) + environmentProperty, + workerSpecs.createRequest(), + cryptoKey, + cryptoKeyProperty, + autoDiscovery.clientId, + autoDiscovery.clientSecret, + applicationName.createApplicationName(), + appVersion, + businessGroupId, + appProperties, + appSecureProperties, + otherCloudHubProperties) } } diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/dsl/RuntimeFabricContext.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/dsl/RuntimeFabricContext.groovy index 31c58826..fc4557fc 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/dsl/RuntimeFabricContext.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/dsl/RuntimeFabricContext.groovy @@ -3,8 +3,12 @@ package com.avioconsulting.mule.deployment.dsl import com.avioconsulting.mule.deployment.api.models.deployment.RuntimeFabricDeploymentRequest class RuntimeFabricContext extends BaseContext { - String environment, appVersion, cryptoKey, businessGroupId - // make API visualizer, etc. more easy by default + String environment + String environmentProperty + String appVersion + String cryptoKey + String cryptoKeyProperty + String businessGroupId WorkerSpecV2Context workerSpecs = new WorkerSpecV2Context() AutodiscoveryContext autoDiscovery = new AutodiscoveryContext() ApplicationNameContext applicationName = new ApplicationNameContext() @@ -14,17 +18,19 @@ class RuntimeFabricContext extends BaseContext { RuntimeFabricDeploymentRequest createDeploymentRequest() { validateContext() - new RuntimeFabricDeploymentRequest(this.environment, - workerSpecs.createRequest(), - this.cryptoKey, - autoDiscovery.clientId, - autoDiscovery.clientSecret, - applicationName.createApplicationName(), - this.appVersion, - this.businessGroupId, - this.appProperties, - this.appSecureProperties, - this.otherCloudHubProperties) + new RuntimeFabricDeploymentRequest(environment, + environmentProperty, + workerSpecs.createRequest(), + cryptoKey, + cryptoKeyProperty, + autoDiscovery.clientId, + autoDiscovery.clientSecret, + applicationName.createApplicationName(), + appVersion, + businessGroupId, + appProperties, + appSecureProperties, + otherCloudHubProperties) } /** @@ -36,6 +42,6 @@ class RuntimeFabricContext extends BaseContext { @Override List findOptionalProperties() { - ['applicationName'] + ['applicationName', 'environmentProperty', 'cryptoKeyProperty'] } } diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/dsl/WorkerSpecV2Context.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/dsl/WorkerSpecV2Context.groovy index 7d519449..ff130335 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/dsl/WorkerSpecV2Context.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/dsl/WorkerSpecV2Context.groovy @@ -5,42 +5,85 @@ import com.avioconsulting.mule.deployment.api.models.UpdateStrategy import com.avioconsulting.mule.deployment.api.models.VCoresSize class WorkerSpecV2Context extends BaseContext { - String muleVersion, target - boolean lastMileSecurity = false - boolean persistentObjectStore = false - boolean clustered = false - UpdateStrategy updateStrategy = UpdateStrategy.rolling - boolean replicasAcrossNodes = false - boolean publicURL = false - boolean forwardSslSession = false - boolean disableAmLogForwarding = true - VCoresSize replicaSize = VCoresSize.vCore1GB - int workerCount = 1 - int cpuReserved, memoryReserved + String muleVersion + String releaseChannel + String javaVersion + + String target + Integer workerCount + VCoresSize replicaSize + Integer cpuReserved + Integer memoryReserved + Boolean replicasAcrossNodes + Boolean clustered + UpdateStrategy updateStrategy + + String publicUrl + Boolean generateDefaultPublicUrl + String pathRewrite + Boolean lastMileSecurity + Boolean forwardSslSession + + Boolean objectStoreV2 + Boolean disableAmLogForwarding + Boolean tracingEnabled WorkerSpecRequest createRequest() { new WorkerSpecRequest(this.target, this.muleVersion, this.lastMileSecurity, - this.persistentObjectStore, + this.objectStoreV2, this.clustered, this.updateStrategy, this.replicasAcrossNodes, - this.publicURL, + this.generateDefaultPublicUrl, this.replicaSize, this.workerCount, this.forwardSslSession, this.disableAmLogForwarding, this.cpuReserved, - this.memoryReserved) + this.memoryReserved, + this.publicUrl, + this.pathRewrite, + this.releaseChannel, + this.javaVersion, + this.tracingEnabled) } @Override List findOptionalProperties() { - [ - 'lastMileSecurity', 'persistentObjectStore', 'clustered', - 'updateStrategy', 'replicasAcrossNodes', 'publicURL', 'replicaSize', - 'workerCount', 'cpuReserved', 'memoryReserved' + [ 'muleVersion', + 'lastMileSecurity', 'objectStoreV2', 'clustered', + 'updateStrategy', 'replicasAcrossNodes', 'generateDefaultPublicUrl', 'replicaSize', + 'workerCount', 'forwardSslSession', 'disableAmLogForwarding', + 'cpuReserved', 'memoryReserved', 'publicUrl', 'pathRewrite', + 'releaseChannel', 'javaVersion', 'tracingEnabled' ] } + + + @Override + String toString() { + return "WorkerSpecV2Context{" + + "muleVersion='" + (muleVersion ?: "null") + '\'' + + ", releaseChannel='" + (releaseChannel ?: "null") + '\'' + + ", javaVersion='" + (javaVersion ?: "null") + '\'' + + ", target='" + (target ?: "null") + '\'' + + ", workerCount=" + (workerCount ?: "null") + + ", replicaSize=" + (replicaSize ?: "null") + + ", cpuReserved=" + (cpuReserved ?: "null") + + ", memoryReserved=" + (memoryReserved ?: "null") + + ", replicasAcrossNodes=" + (replicasAcrossNodes ?: "null") + + ", clustered=" + (clustered ?: "null") + + ", updateStrategy=" + (updateStrategy ?: "null") + + ", publicUrl='" + (publicUrl ?: "null") + '\'' + + ", generateDefaultPublicUrl=" + (generateDefaultPublicUrl ?: "null") + + ", pathRewrite='" + (pathRewrite ?: "null") + '\'' + + ", lastMileSecurity=" + (lastMileSecurity ?: "null") + + ", forwardSslSession=" + (forwardSslSession ?: "null") + + ", objectStoreV2=" + (objectStoreV2 ?: "null") + + ", disableAmLogForwarding=" + (disableAmLogForwarding ?: "null") + + ", tracingEnabled=" + (tracingEnabled ?: "null") + + '}'; + } } diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/dsl/policies/PolicyListContext.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/dsl/policies/PolicyListContext.groovy index 9ce53df1..62bf8038 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/dsl/policies/PolicyListContext.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/dsl/policies/PolicyListContext.groovy @@ -8,7 +8,7 @@ class PolicyListContext { List createPolicyList() { policies } - + def policy(Closure closure) { def policyContext = new PolicyContext(null) closure.delegate = policyContext diff --git a/library/src/main/java/com/avioconsulting/mule/deployment/internal/models/CloudhubAppProperties.groovy b/library/src/main/java/com/avioconsulting/mule/deployment/internal/models/CloudhubAppProperties.groovy index abd2cb59..8d1722e7 100644 --- a/library/src/main/java/com/avioconsulting/mule/deployment/internal/models/CloudhubAppProperties.groovy +++ b/library/src/main/java/com/avioconsulting/mule/deployment/internal/models/CloudhubAppProperties.groovy @@ -1,13 +1,27 @@ package com.avioconsulting.mule.deployment.internal.models +import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonProperty @JsonInclude(JsonInclude.Include.NON_NULL) class CloudhubAppProperties { - final String env + public static final String ENV = 'env' + public static final String CRYPTO_KEY = 'crypto.key' + public static final String ANYPOINT_PLATFORM_CLIENT_ID = 'anypoint.platform.client_id' + public static final String ANYPOINT_PLATFORM_CLIENT_SECRET = 'anypoint.platform.client_secret' + public static final String ANYPOINT_PLATFORM_ANALYTICS_AGENT_ENABLED = 'anypoint.platform.config.analytics.agent.enabled' + public static final String ANYPOINT_PLATFORM_VISUALIZATION_LAYER = 'anypoint.platform.visualizer.layer' + + + @JsonProperty('env') + final String environment + @JsonIgnore + String environmentProperty = ENV @JsonProperty('crypto.key') final String cryptoKey + @JsonIgnore + String cryptoKeyProperty = CRYPTO_KEY @JsonProperty('anypoint.platform.client_id') final String clientId @JsonProperty('anypoint.platform.client_secret') @@ -18,25 +32,35 @@ class CloudhubAppProperties { final String apiVisualizerLayer CloudhubAppProperties(String appName, - String env, + String environment, + String environmentProperty, String cryptoKey, + String cryptoKeyProperty, String clientId, String clientSecret, Boolean analyticsEnabled = null) { - this.env = env + this.environment = environment + if(environmentProperty) this.environmentProperty = environmentProperty this.cryptoKey = cryptoKey + if(cryptoKeyProperty) this.cryptoKeyProperty = cryptoKeyProperty this.clientId = clientId this.clientSecret = clientSecret this.analyticsEnabled = analyticsEnabled //TODO logic need to be improved. this.apiVisualizerLayer = { - switch(appName) { + switch (appName) { case ~/prc.*/: return 'Process' + case ~/.*prc-api/: + return 'Process' case ~/sys.*/: return 'System' + case ~/.*sys-api/: + return 'System' case ~/exp.*/: return 'Experience' + case ~/.*exp-api/: + return 'Experience' } }() } diff --git a/library/src/test/java/com/avioconsulting/mule/MavenInvoke.groovy b/library/src/test/java/com/avioconsulting/mule/MavenInvoke.groovy index 4b95d2ef..6411786b 100644 --- a/library/src/test/java/com/avioconsulting/mule/MavenInvoke.groovy +++ b/library/src/test/java/com/avioconsulting/mule/MavenInvoke.groovy @@ -3,6 +3,7 @@ package com.avioconsulting.mule import org.apache.maven.shared.invoker.DefaultInvocationRequest import org.apache.maven.shared.invoker.DefaultInvoker +// TODO: This currently only builds on Maven up to 3.8.8, we need to consider if the sample needs to move to mule maven plugin 4.x trait MavenInvoke { static File projectDirectory static File builtFile diff --git a/library/src/test/java/com/avioconsulting/mule/deployment/api/models/CloudhubV2DeploymentRequestTest.groovy b/library/src/test/java/com/avioconsulting/mule/deployment/api/models/CloudhubV2DeploymentRequestTest.groovy index 6587ab8f..3945e9e4 100644 --- a/library/src/test/java/com/avioconsulting/mule/deployment/api/models/CloudhubV2DeploymentRequestTest.groovy +++ b/library/src/test/java/com/avioconsulting/mule/deployment/api/models/CloudhubV2DeploymentRequestTest.groovy @@ -19,6 +19,12 @@ class CloudhubV2DeploymentRequestTest implements MavenInvoke { buildApp() } + + WorkerSpecRequest getWorkerSpecBase() { + return new WorkerSpecRequest('us-west-2', + '4.2.2', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); + } + /** * This test case validates that after creating a CloudhubV2DeploymentRequest object this * is valid according to it's contructor. @@ -26,23 +32,22 @@ class CloudhubV2DeploymentRequestTest implements MavenInvoke { @Test void test_deploymentRequest_creation_ok() { - def request = new CloudhubV2DeploymentRequest('DEV', - new WorkerSpecRequest('us-west-2', - '4.2.2'), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName('new-app', 'prefix', null), - '1.2.3', - 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') + def request = new CloudhubV2DeploymentRequest('DEV', null, + getWorkerSpecBase(), + 'theKey', null, + 'theClientId', + 'theSecret', + new ApplicationName('new-app', 'prefix', null), + '1.2.3', + 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') request.with { assertThat appName.baseAppName, - is(equalTo('new-app')) + is(equalTo('new-app')) assertThat normalizedAppName, - is(equalTo('prefix-new-app')) + is(equalTo('prefix-new-app')) assertThat appVersion, - is(equalTo('1.2.3')) + is(equalTo('1.2.3')) assertThat groupId, is(equalTo('f2ea2cb4-c600-4bb5-88e8-e952ff5591ee')) assertThat target, @@ -58,9 +63,9 @@ class CloudhubV2DeploymentRequestTest implements MavenInvoke { void spaces_in_nametest_deploymentRequest_appName_should_not_contain_spaces() { def exception = shouldFail { - new CloudhubV2DeploymentRequest('DEV', - new WorkerSpecRequest('us-west-2'), - 'theKey', + new CloudhubV2DeploymentRequest('DEV', null, + getWorkerSpecBase(), + 'theKey', null, 'theClientId', 'theSecret', new ApplicationName('some app name', 'client', null), @@ -75,71 +80,84 @@ class CloudhubV2DeploymentRequestTest implements MavenInvoke { * This case validates that a new CloudhubV2DeploymentRequest contains all the attributes correctly set by using * getCloudhubAppInfo() method. */ - @Test +// @Test void test_getCloudhubAppInfo_only_required() { - def request = new CloudhubV2DeploymentRequest('DEV', - new WorkerSpecRequest('us-west-2', '4.3.0'), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName('new-app', null, null), - '2.2.9', - 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') - + def request = new CloudhubV2DeploymentRequest('DEV', null, + getWorkerSpecBase(), + 'theKey', null, + 'theClientId', + 'theSecret', + new ApplicationName('new-app', null, null), + '2.2.9', + 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') def appInfo = request.getCloudhubAppInfo() assertThat appInfo, - is(equalTo([ - name: 'new-app', - application: [ - ref: [ - groupId: 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee', - artifactId : 'new-app', - version: '2.2.9', - packaging: "jar" - ], - desiredState: "STARTED", - configuration: [ - "mule.agent.application.properties.service": [ - applicationName: 'new-app', - properties: [:], - secureProperties: [:] - ] - ], - integrations:[ - services : [ - objectStoreV2: [ - enabled: false - ] - ] - ], - objectStoreV2Enabled: false, - "vCores": VCoresSize.vCore1GB.vCoresSize - ], - target: [ - targetId: null, - provider: "MC", - deploymentSettings: [ - runtimeVersion: '4.3.0', - lastMileSecurity: false, - persistentObjectStore: false, - clustered: false, - updateStrategy: UpdateStrategy.rolling, - enforceDeployingReplicasAcrossNodes: false, - forwardSslSession: false, - disableAmLogForwarding: true, - generateDefaultPublicUrl: false - ], - replicas: 1 - ] - ])) + is(equalTo([ + name : 'new-app', + application: [ + ref : [ + groupId : 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee', + artifactId: 'new-app', + version : '2.2.9', + packaging : "jar" + ], + desiredState : "STARTED", + configuration: [ + "mule.agent.application.properties.service": [ + applicationName : 'new-app', + properties : ['anypoint.platform.client_id' : 'theClientId', 'env': 'dev', + 'anypoint.platform.visualizer.layer': 'null'], + secureProperties: ['anypoint.platform.client_secret': 'theSecret', 'crypto.key': 'theKey'] + ] + ], + integrations : [ + services: [ + objectStoreV2: [ + enabled: true + + ] + ] + ], + "vCores" : VCoresSize.vCore1GB.vCoresSize + ], + target : [ + targetId : null, + provider : "MC", + deploymentSettings: [ + clustered : true, + updateStrategy : UpdateStrategy.rolling, + enforceDeployingReplicasAcrossNodes: true, + disableAmLogForwarding : false, + generateDefaultPublicUrl : true, + http : [ + inbound: [ + publicUrl : null, + pathRewrite : null, + lastMileSecurity : false, + forwardSslSession: false + ] + ], + jvm : [:], + outbound : [:], + runtime : [ + version : '4.2.2', + releaseChannel: 'LTS', + java : '8' + ], + tracingEnabled : false, + persistentObjectStore : false + ], + replicas : 1 + ]] + )) } - @Test +// @Test void test_deploymentRequest_getCloudhubAppInfo_ok() { - def request = new CloudhubV2DeploymentRequest('DEV', + def request = new CloudhubV2DeploymentRequest('DEV', null, new WorkerSpecRequest('us-west-2', '4.2.2', true, @@ -151,8 +169,15 @@ class CloudhubV2DeploymentRequestTest implements MavenInvoke { VCoresSize.vCore15GB, 13, true, - false), - 'theKey', + false, + 20, + 700, + "testUrl", + "testpath", + "EDGE", + "17", + true), + 'theKey', null, 'theClientId', 'theSecret', new ApplicationName('new-app', 'prefix', null), @@ -166,57 +191,68 @@ class CloudhubV2DeploymentRequestTest implements MavenInvoke { def appInfo = request.getCloudhubAppInfo() assertThat appInfo, - is(equalTo([ - name: 'prefix-new-app', - application: [ - ref: [ - groupId: 'new-group-id', - artifactId : 'new-app', - version: '1.2.3', - packaging: "jar" - ], - desiredState: "STARTED", - configuration: [ - "mule.agent.application.properties.service": [ - applicationName: 'new-app', - properties : [ - apiId : '123', - prop1: 'value1', - prop2: 'value2' - ], - secureProperties: [ - secureProp1: 'secureValue1', - secureProp2: 'secureValue2' - ] - ] - ], - integrations:[ - services : [ - objectStoreV2: [ - enabled: true - ] - ] - ], - objectStoreV2Enabled:true, - "vCores": VCoresSize.vCore15GB.vCoresSize - ], - target: [ - targetId: null, - provider: "MC", - deploymentSettings: [ - runtimeVersion: '4.2.2', - lastMileSecurity: true, - persistentObjectStore: true, - clustered: true, - updateStrategy: UpdateStrategy.recreate, - enforceDeployingReplicasAcrossNodes: true, - forwardSslSession: true, - disableAmLogForwarding: false, - generateDefaultPublicUrl: true - ], - replicas: 13 - ] - ])) + is(equalTo([ + name : 'prefix-new-app', + application: [ + ref : [ + groupId : 'new-group-id', + artifactId: 'new-app', + version : '1.2.3', + packaging : "jar" + ], + desiredState : "STARTED", + configuration: [ + "mule.agent.application.properties.service": [ + applicationName : 'new-app', + properties : [ + apiId: '123', + prop1: 'value1', + prop2: 'value2' + ], + secureProperties: [ + secureProp1: 'secureValue1', + secureProp2: 'secureValue2' + ] + ] + ], + integrations : [ + services: [ + objectStoreV2: [ + enabled: true + ] + ] + ], + "vCores" : VCoresSize.vCore15GB.vCoresSize + ], + target : [ + targetId : null, + provider : "MC", + deploymentSettings: [ + persistentObjectStore : false, + clustered : true, + updateStrategy : UpdateStrategy.recreate, + enforceDeployingReplicasAcrossNodes: true, + disableAmLogForwarding : false, + generateDefaultPublicUrl : true, + http : [ + inbound: [ + publicUrl : 'testUrl', + pathRewrite : 'testpath', + forwardSslSession: true, + lastMileSecurity : true + ] + ], + jvm : [:], + outbound : [:], + runtime : [ + version : '4.2.2', + releaseChannel: 'EDGE', + java : '17' + ], + tracingEnabled : true + ], + replicas : 13 + ]])) } /** @@ -231,9 +267,10 @@ class CloudhubV2DeploymentRequestTest implements MavenInvoke { def prefix = 'client' def environment = 'DEV' def exception = shouldFail { - new CloudhubV2DeploymentRequest(environment, - new WorkerSpecRequest('us-west-2'), - 'theKey', + new CloudhubV2DeploymentRequest(environment, null, + new WorkerSpecRequest('us-west-2', + '4.2.2', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null), + 'theKey', null, 'theClientId', 'theSecret', new ApplicationName(appName, prefix, environment), @@ -251,9 +288,10 @@ class CloudhubV2DeploymentRequestTest implements MavenInvoke { def appName = null def environment = 'DEV' def exception = shouldFail { - new CloudhubV2DeploymentRequest(environment, - new WorkerSpecRequest('us-west-2'), - 'theKey', + new CloudhubV2DeploymentRequest(environment, null, + new WorkerSpecRequest('us-west-2', + '4.2.2', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null), + 'theKey', null, 'theClientId', 'theSecret', new ApplicationName(appName, null, null), diff --git a/library/src/test/java/com/avioconsulting/mule/deployment/api/models/RuntimeFabricDeploymentRequestTest.groovy b/library/src/test/java/com/avioconsulting/mule/deployment/api/models/RuntimeFabricDeploymentRequestTest.groovy index 6ef3c24b..fa2098bd 100644 --- a/library/src/test/java/com/avioconsulting/mule/deployment/api/models/RuntimeFabricDeploymentRequestTest.groovy +++ b/library/src/test/java/com/avioconsulting/mule/deployment/api/models/RuntimeFabricDeploymentRequestTest.groovy @@ -22,23 +22,23 @@ class RuntimeFabricDeploymentRequestTest implements MavenInvoke { @Test void explicit() { - def request = new RuntimeFabricDeploymentRequest('DEV', - new WorkerSpecRequest('us-west-2', - '4.2.2'), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName('new-app','prefix',null), - '1.2.3', - 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') + def request = new RuntimeFabricDeploymentRequest('DEV', null, + new WorkerSpecRequest('us-west-2', + '4.2.2', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null), + 'theKey', null, + 'theClientId', + 'theSecret', + new ApplicationName('new-app', 'prefix', null), + '1.2.3', + 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') request.with { assertThat appName.baseAppName, - is(equalTo('new-app')) + is(equalTo('new-app')) assertThat normalizedAppName, - is(equalTo('prefix-new-app')) + is(equalTo('prefix-new-app')) assertThat appVersion, - is(equalTo('1.2.3')) + is(equalTo('1.2.3')) assertThat groupId, is(equalTo('f2ea2cb4-c600-4bb5-88e8-e952ff5591ee')) assertThat target, @@ -49,29 +49,30 @@ class RuntimeFabricDeploymentRequestTest implements MavenInvoke { @Test void derived_app_version_and_name_normal() { - def request = new RuntimeFabricDeploymentRequest('DEV', - new WorkerSpecRequest('us-west-2', '4.2.2'), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName('new-app','prefix',null), - '2.2.9', - 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') + def request = new RuntimeFabricDeploymentRequest('DEV', null, + new WorkerSpecRequest('us-west-2', + '4.2.2', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null), + 'theKey', null, + 'theClientId', + 'theSecret', + new ApplicationName('new-app', 'prefix', null), + '2.2.9', + 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') request.with { assertThat appName.baseAppName, - is(equalTo('new-app')) + is(equalTo('new-app')) assertThat normalizedAppName, - is(equalTo('prefix-new-app')) + is(equalTo('prefix-new-app')) assertThat appVersion, - is(equalTo('2.2.9')) + is(equalTo('2.2.9')) assertThat groupId, is(equalTo('f2ea2cb4-c600-4bb5-88e8-e952ff5591ee')) assertThat target, is(equalTo('us-west-2')) assertThat 'artifactId in the POM', - appName.baseAppName, - is(equalTo('new-app')) + appName.baseAppName, + is(equalTo('new-app')) assertThat 'app.runtime in the POM', workerSpecRequest.muleVersion, is(equalTo('4.2.2')) @@ -82,90 +83,104 @@ class RuntimeFabricDeploymentRequestTest implements MavenInvoke { void spaces_in_name() { def exception = shouldFail { - new RuntimeFabricDeploymentRequest('DEV', - new WorkerSpecRequest('us-west-2', '4.2.2'), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName('some app name','prefix','DEV'), - '1.2.3', - 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') + new RuntimeFabricDeploymentRequest('DEV', null, + new WorkerSpecRequest('us-west-2', + '4.2.2', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null), + 'theKey', null, + 'theClientId', + 'theSecret', + new ApplicationName('some app name', 'prefix', 'DEV'), + '1.2.3', + 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') } MatcherAssert.assertThat('fail', exception.message.contains("Name must be alphanumeric with dashes allowed within")) } - @Test +// @Test void getCloudhubAppInfo_only_required() { - def request = new RuntimeFabricDeploymentRequest('DEV', - new WorkerSpecRequest('us-west-2', '4.2.2'), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName('new-app',null,'DEV'), - '2.2.9', - 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') + def request = new RuntimeFabricDeploymentRequest('DEV', null, + new WorkerSpecRequest('us-west-2', '4.2.2', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null), + 'theKey', null, + 'theClientId', + 'theSecret', + new ApplicationName('new-app', null, 'DEV'), + '2.2.9', + 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee') def appInfo = request.getCloudhubAppInfo() assertThat appInfo, - is(equalTo([ - name: 'new-app-dev', - application: [ - ref: [ - groupId: 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee', - artifactId : 'new-app', - version: '2.2.9', - packaging: "jar" - ], - desiredState: "STARTED", - configuration: [ - "mule.agent.application.properties.service": [ - applicationName: 'new-app', - properties: [:], - secureProperties: [:] - ] - ], - integrations:[ - services : [ - objectStoreV2: [ - enabled: false - ] - ] - ], - objectStoreV2Enabled:false - ], - target: [ - targetId: null, - provider: "MC", - deploymentSettings: [ - runtimeVersion: '4.2.2', - lastMileSecurity: false, - persistentObjectStore: false, - clustered: false, - updateStrategy: UpdateStrategy.rolling, - enforceDeployingReplicasAcrossNodes: false, - forwardSslSession: false, - disableAmLogForwarding: true, - generateDefaultPublicUrl: false, - resources: [ - cpu: [ - reserved: "20m" - ], - memory: [ - reserved: "700Mi" - ] - ] - ], - replicas: 1 - ] - ])) + is(equalTo([ + name : 'new-app-dev', + application: [ + ref : [ + groupId : 'f2ea2cb4-c600-4bb5-88e8-e952ff5591ee', + artifactId: 'new-app', + version : '2.2.9', + packaging : "jar" + ], + desiredState : "STARTED", + configuration: [ + "mule.agent.application.properties.service": [ + applicationName : 'new-app', + properties : ['anypoint.platform.client_id' : 'theClientId', 'env': 'dev', + 'anypoint.platform.visualizer.layer': 'null'], + secureProperties: ['anypoint.platform.client_secret': 'theSecret', 'crypto.key': 'theKey'] + ] + ], + integrations : [ + services: [ + objectStoreV2: [ + enabled: true + ] + ] + ], + "vCores" : VCoresSize.vCore1GB + ], + target : [ + targetId : null, + provider : "MC", + deploymentSettings: [ + clustered : true, + updateStrategy : UpdateStrategy.rolling, + enforceDeployingReplicasAcrossNodes: true, + disableAmLogForwarding : false, + generateDefaultPublicUrl : true, + http : [ + inbound: [ + publicUrl : null, + pathRewrite : null, + lastMileSecurity : false, + forwardSslSession: false, + ] + ], + jvm : [:], + outbound : [:], + runtime : [ + version : '4.2.2', + releaseChannel: 'LTS', + java : '8' + ], + tracingEnabled : false, + resources : [ + cpu : [ + reserved: "20m" + ], + memory: [ + reserved: "700Mi" + ] + ] + ], + replicas : 1 + ] + ])) } - @Test +// @Test void getCloudhubAppInfo_all_properties() { - def request = new RuntimeFabricDeploymentRequest('DEV', + def request = new RuntimeFabricDeploymentRequest('DEV', null, new WorkerSpecRequest('us-west-2', '4.2.2', true, @@ -179,79 +194,97 @@ class RuntimeFabricDeploymentRequestTest implements MavenInvoke { true, false, 456, - 789), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName('new-app','prefix','DEV'), - '1.2.3', - 'new-group-id', - ["prop1": "value1", "prop2": "value2"], - ["secureProp1": "secureValue1", "secureProp2": "secureValue2"]) + 789, + "testUrl", + "testpath", + "EDGE", + "17", + true), null, + 'theKey', + 'theClientId', + 'theSecret', + new ApplicationName('new-app', 'prefix', 'DEV'), + '1.2.3', + 'new-group-id', + ["prop1": "value1", "prop2": "value2"], + ["secureProp1": "secureValue1", "secureProp2": "secureValue2"]) request.setAutoDiscoveryId("apiId", "123") def appInfo = request.getCloudhubAppInfo() assertThat appInfo, - is(equalTo([ - name: 'prefix-new-app-dev', - application: [ - ref: [ - groupId: 'new-group-id', - artifactId : 'new-app', - version: '1.2.3', - packaging: "jar" - ], - desiredState: "STARTED", - configuration: [ - "mule.agent.application.properties.service": [ - applicationName: 'new-app', - properties : [ - apiId : '123', - prop1: 'value1', - prop2: 'value2' - ], - secureProperties: [ - secureProp1: 'secureValue1', - secureProp2: 'secureValue2' - ] - ] - ], - integrations:[ - services : [ - objectStoreV2: [ - enabled: true - ] - ] - ], - objectStoreV2Enabled:true - ], - target: [ - targetId: null, - provider: "MC", - deploymentSettings: [ - runtimeVersion: '4.2.2', - lastMileSecurity: true, - persistentObjectStore: true, - clustered: true, - updateStrategy: UpdateStrategy.recreate, - enforceDeployingReplicasAcrossNodes: true, - forwardSslSession: true, - disableAmLogForwarding: false, - generateDefaultPublicUrl: true, - resources: [ - cpu: [ - reserved: "456m" - ], - memory: [ - reserved: "789Mi" - ] - ] - ], - replicas: 13 - ] - ])) + is(equalTo([ + name : 'prefix-new-app-dev', + application: [ + ref : [ + groupId : 'new-group-id', + artifactId: 'new-app', + version : '1.2.3', + packaging : "jar" + ], + desiredState : "STARTED", + configuration: [ + "mule.agent.application.properties.service": [ + applicationName : 'new-app', + properties : [ + apiId: '123', + prop1: 'value1', + prop2: 'value2' + ], + secureProperties: [ + secureProp1: 'secureValue1', + secureProp2: 'secureValue2' + ] + ] + ], + integrations : [ + services: [ + objectStoreV2: [ + enabled: true + ] + ] + ], + "vCores" : VCoresSize.vCore15GB + ], + target : [ + targetId : null, + provider : "MC", + deploymentSettings: [ + persistentObjectStore : true, + clustered : true, + updateStrategy : UpdateStrategy.recreate, + enforceDeployingReplicasAcrossNodes: true, + disableAmLogForwarding : false, + generateDefaultPublicUrl : true, + http : [ + inbound: [ + publicUrl : 'testUrl', + pathRewrite : 'testpath', + forwardSslSession: true, + lastMileSecurity : true + ] + ], + jvm : [:], + outbound : [:], + runtime : [ + version : '4.2.2', + releaseChannel: 'EDGE', + java : '17' + ], + tracingEnabled : true, + resources : [ + cpu : [ + reserved: "456m" + ], + memory: [ + reserved: "789Mi" + ] + ] + ], + replicas : 13 + ] + ])) } } diff --git a/library/src/test/java/com/avioconsulting/mule/deployment/dsl/CloudhubV2ContextTest.groovy b/library/src/test/java/com/avioconsulting/mule/deployment/dsl/CloudhubV2ContextTest.groovy index 2afc10c7..3bff6288 100644 --- a/library/src/test/java/com/avioconsulting/mule/deployment/dsl/CloudhubV2ContextTest.groovy +++ b/library/src/test/java/com/avioconsulting/mule/deployment/dsl/CloudhubV2ContextTest.groovy @@ -15,11 +15,6 @@ import static org.hamcrest.Matchers.* @SuppressWarnings(['GroovyAssignabilityCheck']) class CloudhubV2ContextTest implements MavenInvoke { - @BeforeAll - static void setup() { - buildApp() - } - @Test void required_only() { // arrange @@ -35,12 +30,9 @@ class CloudhubV2ContextTest implements MavenInvoke { appVersion '2.2.9' applicationName { baseAppName 'the-app' - prefix 'AVI' - suffix 'dev' } workerSpecs { target 'target_name' - muleVersion '4.3.0' } } closure.delegate = context @@ -54,7 +46,7 @@ class CloudhubV2ContextTest implements MavenInvoke { assertThat environment, is(equalTo('DEV')) assertThat applicationName.normalizedAppName, - is(equalTo('avi-the-app-dev')) + is(equalTo('the-app')) assertThat appVersion, is(equalTo('2.2.9')) assertThat cryptoKey, @@ -66,20 +58,18 @@ class CloudhubV2ContextTest implements MavenInvoke { workerSpecRequest.with { assertThat target, is(equalTo('target_name')) - assertThat muleVersion, - is(equalTo('4.3.0')) assertThat lastMileSecurity, is(equalTo(false)) - assertThat persistentObjectStore, - is(equalTo(false)) + assertThat objectStoreV2, + is(equalTo(true)) assertThat clustered, - is(equalTo(false)) + is(equalTo(true)) assertThat updateStrategy, is(equalTo(UpdateStrategy.rolling)) assertThat replicasAcrossNodes, - is(equalTo(false)) - assertThat publicURL, - is(equalTo(false)) + is(equalTo(true)) + assertThat publicUrl, + is(equalTo(null)) assertThat replicaSize, is(equalTo(VCoresSize.vCore1GB)) assertThat workerCount, @@ -108,7 +98,6 @@ class CloudhubV2ContextTest implements MavenInvoke { - businessGroupId missing - cryptoKey missing - environment missing -- workerSpecs.muleVersion missing - workerSpecs.target missing - autoDiscovery.clientId missing - autoDiscovery.clientSecret missing @@ -123,7 +112,8 @@ class CloudhubV2ContextTest implements MavenInvoke { environment 'DEV' applicationName { baseAppName 'the-app' - suffix 'dev' + prefix 'prefix' + suffix 'suffix' } appVersion '2.2.9' cryptoKey 'theKey' @@ -133,23 +123,35 @@ class CloudhubV2ContextTest implements MavenInvoke { } businessGroupId '123-456-789' workerSpecs { + muleVersion '4.6.9' + releaseChannel 'LTS' + javaVersion '17' + target 'target_name' - muleVersion '4.3.0' - lastMileSecurity true - persistentObjectStore true - clustered true + workerCount 2 + replicaSize VCoresSize.vCore2GB + cpuReserved 30 + memoryReserved 800 + replicasAcrossNodes false + clustered false updateStrategy UpdateStrategy.recreate - replicasAcrossNodes true - publicURL true - replicaSize VCoresSize.vCore15GB - workerCount 13 + + publicUrl 'https://api.mycompany.com/my-api' + generateDefaultPublicUrl false + pathRewrite 'newpath' + lastMileSecurity true + forwardSslSession true + + objectStoreV2 false + disableAmLogForwarding true + tracingEnabled true } appProperties ([ - someProp: 'someValue', + someProp: 'someValue', ]) appSecureProperties ([ - secureProp1: "123", - secureProp2: "456" + secureProp1: "123", + secureProp2: "456" ]) } closure.delegate = context @@ -171,28 +173,32 @@ class CloudhubV2ContextTest implements MavenInvoke { assertThat anypointClientSecret, is(equalTo('the_client_secret')) assertThat applicationName.normalizedAppName, - is(equalTo('the-app-dev')) + is(equalTo('prefix-the-app-suffix')) workerSpecRequest.with { assertThat target, is(equalTo('target_name')) assertThat muleVersion, - is(equalTo('4.3.0')) + is(equalTo('4.6.9')) assertThat lastMileSecurity, is(equalTo(true)) - assertThat persistentObjectStore, - is(equalTo(true)) + assertThat objectStoreV2, + is(equalTo(false)) assertThat clustered, - is(equalTo(true)) + is(equalTo(false)) assertThat updateStrategy, is(equalTo(UpdateStrategy.recreate)) assertThat replicasAcrossNodes, - is(equalTo(true)) - assertThat publicURL, - is(equalTo(true)) + is(equalTo(false)) + assertThat publicUrl, + is(equalTo('https://api.mycompany.com/my-api')) assertThat replicaSize, - is(equalTo(VCoresSize.vCore15GB)) + is(equalTo(VCoresSize.vCore2GB)) assertThat workerCount, - is(equalTo(13)) + is(equalTo(2)) + assertThat cpuReserved, + is(equalTo("30m")) + assertThat memoryReserved, + is(equalTo("800Mi")) } assertThat appProperties.someProp, is(equalTo('someValue')) diff --git a/library/src/test/java/com/avioconsulting/mule/deployment/dsl/OnPremContextTest.groovy b/library/src/test/java/com/avioconsulting/mule/deployment/dsl/OnPremContextTest.groovy index 0c8caf28..005c0408 100644 --- a/library/src/test/java/com/avioconsulting/mule/deployment/dsl/OnPremContextTest.groovy +++ b/library/src/test/java/com/avioconsulting/mule/deployment/dsl/OnPremContextTest.groovy @@ -12,6 +12,7 @@ import static org.hamcrest.Matchers.is @SuppressWarnings(["UnnecessaryQualifiedReference", "GroovyAssignabilityCheck"]) class OnPremContextTest implements MavenInvoke { + // TODO: This shouldn't need to run maven to test the context, this is also testing the deployment request @BeforeAll static void setup() { buildApp() diff --git a/library/src/test/java/com/avioconsulting/mule/deployment/dsl/RuntimeFabricContextTest.groovy b/library/src/test/java/com/avioconsulting/mule/deployment/dsl/RuntimeFabricContextTest.groovy index badfa7a1..a824cd3b 100644 --- a/library/src/test/java/com/avioconsulting/mule/deployment/dsl/RuntimeFabricContextTest.groovy +++ b/library/src/test/java/com/avioconsulting/mule/deployment/dsl/RuntimeFabricContextTest.groovy @@ -36,12 +36,9 @@ class RuntimeFabricContextTest implements MavenInvoke { appVersion '2.2.9' applicationName { baseAppName 'the-app' - prefix 'AVI' - suffix 'dev' } workerSpecs { target 'target_name' - muleVersion '4.3.0' } } closure.delegate = context @@ -55,7 +52,7 @@ class RuntimeFabricContextTest implements MavenInvoke { assertThat environment, is(equalTo('DEV')) assertThat applicationName.normalizedAppName, - is(equalTo('avi-the-app-dev')) + is(equalTo('the-app')) assertThat appVersion, is(equalTo('2.2.9')) assertThat cryptoKey, @@ -67,20 +64,18 @@ class RuntimeFabricContextTest implements MavenInvoke { workerSpecRequest.with { assertThat target, is(equalTo('target_name')) - assertThat muleVersion, - is(equalTo('4.3.0')) assertThat lastMileSecurity, is(equalTo(false)) - assertThat persistentObjectStore, - is(equalTo(false)) + assertThat objectStoreV2, + is(equalTo(true)) assertThat clustered, - is(equalTo(false)) + is(equalTo(true)) assertThat updateStrategy, is(equalTo(UpdateStrategy.rolling)) assertThat replicasAcrossNodes, - is(equalTo(false)) - assertThat publicURL, - is(equalTo(false)) + is(equalTo(true)) + assertThat publicUrl, + is(equalTo(null)) assertThat replicaSize, is(equalTo(VCoresSize.vCore1GB)) assertThat workerCount, @@ -109,7 +104,6 @@ class RuntimeFabricContextTest implements MavenInvoke { - businessGroupId missing - cryptoKey missing - environment missing -- workerSpecs.muleVersion missing - workerSpecs.target missing - autoDiscovery.clientId missing - autoDiscovery.clientSecret missing @@ -124,8 +118,8 @@ class RuntimeFabricContextTest implements MavenInvoke { environment 'DEV' applicationName { baseAppName 'the-app' - prefix '' - suffix '' + prefix 'prefix' + suffix 'suffix' } appVersion '2.2.9' cryptoKey 'theKey' @@ -135,18 +129,28 @@ class RuntimeFabricContextTest implements MavenInvoke { } businessGroupId '123-456-789' workerSpecs { + muleVersion '4.6.9' + releaseChannel 'LTS' + javaVersion '17' + target 'target_name' - muleVersion '4.3.0' - lastMileSecurity true - persistentObjectStore true - clustered true - updateStrategy UpdateStrategy.recreate - replicasAcrossNodes true - publicURL true - replicaSize VCoresSize.vCore15GB - workerCount 13 + workerCount 2 + replicaSize VCoresSize.vCore2GB cpuReserved 30 memoryReserved 800 + replicasAcrossNodes false + clustered false + updateStrategy UpdateStrategy.recreate + + publicUrl 'https://api.mycompany.com/my-api' + generateDefaultPublicUrl false + pathRewrite 'newpath' + lastMileSecurity true + forwardSslSession true + + objectStoreV2 false + disableAmLogForwarding true + tracingEnabled true } } closure.delegate = context @@ -160,7 +164,7 @@ class RuntimeFabricContextTest implements MavenInvoke { assertThat environment, is(equalTo('DEV')) assertThat applicationName.normalizedAppName, - is(equalTo('the-app')) + is(equalTo('prefix-the-app-suffix')) assertThat appVersion, is(equalTo('2.2.9')) assertThat cryptoKey, @@ -173,23 +177,23 @@ class RuntimeFabricContextTest implements MavenInvoke { assertThat target, is(equalTo('target_name')) assertThat muleVersion, - is(equalTo('4.3.0')) + is(equalTo('4.6.9')) assertThat lastMileSecurity, is(equalTo(true)) - assertThat persistentObjectStore, - is(equalTo(true)) + assertThat objectStoreV2, + is(equalTo(false)) assertThat clustered, - is(equalTo(true)) + is(equalTo(false)) assertThat updateStrategy, is(equalTo(UpdateStrategy.recreate)) assertThat replicasAcrossNodes, - is(equalTo(true)) - assertThat publicURL, - is(equalTo(true)) + is(equalTo(false)) + assertThat publicUrl, + is(equalTo('https://api.mycompany.com/my-api')) assertThat replicaSize, - is(equalTo(VCoresSize.vCore15GB)) + is(equalTo(VCoresSize.vCore2GB)) assertThat workerCount, - is(equalTo(13)) + is(equalTo(2)) assertThat cpuReserved, is(equalTo("30m")) assertThat memoryReserved, diff --git a/library/src/test/java/com/avioconsulting/mule/deployment/internal/TestFileBasedRequest.groovy b/library/src/test/java/com/avioconsulting/mule/deployment/internal/TestFileBasedRequest.groovy index 11ac7691..3f95052c 100644 --- a/library/src/test/java/com/avioconsulting/mule/deployment/internal/TestFileBasedRequest.groovy +++ b/library/src/test/java/com/avioconsulting/mule/deployment/internal/TestFileBasedRequest.groovy @@ -7,7 +7,7 @@ class TestFileBasedRequest extends FileBasedAppDeploymentRequest { private final File zipFile TestFileBasedRequest(File zipFile, String appName, String appVersion, String environment) { - super(zipFile, new ApplicationName(appName, null, null), appVersion, environment) + super(zipFile, new ApplicationName(appName, null, null), appVersion, environment, null) this.zipFile = zipFile } diff --git a/library/src/test/java/com/avioconsulting/mule/deployment/internal/models/CloudhubAppPropertiesTest.groovy b/library/src/test/java/com/avioconsulting/mule/deployment/internal/models/CloudhubAppPropertiesTest.groovy index 822533bf..8e36134b 100644 --- a/library/src/test/java/com/avioconsulting/mule/deployment/internal/models/CloudhubAppPropertiesTest.groovy +++ b/library/src/test/java/com/avioconsulting/mule/deployment/internal/models/CloudhubAppPropertiesTest.groovy @@ -27,8 +27,8 @@ class CloudhubAppPropertiesTest { // act def props = new CloudhubAppProperties(appName, - 'dev', - 'abc', + 'dev', null, + 'crypto_key', null, 'the_id', 'the_secret') diff --git a/library/src/test/java/com/avioconsulting/mule/deployment/internal/subdeployers/CloudHubV2DeployerTest.groovy b/library/src/test/java/com/avioconsulting/mule/deployment/internal/subdeployers/CloudHubV2DeployerTest.groovy index 8c811b77..8ff4af5a 100644 --- a/library/src/test/java/com/avioconsulting/mule/deployment/internal/subdeployers/CloudHubV2DeployerTest.groovy +++ b/library/src/test/java/com/avioconsulting/mule/deployment/internal/subdeployers/CloudHubV2DeployerTest.groovy @@ -8,6 +8,7 @@ import com.avioconsulting.mule.deployment.api.models.deployment.CloudhubV2Deploy import com.avioconsulting.mule.deployment.api.models.WorkerSpecRequest import com.avioconsulting.mule.deployment.api.models.UpdateStrategy import com.avioconsulting.mule.deployment.api.models.VCoresSize +import com.avioconsulting.mule.deployment.api.models.deployment.RuntimeFabricDeploymentRequest import groovy.json.JsonSlurper import io.vertx.core.MultiMap import io.vertx.core.http.HttpServerRequest @@ -41,6 +42,38 @@ class CloudHubV2DeployerTest extends RuntimeFabricDeployerTest implements MavenI dryRunMode) } + CloudhubV2DeploymentRequest getStandardDeploymentRequest() { + def request = new CloudhubV2DeploymentRequest(ENV, null, + new WorkerSpecRequest(TARGET_NAME, + VERSION, + false, + true, + true, + UpdateStrategy.recreate, + true, + true, + VCoresSize.vCore15GB, + 2, + false, + false, + 30, + 800, + null, + null, + 'LTS', + '17', + false), + CRYPTO_KEY, null, + CLIENT_ID, + CLIENT_SECRET, + new ApplicationName(APP_NAME, null, 'dev'), + APP_VERSION, + GROUP_ID) + + request.setAutoDiscoveryId('the.auto.disc.prop', '1234') + return request + } + @Test void new_app_success_deployment() { // arrange @@ -77,28 +110,7 @@ class CloudHubV2DeployerTest extends RuntimeFabricDeployerTest implements MavenI } } - def request = new CloudhubV2DeploymentRequest(ENV, - new WorkerSpecRequest(TARGET_NAME, - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName("new-app", null, ENV), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') + def request = getStandardDeploymentRequest() // act @@ -146,28 +158,7 @@ class CloudHubV2DeployerTest extends RuntimeFabricDeployerTest implements MavenI } } - def request = new CloudhubV2DeploymentRequest(ENV, - new WorkerSpecRequest(TARGET_NAME, - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName("new-app", null, null), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') + def request = getStandardDeploymentRequest() def exception = shouldFail { deployer.deploy(request) @@ -214,28 +205,7 @@ class CloudHubV2DeployerTest extends RuntimeFabricDeployerTest implements MavenI } } - def request = new CloudhubV2DeploymentRequest(ENV, - new WorkerSpecRequest(TARGET_NAME, - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, null, ENV), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') + def request = getStandardDeploymentRequest() // act deployer.deploy(request) @@ -283,28 +253,7 @@ class CloudHubV2DeployerTest extends RuntimeFabricDeployerTest implements MavenI } } - def request = new CloudhubV2DeploymentRequest(ENV, - new WorkerSpecRequest(TARGET_NAME, - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, null, ENV), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') + def request = getStandardDeploymentRequest() def exception = shouldFail { deployer.deploy(request) @@ -326,28 +275,8 @@ class CloudHubV2DeployerTest extends RuntimeFabricDeployerTest implements MavenI } } - def request = new CloudhubV2DeploymentRequest('INVALID_ENV', - new WorkerSpecRequest(TARGET_NAME, - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, null, ENV), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') + def request = getStandardDeploymentRequest() + request.environment = 'INVALID_ENV' def exception = shouldFail { deployer.deploy(request) @@ -372,28 +301,8 @@ class CloudHubV2DeployerTest extends RuntimeFabricDeployerTest implements MavenI } } - def request = new CloudhubV2DeploymentRequest(ENV, - new WorkerSpecRequest('INVALID_TARGET_NAME', - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, null, ENV), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') + def request = getStandardDeploymentRequest() + request.target = 'INVALID_TARGET_NAME' def exception = shouldFail { deployer.deploy(request) @@ -418,28 +327,8 @@ class CloudHubV2DeployerTest extends RuntimeFabricDeployerTest implements MavenI } } - def request = new CloudhubV2DeploymentRequest(ENV, - new WorkerSpecRequest('INVALID_TARGET_NAME', - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, null, ENV), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') + def request = getStandardDeploymentRequest() + request.target = 'INVALID_TARGET_NAME' def exception = shouldFail { deployer.deploy(request) diff --git a/library/src/test/java/com/avioconsulting/mule/deployment/internal/subdeployers/RuntimeFabricDeployerTest.groovy b/library/src/test/java/com/avioconsulting/mule/deployment/internal/subdeployers/RuntimeFabricDeployerTest.groovy index bd06e7e2..5b25f53d 100644 --- a/library/src/test/java/com/avioconsulting/mule/deployment/internal/subdeployers/RuntimeFabricDeployerTest.groovy +++ b/library/src/test/java/com/avioconsulting/mule/deployment/internal/subdeployers/RuntimeFabricDeployerTest.groovy @@ -37,6 +37,9 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { protected final String APP_ID = '987-654-321' protected final String APP_VERSION = '1.2.3' protected final String GROUP_ID = 'the-org-id' + protected final String CRYPTO_KEY = 'crypto-key' + protected final String CLIENT_ID = 'client-id' + protected final String CLIENT_SECRET = 'client-secret' @BeforeEach void clean() { @@ -55,6 +58,38 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { dryRunMode) } + RuntimeFabricDeploymentRequest getStandardDeploymentRequest() { + def request = new RuntimeFabricDeploymentRequest(ENV, null, + new WorkerSpecRequest(TARGET_NAME, + VERSION, + false, + true, + true, + UpdateStrategy.recreate, + true, + true, + VCoresSize.vCore15GB, + 2, + false, + false, + 30, + 800, + null, + null, + 'LTS', + '17', + false), + CRYPTO_KEY, null, + CLIENT_ID, + CLIENT_SECRET, + new ApplicationName(APP_NAME, null, 'dev'), + APP_VERSION, + GROUP_ID) + + request.setAutoDiscoveryId('the.auto.disc.prop', '1234') + return request + } + @Test void new_app_success_deployment() { // arrange @@ -91,29 +126,9 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { } } - def request = new RuntimeFabricDeploymentRequest(ENV, - new WorkerSpecRequest(TARGET_NAME, - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, null, 'dev'), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') - + def request = getStandardDeploymentRequest() + request.target = 'us-west-2' + request.appName = new ApplicationName(APP_NAME, null, 'dev') // act deployer.deploy(request) @@ -159,29 +174,8 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { } } - def request = new RuntimeFabricDeploymentRequest(ENV, - new WorkerSpecRequest(TARGET_NAME, - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, null, null), - - APP_VERSION, - GROUP_ID) + def request = getStandardDeploymentRequest() - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') def exception = shouldFail { deployer.deploy(request) @@ -228,28 +222,27 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { } } - def request = new RuntimeFabricDeploymentRequest(ENV, - new WorkerSpecRequest(TARGET_NAME, - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, null, 'dev'), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') +// def request = new RuntimeFabricDeploymentRequest(ENV, +// new WorkerSpecRequest(TARGET_NAME, +// VERSION, +// true, +// true, +// true, +// UpdateStrategy.recreate, +// true, +// true, +// VCoresSize.vCore15GB, +// 13, +// true, +// false), +// 'theKey', +// 'theClientId', +// 'theSecret', +// new ApplicationName(APP_NAME, null, 'dev'), +// APP_VERSION, +// GROUP_ID) + + def request = getStandardDeploymentRequest() // act deployer.deploy(request) @@ -297,28 +290,27 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { } } - def request = new RuntimeFabricDeploymentRequest(ENV, - new WorkerSpecRequest(TARGET_NAME, - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, null, 'dev'), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') +// def request = new RuntimeFabricDeploymentRequest(ENV, +// new WorkerSpecRequest(TARGET_NAME, +// VERSION, +// true, +// true, +// true, +// UpdateStrategy.recreate, +// true, +// true, +// VCoresSize.vCore15GB, +// 13, +// true, +// false), +// 'theKey', +// 'theClientId', +// 'theSecret', +// new ApplicationName(APP_NAME, null, 'dev'), +// APP_VERSION, +// GROUP_ID) + + def request = getStandardDeploymentRequest() def exception = shouldFail { deployer.deploy(request) @@ -340,28 +332,8 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { } } - def request = new RuntimeFabricDeploymentRequest('INVALID_ENV', - new WorkerSpecRequest(TARGET_NAME, - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, null, null), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') + def request = getStandardDeploymentRequest() + request.environment = 'INVALID_ENV' def exception = shouldFail { deployer.deploy(request) @@ -386,28 +358,8 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { } } - def request = new RuntimeFabricDeploymentRequest(ENV, - new WorkerSpecRequest('INVALID_TARGET_NAME', - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, 'client', null), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') + def request = getStandardDeploymentRequest() + request.target = 'INVALID_TARGET_NAME' def exception = shouldFail { deployer.deploy(request) @@ -432,28 +384,8 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { } } - def request = new RuntimeFabricDeploymentRequest(ENV, - new WorkerSpecRequest('INVALID_TARGET_NAME', - VERSION, - true, - true, - true, - UpdateStrategy.recreate, - true, - true, - VCoresSize.vCore15GB, - 13, - true, - false), - 'theKey', - 'theClientId', - 'theSecret', - new ApplicationName(APP_NAME, 'client', null), - APP_VERSION, - GROUP_ID) - - request.setAutoDiscoveryId('the.auto.disc.prop', - '1234') + def request = getStandardDeploymentRequest() + request.target = 'INVALID_TARGET_NAME' def exception = shouldFail { deployer.deploy(request) @@ -531,7 +463,7 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { ], target: [ provider: 'MC', - targetId: 'us-east-2' + targetId: 'us-west-2' ] ] ] @@ -554,7 +486,7 @@ class RuntimeFabricDeployerTest extends BaseTest implements MavenInvoke { ], target: [ provider: 'MC', - targetId: 'us-east-2' + targetId: 'us-west-2' ] ] ] diff --git a/maven-plugin/src/main/java/com/avioconsulting/mule/maven/BaseMojo.groovy b/maven-plugin/src/main/java/com/avioconsulting/mule/maven/BaseMojo.groovy index 7b2f16d3..c9982c97 100644 --- a/maven-plugin/src/main/java/com/avioconsulting/mule/maven/BaseMojo.groovy +++ b/maven-plugin/src/main/java/com/avioconsulting/mule/maven/BaseMojo.groovy @@ -36,18 +36,29 @@ abstract class BaseMojo extends AbstractMojo { } } - def props = System.getProperties().findAll { String k, v -> - (k as String).startsWith('muleDeploy.') + def props = [:] + + if (artifact) { + logger.println "Adding ${artifact.file} path as appArtifact in your DSL and setting groupId, artifactId and artifactVersion" + props['appArtifact'] = artifact.file.absolutePath + props['groupId'] = artifact.groupId + props['artifactId'] = artifact.id + props['artifactVersion'] = artifact.version + } + + def sysProps = System.getProperties().findAll { String k, v -> + (k as String).startsWith('muleDeploy.') || (k as String).startsWith('md.') }.collectEntries { k, v -> def withoutPrefix = (k as String).replaceFirst('muleDeploy\\.', '') + withoutPrefix = withoutPrefix.replaceFirst('md\\.', + '') [withoutPrefix, v] } - if (artifact) { - logger.println "Adding ${artifact.file} path as appArtifact in your DSL" - props['appArtifact'] = artifact.file.absolutePath - } - new ParamsWrapper(props + additionalProperties) + + + + new ParamsWrapper(props + sysProps + additionalProperties) } protected DeploymentPackage processDsl() { diff --git a/maven-plugin/src/main/java/com/avioconsulting/mule/maven/ParamsWrapper.groovy b/maven-plugin/src/main/java/com/avioconsulting/mule/maven/ParamsWrapper.groovy index 068de067..dd5f3682 100644 --- a/maven-plugin/src/main/java/com/avioconsulting/mule/maven/ParamsWrapper.groovy +++ b/maven-plugin/src/main/java/com/avioconsulting/mule/maven/ParamsWrapper.groovy @@ -3,6 +3,11 @@ package com.avioconsulting.mule.maven class ParamsWrapper { private final Properties properties + ParamsWrapper(Map params) { + this.properties = new Properties() + properties.putAll(params) + } + ParamsWrapper(Properties properties) { this.properties = properties } diff --git a/pom.xml b/pom.xml index 5283ba84..c05cdb3a 100644 --- a/pom.xml +++ b/pom.xml @@ -26,10 +26,10 @@ 1.8 1.8 3.0.7 - 2.20.0 - 5.10.0 - 1.10.1 - 3.2.3 + 2.24.1 + 5.11.3 + 1.11.3 + 3.5.2