diff options
author | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2017-08-08 02:54:59 -0700 |
---|---|---|
committer | Sébastien Determe <sd378r@intl.att.com> | 2017-08-08 12:33:20 +0000 |
commit | 08673dc040d7483e159a6e705993690538d7b117 (patch) | |
tree | 1132245edd9d032db925b44892177adad4df052c /src/main | |
parent | 8fab8020f0bb45c8bf048c929fba13db638b9fc1 (diff) |
Rework SDC calls and model
Rework the SDC model and queries
+ Add unit tests with JSON to validate the SDC model
Change-Id: I93f08cdc883f5357e3a08e9c246ed30be50a3492
Issue-Id: CLAMP-1
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/main')
8 files changed, 1277 insertions, 388 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java b/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java index 58bba3c9..a009f06f 100644 --- a/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java +++ b/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java @@ -5,16 +5,16 @@ * Copyright (C) 2017 AT&T Intellectual Property. All rights * reserved. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ * =================================================================== @@ -23,41 +23,66 @@ package org.onap.clamp.clds.client; +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVRecord; +import org.apache.commons.lang3.StringUtils; +import org.onap.clamp.clds.client.req.SdcReq; +import org.onap.clamp.clds.model.CldsAlarmCondition; +import org.onap.clamp.clds.model.CldsDBServiceCache; +import org.onap.clamp.clds.model.CldsSdcArtifact; +import org.onap.clamp.clds.model.CldsSdcResource; +import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo; +import org.onap.clamp.clds.model.CldsSdcServiceDetail; +import org.onap.clamp.clds.model.CldsSdcServiceInfo; +import org.onap.clamp.clds.model.CldsServiceData; +import org.onap.clamp.clds.model.CldsVfData; +import org.onap.clamp.clds.model.CldsVfKPIData; +import org.onap.clamp.clds.model.CldsVfcData; +import org.onap.clamp.clds.model.prop.ModelProperties; +import org.onap.clamp.clds.model.refprop.RefProp; +import org.onap.clamp.clds.util.LoggingUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.TextNode; -import org.onap.clamp.clds.client.req.SdcReq; -import org.onap.clamp.clds.model.*; -import org.onap.clamp.clds.model.prop.ModelProperties; -import org.onap.clamp.clds.model.refprop.RefProp; -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVRecord; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; public class SdcCatalogServices { - private static final Logger logger = LoggerFactory.getLogger(SdcSendReqDelegate.class); + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcCatalogServices.class); + protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); + + private static final String RESOURCE_VF_TYPE = "VF"; + private static final String RESOURCE_VFC_TYPE = "VFC"; @Autowired - private RefProp refProp; + private RefProp refProp; - public String getAsdcServicesInformation(String uuid) throws Exception { - String baseUrl = refProp.getStringValue("asdc.serviceUrl"); - String basicAuth = SdcReq.getAsdcBasicAuth(refProp); + public String getSdcServicesInformation(String uuid) throws Exception { + Date startTime = new Date(); + String baseUrl = refProp.getStringValue("sdc.serviceUrl"); + String basicAuth = SdcReq.getSdcBasicAuth(refProp); try { String url = baseUrl; if (uuid != null) { @@ -67,7 +92,7 @@ public class SdcCatalogServices { HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection(); - conn.setRequestProperty("X-ONAP-InstanceID", "CLAMP-Tool"); + conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool"); conn.setRequestProperty("Authorization", basicAuth); conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); conn.setRequestMethod("GET"); @@ -77,113 +102,129 @@ public class SdcCatalogServices { logger.info(resp.toString()); return resp; } + // metrics log + LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName()); + } catch (Exception e) { - logger.error("not able to ger any service information from asdc for uuid:" + uuid); + LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName()); + LoggingUtils.setErrorContext("900", "Get sdc services error"); + logger.error("not able to get any service information from sdc for uuid:" + uuid); } + LoggingUtils.setTimeContext(startTime, new Date()); + LoggingUtils.setTargetContext("SDC", "Get Services"); + metricsLogger.info("Get sdc services information"); + return ""; } /** - * To remove duplicate serviceUUIDs from asdc services List + * To remove duplicate serviceUUIDs from sdc services List * - * @param rawCldsAsdcServiceList + * @param rawCldsSdcServiceList * @return */ - public List<CldsAsdcServiceInfo> removeDuplicateServices(List<CldsAsdcServiceInfo> rawCldsAsdcServiceList) { - List<CldsAsdcServiceInfo> cldsAsdcServiceInfoList = null; - if (rawCldsAsdcServiceList != null && rawCldsAsdcServiceList.size() > 0) { + public List<CldsSdcServiceInfo> removeDuplicateServices(List<CldsSdcServiceInfo> rawCldsSdcServiceList) { + List<CldsSdcServiceInfo> cldsSdcServiceInfoList = null; + if (rawCldsSdcServiceList != null && rawCldsSdcServiceList.size() > 0) { // sort list - Collections.sort(rawCldsAsdcServiceList); - // and then take only the services with the max version (last in the list with the same name) - cldsAsdcServiceInfoList = new ArrayList<>(); - for (int i = 1; i < rawCldsAsdcServiceList.size(); i++) { - // compare name with previous - if not equal, then keep the previous (it's the last with that name) - CldsAsdcServiceInfo prev = rawCldsAsdcServiceList.get(i - 1); - if (!rawCldsAsdcServiceList.get(i).getName().equals(prev.getName())) { - cldsAsdcServiceInfoList.add(prev); + Collections.sort(rawCldsSdcServiceList); + // and then take only the services with the max version (last in the + // list with the same name) + cldsSdcServiceInfoList = new ArrayList<>(); + for (int i = 1; i < rawCldsSdcServiceList.size(); i++) { + // compare name with previous - if not equal, then keep the + // previous (it's the last with that name) + CldsSdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1); + if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) { + cldsSdcServiceInfoList.add(prev); } } // add the last in the list - cldsAsdcServiceInfoList.add(rawCldsAsdcServiceList.get(rawCldsAsdcServiceList.size() - 1)); + cldsSdcServiceInfoList.add(rawCldsSdcServiceList.get(rawCldsSdcServiceList.size() - 1)); } - return cldsAsdcServiceInfoList; + return cldsSdcServiceInfoList; } /** - * To remove duplicate serviceUUIDs from asdc resources List + * To remove duplicate serviceUUIDs from sdc resources List * - * @param rawCldsAsdcResourceList + * @param rawCldsSdcResourceList * @return */ - public List<CldsAsdcResource> removeDuplicateAsdcResourceInstances(List<CldsAsdcResource> rawCldsAsdcResourceList) { - List<CldsAsdcResource> cldsAsdcResourceList = null; - if (rawCldsAsdcResourceList != null && rawCldsAsdcResourceList.size() > 0) { + public List<CldsSdcResource> removeDuplicateSdcResourceInstances(List<CldsSdcResource> rawCldsSdcResourceList) { + List<CldsSdcResource> cldsSdcResourceList = null; + if (rawCldsSdcResourceList != null && rawCldsSdcResourceList.size() > 0) { // sort list - Collections.sort(rawCldsAsdcResourceList); - // and then take only the resources with the max version (last in the list with the same name) - cldsAsdcResourceList = new ArrayList<>(); - for (int i = 1; i < rawCldsAsdcResourceList.size(); i++) { - // compare name with previous - if not equal, then keep the previous (it's the last with that name) - CldsAsdcResource prev = rawCldsAsdcResourceList.get(i - 1); - if (!rawCldsAsdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) { - cldsAsdcResourceList.add(prev); + Collections.sort(rawCldsSdcResourceList); + // and then take only the resources with the max version (last in + // the list with the same name) + cldsSdcResourceList = new ArrayList<>(); + for (int i = 1; i < rawCldsSdcResourceList.size(); i++) { + // compare name with previous - if not equal, then keep the + // previous (it's the last with that name) + CldsSdcResource prev = rawCldsSdcResourceList.get(i - 1); + if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) { + cldsSdcResourceList.add(prev); } } // add the last in the list - cldsAsdcResourceList.add(rawCldsAsdcResourceList.get(rawCldsAsdcResourceList.size() - 1)); + cldsSdcResourceList.add(rawCldsSdcResourceList.get(rawCldsSdcResourceList.size() - 1)); } - return cldsAsdcResourceList; + return cldsSdcResourceList; } - /** * To remove duplicate basic resources with same resourceUUIDs * - * @param rawCldsAsdcResourceListBasicList + * @param rawCldsSdcResourceListBasicList * @return */ - public List<CldsAsdcResourceBasicInfo> removeDuplicateAsdcResourceBasicInfo(List<CldsAsdcResourceBasicInfo> rawCldsAsdcResourceListBasicList) { - List<CldsAsdcResourceBasicInfo> cldsAsdcResourceBasicInfoList = null; - if (rawCldsAsdcResourceListBasicList != null && rawCldsAsdcResourceListBasicList.size() > 0) { + public List<CldsSdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo( + List<CldsSdcResourceBasicInfo> rawCldsSdcResourceListBasicList) { + List<CldsSdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null; + if (rawCldsSdcResourceListBasicList != null && rawCldsSdcResourceListBasicList.size() > 0) { // sort list - Collections.sort(rawCldsAsdcResourceListBasicList); - // and then take only the resources with the max version (last in the list with the same name) - cldsAsdcResourceBasicInfoList = new ArrayList<>(); - for (int i = 1; i < rawCldsAsdcResourceListBasicList.size(); i++) { - // compare name with previous - if not equal, then keep the previous (it's the last with that name) - CldsAsdcResourceBasicInfo prev = rawCldsAsdcResourceListBasicList.get(i - 1); - if (!rawCldsAsdcResourceListBasicList.get(i).getName().equals(prev.getName())) { - cldsAsdcResourceBasicInfoList.add(prev); + Collections.sort(rawCldsSdcResourceListBasicList); + // and then take only the resources with the max version (last in + // the list with the same name) + cldsSdcResourceBasicInfoList = new ArrayList<>(); + for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) { + // compare name with previous - if not equal, then keep the + // previous (it's the last with that name) + CldsSdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1); + if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) { + cldsSdcResourceBasicInfoList.add(prev); } } // add the last in the list - cldsAsdcResourceBasicInfoList.add(rawCldsAsdcResourceListBasicList.get(rawCldsAsdcResourceListBasicList.size() - 1)); + cldsSdcResourceBasicInfoList + .add(rawCldsSdcResourceListBasicList.get(rawCldsSdcResourceListBasicList.size() - 1)); } - return cldsAsdcResourceBasicInfoList; + return cldsSdcResourceBasicInfoList; } /** * To get ServiceUUID by using serviceInvariantUUID * - * @param invariantID + * @param invariantId * @return * @throws Exception */ - public String getServiceUUIDFromServiceInvariantID(String invariantID) throws Exception { - String serviceUUID = ""; - String responseStr = getAsdcServicesInformation(null); - List<CldsAsdcServiceInfo> rawCldsAsdcServicesList = getCldsAsdcServicesListFromJson(responseStr); - List<CldsAsdcServiceInfo> cldsAsdcServicesList = removeDuplicateServices(rawCldsAsdcServicesList); - if (cldsAsdcServicesList != null && cldsAsdcServicesList.size() > 0) { - for (CldsAsdcServiceInfo currCldsAsdcServiceInfo : cldsAsdcServicesList) { - if (currCldsAsdcServiceInfo != null && currCldsAsdcServiceInfo.getInvariantUUID() != null - && currCldsAsdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantID)) { - serviceUUID = currCldsAsdcServiceInfo.getUuid(); + public String getServiceUuidFromServiceInvariantId(String invariantId) throws Exception { + String serviceUuid = ""; + String responseStr = getSdcServicesInformation(null); + List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr); + List<CldsSdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList); + if (cldsSdcServicesList != null && cldsSdcServicesList.size() > 0) { + for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) { + if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null + && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) { + serviceUuid = currCldsSdcServiceInfo.getUuid(); break; } } } - return serviceUUID; + return serviceUuid; } /** @@ -195,16 +236,17 @@ public class SdcCatalogServices { * @throws JsonMappingException * @throws IOException */ - public List<CldsAsdcServiceInfo> getCldsAsdcServicesListFromJson(String jsonStr) throws IOException { + public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); if (StringUtils.isBlank(jsonStr)) { return null; } - return objectMapper.readValue(jsonStr, objectMapper.getTypeFactory().constructCollectionType(List.class, CldsAsdcServiceInfo.class)); + return objectMapper.readValue(jsonStr, + objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class)); } /** - * To get List<CldsAsdcResourceBasicInfo> class by parsing json string + * To get List<CldsSdcResourceBasicInfo> class by parsing json string * * @param jsonStr * @return @@ -212,12 +254,13 @@ public class SdcCatalogServices { * @throws JsonMappingException * @throws IOException */ - public List<CldsAsdcResourceBasicInfo> getAllAsdcResourcesListFromJson(String jsonStr) throws IOException { + public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); if (StringUtils.isBlank(jsonStr)) { return null; } - return objectMapper.readValue(jsonStr, objectMapper.getTypeFactory().constructCollectionType(List.class, CldsAsdcResourceBasicInfo.class)); + return objectMapper.readValue(jsonStr, + objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class)); } /** @@ -229,13 +272,13 @@ public class SdcCatalogServices { * @throws JsonMappingException * @throws IOException */ - public CldsAsdcResource getCldsAsdcResourceFromJson(String jsonStr) throws IOException { + public CldsSdcResource getCldsSdcResourceFromJson(String jsonStr) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.readValue(jsonStr, CldsAsdcResource.class); + return objectMapper.readValue(jsonStr, CldsSdcResource.class); } /** - * To get CldsAsdcServiceDetail by parsing json string + * To get CldsSdcServiceDetail by parsing json string * * @param jsonStr * @return @@ -243,26 +286,32 @@ public class SdcCatalogServices { * @throws JsonMappingException * @throws IOException */ - public CldsAsdcServiceDetail getCldsAsdcServiceDetailFromJson(String jsonStr) throws IOException { + public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.readValue(jsonStr, CldsAsdcServiceDetail.class); + return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class); } /** - * To upload artifact to asdc based on serviceUUID and resourcename on url + * To upload artifact to sdc based on serviceUUID and resourcename on url + * * @param prop * @param userid * @param url - * @param formatttedAsdcReq + * @param formatttedSdcReq * @return * @throws Exception */ - public String uploadArtifactToAsdc(ModelProperties prop, String userid, String url, String formatttedAsdcReq) throws Exception { + public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatttedSdcReq) + throws Exception { + // Verify whether it is triggered by Validation Test button from UI + if (prop.isTest()) { + return "sdc artifact upload not executed for test action"; + } logger.info("userid=" + userid); - String md5Text = SdcReq.calculateMD5ByString(formatttedAsdcReq); - byte[] postData = SdcReq.stringToByteArray(formatttedAsdcReq); + String md5Text = SdcReq.calculateMD5ByString(formatttedSdcReq); + byte[] postData = SdcReq.stringToByteArray(formatttedSdcReq); int postDataLength = postData.length; - HttpURLConnection conn = getAsdcHttpUrlConnection(userid, postDataLength, url, md5Text); + HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text); try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) { wr.write(postData); } @@ -283,18 +332,19 @@ public class SdcCatalogServices { return responseStr; } - private HttpURLConnection getAsdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text) throws IOException { + private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text) + throws IOException { logger.info("userid=" + userid); - String basicAuth = SdcReq.getAsdcBasicAuth(refProp); - String asdcXONAPInstanceID = refProp.getStringValue("asdc.asdcX-ONAP-InstanceID"); + String basicAuth = SdcReq.getSdcBasicAuth(refProp); + String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID"); URL urlObj = new URL(url); HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection(); conn.setDoOutput(true); - conn.setRequestProperty("X-ONAP-InstanceID", asdcXONAPInstanceID); + conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), sdcXonapInstanceId); conn.setRequestProperty("Authorization", basicAuth); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-MD5", md5Text); - conn.setRequestProperty("HTTP_CSP_USERID", userid); + conn.setRequestProperty("USER_ID", userid); conn.setRequestMethod("POST"); conn.setRequestProperty("charset", "utf-8"); conn.setRequestProperty("Content-Length", Integer.toString(postDataLength)); @@ -326,8 +376,8 @@ public class SdcCatalogServices { return inStream; } - - public CldsDBServiceCache getCldsDBServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData) throws IOException { + public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData) + throws IOException { CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache(); cldsDbServiceCache.setCldsDataInstream(cldsServiceData); cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID()); @@ -335,14 +385,14 @@ public class SdcCatalogServices { return cldsDbServiceCache; } - public boolean isCldsAsdcCacheDataExpired(CldsServiceData cldsServiceData) throws Exception { + public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) throws Exception { boolean expired = false; if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) { - String cachedServiceUUID = cldsServiceData.getServiceUUID(); - String latestServiceUUID = getServiceUUIDFromServiceInvariantID(cldsServiceData.getServiceInvariantUUID()); + String cachedServiceUuid = cldsServiceData.getServiceUUID(); + String latestServiceUuid = getServiceUuidFromServiceInvariantId(cldsServiceData.getServiceInvariantUUID()); String defaultRecordAge = refProp.getStringValue("CLDS_SERVICE_CACHE_MAX_SECONDS"); - if ((!cachedServiceUUID.equalsIgnoreCase(latestServiceUUID)) || - (cldsServiceData.getAgeOfRecord() != null && cldsServiceData.getAgeOfRecord() > Long.parseLong(defaultRecordAge))) { + if ((!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null + && cldsServiceData.getAgeOfRecord() > Long.parseLong(defaultRecordAge))) { expired = true; } } else { @@ -351,29 +401,32 @@ public class SdcCatalogServices { return expired; } - public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUUID) throws Exception { - String url = refProp.getStringValue("asdc.serviceUrl"); - String catalogUrl = refProp.getStringValue("asdc.catalog.url"); - String serviceUUID = getServiceUUIDFromServiceInvariantID(invariantServiceUUID); - String serviceDetailUrl = url + "/" + serviceUUID + "/metadata"; + public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid) throws Exception { + String url = refProp.getStringValue("sdc.serviceUrl"); + String catalogUrl = refProp.getStringValue("sdc.catalog.url"); + String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid); + String serviceDetailUrl = url + "/" + serviceUuid + "/metadata"; String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl, false); ObjectMapper objectMapper = new ObjectMapper(); CldsServiceData cldsServiceData = new CldsServiceData(); if (responseStr != null) { - CldsAsdcServiceDetail cldsAsdcServiceDetail = objectMapper.readValue(responseStr, CldsAsdcServiceDetail.class); - cldsServiceData.setServiceUUID(cldsAsdcServiceDetail.getUuid()); - cldsServiceData.setServiceInvariantUUID(cldsAsdcServiceDetail.getInvariantUUID()); - - // To remove duplicate resources from serviceDetail and add valid vfs to service - if (cldsAsdcServiceDetail != null && cldsAsdcServiceDetail.getResources() != null) { - List<CldsAsdcResource> cldsAsdcResourceList = removeDuplicateAsdcResourceInstances(cldsAsdcServiceDetail.getResources()); - if (cldsAsdcResourceList != null && cldsAsdcResourceList.size() > 0) { + CldsSdcServiceDetail cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class); + cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid()); + cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID()); + + // To remove duplicate resources from serviceDetail and add valid + // vfs to service + if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) { + List<CldsSdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances( + cldsSdcServiceDetail.getResources()); + if (cldsSdcResourceList != null && cldsSdcResourceList.size() > 0) { List<CldsVfData> cldsVfDataList = new ArrayList<>(); - for (CldsAsdcResource currCldsAsdcResource : cldsAsdcResourceList) { - if (currCldsAsdcResource != null && currCldsAsdcResource.getResoucreType() != null && currCldsAsdcResource.getResoucreType().equalsIgnoreCase("VF")) { + for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) { + if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null + && currCldsSdcResource.getResoucreType().equalsIgnoreCase("VF")) { CldsVfData currCldsVfData = new CldsVfData(); - currCldsVfData.setVfName(currCldsAsdcResource.getResourceInstanceName()); - currCldsVfData.setVfInvariantResourceUUID(currCldsAsdcResource.getResourceInvariantUUID()); + currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName()); + currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID()); cldsVfDataList.add(currCldsVfData); } } @@ -395,35 +448,47 @@ public class SdcCatalogServices { private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) throws IOException { // todo : refact this.. if (cldsVfDataList != null && cldsVfDataList.size() > 0) { - List<CldsAsdcResourceBasicInfo> allAsdcResources = getAllAsdcResources(); - String resourceVFType = "VF"; - List<CldsAsdcResourceBasicInfo> allVfResources = getAllAsdcVForVFCResourcesBasedOnResourceType(resourceVFType, allAsdcResources); - String resourceVFCType = "VFC"; - List<CldsAsdcResourceBasicInfo> allVfcResources = getAllAsdcVForVFCResourcesBasedOnResourceType(resourceVFCType, allAsdcResources); + List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVFCResourcesBasedOnResourceType( + RESOURCE_VF_TYPE); + List<CldsSdcResourceBasicInfo> allVfcResources = getAllSdcVForVFCResourcesBasedOnResourceType( + RESOURCE_VFC_TYPE); for (CldsVfData currCldsVfData : cldsVfDataList) { if (currCldsVfData != null && currCldsVfData.getVfInvariantResourceUUID() != null) { - String resourceUUID = getResourceUUIDFromResourceInvariantUUID(currCldsVfData.getVfInvariantResourceUUID(), allVfResources); - if (resourceUUID != null) { - String vfResourceUUIDUrl = catalogUrl + "resources" + "/" + resourceUUID + "/metadata"; - String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUUIDUrl, false); + String resourceUuid = getResourceUuidFromResourceInvariantUuid( + currCldsVfData.getVfInvariantResourceUUID(), allVfResources); + if (resourceUuid != null) { + String vfResourceUuidUrl = catalogUrl + "resources" + "/" + resourceUuid + "/metadata"; + String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUuidUrl, false); if (vfResponse != null) { - List<CldsVfcData> vfcDataListFromVfResponse = getVFCDataListFromVfResponse(vfResponse); + // Below 2 line are to get the KPI(field path) data + // associated with the VF's + List<CldsVfKPIData> cldsVfKPIDataList = getFieldPathFromVF(vfResponse); + currCldsVfData.setCldsKPIList(cldsVfKPIDataList); + + List<CldsVfcData> vfcDataListFromVfResponse = getVfcDataListFromVfResponse(vfResponse); if (vfcDataListFromVfResponse != null) { currCldsVfData.setCldsVfcs(vfcDataListFromVfResponse); if (vfcDataListFromVfResponse.size() > 0) { - // To get artifacts for every VFC and get alarm conditions from artifact + // To get artifacts for every VFC and get + // alarm conditions from artifact for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) { - if (currCldsVfcData != null && currCldsVfcData.getVfcInvariantResourceUUID() != null) { - String resourceVFCUUID = getResourceUUIDFromResourceInvariantUUID(currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources); - if (resourceVFCUUID != null) { - String vfcResourceUUIDUrl = catalogUrl + "resources" + "/" + resourceVFCUUID + "/metadata"; - String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl, false); + if (currCldsVfcData != null + && currCldsVfcData.getVfcInvariantResourceUUID() != null) { + String resourceVfcUuid = getResourceUuidFromResourceInvariantUuid( + currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources); + if (resourceVfcUuid != null) { + String vfcResourceUuidUrl = catalogUrl + "resources" + "/" + + resourceVfcUuid + "/metadata"; + String vfcResponse = getCldsServicesOrResourcesBasedOnURL( + vfcResourceUuidUrl, false); if (vfcResponse != null) { - List<CldsAlarmCondition> alarmCondtionsFromVfc = getAlarmCondtionsFromVfc(vfcResponse); + List<CldsAlarmCondition> alarmCondtionsFromVfc = getAlarmCondtionsFromVfc( + vfcResponse); currCldsVfcData.setCldsAlarmConditions(alarmCondtionsFromVfc); } } else { - logger.info("No resourceVFC UUID found for given invariantID:" + currCldsVfcData.getVfcInvariantResourceUUID()); + logger.info("No resourceVFC UUID found for given invariantID:" + + currCldsVfcData.getVfcInvariantResourceUUID()); } } } @@ -431,14 +496,15 @@ public class SdcCatalogServices { } } } else { - logger.info("No resourceUUID found for given invariantREsourceUUID:" + currCldsVfData.getVfInvariantResourceUUID()); + logger.info("No resourceUUID found for given invariantREsourceUUID:" + + currCldsVfData.getVfInvariantResourceUUID()); } } } } } - private List<CldsVfcData> getVFCDataListFromVfResponse(String vfResponse) throws IOException { + private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws IOException { ObjectMapper mapper = new ObjectMapper(); ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse); ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources"); @@ -450,9 +516,9 @@ public class SdcCatalogServices { TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType"); if (resourceTypeNode != null && resourceTypeNode.textValue().equalsIgnoreCase("VFC")) { TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName"); - TextNode vfcInvariantResourceUUID = (TextNode) currVfcNode.get("resourceInvariantUUID"); + TextNode vfcInvariantResourceUuid = (TextNode) currVfcNode.get("resourceInvariantUUID"); currCldsVfcData.setVfcName(vfcResourceName.textValue()); - currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUUID.textValue()); + currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid.textValue()); cldsVfcDataList.add(currCldsVfcData); } } @@ -501,6 +567,75 @@ public class SdcCatalogServices { return cldsAlarmConditionList; } + // Method to get the artifact for any particular VF + private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws JsonProcessingException, IOException { + List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>(); + ObjectMapper mapper = new ObjectMapper(); + ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse); + ArrayNode artifactsArrayNode = (ArrayNode) vfResponseNode.get("artifacts"); + + if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) { + for (int index = 0; index < artifactsArrayNode.size(); index++) { + ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index); + TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL"); + TextNode artifactNameNode = (TextNode) currArtifactNode.get("artifactName"); + String artifactName = ""; + if (artifactNameNode != null) { + artifactName = artifactNameNode.textValue(); + artifactName = artifactName.substring(artifactName.lastIndexOf(".") + 1); + } + if (artifactUrlNode != null && artifactName != null && !artifactName.isEmpty() + && artifactName.equalsIgnoreCase("csv")) { + String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue()); + cldsVfKPIDataList.addAll(parseCsvToGetFieldPath(responsesFromArtifactUrl)); + logger.info(responsesFromArtifactUrl); + } + } + } + return cldsVfKPIDataList; + } + + private CldsVfKPIData convertCsvRecordToKpiData(CSVRecord record) { + if (record.size() < 6) { + logger.debug("invalid csv field path Record,total columns less than 6: " + record); + return null; + } + + if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3)) + || StringUtils.isBlank(record.get(5))) { + logger.debug("Invalid csv field path Record,one of column is having blank value : " + record); + return null; + } + + CldsVfKPIData cldsVfKPIData = new CldsVfKPIData(); + cldsVfKPIData.setNfNamingCode(record.get(0).trim()); + cldsVfKPIData.setNfNamingValue(record.get(1).trim()); + + cldsVfKPIData.setFieldPath(record.get(2).trim()); + cldsVfKPIData.setFieldPathValue(record.get(3).trim()); + + cldsVfKPIData.setThresholdName(record.get(4).trim()); + cldsVfKPIData.setThresholdValue(record.get(5).trim()); + return cldsVfKPIData; + + } + + // Method to get the artifactURL Data and set the CldsVfKPIData node + private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) throws IOException { + List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>(); + Reader alarmReader = new StringReader(allFieldPathValues); + Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader); + if (records != null) { + for (CSVRecord record : records) { + CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record); + if (kpiData != null) { + cldsVfKPIDataList.add(kpiData); + } + } + } + return cldsVfKPIDataList; + } + private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) { if (record == null) { return; @@ -509,7 +644,8 @@ public class SdcCatalogServices { logger.debug("invalid csv alarm Record,total columns less than 5: " + record); return; } - if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3)) || StringUtils.isBlank(record.get(4))) { + if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3)) + || StringUtils.isBlank(record.get(4))) { logger.debug("invalid csv alarm Record,one of column is having blank value : " + record); return; } @@ -520,8 +656,8 @@ public class SdcCatalogServices { cldsAlarmConditionList.add(cldsAlarmCondition); } - private String getResponsesFromArtifactUrl(String artifactsUrl) throws IOException { - String hostUrl = refProp.getStringValue("asdc.hostUrl"); + public String getResponsesFromArtifactUrl(String artifactsUrl) throws IOException { + String hostUrl = refProp.getStringValue("sdc.hostUrl"); artifactsUrl = artifactsUrl.replaceAll("\"", ""); String artifactUrl = hostUrl + artifactsUrl; logger.info("value of artifactURl:" + artifactUrl); @@ -531,22 +667,23 @@ public class SdcCatalogServices { } /** - * Service to services/resources/artifacts from asdc.Pass alarmConditions as true to get alarmconditons from artifact url and else it is false + * Service to services/resources/artifacts from sdc.Pass alarmConditions as + * true to get alarmconditons from artifact url and else it is false * * @param url * @param alarmConditions * @return * @throws IOException */ - private String getCldsServicesOrResourcesBasedOnURL(String url, boolean alarmConditions) throws IOException { + public String getCldsServicesOrResourcesBasedOnURL(String url, boolean alarmConditions) { String responseStr; try { url = removeUnwantedBracesFromString(url); URL urlObj = new URL(url); HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection(); - String basicAuth = SdcReq.getAsdcBasicAuth(refProp); - conn.setRequestProperty("X-ONAP-InstanceID", "CLAMP-Tool"); + String basicAuth = SdcReq.getSdcBasicAuth(refProp); + conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool"); conn.setRequestProperty("Authorization", basicAuth); conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); conn.setRequestMethod("GET"); @@ -565,11 +702,12 @@ public class SdcCatalogServices { } responseStr = response.toString(); in.close(); + return responseStr; } catch (Exception e) { - logger.error("Exception occured :" + e.getMessage()); - throw e; + logger.error("Exception occurred :", e); + return ""; } - return responseStr; + } /** @@ -586,40 +724,42 @@ public class SdcCatalogServices { ObjectNode globalPropsJson; if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) { - /** - * Objectnode to save all byservice, byvf , byvfc and byalarm nodes - */ + // Objectnode to save all byservice, byvf , byvfc and byalarm nodes ObjectNode byIdObjectNode = mapper.createObjectNode(); - /** - * To create vf ResourceUUID node with serviceInvariantUUID - * - */ - ObjectNode invariantUUIDObjectNodeWithVF = createVFObjectNodeByServiceInvariantUUID(mapper, cldsServiceData); - byIdObjectNode.putPOJO("byService", invariantUUIDObjectNodeWithVF); - /** - * To create byVf and vfcResourceNode with vfResourceUUID - */ - ObjectNode vfcObjectNodeByVfUUID = createVFCObjectNodeByVfUUID(mapper, cldsServiceData.getCldsVfs()); - byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUUID); + // To create vf ResourceUUID node with serviceInvariantUUID + ObjectNode invariantUuidObjectNodeWithVF = createVFObjectNodeByServiceInvariantUUID(mapper, + cldsServiceData); + byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVF); + // To create byVf and vfcResourceNode with vfResourceUUID + ObjectNode vfcObjectNodeByVfUuid = createVFCObjectNodeByVfUuid(mapper, cldsServiceData.getCldsVfs()); + byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid); - /** - * To create byVfc and alarmCondition with vfcResourceUUID - */ - ObjectNode vfcResourceUUIDObjectNode = mapper.createObjectNode(); + // To create byKpi + ObjectNode kpiObjectNode = mapper.createObjectNode(); if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) { for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) { if (currCldsVfData != null) { - createAlarmCondObjectNodeByVfcUUID(mapper, vfcResourceUUIDObjectNode, currCldsVfData.getCldsVfcs()); + createKPIObjectNodeByVfUUID(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList()); } } } - byIdObjectNode.putPOJO("byVfc", vfcResourceUUIDObjectNode); + byIdObjectNode.putPOJO("byKpi", kpiObjectNode); - /** - * To create byAlarmCondition with alarmConditionKey - */ + // To create byVfc and alarmCondition with vfcResourceUUID + ObjectNode vfcResourceUuidObjectNode = mapper.createObjectNode(); + if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) { + for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) { + if (currCldsVfData != null) { + createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode, + currCldsVfData.getCldsVfcs()); + } + } + } + byIdObjectNode.putPOJO("byVfc", vfcResourceUuidObjectNode); + + // To create byAlarmCondition with alarmConditionKey List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData); ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(mapper, allAlarmConditions); @@ -631,7 +771,7 @@ public class SdcCatalogServices { logger.info("valuie of objNode:" + globalPropsJson); } else { /** - * to create json with total properties when no serviceUUID passed + * to create json with total properties when no serviceUUID passed */ globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class); } @@ -639,13 +779,16 @@ public class SdcCatalogServices { return totalPropsStr; } - private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsServiceData(CldsServiceData cldsServiceData) { + public List<CldsAlarmCondition> getAllAlarmConditionsFromCldsServiceData(CldsServiceData cldsServiceData) { List<CldsAlarmCondition> alarmCondList = new ArrayList<>(); - if (cldsServiceData != null && cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) { + if (cldsServiceData != null && cldsServiceData.getCldsVfs() != null + && cldsServiceData.getCldsVfs().size() > 0) { for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) { - if (currCldsVfData != null && currCldsVfData.getCldsVfcs() != null && currCldsVfData.getCldsVfcs().size() > 0) { + if (currCldsVfData != null && currCldsVfData.getCldsVfcs() != null + && currCldsVfData.getCldsVfcs().size() > 0) { for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) { - if (currCldsVfcData != null && currCldsVfcData.getCldsAlarmConditions() != null && currCldsVfcData.getCldsAlarmConditions().size() > 0) { + if (currCldsVfcData != null && currCldsVfcData.getCldsAlarmConditions() != null + && currCldsVfcData.getCldsAlarmConditions().size() > 0) { for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) { if (currCldsAlarmCondition != null) { alarmCondList.add(currCldsAlarmCondition); @@ -659,7 +802,8 @@ public class SdcCatalogServices { return alarmCondList; } - private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper, List<CldsAlarmCondition> cldsAlarmCondList) { + private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper, + List<CldsAlarmCondition> cldsAlarmCondList) { ObjectNode alarmCondKeyNode = mapper.createObjectNode(); if (cldsAlarmCondList != null && cldsAlarmCondList.size() > 0) { @@ -681,39 +825,66 @@ public class SdcCatalogServices { } private ObjectNode createVFObjectNodeByServiceInvariantUUID(ObjectMapper mapper, CldsServiceData cldsServiceData) { - ObjectNode invariantUUIDObjectNode = mapper.createObjectNode(); + ObjectNode invariantUuidObjectNode = mapper.createObjectNode(); ObjectNode vfObjectNode = mapper.createObjectNode(); - ObjectNode vfUUIDNode = mapper.createObjectNode(); + ObjectNode vfUuidNode = mapper.createObjectNode(); List<CldsVfData> cldsVfsList = cldsServiceData.getCldsVfs(); if (cldsVfsList != null && cldsVfsList.size() > 0) { for (CldsVfData currCldsVfData : cldsVfsList) { if (currCldsVfData != null) { - vfUUIDNode.put(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName()); + vfUuidNode.put(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName()); } } } else { - vfUUIDNode.put("", ""); + vfUuidNode.put("", ""); } - vfObjectNode.putPOJO("vf", vfUUIDNode); - invariantUUIDObjectNode.putPOJO(cldsServiceData.getServiceInvariantUUID(), vfObjectNode); - return invariantUUIDObjectNode; + vfObjectNode.putPOJO("vf", vfUuidNode); + invariantUuidObjectNode.putPOJO(cldsServiceData.getServiceInvariantUUID(), vfObjectNode); + return invariantUuidObjectNode; } - private void createAlarmCondObjectNodeByVfcUUID(ObjectMapper mapper, ObjectNode vfcResourceUUIDObjectNode, List<CldsVfcData> cldsVfcDataList) { + private void createKPIObjectNodeByVfUUID(ObjectMapper mapper, ObjectNode vfResourceUUIDObjectNode, + List<CldsVfKPIData> cldsVfKPIDataList) { + if (cldsVfKPIDataList != null && cldsVfKPIDataList.size() > 0) { + for (CldsVfKPIData currCldsVfKPIData : cldsVfKPIDataList) { + if (currCldsVfKPIData != null) { + ObjectNode thresholdNameObjectNode = mapper.createObjectNode(); + + ObjectNode fieldPathObjectNode = mapper.createObjectNode(); + ObjectNode nfNamingCodeNode = mapper.createObjectNode(); + + fieldPathObjectNode.put(currCldsVfKPIData.getFieldPathValue(), + currCldsVfKPIData.getFieldPathValue()); + nfNamingCodeNode.put(currCldsVfKPIData.getNfNamingValue(), currCldsVfKPIData.getNfNamingValue()); + + thresholdNameObjectNode.putPOJO("fieldPath", fieldPathObjectNode); + thresholdNameObjectNode.putPOJO("nfNamingCode", nfNamingCodeNode); + + vfResourceUUIDObjectNode.putPOJO(currCldsVfKPIData.getThresholdValue(), thresholdNameObjectNode); + } + } + } + } + + private void createAlarmCondObjectNodeByVfcUuid(ObjectMapper mapper, ObjectNode vfcResourceUUIDObjectNode, + List<CldsVfcData> cldsVfcDataList) { ObjectNode alarmCondContsObjectNode = mapper.createObjectNode(); ObjectNode alarmCondNode = mapper.createObjectNode(); - // alarmCondNode.put("", ""); + // alarmCondNode.put("", ""); if (cldsVfcDataList != null && cldsVfcDataList.size() > 0) { for (CldsVfcData currCldsVfcData : cldsVfcDataList) { if (currCldsVfcData != null) { - if (currCldsVfcData.getCldsAlarmConditions() != null && currCldsVfcData.getCldsAlarmConditions().size() > 0) { + if (currCldsVfcData.getCldsAlarmConditions() != null + && currCldsVfcData.getCldsAlarmConditions().size() > 0) { for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) { - alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(), currCldsAlarmCondition.getAlarmConditionKey()); + alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(), + currCldsAlarmCondition.getAlarmConditionKey()); } alarmCondContsObjectNode.putPOJO("alarmCondition", alarmCondNode); } alarmCondContsObjectNode.putPOJO("alarmCondition", alarmCondNode); - vfcResourceUUIDObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(), alarmCondContsObjectNode); + vfcResourceUUIDObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(), + alarmCondContsObjectNode); } } } else { @@ -723,48 +894,51 @@ public class SdcCatalogServices { } } - private ObjectNode createVFCObjectNodeByVfUUID(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) { + private ObjectNode createVFCObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) { ObjectNode vfUUIDObjectNode = mapper.createObjectNode(); if (cldsVfDataList != null && cldsVfDataList.size() > 0) { for (CldsVfData currCldsVfData : cldsVfDataList) { if (currCldsVfData != null) { ObjectNode vfcObjectNode = mapper.createObjectNode(); - ObjectNode vfcUUIDNode = mapper.createObjectNode(); + ObjectNode vfcUuidNode = mapper.createObjectNode(); if (currCldsVfData.getCldsVfcs() != null && currCldsVfData.getCldsVfcs().size() > 0) { for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) { - vfcUUIDNode.put(currCldsVfcData.getVfcInvariantResourceUUID(), currCldsVfcData.getVfcName()); + vfcUuidNode.put(currCldsVfcData.getVfcInvariantResourceUUID(), + currCldsVfcData.getVfcName()); } } else { - vfcUUIDNode.put("", ""); + vfcUuidNode.put("", ""); } - vfcObjectNode.putPOJO("vfc", vfcUUIDNode); + vfcObjectNode.putPOJO("vfc", vfcUuidNode); vfUUIDObjectNode.putPOJO(currCldsVfData.getVfInvariantResourceUUID(), vfcObjectNode); } } } else { - ObjectNode vfcUUIDNode = mapper.createObjectNode(); - vfcUUIDNode.put("", ""); + ObjectNode vfcUuidNode = mapper.createObjectNode(); + vfcUuidNode.put("", ""); ObjectNode vfcObjectNode = mapper.createObjectNode(); - vfcObjectNode.putPOJO("vfc", vfcUUIDNode); + vfcObjectNode.putPOJO("vfc", vfcUuidNode); vfUUIDObjectNode.putPOJO("", vfcObjectNode); } return vfUUIDObjectNode; } - public String getArtifactIdIfArtifactAlreadyExists(CldsAsdcServiceDetail cldsAsdcServiceDetail, String artifactName) { - String artifactUUId = null; + public String getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail CldsSdcServiceDetail, String artifactName) { + String artifactUuid = null; boolean artifactxists = false; - if (cldsAsdcServiceDetail != null && cldsAsdcServiceDetail.getResources() != null && cldsAsdcServiceDetail.getResources().size() > 0) { - for (CldsAsdcResource currCldsAsdcResource : cldsAsdcServiceDetail.getResources()) { + if (CldsSdcServiceDetail != null && CldsSdcServiceDetail.getResources() != null + && CldsSdcServiceDetail.getResources().size() > 0) { + for (CldsSdcResource currCldsSdcResource : CldsSdcServiceDetail.getResources()) { if (artifactxists) { break; } - if (currCldsAsdcResource != null && currCldsAsdcResource.getArtifacts() != null && currCldsAsdcResource.getArtifacts().size() > 0) { - for (CldsAsdcArtifact currCldsAsdcArtifact : currCldsAsdcResource.getArtifacts()) { - if (currCldsAsdcArtifact != null && currCldsAsdcArtifact.getArtifactName() != null) { - if (currCldsAsdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) { - artifactUUId = currCldsAsdcArtifact.getArtifactUUID(); + if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null + && currCldsSdcResource.getArtifacts().size() > 0) { + for (CldsSdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) { + if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null) { + if (currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) { + artifactUuid = currCldsSdcArtifact.getArtifactUUID(); artifactxists = true; break; } @@ -773,27 +947,25 @@ public class SdcCatalogServices { } } } - return artifactUUId; + return artifactUuid; } - public String updateControlLoopStatusToDCAE(String dcaeUrl, String invariantResourceUUID, String invariantServiceUUID, String artifactName) { - String baseUrl = refProp.getStringValue("asdc.serviceUrl"); - String basicAuth = SdcReq.getAsdcBasicAuth(refProp); - String postStatusData = "{ \n" + - "\"event\" : \"" + "Created" + "\",\n" + - "\"serviceUUID\" : \"" + invariantServiceUUID + "\",\n" + - "\"resourceUUID\" :\"" + invariantResourceUUID + "\",\n" + - "\"artifactName\" : \"" + artifactName + "\",\n" + - "} \n"; + public String updateControlLoopStatusToDcae(String dcaeUrl, String invariantResourceUuid, + String invariantServiceUuid, String artifactName) { + String baseUrl = refProp.getStringValue("sdc.serviceUrl"); + String basicAuth = SdcReq.getSdcBasicAuth(refProp); + String postStatusData = "{ \n" + "\"event\" : \"" + "Created" + "\",\n" + "\"serviceUUID\" : \"" + + invariantServiceUuid + "\",\n" + "\"resourceUUID\" :\"" + invariantResourceUuid + "\",\n" + + "\"artifactName\" : \"" + artifactName + "\",\n" + "} \n"; try { String url = baseUrl; - if (invariantServiceUUID != null) { + if (invariantServiceUuid != null) { url = dcaeUrl + "/closed-loops"; } URL urlObj = new URL(url); HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection(); - conn.setRequestProperty("X-ONAP-InstanceID", "CLAMP-Tool"); + conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool"); conn.setRequestProperty("Authorization", basicAuth); conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); conn.setRequestMethod("POST"); @@ -811,54 +983,40 @@ public class SdcCatalogServices { return resp; } } catch (Exception e) { - logger.error("not able to ger any service information from asdc for uuid:" + invariantServiceUUID); + logger.error("not able to ger any service information from sdc for uuid:" + invariantServiceUuid); } return ""; } /** - * To get all asdc VF/VFC Resources basic info + * To get all sdc VF/VFC Resources basic info * * @return * @throws IOException */ - private List<CldsAsdcResourceBasicInfo> getAllAsdcVForVFCResourcesBasedOnResourceType(String resourceType, List<CldsAsdcResourceBasicInfo> allAsdcResources) throws IOException { - List<CldsAsdcResourceBasicInfo> allAsdcVFResources = new ArrayList<>(); - if (allAsdcResources != null && allAsdcResources.size() > 0) { - for (CldsAsdcResourceBasicInfo currResource : allAsdcResources) { - if (currResource != null && currResource.getResourceType() != null && currResource.getResourceType().equalsIgnoreCase(resourceType)) { - allAsdcVFResources.add(currResource); - } - } - } - return allAsdcVFResources; + private List<CldsSdcResourceBasicInfo> getAllSdcVForVFCResourcesBasedOnResourceType(String resourceType) + throws IOException { + List<CldsSdcResourceBasicInfo> allSdcResourceVFCBasicInfo = new ArrayList<CldsSdcResourceBasicInfo>(); + String catalogUrl = refProp.getStringValue("sdc.catalog.url"); + String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType; + String allSdcVFCResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl, false); + + allSdcResourceVFCBasicInfo = getAllSdcResourcesListFromJson(allSdcVFCResources); + return removeDuplicateSdcResourceBasicInfo(allSdcResourceVFCBasicInfo); } - private String getResourceUUIDFromResourceInvariantUUID(String resourceInvariantUUID, List<CldsAsdcResourceBasicInfo> resourceInfoList) throws IOException { - String resourceUUID = null; + private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUUID, + List<CldsSdcResourceBasicInfo> resourceInfoList) throws IOException { + String resourceUuid = null; if (resourceInfoList != null && resourceInfoList.size() > 0) { - for (CldsAsdcResourceBasicInfo currResource : resourceInfoList) { + for (CldsSdcResourceBasicInfo currResource : resourceInfoList) { if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUUID)) { - resourceUUID = currResource.getUuid(); + resourceUuid = currResource.getUuid(); break; } } } - return resourceUUID; - } - - /** - * To get all asdc Resources basic info - * - * @return - * @throws IOException - */ - private List<CldsAsdcResourceBasicInfo> getAllAsdcResources() throws IOException { - String catalogUrl = refProp.getStringValue("asdc.catalog.url"); - String resourceUrl = catalogUrl + "resources"; - String allAsdcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl, false); - List<CldsAsdcResourceBasicInfo> allAsdcResourceBasicInfo = getAllAsdcResourcesListFromJson(allAsdcResources); - return removeDuplicateAsdcResourceBasicInfo(allAsdcResourceBasicInfo); + return resourceUuid; } } diff --git a/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java b/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java index 93b6e954..47a4ddc8 100644 --- a/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java @@ -5,16 +5,16 @@ * Copyright (C) 2017 AT&T Intellectual Property. All rights * reserved. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ * =================================================================== @@ -23,67 +23,71 @@ package org.onap.clamp.clds.client; +import java.util.List; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.clamp.clds.client.req.SdcReq; -import org.onap.clamp.clds.model.CldsAsdcServiceDetail; +import org.onap.clamp.clds.model.CldsSdcServiceDetail; import org.onap.clamp.clds.model.DcaeEvent; import org.onap.clamp.clds.model.prop.Global; import org.onap.clamp.clds.model.prop.ModelProperties; import org.onap.clamp.clds.model.refprop.RefProp; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.engine.delegate.JavaDelegate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import java.util.List; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; /** * Send control loop model to dcae proxy. */ public class SdcSendReqDelegate implements JavaDelegate { - // currently uses the java.util.logging.Logger like the Camunda engine - private static final Logger logger = LoggerFactory.getLogger(SdcSendReqDelegate.class); + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcSendReqDelegate.class); + protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); @Autowired - private RefProp refProp; + private RefProp refProp; @Autowired - private SdcCatalogServices asdcCatalogServices; + private SdcCatalogServices sdcCatalogServices; - private String baseUrl; - private String artifactType; - private String locationArtifactType; - private String artifactLabel; - private String locationArtifactLabel; + private String baseUrl; + private String artifactType; + private String locationArtifactType; + private String artifactLabel; + private String locationArtifactLabel; /** - * Perform activity. Send to asdc proxy. + * Perform activity. Send to sdc proxy. * * @param execution */ + @Override public void execute(DelegateExecution execution) throws Exception { String userid = (String) execution.getVariable("userid"); logger.info("userid=" + userid); - String docText = (String) execution.getVariable("docText"); - String artifactName = execution.getVariable("controlName") + DcaeEvent.ARTIFACT_NAME_SUFFIX; + String docText = new String((byte[]) execution.getVariable("docText")); + String artifactName = (String) execution.getVariable("controlName") + DcaeEvent.ARTIFACT_NAME_SUFFIX; execution.setVariable("artifactName", artifactName); - getAsdcAttributes(); + getSdcAttributes((String) execution.getVariable("controlName")); ModelProperties prop = ModelProperties.create(execution); String bluprintPayload = SdcReq.formatBlueprint(refProp, prop, docText); - String formatttedAsdcReq = SdcReq.formatAsdcReq(bluprintPayload, artifactName, artifactLabel, artifactType); - if (formatttedAsdcReq != null) { - execution.setVariable("formattedArtifactReq", formatttedAsdcReq.getBytes()); + String formatttedSdcReq = SdcReq.formatSdcReq(bluprintPayload, artifactName, artifactLabel, artifactType); + if (formatttedSdcReq != null) { + execution.setVariable("formattedArtifactReq", formatttedSdcReq.getBytes()); } - List<String> asdcReqUrlsList = SdcReq.getAsdcReqUrlsList(prop, baseUrl, asdcCatalogServices, execution); + List<String> sdcReqUrlsList = SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, execution); - String asdcLocationsPayload = SdcReq.formatAsdcLocationsReq(prop, artifactName); - String locationArtifactName = execution.getVariable("controlName") + "-location.json"; - String formattedAsdcLocationReq = SdcReq.formatAsdcReq(asdcLocationsPayload, locationArtifactName, locationArtifactLabel, locationArtifactType); - if (formattedAsdcLocationReq != null) { - execution.setVariable("formattedLocationReq", formattedAsdcLocationReq.getBytes()); + String sdcLocationsPayload = SdcReq.formatSdcLocationsReq(prop, artifactName); + String locationArtifactName = (String) execution.getVariable("controlName") + "-location.json"; + String formattedSdcLocationReq = SdcReq.formatSdcReq(sdcLocationsPayload, locationArtifactName, + locationArtifactLabel, locationArtifactType); + if (formattedSdcLocationReq != null) { + execution.setVariable("formattedLocationReq", formattedSdcLocationReq.getBytes()); } String serviceInvariantUUID = getServiceInvariantUUIDFromProps(prop); - uploadToAsdc(prop, serviceInvariantUUID, userid, asdcReqUrlsList, formatttedAsdcReq, formattedAsdcLocationReq, artifactName, locationArtifactName); + uploadToSdc(prop, serviceInvariantUUID, userid, sdcReqUrlsList, formatttedSdcReq, formattedSdcLocationReq, + artifactName, locationArtifactName); } private String getServiceInvariantUUIDFromProps(ModelProperties props) { @@ -97,42 +101,53 @@ public class SdcSendReqDelegate implements JavaDelegate { return invariantUUID; } - private void uploadToAsdc(ModelProperties prop, String serviceInvariantUUID, String userid, List<String> asdcReqUrlsList, String formatttedAsdcReq, String formattedAsdcLocationReq, String artifactName, String locationArtifactName) throws Exception { + private void uploadToSdc(ModelProperties prop, String serviceInvariantUUID, String userid, + List<String> sdcReqUrlsList, String formatttedSdcReq, String formattedSdcLocationReq, String artifactName, + String locationArtifactName) throws Exception { logger.info("userid=" + userid); - if (asdcReqUrlsList != null && asdcReqUrlsList.size() > 0) { - for (String url : asdcReqUrlsList) { + if (sdcReqUrlsList != null && sdcReqUrlsList.size() > 0) { + for (String url : sdcReqUrlsList) { if (url != null) { - String originalServiceUUID = asdcCatalogServices.getServiceUUIDFromServiceInvariantID(serviceInvariantUUID); + String originalServiceUUID = sdcCatalogServices + .getServiceUuidFromServiceInvariantId(serviceInvariantUUID); logger.info("ServiceUUID used before upload in url:" + originalServiceUUID); - String asdcServicesInformation = asdcCatalogServices.getAsdcServicesInformation(originalServiceUUID); - CldsAsdcServiceDetail cldsAsdcServiceDetail = asdcCatalogServices.getCldsAsdcServiceDetailFromJson(asdcServicesInformation); - String uploadedArtifactUUID = asdcCatalogServices.getArtifactIdIfArtifactAlreadyExists(cldsAsdcServiceDetail, artifactName); - // Upload artifacts to asdc + String sdcServicesInformation = sdcCatalogServices.getSdcServicesInformation(originalServiceUUID); + CldsSdcServiceDetail CldsSdcServiceDetail = sdcCatalogServices + .getCldsSdcServiceDetailFromJson(sdcServicesInformation); + String uploadedArtifactUUID = sdcCatalogServices + .getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail, artifactName); + // Upload artifacts to sdc String updateUrl = uploadedArtifactUUID != null ? url + "/" + uploadedArtifactUUID : url; - String responseStr = asdcCatalogServices.uploadArtifactToAsdc(prop, userid, updateUrl, formatttedAsdcReq); - logger.info("value of asdc Response of uploading to asdc :" + responseStr); - String updatedServiceUUID = asdcCatalogServices.getServiceUUIDFromServiceInvariantID(serviceInvariantUUID); + String responseStr = sdcCatalogServices.uploadArtifactToSdc(prop, userid, updateUrl, + formatttedSdcReq); + logger.info("value of sdc Response of uploading to sdc :" + responseStr); + String updatedServiceUUID = sdcCatalogServices + .getServiceUuidFromServiceInvariantId(serviceInvariantUUID); if (!originalServiceUUID.equalsIgnoreCase(updatedServiceUUID)) { url = url.replace(originalServiceUUID, updatedServiceUUID); } logger.info("ServiceUUID used after upload in ulr:" + updatedServiceUUID); - asdcServicesInformation = asdcCatalogServices.getAsdcServicesInformation(updatedServiceUUID); - cldsAsdcServiceDetail = asdcCatalogServices.getCldsAsdcServiceDetailFromJson(asdcServicesInformation); - uploadedArtifactUUID = asdcCatalogServices.getArtifactIdIfArtifactAlreadyExists(cldsAsdcServiceDetail, locationArtifactName); - // To send location information also to asdc + sdcServicesInformation = sdcCatalogServices.getSdcServicesInformation(updatedServiceUUID); + CldsSdcServiceDetail = sdcCatalogServices.getCldsSdcServiceDetailFromJson(sdcServicesInformation); + uploadedArtifactUUID = sdcCatalogServices.getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail, + locationArtifactName); + // To send location information also to sdc updateUrl = uploadedArtifactUUID != null ? url + "/" + uploadedArtifactUUID : url; - responseStr = asdcCatalogServices.uploadArtifactToAsdc(prop, userid, updateUrl, formattedAsdcLocationReq); - logger.info("value of asdc Response of uploading location to asdc :" + responseStr); + responseStr = sdcCatalogServices.uploadArtifactToSdc(prop, userid, updateUrl, + formattedSdcLocationReq); + logger.info("value of sdc Response of uploading location to sdc :" + responseStr); } } } } - private void getAsdcAttributes() { - baseUrl = refProp.getStringValue("asdc.serviceUrl"); - artifactLabel = refProp.getStringValue("asdc.artifactLabel"); - locationArtifactLabel = refProp.getStringValue("asdc.locationArtifactLabel"); - artifactType = refProp.getStringValue("asdc.artifactType"); - locationArtifactType = refProp.getStringValue("asdc.locationArtifactType"); + private void getSdcAttributes(String controlName) { + baseUrl = refProp.getStringValue("sdc.serviceUrl"); + artifactLabel = SdcReq + .normalizeResourceInstanceName(refProp.getStringValue("sdc.artifactLabel") + "-" + controlName); + locationArtifactLabel = SdcReq + .normalizeResourceInstanceName(refProp.getStringValue("sdc.locationArtifactLabel") + "-" + controlName); + artifactType = refProp.getStringValue("sdc.artifactType"); + locationArtifactType = refProp.getStringValue("sdc.locationArtifactType"); } } diff --git a/src/main/java/org/onap/clamp/clds/client/req/SdcReq.java b/src/main/java/org/onap/clamp/clds/client/req/SdcReq.java index 45f17164..8a31a3b9 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/SdcReq.java +++ b/src/main/java/org/onap/clamp/clds/client/req/SdcReq.java @@ -5,16 +5,16 @@ * Copyright (C) 2017 AT&T Intellectual Property. All rights * reserved. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ * =================================================================== @@ -23,6 +23,28 @@ package org.onap.clamp.clds.client.req; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Base64; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.codec.digest.DigestUtils; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.clamp.clds.client.SdcCatalogServices; +import org.onap.clamp.clds.model.CldsSdcResource; +import org.onap.clamp.clds.model.CldsSdcServiceDetail; +import org.onap.clamp.clds.model.prop.Global; +import org.onap.clamp.clds.model.prop.ModelProperties; +import org.onap.clamp.clds.model.prop.StringMatch; +import org.onap.clamp.clds.model.prop.Tca; +import org.onap.clamp.clds.model.refprop.RefProp; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; @@ -31,29 +53,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; -import org.onap.clamp.clds.client.SdcCatalogServices; -import org.onap.clamp.clds.model.CldsAsdcResource; -import org.onap.clamp.clds.model.CldsAsdcServiceDetail; -import org.onap.clamp.clds.model.prop.Global; -import org.onap.clamp.clds.model.prop.ModelProperties; -import org.onap.clamp.clds.model.prop.StringMatch; -import org.onap.clamp.clds.model.prop.Tca; -import org.onap.clamp.clds.model.refprop.RefProp; -import org.apache.commons.codec.digest.DigestUtils; -import org.camunda.bpm.engine.delegate.DelegateExecution; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.Map.Entry; -import java.util.logging.Logger; /** - * Construct a Asdc request given CLDS objects. + * Construct a Sdc request given CLDS objects. */ public class SdcReq { - // currently uses the java.util.logging.Logger like the Camunda engine - private static final Logger logger = Logger.getLogger(SdcReq.class.getName()); + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcReq.class); + protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); /** * @param refProp @@ -72,14 +78,15 @@ public class SdcReq { String yamlvalue = getYamlvalue(docText); String updatedBlueprint = ""; - StringMatch stringMatch = prop.getStringMatch(); - Tca tca = prop.getTca(); + StringMatch stringMatch = prop.getType(StringMatch.class); + Tca tca = prop.getType(Tca.class); if (stringMatch.isFound()) { prop.setCurrentModelElementId(stringMatch.getId()); ObjectMapper objectMapper = new ObjectMapper(); ObjectNode serviceConfigurations = objectMapper.createObjectNode(); - StringMatchPolicyReq.appendServiceConfigurations(refProp, service, serviceConfigurations, stringMatch); + StringMatchPolicyReq.appendServiceConfigurations(refProp, service, serviceConfigurations, stringMatch, + prop); logger.info("Value of serviceConfigurations:" + serviceConfigurations); ObjectNode servConfNode = (ObjectNode) serviceConfigurations.get("serviceConfigurations"); @@ -111,15 +118,15 @@ public class SdcReq { // Serialiaze Yaml file Map<String, Map> loadedYaml = (Map<String, Map>) yaml.load(yamlValue); // Get node templates information from Yaml - Map<String, Map> nodeTemplates = (Map<String, Map>) loadedYaml.get("node_templates"); + Map<String, Map> nodeTemplates = loadedYaml.get("node_templates"); logger.info("value of NodeTemplates:" + nodeTemplates); // Get StringMatch Object information from node templates of Yaml - Map<String, Map> smObject = (Map<String, Map>) nodeTemplates.get("SM"); + Map<String, Map> smObject = nodeTemplates.get("SM"); logger.info("value of StringMatch:" + smObject); // Get Properties Object information from stringmatch of Yaml - Map<String, String> propsObject = (Map<String, String>) smObject.get("properties"); + Map<String, String> propsObject = smObject.get("properties"); logger.info("value of PropsObject:" + propsObject); String deploymentJsonObject = propsObject.get("deployment_JSON"); @@ -154,15 +161,15 @@ public class SdcReq { // Serialiaze Yaml file Map<String, Map> loadedYaml = (Map<String, Map>) yaml.load(yamlValue); // Get node templates information from Yaml - Map<String, Map> nodeTemplates = (Map<String, Map>) loadedYaml.get("node_templates"); + Map<String, Map> nodeTemplates = loadedYaml.get("node_templates"); logger.info("value of NodeTemplates:" + nodeTemplates); // Get Tca Object information from node templates of Yaml - Map<String, Map> tcaObject = (Map<String, Map>) nodeTemplates.get("MTCA"); + Map<String, Map> tcaObject = nodeTemplates.get("MTCA"); logger.info("value of Tca:" + tcaObject); // Get Properties Object information from tca of Yaml - Map<String, String> propsObject = (Map<String, String>) tcaObject.get("properties"); + Map<String, String> propsObject = tcaObject.get("properties"); logger.info("value of PropsObject:" + propsObject); - String deploymentJsonObject = (String) propsObject.get("deployment_JSON"); + String deploymentJsonObject = propsObject.get("deployment_JSON"); logger.info("value of deploymentJson:" + deploymentJsonObject); ObjectMapper mapper = new ObjectMapper(); @@ -182,7 +189,7 @@ public class SdcReq { return blueprint; } - public static String formatAsdcLocationsReq(ModelProperties prop, String artifactName) { + public static String formatSdcLocationsReq(ModelProperties prop, String artifactName) { ObjectMapper objectMapper = new ObjectMapper(); Global global = prop.getGlobal(); List<String> locationsList = global.getLocation(); @@ -198,7 +205,7 @@ public class SdcReq { return locationJsonFormat; } - public static String formatAsdcReq(String payloadData, String artifactName, String artifactLabel, + public static String formatSdcReq(String payloadData, String artifactName, String artifactLabel, String artifactType) throws IOException { logger.info("artifact=" + payloadData); String base64Artifact = base64Encode(payloadData); @@ -208,7 +215,7 @@ public class SdcReq { + "} \n"; } - public static String getAsdcReqUrl(ModelProperties prop, String url) { + public static String getSdcReqUrl(ModelProperties prop, String url) { Global globalProps = prop.getGlobal(); String serviceUUID = ""; String resourceInstanceName = ""; @@ -234,7 +241,7 @@ public class SdcReq { * @return * @throws Exception */ - public static List<String> getAsdcReqUrlsList(ModelProperties prop, String baseUrl, + public static List<String> getSdcReqUrlsList(ModelProperties prop, String baseUrl, SdcCatalogServices sdcCatalogServices, DelegateExecution execution) throws Exception { // TODO : refact and regroup with very similar code List<String> urlList = new ArrayList<>(); @@ -244,18 +251,21 @@ public class SdcReq { String serviceInvariantUUID = globalProps.getService(); execution.setVariable("serviceInvariantUUID", serviceInvariantUUID); List<String> resourceVfList = globalProps.getResourceVf(); - String serviceUUID = sdcCatalogServices.getServiceUUIDFromServiceInvariantID(serviceInvariantUUID); - String asdcServicesInformation = sdcCatalogServices.getAsdcServicesInformation(serviceUUID); - CldsAsdcServiceDetail cldsAsdcServiceDetail = sdcCatalogServices.getCldsAsdcServiceDetailFromJson(asdcServicesInformation); - if (cldsAsdcServiceDetail != null && resourceVfList != null) { - List<CldsAsdcResource> cldsAsdcResourcesList = cldsAsdcServiceDetail.getResources(); - if (cldsAsdcResourcesList != null && cldsAsdcResourcesList.size() > 0) { - for (CldsAsdcResource cldsAsdcResource : cldsAsdcResourcesList) { - if (cldsAsdcResource != null && cldsAsdcResource.getResoucreType() != null - && cldsAsdcResource.getResoucreType().equalsIgnoreCase("VF")) { - if (resourceVfList.contains(cldsAsdcResource.getResourceInvariantUUID())) { - String normalizedResourceInstanceName = normalizeResourceInstanceName(cldsAsdcResource.getResourceInstanceName()); - String svcUrl = baseUrl + "/" + serviceUUID + "/resourceInstances/" + normalizedResourceInstanceName + "/artifacts"; + String serviceUUID = sdcCatalogServices.getServiceUuidFromServiceInvariantId(serviceInvariantUUID); + String sdcServicesInformation = sdcCatalogServices.getSdcServicesInformation(serviceUUID); + CldsSdcServiceDetail CldsSdcServiceDetail = sdcCatalogServices + .getCldsSdcServiceDetailFromJson(sdcServicesInformation); + if (CldsSdcServiceDetail != null && resourceVfList != null) { + List<CldsSdcResource> CldsSdcResourcesList = CldsSdcServiceDetail.getResources(); + if (CldsSdcResourcesList != null && CldsSdcResourcesList.size() > 0) { + for (CldsSdcResource CldsSdcResource : CldsSdcResourcesList) { + if (CldsSdcResource != null && CldsSdcResource.getResoucreType() != null + && CldsSdcResource.getResoucreType().equalsIgnoreCase("VF")) { + if (resourceVfList.contains(CldsSdcResource.getResourceInvariantUUID())) { + String normalizedResourceInstanceName = normalizeResourceInstanceName( + CldsSdcResource.getResourceInstanceName()); + String svcUrl = baseUrl + "/" + serviceUUID + "/resourceInstances/" + + normalizedResourceInstanceName + "/artifacts"; urlList.add(svcUrl); } } @@ -269,8 +279,8 @@ public class SdcReq { /** * "Normalize" the resource instance name: - Remove spaces, underscores, - * dashes, and periods. - make lower case This is required by ASDC when - * using the resource instance name to upload an artifact. + * dashes, and periods. - make lower case This is required by SDC when using + * the resource instance name to upload an artifact. * * @param inText * @return @@ -323,15 +333,15 @@ public class SdcReq { } /** - * Return ASDC id and pw as a HTTP Basic Auth string (for example: Basic + * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic * dGVzdDoxMjM0NTY=). * * @return */ - public static String getAsdcBasicAuth(RefProp refProp) { - String asdcId = refProp.getStringValue("asdc.serviceUsername"); - String asdcPw = refProp.getStringValue("asdc.servicePassword"); - String idPw = base64Encode(asdcId + ":" + asdcPw); + public static String getSdcBasicAuth(RefProp refProp) { + String sdcId = refProp.getStringValue("sdc.serviceUsername"); + String sdcPw = refProp.getStringValue("sdc.servicePassword"); + String idPw = base64Encode(sdcId + ":" + sdcPw); return "Basic " + idPw; } diff --git a/src/main/java/org/onap/clamp/clds/model/CldsSdcArtifact.java b/src/main/java/org/onap/clamp/clds/model/CldsSdcArtifact.java new file mode 100644 index 00000000..48f90170 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/CldsSdcArtifact.java @@ -0,0 +1,112 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class CldsSdcArtifact { + + private String artifactName; + private String artifactType; + private String artifactUrl; + private String artifactDescription; + private String artifactTimeout; + private String artifactChecksum; + private String artifactUuid; + private String artifactVersion; + private String generatedFromUuid; + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactURL() { + return artifactUrl; + } + + public void setArtifactURL(String artifactURL) { + this.artifactUrl = artifactURL; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public String getArtifactTimeout() { + return artifactTimeout; + } + + public void setArtifactTimeout(String artifactTimeout) { + this.artifactTimeout = artifactTimeout; + } + + public String getArtifactChecksum() { + return artifactChecksum; + } + + public void setArtifactChecksum(String artifactChecksum) { + this.artifactChecksum = artifactChecksum; + } + + public String getArtifactUUID() { + return artifactUuid; + } + + public void setArtifactUUID(String artifactUUID) { + this.artifactUuid = artifactUUID; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getGeneratedFromUUID() { + return generatedFromUuid; + } + + public void setGeneratedFromUUID(String generatedFromUUID) { + this.generatedFromUuid = generatedFromUUID; + } +} diff --git a/src/main/java/org/onap/clamp/clds/model/CldsSdcResource.java b/src/main/java/org/onap/clamp/clds/model/CldsSdcResource.java new file mode 100644 index 00000000..7fa741c8 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/CldsSdcResource.java @@ -0,0 +1,135 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model; + +import java.math.BigDecimal; +import java.util.List; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class CldsSdcResource implements Comparable<CldsSdcResource> { + + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSdcResource.class); + protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); + + private String resourceInstanceName; + private String resourceName; + private String resourceInvariantUuid; + private String resourceVersion; + private String resoucreType; + private String resourceUuid; + private List<CldsSdcArtifact> artifacts; + + public String getResourceInstanceName() { + return resourceInstanceName; + } + + public void setResourceInstanceName(String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getResourceInvariantUUID() { + return resourceInvariantUuid; + } + + public void setResourceInvariantUUID(String resourceInvariantUUID) { + this.resourceInvariantUuid = resourceInvariantUUID; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public String getResoucreType() { + return resoucreType; + } + + public void setResoucreType(String resoucreType) { + this.resoucreType = resoucreType; + } + + public String getResourceUUID() { + return resourceUuid; + } + + public void setResourceUUID(String resourceUUID) { + this.resourceUuid = resourceUUID; + } + + public List<CldsSdcArtifact> getArtifacts() { + return artifacts; + } + + public void setArtifacts(List<CldsSdcArtifact> artifacts) { + this.artifacts = artifacts; + } + + @Override + public int compareTo(CldsSdcResource in) { + // Compares this object with the specified object for order. + // Returns a negative integer, zero, or a positive integer as this + // object is less than, equal to, or greater than the specified object. + + // first compare based on name + int rtn = resourceInstanceName.compareToIgnoreCase(in.resourceInstanceName); + + if (rtn == 0) { + BigDecimal myVersion = convertVersion(resourceVersion); + BigDecimal inVersion = convertVersion(in.resourceVersion); + rtn = myVersion.compareTo(inVersion); + } + return rtn; + } + + /** + * Convert version String into a BigDecimal + * + * @param versionText + * @return + */ + private BigDecimal convertVersion(String versionText) { + BigDecimal rtn = new BigDecimal(0.0); + try { + rtn = new BigDecimal(versionText); + } catch (NumberFormatException nfe) { + logger.warn("SDC version=" + versionText + " is not decimal for name=" + resourceInstanceName); + } + return rtn; + } +} diff --git a/src/main/java/org/onap/clamp/clds/model/CldsSdcResourceBasicInfo.java b/src/main/java/org/onap/clamp/clds/model/CldsSdcResourceBasicInfo.java new file mode 100644 index 00000000..80fa787e --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/CldsSdcResourceBasicInfo.java @@ -0,0 +1,164 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model; + +import java.math.BigDecimal; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class CldsSdcResourceBasicInfo implements Comparable<CldsSdcResourceBasicInfo> { + + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSdcResourceBasicInfo.class); + protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); + + private String uuid; + private String invariantUUID; + private String name; + private String version; + private String toscaModelURL; + private String category; + private String subCategory; + private String resourceType; + private String lifecycleState; + private String lastUpdaterUserId; + + @Override + public int compareTo(CldsSdcResourceBasicInfo in) { + // Compares this object with the specified object for order. + // Returns a negative integer, zero, or a positive integer as this + // object is less than, equal to, or greater than the specified object. + // first compare based on name + int rtn = name.compareToIgnoreCase(in.name); + + if (rtn == 0) { + BigDecimal myVersion = convertVersion(version); + BigDecimal inVersion = convertVersion(in.version); + rtn = myVersion.compareTo(inVersion); + } + return rtn; + } + + /** + * Convert version String into a BigDecimal + * + * @param version + * @return + */ + private BigDecimal convertVersion(String version) { + BigDecimal rtn = new BigDecimal(0.0); + try { + rtn = new BigDecimal(version); + } catch (NumberFormatException nfe) { + logger.warn("SDC version=" + version + " is not decimal for name=" + name); + } + return rtn; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getInvariantUUID() { + return invariantUUID; + } + + public void setInvariantUUID(String invariantUUID) { + this.invariantUUID = invariantUUID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getToscaModelURL() { + return toscaModelURL; + } + + public void setToscaModelURL(String toscaModelURL) { + this.toscaModelURL = toscaModelURL; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getSubCategory() { + return subCategory; + } + + public void setSubCategory(String subCategory) { + this.subCategory = subCategory; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getLifecycleState() { + return lifecycleState; + } + + public void setLifecycleState(String lifecycleState) { + this.lifecycleState = lifecycleState; + } + + public String getLastUpdaterUserId() { + return lastUpdaterUserId; + } + + public void setLastUpdaterUserId(String lastUpdaterUserId) { + this.lastUpdaterUserId = lastUpdaterUserId; + } + + public EELFLogger getLOGGER() { + return logger; + } +} diff --git a/src/main/java/org/onap/clamp/clds/model/CldsSdcServiceDetail.java b/src/main/java/org/onap/clamp/clds/model/CldsSdcServiceDetail.java new file mode 100644 index 00000000..551418b7 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/CldsSdcServiceDetail.java @@ -0,0 +1,142 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class CldsSdcServiceDetail { + + private String uuid; + private String invariantUUID; + private String name; + private String version; + private String toscaModelURL; + private String category; + private String lifecycleState; + private String lastUpdaterUserId; + private String distributionStatus; + private String lastUpdaterFullName; + private List<CldsSdcResource> resources; + private List<CldsSdcArtifact> artifacts; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getInvariantUUID() { + return invariantUUID; + } + + public void setInvariantUUID(String invariantUUID) { + this.invariantUUID = invariantUUID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getToscaModelURL() { + return toscaModelURL; + } + + public void setToscaModelURL(String toscaModelURL) { + this.toscaModelURL = toscaModelURL; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getLifecycleState() { + return lifecycleState; + } + + public void setLifecycleState(String lifecycleState) { + this.lifecycleState = lifecycleState; + } + + public String getLastUpdaterUserId() { + return lastUpdaterUserId; + } + + public void setLastUpdaterUserId(String lastUpdaterUserId) { + this.lastUpdaterUserId = lastUpdaterUserId; + } + + public String getDistributionStatus() { + return distributionStatus; + } + + public void setDistributionStatus(String distributionStatus) { + this.distributionStatus = distributionStatus; + } + + public String getLastUpdaterFullName() { + return lastUpdaterFullName; + } + + public void setLastUpdaterFullName(String lastUpdaterFullName) { + this.lastUpdaterFullName = lastUpdaterFullName; + } + + public List<CldsSdcResource> getResources() { + return resources; + } + + public void setResources(List<CldsSdcResource> resources) { + this.resources = resources; + } + + public List<CldsSdcArtifact> getArtifacts() { + return artifacts; + } + + public void setArtifacts(List<CldsSdcArtifact> artifacts) { + this.artifacts = artifacts; + } + +} diff --git a/src/main/java/org/onap/clamp/clds/model/CldsSdcServiceInfo.java b/src/main/java/org/onap/clamp/clds/model/CldsSdcServiceInfo.java new file mode 100644 index 00000000..175dc753 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/CldsSdcServiceInfo.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model; + +import java.math.BigDecimal; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class CldsSdcServiceInfo implements Comparable<CldsSdcServiceInfo> { + + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSdcServiceInfo.class); + protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); + + private String uuid; + private String invariantUUID; + private String name; + private String version; + private String toscaModelURL; + private String category; + private String lifecycleState; + private String lastUpdaterUserId; + private String distributionStatus; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getInvariantUUID() { + return invariantUUID; + } + + public void setInvariantUUID(String invariantUUID) { + this.invariantUUID = invariantUUID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getToscaModelURL() { + return toscaModelURL; + } + + public void setToscaModelURL(String toscaModelURL) { + this.toscaModelURL = toscaModelURL; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getLifecycleState() { + return lifecycleState; + } + + public void setLifecycleState(String lifecycleState) { + this.lifecycleState = lifecycleState; + } + + public String getLastUpdaterUserId() { + return lastUpdaterUserId; + } + + public void setLastUpdaterUserId(String lastUpdaterUserId) { + this.lastUpdaterUserId = lastUpdaterUserId; + } + + public String getDistributionStatus() { + return distributionStatus; + } + + public void setDistributionStatus(String distributionStatus) { + this.distributionStatus = distributionStatus; + } + + /** + * Compare using name and then version. Version is converted to a decimal. + */ + @Override + public int compareTo(CldsSdcServiceInfo in) { + // Compares this object with the specified object for order. + // Returns a negative integer, zero, or a positive integer as this + // object is less than, equal to, or greater than the specified object. + // first compare based on name + int rtn = name.compareToIgnoreCase(in.name); + + if (rtn == 0) { + BigDecimal myVersion = convertVersion(version); + BigDecimal inVersion = convertVersion(in.version); + rtn = myVersion.compareTo(inVersion); + } + + return rtn; + } + + /** + * Convert version String into a BigDecimal + * + * @param versionText + * @return + */ + private BigDecimal convertVersion(String versionText) { + try { + return new BigDecimal(versionText); + } catch (NumberFormatException nfe) { + logger.warn("SDC version=" + versionText + " is not decimal for name=" + name); + } + return new BigDecimal(0.0); + } + +} |