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());
if (holmes.isFound()) {
prop.setCurrentModelElementId(holmes.getId());
- policyClient.deleteMicrosService(prop);
+ policyClient.deleteBasePolicy(prop);
}
}
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;
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;
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;
* @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();
* @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();
* 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();
* 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 = "";
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 {
* @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";
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);
* @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();
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);
}
/**
* 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());
}
* @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);
}
* 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()) {
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();
}
/**
* @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);
\r
import com.att.eelf.configuration.EELFLogger;\r
import com.att.eelf.configuration.EELFManager;\r
-import com.fasterxml.jackson.core.JsonProcessingException;\r
import com.fasterxml.jackson.databind.JsonNode;\r
import com.fasterxml.jackson.databind.ObjectMapper;\r
import com.fasterxml.jackson.databind.node.ArrayNode;\r
import org.apache.commons.csv.CSVRecord;\r
import org.apache.commons.lang3.StringUtils;\r
import org.onap.clamp.clds.client.req.SdcReq;\r
+import org.onap.clamp.clds.exception.SdcCommunicationException;\r
import org.onap.clamp.clds.model.CldsAlarmCondition;\r
import org.onap.clamp.clds.model.CldsDBServiceCache;\r
import org.onap.clamp.clds.model.CldsSdcArtifact;\r
*/\r
public List<CldsSdcServiceInfo> removeDuplicateServices(List<CldsSdcServiceInfo> rawCldsSdcServiceList) {\r
List<CldsSdcServiceInfo> cldsSdcServiceInfoList = null;\r
- if (rawCldsSdcServiceList != null && rawCldsSdcServiceList.size() > 0) {\r
+ if (rawCldsSdcServiceList != null && !rawCldsSdcServiceList.isEmpty()) {\r
// sort list\r
Collections.sort(rawCldsSdcServiceList);\r
// and then take only the services with the max version (last in the\r
*/\r
public List<CldsSdcResource> removeDuplicateSdcResourceInstances(List<CldsSdcResource> rawCldsSdcResourceList) {\r
List<CldsSdcResource> cldsSdcResourceList = null;\r
- if (rawCldsSdcResourceList != null && rawCldsSdcResourceList.size() > 0) {\r
+ if (rawCldsSdcResourceList != null && !rawCldsSdcResourceList.isEmpty()) {\r
// sort list\r
Collections.sort(rawCldsSdcResourceList);\r
// and then take only the resources with the max version (last in\r
public List<CldsSdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(\r
List<CldsSdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
List<CldsSdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;\r
- if (rawCldsSdcResourceListBasicList != null && rawCldsSdcResourceListBasicList.size() > 0) {\r
+ if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) {\r
// sort list\r
Collections.sort(rawCldsSdcResourceListBasicList);\r
// and then take only the resources with the max version (last in\r
* @param invariantId\r
* The invariant ID\r
* @return The service UUID\r
- * @throws IOException\r
- * In case of issues with the JSON decoder\r
*/\r
- public String getServiceUuidFromServiceInvariantId(String invariantId) throws IOException {\r
+ public String getServiceUuidFromServiceInvariantId(String invariantId) {\r
String serviceUuid = "";\r
String responseStr = getSdcServicesInformation(null);\r
List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);\r
List<CldsSdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);\r
- if (cldsSdcServicesList != null && cldsSdcServicesList.size() > 0) {\r
+ if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {\r
for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {\r
if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null\r
&& currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {\r
* To get CldsAsdsServiceInfo class by parsing json string.\r
*\r
* @param jsonStr\r
- * @return\r
- * @throws IOException\r
+ * The Json string that must be decoded\r
+ * @return The list of CldsSdcServiceInfo, if there is a failure it return\r
+ * an empty list\r
*/\r
- public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) throws IOException {\r
+ public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
ObjectMapper objectMapper = new ObjectMapper();\r
if (StringUtils.isBlank(jsonStr)) {\r
- return null;\r
+ return new ArrayList<>();\r
+ }\r
+ try {\r
+ return objectMapper.readValue(jsonStr,\r
+ objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));\r
+ } catch (IOException e) {\r
+ logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);\r
+ return new ArrayList<>();\r
}\r
- return objectMapper.readValue(jsonStr,\r
- objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));\r
}\r
\r
/**\r
* To get List of CldsSdcResourceBasicInfo class by parsing json string.\r
*\r
* @param jsonStr\r
- * @return\r
- * @throws IOException\r
+ * The JSOn string that must be decoded\r
+ * @return The list of CldsSdcResourceBasicInfo, an empty list in case of\r
+ * issues\r
*/\r
- public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) throws IOException {\r
+ public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
ObjectMapper objectMapper = new ObjectMapper();\r
if (StringUtils.isBlank(jsonStr)) {\r
- return null;\r
+ return new ArrayList<>();\r
+ }\r
+\r
+ try {\r
+ return objectMapper.readValue(jsonStr,\r
+ objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));\r
+ } catch (IOException e) {\r
+ logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);\r
+ return new ArrayList<>();\r
}\r
- return objectMapper.readValue(jsonStr,\r
- objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));\r
}\r
\r
/**\r
*\r
* @param jsonStr\r
* @return\r
- * @throws IOException\r
*/\r
- public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) throws IOException {\r
+ public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) {\r
ObjectMapper objectMapper = new ObjectMapper();\r
- return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);\r
+ try {\r
+ return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);\r
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e);\r
+ return null;\r
+ }\r
}\r
\r
/**\r
- * To upload artifact to sdc based on serviceUUID and resourcename on url.\r
+ * To upload artifact to sdc based on serviceUUID and resource name on url.\r
*\r
* @param prop\r
* @param userid\r
* @param url\r
- * @param formatttedSdcReq\r
+ * @param formattedSdcReq\r
* @return\r
- * @throws IOException\r
*/\r
- public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatttedSdcReq)\r
- throws IOException {\r
+ public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatttedSdcReq) {\r
// Verify whether it is triggered by Validation Test button from UI\r
if (prop.isTest()) {\r
return "sdc artifact upload not executed for test action";\r
}\r
- logger.info("userid=" + userid);\r
- String md5Text = SdcReq.calculateMD5ByString(formatttedSdcReq);\r
- byte[] postData = SdcReq.stringToByteArray(formatttedSdcReq);\r
- int postDataLength = postData.length;\r
- HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text);\r
- try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {\r
- wr.write(postData);\r
- }\r
- boolean requestFailed = true;\r
- int responseCode = conn.getResponseCode();\r
- logger.info("responseCode=" + responseCode);\r
- if (responseCode == 200) {\r
- requestFailed = false;\r
- }\r
+ try {\r
+ logger.info("userid=" + userid);\r
+ String md5Text = SdcReq.calculateMD5ByString(formatttedSdcReq);\r
+ byte[] postData = SdcReq.stringToByteArray(formatttedSdcReq);\r
+ int postDataLength = postData.length;\r
+ HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text);\r
+ try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {\r
+ wr.write(postData);\r
+ }\r
+ boolean requestFailed = true;\r
+ int responseCode = conn.getResponseCode();\r
+ logger.info("responseCode=" + responseCode);\r
+ if (responseCode == 200) {\r
+ requestFailed = false;\r
+ }\r
\r
- String responseStr = getResponse(conn);\r
- if (responseStr != null) {\r
- if (requestFailed) {\r
+ String responseStr = getResponse(conn);\r
+ if (responseStr != null && requestFailed) {\r
logger.error("requestFailed - responseStr=" + responseStr);\r
throw new BadRequestException(responseStr);\r
}\r
+ return responseStr;\r
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to communicate with SDC", e);\r
+ throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e);\r
}\r
- return responseStr;\r
+\r
}\r
\r
- private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text)\r
- throws IOException {\r
- logger.info("userid=" + userid);\r
- String basicAuth = SdcReq.getSdcBasicAuth(refProp);\r
- String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");\r
- URL urlObj = new URL(url);\r
- HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
- conn.setDoOutput(true);\r
- conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), sdcXonapInstanceId);\r
- conn.setRequestProperty("Authorization", basicAuth);\r
- conn.setRequestProperty("Content-Type", "application/json");\r
- conn.setRequestProperty("Content-MD5", md5Text);\r
- conn.setRequestProperty("USER_ID", userid);\r
- conn.setRequestMethod("POST");\r
- conn.setRequestProperty("charset", "utf-8");\r
- conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));\r
- conn.setUseCaches(false);\r
- conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
- return conn;\r
+ private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text) {\r
+ try {\r
+ logger.info("userid=" + userid);\r
+ String basicAuth = SdcReq.getSdcBasicAuth(refProp);\r
+ String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");\r
+ URL urlObj = new URL(url);\r
+ HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
+ conn.setDoOutput(true);\r
+ conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), sdcXonapInstanceId);\r
+ conn.setRequestProperty("Authorization", basicAuth);\r
+ conn.setRequestProperty("Content-Type", "application/json");\r
+ conn.setRequestProperty("Content-MD5", md5Text);\r
+ conn.setRequestProperty("USER_ID", userid);\r
+ conn.setRequestMethod("POST");\r
+ conn.setRequestProperty("charset", "utf-8");\r
+ conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));\r
+ conn.setUseCaches(false);\r
+ conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
+ return conn;\r
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to open connection with SDC", e);\r
+ throw new SdcCommunicationException("Exception when attempting to open connection with SDC", e);\r
+ }\r
}\r
\r
- private String getResponse(HttpURLConnection conn) throws IOException {\r
+ private String getResponse(HttpURLConnection conn) {\r
try (InputStream is = getInputStream(conn)) {\r
if (is != null) {\r
try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {\r
}\r
return response.toString();\r
}\r
+ } else {\r
+ return null;\r
}\r
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to open SDC response", e);\r
+ throw new SdcCommunicationException("Exception when attempting to open SDC response", e);\r
}\r
- return null;\r
}\r
\r
- private InputStream getInputStream(HttpURLConnection conn) throws IOException {\r
- InputStream inStream = conn.getErrorStream();\r
- if (inStream == null) {\r
- inStream = conn.getInputStream();\r
+ private InputStream getInputStream(HttpURLConnection conn) {\r
+ try {\r
+ InputStream inStream = conn.getErrorStream();\r
+ if (inStream == null) {\r
+ inStream = conn.getInputStream();\r
+ }\r
+ return inStream;\r
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to open SDC error stream", e);\r
+ throw new SdcCommunicationException("Exception when attempting to open SDC error stream", e);\r
}\r
- return inStream;\r
}\r
\r
- public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData)\r
- throws IOException {\r
- CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache();\r
- cldsDbServiceCache.setCldsDataInstream(cldsServiceData);\r
- cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID());\r
- cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID());\r
- return cldsDbServiceCache;\r
+ public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData) {\r
+ try {\r
+ CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache();\r
+ cldsDbServiceCache.setCldsDataInstream(cldsServiceData);\r
+ cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID());\r
+ cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID());\r
+ return cldsDbServiceCache;\r
+ } catch (IOException e) {\r
+ logger.error("Exception when getting service in cache", e);\r
+ throw new SdcCommunicationException("Exception when getting service in cache", e);\r
+ }\r
}\r
\r
- public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) throws IOException {\r
+ public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) {\r
boolean expired = false;\r
if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {\r
String cachedServiceUuid = cldsServiceData.getServiceUUID();\r
return expired;\r
}\r
\r
- public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid) throws IOException {\r
+ public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid) {\r
String url = refProp.getStringValue("sdc.serviceUrl");\r
String catalogUrl = refProp.getStringValue("sdc.catalog.url");\r
String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);\r
ObjectMapper objectMapper = new ObjectMapper();\r
CldsServiceData cldsServiceData = new CldsServiceData();\r
if (responseStr != null) {\r
- CldsSdcServiceDetail cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);\r
+ CldsSdcServiceDetail cldsSdcServiceDetail;\r
+ try {\r
+ cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);\r
+ } catch (IOException e) {\r
+ logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);\r
+ throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);\r
+ }\r
cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());\r
cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());\r
\r
return cldsServiceData;\r
}\r
\r
- /**\r
- * @param cldsVfDataList\r
- * @throws IOException\r
- */\r
- private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) throws IOException {\r
+ private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) {\r
// todo : refact this..\r
if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
}\r
}\r
\r
- private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws IOException {\r
+ private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) {\r
ObjectMapper mapper = new ObjectMapper();\r
- ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+ ObjectNode vfResponseNode;\r
+ try {\r
+ vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+ } catch (IOException e) {\r
+ logger.error("Exception when decoding the JSON list of CldsVfcData", e);\r
+ return new ArrayList<>();\r
+ }\r
ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");\r
List<CldsVfcData> cldsVfcDataList = new ArrayList<>();\r
if (vfcArrayNode != null) {\r
return (id != null) ? id.replaceAll("\"", "") : "";\r
}\r
\r
- private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws IOException {\r
+ private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) {\r
List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
ObjectMapper mapper = new ObjectMapper();\r
- ObjectNode vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+ ObjectNode vfcResponseNode;\r
+ try {\r
+ vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+ } catch (IOException e) {\r
+ logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);\r
+ return cldsAlarmConditionList;\r
+ }\r
ArrayNode artifactsArrayNode = (ArrayNode) vfcResponseNode.get("artifacts");\r
\r
if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {\r
return cldsAlarmConditionList;\r
}\r
\r
- private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) throws IOException {\r
- List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
- Reader alarmReader = new StringReader(allAlarmCondsValues);\r
- Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
- if (records != null) {\r
- Iterator<CSVRecord> it = records.iterator();\r
- if (it.hasNext()) {\r
- it.next();\r
+ private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) {\r
+ try {\r
+ List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
+ Reader alarmReader = new StringReader(allAlarmCondsValues);\r
+ Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
+ if (records != null) {\r
+ Iterator<CSVRecord> it = records.iterator();\r
+ if (it.hasNext()) {\r
+ it.next();\r
+ }\r
+ it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));\r
}\r
- it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));\r
+ return cldsAlarmConditionList;\r
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to parse the CSV containing the alarm", e);\r
+ return new ArrayList<>();\r
}\r
- return cldsAlarmConditionList;\r
}\r
\r
// Method to get the artifact for any particular VF\r
- private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws JsonProcessingException, IOException {\r
+ private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) {\r
List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
ObjectMapper mapper = new ObjectMapper();\r
- ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+ ObjectNode vfResponseNode;\r
+ try {\r
+ vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+ } catch (IOException e) {\r
+ logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);\r
+ return cldsVfKPIDataList;\r
+ }\r
ArrayNode artifactsArrayNode = (ArrayNode) vfResponseNode.get("artifacts");\r
\r
if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {\r
String artifactName = "";\r
if (artifactNameNode != null) {\r
artifactName = artifactNameNode.textValue();\r
- artifactName = artifactName.substring(artifactName.lastIndexOf(".") + 1);\r
+ artifactName = artifactName.substring(artifactName.lastIndexOf('.') + 1);\r
}\r
if (artifactUrlNode != null && artifactName != null && !artifactName.isEmpty()\r
&& artifactName.equalsIgnoreCase("csv")) {\r
}\r
\r
// Method to get the artifactURL Data and set the CldsVfKPIData node\r
- private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) throws IOException {\r
- List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
- Reader alarmReader = new StringReader(allFieldPathValues);\r
- Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
- if (records != null) {\r
- for (CSVRecord record : records) {\r
- CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);\r
- if (kpiData != null) {\r
- cldsVfKPIDataList.add(kpiData);\r
+ private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) {\r
+ try {\r
+ List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
+ Reader alarmReader = new StringReader(allFieldPathValues);\r
+ Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
+ if (records != null) {\r
+ for (CSVRecord record : records) {\r
+ CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);\r
+ if (kpiData != null) {\r
+ cldsVfKPIDataList.add(kpiData);\r
+ }\r
}\r
}\r
+ return cldsVfKPIDataList;\r
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to parse the CSV containing the alarm kpi data", e);\r
+ return new ArrayList<>();\r
}\r
- return cldsVfKPIDataList;\r
}\r
\r
private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) {\r
* @param url\r
* @param alarmConditions\r
* @return\r
- * @throws IOException\r
*/\r
public String getCldsServicesOrResourcesBasedOnURL(String url, boolean alarmConditions) {\r
try {\r
String inputLine;\r
while ((inputLine = in.readLine()) != null) {\r
if (!inputLine.isEmpty()) {\r
- response.append(inputLine);\r
+ response.append(inputLine);\r
}\r
if (alarmConditions) {\r
response.append("\n");\r
* @param globalProps\r
* @param cldsServiceData\r
* @return\r
- * @throws IOException\r
*/\r
- public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) throws IOException {\r
+ public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) {\r
String totalPropsStr;\r
ObjectMapper mapper = new ObjectMapper();\r
ObjectNode globalPropsJson;\r
\r
byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);\r
\r
- globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);\r
+ globalPropsJson = decodeGlobalProp(globalProps, mapper);\r
\r
globalPropsJson.putPOJO("shared", byIdObjectNode);\r
- logger.info("valuie of objNode:" + globalPropsJson);\r
+ logger.info("value of objNode:" + globalPropsJson);\r
} else {\r
/**\r
* to create json with total properties when no serviceUUID passed\r
*/\r
- globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);\r
+ globalPropsJson = decodeGlobalProp(globalProps, mapper);\r
}\r
totalPropsStr = globalPropsJson.toString();\r
return totalPropsStr;\r
}\r
\r
+ private ObjectNode decodeGlobalProp(String globalProps, ObjectMapper mapper) {\r
+ try {\r
+ return (ObjectNode) mapper.readValue(globalProps, JsonNode.class);\r
+ } catch (IOException e) {\r
+ logger.error("Exception occurred during decoding of the global props, returning an empty objectNode", e);\r
+ return mapper.createObjectNode();\r
+ }\r
+ }\r
+\r
/**\r
* Method to get alarm conditions/alert description from Service Data.\r
* \r
alertDescNode.put(currCldsAlarmCondition.getAlarmConditionKey(),\r
currCldsAlarmCondition.getAlarmConditionKey());\r
}\r
- }\r
}\r
+ }\r
\r
vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);\r
vfcObjectNode.putPOJO("alertDescription", alertDescNode);\r
vfcResourceUuidObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(), vfcObjectNode);\r
- }\r
+ }\r
}\r
} else {\r
alarmCondNode.put("", "");\r
if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null\r
&& !currCldsSdcResource.getArtifacts().isEmpty()) {\r
for (CldsSdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {\r
- if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null) {\r
- if (currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {\r
- artifactUuid = currCldsSdcArtifact.getArtifactUUID();\r
- artifactExists = true;\r
- break;\r
- }\r
+ if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null\r
+ && currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {\r
+ artifactUuid = currCldsSdcArtifact.getArtifactUUID();\r
+ artifactExists = true;\r
+ break;\r
}\r
}\r
}\r
* @param resourceType\r
* The resourceType\r
* @return The list of CldsSdcResourceBasicInfo\r
- * @throws IOException\r
- * In case of issues with the Streams\r
*/\r
- private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType)\r
- throws IOException {\r
- List<CldsSdcResourceBasicInfo> allSdcResourceVfcBasicInfo = new ArrayList<CldsSdcResourceBasicInfo>();\r
+ private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {\r
String catalogUrl = refProp.getStringValue("sdc.catalog.url");\r
String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;\r
String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl, false);\r
-\r
- allSdcResourceVfcBasicInfo = getAllSdcResourcesListFromJson(allSdcVfcResources);\r
- return removeDuplicateSdcResourceBasicInfo(allSdcResourceVfcBasicInfo);\r
+ return removeDuplicateSdcResourceBasicInfo(getAllSdcResourcesListFromJson(allSdcVfcResources));\r
}\r
\r
private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,\r
- List<CldsSdcResourceBasicInfo> resourceInfoList) throws IOException {\r
+ List<CldsSdcResourceBasicInfo> resourceInfoList) {\r
String resourceUuid = null;\r
if (resourceInfoList != null && !resourceInfoList.isEmpty()) {\r
for (CldsSdcResourceBasicInfo currResource : resourceInfoList) {\r
* @param locationArtifactName\r
* The location artifact name from where we can get the Artifact\r
* UUID\r
- * @throws IOException\r
- * In case of issues with the streams\r
* \r
*/\r
public void uploadToSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList, String formattedSdcReq,\r
- String formattedSdcLocationReq, String artifactName, String locationArtifactName) throws IOException {\r
+ String formattedSdcLocationReq, String artifactName, String locationArtifactName) {\r
logger.info("userid=" + userid);\r
String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);\r
if (sdcReqUrlsList != null && !sdcReqUrlsList.isEmpty()) {\r
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);
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
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;
* @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) {
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;
}
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;
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 {
}
@Bean
- public RefProp getRefProp() throws IOException {
+ public RefProp getRefProp() {
return new RefProp();
}
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 {
/**
// the ObjectMapper readValue method closes the stream no need to do it
return new ObjectMapper().readValue(cldsUsersFile, CldsUser[].class);
}
+
+ private CldsUserJsonDecoder() {
+
+ }
}
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;
* @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());
}
/**
* @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());
}
/**
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;
}
}
}
- public void doHealthCheck() throws SQLException, IOException {
+ public void doHealthCheck() {
jdbcTemplateObject.execute(HEALTHCHECK);
}
--- /dev/null
+/*-
+ * ============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);
+ }
+
+}
--- /dev/null
+/*-
+ * ============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;
+ }
+}
/**
* 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();
*/
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");
}
/**
* [{"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";
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) {
// 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 {
* @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);
}
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);
* ""]},{"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();
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()));
}
* @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");
}
*/
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");
* @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");
* "outputEventName","value":["ABATED"]}]]}]}}
*
*/
-public class StringMatch extends ModelElement {
+public class StringMatch extends AbstractModelElement {
private List<ResourceGroup> resourceGroups;
*
*
*/
-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();
*/
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
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);
/**
* 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
@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();
@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";
}
public String[] getPermissionsString() {
- return Arrays.stream(getPermissions()).map(perm -> perm.getKey()).toArray(String[]::new);
+ return Arrays.stream(getPermissions()).map(SecureServicePermission::getKey).toArray(String[]::new);
}
/**
public class SdcReqTest {
- String baseUrl = "AYBABTU";
+ String baseUrl = "AYBABTU";
String serviceInvariantUUID = "serviceInvariantUUID";
@Test
- public void getSdcReqUrlsListNoGlobalPropTest() throws Exception {
+ public void getSdcReqUrlsListNoGlobalPropTest() {
ModelProperties prop = mock(ModelProperties.class);
SdcCatalogServices sdcCatalogServices = mock(SdcCatalogServices.class);
DelegateExecution delegateExecution = mock(DelegateExecution.class);
try {
responseMessage = policyClient.sendMicroServiceInJson(policyJson, prop, tcaPolicyRequestUuid);
} catch (Exception e) {
- assertTrue(e.getMessage().contains("Policy send failed: PE500 "));
+ assertTrue(e.getMessage().contains("Exception while communicating with Policy"));
}
System.out.println(responseMessage);
}
@Test
public void getServiceUuidFromServiceInvariantIdTest() throws Exception {
SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);
- Mockito.when(spy.getSdcServicesInformation(null)).thenReturn(IOUtils.toString(
- SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8"));
+ Mockito.doReturn(IOUtils.toString(
+ SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8"))
+ .when(spy).getSdcServicesInformation(null);
// Try the vcts4 version 1.0, this one should be replaced by 1.1 so it
// should not exist, returning empty string
String resUuidVcts4Null = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9b");
@Test
public void getCldsServiceDataWithAlarmConditionsTest() throws Exception {
SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);
- Mockito.when(spy.getSdcServicesInformation(null)).thenReturn(IOUtils.toString(
- SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8"));
+
+ Mockito.doReturn(IOUtils.toString(
+ SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8"))
+ .when(spy).getSdcServicesInformation(null);
// This invariant uuid is the one from vcts4 v1.1
String serviceResourceDetailUrl = refProp.getStringValue("sdc.serviceUrl")
assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(cldsServiceData.getServiceUUID()));
assertTrue(cldsServiceData.getCldsVfs().size() == 1);
- List<CldsAlarmCondition> alarmsList = spy.getAllAlarmConditionsFromCldsServiceData(cldsServiceData, "alarmCondition");
+ List<CldsAlarmCondition> alarmsList = spy.getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
+ "alarmCondition");
assertTrue(alarmsList.size() == 6);
}
/**\r
* A CustomModelElement to test the capability to add new elements on the fly.\r
*/\r
-public class CustomModelElement extends ModelElement {\r
+public class CustomModelElement extends AbstractModelElement {\r
\r
private static final String CUSTOM_TYPE = "customType";\r
\r