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

create API method to get current configuration of the service #1979

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 @@ -20,6 +20,7 @@
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;
import org.eclipse.xpanse.modules.models.serviceconfiguration.ServiceConfigurationDetails;
import org.eclipse.xpanse.modules.models.serviceconfiguration.ServiceConfigurationUpdate;
import org.eclipse.xpanse.modules.models.serviceconfiguration.enums.ServiceConfigurationStatus;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
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 ServiceConfigurationDetails 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 @@ -13,6 +13,7 @@
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.servicemigration.ServiceMigrationEntity;
import org.eclipse.xpanse.modules.database.serviceorder.ServiceOrderEntity;
import org.eclipse.xpanse.modules.database.servicestatemanagement.ServiceStateManagementTaskEntity;
Expand All @@ -22,6 +23,7 @@
import org.eclipse.xpanse.modules.models.service.view.DeployedService;
import org.eclipse.xpanse.modules.models.service.view.DeployedServiceDetails;
import org.eclipse.xpanse.modules.models.service.view.VendorHostedDeployedServiceDetails;
import org.eclipse.xpanse.modules.models.serviceconfiguration.ServiceConfigurationDetails;
import org.eclipse.xpanse.modules.models.workflow.migrate.view.ServiceMigrationDetails;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -167,4 +169,17 @@ public static ServiceOrderDetails transToServiceOrderDetails(
return details;
}

/**
* ServiceConfigurationEntity converted to ServiceConfigurationDetails.
*
* @param entity ServiceConfigurationEntity
* @return ServiceConfigurationDetails
*/
public static ServiceConfigurationDetails
transToServiceConfigurationDetails(ServiceConfigurationEntity entity) {
ServiceConfigurationDetails details = new ServiceConfigurationDetails();
BeanUtils.copyProperties(entity, details);
details.setServiceId(entity.getId());
return details;
}
}
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 @@ -41,9 +43,11 @@
import org.eclipse.xpanse.modules.models.serviceconfiguration.AnsibleHostInfo;
import org.eclipse.xpanse.modules.models.serviceconfiguration.ServiceConfigurationChangeRequest;
import org.eclipse.xpanse.modules.models.serviceconfiguration.ServiceConfigurationChangeResult;
import org.eclipse.xpanse.modules.models.serviceconfiguration.ServiceConfigurationDetails;
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 +78,9 @@ public class ServiceConfigurationManager {
@Resource
private ServiceConfigurationUpdateStorage serviceConfigurationUpdateStorage;

@Resource
private ServiceConfigurationStorage serviceConfigurationStorage;

@Resource
private ServiceTemplateStorage serviceTemplateStorage;

Expand All @@ -94,6 +101,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 ServiceConfigurationDetails 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 EntityTransUtils.transToServiceConfigurationDetails(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,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

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

import java.time.OffsetDateTime;
import java.util.Map;
import java.util.UUID;
import lombok.Data;

/**
* Details of the service configuration.
*/
@Data
public class ServiceConfigurationDetails {
private UUID serviceId;
private Map<String, Object> configuration;
private OffsetDateTime createdTime;
private OffsetDateTime updatedTime;
}
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
Loading