* Policy utility methods - specifically, send the policy.
*/
public class PolicyClient {
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyClient.class);
- protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+
+ 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();
@Value("${org.onap.clamp.config.files.cldsPolicyConfig:'classpath:/clds/clds-policy-config.properties'}")
protected String cldsPolicyConfigFile;
@Autowired
protected RefProp refProp;
- public PolicyClient() {
-
- }
-
/**
* Perform send of microservice policy.
*
// API method to create or update Policy.
PolicyChangeResponse response = null;
- String responseMessage;
+ String responseMessage = "";
Date startTime = new Date();
try {
List<Integer> versions = getVersions(policyNamePrefix, prop);
- if (versions.size() <= 0) {
+ if (versions.isEmpty()) {
LoggingUtils.setTargetContext("Policy", "createPolicy");
logger.info("Attempting to create policy for action=" + prop.getActionCd());
response = policyEngine.createPolicy(policyParameters);
responseMessage = response.getResponseMessage();
}
} catch (Exception e) {
- responseMessage = e.toString();
+ logger.error("Exception occurred during policy communnication", e);
}
- logger.info("response is " + responseMessage);
+ logger.info(LOG_POLICY_PREFIX + responseMessage);
LoggingUtils.setTimeContext(startTime, new Date());
// API method to create or update Policy.
PolicyChangeResponse response = null;
- String responseMessage;
+ String responseMessage = "";
try {
logger.info("Attempting to push policy...");
response = policyEngine.pushPolicy(pushPolicyParameters);
responseMessage = response.getResponseMessage();
} catch (Exception e) {
- responseMessage = e.toString();
+ logger.error("Exception occurred during policy communnication", e);
}
- logger.info("response is " + responseMessage);
+ logger.info(LOG_POLICY_PREFIX + responseMessage);
if (response != null && (response.getResponseCode() == 200 || response.getResponseCode() == 204)) {
logger.info("Policy push successful");
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);
+ logger.warn("warning: policy not found...policy name - " + policyName, e);
}
return versions;
deletePolicyParameters.setPdpGroup(refProp.getStringValue("policy.pdp.group"));
deletePolicyParameters.setPolicyType(policyType);
// send delete request
- String responseMessage = null;
- responseMessage = sendDeletePolicy(deletePolicyParameters, prop);
+ String responseMessage = sendDeletePolicy(deletePolicyParameters, prop);
logger.info("Deleting policy from PAP...");
deletePolicyParameters.setPolicyComponent("PAP");
// API method to create or update Policy.
PolicyChangeResponse response = null;
- String responseMessage;
+ String responseMessage = "";
try {
logger.info("Attempting to delete policy...");
response = policyEngine.deletePolicy(deletePolicyParameters);
responseMessage = response.getResponseMessage();
} catch (Exception e) {
- responseMessage = e.toString();
+ logger.error("Exception occurred during policy communnication", e);
}
- logger.info("response is " + responseMessage);
+ logger.info(LOG_POLICY_PREFIX + responseMessage);
if (response != null && response.getResponseCode() == 200) {
logger.info("Policy delete successful");
\r
// To remove duplicate resources from serviceDetail and add valid\r
// vfs to service\r
- if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {\r
+ if (cldsSdcServiceDetail.getResources() != null) {\r
List<CldsSdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(\r
cldsSdcServiceDetail.getResources());\r
- if (cldsSdcResourceList != null && cldsSdcResourceList.size() > 0) {\r
+ if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {\r
List<CldsVfData> cldsVfDataList = new ArrayList<>();\r
for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) {\r
if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null\r
- && currCldsSdcResource.getResoucreType().equalsIgnoreCase("VF")) {\r
+ && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {\r
CldsVfData currCldsVfData = new CldsVfData();\r
currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName());\r
currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID());\r
*/\r
private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) throws IOException {\r
// todo : refact this..\r
- if (cldsVfDataList != null && cldsVfDataList.size() > 0) {\r
+ if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
RESOURCE_VF_TYPE);\r
List<CldsSdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
List<CldsVfcData> vfcDataListFromVfResponse = getVfcDataListFromVfResponse(vfResponse);\r
if (vfcDataListFromVfResponse != null) {\r
currCldsVfData.setCldsVfcs(vfcDataListFromVfResponse);\r
- if (vfcDataListFromVfResponse.size() > 0) {\r
+ if (!vfcDataListFromVfResponse.isEmpty()) {\r
// To get artifacts for every VFC and get\r
// alarm conditions from artifact\r
for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) {\r
\r
private List<CldsVfcData> getVFCfromCVFC(String resourceUUID) {\r
String catalogUrl = refProp.getStringValue("sdc.catalog.url");\r
- List<CldsVfcData> cldsVfcDataList = new ArrayList<CldsVfcData>();\r
+ List<CldsVfcData> cldsVfcDataList = new ArrayList<>();\r
\r
if (resourceUUID != null) {\r
String vfcResourceUUIDUrl = catalogUrl + "resources" + "/" + resourceUUID + "/metadata";\r
}\r
\r
private String removeUnwantedBracesFromString(String id) {\r
+ String idReworked = "";\r
if (id != null && id.contains("\"")) {\r
- id = id.replaceAll("\"", "");\r
+ idReworked = id.replaceAll("\"", "");\r
}\r
- return id;\r
+ return idReworked;\r
}\r
\r
private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws IOException {\r
\r
// Method to get the artifact for any particular VF\r
private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws JsonProcessingException, IOException {\r
- List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>();\r
+ List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
ObjectMapper mapper = new ObjectMapper();\r
ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
ArrayNode artifactsArrayNode = (ArrayNode) vfResponseNode.get("artifacts");\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<CldsVfKPIData>();\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
\r
public String getResponsesFromArtifactUrl(String artifactsUrl) {\r
String hostUrl = refProp.getStringValue("sdc.hostUrl");\r
- artifactsUrl = artifactsUrl.replaceAll("\"", "");\r
- String artifactUrl = hostUrl + artifactsUrl;\r
+ String artifactsUrlReworked = artifactsUrl.replaceAll("\"", "");\r
+ String artifactUrl = hostUrl + artifactsUrlReworked;\r
logger.info("value of artifactURl:" + artifactUrl);\r
String currArtifactResponse = getCldsServicesOrResourcesBasedOnURL(artifactUrl, true);\r
logger.info("value of artifactResponse:" + currArtifactResponse);\r
*/\r
public String getCldsServicesOrResourcesBasedOnURL(String url, boolean alarmConditions) {\r
try {\r
- url = removeUnwantedBracesFromString(url);\r
- URL urlObj = new URL(url);\r
+ String urlReworked = removeUnwantedBracesFromString(url);\r
+ URL urlObj = new URL(urlReworked);\r
\r
HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
String basicAuth = SdcReq.getSdcBasicAuth(refProp);\r
response = new StringBuilder();\r
String inputLine;\r
while ((inputLine = in.readLine()) != null) {\r
- response.append(inputLine);\r
+ if (!inputLine.isEmpty()) {\r
+ response.append(inputLine);\r
+ }\r
if (alarmConditions) {\r
response.append("\n");\r
}\r
\r
// To create byKpi\r
ObjectNode kpiObjectNode = mapper.createObjectNode();\r
- if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) {\r
+ if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
if (currCldsVfData != null) {\r
createKpiObjectNodeByVfUuid(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList());\r
\r
// To create byVfc and alarmCondition with vfcResourceUUID\r
ObjectNode vfcResourceUuidObjectNode = mapper.createObjectNode();\r
- if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) {\r
+ if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
if (currCldsVfData != null) {\r
createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode,\r
List<CldsAlarmCondition> cldsAlarmCondList) {\r
ObjectNode alarmCondKeyNode = mapper.createObjectNode();\r
\r
- if (cldsAlarmCondList != null && cldsAlarmCondList.size() > 0) {\r
+ if (cldsAlarmCondList != null && !cldsAlarmCondList.isEmpty()) {\r
for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {\r
if (currCldsAlarmCondition != null) {\r
ObjectNode alarmCondNode = mapper.createObjectNode();\r
ObjectNode vfObjectNode = mapper.createObjectNode();\r
ObjectNode vfUuidNode = mapper.createObjectNode();\r
List<CldsVfData> cldsVfsList = cldsServiceData.getCldsVfs();\r
- if (cldsVfsList != null && cldsVfsList.size() > 0) {\r
+ if (cldsVfsList != null && !cldsVfsList.isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsVfsList) {\r
if (currCldsVfData != null) {\r
vfUuidNode.put(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName());\r
\r
private void createKpiObjectNodeByVfUuid(ObjectMapper mapper, ObjectNode vfResourceUuidObjectNode,\r
List<CldsVfKPIData> cldsVfKpiDataList) {\r
- if (cldsVfKpiDataList != null && cldsVfKpiDataList.size() > 0) {\r
+ if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) {\r
for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {\r
if (currCldsVfKpiData != null) {\r
ObjectNode thresholdNameObjectNode = mapper.createObjectNode();\r
ObjectNode vfcObjectNode = mapper.createObjectNode();\r
ObjectNode alarmCondNode = mapper.createObjectNode();\r
ObjectNode alertDescNode = mapper.createObjectNode();\r
- if (cldsVfcDataList != null && cldsVfcDataList.size() > 0) {\r
+ if (cldsVfcDataList != null && !cldsVfcDataList.isEmpty()) {\r
for (CldsVfcData currCldsVfcData : cldsVfcDataList) {\r
if (currCldsVfcData != null) {\r
if (currCldsVfcData.getCldsAlarmConditions() != null\r
- && currCldsVfcData.getCldsAlarmConditions().size() > 0) {\r
+ && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {\r
alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(),\r
currCldsAlarmCondition.getAlarmConditionKey());\r
private ObjectNode createVfcObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) {\r
ObjectNode vfUuidObjectNode = mapper.createObjectNode();\r
\r
- if (cldsVfDataList != null && cldsVfDataList.size() > 0) {\r
+ if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsVfDataList) {\r
if (currCldsVfData != null) {\r
ObjectNode vfcObjectNode = mapper.createObjectNode();\r
ObjectNode vfcUuidNode = mapper.createObjectNode();\r
- if (currCldsVfData.getCldsVfcs() != null && currCldsVfData.getCldsVfcs().size() > 0) {\r
+ if (currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {\r
for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {\r
vfcUuidNode.put(currCldsVfcData.getVfcInvariantResourceUUID(),\r
currCldsVfcData.getVfcName());\r
private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,\r
List<CldsSdcResourceBasicInfo> resourceInfoList) throws IOException {\r
String resourceUuid = null;\r
- if (resourceInfoList != null && resourceInfoList.size() > 0) {\r
+ if (resourceInfoList != null && !resourceInfoList.isEmpty()) {\r
for (CldsSdcResourceBasicInfo currResource : resourceInfoList) {\r
if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null\r
&& currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {\r