Skip to content

Commit

Permalink
create API method to get current configuration of the service
Browse files Browse the repository at this point in the history
  • Loading branch information
WangLiNaruto committed Sep 26, 2024
1 parent 4c1709f commit 220936e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.api.config.AuditApiRequest;
import org.eclipse.xpanse.modules.database.serviceconfiguration.ServiceConfigurationEntity;
import org.eclipse.xpanse.modules.database.serviceconfiguration.update.ServiceConfigurationUpdateRequest;
import org.eclipse.xpanse.modules.deployment.ServiceConfigurationManager;
import org.eclipse.xpanse.modules.models.service.order.ServiceOrder;
Expand Down Expand Up @@ -51,6 +52,33 @@ public class ServiceConfigurationApi {
@Resource
private ServiceConfigurationManager serviceConfigurationManager;

/**
* Query the service's current configuration by id of the deployed service.
*
* @param serviceId id of the deployed service.
* @return ServiceConfigurationEntity.
*/
@Tag(name = "ServiceConfiguration",
description = "APIs for managing service's configuration.")
@GetMapping(value = "/service/current/config/{serviceId}",
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
@Operation(description = "Query the service's current configuration by"
+ " id of the deployed service.")
@AuditApiRequest(methodName = "getCspFromServiceId")
public ServiceConfigurationEntity getCurrentConfigurationOfService(
@Parameter(name = "serviceId", description = "The id of the deployed service")
@PathVariable("serviceId") String serviceId) {
return serviceConfigurationManager.getCurrentConfigurationOfService(serviceId);
}

/**
* Update the service's configuration to the registered service template.
*
* @param serviceId id of the deployed service
* @param serviceConfigurationUpdate serviceConfigurationUpdate.
* @return serviceOrder.
*/
@Tag(name = "ServiceConfiguration",
description = "APIs for managing service's configuration.")
@PutMapping(value = "/services/config/{serviceId}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.xpanse.modules.models.response.Response;
import org.eclipse.xpanse.modules.models.response.ResultType;
import org.eclipse.xpanse.modules.models.serviceconfiguration.exceptions.ServiceConfigurationInvalidException;
import org.eclipse.xpanse.modules.models.serviceconfiguration.exceptions.ServiceConfigurationNotFoundException;
import org.eclipse.xpanse.modules.models.serviceconfiguration.exceptions.ServiceConfigurationUpdateRequestNotFoundException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
Expand Down Expand Up @@ -54,4 +55,16 @@ public Response handleServiceConfigurationUpdateRequestNotFoundException(
return getErrorResponse(ResultType.SERVICE_CONFIG_UPDATE_REQUEST_NOT_FOUND,
Collections.singletonList(ex.getMessage()));
}

/**
* Exception handler for ServiceConfigurationNotFoundException.
*/
@ExceptionHandler({ServiceConfigurationNotFoundException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public Response handleServiceConfigurationNotFoundException(
ServiceConfigurationNotFoundException ex) {
return getErrorResponse(ResultType.SERVICE_CONFIGURATION_NOT_FOUND,
Collections.singletonList(ex.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ServiceConfigurationEntity {
@MapsId
@OneToOne
@JoinColumn(name = "service_id")
@JsonIgnoreProperties({"serviceConfigurationEntity"})
@JsonIgnoreProperties({"deployResourceList", "serviceConfigurationEntity"})
private DeployServiceEntity deployServiceEntity;

@Column(columnDefinition = "json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.modules.database.resource.DeployResourceEntity;
import org.eclipse.xpanse.modules.database.service.DeployServiceEntity;
import org.eclipse.xpanse.modules.database.serviceconfiguration.ServiceConfigurationEntity;
import org.eclipse.xpanse.modules.database.serviceconfiguration.ServiceConfigurationStorage;
import org.eclipse.xpanse.modules.database.serviceconfiguration.update.ServiceConfigurationUpdateRequest;
import org.eclipse.xpanse.modules.database.serviceconfiguration.update.ServiceConfigurationUpdateRequestQueryModel;
import org.eclipse.xpanse.modules.database.serviceconfiguration.update.ServiceConfigurationUpdateStorage;
Expand All @@ -44,6 +46,7 @@
import org.eclipse.xpanse.modules.models.serviceconfiguration.ServiceConfigurationUpdate;
import org.eclipse.xpanse.modules.models.serviceconfiguration.enums.ServiceConfigurationStatus;
import org.eclipse.xpanse.modules.models.serviceconfiguration.exceptions.ServiceConfigurationInvalidException;
import org.eclipse.xpanse.modules.models.serviceconfiguration.exceptions.ServiceConfigurationNotFoundException;
import org.eclipse.xpanse.modules.models.serviceconfiguration.exceptions.ServiceConfigurationUpdateRequestNotFoundException;
import org.eclipse.xpanse.modules.models.servicetemplate.ConfigManageScript;
import org.eclipse.xpanse.modules.models.servicetemplate.Ocl;
Expand Down Expand Up @@ -74,6 +77,9 @@ public class ServiceConfigurationManager {
@Resource
private ServiceConfigurationUpdateStorage serviceConfigurationUpdateStorage;

@Resource
private ServiceConfigurationStorage serviceConfigurationStorage;

@Resource
private ServiceTemplateStorage serviceTemplateStorage;

Expand All @@ -94,6 +100,24 @@ public class ServiceConfigurationManager {
private ServiceConfigurationVariablesJsonSchemaGenerator
serviceConfigurationVariablesJsonSchemaGenerator;

/**
* Query the service's current configuration by id of the deployed service.
*
* @param serviceId id of the deployed service
* @return ServiceConfigurationEntity.
*/
public ServiceConfigurationEntity getCurrentConfigurationOfService(String serviceId) {
ServiceConfigurationEntity entity = serviceConfigurationStorage
.findServiceConfigurationById(UUID.fromString(serviceId));
if (Objects.isNull(entity)) {
String errorMsg = String.format("Service Configuration with service id %s not found.",
serviceId);
log.error(errorMsg);
throw new ServiceConfigurationNotFoundException(errorMsg);
}
return entity;
}

/**
* update ServiceConfiguration.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public enum ResultType {
INVALID_GIT_REPO_DETAILS("Invalid Git Repo Details"),
FILE_LOCKED("File Locked"),
INVALID_SERVICE_CONFIGURATION("Service Configuration Invalid"),
SERVICE_CONFIG_UPDATE_REQUEST_NOT_FOUND("Service Configuration Update Request Not Found");
SERVICE_CONFIG_UPDATE_REQUEST_NOT_FOUND("Service Configuration Update Request Not Found"),
SERVICE_CONFIGURATION_NOT_FOUND("Service Configuration Not Found");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

package org.eclipse.xpanse.modules.models.serviceconfiguration.exceptions;

/**
* Exception thrown when service configuration not found.
*/
public class ServiceConfigurationNotFoundException extends RuntimeException {
public ServiceConfigurationNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
/**
* Exception thrown when service configuration update request not found.
*/

public class ServiceConfigurationUpdateRequestNotFoundException extends RuntimeException {

public class ServiceConfigurationUpdateRequestNotFoundException extends RuntimeException {
public ServiceConfigurationUpdateRequestNotFoundException(String message) {
super(message);
}
Expand Down

0 comments on commit 220936e

Please sign in to comment.