Skip to content

Commit

Permalink
Initial Model object changes for Cloudhub V2 Deployment Fucntionality (
Browse files Browse the repository at this point in the history
…#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 <adesjardin@gmail.com>
  • Loading branch information
djizatt-avio and adesjardin authored Nov 8, 2024
1 parent 23e8896 commit 30cd213
Show file tree
Hide file tree
Showing 30 changed files with 931 additions and 852 deletions.
5 changes: 5 additions & 0 deletions library/examples/muleDeploy_ch2.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<configuration>
<excludes>
<exclude>**/IntegrationTest.java</exclude>
<exclude>com.avioconsulting.mule.integrationtest.CloudHubV2IntegrationTest</exclude>
</excludes>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ enum UpdateStrategy {
* Re-deployment is quicker than rolling and doesn’t require additional resources.
*/
recreate

String updateStrategy
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class CloudhubDeploymentRequest extends FileBasedAppDeploymentRequest {
Map<String, String> appProperties = [:],
Map<String, String> 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]
Expand All @@ -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
}

Expand All @@ -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<String, String> getCloudhubAppInfo() {
def props = new ObjectMapper().convertValue(this.cloudhubAppProperties,
Map)
Map)
props += this.autoDiscoveries
def result = [
// CloudHub's API calls the Mule application the 'domain'
Expand Down Expand Up @@ -153,8 +156,8 @@ class CloudhubDeploymentRequest extends FileBasedAppDeploymentRequest {
JsonOutput.toJson(cloudhubAppInfo)
}

Map<String,String> getCloudAppInfoAsObfuscatedJson() {
PropertiesObfuscator.obfuscateMap(cloudhubAppInfo,"properties")
Map<String, String> getCloudAppInfoAsObfuscatedJson() {
PropertiesObfuscator.obfuscateMap(cloudhubAppInfo, "properties")
}

@Lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,11 +23,13 @@ class CloudhubV2DeploymentRequest extends RuntimeFabricDeploymentRequest {
Map<String, String> appProperties = [:],
Map<String, String> appSecureProperties = [:],
Map<String, String> 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<String, String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class OnPremDeploymentRequest extends FileBasedAppDeploymentRequest {
ApplicationName appName,
String appVersion = null,
Map<String, String> 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
}
Expand Down
Loading

0 comments on commit 30cd213

Please sign in to comment.