diff options
25 files changed, 498 insertions, 318 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java index c35eb0da4..192dcdb91 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java @@ -100,7 +100,7 @@ public class DcaeInventoryServices { List<String> resourceUuidList = global.getResourceVf();
String serviceUuid = sdcCatalogServices.getServiceUuidFromServiceInvariantId(invariantServiceUuid);
String resourceUuid = "";
- if (resourceUuidList != null && resourceUuidList.size() > 0) {
+ if (resourceUuidList != null && !resourceUuidList.isEmpty()) {
resourceUuid = resourceUuidList.get(0).toString();
}
/* Invemtory service url is called in this method */
diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java index 566d11a24..493b3b3c7 100644 --- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java @@ -78,9 +78,6 @@ public class OperationalPolicyDelegate implements JavaDelegate { */ @Override public void execute(DelegateExecution execution) throws IOException, BuilderException, PolicyEngineException { - - // execution.setVariable("operationalPolicyRequestUuid", - // operationalPolicyRequestUuid); String responseMessage = null; String operationalPolicyRequestUuid = null; ModelProperties prop = ModelProperties.create(execution); @@ -90,7 +87,7 @@ public class OperationalPolicyDelegate implements JavaDelegate { operationalPolicyRequestUuid = LoggingUtils.getRequestId(); Map<AttributeType, Map<String, String>> attributes = OperationalPolicyReq.formatAttributes(refProp, prop, prop.getType(Policy.class).getId(), policyChain); - responseMessage = policyClient.sendBrms(attributes, prop, operationalPolicyRequestUuid); + responseMessage = policyClient.sendBrmsPolicy(attributes, prop, operationalPolicyRequestUuid); } if (responseMessage != null) { execution.setVariable("operationalPolicyResponseMessage", responseMessage.getBytes()); diff --git a/src/main/java/org/onap/clamp/clds/client/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/PolicyClient.java index 22f215ccf..2b49a8ff5 100644 --- a/src/main/java/org/onap/clamp/clds/client/PolicyClient.java +++ b/src/main/java/org/onap/clamp/clds/client/PolicyClient.java @@ -62,10 +62,15 @@ import org.springframework.context.ApplicationContext; */ public class PolicyClient { + protected static final String POLICY_PREFIX_BASE = "Config_"; + protected static final String POLICY_PREFIX_BRMS_PARAM = "Config_BRMS_Param_"; + protected static final String POLICY_PREFIX_MICROSERVICE = "Config_MS_"; + protected static final String LOG_POLICY_PREFIX = "Response is "; - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyClient.class); - protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); + protected static final EELFLogger logger = EELFManager.getInstance() + .getLogger(PolicyClient.class); + protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); @Value("${org.onap.clamp.config.files.cldsPolicyConfig:'classpath:/clds/clds-policy-config.properties'}") protected String cldsPolicyConfigFile; @@ -77,7 +82,7 @@ public class PolicyClient { protected RefProp refProp; /** - * Perform send of microservice policy. + * Perform BRMS policy type. * * @param attributes * A map of attributes @@ -92,7 +97,7 @@ public class PolicyClient { * In case of issues with the PolicyEngine class * */ - public String sendBrms(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop, + public String sendBrmsPolicy(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop, String policyRequestUuid) throws PolicyEngineException, IOException { PolicyParameters policyParameters = new PolicyParameters(); @@ -122,7 +127,7 @@ public class PolicyClient { } /** - * Perform send of microservice policy. + * Perform send of microservice policy in JSON. * * @param policyJson * The policy JSON @@ -136,7 +141,7 @@ public class PolicyClient { * @throws IOException * In case of issue with the Stream */ - public String sendMicroService(String policyJson, ModelProperties prop, String policyRequestUuid) + public String sendMicroServiceInJson(String policyJson, ModelProperties prop, String policyRequestUuid) throws IOException, PolicyEngineException { PolicyParameters policyParameters = new PolicyParameters(); @@ -164,6 +169,47 @@ public class PolicyClient { } /** + * Perform send of base policy in OTHER type. + * + * @param configBody + * The config policy string body + * @param prop + * The ModelProperties + * @param policyRequestUuid + * The policy request UUID + * @return + * @throws IOException + * In case of issues with the policy engine class creation + * @throws PolicyEngineException + * In case of issue with the Stream + */ + public String sendBasePolicyInOther(String configBody, ModelProperties prop, String policyRequestUuid) + throws IOException, PolicyEngineException { + + PolicyParameters policyParameters = new PolicyParameters(); + + // Set Policy Type + policyParameters.setPolicyConfigType(PolicyConfigType.Base); + policyParameters.setEcompName(refProp.getStringValue("policy.ecomp.name")); + policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName()); + + policyParameters.setConfigBody(configBody); + policyParameters.setConfigBodyType(PolicyType.OTHER); + policyParameters.setConfigName("HolmesPolicy"); + + policyParameters.setRequestID(UUID.fromString(policyRequestUuid)); + + // Adding this line to clear the policy id from policy name while + // pushing to policy engine + prop.setPolicyUniqueId(""); + + String rtnMsg = send(policyParameters, prop, POLICY_PREFIX_BASE); + push(PolicyConfigType.Base.toString(), prop); + + return rtnMsg; + } + + /** * Perform send of policy. * * @param policyParameters @@ -204,7 +250,7 @@ public class PolicyClient { responseMessage = response.getResponseMessage(); } } catch (Exception e) { - logger.error("Exception occurred during policy communnication", e); + logger.error("Exception occurred during policy communication", e); } logger.info(LOG_POLICY_PREFIX + responseMessage); @@ -266,7 +312,7 @@ public class PolicyClient { response = policyEngine.pushPolicy(pushPolicyParameters); responseMessage = response.getResponseMessage(); } catch (Exception e) { - logger.error("Exception occurred during policy communnication", e); + logger.error("Exception occurred during policy communication", e); } logger.info(LOG_POLICY_PREFIX + responseMessage); @@ -350,9 +396,20 @@ public class PolicyClient { * In case of issues with the PolicyEngine creation */ public String deleteMicrosService(ModelProperties prop) throws PolicyEngineException, IOException { - String policyNamePrefix = refProp.getStringValue("policy.ms.policyNamePrefix"); String policyType = refProp.getStringValue("policy.ms.type"); - return deletePolicy(policyNamePrefix, prop, policyType); + return deletePolicy(prop, policyType); + } + + /** + * This method delete the Base policy. + * + * @param prop The model Properties + * @return A string with the answer from policy + * @throws PolicyEngineException In case of issues with the policy engine + * @throws IOException In case of issues with the stream + */ + public String deleteBasePolicy(ModelProperties prop) throws PolicyEngineException, IOException { + return deletePolicy(prop, PolicyConfigType.Base.toString()); } /** @@ -367,26 +424,23 @@ public class PolicyClient { * In case of issues with the PolicyEngine creation */ public String deleteBrms(ModelProperties prop) throws PolicyEngineException, IOException { - String policyNamePrefix = refProp.getStringValue("policy.op.policyNamePrefix"); String policyType = refProp.getStringValue("policy.op.type"); - return deletePolicy(policyNamePrefix, prop, policyType); + return deletePolicy(prop, policyType); } /** * Format and send delete PAP and PDP requests to Policy. * - * @param policyNamePrefix - * The String policyNamePrefix * @param prop * The ModelProperties + * * @return The response message from policy * @throws IOException * in case of issues with the Stream * @throws PolicyEngineException * In case of issues with the PolicyEngine class creation */ - protected String deletePolicy(String policyNamePrefix, ModelProperties prop, String policyType) - throws PolicyEngineException, IOException { + protected String deletePolicy(ModelProperties prop, String policyType) throws PolicyEngineException, IOException { DeletePolicyParameters deletePolicyParameters = new DeletePolicyParameters(); if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) { 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 24a3d3c41..d418ea55b 100644 --- a/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java +++ b/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java @@ -569,11 +569,7 @@ public class SdcCatalogServices { }
private String removeUnwantedBracesFromString(String id) {
- String idReworked = "";
- if (id != null && id.contains("\"")) {
- idReworked = id.replaceAll("\"", "");
- }
- return idReworked;
+ return (id != null) ? id.replaceAll("\"", "") : "";
}
private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws IOException {
@@ -740,7 +736,7 @@ public class SdcCatalogServices { String inputLine;
while ((inputLine = in.readLine()) != null) {
if (!inputLine.isEmpty()) {
- response.append(inputLine);
+ response.append(inputLine);
}
if (alarmConditions) {
response.append("\n");
@@ -985,12 +981,13 @@ public class SdcCatalogServices { alertDescNode.put(currCldsAlarmCondition.getAlarmConditionKey(),
currCldsAlarmCondition.getAlarmConditionKey());
}
+ }
}
- }
+
vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);
vfcObjectNode.putPOJO("alertDescription", alertDescNode);
vfcResourceUuidObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(), vfcObjectNode);
- }
+ }
}
} else {
alarmCondNode.put("", "");
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 ee233686b..0ffde932e 100644 --- a/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java @@ -70,9 +70,9 @@ public class SdcSendReqDelegate implements JavaDelegate { getSdcAttributes((String) execution.getVariable("controlName")); ModelProperties prop = ModelProperties.create(execution); String bluprintPayload = SdcReq.formatBlueprint(refProp, prop, docText); - String formatttedSdcReq = SdcReq.formatSdcReq(bluprintPayload, artifactName, artifactLabel, artifactType); - if (formatttedSdcReq != null) { - execution.setVariable("formattedArtifactReq", formatttedSdcReq.getBytes()); + String formattedSdcReq = SdcReq.formatSdcReq(bluprintPayload, artifactName, artifactLabel, artifactType); + if (formattedSdcReq != null) { + execution.setVariable("formattedArtifactReq", formattedSdcReq.getBytes()); } List<String> sdcReqUrlsList = SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, execution); @@ -83,7 +83,7 @@ public class SdcSendReqDelegate implements JavaDelegate { if (formattedSdcLocationReq != null) { execution.setVariable("formattedLocationReq", formattedSdcLocationReq.getBytes()); } - sdcCatalogServices.uploadToSdc(prop, userid, sdcReqUrlsList, formatttedSdcReq, formattedSdcLocationReq, + sdcCatalogServices.uploadToSdc(prop, userid, sdcReqUrlsList, formattedSdcReq, formattedSdcLocationReq, artifactName, locationArtifactName); } diff --git a/src/main/java/org/onap/clamp/clds/client/StringMatchPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/StringMatchPolicyDelegate.java index 50126d55e..d149137b6 100644 --- a/src/main/java/org/onap/clamp/clds/client/StringMatchPolicyDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/StringMatchPolicyDelegate.java @@ -64,7 +64,7 @@ public class StringMatchPolicyDelegate implements JavaDelegate { StringMatch stringMatch = prop.getType(StringMatch.class); if (stringMatch.isFound()) { String policyJson = StringMatchPolicyReq.format(refProp, prop); - String responseMessage = policyClient.sendMicroService(policyJson, prop, stringMatchPolicyRequestUuid); + String responseMessage = policyClient.sendMicroServiceInJson(policyJson, prop, stringMatchPolicyRequestUuid); if (responseMessage != null) { execution.setVariable("stringMatchPolicyResponseMessage", responseMessage.getBytes()); } diff --git a/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java index e8b92a42b..9debcc2a6 100644 --- a/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java @@ -65,7 +65,7 @@ public class TcaPolicyDelegate implements JavaDelegate { Tca tca = prop.getType(Tca.class); if (tca.isFound()) { String policyJson = TcaMPolicyReq.formatTca(refProp, prop); - String responseMessage = policyClient.sendMicroService(policyJson, prop, tcaPolicyRequestUuid); + String responseMessage = policyClient.sendMicroServiceInJson(policyJson, prop, tcaPolicyRequestUuid); if (responseMessage != null) { execution.setVariable("tcaPolicyResponseMessage", responseMessage.getBytes()); } diff --git a/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java b/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java index e7f956d33..2b1762a24 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java +++ b/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java @@ -85,8 +85,8 @@ public class OperationalPolicyReq { String operationTopic = ""; String notificationTopic = ""; String controller = ""; - Tca tca = prop.getTca(); - if (tca.isFound()) { + Tca tca = prop.getType(Tca.class); + if (tca != null && tca.isFound()) { if (!global.getActionSet().equalsIgnoreCase("enbRecipe")) { throw new BadRequestException( "Operation Policy validation problem: action set is not selected properly."); @@ -108,9 +108,9 @@ public class OperationalPolicyReq { String recipeTopic = refProp.getStringValue("op.recipeTopic", global.getService()); // ruleAttributes - Map<String, String> ruleAttributes = new HashMap<String, String>(); + Map<String, String> ruleAttributes = new HashMap<>(); - if (operationTopic == null || operationTopic.length() == 0) { + if (operationTopic == null || operationTopic.isEmpty()) { logger.info("templateName=" + templateName); logger.info("recipeTopic=" + recipeTopic); logger.info("notificationTopic=" + notificationTopic); @@ -151,10 +151,10 @@ public class OperationalPolicyReq { } // matchingAttributes - Map<String, String> matchingAttributes = new HashMap<String, String>(); + Map<String, String> matchingAttributes = new HashMap<>(); matchingAttributes.put("controller", controller); - Map<AttributeType, Map<String, String>> attributes = new HashMap<AttributeType, Map<String, String>>(); + Map<AttributeType, Map<String, String>> attributes = new HashMap<>(); attributes.put(AttributeType.RULE, ruleAttributes); attributes.put(AttributeType.MATCHING, matchingAttributes); @@ -189,7 +189,7 @@ public class OperationalPolicyReq { builder.addResource(vfcResources); // process each policy - HashMap<String, org.onap.policy.controlloop.policy.Policy> policyObjMap = new HashMap<String, org.onap.policy.controlloop.policy.Policy>(); + HashMap<String, org.onap.policy.controlloop.policy.Policy> policyObjMap = new HashMap<>(); List<PolicyItem> policyItemList = orderParentFirst(policyChain.getPolicyItems()); Target target = new Target(); target.setType(TargetType.VM); @@ -227,7 +227,7 @@ public class OperationalPolicyReq { logger.info("results.getSpecification()=" + results.getSpecification()); } else { // throw exception with error info - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("Operation Policy validation problem: ControlLoopPolicyBuilder failed with following messages: "); for (Message message : results.getMessages()) { sb.append(message.getMessage()); @@ -235,10 +235,7 @@ public class OperationalPolicyReq { } throw new BadRequestException(sb.toString()); } - - String encodedYaml = URLEncoder.encode(results.getSpecification(), "UTF-8"); - - return encodedYaml; + return URLEncoder.encode(results.getSpecification(), "UTF-8"); } /** @@ -269,7 +266,7 @@ public class OperationalPolicyReq { builder.addResource(vfcResources); // process each policy - HashMap<String, Policy> policyObjMap = new HashMap<String, Policy>(); + HashMap<String, Policy> policyObjMap = new HashMap<>(); List<PolicyItem> policyItemList = addAOTSActorRecipe(refProp, global.getService(), policyChain.getPolicyItems()); Target target = new Target(); @@ -281,7 +278,7 @@ public class OperationalPolicyReq { String policyName = policyItem.getRecipe() + " Policy"; if (i == 0) { // To set up time window payload for trigger policy - Map<String, String> payloadMap = new HashMap<String, String>(); + Map<String, String> payloadMap = new HashMap<>(); payloadMap.put("timeWindow", refProp.getStringValue("op.eNodeB.timeWindow")); String policyDescription = policyItem.getRecipe() + " Policy - the trigger (no parent) policy - created by CLDS"; @@ -314,7 +311,7 @@ public class OperationalPolicyReq { logger.info("results.getSpecification()=" + results.getSpecification()); } else { // throw exception with error info - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("Operation Policy validation problem: ControlLoopPolicyBuilder failed with following messages: "); for (Message message : results.getMessages()) { sb.append(message.getMessage()); @@ -322,10 +319,7 @@ public class OperationalPolicyReq { } throw new BadRequestException(sb.toString()); } - - String encodedYaml = URLEncoder.encode(results.getSpecification(), "UTF-8"); - - return encodedYaml; + return URLEncoder.encode(results.getSpecification(), "UTF-8"); } /** @@ -335,7 +329,7 @@ public class OperationalPolicyReq { * @return */ private static List<PolicyItem> addAOTSActorRecipe(RefProp refProp, String service, List<PolicyItem> inOrigList) { - List<PolicyItem> outList = new ArrayList<PolicyItem>(); + List<PolicyItem> outList = new ArrayList<>(); try { PolicyItem policyItem = inOrigList.get(0); ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("op.eNodeB.recipe", service); @@ -354,7 +348,7 @@ public class OperationalPolicyReq { policyItemObj.setRetryTimeLimit(Integer.parseInt(recipeNode.path("TimeLimit").asText())); } if (!recipeNode.path("PPConditions").asText().isEmpty()) { - List<String> parentPolicyConditions = new ArrayList<String>(); + List<String> parentPolicyConditions = new ArrayList<>(); for (String ppCondition : recipeNode.path("PPConditions").asText().split(",")) { parentPolicyConditions.add(ppCondition); } @@ -395,7 +389,7 @@ public class OperationalPolicyReq { // check for trigger policy (no parent) String parent = inItem.getParentPolicy(); if (parent == null || parent.length() == 0) { - if (outList.size() > 0) { + if (!outList.isEmpty()) { throw new BadRequestException( "Operation Policy validation problem: more than one trigger policy"); } else { @@ -431,7 +425,7 @@ public class OperationalPolicyReq { return new Resource[0]; } return stringList.stream().map(stringElem -> new Resource(stringElem, resourceType)).toArray(Resource[]::new); - } + } /** * Convert a List of policy result strings to an array of PolicyResult 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 9c2ebcda1..93c562601 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 @@ -233,7 +233,7 @@ public class SdcReq { String resourceInstanceName = ""; if (globalProps != null) { List<String> resourceVf = globalProps.getResourceVf(); - if (resourceVf != null && resourceVf.size() > 0) { + if (resourceVf != null && !resourceVf.isEmpty()) { resourceInstanceName = resourceVf.get(0); } if (globalProps.getService() != null) { @@ -258,35 +258,35 @@ public class SdcReq { // TODO : refact and regroup with very similar code List<String> urlList = new ArrayList<>(); try { - Global globalProps = prop.getGlobal(); - if (globalProps != null) { - if (globalProps.getService() != null) { - String serviceInvariantUUID = globalProps.getService(); - execution.setVariable("serviceInvariantUUID", serviceInvariantUUID); - List<String> resourceVfList = globalProps.getResourceVf(); - 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); - } + Global globalProps = prop.getGlobal(); + if (globalProps != null) { + if (globalProps.getService() != null) { + String serviceInvariantUUID = globalProps.getService(); + execution.setVariable("serviceInvariantUUID", serviceInvariantUUID); + List<String> resourceVfList = globalProps.getResourceVf(); + 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.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); } } } } } } + } } catch (IOException e) { throw new SdcCommunicationException("Exception occurred during the SDC communication",e); } diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java index d54976b84..3b69502ae 100644 --- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java +++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java @@ -23,6 +23,9 @@ package org.onap.clamp.clds.dao; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; @@ -51,9 +54,6 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.simple.SimpleJdbcCall; import org.springframework.stereotype.Repository; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - /** * Data Access for CLDS Model tables. */ @@ -63,19 +63,19 @@ public class CldsDao { protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDao.class); protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); - private JdbcTemplate jdbcTemplateObject; - private SimpleJdbcCall procGetModel; - private SimpleJdbcCall procGetModelTemplate; - private SimpleJdbcCall procSetModel; - private SimpleJdbcCall procInsEvent; - private SimpleJdbcCall procUpdEvent; - private SimpleJdbcCall procSetTemplate; - private SimpleJdbcCall procGetTemplate; - private SimpleJdbcCall procDelAllModelInstances; - private SimpleJdbcCall procInsModelInstance; - private SimpleJdbcCall procDelModelInstance; + private JdbcTemplate jdbcTemplateObject; + private SimpleJdbcCall procGetModel; + private SimpleJdbcCall procGetModelTemplate; + private SimpleJdbcCall procSetModel; + private SimpleJdbcCall procInsEvent; + private SimpleJdbcCall procUpdEvent; + private SimpleJdbcCall procSetTemplate; + private SimpleJdbcCall procGetTemplate; + private SimpleJdbcCall procDelAllModelInstances; + private SimpleJdbcCall procInsModelInstance; + private SimpleJdbcCall procDelModelInstance; - private static final String healthcheck = "Select 1"; + private static final String HEALTHCHECK = "Select 1"; /** * Log message when instantiating @@ -386,7 +386,7 @@ public class CldsDao { cldsServiceData = (CldsServiceData) oip.readObject(); cldsServiceData.setAgeOfRecord(age); } catch (IOException | ClassNotFoundException e) { - logger.error("Error caught while retrieving cldsServiceData from database"); + logger.error("Error caught while retrieving cldsServiceData from database", e); } return cldsServiceData; } @@ -463,8 +463,7 @@ public class CldsDao { return template; } - public CldsServiceData getCldsServiceCache(String invariantUUID) - throws SQLException, IOException, ClassNotFoundException { + public CldsServiceData getCldsServiceCache(String invariantUUID) { CldsServiceData cldsServiceData = null; List<CldsServiceData> cldsServiceDataList = new ArrayList<>(); try { @@ -478,7 +477,7 @@ public class CldsDao { return cldsServiceData; } - public void setCldsServiceCache(CldsDBServiceCache cldsDBServiceCache) throws SQLException, IOException { + public void setCldsServiceCache(CldsDBServiceCache cldsDBServiceCache) { if (cldsDBServiceCache != null && cldsDBServiceCache.getInvariantId() != null && cldsDBServiceCache.getServiceId() != null) { String invariantUuid = cldsDBServiceCache.getInvariantId(); @@ -501,7 +500,7 @@ public class CldsDao { } public void doHealthCheck() throws SQLException, IOException { - jdbcTemplateObject.execute(healthcheck); + jdbcTemplateObject.execute(HEALTHCHECK); } } diff --git a/src/main/java/org/onap/clamp/clds/exception/CldsConfigException.java b/src/main/java/org/onap/clamp/clds/exception/CldsConfigException.java new file mode 100644 index 000000000..3122fbaa4 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/exception/CldsConfigException.java @@ -0,0 +1,61 @@ +/*- + * ============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.exception; + +/** + * New exception to CldsUser errors. + * + */ +public class CldsConfigException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 5958873136187918505L; + + /** + * This constructor can be used to create a new CldsConfigException. + * + * @param message + * A string message detailing the problem + * @param e + * The exception sent by the code + */ + public CldsConfigException(String message, Throwable e) { + super(message, e); + } + + /** + * This constructor can be used to create a new CldsConfigException. Use + * this constructor only if you are creating a new exception stack, not if + * an exception was already raised by another code. + * + * @param message + * A string message detailing the problem + */ + public CldsConfigException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/onap/clamp/clds/model/CldsDBServiceCache.java b/src/main/java/org/onap/clamp/clds/model/CldsDBServiceCache.java index 4b2a2e30f..f9a760b77 100644 --- a/src/main/java/org/onap/clamp/clds/model/CldsDBServiceCache.java +++ b/src/main/java/org/onap/clamp/clds/model/CldsDBServiceCache.java @@ -51,7 +51,7 @@ public class CldsDBServiceCache { this.serviceId = serviceId; } - public InputStream getCldsDataInstream() throws IOException { + public InputStream getCldsDataInstream() { return cldsDataInstream; } diff --git a/src/main/java/org/onap/clamp/clds/model/CldsSdcResource.java b/src/main/java/org/onap/clamp/clds/model/CldsSdcResource.java index 7fa741c8b..9c47f450c 100644 --- a/src/main/java/org/onap/clamp/clds/model/CldsSdcResource.java +++ b/src/main/java/org/onap/clamp/clds/model/CldsSdcResource.java @@ -23,26 +23,26 @@ 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; +import java.math.BigDecimal; +import java.util.List; + @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; + 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; @@ -117,6 +117,37 @@ public class CldsSdcResource implements Comparable<CldsSdcResource> { return rtn; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((resourceInstanceName == null) ? 0 : resourceInstanceName.hashCode()); + result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CldsSdcResource other = (CldsSdcResource) obj; + if (resourceInstanceName == null) { + if (other.resourceInstanceName != null) + return false; + } else if (!resourceInstanceName.equals(other.resourceInstanceName)) + return false; + if (resourceVersion == null) { + if (other.resourceVersion != null) + return false; + } else if (!resourceVersion.equals(other.resourceVersion)) + return false; + return true; + } + /** * Convert version String into a BigDecimal * @@ -124,7 +155,7 @@ public class CldsSdcResource implements Comparable<CldsSdcResource> { * @return */ private BigDecimal convertVersion(String versionText) { - BigDecimal rtn = new BigDecimal(0.0); + BigDecimal rtn = BigDecimal.valueOf(0.0); try { rtn = new BigDecimal(versionText); } catch (NumberFormatException nfe) { diff --git a/src/main/java/org/onap/clamp/clds/model/CldsSdcResourceBasicInfo.java b/src/main/java/org/onap/clamp/clds/model/CldsSdcResourceBasicInfo.java index 80fa787ee..f91e36a81 100644 --- a/src/main/java/org/onap/clamp/clds/model/CldsSdcResourceBasicInfo.java +++ b/src/main/java/org/onap/clamp/clds/model/CldsSdcResourceBasicInfo.java @@ -23,28 +23,29 @@ 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; +import java.math.BigDecimal; + @JsonIgnoreProperties(ignoreUnknown = true) public class CldsSdcResourceBasicInfo implements Comparable<CldsSdcResourceBasicInfo> { - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSdcResourceBasicInfo.class); + 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; + 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) { @@ -62,6 +63,37 @@ public class CldsSdcResourceBasicInfo implements Comparable<CldsSdcResourceBasic return rtn; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CldsSdcResourceBasicInfo other = (CldsSdcResourceBasicInfo) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + /** * Convert version String into a BigDecimal * @@ -69,7 +101,7 @@ public class CldsSdcResourceBasicInfo implements Comparable<CldsSdcResourceBasic * @return */ private BigDecimal convertVersion(String version) { - BigDecimal rtn = new BigDecimal(0.0); + BigDecimal rtn = BigDecimal.valueOf(0.0); try { rtn = new BigDecimal(version); } catch (NumberFormatException nfe) { diff --git a/src/main/java/org/onap/clamp/clds/model/CldsSdcServiceInfo.java b/src/main/java/org/onap/clamp/clds/model/CldsSdcServiceInfo.java index 175dc753c..cf447c5c7 100644 --- a/src/main/java/org/onap/clamp/clds/model/CldsSdcServiceInfo.java +++ b/src/main/java/org/onap/clamp/clds/model/CldsSdcServiceInfo.java @@ -23,25 +23,25 @@ package org.onap.clamp.clds.model; -import java.math.BigDecimal; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import java.math.BigDecimal; + public class CldsSdcServiceInfo implements Comparable<CldsSdcServiceInfo> { - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSdcServiceInfo.class); + 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; + 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; @@ -135,6 +135,37 @@ public class CldsSdcServiceInfo implements Comparable<CldsSdcServiceInfo> { return rtn; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CldsSdcServiceInfo other = (CldsSdcServiceInfo) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + /** * Convert version String into a BigDecimal * @@ -147,7 +178,7 @@ public class CldsSdcServiceInfo implements Comparable<CldsSdcServiceInfo> { } catch (NumberFormatException nfe) { logger.warn("SDC version=" + versionText + " is not decimal for name=" + name); } - return new BigDecimal(0.0); + return BigDecimal.valueOf(0.0); } } diff --git a/src/main/java/org/onap/clamp/clds/model/CldsServiceData.java b/src/main/java/org/onap/clamp/clds/model/CldsServiceData.java index dad7cb615..943532f02 100644 --- a/src/main/java/org/onap/clamp/clds/model/CldsServiceData.java +++ b/src/main/java/org/onap/clamp/clds/model/CldsServiceData.java @@ -23,6 +23,9 @@ package org.onap.clamp.clds.model; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -32,20 +35,17 @@ import javax.ws.rs.NotAuthorizedException; import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.service.CldsService; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - public class CldsServiceData implements Serializable { - private static final long serialVersionUID = -9153372664377279423L; + private static final long serialVersionUID = -9153372664377279423L; - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsServiceData.class); + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsServiceData.class); protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); - private String serviceInvariantUUID; - private String serviceUUID; - private Long ageOfRecord; - private List<CldsVfData> cldsVfs; + private String serviceInvariantUUID; + private String serviceUUID; + private Long ageOfRecord; + private List<CldsVfData> cldsVfs; public String getServiceInvariantUUID() { return serviceInvariantUUID; @@ -71,11 +71,11 @@ public class CldsServiceData implements Serializable { this.serviceUUID = serviceUUID; } - public CldsServiceData getCldsServiceCache(CldsDao cldsDao, String invariantServiceUUID) throws Exception { + public CldsServiceData getCldsServiceCache(CldsDao cldsDao, String invariantServiceUUID) { return cldsDao.getCldsServiceCache(invariantServiceUUID); } - public void setCldsServiceCache(CldsDao cldsDao, CldsDBServiceCache cldsDBServiceCache) throws Exception { + public void setCldsServiceCache(CldsDao cldsDao, CldsDBServiceCache cldsDBServiceCache) { cldsDao.setCldsServiceCache(cldsDBServiceCache); } @@ -106,7 +106,7 @@ public class CldsServiceData implements Serializable { filteredCldsVfs.add(vf); } } catch (NotAuthorizedException e) { - logger.debug("user not authorized for {}", vf.getVfInvariantResourceUUID()); + logger.error("user not authorized for {}" + vf.getVfInvariantResourceUUID(), e); // when not NotAuthorizedException - don't add to // filteredCldsVfs list } diff --git a/src/main/java/org/onap/clamp/clds/model/refprop/RefProp.java b/src/main/java/org/onap/clamp/clds/model/refprop/RefProp.java index 3b1f9682f..4b26bc05d 100644 --- a/src/main/java/org/onap/clamp/clds/model/refprop/RefProp.java +++ b/src/main/java/org/onap/clamp/clds/model/refprop/RefProp.java @@ -23,6 +23,11 @@ package org.onap.clamp.clds.model.refprop; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; @@ -36,33 +41,20 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; import org.springframework.core.io.Resource; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - /** * Holds reference properties. */ public class RefProp { - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(RefProp.class); + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(RefProp.class); protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); @Autowired - private ApplicationContext appContext; + private ApplicationContext appContext; - private Properties prop; + private Properties prop; @Value("${org.onap.clamp.config.files.cldsReference:'classpath:/clds/clds-reference.properties'}") - private String cldsReferenceValuesFile; - - /** - * Load reference properties via null constructor - * - * @throws IOException - */ - public RefProp() throws IOException { - } + private String cldsReferenceValuesFile; @PostConstruct public void loadConfig() throws IOException { diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index 3d6d54a11..ff4cfda17 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -24,16 +24,12 @@ package org.onap.clamp.clds.service; import com.att.ajsc.common.AjscService; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; import java.io.InputStream; -import java.sql.SQLException; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -54,16 +50,18 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import org.apache.commons.lang3.StringUtils; import org.camunda.bpm.engine.RuntimeService; import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.json.simple.parser.ParseException; import org.onap.clamp.clds.client.DcaeDispatcherServices; import org.onap.clamp.clds.client.DcaeInventoryServices; import org.onap.clamp.clds.client.SdcCatalogServices; import org.onap.clamp.clds.dao.CldsDao; +import org.onap.clamp.clds.exception.CldsConfigException; +import org.onap.clamp.clds.exception.SdcCommunicationException; import org.onap.clamp.clds.model.CldsDBServiceCache; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsHealthCheck; @@ -93,43 +91,40 @@ import io.swagger.annotations.ApiOperation; * Service to save and retrieve the CLDS model attributes. */ @AjscService -@Api(value = "/clds", description = "Clds operations") +@Api(value = "/clds") @Path("/clds") public class CldsService extends SecureServiceBase { @Autowired - private ApplicationContext appContext; + private ApplicationContext appContext; - private static final String RESOURCE_NAME = "clds-version.properties"; - - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsService.class); - protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); + private static final String RESOURCE_NAME = "clds-version.properties"; @Value("${CLDS_PERMISSION_TYPE_CL:permission-type-cl}") - private String cldsPersmissionTypeCl; + private String cldsPersmissionTypeCl; @Value("${CLDS_PERMISSION_TYPE_CL_MANAGE:permission-type-cl-manage}") - private String cldsPermissionTypeClManage; + private String cldsPermissionTypeClManage; @Value("${CLDS_PERMISSION_TYPE_CL_EVENT:permission-type-cl-event}") - private String cldsPermissionTypeClEvent; + private String cldsPermissionTypeClEvent; @Value("${CLDS_PERMISSION_TYPE_FILTER_VF:permission-type-filter-vf}") - private String cldsPermissionTypeFilterVf; + private String cldsPermissionTypeFilterVf; @Value("${CLDS_PERMISSION_TYPE_TEMPLATE:permission-type-template}") - private String cldsPermissionTypeTemplate; + private String cldsPermissionTypeTemplate; @Value("${CLDS_PERMISSION_INSTANCE:dev}") - private String cldsPermissionInstance; + private String cldsPermissionInstance; - private SecureServicePermission permissionReadCl; + private SecureServicePermission permissionReadCl; - private SecureServicePermission permissionUpdateCl; + private SecureServicePermission permissionUpdateCl; - private SecureServicePermission permissionReadTemplate; + private SecureServicePermission permissionReadTemplate; - private SecureServicePermission permissionUpdateTemplate; + private SecureServicePermission permissionUpdateTemplate; @PostConstruct private final void afterConstruction() { @@ -192,23 +187,14 @@ public class CldsService extends SecureServiceBase { // Get CLDS application version String cldsVersion = ""; Properties props = new Properties(); - InputStream resourceStream = null; - try { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - resourceStream = loader.getResourceAsStream(RESOURCE_NAME); + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + + try (InputStream resourceStream = loader.getResourceAsStream(RESOURCE_NAME)) { props.load(resourceStream); cldsVersion = props.getProperty("clds.version"); } catch (Exception ex) { - ex.printStackTrace(); - } finally { - if (resourceStream != null) { - try { - resourceStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } + logger.error("Exception caught during the clds.version reading", ex); } cldsInfo.setCldsVersion(cldsVersion); @@ -232,22 +218,12 @@ public class CldsService extends SecureServiceBase { cldsHealthCheck.setHealthCheckComponent("CLDS-APP"); cldsHealthCheck.setHealthCheckStatus("UP"); cldsHealthCheck.setDescription("OK"); - } catch (SQLException e) { - logger.error("CLAMP application DB Error" + e); - cldsHealthCheck.setHealthCheckComponent("CLDS-APP"); - cldsHealthCheck.setHealthCheckStatus("DOWN"); - cldsHealthCheck.setDescription("NOT-OK"); - // return Response.status(500).entity("Database down for CLDS - // application").build(); } catch (Exception e) { - logger.error("CLAMP application DB Error" + e); + logger.error("CLAMP application DB Error", e); cldsHealthCheck.setHealthCheckComponent("CLDS-APP"); cldsHealthCheck.setHealthCheckStatus("DOWN"); cldsHealthCheck.setDescription("NOT-OK"); - // return Response.status(500).entity("Database down for CLDS - // application").build(); } - return cldsHealthCheck; } @@ -360,13 +336,12 @@ public class CldsService extends SecureServiceBase { * * @param modelName * @return clds model - clds model for the given model name - * @throws NotAuthorizedException */ @ApiOperation(value = "Retrieves a CLDS model by name from the database", notes = "", response = String.class) @GET @Path("/model/{modelName}") @Produces(MediaType.APPLICATION_JSON) - public CldsModel getModel(@PathParam("modelName") String modelName) throws NotAuthorizedException { + public CldsModel getModel(@PathParam("modelName") String modelName) { Date startTime = new Date(); LoggingUtils.setRequestContext("CldsService: GET model", getPrincipalName()); isAuthorized(permissionReadCl); @@ -376,7 +351,7 @@ public class CldsService extends SecureServiceBase { cldsModel.setUserAuthorizedToUpdate(isAuthorizedNoException(permissionUpdateCl)); /** - * Checking condtion whether our CLDS model can call INventory Method + * Checking condition whether our CLDS model can call INventory Method */ if (cldsModel.canInventoryCall()) { try { @@ -401,16 +376,13 @@ public class CldsService extends SecureServiceBase { * REST service that saves a CLDS model by name in the database. * * @param modelName - * @throws TransformerException - * @throws TransformerConfigurationException */ @ApiOperation(value = "Saves a CLDS model by name in the database", notes = "", response = String.class) @PUT @Path("/model/{modelName}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - public CldsModel putModel(@PathParam("modelName") String modelName, CldsModel cldsModel) - throws TransformerException { + public CldsModel putModel(@PathParam("modelName") String modelName, CldsModel cldsModel) { Date startTime = new Date(); LoggingUtils.setRequestContext("CldsService: PUT model", getPrincipalName()); isAuthorized(permissionUpdateCl); @@ -468,9 +440,8 @@ public class CldsService extends SecureServiceBase { * @param test * @param model * @return - * @throws Exception - * @throws JsonProcessingException - * @throws NotAuthorizedException + * @throws TransformerException + * @throws ParseException */ @ApiOperation(value = "Saves and processes an action for a CLDS model by name", notes = "", response = String.class) @PUT @@ -479,7 +450,7 @@ public class CldsService extends SecureServiceBase { @Produces(MediaType.APPLICATION_JSON) public CldsModel putModelAndProcessAction(@PathParam("action") String action, @PathParam("modelName") String modelName, @QueryParam("test") String test, CldsModel model) - throws Exception { + throws TransformerException, ParseException { Date startTime = new Date(); LoggingUtils.setRequestContext("CldsService: Process model action", getPrincipalName()); String actionCd = action.toUpperCase(); @@ -656,17 +627,19 @@ public class CldsService extends SecureServiceBase { @GET @Path("/sdc/services") @Produces(MediaType.APPLICATION_JSON) - public String getSdcServices() throws Exception { + public String getSdcServices() { Date startTime = new Date(); LoggingUtils.setRequestContext("CldsService: GET sdc services", getPrincipalName()); String retStr; + + String responseStr = sdcCatalogServices.getSdcServicesInformation(null); try { - String responseStr = sdcCatalogServices.getSdcServicesInformation(null); retStr = createUiServiceFormatJson(responseStr); - } catch (Exception e) { - logger.info("{} {}", e.getClass().getName(), e.getMessage()); - throw e; + } catch (IOException e) { + logger.error("IOException during SDC communication", e); + throw new SdcCommunicationException("IOException during SDC communication", e); } + logger.info("value of sdcServices : {}", retStr); // audit log LoggingUtils.setTimeContext(startTime, new Date()); @@ -677,14 +650,16 @@ public class CldsService extends SecureServiceBase { /** * REST service that retrieves total properties required by UI + * + * @throws IOException + * In case of issues * - * @throws Exception */ @ApiOperation(value = "Retrieves total properties required by UI", notes = "", response = String.class) @GET @Path("/properties") @Produces(MediaType.APPLICATION_JSON) - public String getSdcProperties() throws Exception { + public String getSdcProperties() throws IOException { return createPropertiesObjectByUUID(getGlobalCldsString(), "{}"); } @@ -749,8 +724,8 @@ public class CldsService extends SecureServiceBase { * @throws NotAuthorizedException * @return */ - public boolean isAuthorizedForVf(String vfInvariantUuid) throws NotAuthorizedException { - if (cldsPermissionTypeFilterVf != null && cldsPermissionTypeFilterVf.length() > 0) { + public boolean isAuthorizedForVf(String vfInvariantUuid) { + if (cldsPermissionTypeFilterVf != null && !cldsPermissionTypeFilterVf.isEmpty()) { SecureServicePermission permission = SecureServicePermission.create(cldsPermissionTypeFilterVf, cldsPermissionInstance, vfInvariantUuid); return isAuthorized(permission); @@ -769,7 +744,7 @@ public class CldsService extends SecureServiceBase { * @param model * @return */ - private boolean isAuthorizedForVf(CldsModel model) throws NotAuthorizedException { + private boolean isAuthorizedForVf(CldsModel model) { String vf = ModelProperties.getVf(model); if (vf == null || vf.length() == 0) { logger.info("VF not found in model"); @@ -789,7 +764,7 @@ public class CldsService extends SecureServiceBase { ObjectNode invariantIdServiceNode = objectMapper.createObjectNode(); ObjectNode serviceNode = objectMapper.createObjectNode(); logger.info("value of cldsserviceiNfolist: {}", rawList); - if (rawList != null && rawList.size() > 0) { + if (rawList != null && !rawList.isEmpty()) { List<CldsSdcServiceInfo> cldsSdcServiceInfoList = sdcCatalogServices.removeDuplicateServices(rawList); for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServiceInfoList) { @@ -852,40 +827,55 @@ public class CldsService extends SecureServiceBase { } private void createVfObjectNode(ObjectNode vfObjectNode2, ObjectMapper mapper, - List<CldsSdcResource> rawCldsSdcResourceList) throws IOException { + List<CldsSdcResource> rawCldsSdcResourceList) { ObjectNode vfNode = mapper.createObjectNode(); vfNode.put("", ""); - // To remove repeated resource instance name from resourceInstanceList + // To remove repeated resource instance name from + // resourceInstanceList List<CldsSdcResource> cldsSdcResourceList = sdcCatalogServices .removeDuplicateSdcResourceInstances(rawCldsSdcResourceList); /** * Creating vf resource node using cldsSdcResource Object */ - if (cldsSdcResourceList != null && cldsSdcResourceList.size() > 0) { + if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) { for (CldsSdcResource cldsSdcResource : cldsSdcResourceList) { - if (cldsSdcResource != null && cldsSdcResource.getResoucreType() != null - && cldsSdcResource.getResoucreType().equalsIgnoreCase("VF")) { + if (cldsSdcResource != null && "VF".equalsIgnoreCase(cldsSdcResource.getResoucreType())) { vfNode.put(cldsSdcResource.getResourceUUID(), cldsSdcResource.getResourceName()); } } } vfObjectNode2.putPOJO("vf", vfNode); - String locationStringValue = refProp.getStringValue("ui.location.default"); - String alarmStringValue = refProp.getStringValue("ui.alarm.default"); /** * creating location json object using properties file value */ - ObjectNode locationJsonNode = (ObjectNode) mapper.readValue(locationStringValue, JsonNode.class); + ObjectNode locationJsonNode; + try { + locationJsonNode = (ObjectNode) mapper.readValue(refProp.getStringValue("ui.location.default"), + JsonNode.class); + } catch (IOException e) { + logger.error("Unable to load ui.location.default JSON in clds-references.properties properly", e); + throw new CldsConfigException( + "Unable to load ui.location.default JSON in clds-references.properties properly", e); + } vfObjectNode2.putPOJO("location", locationJsonNode); /** * creating alarm json object using properties file value */ + String alarmStringValue = refProp.getStringValue("ui.alarm.default"); logger.info("value of alarm: {}", alarmStringValue); - ObjectNode alarmStringJsonNode = (ObjectNode) mapper.readValue(alarmStringValue, JsonNode.class); + ObjectNode alarmStringJsonNode; + try { + alarmStringJsonNode = (ObjectNode) mapper.readValue(alarmStringValue, JsonNode.class); + } catch (IOException e) { + logger.error("Unable to ui.alarm.default JSON in clds-references.properties properly", e); + throw new CldsConfigException("Unable to load ui.alarm.default JSON in clds-references.properties properly", + e); + } vfObjectNode2.putPOJO("alarmCondition", alarmStringJsonNode); + } private ObjectNode createByVFCObjectNode(ObjectMapper mapper, List<CldsSdcResource> cldsSdcResourceList) { @@ -895,10 +885,9 @@ public class CldsService extends SecureServiceBase { vfCObjectNode.putPOJO("vfC", emptyObjectNode); ObjectNode subVfCObjectNode = mapper.createObjectNode(); subVfCObjectNode.putPOJO("vfc", emptyObjectNode); - if (cldsSdcResourceList != null && cldsSdcResourceList.size() > 0) { + if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) { for (CldsSdcResource cldsSdcResource : cldsSdcResourceList) { - if (cldsSdcResource != null && cldsSdcResource.getResoucreType() != null - && cldsSdcResource.getResoucreType().equalsIgnoreCase("VF")) { + if (cldsSdcResource != null && "VF".equalsIgnoreCase(cldsSdcResource.getResoucreType())) { vfCObjectNode.putPOJO(cldsSdcResource.getResourceUUID(), subVfCObjectNode); } } @@ -920,14 +909,14 @@ public class CldsService extends SecureServiceBase { model.getTypeId()); String operationStatus = "processing"; long waitingTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(10); - while (operationStatus.equalsIgnoreCase("processing")) { + while ("processing".equalsIgnoreCase(operationStatus)) { // Break the loop if waiting for more than 10 mins if (waitingTime < System.nanoTime()) { break; } operationStatus = dcaeDispatcherServices.getOperationStatus(createNewDeploymentStatusUrl); } - if (operationStatus.equalsIgnoreCase("succeeded")) { + if ("succeeded".equalsIgnoreCase(operationStatus)) { String artifactName = model.getControlName(); if (artifactName != null) { artifactName = artifactName + ".yml"; @@ -958,20 +947,20 @@ public class CldsService extends SecureServiceBase { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public CldsModel unDeployModel(@PathParam("action") String action, @PathParam("modelName") String modelName, - @QueryParam("test") String test, CldsModel model) throws Exception { + @QueryParam("test") String test, CldsModel model) throws IOException { Date startTime = new Date(); LoggingUtils.setRequestContext("CldsService: Undeploy model", getPrincipalName()); String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(), model.getTypeId()); String operationStatus = "processing"; long waitingTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(10); - while (operationStatus.equalsIgnoreCase("processing")) { + while ("processing".equalsIgnoreCase(operationStatus)) { if (waitingTime < System.nanoTime()) { break; } operationStatus = dcaeDispatcherServices.getOperationStatus(operationStatusUndeployUrl); } - if (operationStatus.equalsIgnoreCase("succeeded")) { + if ("succeeded".equalsIgnoreCase(operationStatus)) { String artifactName = model.getControlName(); if (artifactName != null) { artifactName = artifactName + ".yml"; @@ -997,11 +986,16 @@ public class CldsService extends SecureServiceBase { return model; } - private String getGlobalCldsString() throws Exception { - if (null == globalCldsProperties) { - globalCldsProperties = new Properties(); - globalCldsProperties.load(appContext.getResource(globalClds).getInputStream()); + private String getGlobalCldsString() { + try { + if (null == globalCldsProperties) { + globalCldsProperties = new Properties(); + globalCldsProperties.load(appContext.getResource(globalClds).getInputStream()); + } + return (String) globalCldsProperties.get("globalCldsProps"); + } catch (IOException e) { + logger.error("Unable to load the globalClds due to an exception", e); + throw new CldsConfigException("Unable to load the globalClds due to an exception", e); } - return (String) globalCldsProperties.get("globalCldsProps"); } } diff --git a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java index 07b9bb98f..87f9c0c4f 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java @@ -23,6 +23,14 @@ package org.onap.clamp.clds.service; +import com.att.ajsc.common.AjscService; +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 java.io.IOException; import java.util.Date; import java.util.HashMap; @@ -51,16 +59,6 @@ import org.onap.clamp.clds.util.LoggingUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import com.att.ajsc.common.AjscService; -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; - /** * Service to save and retrieve the CLDS model attributes. */ @@ -68,12 +66,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode; @Path("/cldsTempate") public class CldsTemplateService extends SecureServiceBase { - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsTemplateService.class); - protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); - - private static final String collectorKey = "Collector"; - private static final String stringMatchKey = "StringMatch"; - private static final String policyKey = "Policy"; + private static final String COLLECTOR_KEY = "Collector"; + private static final String STRING_MATCH_KEY = "StringMatch"; + private static final String POLICY_KEY = "Policy"; @Value("${CLDS_PERMISSION_TYPE_TEMPLATE:permission-type-template}") private String cldsPermissionTypeTemplate; @@ -309,7 +304,7 @@ public class CldsTemplateService extends SecureServiceBase { logger.info("value of elementIds:" + bpmnElementIds); logger.info("value of prop text:" + propText); Map<String, String> bpmnIoIdsMap = new HashMap<>(); - if (bpmnElementIds != null && bpmnElementIds.size() > 0) { + if (bpmnElementIds != null && !bpmnElementIds.isEmpty()) { ObjectMapper objectMapper = new ObjectMapper(); ObjectNode root = objectMapper.readValue(propText, ObjectNode.class); Iterator<Entry<String, JsonNode>> entryItr = root.fields(); @@ -326,12 +321,12 @@ public class CldsTemplateService extends SecureServiceBase { ObjectNode node = (ObjectNode) anArrayNode; String valueNode = node.get("value").asText(); logger.info("value of node:" + valueNode); - if (keyPropName.startsWith(collectorKey)) { - valueNode = collectorKey + "_" + valueNode; - } else if (keyPropName.startsWith(stringMatchKey)) { - valueNode = stringMatchKey + "_" + valueNode; - } else if (keyPropName.startsWith(policyKey)) { - valueNode = policyKey + "_" + valueNode; + if (keyPropName.startsWith(COLLECTOR_KEY)) { + valueNode = COLLECTOR_KEY + "_" + valueNode; + } else if (keyPropName.startsWith(STRING_MATCH_KEY)) { + valueNode = STRING_MATCH_KEY + "_" + valueNode; + } else if (keyPropName.startsWith(POLICY_KEY)) { + valueNode = POLICY_KEY + "_" + valueNode; } bpmnIoIdsMap.put(keyPropName, valueNode); } diff --git a/src/main/java/org/onap/clamp/clds/transform/TransformUtil.java b/src/main/java/org/onap/clamp/clds/util/ResourceFileUtil.java index 2c152c5a1..0aaa09ac2 100644 --- a/src/main/java/org/onap/clamp/clds/transform/TransformUtil.java +++ b/src/main/java/org/onap/clamp/clds/util/ResourceFileUtil.java @@ -21,7 +21,7 @@ * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ -package org.onap.clamp.clds.transform; +package org.onap.clamp.clds.util; import java.io.IOException; import java.io.InputStream; @@ -29,7 +29,14 @@ import java.io.InputStream; /** * Utility methods supporting transforms. */ -public class TransformUtil { +public class ResourceFileUtil { + + /** + * Disable the ResourceFileUtil constructor. + */ + private ResourceFileUtil() { + + } /** * Return resource as a Stream. diff --git a/src/test/java/org/onap/clamp/clds/it/DcaeIT.java b/src/test/java/org/onap/clamp/clds/it/DcaeIT.java index 6cdcf98d6..fc13270c3 100644 --- a/src/test/java/org/onap/clamp/clds/it/DcaeIT.java +++ b/src/test/java/org/onap/clamp/clds/it/DcaeIT.java @@ -30,8 +30,7 @@ import org.onap.clamp.clds.AbstractIT; import org.onap.clamp.clds.client.req.DcaeReq; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.prop.ModelProperties; -import org.onap.clamp.clds.transform.TransformUtil; - +import org.onap.clamp.clds.util.ResourceFileUtil; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.test.context.junit4.SpringRunner; @@ -45,8 +44,8 @@ public class DcaeIT extends AbstractIT { @Test public void testDcaeReq() throws Exception { - String modelProp = TransformUtil.getResourceAsString("example/modelProp.json"); - String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnProp.json"); + String modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json"); + String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json"); String modelName = "example-model"; String controlName = "ClosedLoop-FRWL-SIG-1582f840-2881-11e6-b4ec-005056a9d756"; diff --git a/src/test/java/org/onap/clamp/clds/it/PolicyClientIT.java b/src/test/java/org/onap/clamp/clds/it/PolicyClientIT.java index c0487e915..19fad4805 100644 --- a/src/test/java/org/onap/clamp/clds/it/PolicyClientIT.java +++ b/src/test/java/org/onap/clamp/clds/it/PolicyClientIT.java @@ -43,7 +43,7 @@ import org.onap.clamp.clds.model.prop.Policy; import org.onap.clamp.clds.model.prop.PolicyChain; import org.onap.clamp.clds.model.prop.StringMatch; import org.onap.clamp.clds.model.prop.Tca; -import org.onap.clamp.clds.transform.TransformUtil; +import org.onap.clamp.clds.util.ResourceFileUtil; import org.onap.policy.api.AttributeType; import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.boot.test.context.SpringBootTest; @@ -62,14 +62,13 @@ public class PolicyClientIT extends AbstractIT { String modelName; String controlName; - /** - * Initialize Test. - */ + * Initialize Test. + */ @Before public void setUp() throws IOException { - modelProp = TransformUtil.getResourceAsString("example/modelProp.json"); - modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnProp.json"); + modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json"); + modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json"); modelName = "example-model06"; controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf"; } @@ -81,11 +80,11 @@ public class PolicyClientIT extends AbstractIT { String stringMatchPolicyRequestUuid = UUID.randomUUID().toString(); String policyJson = StringMatchPolicyReq.format(refProp, prop); - String correctValue = TransformUtil.getResourceAsString("expected/stringmatch.json"); + String correctValue = ResourceFileUtil.getResourceAsString("expected/stringmatch.json"); JSONAssert.assertEquals(policyJson, correctValue, true); String responseMessage = ""; try { - responseMessage = policyClient.sendMicroService(policyJson, prop, stringMatchPolicyRequestUuid); + responseMessage = policyClient.sendMicroServiceInJson(policyJson, prop, stringMatchPolicyRequestUuid); } catch (Exception e) { assertTrue(e.getMessage().contains("Policy send failed: PE500 ")); } @@ -102,7 +101,7 @@ public class PolicyClientIT extends AbstractIT { Map<AttributeType, Map<String, String>> attributes = OperationalPolicyReq.formatAttributes(refProp, prop, policy.getId(), policyChain); - String responseMessage = policyClient.sendBrms(attributes, prop, operationalPolicyRequestUuid); + String responseMessage = policyClient.sendBrmsPolicy(attributes, prop, operationalPolicyRequestUuid); System.out.println(responseMessage); } } @@ -110,15 +109,15 @@ public class PolicyClientIT extends AbstractIT { private void createUpdateTcaPolicy(String actionCd) throws Exception { ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp); - Tca tca = prop.getTca(); + Tca tca = prop.getType(Tca.class); if (tca.isFound()) { String tcaPolicyRequestUuid = UUID.randomUUID().toString(); String policyJson = TcaMPolicyReq.formatTca(refProp, prop); - String correctValue = TransformUtil.getResourceAsString("expected/tca.json"); + String correctValue = ResourceFileUtil.getResourceAsString("expected/tca.json"); JSONAssert.assertEquals(policyJson, correctValue, true); String responseMessage = ""; try { - responseMessage = policyClient.sendMicroService(policyJson, prop, tcaPolicyRequestUuid); + responseMessage = policyClient.sendMicroServiceInJson(policyJson, prop, tcaPolicyRequestUuid); } catch (Exception e) { assertTrue(e.getMessage().contains("Policy send failed: PE500 ")); } @@ -159,7 +158,7 @@ public class PolicyClientIT extends AbstractIT { private void deleteTcaPolicy(String actionCd) throws Exception { ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp); - Tca tca = prop.getTca(); + Tca tca = prop.getType(Tca.class); if (tca.isFound()) { prop.setCurrentModelElementId(tca.getId()); String responseMessage = ""; diff --git a/src/test/java/org/onap/clamp/clds/it/SdcIT.java b/src/test/java/org/onap/clamp/clds/it/SdcIT.java index 62932f82a..da9e5af76 100644 --- a/src/test/java/org/onap/clamp/clds/it/SdcIT.java +++ b/src/test/java/org/onap/clamp/clds/it/SdcIT.java @@ -33,8 +33,7 @@ import org.onap.clamp.clds.client.req.SdcReq; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.prop.ModelProperties; import org.onap.clamp.clds.model.refprop.RefProp; -import org.onap.clamp.clds.transform.TransformUtil; - +import org.onap.clamp.clds.util.ResourceFileUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -58,11 +57,11 @@ public class SdcIT extends AbstractIT { @Test public void testBlueprint() throws Exception { - String modelProp = TransformUtil.getResourceAsString("example/modelProp.json"); - String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnProp.json"); + String modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json"); + String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json"); String modelName = "example-model06"; String controlName = "ClosedLoop-FRWL-SIG04-1582f840-test-test-1234-005056a9d756"; - String docText = TransformUtil.getResourceAsString("example/templateProp.json"); + String docText = ResourceFileUtil.getResourceAsString("example/templateProp.json"); ModelProperties prop = new ModelProperties(modelName, controlName, CldsEvent.ACTION_SUBMIT, true, modelBpmnProp, modelProp); String blueprint = SdcReq.formatBlueprint(refProp, prop, docText); @@ -73,11 +72,11 @@ public class SdcIT extends AbstractIT { @Test public void testTcaBlueprint() throws Exception { - String modelProp = TransformUtil.getResourceAsString("example/modelPropForPolicy.json"); - String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnPropForPolicy.json"); + String modelProp = ResourceFileUtil.getResourceAsString("example/modelPropForPolicy.json"); + String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnPropForPolicy.json"); String modelName = "example-model06"; String controlName = "ClosedLoop-FRWL-SIG04-1582f840-test-test-1234-005056a9d756"; - String docText = TransformUtil.getResourceAsString("example/templatePropForTca.json"); + String docText = ResourceFileUtil.getResourceAsString("example/templatePropForTca.json"); ModelProperties prop = new ModelProperties(modelName, controlName, CldsEvent.ACTION_SUBMIT, true, modelBpmnProp, modelProp); String blueprint = SdcReq.formatBlueprint(refProp, prop, docText); diff --git a/src/test/java/org/onap/clamp/clds/model/prop/CustomModelElementTest.java b/src/test/java/org/onap/clamp/clds/model/prop/CustomModelElementTest.java index 9c9cb4a73..89eaf51cd 100644 --- a/src/test/java/org/onap/clamp/clds/model/prop/CustomModelElementTest.java +++ b/src/test/java/org/onap/clamp/clds/model/prop/CustomModelElementTest.java @@ -27,7 +27,7 @@ import java.io.IOException; import org.junit.Assert;
import org.junit.Test;
-import org.onap.clamp.clds.transform.TransformUtil;
+import org.onap.clamp.clds.util.ResourceFileUtil;
public class CustomModelElementTest {
@@ -38,8 +38,8 @@ public class CustomModelElementTest { public void testNewElement() {
try {
- String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnProp.json");
- String modelProp = TransformUtil.getResourceAsString("example/modelProp.json");
+ String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json");
+ String modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json");
String modName = "example-model-name";
String controlName = "example-control-name";
diff --git a/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java b/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java index c1c4a8c39..22b3ba0cb 100644 --- a/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java +++ b/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java @@ -29,8 +29,7 @@ import java.io.IOException; import org.junit.Assert; import org.junit.Test; - -import org.onap.clamp.clds.transform.TransformUtil; +import org.onap.clamp.clds.util.ResourceFileUtil; /** @@ -40,8 +39,8 @@ public class ModelPropertiesTest { @Test public void testJsonParse() throws IOException { - String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnProp.json"); - String modelProp = TransformUtil.getResourceAsString("example/modelProp.json"); + String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json"); + String modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json"); String modName = "example-model-name"; String controlName = "example-control-name"; @@ -68,10 +67,10 @@ public class ModelPropertiesTest { @Test public void testPolicy() throws IOException { - String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnPropForPolicy.json"); + String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnPropForPolicy.json"); System.out.println(modelBpmnProp); - String modelProp = TransformUtil.getResourceAsString("example/modelPropForPolicy.json"); + String modelProp = ResourceFileUtil.getResourceAsString("example/modelPropForPolicy.json"); System.out.println(modelProp); ModelProperties prop = new ModelProperties("example-model-name", "example-control-name", null, true, modelBpmnProp, modelProp); |