X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fclient%2Freq%2FSdcReq.java;h=9c3f261782fbb15972f30f30eb0ecc8fc14a3b1e;hb=e00f654909c75400cb881ed648a75d09767502cc;hp=3c16ce60b5fb47b2efc7a8325f96b479e5ddfd37;hpb=f74d1e91d69f202439da6db420dd8efc028e6c4e;p=clamp.git 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 3c16ce60..9c3f2617 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 @@ -23,6 +23,16 @@ package org.onap.clamp.clds.client.req; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.core.JsonParseException; +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.dataformat.yaml.snakeyaml.Yaml; + import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -39,21 +49,9 @@ 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; -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.dataformat.yaml.snakeyaml.Yaml; - /** * Construct a Sdc request given CLDS objects. */ @@ -63,14 +61,14 @@ public class SdcReq { /** * Format the Blueprint from a Yaml - * + * * @param refProp * The RefProp instance containing the Clds config * @param prop * The ModelProperties describing the clds model * @param docText * The Yaml file that must be converted - * + * * @return A String containing the BluePrint * @throws JsonParseException * In case of issues @@ -88,85 +86,16 @@ public class SdcReq { String yamlvalue = getYamlvalue(docText); String updatedBlueprint = ""; - 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, - prop); - logger.info("Value of serviceConfigurations:" + serviceConfigurations); - ObjectNode servConfNode = (ObjectNode) serviceConfigurations.get("serviceConfigurations"); - - // get updated blueprint by attaching service Conf from - // globalProperties - updatedBlueprint = getUpdatedBlueprintWithServiceConf(refProp, prop, yamlvalue, servConfNode); - } else if (tca.isFound()) { - prop.setCurrentModelElementId(tca.getId()); - ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("tca.template", service); - ObjectNode content = rootNode.with("content"); - TcaMPolicyReq.appendSignatures(refProp, service, content, tca, prop); - logger.info("Value of content:" + content); - // ObjectNode servConfNode = - // (ObjectNode)signatures.get("signatures"); - - // get updated blueprint by attaching service Conf from - // globalProperties - updatedBlueprint = getUpdatedBlueprintWithConfiguration(refProp, prop, yamlvalue, content); + if (tca.isFound()) { + updatedBlueprint = TcaRequestFormatter.updatedBlueprintWithConfiguration(refProp, prop, yamlvalue); } - logger.info("value of blueprint:" + updatedBlueprint); return updatedBlueprint; } - private static String getUpdatedBlueprintWithServiceConf(RefProp refProp, ModelProperties prop, String yamlValue, - ObjectNode serviceConf) throws IOException { - Yaml yaml = new Yaml(); - - // Serialiaze Yaml file - Map loadedYaml = (Map) yaml.load(yamlValue); - // Get node templates information from Yaml - Map nodeTemplates = loadedYaml.get("node_templates"); - logger.info("value of NodeTemplates:" + nodeTemplates); - - // Get StringMatch Object information from node templates of Yaml - Map smObject = nodeTemplates.get("SM"); - logger.info("value of StringMatch:" + smObject); - - // Get Properties Object information from stringmatch of Yaml - Map propsObject = smObject.get("properties"); - logger.info("value of PropsObject:" + propsObject); - - String deploymentJsonObject = propsObject.get("deployment_JSON"); - logger.info("value of deploymentJson:" + deploymentJsonObject); - - ObjectMapper mapper = new ObjectMapper(); - ObjectNode deployJsonNode = (ObjectNode) mapper.readTree(deploymentJsonObject); - ObjectNode configurationObjectNode = (ObjectNode) deployJsonNode.get("configuration"); - - // "policyName":"example_model06.ClosedLoop_FRWL_SIG_0538e6f2_8c1b_4656_9999_3501b3c59ad7_StringMatch_", - String policyNamePrefix = refProp.getStringValue("policy.ms.policyNamePrefix"); - String policyName = prop.getCurrentPolicyScopeAndFullPolicyName(policyNamePrefix); - configurationObjectNode.put("policyName", policyName); - - // "closedLoopControlName":"ClosedLoop-FRWL-SIG-0538e6f2-8c1b-4656-9999-3501b3c59ad7", - configurationObjectNode.put("closedLoopControlName", prop.getControlName()); - configurationObjectNode.put("messageReaderConsumerGroup", prop.getModelName()); - configurationObjectNode.set("serviceConfigurations", serviceConf); - propsObject.put("deployment_JSON", deployJsonNode.toString()); - String blueprint = yaml.dump(loadedYaml); - logger.info("value of updated Yaml File:" + blueprint); - - blueprint = yaml.dump(loadedYaml); - logger.info("value of updated Yaml File:" + blueprint); - - return blueprint; - } - private static String getUpdatedBlueprintWithConfiguration(RefProp refProp, ModelProperties prop, String yamlValue, - ObjectNode serviceConf) throws JsonProcessingException, IOException { + ObjectNode serviceConf) throws IOException { String blueprint = ""; Yaml yaml = new Yaml(); // Serialiaze Yaml file @@ -232,7 +161,7 @@ public class SdcReq { String resourceInstanceName = ""; if (globalProps != null) { List resourceVf = globalProps.getResourceVf(); - if (resourceVf != null && resourceVf.size() > 0) { + if (resourceVf != null && !resourceVf.isEmpty()) { resourceInstanceName = resourceVf.get(0); } if (globalProps.getService() != null) { @@ -250,12 +179,12 @@ public class SdcReq { * @param baseUrl * @param sdcCatalogServices * @return - * @throws Exception */ public static List getSdcReqUrlsList(ModelProperties prop, String baseUrl, - SdcCatalogServices sdcCatalogServices, DelegateExecution execution) throws Exception { + SdcCatalogServices sdcCatalogServices, DelegateExecution execution) { // TODO : refact and regroup with very similar code List urlList = new ArrayList<>(); + Global globalProps = prop.getGlobal(); if (globalProps != null) { if (globalProps.getService() != null) { @@ -264,27 +193,28 @@ public class SdcReq { List resourceVfList = globalProps.getResourceVf(); String serviceUUID = sdcCatalogServices.getServiceUuidFromServiceInvariantId(serviceInvariantUUID); String sdcServicesInformation = sdcCatalogServices.getSdcServicesInformation(serviceUUID); - CldsSdcServiceDetail CldsSdcServiceDetail = sdcCatalogServices + CldsSdcServiceDetail cldsSdcServiceDetail = sdcCatalogServices .getCldsSdcServiceDetailFromJson(sdcServicesInformation); - if (CldsSdcServiceDetail != null && resourceVfList != null) { - List CldsSdcResourcesList = CldsSdcServiceDetail.getResources(); - if (CldsSdcResourcesList != null && CldsSdcResourcesList.size() > 0) { - for (CldsSdcResource CldsSdcResource : CldsSdcResourcesList) { + if (cldsSdcServiceDetail != null && resourceVfList != null) { + List cldsSdcResourcesList = cldsSdcServiceDetail.getResources(); + if (cldsSdcResourcesList != null && !cldsSdcResourcesList.isEmpty()) { + 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); - } + && CldsSdcResource.getResoucreType().equalsIgnoreCase("VF") + && resourceVfList.contains(CldsSdcResource.getResourceInvariantUUID())) { + String normalizedResourceInstanceName = normalizeResourceInstanceName( + CldsSdcResource.getResourceInstanceName()); + String svcUrl = baseUrl + "/" + serviceUUID + "/resourceInstances/" + + normalizedResourceInstanceName + "/artifacts"; + urlList.add(svcUrl); + } } } } } } + return urlList; } @@ -358,7 +288,7 @@ public class SdcReq { /** * Method to get yaml/template properties value from json - * + * * @param docText * @return * @throws IOException