Skip to content

Commit

Permalink
Create environment as relation
Browse files Browse the repository at this point in the history
  • Loading branch information
cmleite committed Jan 30, 2025
1 parent 2d2bf98 commit d638d66
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions src/Common/Handlers/NewEnvironmentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,25 @@ bool terminateOtherVersionsRemoveVolumes
environment.Description = description;
}

environment.DeploymentPackage = isInfrastructureAgent || string.IsNullOrWhiteSpace(deploymentPackageName) ? environment.DeploymentPackage : await _customerPortalClient.GetObjectByName<DeploymentPackage>(deploymentPackageName);
environment.SoftwareLicense = isInfrastructureAgent || string.IsNullOrWhiteSpace(licenseName) ? environment.SoftwareLicense : await Utils.GetLicenseByUniqueName(licenseName);
environment.DeploymentTarget = _newEnvironmentUtilities.GetDeploymentTargetValue(target);
environment.ChangeSet = null;

var cedpCollection = new CustomerEnvironmentDeploymentPackageCollection();
if (isInfrastructureAgent || string.IsNullOrWhiteSpace(deploymentPackageName))
{
cedpCollection.AddRange(environment.RelationCollection.FirstOrDefault(x => x.Key == nameof(CustomerEnvironmentDeploymentPackage)).Value
.Cast<CustomerEnvironmentDeploymentPackage>());
}
else
{
cedpCollection.Add(new CustomerEnvironmentDeploymentPackage()
{
SourceEntity = environment,
SoftwareLicense = await Utils.GetLicenseByUniqueName(licenseName),
TargetEntity = await _customerPortalClient.GetObjectByName<DeploymentPackage>(deploymentPackageName)
});
}

// check environment connection
await _newEnvironmentUtilities.CheckEnvironmentConnection(environment);

Expand All @@ -105,7 +119,7 @@ bool terminateOtherVersionsRemoveVolumes

// Update environment with the parameters to be merged instead of overwriting
environment.Parameters = rawParameters;
environment = await UpdateEnvironment(environment);
environment = await UpdateEnvironment(environment, cedpCollection);

// terminate other versions
if (terminateOtherVersions)
Expand Down Expand Up @@ -190,12 +204,22 @@ bool terminateOtherVersionsRemoveVolumes
Description = description,
Parameters = rawParameters,
EnvironmentType = environmentType.ToString(),
DeploymentPackage = isInfrastructureAgent ? null : await _customerPortalClient.GetObjectByName<DeploymentPackage>(deploymentPackageName),
DeploymentTarget = _newEnvironmentUtilities.GetDeploymentTargetValue(target),
Site = environmentSite,
SoftwareLicense = isInfrastructureAgent ? null : await Utils.GetLicenseByUniqueName(licenseName)
};

var deploymentPackage = isInfrastructureAgent ? null : await _customerPortalClient.GetObjectByName<DeploymentPackage>(deploymentPackageName);
var softwareLicense = isInfrastructureAgent ? null : await Utils.GetLicenseByUniqueName(licenseName);
var cedpCollection = new CustomerEnvironmentDeploymentPackageCollection
{
new CustomerEnvironmentDeploymentPackage()
{
SourceEntity = environment,
TargetEntity = deploymentPackage,
SoftwareLicense = softwareLicense
}
};

// check environment connection
await CheckConnectionNewEnvironmentCreation(environment, customerInfrastructureName);

Expand All @@ -205,7 +229,8 @@ bool terminateOtherVersionsRemoveVolumes
{
CustomerInfrastructureName = customerInfrastructureName,
CustomerEnvironment = environment,
IsInfrastructureAgent = isInfrastructureAgent
IsInfrastructureAgent = isInfrastructureAgent,
CustomerEnvironmentDeploymentPackageRelations = cedpCollection

Check failure on line 233 in src/Common/Handlers/NewEnvironmentHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'CreateCustomerEnvironmentForCustomerInfrastructureInput' does not contain a definition for 'CustomerEnvironmentDeploymentPackageRelations'

Check failure on line 233 in src/Common/Handlers/NewEnvironmentHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'CreateCustomerEnvironmentForCustomerInfrastructureInput' does not contain a definition for 'CustomerEnvironmentDeploymentPackageRelations'
}.CreateCustomerEnvironmentForCustomerInfrastructureAsync(true)).CustomerEnvironment;
}
// if not, just create a new environment
Expand All @@ -218,13 +243,24 @@ bool terminateOtherVersionsRemoveVolumes
EnvironmentType = environmentType.ToString(),
Site = isInfrastructureAgent ? null : await _customerPortalClient.GetObjectByName<ProductSite>(siteName),
Name = name,
DeploymentPackage = isInfrastructureAgent ? null : await _customerPortalClient.GetObjectByName<DeploymentPackage>(deploymentPackageName),
SoftwareLicense = isInfrastructureAgent ? null : await Utils.GetLicenseByUniqueName(licenseName),
DeploymentTarget = _newEnvironmentUtilities.GetDeploymentTargetValue(target),
Parameters = rawParameters
};

var deploymentPackage = isInfrastructureAgent ? null : await _customerPortalClient.GetObjectByName<DeploymentPackage>(deploymentPackageName);
var softwareLicense = isInfrastructureAgent ? null : await Utils.GetLicenseByUniqueName(licenseName);
var cedpCollection = new CustomerEnvironmentDeploymentPackageCollection
{
new CustomerEnvironmentDeploymentPackage()
{
SourceEntity = environment,
TargetEntity = deploymentPackage,
SoftwareLicense = softwareLicense
}
};

environment = await CreateEnvironment(_customerPortalClient, environment);
environment = await UpdateEnvironment(environment, cedpCollection);
}

Session.LogInformation($"Customer environment {name} created...");
Expand Down Expand Up @@ -293,13 +329,14 @@ public static async Task<CustomerEnvironment> CreateNewEnvironmentEntityOrVersio
/// </summary>
/// <param name="customerEnvironment">customer environment</param>
/// <returns></returns>
public static async Task<CustomerEnvironment> UpdateEnvironment(CustomerEnvironment customerEnvironment)
public static async Task<CustomerEnvironment> UpdateEnvironment(CustomerEnvironment customerEnvironment, CustomerEnvironmentDeploymentPackageCollection cedpCollection)
{
customerEnvironment.ChangeSet = null;
return (await new UpdateCustomerEnvironmentInput
{
CustomerEnvironment = customerEnvironment,
DeploymentParametersMergeMode = DeploymentParametersMergeMode.Merge
DeploymentParametersMergeMode = DeploymentParametersMergeMode.Merge,
CustomerEnvironmentDeploymentPackageRelations = cedpCollection

Check failure on line 339 in src/Common/Handlers/NewEnvironmentHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'UpdateCustomerEnvironmentInput' does not contain a definition for 'CustomerEnvironmentDeploymentPackageRelations'

Check failure on line 339 in src/Common/Handlers/NewEnvironmentHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'UpdateCustomerEnvironmentInput' does not contain a definition for 'CustomerEnvironmentDeploymentPackageRelations'
}.UpdateCustomerEnvironmentAsync(true)).CustomerEnvironment;
}
}
Expand Down

0 comments on commit d638d66

Please sign in to comment.