Skip to content

Commit 475ae81

Browse files
authored
Add table service_orders to record all services managements (eclipse-xpanse#1779)
1 parent d596620 commit 475ae81

File tree

109 files changed

+3119
-2410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+3119
-2410
lines changed

modules/api/src/main/java/org/eclipse/xpanse/api/config/AuditLogWriter.java

+20-29
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,14 @@ public void controllerMethods() {
6464
@Around("controllerMethods()")
6565
public Object auditRequest(ProceedingJoinPoint joinPoint) throws Throwable {
6666
Csp csp = getCsp(joinPoint);
67-
log.info("Get csp from request attributes: {}", csp);
6867
Object result = joinPoint.proceed();
6968
if (Objects.nonNull(csp)) {
7069
HttpServletRequest request =
7170
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
7271
.getRequest();
73-
7472
OrchestratorPlugin orchestratorPlugin = pluginManager.getOrchestratorPlugin(csp);
7573
orchestratorPlugin.auditApiRequest(
76-
getAuditLog(csp, joinPoint.getSignature().getName(), request.getMethod(),
74+
getAuditLog(csp, joinPoint.getSignature().getName(), request,
7775
joinPoint.getArgs(), result));
7876
}
7977
return result;
@@ -110,47 +108,40 @@ private Csp getCspFromMethodInfo(AuditApiRequest auditApiRequest, Object[] args)
110108
return csp;
111109
}
112110
} catch (Exception e) {
113-
log.error("Get csp with annotation @AuditApiRequest error.", e);
111+
log.error("Get csp with method {} error.", methodName, e);
114112
}
115113
return null;
116114
}
117115

118116
private Csp getCspFromRequestParams(Object[] args) {
119117
for (Object arg : args) {
120-
if (arg instanceof Ocl ocl) {
121-
return ocl.getCloudServiceProvider().getName();
122-
} else if (arg instanceof DeployRequest deployRequest) {
123-
return deployRequest.getCsp();
124-
} else if (arg instanceof MigrateRequest migrateRequest) {
125-
return migrateRequest.getCsp();
126-
} else if (arg instanceof CreateCredential createCredential) {
127-
return createCredential.getCsp();
128-
} else if (arg instanceof UserPolicyCreateRequest userPolicyCreateRequest) {
129-
return userPolicyCreateRequest.getCsp();
130-
} else if (arg instanceof UserPolicyUpdateRequest userPolicyUpdateRequest) {
131-
return userPolicyUpdateRequest.getCsp();
132-
} else if (arg instanceof ServicePolicyCreateRequest servicePolicyCreateRequest) {
133-
return getCspInfoFromRequest.getCspFromServiceTemplateId(
134-
servicePolicyCreateRequest.getServiceTemplateId().toString());
135-
} else if (arg instanceof Csp csp) {
136-
return csp;
137-
} else {
138-
return null;
139-
}
118+
return switch (arg) {
119+
case Ocl ocl -> ocl.getCloudServiceProvider().getName();
120+
case DeployRequest deployRequest -> deployRequest.getCsp();
121+
case MigrateRequest migrateRequest -> migrateRequest.getCsp();
122+
case CreateCredential createCredential -> createCredential.getCsp();
123+
case UserPolicyCreateRequest userPolicyCreateRequest ->
124+
userPolicyCreateRequest.getCsp();
125+
case UserPolicyUpdateRequest userPolicyUpdateRequest ->
126+
userPolicyUpdateRequest.getCsp();
127+
case ServicePolicyCreateRequest servicePolicyCreateRequest ->
128+
getCspInfoFromRequest.getCspFromServiceTemplateId(
129+
servicePolicyCreateRequest.getServiceTemplateId().toString());
130+
case Csp csp -> csp;
131+
case null, default -> null;
132+
};
140133
}
141134
return null;
142135
}
143136

144-
private AuditLog getAuditLog(Csp csp, String methodName, String methodType, Object[] args,
137+
private AuditLog getAuditLog(Csp csp, String methodName, HttpServletRequest request,
138+
Object[] args,
145139
Object result) {
146140
AuditLog auditLog = new AuditLog();
147141
auditLog.setMethodName(methodName);
148-
auditLog.setMethodType(methodType);
142+
auditLog.setMethodType(request.getMethod());
149143
auditLog.setParams(args);
150144
auditLog.setResult(result);
151-
ServletRequestAttributes attributes =
152-
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
153-
HttpServletRequest request = attributes.getRequest();
154145
auditLog.setUrl(String.valueOf(request.getRequestURL()));
155146
auditLog.setCsp(csp);
156147
auditLog.setOperatingTime(OffsetDateTime.now());

modules/api/src/main/java/org/eclipse/xpanse/api/config/GetCspInfoFromRequest.java

+15-13
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import org.eclipse.xpanse.modules.database.service.DeployServiceEntity;
2121
import org.eclipse.xpanse.modules.database.servicemigration.DatabaseServiceMigrationStorage;
2222
import org.eclipse.xpanse.modules.database.servicemigration.ServiceMigrationEntity;
23-
import org.eclipse.xpanse.modules.database.servicemodification.DatabaseServiceModificationAuditStorage;
24-
import org.eclipse.xpanse.modules.database.servicemodification.ServiceModificationAuditEntity;
23+
import org.eclipse.xpanse.modules.database.serviceorder.DatabaseServiceOrderStorage;
24+
import org.eclipse.xpanse.modules.database.serviceorder.ServiceOrderEntity;
2525
import org.eclipse.xpanse.modules.database.servicepolicy.DatabaseServicePolicyStorage;
2626
import org.eclipse.xpanse.modules.database.servicepolicy.ServicePolicyEntity;
2727
import org.eclipse.xpanse.modules.database.servicestatemanagement.DatabaseServiceStateManagementTaskStorage;
@@ -57,7 +57,7 @@ public class GetCspInfoFromRequest {
5757
@Resource
5858
private DatabaseServiceStateManagementTaskStorage managementTaskStorage;
5959
@Resource
60-
private DatabaseServiceModificationAuditStorage modificationAuditStorage;
60+
private DatabaseServiceOrderStorage serviceOrderTaskStorage;
6161

6262
/**
6363
* Get Csp with the URL of Ocl.
@@ -122,6 +122,9 @@ public Csp getCspFromServiceId(String id) {
122122
* @return csp.
123123
*/
124124
public Csp getCspFromServiceMigrationId(String id) {
125+
if (StringUtils.isBlank(id)) {
126+
return null;
127+
}
125128
try {
126129
ServiceMigrationEntity serviceMigrationEntity =
127130
serviceMigrationStorage.findServiceMigrationById(UUID.fromString(id));
@@ -132,7 +135,7 @@ public Csp getCspFromServiceMigrationId(String id) {
132135
return deployService.getCsp();
133136
}
134137
} catch (Exception e) {
135-
log.error("Get csp with service id:{} failed.", id, e);
138+
log.error("Get csp with service migration id:{} failed.", id, e);
136139
}
137140
return null;
138141
}
@@ -228,23 +231,22 @@ public Csp getCspFromManagementTaskId(String managementTaskId) {
228231

229232

230233
/**
231-
* Get Csp with id of service modification audit.
234+
* Get Csp with id of the service order.
232235
*
233-
* @param modificationAuditId id of service modification audit.
236+
* @param orderId id of the service order.
234237
* @return csp.
235238
*/
236-
public Csp getCspFromModificationAuditId(String modificationAuditId) {
239+
public Csp getCspFromServiceOrderId(String orderId) {
237240
try {
238-
ServiceModificationAuditEntity audit =
239-
modificationAuditStorage.getEntityById(UUID.fromString(modificationAuditId));
240-
if (Objects.nonNull(audit) && Objects.nonNull(audit.getServiceId())) {
241+
ServiceOrderEntity order =
242+
serviceOrderTaskStorage.getEntityById(UUID.fromString(orderId));
243+
if (Objects.nonNull(order) && Objects.nonNull(order.getServiceId())) {
241244
DeployServiceEntity deployService =
242-
deployServiceStorage.findDeployServiceById(audit.getServiceId());
245+
deployServiceStorage.findDeployServiceById(order.getServiceId());
243246
return deployService.getCsp();
244247
}
245248
} catch (Exception e) {
246-
log.error("Get csp with service modification audit id:{} failed.",
247-
modificationAuditId, e);
249+
log.error("Get csp with service order id:{} failed.", orderId, e);
248250
}
249251
return null;
250252
}

modules/api/src/main/java/org/eclipse/xpanse/api/config/ManagementTaskTypeEnumConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package org.eclipse.xpanse.api.config;
77

88
import lombok.NonNull;
9-
import org.eclipse.xpanse.modules.models.service.enums.ServiceStateManagementTaskType;
9+
import org.eclipse.xpanse.modules.models.service.statemanagement.enums.ServiceStateManagementTaskType;
1010
import org.springframework.core.convert.converter.Converter;
1111
import org.springframework.stereotype.Component;
1212

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* SPDX-FileCopyrightText: Huawei Inc.
4+
*/
5+
6+
package org.eclipse.xpanse.api.config;
7+
8+
import jakarta.annotation.Nonnull;
9+
import org.eclipse.xpanse.modules.models.service.order.enums.ServiceOrderType;
10+
import org.springframework.core.convert.converter.Converter;
11+
import org.springframework.stereotype.Component;
12+
13+
/**
14+
* Bean for serializing string in request parameters to ServiceOrderType enum.
15+
*/
16+
@Component
17+
public class ServiceOrderTypeEnumConverter implements Converter<String, ServiceOrderType> {
18+
19+
@Override
20+
public ServiceOrderType convert(@Nonnull String taskType) {
21+
return ServiceOrderType.getByValue(taskType);
22+
}
23+
}

modules/api/src/main/java/org/eclipse/xpanse/api/controllers/IsvServiceDeployApi.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class IsvServiceDeployApi {
5151
*
5252
* @return list of all services deployed by a user.
5353
*/
54-
@Tag(name = "Service", description = "APIs to manage the service instances")
54+
@Tag(name = "Service", description = "APIs to manage the services")
5555
@Operation(description = "List all deployed services by a user.")
5656
@GetMapping(value = "/services/isv",
5757
produces = MediaType.APPLICATION_JSON_VALUE)
@@ -68,25 +68,26 @@ public List<DeployedService> listDeployedServicesOfIsv(
6868
@RequestParam(name = "serviceVersion", required = false) String serviceVersion,
6969
@Parameter(name = "serviceState", description = "deployment state of the service")
7070
@RequestParam(name = "serviceState", required = false)
71-
ServiceDeploymentState serviceState) {
71+
ServiceDeploymentState serviceState) {
7272
return this.serviceDetailsViewManager.listDeployedServicesOfIsv(
7373
category, csp, serviceName, serviceVersion, serviceState);
7474
}
7575

7676
/**
77-
* Get details of the managed service by id for ISV role.
77+
* Get details of the managed service by serviceId for ISV role.
7878
*
7979
* @return Details of the managed service.
8080
*/
81-
@Tag(name = "Service", description = "APIs to manage the service instances")
82-
@Operation(description = "Get deployed service details by id.")
83-
@GetMapping(value = "/services/isv/details/vendor_hosted/{id}",
81+
@Tag(name = "Service", description = "APIs to manage the services")
82+
@Operation(description = "Get the details of the deployed service by service id.")
83+
@GetMapping(value = "/services/isv/details/vendor_hosted/{serviceId}",
8484
produces = MediaType.APPLICATION_JSON_VALUE)
8585
@ResponseStatus(HttpStatus.OK)
8686
@AuditApiRequest(methodName = "getCspFromServiceId")
8787
public DeployedServiceDetails getServiceDetailsByIdForIsv(
88-
@Parameter(name = "id", description = "Task id of deployed service")
89-
@PathVariable("id") String id) {
90-
return this.serviceDetailsViewManager.getServiceDetailsByIdForIsv(UUID.fromString(id));
88+
@Parameter(name = "serviceId", description = "Id of deployed service")
89+
@PathVariable("serviceId") String serviceId) {
90+
return this.serviceDetailsViewManager.getServiceDetailsByIdForIsv(
91+
UUID.fromString(serviceId));
9192
}
9293
}

0 commit comments

Comments
 (0)