Policy client fixes
[clamp.git] / src / main / java / org / onap / clamp / clds / client / PolicyClient.java
index 7aa1330..ed29afe 100644 (file)
@@ -62,7 +62,6 @@ import org.springframework.context.ApplicationContext;
  * Policy utility methods - specifically, send the policy.
  */
 public class PolicyClient {
-
     protected static final String     POLICY_PREFIX_BASE         = "Config_";
     protected static final String     POLICY_PREFIX_BRMS_PARAM   = "Config_BRMS_Param_";
     protected static final String     POLICY_PREFIX_MICROSERVICE = "Config_MS_";
@@ -109,9 +108,7 @@ public class PolicyClient {
         // following failure: java.lang.Exception: Policy send failed: PE300 -
         // Data Issue: No policyDescription given.
         policyParameters.setPolicyDescription(refProp.getStringValue("op.policyDescription"));
-
         policyParameters.setAttributes(attributes);
-
         // Set a random UUID(Mandatory)
         policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
         String policyNamePrefix = refProp.getStringValue("policy.op.policyNamePrefix");
@@ -162,17 +159,20 @@ public class PolicyClient {
 
     /**
      * Perform send of base policy in OTHER type.
-     * 
+     *
      * @param configBody
      *            The config policy string body
+     * @param configPolicyName
+     *            The config policy name of the component that has been
+     *            pre-deployed in DCAE
      * @param prop
      *            The ModelProperties
      * @param policyRequestUuid
      *            The policy request UUID
      * @return The answer from policy call
      */
-    public String sendBasePolicyInOther(String configBody, ModelProperties prop, String policyRequestUuid) {
-
+    public String sendBasePolicyInOther(String configBody, String configPolicyName, ModelProperties prop,
+            String policyRequestUuid) {
         PolicyParameters policyParameters = new PolicyParameters();
 
         // Set Policy Type
@@ -183,6 +183,7 @@ public class PolicyClient {
         policyParameters.setConfigBody(configBody);
         policyParameters.setConfigBodyType(PolicyType.OTHER);
         policyParameters.setConfigName("HolmesPolicy");
+        policyParameters.setPolicyName(configPolicyName);
 
         policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
 
@@ -210,16 +211,12 @@ public class PolicyClient {
     public String sendMicroServiceInOther(String configBody, ModelProperties prop, String policyRequestUuid) {
 
         PolicyParameters policyParameters = new PolicyParameters();
-
-        // Set Policy Type
+        // Set Policy Type 
         policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
+        policyParameters.setOnapName("DCAE");
         policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
         policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
-
         policyParameters.setConfigBody(configBody);
-        policyParameters.setConfigBodyType(PolicyType.OTHER);
-
-        policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
         String policyNamePrefix = refProp.getStringValue("policy.ms.policyNamePrefix");
 
         // Adding this line to clear the policy id from policy name while
@@ -323,6 +320,7 @@ public class PolicyClient {
             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);
 
@@ -362,15 +360,18 @@ public class PolicyClient {
 
         logger.info("policyName=" + policyName);
         configRequestParameters.setPolicyName(policyName);
-
-        Collection<PolicyConfig> response = getPolicyEngine().getConfig(configRequestParameters);
-        for (PolicyConfig policyConfig : response) {
-            Integer version = Integer.valueOf(policyConfig.getPolicyVersion());
-            versions.add(version);
+        try {
+            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());
+        } catch (PolicyConfigException e) {
+            // just print warning - if no policy version found
+            logger.warn("warning: policy not found...policy name - " + policyName, e.getMessage());
         }
-        Collections.sort(versions);
-        logger.info("Policy versions.size()=" + versions.size());
-
         return versions;
 
     }