1 package org.onap.vid.services;
4 import com.google.common.collect.ImmutableList;
5 import org.apache.commons.lang3.StringUtils;
6 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
7 import org.onap.vid.aai.AaiClientInterface;
8 import org.onap.vid.exceptions.GenericUncheckedException;
9 import org.onap.vid.exceptions.NotFoundException;
10 import org.onap.vid.mso.model.CloudConfiguration;
11 import org.onap.vid.mso.rest.RequestDetails;
12 import org.onap.vid.properties.Features;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.togglz.core.manager.FeatureManager;
16 import java.util.List;
19 public class CloudOwnerServiceImpl implements CloudOwnerService {
21 private static final List<String> CLOUD_CONFIGURATION_PATH = ImmutableList.of("requestDetails", "cloudConfiguration");
22 private static final List<String> LCP_CLOUD_REGION_ID_PATH = ImmutableList.of("requestDetails", "cloudConfiguration", "lcpCloudRegionId");
24 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(CloudOwnerService.class);
26 private final AaiClientInterface aaiClient;
27 private final FeatureManager featureManager;
30 public CloudOwnerServiceImpl(AaiClientInterface aaiClient, FeatureManager featureManager) {
31 this.aaiClient = aaiClient;
32 this.featureManager = featureManager;
36 public void enrichRequestWithCloudOwner(RequestDetails msoRequest) {
37 if (!featureManager.isActive(Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST)) {
42 //if cloudConfiguration field contains lcpRegion (e.g. in changeManagement scenarios)
43 if (msoRequest.getCloudConfiguration()!=null && StringUtils.isNotEmpty(msoRequest.getCloudConfiguration().getLcpCloudRegionId())) {
44 enrichCloudConfigurationWithCloudOwner(msoRequest.getCloudConfiguration(), msoRequest.getCloudConfiguration().getLcpCloudRegionId());
46 //otherwise the cloudConfiguration is in the additionalProperties field of RequestDetails (e.g. in ng1 view/edit scenario)
48 enrichRequestWithCloudOwnerByAdditionalProperties(msoRequest);
52 throw new GenericUncheckedException("Failed to enrich requestDetails with cloudOwner", e);
56 protected void enrichRequestWithCloudOwnerByAdditionalProperties(RequestDetails msoRequest) {
57 String lcpCloudRegionId = null;
59 lcpCloudRegionId = msoRequest.extractValueByPathUsingAdditionalProperties(LCP_CLOUD_REGION_ID_PATH, String.class);
61 catch (NotFoundException exception) {
62 LOGGER.debug("Can't find lcp region in RequestDetails. Assume no cloudOwner enrichment is needed. Reason: "+exception.getMessage());
65 String cloudOwner = aaiClient.getCloudOwnerByCloudRegionId(lcpCloudRegionId);
66 msoRequest.extractValueByPathUsingAdditionalProperties(CLOUD_CONFIGURATION_PATH, Map.class).put("cloudOwner", cloudOwner);
70 public void enrichCloudConfigurationWithCloudOwner(CloudConfiguration cloudConfiguration, String lcpCloudRegionId) {
71 if (featureManager.isActive(Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST)) {
72 String cloudOwner = aaiClient.getCloudOwnerByCloudRegionId(lcpCloudRegionId);
73 cloudConfiguration.setCloudOwner(cloudOwner);