Skip to content

Commit

Permalink
Fix destroy failed when deployed service with null serviceRequestProp…
Browse files Browse the repository at this point in the history
…erties (#2467)
  • Loading branch information
baixinsui authored Feb 26, 2025
1 parent 8f9047c commit 7551738
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,37 +226,40 @@ private Map<String, Object> getVariables(
List<DeployVariable> deployVariables,
boolean isDeployRequest) {
Map<String, Object> variables = new HashMap<>();
for (DeployVariable variable : deployVariables) {
if (variable.getKind() == DeployVariableKind.VARIABLE) {
if (serviceRequestProperties.containsKey(variable.getName())
&& serviceRequestProperties.get(variable.getName()) != null) {
if (!CollectionUtils.isEmpty(serviceRequestProperties)
&& !CollectionUtils.isEmpty(deployVariables)) {
for (DeployVariable variable : deployVariables) {
if (variable.getKind() == DeployVariableKind.VARIABLE) {
if (serviceRequestProperties.containsKey(variable.getName())
&& serviceRequestProperties.get(variable.getName()) != null) {
variables.put(
variable.getName(),
(variable.getSensitiveScope() != SensitiveScope.NONE
&& isDeployRequest)
? secretsManager.decodeBackToOriginalType(
variable.getDataType(),
serviceRequestProperties
.get(variable.getName())
.toString())
: serviceRequestProperties.get(variable.getName()));
} else {
variables.put(variable.getName(), System.getenv(variable.getName()));
}
}

if (variable.getKind() == DeployVariableKind.ENV_VARIABLE) {
variables.put(variable.getName(), System.getenv(variable.getName()));
}

if (variable.getKind() == DeployVariableKind.FIX_VARIABLE) {
variables.put(
variable.getName(),
(variable.getSensitiveScope() != SensitiveScope.NONE && isDeployRequest)
? secretsManager.decodeBackToOriginalType(
variable.getDataType(),
serviceRequestProperties
.get(variable.getName())
.toString())
: serviceRequestProperties.get(variable.getName()));
} else {
variables.put(variable.getName(), System.getenv(variable.getName()));
? secretsManager.decrypt(variable.getValue())
: variable.getValue());
}
}

if (variable.getKind() == DeployVariableKind.ENV_VARIABLE) {
variables.put(variable.getName(), System.getenv(variable.getName()));
}

if (variable.getKind() == DeployVariableKind.FIX_VARIABLE) {
variables.put(
variable.getName(),
(variable.getSensitiveScope() != SensitiveScope.NONE && isDeployRequest)
? secretsManager.decrypt(variable.getValue())
: variable.getValue());
}
}

return variables;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.eclipse.xpanse.modules.models.service.order.exceptions.ServiceOrderNotFound;
import org.eclipse.xpanse.modules.models.service.utils.ServiceDeployVariablesJsonSchemaGenerator;
import org.eclipse.xpanse.modules.models.service.view.DeployedServiceDetails;
import org.eclipse.xpanse.modules.models.servicetemplate.AvailabilityZoneConfig;
import org.eclipse.xpanse.modules.models.servicetemplate.Ocl;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceTemplateRegistrationState;
import org.eclipse.xpanse.modules.models.servicetemplate.request.ServiceTemplateRequestInfo;
Expand Down Expand Up @@ -182,20 +181,7 @@ DeployRequest getDeployRequest(ServiceTemplateDetailVo serviceTemplate) {
deployRequest.setRegion(serviceTemplate.getRegions().getFirst());
deployRequest.setServiceHostingType(serviceTemplate.getServiceHostingType());
deployRequest.setBillingMode(serviceTemplate.getBilling().getBillingModes().getFirst());

Map<String, Object> serviceRequestProperties = new HashMap<>();
serviceRequestProperties.put("admin_passwd", "111111111@Qq");
deployRequest.setServiceRequestProperties(serviceRequestProperties);

List<AvailabilityZoneConfig> availabilityZoneConfigs =
serviceTemplate.getDeployment().getServiceAvailabilityConfig();
Map<String, String> availabilityZones = new HashMap<>();
availabilityZoneConfigs.forEach(
availabilityZoneConfig ->
availabilityZones.put(
availabilityZoneConfig.getVarName(),
availabilityZoneConfig.getDisplayName()));
deployRequest.setAvailabilityZones(availabilityZones);
// null serviceRequestProperties and availabilityZones
return deployRequest;
}

Expand Down

0 comments on commit 7551738

Please sign in to comment.