Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize method for reading the files generated by the deployer #2094

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.xpanse.modules.deployment.ServiceDeploymentEntityHandler;
import org.eclipse.xpanse.modules.deployment.ServiceOrderManager;
import org.eclipse.xpanse.modules.deployment.migration.consts.MigrateConstants;
import org.eclipse.xpanse.modules.logging.CustomRequestIdGenerator;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.BillingModeNotSupported;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.EulaNotAccepted;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.ServiceLockedException;
Expand Down Expand Up @@ -148,7 +149,7 @@ private void validateData(MigrateRequest migrateRequest) {

private DeployTask getMigrateTask(MigrateRequest migrateRequest) {
DeployTask migrateTask = new DeployTask();
migrateTask.setOrderId(UUID.randomUUID());
migrateTask.setOrderId(CustomRequestIdGenerator.generateOrderId());
migrateTask.setTaskType(ServiceOrderType.MIGRATE);
migrateTask.setServiceId(migrateRequest.getOriginalServiceId());
migrateTask.setOriginalServiceId(migrateRequest.getOriginalServiceId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.xpanse.modules.deployment.ServiceDeploymentEntityHandler;
import org.eclipse.xpanse.modules.deployment.ServiceOrderManager;
import org.eclipse.xpanse.modules.deployment.recreate.consts.RecreateConstants;
import org.eclipse.xpanse.modules.logging.CustomRequestIdGenerator;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.InvalidServiceStateException;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.ServiceLockedException;
import org.eclipse.xpanse.modules.models.service.enums.ServiceDeploymentState;
Expand Down Expand Up @@ -135,7 +136,7 @@ public ServiceOrder recreateService(@Valid @PathVariable("serviceId") String ser

private DeployTask getRecreateTask(ServiceDeploymentEntity serviceDeploymentEntity) {
DeployTask recreateTask = new DeployTask();
recreateTask.setOrderId(UUID.randomUUID());
recreateTask.setOrderId(CustomRequestIdGenerator.generateOrderId());
recreateTask.setTaskType(ServiceOrderType.RECREATE);
recreateTask.setServiceId(serviceDeploymentEntity.getId());
recreateTask.setOriginalServiceId(serviceDeploymentEntity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.exceptions.TerraformBootRequestFailedException;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.exceptions.TerraformExecutorException;
import org.eclipse.xpanse.modules.deployment.exceptions.DeploymentScriptsCreationFailedException;
import org.eclipse.xpanse.modules.models.billing.exceptions.ServicePriceCalculationFailed;
import org.eclipse.xpanse.modules.models.common.exceptions.InvalidDeployerToolException;
import org.eclipse.xpanse.modules.models.response.Response;
Expand Down Expand Up @@ -270,4 +271,16 @@ public Response handleInvalidDeployerToolException(InvalidDeployerToolException
return getErrorResponse(ResultType.INVALID_DEPLOYER_TOOL,
Collections.singletonList(ex.getMessage()));
}

/**
* Exception handler for DeploymentScriptsCreationFailedException.
*/
@ExceptionHandler({DeploymentScriptsCreationFailedException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public Response handleDeploymentScriptsCreatedException(
DeploymentScriptsCreationFailedException ex) {
return getErrorResponse(ResultType.DEPLOYMENT_SCRIPTS_CREATION_FAILED,
Collections.singletonList(ex.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package org.eclipse.xpanse.modules.deployment;

import static org.eclipse.xpanse.modules.deployment.utils.DeploymentScriptsHelper.TF_STATE_FILE_NAME;

import jakarta.annotation.Resource;
import java.time.OffsetDateTime;
import java.util.ArrayList;
Expand All @@ -25,6 +27,7 @@
import org.eclipse.xpanse.modules.database.servicetemplate.ServiceTemplateStorage;
import org.eclipse.xpanse.modules.deployment.migration.consts.MigrateConstants;
import org.eclipse.xpanse.modules.deployment.recreate.consts.RecreateConstants;
import org.eclipse.xpanse.modules.logging.CustomRequestIdGenerator;
import org.eclipse.xpanse.modules.models.service.deploy.DeployRequest;
import org.eclipse.xpanse.modules.models.service.deploy.DeployResource;
import org.eclipse.xpanse.modules.models.service.enums.ServiceDeploymentState;
Expand Down Expand Up @@ -128,7 +131,7 @@ public void rollbackOnDeploymentFailure(DeployTask rollbackTask,
DeployResult rollbackResult;
RuntimeException exception = null;
log.info("Performing rollback of already provisioned resources.");
rollbackTask.setOrderId(UUID.randomUUID());
rollbackTask.setOrderId(CustomRequestIdGenerator.generateOrderId());
rollbackTask.setTaskType(ServiceOrderType.ROLLBACK);
ServiceOrderEntity serviceOrderEntity = serviceOrderManager
.storeNewServiceOrderEntity(rollbackTask, serviceDeploymentEntity);
Expand Down Expand Up @@ -169,14 +172,27 @@ private ServiceDeploymentEntity updateDeployServiceEntityWithDeployResult(
log.info("Update deploy service entity {} with deploy result {}",
serviceDeploymentEntity.getId(), deployResult);
if (StringUtils.isNotBlank(deployResult.getTfStateContent())) {
deployResult.getDeploymentGeneratedFiles()
.put(TF_STATE_FILE_NAME, deployResult.getTfStateContent());
ServiceTemplateEntity serviceTemplateEntity =
serviceTemplateStorage.getServiceTemplateById(
serviceDeploymentEntity.getServiceTemplateId());
DeployerKind deployerKind =
serviceTemplateEntity.getOcl().getDeployment().getDeployerTool().getKind();
resourceHandlerManager.getResourceHandler(serviceDeploymentEntity.getCsp(),
deployerKind).handler(deployResult);
} else {
if (Objects.nonNull(serviceDeploymentEntity.getDeploymentGeneratedFiles())) {
String storedTfStateContent = serviceDeploymentEntity.getDeploymentGeneratedFiles()
.get(TF_STATE_FILE_NAME);
if (StringUtils.isNotBlank(storedTfStateContent)) {
deployResult.setTfStateContent(storedTfStateContent);
deployResult.getDeploymentGeneratedFiles()
.put(TF_STATE_FILE_NAME, deployResult.getTfStateContent());
}
}
}

ServiceDeploymentEntity deployServiceToUpdate = new ServiceDeploymentEntity();
BeanUtils.copyProperties(serviceDeploymentEntity, deployServiceToUpdate);
updateServiceEntityWithDeployResult(deployResult, taskType, deployServiceToUpdate);
Expand All @@ -185,7 +201,8 @@ private ServiceDeploymentEntity updateDeployServiceEntityWithDeployResult(


private void updateServiceEntityWithDeployResult(DeployResult deployResult,
ServiceOrderType taskType, ServiceDeploymentEntity serviceDeployment) {
ServiceOrderType taskType,
ServiceDeploymentEntity serviceDeployment) {
boolean isTaskSuccessful = deployResult.getIsTaskSuccessful();
ServiceDeploymentState deploymentState =
getServiceDeploymentState(taskType, isTaskSuccessful);
Expand Down Expand Up @@ -370,7 +387,6 @@ private void processRelatedWorkflowTask(ServiceOrderEntity serviceOrder) {
}
}
}

} catch (Exception e) {
log.error("Failed to process the related workflow task of service order: {}",
serviceOrder.getOrderId(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import org.eclipse.xpanse.modules.database.service.ServiceDeploymentEntity;
import org.eclipse.xpanse.modules.database.serviceconfiguration.ServiceConfigurationEntity;
import org.eclipse.xpanse.modules.database.servicetemplate.ServiceTemplateEntity;
import org.eclipse.xpanse.modules.database.servicetemplate.ServiceTemplateStorage;
import org.eclipse.xpanse.modules.logging.CustomRequestIdGenerator;
import org.eclipse.xpanse.modules.models.service.order.enums.ServiceOrderType;
import org.eclipse.xpanse.modules.models.servicetemplate.ServiceConfigurationManage;
import org.eclipse.xpanse.modules.models.servicetemplate.ServiceConfigurationParameter;
Expand All @@ -38,15 +38,15 @@ public class DeployServiceEntityConverter {
/**
* Method to create a DeployTask from DeployServiceEntity.
*
* @param orderType ServiceOrderType.
* @param orderType ServiceOrderType.
* @param serviceDeploymentEntity DeployServiceEntity object.
* @return DeployTask object.
*/
public DeployTask getDeployTaskByStoredService(ServiceOrderType orderType,
ServiceDeploymentEntity serviceDeploymentEntity) {
public DeployTask getDeployTaskByStoredService(
ServiceOrderType orderType, ServiceDeploymentEntity serviceDeploymentEntity) {
// Set Ocl and CreateRequest
DeployTask deployTask = new DeployTask();
deployTask.setOrderId(UUID.randomUUID());
deployTask.setOrderId(CustomRequestIdGenerator.generateOrderId());
deployTask.setTaskType(orderType);
deployTask.setServiceId(serviceDeploymentEntity.getId());
deployTask.setUserId(serviceDeploymentEntity.getUserId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import java.util.Objects;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.xpanse.modules.deployment.DeployResultManager;
import org.eclipse.xpanse.modules.deployment.deployers.opentofu.tofumaker.generated.model.OpenTofuResult;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.utils.TfResourceTransUtils;
import org.eclipse.xpanse.modules.orchestrator.deployment.DeployResult;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -48,11 +48,12 @@ private DeployResult getDeployResult(OpenTofuResult result) {
deployResult.setIsTaskSuccessful(true);
deployResult.setMessage(null);
}
deployResult.setTfStateContent(result.getTerraformState());
deployResult.getDeploymentGeneratedFiles()
.put(TfResourceTransUtils.STATE_FILE_NAME, result.getTerraformState());
if (Objects.nonNull(result.getImportantFileContentMap())) {
deployResult.getDeploymentGeneratedFiles().putAll(result.getImportantFileContentMap());
if (StringUtils.isNotBlank(result.getTerraformState())) {
deployResult.setTfStateContent(result.getTerraformState());
}
if (Objects.nonNull(result.getGeneratedFileContentMap())) {
deployResult.getDeploymentGeneratedFiles()
.putAll(result.getGeneratedFileContentMap());
}
return deployResult;
}
Expand Down
Loading
Loading