Skip to content

Commit

Permalink
Add Service to list availability zones with region of csp
Browse files Browse the repository at this point in the history
  • Loading branch information
baixinsui committed Mar 14, 2024
1 parent d5fca4e commit 76a0a92
Show file tree
Hide file tree
Showing 19 changed files with 363 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public static UserOrderableServiceVo convertToUserOrderableServiceVo(
serviceTemplateEntity.getOcl().getServiceHostingType());
userOrderableServiceVo.setServiceProviderContactDetails(
serviceTemplateEntity.getOcl().getServiceProviderContactDetails());
userOrderableServiceVo.setServiceAvailability(
serviceTemplateEntity.getOcl().getDeployment().getServiceAvailability());
return userOrderableServiceVo;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.List;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.xpanse.modules.models.common.enums.Csp;
import org.eclipse.xpanse.modules.models.service.deploy.enums.DeployResourceKind;
import org.eclipse.xpanse.modules.orchestrator.OrchestratorPlugin;
Expand Down Expand Up @@ -58,8 +57,8 @@ public class ExistingCloudResourcesApi {
@GetMapping(value = "/csp/resources/{deployResourceKind}",
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
@Operation(description = "List existing cloud resource types")
public List<String> getExistingResourcesOfType(
@Operation(description = "List existing cloud resource names with kind")
public List<String> getExistingResourceNamesWithKind(
@Parameter(name = "csp", description = "name of the cloud service provider")
@RequestParam(name = "csp") Csp csp,
@Parameter(name = "region", description = "name of he region")
Expand All @@ -68,12 +67,12 @@ public List<String> getExistingResourcesOfType(
@PathVariable("deployResourceKind") DeployResourceKind deployResourceKind) {

Optional<String> userIdOptional = identityProviderManager.getCurrentLoginUserId();
if (StringUtils.isEmpty(userIdOptional.get())) {
if (userIdOptional.isEmpty()) {
throw new AccessDeniedException(
"No permissions to view resources of services belonging to other users.");
}
OrchestratorPlugin orchestratorPlugin = pluginManager.getOrchestratorPlugin(csp);
return orchestratorPlugin.getExistingResourcesOfType(userIdOptional.get(), region,
return orchestratorPlugin.getExistingResourceNamesWithKind(userIdOptional.get(), region,
deployResourceKind);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
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.orchestrator.OrchestratorPlugin;
import org.eclipse.xpanse.modules.orchestrator.PluginManager;
import org.eclipse.xpanse.modules.orchestrator.deployment.DeployTask;
import org.eclipse.xpanse.modules.security.IdentityProviderManager;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -73,6 +75,9 @@ public class ServiceDeployerApi {
@Resource
private DeployServiceEntityHandler deployServiceEntityHandler;

@Resource
private PluginManager pluginManager;

/**
* Get details of the managed service by id.
*
Expand Down Expand Up @@ -243,4 +248,29 @@ public Response purge(@PathVariable("id") String id) {
return Response.successResponse(Collections.singletonList(successMsg));
}


/**
* Get details of the managed service by id.
*
* @return Details of the managed service.
*/
@Tag(name = "Service", description = "APIs to manage the service instances")
@Operation(description = "Get availability zones with csp and region.")
@GetMapping(value = "/csp/region/azs",
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public List<String> getAvailabilityZones(
@Parameter(name = "cspName", description = "name of the cloud service provider")
@RequestParam(name = "cspName") Csp csp,
@Parameter(name = "regionName", description = "name of the region")
@RequestParam(name = "regionName") String regionName) {
Optional<String> userIdOptional = identityProviderManager.getCurrentLoginUserId();
if (userIdOptional.isPresent()) {
OrchestratorPlugin orchestratorPlugin = pluginManager.getOrchestratorPlugin(csp);
return orchestratorPlugin.getAvailabilityZonesOfRegion(
userIdOptional.get(), regionName);
}
return Collections.emptyList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.java.Log;
Expand Down Expand Up @@ -34,12 +35,17 @@ public class DummyPluginImpl implements OrchestratorPlugin {

@Override
public Map<DeployerKind, DeployResourceHandler> resourceHandlers() {
return null;
return new HashMap<>();
}

@Override
public List<String> getExistingResourceNamesWithKind(String userId, String region,
DeployResourceKind kind) {
return new ArrayList<>();
}

@Override
public List<String> getExistingResourcesOfType(String userId, String region,
DeployResourceKind kind) {
public List<String> getAvailabilityZonesOfRegion(String userId, String region) {
return new ArrayList<>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,15 @@ public Map<DeployerKind, DeployResourceHandler> resourceHandlers() {
}

@Override
public List<String> getExistingResourcesOfType(String userId, String region,
DeployResourceKind kind) {
public List<String> getExistingResourceNamesWithKind(String userId, String region,
DeployResourceKind kind) {
return new ArrayList<>();
}

@Override
public List<String> getAvailabilityZonesOfRegion(String userId, String region) {
return new ArrayList<>();
}
@Override
public List<Metric> getMetricsForResource(
ResourceMetricsRequest resourceMetricRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import lombok.EqualsAndHashCode;
import org.eclipse.xpanse.modules.models.common.enums.Category;
import org.eclipse.xpanse.modules.models.common.enums.Csp;
import org.eclipse.xpanse.modules.models.servicetemplate.AvailabilityZoneConfig;
import org.eclipse.xpanse.modules.models.servicetemplate.Billing;
import org.eclipse.xpanse.modules.models.servicetemplate.DeployVariable;
import org.eclipse.xpanse.modules.models.servicetemplate.FlavorBasic;
Expand Down Expand Up @@ -90,4 +91,6 @@ public class UserOrderableServiceVo extends RepresentationModel<UserOrderableSer
@Schema(description = "The contact details of the service provider.")
private ServiceProviderContactDetails serviceProviderContactDetails;

@Schema(description = "The list of availability zones of the service.")
private List<AvailabilityZoneConfig> serviceAvailability;
}

0 comments on commit 76a0a92

Please sign in to comment.