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

remove deploy_request && add deployment_input_properties #2422

Merged
merged 1 commit into from
Feb 24, 2025
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 @@ -113,8 +113,8 @@ private Csp getCspFromRequestParams(Object[] args) {
for (Object arg : args) {
return switch (arg) {
case Ocl ocl -> ocl.getCloudServiceProvider().getName();
case DeployRequest deployRequest -> deployRequest.getCsp();
case ServicePortingRequest servicePortingRequest -> servicePortingRequest.getCsp();
case DeployRequest deployRequest -> deployRequest.getCsp();
case CreateCredential createCredential -> createCredential.getCsp();
case UserPolicyCreateRequest userPolicyCreateRequest ->
userPolicyCreateRequest.getCsp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public void validateRequest(JoinPoint joinPoint) {
for (Object arg : args) {
if (arg instanceof Ocl ocl) {
validatePluginForCspIsActive(ocl.getCloudServiceProvider().getName());
} else if (arg instanceof DeployRequest deployRequest) {
validatePluginForCspIsActive(deployRequest.getCsp());
} else if (arg instanceof ServicePortingRequest servicePortingRequest) {
validatePluginForCspIsActive(servicePortingRequest.getCsp());
} else if (arg instanceof DeployRequest deployRequest) {
validatePluginForCspIsActive(deployRequest.getCsp());
} else if (arg instanceof CreateCredential createCredential) {
validatePluginForCspIsActive(createCredential.getCsp());
} else if (arg instanceof UserPolicyCreateRequest userPolicyCreateRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.xpanse.modules.models.common.enums.UserOperation;
import org.eclipse.xpanse.modules.models.service.deployment.exceptions.BillingModeNotSupported;
import org.eclipse.xpanse.modules.models.service.deployment.exceptions.ServiceLockedException;
import org.eclipse.xpanse.modules.models.service.enums.Handler;
import org.eclipse.xpanse.modules.models.service.order.ServiceOrder;
import org.eclipse.xpanse.modules.models.service.order.enums.ServiceOrderType;
import org.eclipse.xpanse.modules.models.servicetemplate.exceptions.ServiceTemplateUnavailableException;
Expand Down Expand Up @@ -100,21 +101,18 @@ public ServiceOrder port(@Valid @RequestBody ServicePortingRequest servicePortin
servicePortingRequest.getOriginalServiceId());
throw new ServiceLockedException(errorMsg);
}
servicePortingRequest.setUserId(userId);
DeployTask servicePortingTask = getServicePortingTask(servicePortingRequest);
servicePortingTask.setUserId(userId);
ServiceOrderEntity servicePortingOrderEntity =
serviceOrderManager.storeNewServiceOrderEntity(
servicePortingTask, deployServiceEntity);
Map<String, Object> variable =
getServicePortingProcessVariable(servicePortingRequest, servicePortingOrderEntity);
servicePortingTask, deployServiceEntity, Handler.WORKFLOW);
Map<String, Object> variables = getServicePortingProcessVariables(servicePortingTask);
ProcessInstance instance =
workflowUtils.startProcess(ServicePortingConstants.PROCESS_KEY, variable);
workflowUtils.startProcessWithVariables(
ServicePortingConstants.PROCESS_KEY, variables);
servicePortingOrderEntity.setWorkflowId(instance.getProcessInstanceId());
ServiceOrderEntity updatedOrderEntity =
serviceOrderManager.startOrderProgress(servicePortingOrderEntity);
return new ServiceOrder(
updatedOrderEntity.getOrderId(),
(UUID) variable.get(ServicePortingConstants.NEW_SERVICE_ID));
serviceOrderManager.startOrderProgress(servicePortingOrderEntity);
return new ServiceOrder(servicePortingTask.getOrderId(), servicePortingTask.getServiceId());
}

private void validateData(ServicePortingRequest servicePortingRequest) {
Expand Down Expand Up @@ -159,28 +157,25 @@ private DeployTask getServicePortingTask(ServicePortingRequest servicePortingReq
DeployTask servicePortingTask = new DeployTask();
servicePortingTask.setOrderId(CustomRequestIdGenerator.generateOrderId());
servicePortingTask.setTaskType(ServiceOrderType.PORT);
servicePortingTask.setServiceId(servicePortingRequest.getOriginalServiceId());
servicePortingTask.setServiceId(UUID.randomUUID());
servicePortingTask.setOriginalServiceId(servicePortingRequest.getOriginalServiceId());
servicePortingTask.setUserId(servicePortingRequest.getUserId());
servicePortingTask.setRequest(servicePortingRequest);
return servicePortingTask;
}

private Map<String, Object> getServicePortingProcessVariable(
ServicePortingRequest servicePortingRequest,
ServiceOrderEntity servicePortingOrderEntity) {
Map<String, Object> variable = new HashMap<>();
variable.put(
ServicePortingConstants.SERVICE_PORTING_ORDER_ID,
servicePortingOrderEntity.getOrderId());
variable.put(
private Map<String, Object> getServicePortingProcessVariables(DeployTask servicePortingTask) {
Map<String, Object> variables = new HashMap<>();
variables.put(
ServicePortingConstants.SERVICE_PORTING_ORDER_ID, servicePortingTask.getOrderId());
variables.put(
ServicePortingConstants.ORIGINAL_SERVICE_ID,
servicePortingRequest.getOriginalServiceId());
variable.put(ServicePortingConstants.NEW_SERVICE_ID, UUID.randomUUID());
variable.put(ServicePortingConstants.SERVICE_PORTING_REQUEST, servicePortingRequest);
variable.put(ServicePortingConstants.USER_ID, servicePortingRequest.getUserId());
variable.put(ServicePortingConstants.DEPLOY_RETRY_NUM, 0);
variable.put(ServicePortingConstants.DESTROY_RETRY_NUM, 0);
return variable;
servicePortingTask.getOriginalServiceId());
variables.put(ServicePortingConstants.NEW_SERVICE_ID, servicePortingTask.getServiceId());
variables.put(
ServicePortingConstants.SERVICE_PORTING_REQUEST, servicePortingTask.getRequest());
variables.put(ServicePortingConstants.USER_ID, servicePortingTask.getUserId());
variables.put(ServicePortingConstants.DEPLOY_RETRY_NUM, 0);
variables.put(ServicePortingConstants.DESTROY_RETRY_NUM, 0);
return variables;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.xpanse.modules.models.common.enums.UserOperation;
import org.eclipse.xpanse.modules.models.service.deployment.exceptions.InvalidServiceStateException;
import org.eclipse.xpanse.modules.models.service.deployment.exceptions.ServiceLockedException;
import org.eclipse.xpanse.modules.models.service.enums.Handler;
import org.eclipse.xpanse.modules.models.service.enums.ServiceDeploymentState;
import org.eclipse.xpanse.modules.models.service.order.ServiceOrder;
import org.eclipse.xpanse.modules.models.service.order.enums.ServiceOrderType;
Expand Down Expand Up @@ -81,7 +82,7 @@ public class ServiceRecreateApi {
public ServiceOrder recreateService(@Valid @PathVariable("serviceId") UUID serviceId) {
ServiceDeploymentEntity serviceDeploymentEntity =
this.serviceDeploymentEntityHandler.getServiceDeploymentEntity(serviceId);
String userId = getUserId();
String userId = userServiceHelper.getCurrentUserId();
if (!StringUtils.equals(userId, serviceDeploymentEntity.getUserId())) {
String errorMsg =
String.format(
Expand Down Expand Up @@ -131,21 +132,15 @@ public ServiceOrder recreateService(@Valid @PathVariable("serviceId") UUID servi
DeployTask recreateTask = getRecreateTask(serviceDeploymentEntity);
ServiceOrderEntity recreateOrderEntity =
serviceOrderManager.storeNewServiceOrderEntity(
recreateTask, serviceDeploymentEntity);
recreateTask, serviceDeploymentEntity, Handler.WORKFLOW);

// prepare recreate process variables
Map<String, Object> variable =
getRecreateProcessVariable(serviceDeploymentEntity, recreateOrderEntity);
Map<String, Object> variables = getRecreateProcessVariables(recreateTask);
ProcessInstance instance =
workflowUtils.startProcess(RecreateConstants.PROCESS_KEY, variable);

workflowUtils.startProcessWithVariables(RecreateConstants.PROCESS_KEY, variables);
recreateOrderEntity.setWorkflowId(instance.getProcessInstanceId());
ServiceOrderEntity updatedRecreateOrderEntity =
serviceOrderManager.startOrderProgress(recreateOrderEntity);

return new ServiceOrder(
updatedRecreateOrderEntity.getOrderId(),
updatedRecreateOrderEntity.getOriginalServiceId());
serviceOrderManager.startOrderProgress(recreateOrderEntity);
return new ServiceOrder(recreateTask.getOrderId(), recreateTask.getServiceId());
}

private DeployTask getRecreateTask(ServiceDeploymentEntity serviceDeploymentEntity) {
Expand All @@ -154,22 +149,16 @@ private DeployTask getRecreateTask(ServiceDeploymentEntity serviceDeploymentEnti
recreateTask.setTaskType(ServiceOrderType.RECREATE);
recreateTask.setServiceId(serviceDeploymentEntity.getId());
recreateTask.setOriginalServiceId(serviceDeploymentEntity.getId());
recreateTask.setUserId(getUserId());
recreateTask.setDeployRequest(serviceDeploymentEntity.getDeployRequest());
recreateTask.setUserId(serviceDeploymentEntity.getUserId());
return recreateTask;
}

private String getUserId() {
return this.userServiceHelper.getCurrentUserId();
}

private Map<String, Object> getRecreateProcessVariable(
ServiceDeploymentEntity deployedService, ServiceOrderEntity recreateOrderEntity) {
private Map<String, Object> getRecreateProcessVariables(DeployTask recreateTask) {
Map<String, Object> variable = new HashMap<>();
variable.put(RecreateConstants.SERVICE_ID, deployedService.getId());
variable.put(RecreateConstants.RECREATE_ORDER_ID, recreateOrderEntity.getOrderId());
variable.put(RecreateConstants.RECREATE_REQUEST, deployedService.getDeployRequest());
variable.put(RecreateConstants.USER_ID, recreateOrderEntity.getUserId());
variable.put(RecreateConstants.SERVICE_ID, recreateTask.getServiceId());
variable.put(RecreateConstants.RECREATE_ORDER_ID, recreateTask.getOrderId());
variable.put(RecreateConstants.RECREATE_REQUEST, recreateTask.getDeployRequest());
variable.put(RecreateConstants.USER_ID, recreateTask.getUserId());
variable.put(RecreateConstants.DEPLOY_RETRY_NUM, 0);
variable.put(RecreateConstants.DESTROY_RETRY_NUM, 0);
return variable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.eclipse.xpanse.api.controllers.ServiceDeployerApi;
import org.eclipse.xpanse.modules.database.serviceorder.ServiceOrderStorage;
import org.eclipse.xpanse.modules.deployment.DeployService;
import org.eclipse.xpanse.modules.deployment.DeployServiceEntityConverter;
import org.eclipse.xpanse.modules.deployment.DeployerKindManager;
import org.eclipse.xpanse.modules.deployment.ServiceDeploymentEntityConverter;
import org.eclipse.xpanse.modules.deployment.ServiceDeploymentEntityHandler;
import org.eclipse.xpanse.modules.deployment.ServiceDetailsViewManager;
import org.eclipse.xpanse.modules.deployment.ServiceOrderManager;
Expand Down Expand Up @@ -63,7 +63,7 @@
ServiceLockConfigService.class,
ServiceOrderManager.class,
CspPluginValidator.class,
DeployServiceEntityConverter.class,
ServiceDeploymentEntityConverter.class,
PluginManager.class
})
@WebMvcTest
Expand All @@ -80,7 +80,7 @@ class DeploymentExceptionHandlerTest {
@MockitoBean private OrchestratorPlugin orchestratorPlugin;
@MockitoBean private ServiceOrderManager serviceOrderManager;
@MockitoBean private ServiceOrderStorage serviceOrderStorage;
@MockitoBean private DeployServiceEntityConverter deployServiceEntityConverter;
@MockitoBean private ServiceDeploymentEntityConverter serviceDeploymentEntityConverter;

@BeforeEach
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
import org.eclipse.xpanse.modules.database.resource.ServiceResourceEntity;
import org.eclipse.xpanse.modules.database.serviceconfiguration.ServiceConfigurationEntity;
import org.eclipse.xpanse.modules.database.serviceorder.ServiceOrderEntity;
import org.eclipse.xpanse.modules.models.billing.enums.BillingMode;
import org.eclipse.xpanse.modules.models.common.enums.Category;
import org.eclipse.xpanse.modules.models.common.enums.Csp;
import org.eclipse.xpanse.modules.models.service.config.ServiceLockConfig;
import org.eclipse.xpanse.modules.models.service.deployment.DeployRequest;
import org.eclipse.xpanse.modules.models.service.enums.ServiceDeploymentState;
import org.eclipse.xpanse.modules.models.service.statemanagement.enums.ServiceState;
import org.eclipse.xpanse.modules.models.servicetemplate.Region;
import org.eclipse.xpanse.modules.models.servicetemplate.enums.ServiceHostingType;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.Type;
Expand All @@ -55,44 +57,79 @@ public class ServiceDeploymentEntity extends CreateModifiedTime {
@Id private UUID id;

/** The id of user who deployed the service. */
@Column(name = "USER_ID")
private String userId;

/** The category of the Service. */
@Enumerated(EnumType.STRING)
@Column(nullable = false)
@Column(name = "CATEGORY", nullable = false)
private Category category;

/** The name of the Service. */
@Column(name = "NAME")
private String name;

/** The customer provided name for the service deployment. */
private String customerServiceName;

/** The version of the Service. */
@Column(name = "VERSION")
private String version;

/** The customer provided name for the service deployment. */
@Column(name = "CUSTOMER_SERVICE_NAME")
private String customerServiceName;

/** ServiceVendor of the user who registered service template. */
@Column(nullable = false)
@Column(name = "SERVICE_VENDOR", nullable = false)
private String serviceVendor;

/** The csp of the Service. */
@Enumerated(EnumType.STRING)
@Column(nullable = false)
@Column(name = "CSP", nullable = false)
private Csp csp;

/** The hosting type of the Service. */
@Enumerated(EnumType.STRING)
@Column(name = "SERVICE_HOSTING_TYPE", nullable = false)
private ServiceHostingType serviceHostingType;

/** The region of the Service. */
@Column(name = "REGION", columnDefinition = "json", nullable = false)
@Type(value = JsonType.class)
@Convert(converter = ObjectJsonConverter.class)
private Region region;

/** The availability zones of the Service. */
@Column(name = "AVAILABILITY_ZONES", columnDefinition = "json")
@Type(value = JsonType.class)
private Map<String, String> availabilityZones;

/** The flavor of the Service. */
@Column(nullable = false)
@Column(name = "FLAVOR", nullable = false)
private String flavor;

/** The billing mode of the service. */
@Enumerated(EnumType.STRING)
@Column(name = "BILLING_MODE", nullable = false)
private BillingMode billingMode;

/** The input properties of the service deployment. */
@ElementCollection
@CollectionTable(
name = "SERVICE_DEPLOYMENT_INPUT",
joinColumns = @JoinColumn(name = "SERVICE_ID", nullable = false))
@MapKeyColumn(name = "P_KEY")
@Column(name = "P_VALUE")
@OnDelete(action = OnDeleteAction.CASCADE)
private Map<String, String> inputProperties;

/** The deployment id of the Service. */
@Column(name = "IS_EULA_ACCEPTED", nullable = false)
private Boolean isEulaAccepted;

/** The deployment state of the Service. */
@Enumerated(EnumType.STRING)
@Column(name = "SERVICE_DEPLOYMENT_STATE", nullable = false)
private ServiceDeploymentState serviceDeploymentState;

/** The result message of the service deployment. */
@Column(name = "RESULT_MESSAGE", length = Integer.MAX_VALUE)
private String resultMessage;

/** The run state of the Service. */
@Enumerated(EnumType.STRING)
@Column(name = "SERVICE_STATE")
Expand All @@ -102,11 +139,6 @@ public class ServiceDeploymentEntity extends CreateModifiedTime {
@Column(name = "SERVICE_TEMPLATE_ID", nullable = false)
private UUID serviceTemplateId;

@Column(columnDefinition = "json")
@Type(value = JsonType.class)
@Convert(converter = ObjectJsonConverter.class)
private DeployRequest deployRequest;

@OneToMany(
mappedBy = "serviceDeploymentEntity",
cascade = CascadeType.ALL,
Expand Down Expand Up @@ -158,7 +190,7 @@ public class ServiceDeploymentEntity extends CreateModifiedTime {
@Column(name = "LAST_STOPPED_AT")
private OffsetDateTime lastStoppedAt;

@Column(columnDefinition = "json")
@Column(name = "LOCK_CONFIG", columnDefinition = "json")
@Type(value = JsonType.class)
@Convert(converter = ObjectJsonConverter.class)
private ServiceLockConfig lockConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.xpanse.modules.database.common.ObjectJsonConverter;
import org.eclipse.xpanse.modules.database.service.ServiceDeploymentEntity;
import org.eclipse.xpanse.modules.models.response.ErrorResponse;
import org.eclipse.xpanse.modules.models.service.enums.Handler;
import org.eclipse.xpanse.modules.models.service.enums.TaskStatus;
import org.eclipse.xpanse.modules.models.service.order.enums.ServiceOrderType;
import org.hibernate.annotations.OnDelete;
Expand Down Expand Up @@ -96,4 +97,8 @@ public class ServiceOrderEntity implements Serializable {
@Type(value = JsonType.class)
@Convert(converter = ObjectJsonConverter.class)
private Map<String, Object> resultProperties;

@Enumerated(EnumType.STRING)
@Column(name = "HANDLER", nullable = false)
private Handler handler;
}
Loading
Loading