import javax.ws.rs.BadRequestException;
+import org.onap.clamp.clds.client.req.TcaRequestFormatter;
import org.onap.clamp.clds.exception.policy.PolicyClientException;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.refprop.RefProp;
* 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_";
// 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");
// Set Policy Type
policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
- policyParameters.setEcompName(refProp.getStringValue("policy.ecomp.name"));
+ policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
policyParameters.setConfigBody(policyJson);
/**
* 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
policyParameters.setPolicyConfigType(PolicyConfigType.Base);
- policyParameters.setEcompName(refProp.getStringValue("policy.ecomp.name"));
+ policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
policyParameters.setConfigBody(configBody);
policyParameters.setConfigBodyType(PolicyType.OTHER);
policyParameters.setConfigName("HolmesPolicy");
+ policyParameters.setPolicyName(configPolicyName);
policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
return rtnMsg;
}
+ /**
+ * Perform send of Microservice policy in OTHER type.
+ *
+ * @param configBody
+ * The config policy string body
+ * @param prop
+ * The ModelProperties
+ * @param policyRequestUuid
+ * The policy request UUID
+ * @return The answer from policy call
+ */
+ public String sendMicroServiceInOther(String configBody, ModelProperties prop, String policyRequestUuid) {
+
+ PolicyParameters policyParameters = new PolicyParameters();
+ // Set Policy Type
+ policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
+ policyParameters.setOnapName("DCAE");
+ policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
+ policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
+ policyParameters.setConfigBody(configBody);
+ String policyNamePrefix = refProp.getStringValue("policy.ms.policyNamePrefix");
+
+ // Adding this line to clear the policy id from policy name while
+ // pushing to policy engine
+ prop.setPolicyUniqueId("");
+
+ String rtnMsg = send(policyParameters, prop, policyNamePrefix);
+ String policyType = refProp.getStringValue("policy.ms.type");
+ push(policyType, prop);
+
+ return rtnMsg;
+ }
+
/**
* Perform send of policy.
*
* @param prop
* The ModelProperties
* @return The response message of Policy
- * @throws Exception
*/
protected String send(PolicyParameters policyParameters, ModelProperties prop, String policyNamePrefix) {
// Verify whether it is triggered by Validation Test button from UI
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;
+
}
/**