summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2017-09-08 17:48:10 +0200
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2017-09-08 17:48:10 +0200
commit02847bc3889fe3c3a419612ea7a94eca8794bdc6 (patch)
tree20ac643bcffdb9f5cdecaf2cf242e3b7d710dde7 /src/main
parent15383eb639c7b78f21c0a969099642f3518bbf80 (diff)
Rework some sonar critical and major bugs
Class renamed to AbstractModelELement, exceptions reworked and IT tests as well Change-Id: Ief2b09b0e36776519338834e2af61aa6e638ee91 Issue-Id: CLAMP-43 Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegate.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/client/PolicyClient.java157
-rw-r--r--src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java344
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java4
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/SdcReq.java34
-rw-r--r--src/main/java/org/onap/clamp/clds/config/CldsConfiguration.java9
-rw-r--r--src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java8
-rw-r--r--src/main/java/org/onap/clamp/clds/dao/CldsDao.java23
-rw-r--r--src/main/java/org/onap/clamp/clds/exception/policy/PolicyClientException.java61
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/AbstractModelElement.java280
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/Collector.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/Global.java10
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/Holmes.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/ModelProperties.java14
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/Policy.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java6
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java12
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/ResourceGroup.java4
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/ServiceConfiguration.java16
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/StringMatch.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/Tca.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/TcaItem.java20
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsService.java10
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsUser.java2
25 files changed, 686 insertions, 342 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java
index db7b5241b..c42a22c61 100644
--- a/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java
@@ -61,7 +61,7 @@ public class HolmesPolicyDelegate implements JavaDelegate {
ModelProperties prop = ModelProperties.create(execution);
Holmes holmes = prop.getType(Holmes.class);
if (holmes.isFound()) {
- String responseMessage = policyClient.sendMicroServiceInJson(holmes.getCorrelationLogic(), prop,
+ String responseMessage = policyClient.sendBasePolicyInOther(holmes.getCorrelationLogic(), prop,
holmesPolicyRequestUuid);
if (responseMessage != null) {
execution.setVariable("holmesPolicyResponseMessage", responseMessage.getBytes());
diff --git a/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegate.java b/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegate.java
index 46b33ffea..c3c91fa88 100644
--- a/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegate.java
@@ -55,7 +55,7 @@ public class HolmesPolicyDeleteDelegate implements JavaDelegate {
if (holmes.isFound()) {
prop.setCurrentModelElementId(holmes.getId());
- policyClient.deleteMicrosService(prop);
+ policyClient.deleteBasePolicy(prop);
}
}
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 2b49a8ff5..2bd680af2 100644
--- a/src/main/java/org/onap/clamp/clds/client/PolicyClient.java
+++ b/src/main/java/org/onap/clamp/clds/client/PolicyClient.java
@@ -31,13 +31,13 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.ws.rs.BadRequestException;
+import org.onap.clamp.clds.exception.policy.PolicyClientException;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.refprop.RefProp;
import org.onap.clamp.clds.util.LoggingUtils;
@@ -47,6 +47,7 @@ import org.onap.policy.api.DeletePolicyCondition;
import org.onap.policy.api.DeletePolicyParameters;
import org.onap.policy.api.PolicyChangeResponse;
import org.onap.policy.api.PolicyConfig;
+import org.onap.policy.api.PolicyConfigException;
import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyEngine;
import org.onap.policy.api.PolicyEngineException;
@@ -66,11 +67,11 @@ public class PolicyClient {
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 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 metricsLogger = EELFManager.getInstance().getMetricsLogger();
@Value("${org.onap.clamp.config.files.cldsPolicyConfig:'classpath:/clds/clds-policy-config.properties'}")
protected String cldsPolicyConfigFile;
@@ -91,14 +92,10 @@ public class PolicyClient {
* @param policyRequestUuid
* PolicyRequest UUID
* @return The response message of policy
- * @throws IOException
- * In case of issues with the Stream
- * @throws PolicyEngineException
- * In case of issues with the PolicyEngine class
*
*/
public String sendBrmsPolicy(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop,
- String policyRequestUuid) throws PolicyEngineException, IOException {
+ String policyRequestUuid) {
PolicyParameters policyParameters = new PolicyParameters();
@@ -136,13 +133,8 @@ public class PolicyClient {
* @param policyRequestUuid
* The policy Request UUID
* @return The response message of policy
- * @throws PolicyEngineException
- * In case of issues with the policy engine class creation
- * @throws IOException
- * In case of issue with the Stream
*/
- public String sendMicroServiceInJson(String policyJson, ModelProperties prop, String policyRequestUuid)
- throws IOException, PolicyEngineException {
+ public String sendMicroServiceInJson(String policyJson, ModelProperties prop, String policyRequestUuid) {
PolicyParameters policyParameters = new PolicyParameters();
@@ -177,14 +169,9 @@ public class PolicyClient {
* 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
+ * @return The answer from policy call
*/
- public String sendBasePolicyInOther(String configBody, ModelProperties prop, String policyRequestUuid)
- throws IOException, PolicyEngineException {
+ public String sendBasePolicyInOther(String configBody, ModelProperties prop, String policyRequestUuid) {
PolicyParameters policyParameters = new PolicyParameters();
@@ -216,22 +203,15 @@ public class PolicyClient {
* The PolicyParameters
* @param prop
* The ModelProperties
- * @return THe response message of Policy
- * @throws IOException
- * In case of issues with the Stream
- * @throws PolicyEngineException
- * In case of issue when creating PolicyEngine class
+ * @return The response message of Policy
+ * @throws Exception
*/
- protected String send(PolicyParameters policyParameters, ModelProperties prop, String policyNamePrefix)
- throws IOException, PolicyEngineException {
+ protected String send(PolicyParameters policyParameters, ModelProperties prop, String policyNamePrefix) {
// Verify whether it is triggered by Validation Test button from UI
if (prop.isTest()) {
return "send not executed for test action";
}
- PolicyEngine policyEngine = new PolicyEngine(
- appContext.getResource(cldsPolicyConfigFile).getFile().getAbsolutePath());
-
// API method to create or update Policy.
PolicyChangeResponse response = null;
String responseMessage = "";
@@ -241,22 +221,23 @@ public class PolicyClient {
if (versions.isEmpty()) {
LoggingUtils.setTargetContext("Policy", "createPolicy");
logger.info("Attempting to create policy for action=" + prop.getActionCd());
- response = policyEngine.createPolicy(policyParameters);
+ response = getPolicyEngine().createPolicy(policyParameters);
responseMessage = response.getResponseMessage();
} else {
LoggingUtils.setTargetContext("Policy", "updatePolicy");
logger.info("Attempting to update policy for action=" + prop.getActionCd());
- response = policyEngine.updatePolicy(policyParameters);
+ response = getPolicyEngine().updatePolicy(policyParameters);
responseMessage = response.getResponseMessage();
}
} catch (Exception e) {
logger.error("Exception occurred during policy communication", e);
+ throw new PolicyClientException("Exception while communicating with Policy", e);
}
logger.info(LOG_POLICY_PREFIX + responseMessage);
LoggingUtils.setTimeContext(startTime, new Date());
- if (response != null && response.getResponseCode() == 200) {
+ if (response.getResponseCode() == 200) {
logger.info("Policy send successful");
metricsLogger.info("Policy send success");
} else {
@@ -276,12 +257,8 @@ public class PolicyClient {
* @param prop
* The ModelProperties
* @return The response message of policy
- * @throws IOException
- * In case of issues with the stream
- * @throws PolicyEngineException
- * In case of issues with the PolicyEngine creation
*/
- protected String push(String policyType, ModelProperties prop) throws PolicyEngineException, IOException {
+ protected String push(String policyType, ModelProperties prop) {
// Verify whether it is triggered by Validation Test button from UI
if (prop.isTest()) {
return "push not executed for test action";
@@ -301,15 +278,12 @@ public class PolicyClient {
pushPolicyParameters.setPdpGroup(refProp.getStringValue("policy.pdp.group"));
pushPolicyParameters.setRequestID(null);
- PolicyEngine policyEngine = new PolicyEngine(
- appContext.getResource(cldsPolicyConfigFile).getFile().getAbsolutePath());
-
// API method to create or update Policy.
PolicyChangeResponse response = null;
String responseMessage = "";
try {
logger.info("Attempting to push policy...");
- response = policyEngine.pushPolicy(pushPolicyParameters);
+ response = getPolicyEngine().pushPolicy(pushPolicyParameters);
responseMessage = response.getResponseMessage();
} catch (Exception e) {
logger.error("Exception occurred during policy communication", e);
@@ -335,13 +309,10 @@ public class PolicyClient {
* @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 creation
+ * @throws PolicyConfigException
+ * In case of issues with policy engine
*/
- protected List<Integer> getVersions(String policyNamePrefix, ModelProperties prop)
- throws PolicyEngineException, IOException {
+ protected List<Integer> getVersions(String policyNamePrefix, ModelProperties prop) throws PolicyConfigException {
ArrayList<Integer> versions = new ArrayList<>();
ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
@@ -356,46 +327,42 @@ public class PolicyClient {
logger.info("policyName=" + policyName);
configRequestParameters.setPolicyName(policyName);
- PolicyEngine policyEngine = new PolicyEngine(
- appContext.getResource(cldsPolicyConfigFile).getFile().getAbsolutePath());
-
- try {
- Collection<PolicyConfig> response = policyEngine.getConfig(configRequestParameters);
- Iterator<PolicyConfig> itrResp = response.iterator();
-
- while (itrResp.hasNext()) {
- PolicyConfig policyConfig = itrResp.next();
- try {
- Integer version = new Integer(policyConfig.getPolicyVersion());
- versions.add(version);
- } catch (Exception e) {
- // just print warning - if n;o policies, version may be null
- logger.warn("Failed to parse due to an exception policyConfig.getPolicyVersion()="
- + policyConfig.getPolicyVersion(), e);
- }
- }
- Collections.sort(versions);
- logger.info("Policy versions.size()=" + versions.size());
- } catch (Exception e) {
- // just print warning - if no policy version found
- logger.warn("warning: policy not found...policy name - " + policyName, e);
+ Collection<PolicyConfig> response = getPolicyEngine().getConfig(configRequestParameters);
+ for (PolicyConfig policyConfig : response) {
+ Integer version = Integer.valueOf(policyConfig.getPolicyVersion());
+ versions.add(version);
}
+ Collections.sort(versions);
+ logger.info("Policy versions.size()=" + versions.size());
return versions;
}
/**
+ * This method create a new policy engine.
+ *
+ * @return A new policy engine
+ */
+ private PolicyEngine getPolicyEngine() {
+ PolicyEngine policyEngine;
+ try {
+ policyEngine = new PolicyEngine(appContext.getResource(cldsPolicyConfigFile).getFile().getAbsolutePath());
+ } catch (IOException e1) {
+ throw new PolicyClientException("Exception when opening policy config file", e1);
+ } catch (PolicyEngineException e) {
+ throw new PolicyClientException("Exception when creating a new policy engine", e);
+ }
+ return policyEngine;
+ }
+
+ /**
* Format and send delete Micro Service requests to Policy.
*
* @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 creation
*/
- public String deleteMicrosService(ModelProperties prop) throws PolicyEngineException, IOException {
+ public String deleteMicrosService(ModelProperties prop) {
String policyType = refProp.getStringValue("policy.ms.type");
return deletePolicy(prop, policyType);
}
@@ -403,12 +370,11 @@ public class PolicyClient {
/**
* This method delete the Base policy.
*
- * @param prop The model Properties
+ * @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 {
+ public String deleteBasePolicy(ModelProperties prop) {
return deletePolicy(prop, PolicyConfigType.Base.toString());
}
@@ -418,12 +384,8 @@ public class PolicyClient {
* @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 creation
*/
- public String deleteBrms(ModelProperties prop) throws PolicyEngineException, IOException {
+ public String deleteBrms(ModelProperties prop) {
String policyType = refProp.getStringValue("policy.op.type");
return deletePolicy(prop, policyType);
}
@@ -435,12 +397,8 @@ public class PolicyClient {
* 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(ModelProperties prop, String policyType) throws PolicyEngineException, IOException {
+ protected String deletePolicy(ModelProperties prop, String policyType) {
DeletePolicyParameters deletePolicyParameters = new DeletePolicyParameters();
if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
@@ -454,16 +412,16 @@ public class PolicyClient {
deletePolicyParameters.setPdpGroup(refProp.getStringValue("policy.pdp.group"));
deletePolicyParameters.setPolicyType(policyType);
// send delete request
- String responseMessage = sendDeletePolicy(deletePolicyParameters, prop);
+ StringBuilder responseMessage = new StringBuilder(sendDeletePolicy(deletePolicyParameters, prop));
logger.info("Deleting policy from PAP...");
deletePolicyParameters.setPolicyComponent("PAP");
deletePolicyParameters.setDeleteCondition(DeletePolicyCondition.ALL);
// send delete request
- responseMessage = sendDeletePolicy(deletePolicyParameters, prop);
+ responseMessage.append(sendDeletePolicy(deletePolicyParameters, prop));
- return responseMessage;
+ return responseMessage.toString();
}
/**
@@ -474,26 +432,19 @@ public class PolicyClient {
* @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 PolicyEngine class creation
*/
- protected String sendDeletePolicy(DeletePolicyParameters deletePolicyParameters, ModelProperties prop)
- throws PolicyEngineException, IOException {
+ protected String sendDeletePolicy(DeletePolicyParameters deletePolicyParameters, ModelProperties prop) {
// Verify whether it is triggered by Validation Test button from UI
if (prop.isTest()) {
return "delete not executed for test action";
}
- PolicyEngine policyEngine = new PolicyEngine(
- appContext.getResource(cldsPolicyConfigFile).getFile().getAbsolutePath());
// API method to create or update Policy.
PolicyChangeResponse response = null;
String responseMessage = "";
try {
logger.info("Attempting to delete policy...");
- response = policyEngine.deletePolicy(deletePolicyParameters);
+ response = getPolicyEngine().deletePolicy(deletePolicyParameters);
responseMessage = response.getResponseMessage();
} catch (Exception e) {
logger.error("Exception occurred during policy communnication", e);
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 d418ea55b..d31767150 100644
--- a/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java
@@ -25,7 +25,6 @@ package org.onap.clamp.clds.client;
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.ArrayNode;
@@ -53,6 +52,7 @@ 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.exception.SdcCommunicationException;
import org.onap.clamp.clds.model.CldsAlarmCondition;
import org.onap.clamp.clds.model.CldsDBServiceCache;
import org.onap.clamp.clds.model.CldsSdcArtifact;
@@ -137,7 +137,7 @@ public class SdcCatalogServices {
*/
public List<CldsSdcServiceInfo> removeDuplicateServices(List<CldsSdcServiceInfo> rawCldsSdcServiceList) {
List<CldsSdcServiceInfo> cldsSdcServiceInfoList = null;
- if (rawCldsSdcServiceList != null && rawCldsSdcServiceList.size() > 0) {
+ if (rawCldsSdcServiceList != null && !rawCldsSdcServiceList.isEmpty()) {
// sort list
Collections.sort(rawCldsSdcServiceList);
// and then take only the services with the max version (last in the
@@ -165,7 +165,7 @@ public class SdcCatalogServices {
*/
public List<CldsSdcResource> removeDuplicateSdcResourceInstances(List<CldsSdcResource> rawCldsSdcResourceList) {
List<CldsSdcResource> cldsSdcResourceList = null;
- if (rawCldsSdcResourceList != null && rawCldsSdcResourceList.size() > 0) {
+ if (rawCldsSdcResourceList != null && !rawCldsSdcResourceList.isEmpty()) {
// sort list
Collections.sort(rawCldsSdcResourceList);
// and then take only the resources with the max version (last in
@@ -194,7 +194,7 @@ public class SdcCatalogServices {
public List<CldsSdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(
List<CldsSdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {
List<CldsSdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;
- if (rawCldsSdcResourceListBasicList != null && rawCldsSdcResourceListBasicList.size() > 0) {
+ if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) {
// sort list
Collections.sort(rawCldsSdcResourceListBasicList);
// and then take only the resources with the max version (last in
@@ -221,15 +221,13 @@ public class SdcCatalogServices {
* @param invariantId
* The invariant ID
* @return The service UUID
- * @throws IOException
- * In case of issues with the JSON decoder
*/
- public String getServiceUuidFromServiceInvariantId(String invariantId) throws IOException {
+ public String getServiceUuidFromServiceInvariantId(String invariantId) {
String serviceUuid = "";
String responseStr = getSdcServicesInformation(null);
List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);
List<CldsSdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);
- if (cldsSdcServicesList != null && cldsSdcServicesList.size() > 0) {
+ if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {
for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {
if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null
&& currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {
@@ -245,32 +243,45 @@ public class SdcCatalogServices {
* To get CldsAsdsServiceInfo class by parsing json string.
*
* @param jsonStr
- * @return
- * @throws IOException
+ * The Json string that must be decoded
+ * @return The list of CldsSdcServiceInfo, if there is a failure it return
+ * an empty list
*/
- public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) throws IOException {
+ public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {
ObjectMapper objectMapper = new ObjectMapper();
if (StringUtils.isBlank(jsonStr)) {
- return null;
+ return new ArrayList<>();
+ }
+ try {
+ return objectMapper.readValue(jsonStr,
+ objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));
+ } catch (IOException e) {
+ logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);
+ return new ArrayList<>();
}
- return objectMapper.readValue(jsonStr,
- objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));
}
/**
* To get List of CldsSdcResourceBasicInfo class by parsing json string.
*
* @param jsonStr
- * @return
- * @throws IOException
+ * The JSOn string that must be decoded
+ * @return The list of CldsSdcResourceBasicInfo, an empty list in case of
+ * issues
*/
- public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) throws IOException {
+ public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {
ObjectMapper objectMapper = new ObjectMapper();
if (StringUtils.isBlank(jsonStr)) {
- return null;
+ return new ArrayList<>();
+ }
+
+ try {
+ return objectMapper.readValue(jsonStr,
+ objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));
+ } catch (IOException e) {
+ logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);
+ return new ArrayList<>();
}
- return objectMapper.readValue(jsonStr,
- objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));
}
/**
@@ -290,76 +301,86 @@ public class SdcCatalogServices {
*
* @param jsonStr
* @return
- * @throws IOException
*/
- public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) throws IOException {
+ public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) {
ObjectMapper objectMapper = new ObjectMapper();
- return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);
+ try {
+ return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);
+ } catch (IOException e) {
+ logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e);
+ return null;
+ }
}
/**
- * To upload artifact to sdc based on serviceUUID and resourcename on url.
+ * To upload artifact to sdc based on serviceUUID and resource name on url.
*
* @param prop
* @param userid
* @param url
- * @param formatttedSdcReq
+ * @param formattedSdcReq
* @return
- * @throws IOException
*/
- public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatttedSdcReq)
- throws IOException {
+ public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatttedSdcReq) {
// 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(formatttedSdcReq);
- byte[] postData = SdcReq.stringToByteArray(formatttedSdcReq);
- int postDataLength = postData.length;
- HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text);
- try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
- wr.write(postData);
- }
- boolean requestFailed = true;
- int responseCode = conn.getResponseCode();
- logger.info("responseCode=" + responseCode);
- if (responseCode == 200) {
- requestFailed = false;
- }
+ try {
+ logger.info("userid=" + userid);
+ String md5Text = SdcReq.calculateMD5ByString(formatttedSdcReq);
+ byte[] postData = SdcReq.stringToByteArray(formatttedSdcReq);
+ int postDataLength = postData.length;
+ HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text);
+ try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
+ wr.write(postData);
+ }
+ boolean requestFailed = true;
+ int responseCode = conn.getResponseCode();
+ logger.info("responseCode=" + responseCode);
+ if (responseCode == 200) {
+ requestFailed = false;
+ }
- String responseStr = getResponse(conn);
- if (responseStr != null) {
- if (requestFailed) {
+ String responseStr = getResponse(conn);
+ if (responseStr != null && requestFailed) {
logger.error("requestFailed - responseStr=" + responseStr);
throw new BadRequestException(responseStr);
}
+ return responseStr;
+ } catch (IOException e) {
+ logger.error("Exception when attempting to communicate with SDC", e);
+ throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e);
}
- return responseStr;
+
}
- private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text)
- throws IOException {
- logger.info("userid=" + userid);
- 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(refProp.getStringValue("sdc.InstanceID"), sdcXonapInstanceId);
- conn.setRequestProperty("Authorization", basicAuth);
- conn.setRequestProperty("Content-Type", "application/json");
- conn.setRequestProperty("Content-MD5", md5Text);
- conn.setRequestProperty("USER_ID", userid);
- conn.setRequestMethod("POST");
- conn.setRequestProperty("charset", "utf-8");
- conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
- conn.setUseCaches(false);
- conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());
- return conn;
+ private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text) {
+ try {
+ logger.info("userid=" + userid);
+ 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(refProp.getStringValue("sdc.InstanceID"), sdcXonapInstanceId);
+ conn.setRequestProperty("Authorization", basicAuth);
+ conn.setRequestProperty("Content-Type", "application/json");
+ conn.setRequestProperty("Content-MD5", md5Text);
+ conn.setRequestProperty("USER_ID", userid);
+ conn.setRequestMethod("POST");
+ conn.setRequestProperty("charset", "utf-8");
+ conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
+ conn.setUseCaches(false);
+ conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());
+ return conn;
+ } catch (IOException e) {
+ logger.error("Exception when attempting to open connection with SDC", e);
+ throw new SdcCommunicationException("Exception when attempting to open connection with SDC", e);
+ }
}
- private String getResponse(HttpURLConnection conn) throws IOException {
+ private String getResponse(HttpURLConnection conn) {
try (InputStream is = getInputStream(conn)) {
if (is != null) {
try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {
@@ -370,29 +391,42 @@ public class SdcCatalogServices {
}
return response.toString();
}
+ } else {
+ return null;
}
+ } catch (IOException e) {
+ logger.error("Exception when attempting to open SDC response", e);
+ throw new SdcCommunicationException("Exception when attempting to open SDC response", e);
}
- return null;
}
- private InputStream getInputStream(HttpURLConnection conn) throws IOException {
- InputStream inStream = conn.getErrorStream();
- if (inStream == null) {
- inStream = conn.getInputStream();
+ private InputStream getInputStream(HttpURLConnection conn) {
+ try {
+ InputStream inStream = conn.getErrorStream();
+ if (inStream == null) {
+ inStream = conn.getInputStream();
+ }
+ return inStream;
+ } catch (IOException e) {
+ logger.error("Exception when attempting to open SDC error stream", e);
+ throw new SdcCommunicationException("Exception when attempting to open SDC error stream", e);
}
- return inStream;
}
- public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData)
- throws IOException {
- CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache();
- cldsDbServiceCache.setCldsDataInstream(cldsServiceData);
- cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID());
- cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID());
- return cldsDbServiceCache;
+ public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData) {
+ try {
+ CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache();
+ cldsDbServiceCache.setCldsDataInstream(cldsServiceData);
+ cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID());
+ cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID());
+ return cldsDbServiceCache;
+ } catch (IOException e) {
+ logger.error("Exception when getting service in cache", e);
+ throw new SdcCommunicationException("Exception when getting service in cache", e);
+ }
}
- public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) throws IOException {
+ public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) {
boolean expired = false;
if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
String cachedServiceUuid = cldsServiceData.getServiceUUID();
@@ -408,7 +442,7 @@ public class SdcCatalogServices {
return expired;
}
- public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid) throws IOException {
+ public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid) {
String url = refProp.getStringValue("sdc.serviceUrl");
String catalogUrl = refProp.getStringValue("sdc.catalog.url");
String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);
@@ -417,7 +451,13 @@ public class SdcCatalogServices {
ObjectMapper objectMapper = new ObjectMapper();
CldsServiceData cldsServiceData = new CldsServiceData();
if (responseStr != null) {
- CldsSdcServiceDetail cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);
+ CldsSdcServiceDetail cldsSdcServiceDetail;
+ try {
+ cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);
+ } catch (IOException e) {
+ logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);
+ throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);
+ }
cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());
cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());
@@ -448,11 +488,7 @@ public class SdcCatalogServices {
return cldsServiceData;
}
- /**
- * @param cldsVfDataList
- * @throws IOException
- */
- private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) throws IOException {
+ private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) {
// todo : refact this..
if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {
List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(
@@ -511,9 +547,15 @@ public class SdcCatalogServices {
}
}
- private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws IOException {
+ private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
+ ObjectNode vfResponseNode;
+ try {
+ vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
+ } catch (IOException e) {
+ logger.error("Exception when decoding the JSON list of CldsVfcData", e);
+ return new ArrayList<>();
+ }
ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");
List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
if (vfcArrayNode != null) {
@@ -572,10 +614,16 @@ public class SdcCatalogServices {
return (id != null) ? id.replaceAll("\"", "") : "";
}
- private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws IOException {
+ private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) {
List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
- ObjectNode vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);
+ ObjectNode vfcResponseNode;
+ try {
+ vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);
+ } catch (IOException e) {
+ logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);
+ return cldsAlarmConditionList;
+ }
ArrayNode artifactsArrayNode = (ArrayNode) vfcResponseNode.get("artifacts");
if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
@@ -592,25 +640,36 @@ public class SdcCatalogServices {
return cldsAlarmConditionList;
}
- private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) throws IOException {
- List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
- Reader alarmReader = new StringReader(allAlarmCondsValues);
- Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
- if (records != null) {
- Iterator<CSVRecord> it = records.iterator();
- if (it.hasNext()) {
- it.next();
+ private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) {
+ try {
+ List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
+ Reader alarmReader = new StringReader(allAlarmCondsValues);
+ Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
+ if (records != null) {
+ Iterator<CSVRecord> it = records.iterator();
+ if (it.hasNext()) {
+ it.next();
+ }
+ it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));
}
- it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));
+ return cldsAlarmConditionList;
+ } catch (IOException e) {
+ logger.error("Exception when attempting to parse the CSV containing the alarm", e);
+ return new ArrayList<>();
}
- return cldsAlarmConditionList;
}
// Method to get the artifact for any particular VF
- private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws JsonProcessingException, IOException {
+ private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) {
List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
- ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
+ ObjectNode vfResponseNode;
+ try {
+ vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
+ } catch (IOException e) {
+ logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);
+ return cldsVfKPIDataList;
+ }
ArrayNode artifactsArrayNode = (ArrayNode) vfResponseNode.get("artifacts");
if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
@@ -621,7 +680,7 @@ public class SdcCatalogServices {
String artifactName = "";
if (artifactNameNode != null) {
artifactName = artifactNameNode.textValue();
- artifactName = artifactName.substring(artifactName.lastIndexOf(".") + 1);
+ artifactName = artifactName.substring(artifactName.lastIndexOf('.') + 1);
}
if (artifactUrlNode != null && artifactName != null && !artifactName.isEmpty()
&& artifactName.equalsIgnoreCase("csv")) {
@@ -660,19 +719,24 @@ public class SdcCatalogServices {
}
// Method to get the artifactURL Data and set the CldsVfKPIData node
- private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) throws IOException {
- List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();
- 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);
+ private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) {
+ try {
+ List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();
+ 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;
+ } catch (IOException e) {
+ logger.error("Exception when attempting to parse the CSV containing the alarm kpi data", e);
+ return new ArrayList<>();
}
- return cldsVfKPIDataList;
}
private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) {
@@ -713,7 +777,6 @@ public class SdcCatalogServices {
* @param url
* @param alarmConditions
* @return
- * @throws IOException
*/
public String getCldsServicesOrResourcesBasedOnURL(String url, boolean alarmConditions) {
try {
@@ -736,7 +799,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");
@@ -757,9 +820,8 @@ public class SdcCatalogServices {
* @param globalProps
* @param cldsServiceData
* @return
- * @throws IOException
*/
- public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) throws IOException {
+ public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) {
String totalPropsStr;
ObjectMapper mapper = new ObjectMapper();
ObjectNode globalPropsJson;
@@ -814,20 +876,29 @@ public class SdcCatalogServices {
byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);
- globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
+ globalPropsJson = decodeGlobalProp(globalProps, mapper);
globalPropsJson.putPOJO("shared", byIdObjectNode);
- logger.info("valuie of objNode:" + globalPropsJson);
+ logger.info("value of objNode:" + globalPropsJson);
} else {
/**
* to create json with total properties when no serviceUUID passed
*/
- globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
+ globalPropsJson = decodeGlobalProp(globalProps, mapper);
}
totalPropsStr = globalPropsJson.toString();
return totalPropsStr;
}
+ private ObjectNode decodeGlobalProp(String globalProps, ObjectMapper mapper) {
+ try {
+ return (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
+ } catch (IOException e) {
+ logger.error("Exception occurred during decoding of the global props, returning an empty objectNode", e);
+ return mapper.createObjectNode();
+ }
+ }
+
/**
* Method to get alarm conditions/alert description from Service Data.
*
@@ -981,13 +1052,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("", "");
@@ -1050,12 +1121,11 @@ public class SdcCatalogServices {
if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null
&& !currCldsSdcResource.getArtifacts().isEmpty()) {
for (CldsSdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {
- if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null) {
- if (currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {
- artifactUuid = currCldsSdcArtifact.getArtifactUUID();
- artifactExists = true;
- break;
- }
+ if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null
+ && currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {
+ artifactUuid = currCldsSdcArtifact.getArtifactUUID();
+ artifactExists = true;
+ break;
}
}
}
@@ -1109,22 +1179,16 @@ public class SdcCatalogServices {
* @param resourceType
* The resourceType
* @return The list of CldsSdcResourceBasicInfo
- * @throws IOException
- * In case of issues with the Streams
*/
- private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType)
- throws IOException {
- List<CldsSdcResourceBasicInfo> allSdcResourceVfcBasicInfo = new ArrayList<CldsSdcResourceBasicInfo>();
+ private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {
String catalogUrl = refProp.getStringValue("sdc.catalog.url");
String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;
String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl, false);
-
- allSdcResourceVfcBasicInfo = getAllSdcResourcesListFromJson(allSdcVfcResources);
- return removeDuplicateSdcResourceBasicInfo(allSdcResourceVfcBasicInfo);
+ return removeDuplicateSdcResourceBasicInfo(getAllSdcResourcesListFromJson(allSdcVfcResources));
}
private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,
- List<CldsSdcResourceBasicInfo> resourceInfoList) throws IOException {
+ List<CldsSdcResourceBasicInfo> resourceInfoList) {
String resourceUuid = null;
if (resourceInfoList != null && !resourceInfoList.isEmpty()) {
for (CldsSdcResourceBasicInfo currResource : resourceInfoList) {
@@ -1172,12 +1236,10 @@ public class SdcCatalogServices {
* @param locationArtifactName
* The location artifact name from where we can get the Artifact
* UUID
- * @throws IOException
- * In case of issues with the streams
*
*/
public void uploadToSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList, String formattedSdcReq,
- String formattedSdcLocationReq, String artifactName, String locationArtifactName) throws IOException {
+ String formattedSdcLocationReq, String artifactName, String locationArtifactName) {
logger.info("userid=" + userid);
String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);
if (sdcReqUrlsList != null && !sdcReqUrlsList.isEmpty()) {
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 2b1762a24..ad466ee7d 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
@@ -139,7 +139,7 @@ public class OperationalPolicyReq {
logger.info("notificationTopic=" + notificationTopic);
// format yaml
- String yaml = tca.isFound() ? formateNodeBYaml(refProp, prop, modelElementId, policyChain)
+ String yaml = (tca != null && tca.isFound()) ? formateNodeBYaml(refProp, prop, modelElementId, policyChain)
: formatYaml(refProp, prop, modelElementId, policyChain);
ruleAttributes.put("templateName", templateName);
@@ -425,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 93c562601..f8351ca5d 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
@@ -46,7 +46,6 @@ 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.exception.SdcCommunicationException;
import org.onap.clamp.clds.model.CldsSdcResource;
import org.onap.clamp.clds.model.CldsSdcServiceDetail;
import org.onap.clamp.clds.model.prop.Global;
@@ -251,13 +250,12 @@ public class SdcReq {
* @param baseUrl
* @param sdcCatalogServices
* @return
- * @throws Exception
*/
public static List<String> getSdcReqUrlsList(ModelProperties prop, String baseUrl,
SdcCatalogServices sdcCatalogServices, DelegateExecution execution) {
// 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) {
@@ -266,30 +264,28 @@ public class SdcReq {
List<String> 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<CldsSdcResource> CldsSdcResourcesList = CldsSdcServiceDetail.getResources();
- if (CldsSdcResourcesList != null && !CldsSdcResourcesList.isEmpty()) {
- for (CldsSdcResource CldsSdcResource : CldsSdcResourcesList) {
+ 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);
- }
+ && CldsSdcResource.getResoucreType().equalsIgnoreCase("VF")
+ && 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);
- }
+
return urlList;
}
diff --git a/src/main/java/org/onap/clamp/clds/config/CldsConfiguration.java b/src/main/java/org/onap/clamp/clds/config/CldsConfiguration.java
index 19c916435..eee179111 100644
--- a/src/main/java/org/onap/clamp/clds/config/CldsConfiguration.java
+++ b/src/main/java/org/onap/clamp/clds/config/CldsConfiguration.java
@@ -23,7 +23,9 @@
package org.onap.clamp.clds.config;
-import java.io.IOException;
+import com.att.ajsc.common.AjscProvider;
+import com.att.ajsc.common.AjscService;
+
import java.util.ArrayList;
import java.util.List;
@@ -55,9 +57,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
-import com.att.ajsc.common.AjscProvider;
-import com.att.ajsc.common.AjscService;
-
@Configuration
@Profile("clamp-default")
public class CldsConfiguration {
@@ -99,7 +98,7 @@ public class CldsConfiguration {
}
@Bean
- public RefProp getRefProp() throws IOException {
+ public RefProp getRefProp() {
return new RefProp();
}
diff --git a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
index 997a20f09..ecfb4aa11 100644
--- a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
+++ b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
@@ -23,13 +23,13 @@
package org.onap.clamp.clds.config;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
import java.io.IOException;
import java.io.InputStream;
import org.onap.clamp.clds.service.CldsUser;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
public class CldsUserJsonDecoder {
/**
@@ -43,4 +43,8 @@ public class CldsUserJsonDecoder {
// the ObjectMapper readValue method closes the stream no need to do it
return new ObjectMapper().readValue(cldsUsersFile, CldsUser[].class);
}
+
+ private CldsUserJsonDecoder() {
+
+ }
}
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 3b69502ae..3cc6a325a 100644
--- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java
+++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java
@@ -46,7 +46,6 @@ import org.onap.clamp.clds.model.CldsModelInstance;
import org.onap.clamp.clds.model.CldsServiceData;
import org.onap.clamp.clds.model.CldsTemplate;
import org.onap.clamp.clds.model.ValueItem;
-import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -398,8 +397,8 @@ public class CldsDao {
* @return model names
*/
public List<ValueItem> getBpmnNames() {
- String SQL = "SELECT model_name FROM model ORDER BY 1;";
- return jdbcTemplateObject.query(SQL, new ValueItemMapper());
+ String sql = "SELECT model_name FROM model ORDER BY 1;";
+ return jdbcTemplateObject.query(sql, new ValueItemMapper());
}
/**
@@ -435,8 +434,8 @@ public class CldsDao {
* @return template names
*/
public List<ValueItem> getTemplateNames() {
- String SQL = "SELECT template_name FROM template ORDER BY 1;";
- return jdbcTemplateObject.query(SQL, new ValueItemMapper());
+ String sql = "SELECT template_name FROM template ORDER BY 1;";
+ return jdbcTemplateObject.query(sql, new ValueItemMapper());
}
/**
@@ -466,14 +465,10 @@ public class CldsDao {
public CldsServiceData getCldsServiceCache(String invariantUUID) {
CldsServiceData cldsServiceData = null;
List<CldsServiceData> cldsServiceDataList = new ArrayList<>();
- try {
- String getCldsServiceSQL = "SELECT * , TIMESTAMPDIFF(SECOND, timestamp, CURRENT_TIMESTAMP()) FROM clds_service_cache where invariant_service_id = ? ";
- cldsServiceData = jdbcTemplateObject.queryForObject(getCldsServiceSQL, new Object[] { invariantUUID },
- new CldsServiceDataMapper());
- logger.info("value of cldsServiceDataList: {}", cldsServiceDataList);
- } catch (EmptyResultDataAccessException e) {
- logger.info("cache row not found for invariantUUID: {}", invariantUUID);
- }
+ String getCldsServiceSQL = "SELECT * , TIMESTAMPDIFF(SECOND, timestamp, CURRENT_TIMESTAMP()) FROM clds_service_cache where invariant_service_id = ? ";
+ cldsServiceData = jdbcTemplateObject.queryForObject(getCldsServiceSQL, new Object[] { invariantUUID },
+ new CldsServiceDataMapper());
+ logger.info("value of cldsServiceDataList: {}", cldsServiceDataList);
return cldsServiceData;
}
@@ -499,7 +494,7 @@ public class CldsDao {
}
}
- public void doHealthCheck() throws SQLException, IOException {
+ public void doHealthCheck() {
jdbcTemplateObject.execute(HEALTHCHECK);
}
diff --git a/src/main/java/org/onap/clamp/clds/exception/policy/PolicyClientException.java b/src/main/java/org/onap/clamp/clds/exception/policy/PolicyClientException.java
new file mode 100644
index 000000000..eaeb0b8fe
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/exception/policy/PolicyClientException.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.policy;
+
+/**
+ * New exception to Policy Client errors.
+ *
+ */
+public class PolicyClientException extends RuntimeException {
+
+ /**
+ * Serial ID.
+ */
+ private static final long serialVersionUID = -8379167975420213634L;
+
+ /**
+ * This constructor can be used to create a new PolicyClientException.
+ *
+ * @param message
+ * A string message detailing the problem
+ * @param e
+ * The exception sent by the code
+ */
+ public PolicyClientException(String message, Throwable e) {
+ super(message, e);
+ }
+
+ /**
+ * This constructor can be used to create a new PolicyClientException. 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 PolicyClientException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/AbstractModelElement.java b/src/main/java/org/onap/clamp/clds/model/prop/AbstractModelElement.java
new file mode 100644
index 000000000..a7dd5cbf0
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/model/prop/AbstractModelElement.java
@@ -0,0 +1,280 @@
+/*-
+ * ============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.prop;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.JsonNode;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Provide base ModelElement functionality. Perform base parsing of properties
+ * for a ModelElement (such as, Collector, StringMatch, Policy, Tca, Holmes,
+ * ...)
+ */
+public abstract class AbstractModelElement {
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(AbstractModelElement.class);
+ protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+
+ private final String type;
+ private final ModelBpmn modelBpmn;
+ private final String id;
+ protected String topicPublishes;
+ protected final JsonNode modelElementJsonNode;
+ private boolean isFound;
+
+ private final ModelProperties modelProp;
+
+ /**
+ * Perform base parsing of properties for a ModelElement (such as,
+ * Collector, StringMatch, Policy and Tca)
+ *
+ * @param type
+ * @param modelProp
+ * @param modelBpmn
+ * @param modelJson
+ */
+ protected AbstractModelElement(String type, ModelProperties modelProp, ModelBpmn modelBpmn, JsonNode modelJson) {
+ this.type = type;
+ this.modelProp = modelProp;
+ this.modelBpmn = modelBpmn;
+ this.id = modelBpmn.getId(type);
+ this.modelElementJsonNode = modelJson.get(id);
+ this.isFound = modelBpmn.isModelElementTypeInList(type);
+ }
+
+ /**
+ * topicSubscribes is the topicPublishes of the from Model Element (the
+ * previous one in the chain).
+ *
+ * @return the topicSubscribes
+ */
+ public String getTopicSubscribes() {
+ // get fromId for this type
+ String fromId = modelBpmn.getFromId(type);
+ // find the type of the from model element
+ String fromType = modelBpmn.getType(fromId);
+ // get the model element for the type
+ AbstractModelElement me = modelProp.getModelElementByType(fromType);
+ // get the topic publishes for the model element
+ return me.topicPublishes;
+ }
+
+ /**
+ * @return the topicPublishes
+ */
+ public String getTopicPublishes() {
+ return topicPublishes;
+ }
+
+ /**
+ * Return the value field of the json node element that has a name field
+ * equals to the given name.
+ *
+ * @param nodeIn
+ * @param name
+ * @return
+ */
+ public static String getValueByName(JsonNode nodeIn, String name) {
+ String value = null;
+ if (nodeIn != null) {
+ for (JsonNode node : nodeIn) {
+ if (node.path("name").asText().equals(name)) {
+ JsonNode vnode = node.path("value");
+ if (vnode.isArray()) {
+ // if array, assume value is in first element
+ value = vnode.path(0).asText();
+ } else {
+ // otherwise, just return text
+ value = vnode.asText();
+ }
+ }
+ }
+ }
+ if (value == null || value.length() == 0) {
+ logger.warn(name + "=" + value);
+ } else {
+ logger.debug(name + "=" + value);
+ }
+ return value;
+ }
+
+ /**
+ * Return the value field of the json node element that has a name field
+ * that equals the given name.
+ *
+ * @param nodeIn
+ * @param name
+ * @return
+ */
+ public static String getNodeValueByName(JsonNode nodeIn, String name) {
+ String value = null;
+ if (nodeIn != null) {
+ value = nodeIn.path(name).asText();
+ }
+ if (value == null || value.length() == 0) {
+ logger.warn(name + "=" + value);
+ } else {
+ logger.debug(name + "=" + value);
+ }
+ return value;
+ }
+
+ /**
+ * Return the value field of the json node element that has a name field
+ * that equals the given name.
+ *
+ * @param nodeIn
+ * @param name
+ * @return
+ */
+ public static List<String> getNodeValuesByName(JsonNode nodeIn, String name) {
+ List<String> values = new ArrayList<>();
+ if (nodeIn != null) {
+ Iterator<JsonNode> i = nodeIn.iterator();
+ while (i.hasNext()) {
+ JsonNode node = i.next();
+ if (node.path("name").asText().equals(name)) {
+ JsonNode vnode = node.path("value");
+ if (vnode.isArray()) {
+ // if array, assume value is in first element
+ values.add(vnode.path(0).asText());
+ } else {
+ // otherwise, just return text
+ values.add(vnode.asText());
+ }
+ }
+ }
+ }
+ return values;
+ }
+
+ /**
+ * Return the int value field of the json node element that has a name field
+ * equals to the given name.
+ *
+ * @param nodeIn
+ * @param name
+ * @return
+ */
+ public static Integer getIntValueByName(JsonNode nodeIn, String name) {
+ String value = getValueByName(nodeIn, name);
+ return Integer.valueOf(value);
+ }
+
+ /**
+ * Return an array of values for the field of the json node element that has
+ * a name field equals to the given name.
+ *
+ * @param nodeIn
+ * @param name
+ * @return
+ */
+ public static List<String> getValuesByName(JsonNode nodeIn, String name) {
+ List<String> values = null;
+ if (nodeIn != null) {
+ Iterator<JsonNode> i = nodeIn.iterator();
+ while (i.hasNext()) {
+ JsonNode node = i.next();
+ if (node.path("name").asText().equals(name)) {
+ values = getValuesList(node);
+ }
+ }
+ }
+ if (values == null || values.isEmpty()) {
+ logger.warn(name + "=" + values);
+ } else {
+ logger.debug(name + "=" + values);
+ }
+ return values;
+ }
+
+ /**
+ * Return an array of String values.
+ *
+ * @param nodeIn
+ * @return
+ */
+ public static List<String> getValuesList(JsonNode nodeIn) {
+ ArrayList<String> al = new ArrayList<>();
+ if (nodeIn != null) {
+ Iterator<JsonNode> itr = nodeIn.path("value").elements();
+ while (itr.hasNext()) {
+ JsonNode node = itr.next();
+ al.add(node.asText());
+ }
+ }
+ return al;
+ }
+
+ /**
+ * Return the value field of the json node element that has a name field
+ * equals to the given name.
+ *
+ * @param name
+ * @return
+ */
+ public String getValueByName(String name) {
+ return getValueByName(modelElementJsonNode, name);
+ }
+
+ /**
+ * Return the int value field of the json node element that has a name field
+ * equals to the given name.
+ *
+ * @param name
+ * @return
+ */
+ public Integer getIntValueByName(String name) {
+ return getIntValueByName(modelElementJsonNode, name);
+ }
+
+ /**
+ * Return an array of values for the field of the json node element that has
+ * a name field equals to the given name.
+ *
+ * @param name
+ * @return
+ */
+ public List<String> getValuesByName(String name) {
+ return getValuesByName(modelElementJsonNode, name);
+ }
+
+ /**
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @return the isFound
+ */
+ public boolean isFound() {
+ return isFound;
+ }
+}
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/Collector.java b/src/main/java/org/onap/clamp/clds/model/prop/Collector.java
index bcb9cf01d..be30f3ec2 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/Collector.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/Collector.java
@@ -30,7 +30,7 @@ import com.fasterxml.jackson.databind.JsonNode;
/**
* Parse Collector json properties.
*/
-public class Collector extends ModelElement {
+public class Collector extends AbstractModelElement {
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(Collector.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/Global.java b/src/main/java/org/onap/clamp/clds/model/prop/Global.java
index 2fb7d5040..48c2fd9fb 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/Global.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/Global.java
@@ -54,11 +54,11 @@ public class Global {
*/
public Global(JsonNode modelJson) {
JsonNode globalNode = modelJson.get("global");
- service = ModelElement.getValueByName(globalNode, "service");
- actionSet = ModelElement.getValueByName(globalNode, "actionSet");
- resourceVf = ModelElement.getValuesByName(globalNode, "vf");
- resourceVfc = ModelElement.getValuesByName(globalNode, "vfc");
- location = ModelElement.getValuesByName(globalNode, "location");
+ service = AbstractModelElement.getValueByName(globalNode, "service");
+ actionSet = AbstractModelElement.getValueByName(globalNode, "actionSet");
+ resourceVf = AbstractModelElement.getValuesByName(globalNode, "vf");
+ resourceVfc = AbstractModelElement.getValuesByName(globalNode, "vfc");
+ location = AbstractModelElement.getValuesByName(globalNode, "location");
}
/**
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/Holmes.java b/src/main/java/org/onap/clamp/clds/model/prop/Holmes.java
index 233f656e1..4fa040754 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/Holmes.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/Holmes.java
@@ -32,7 +32,7 @@ import com.fasterxml.jackson.databind.JsonNode;
* [{"name":"correlationalLogic","value":"vcwx"},{"name":"operationalPolicy","value":"cccc"}]
*
*/
-public class Holmes extends ModelElement {
+public class Holmes extends AbstractModelElement {
private static final String TYPE_HOLMES = "holmes";
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/ModelProperties.java b/src/main/java/org/onap/clamp/clds/model/prop/ModelProperties.java
index 9684eea86..ac25400db 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/ModelProperties.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/ModelProperties.java
@@ -62,13 +62,13 @@ public class ModelProperties {
private Global global;
- private final Map<String, ModelElement> modelElements = new ConcurrentHashMap<>();
+ private final Map<String, AbstractModelElement> modelElements = new ConcurrentHashMap<>();
private String currentModelElementId;
private String policyUniqueId;
private static final Object lock = new Object();
- private static Map<Class<? extends ModelElement>, String> modelElementClasses = new ConcurrentHashMap<>();
+ private static Map<Class<? extends AbstractModelElement>, String> modelElementClasses = new ConcurrentHashMap<>();
static {
synchronized (lock) {
@@ -119,7 +119,7 @@ public class ModelProperties {
// Parse the list of base Model Elements and build up the
// ModelElements
modelElementClasses.entrySet().stream().parallel()
- .filter(entry -> (ModelElement.class.isAssignableFrom(entry.getKey())
+ .filter(entry -> (AbstractModelElement.class.isAssignableFrom(entry.getKey())
&& missingTypes.contains(entry.getValue())))
.forEach(entry -> {
try {
@@ -183,8 +183,8 @@ public class ModelProperties {
* @param type
* @return
*/
- public ModelElement getModelElementByType(String type) {
- ModelElement modelElement = modelElements.get(type);
+ public AbstractModelElement getModelElementByType(String type) {
+ AbstractModelElement modelElement = modelElements.get(type);
if (modelElement == null) {
throw new IllegalArgumentException("Invalid or not found ModelElement type: " + type);
}
@@ -338,14 +338,14 @@ public class ModelProperties {
return global;
}
- public static final synchronized void registerModelElement(Class<? extends ModelElement> modelElementClass,
+ public static final synchronized void registerModelElement(Class<? extends AbstractModelElement> modelElementClass,
String type) {
if (!modelElementClasses.containsKey(modelElementClass.getClass())) {
modelElementClasses.put(modelElementClass, type);
}
}
- public <T extends ModelElement> T getType(Class<T> clazz) {
+ public <T extends AbstractModelElement> T getType(Class<T> clazz) {
instantiateMissingModelElements();
String type = modelElementClasses.get(clazz);
return (type != null ? (T) modelElements.get(type) : null);
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/Policy.java b/src/main/java/org/onap/clamp/clds/model/prop/Policy.java
index 452af20cd..80d12aaba 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/Policy.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/Policy.java
@@ -48,7 +48,7 @@ import java.util.List;
* ""]},{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[
* "vf3RtPi"]}]]}]
*/
-public class Policy extends ModelElement {
+public class Policy extends AbstractModelElement {
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(Policy.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java b/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java
index 6142e9e63..c8c2ef461 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java
@@ -63,13 +63,13 @@ public class PolicyChain {
public PolicyChain(JsonNode node) {
- policyId = ModelElement.getValueByName(node, "pid");
- timeout = ModelElement.getIntValueByName(node, "timeout");
+ policyId = AbstractModelElement.getValueByName(node, "pid");
+ timeout = AbstractModelElement.getIntValueByName(node, "timeout");
// process policy configurations
JsonNode policyNode = node.get(node.size() - 1).get("policyConfigurations");
Iterator<JsonNode> itr = policyNode.elements();
- policyItems = new ArrayList<PolicyItem>();
+ policyItems = new ArrayList<>();
while (itr.hasNext()) {
policyItems.add(new PolicyItem(itr.next()));
}
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java b/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java
index d1729cda1..c84affefe 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java
@@ -64,12 +64,12 @@ public class PolicyItem implements Cloneable {
* @param node
*/
public PolicyItem(JsonNode node) {
- id = ModelElement.getValueByName(node, "_id");
- recipe = ModelElement.getValueByName(node, "recipe");
- maxRetries = ModelElement.getIntValueByName(node, "maxRetries");
- retryTimeLimit = ModelElement.getIntValueByName(node, "retryTimeLimit");
- parentPolicy = ModelElement.getValueByName(node, "parentPolicy");
- parentPolicyConditions = ModelElement.getValuesByName(node, "parentPolicyConditions");
+ id = AbstractModelElement.getValueByName(node, "_id");
+ recipe = AbstractModelElement.getValueByName(node, "recipe");
+ maxRetries = AbstractModelElement.getIntValueByName(node, "maxRetries");
+ retryTimeLimit = AbstractModelElement.getIntValueByName(node, "retryTimeLimit");
+ parentPolicy = AbstractModelElement.getValueByName(node, "parentPolicy");
+ parentPolicyConditions = AbstractModelElement.getValuesByName(node, "parentPolicyConditions");
}
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/ResourceGroup.java b/src/main/java/org/onap/clamp/clds/model/prop/ResourceGroup.java
index 6e986bb0e..7395ced00 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/ResourceGroup.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/ResourceGroup.java
@@ -78,8 +78,8 @@ public class ResourceGroup {
*/
public ResourceGroup(JsonNode node) {
- groupNumber = ModelElement.getValueByName(node, "rgname");
- policyId = ModelElement.getValueByName(node, "policyId");
+ groupNumber = AbstractModelElement.getValueByName(node, "rgname");
+ policyId = AbstractModelElement.getValueByName(node, "policyId");
// process Server_Configurations
JsonNode serviceConfigurationsNode = node.get(node.size() - 1).get("serviceConfigurations");
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/ServiceConfiguration.java b/src/main/java/org/onap/clamp/clds/model/prop/ServiceConfiguration.java
index 186cc2192..f15d70196 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/ServiceConfiguration.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/ServiceConfiguration.java
@@ -84,15 +84,15 @@ public class ServiceConfiguration {
* @param node
*/
public ServiceConfiguration(JsonNode node) {
- aaiMatchingFields = ModelElement.getValuesByName(node, "aaiMatchingFields");
- aaiSendFields = ModelElement.getValuesByName(node, "aaiSendFields");
+ aaiMatchingFields = AbstractModelElement.getValuesByName(node, "aaiMatchingFields");
+ aaiSendFields = AbstractModelElement.getValuesByName(node, "aaiSendFields");
// groupNumber = ModelElement.getValueByName(node, "groupNumber");
- resourceVf = ModelElement.getValuesByName(node, "vf");
- resourceVfc = ModelElement.getValuesByName(node, "vfc");
- timeWindow = ModelElement.getValueByName(node, "timeWindow");
- ageLimit = ModelElement.getValueByName(node, "ageLimit");
- createClosedLoopEventId = ModelElement.getValueByName(node, "createClosedLoopEventId");
- outputEventName = ModelElement.getValueByName(node, "outputEventName");
+ resourceVf = AbstractModelElement.getValuesByName(node, "vf");
+ resourceVfc = AbstractModelElement.getValuesByName(node, "vfc");
+ timeWindow = AbstractModelElement.getValueByName(node, "timeWindow");
+ ageLimit = AbstractModelElement.getValueByName(node, "ageLimit");
+ createClosedLoopEventId = AbstractModelElement.getValueByName(node, "createClosedLoopEventId");
+ outputEventName = AbstractModelElement.getValueByName(node, "outputEventName");
// process the stringSet fields
JsonNode ssNodes = node.findPath("stringSet");
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/StringMatch.java b/src/main/java/org/onap/clamp/clds/model/prop/StringMatch.java
index 7fcc1b1b9..b74e7d134 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/StringMatch.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/StringMatch.java
@@ -59,7 +59,7 @@ import java.util.List;
* "outputEventName","value":["ABATED"]}]]}]}}
*
*/
-public class StringMatch extends ModelElement {
+public class StringMatch extends AbstractModelElement {
private List<ResourceGroup> resourceGroups;
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/Tca.java b/src/main/java/org/onap/clamp/clds/model/prop/Tca.java
index 6bc68e23d..f7bbac0de 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/Tca.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/Tca.java
@@ -48,7 +48,7 @@ import java.util.List;
*
*
*/
-public class Tca extends ModelElement {
+public class Tca extends AbstractModelElement {
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(Tca.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/TcaItem.java b/src/main/java/org/onap/clamp/clds/model/prop/TcaItem.java
index aa1abde17..f104b0917 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/TcaItem.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/TcaItem.java
@@ -70,17 +70,17 @@ public class TcaItem {
*/
public TcaItem(JsonNode node) {
- tcaName = ModelElement.getValueByName(node, "tname");
- tcaUuId = ModelElement.getValueByName(node, "tuuid");
- nfNamingCode = ModelElement.getValueByName(node, "tnfc");
- tcaEnable = ModelElement.getValueByName(node, "tcaEnab");
- policyId = ModelElement.getValueByName(node, "tcaPolId");
- if (ModelElement.getValueByName(node, "tcaInt") != null) {
- interval = Integer.valueOf(ModelElement.getValueByName(node, "tcaInt"));
+ tcaName = AbstractModelElement.getValueByName(node, "tname");
+ tcaUuId = AbstractModelElement.getValueByName(node, "tuuid");
+ nfNamingCode = AbstractModelElement.getValueByName(node, "tnfc");
+ tcaEnable = AbstractModelElement.getValueByName(node, "tcaEnab");
+ policyId = AbstractModelElement.getValueByName(node, "tcaPolId");
+ if (AbstractModelElement.getValueByName(node, "tcaInt") != null) {
+ interval = Integer.valueOf(AbstractModelElement.getValueByName(node, "tcaInt"));
}
- severity = ModelElement.getValueByName(node, "tcaSev");
- if (ModelElement.getValueByName(node, "tcaVio") != null) {
- violations = Integer.valueOf(ModelElement.getValueByName(node, "tcaVio"));
+ severity = AbstractModelElement.getValueByName(node, "tcaSev");
+ if (AbstractModelElement.getValueByName(node, "tcaVio") != null) {
+ violations = Integer.valueOf(AbstractModelElement.getValueByName(node, "tcaVio"));
}
// process service Configurations
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 ff4cfda17..920bce181 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java
@@ -500,9 +500,6 @@ public class CldsService extends SecureServiceBase {
if (test != null && test.equalsIgnoreCase("true")) {
isTest = true;
} else {
- // if action.test.override is true, then any action will be marked
- // as test=true (even if incoming action request had test=false);
- // otherwise, test flag will be unchanged on the action request
String actionTestOverride = refProp.getStringValue("action.test.override");
if (actionTestOverride != null && actionTestOverride.equalsIgnoreCase("true")) {
logger.info("PUT actionTestOverride={}", actionTestOverride);
@@ -666,8 +663,7 @@ public class CldsService extends SecureServiceBase {
/**
* REST service that retrieves total properties by using invariantUUID based
* on refresh and non refresh
- *
- * @throws Exception
+ *
*/
@ApiOperation(value = "Retrieves total properties by using invariantUUID based on refresh and non refresh", notes = "", response = String.class)
@GET
@@ -675,7 +671,7 @@ public class CldsService extends SecureServiceBase {
@Produces(MediaType.APPLICATION_JSON)
public String getSdcPropertiesByServiceUUIDForRefresh(
@PathParam("serviceInvariantUUID") String serviceInvariantUUID,
- @DefaultValue("false") @QueryParam("refresh") String refresh) throws Exception {
+ @DefaultValue("false") @QueryParam("refresh") String refresh) {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsService: GET sdc properties by uuid", getPrincipalName());
CldsServiceData cldsServiceData = new CldsServiceData();
@@ -901,7 +897,7 @@ public class CldsService extends SecureServiceBase {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public CldsModel deployModel(@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: Deploy model", getPrincipalName());
String deploymentId = "closedLoop_" + UUID.randomUUID() + "_deploymentId";
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsUser.java b/src/main/java/org/onap/clamp/clds/service/CldsUser.java
index 9db1e6078..34a3f8ea2 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsUser.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsUser.java
@@ -71,7 +71,7 @@ public class CldsUser {
}
public String[] getPermissionsString() {
- return Arrays.stream(getPermissions()).map(perm -> perm.getKey()).toArray(String[]::new);
+ return Arrays.stream(getPermissions()).map(SecureServicePermission::getKey).toArray(String[]::new);
}
/**