aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java39
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java23
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java33
-rw-r--r--src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html245
-rw-r--r--src/test/java/org/onap/clamp/clds/it/OperationPolicyReqIT.java89
-rw-r--r--src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java5
-rw-r--r--src/test/resources/example/model-properties/modelBpmnProp.json6
-rw-r--r--src/test/resources/example/model-properties/modelBpmnPropWithGlobal.json3
-rw-r--r--src/test/resources/example/modelProp.json95
-rw-r--r--src/test/resources/example/modelPropForPolicy.json28
-rw-r--r--src/test/resources/example/operational-policy/yaml-policy-chain-1.yaml112
-rw-r--r--src/test/resources/example/operational-policy/yaml-policy-chain-2.yaml112
12 files changed, 567 insertions, 223 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java b/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java
index ad466ee7..a64bd717 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java
@@ -66,6 +66,10 @@ public class OperationalPolicyReq {
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(OperationalPolicyReq.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ private OperationalPolicyReq() {
+
+ }
+
/**
* Format Operational Policy attributes.
*
@@ -127,12 +131,16 @@ public class OperationalPolicyReq {
String recipe = policyItem.getRecipe();
String maxRetries = String.valueOf(policyItem.getMaxRetries());
String retryTimeLimit = String.valueOf(policyItem.getRetryTimeLimit());
+ String targetResourceId = String.valueOf(policyItem.getTargetResourceId());
logger.info("recipe=" + recipe);
logger.info("maxRetries=" + maxRetries);
logger.info("retryTimeLimit=" + retryTimeLimit);
+ logger.info("targetResourceId=" + targetResourceId);
ruleAttributes.put("Recipe", recipe);
ruleAttributes.put("MaxRetries", maxRetries);
ruleAttributes.put("RetryTimeLimit", retryTimeLimit);
+ ruleAttributes.put("ResourceId", targetResourceId);
+
} else {
logger.info("templateName=" + templateName);
logger.info("operationTopic=" + operationTopic);
@@ -189,24 +197,22 @@ public class OperationalPolicyReq {
builder.addResource(vfcResources);
// process each policy
- HashMap<String, org.onap.policy.controlloop.policy.Policy> policyObjMap = new HashMap<>();
+ HashMap<String, Policy> policyObjMap = new HashMap<>();
List<PolicyItem> policyItemList = orderParentFirst(policyChain.getPolicyItems());
- Target target = new Target();
- target.setType(TargetType.VM);
- for (int i = 0; i < policyItemList.size(); i++) {
-
- org.onap.policy.controlloop.policy.Policy policyObj;
- PolicyItem policyItem = policyItemList.get(i);
+ for (PolicyItem policyItem : policyItemList) {
String policyName = policyItem.getRecipe() + " Policy";
- if (i == 0) {
+ Target target = new Target();
+ target.setType(TargetType.VM);
+ target.setResourceID(policyItem.getTargetResourceId());
+ Policy policyObj;
+ if (policyItemList.indexOf(policyItem) == 0) {
String policyDescription = policyItem.getRecipe()
+ " Policy - the trigger (no parent) policy - created by CLDS";
policyObj = builder.setTriggerPolicy(policyName, policyDescription,
refProp.getStringValue("op.policy.appc"), target, policyItem.getRecipe(), null,
policyItem.getMaxRetries(), policyItem.getRetryTimeLimit());
} else {
- org.onap.policy.controlloop.policy.Policy parentPolicyObj = policyObjMap
- .get(policyItem.getParentPolicy());
+ Policy parentPolicyObj = policyObjMap.get(policyItem.getParentPolicy());
String policyDescription = policyItem.getRecipe() + " Policy - triggered conditionally by "
+ parentPolicyObj.getName() + " - created by CLDS";
policyObj = builder.setPolicyForPolicyResult(policyName, policyDescription,
@@ -269,14 +275,15 @@ public class OperationalPolicyReq {
HashMap<String, Policy> policyObjMap = new HashMap<>();
List<PolicyItem> policyItemList = addAOTSActorRecipe(refProp, global.getService(),
policyChain.getPolicyItems());
- Target target = new Target();
- target.setType(TargetType.VM);
+
Policy lastPolicyObj = new Policy();
- for (int i = 0; i < policyItemList.size(); i++) {
- org.onap.policy.controlloop.policy.Policy policyObj;
- PolicyItem policyItem = policyItemList.get(i);
+ for (PolicyItem policyItem : policyItemList) {
+ Target target = new Target();
+ target.setType(TargetType.VM);
+ target.setResourceID(policyItem.getTargetResourceId());
String policyName = policyItem.getRecipe() + " Policy";
- if (i == 0) {
+ Policy policyObj;
+ if (policyItemList.indexOf(policyItem) == 0) {
// To set up time window payload for trigger policy
Map<String, String> payloadMap = new HashMap<>();
payloadMap.put("timeWindow", refProp.getStringValue("op.eNodeB.timeWindow"));
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java b/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java
index c8c2ef46..5264629f 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java
@@ -23,14 +23,14 @@
package org.onap.clamp.clds.model.prop;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
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;
+
/**
* Parse Policy json properties.
*
@@ -42,24 +42,27 @@ import com.fasterxml.jackson.databind.JsonNode;
* :"_id","value":["q2JmHD5"]},{"name":"parentPolicy","value":[""]}],[{"name":
* "recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]},{"name":
* "retryTimeLimit","value":["180"]},{"name":"_id","value":["0ZqHdrR"]},{"name":
- * "parentPolicy","value":[""]}]]}],"PolicyTest2":[{"name":"pname","value":
+ * "parentPolicy","value":[""]},{"name":
+ * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}],
+ * "PolicyTest2":[{"name":"pname","value":
* "PolicyTest2"},{"name":"pid","value":"2"},{"name":"timeout","value":"345"},{
* "policyConfigurations":[[{"name":"recipe","value":["restart"]},{"name":
* "maxRetries","value":["3"]},{"name":"retryTimeLimit","value":["180"]},{"name"
* :"_id","value":["q2JmHD5"]},{"name":"parentPolicy","value":[""]}],[{"name":
* "recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]},{"name":
* "retryTimeLimit","value":["180"]},{"name":"_id","value":["0ZqHdrR"]},{"name":
- * "parentPolicy","value":[""]}]]}]}} f
+ * "parentPolicy","value":[""]},{"name":
+ * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}]}} f
*
*/
public class PolicyChain {
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyChain.class);
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyChain.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
- private String policyId;
- private Integer timeout;
- private List<PolicyItem> policyItems;
+ private String policyId;
+ private Integer timeout;
+ private List<PolicyItem> policyItems;
public PolicyChain(JsonNode node) {
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java b/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java
index c84affef..5fc82983 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java
@@ -23,12 +23,12 @@
package org.onap.clamp.clds.model.prop;
-import java.util.List;
-
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.databind.JsonNode;
+import java.util.List;
+
/**
* Parse policyConfigurations from Policy json properties.
* <p>
@@ -44,19 +44,21 @@ import com.fasterxml.jackson.databind.JsonNode;
* ,{"name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"
* ]},{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[
* ""]},{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[
- * "vf3RtPi"]}]]}]
+ * "vf3RtPi"]},{"name":
+ * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}]
*/
public class PolicyItem implements Cloneable {
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyItem.class);
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyItem.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
- private String id;
- private String recipe;
- private int maxRetries;
- private int retryTimeLimit;
- private String parentPolicy;
- private List<String> parentPolicyConditions;
- private String actor;
+ private String id;
+ private String recipe;
+ private int maxRetries;
+ private int retryTimeLimit;
+ private String parentPolicy;
+ private List<String> parentPolicyConditions;
+ private String actor;
+ private String targetResourceId;
/**
* Parse Policy given json node.
@@ -70,6 +72,7 @@ public class PolicyItem implements Cloneable {
retryTimeLimit = AbstractModelElement.getIntValueByName(node, "retryTimeLimit");
parentPolicy = AbstractModelElement.getValueByName(node, "parentPolicy");
parentPolicyConditions = AbstractModelElement.getValuesByName(node, "parentPolicyConditions");
+ targetResourceId = AbstractModelElement.getValueByName(node, "targetResourceId");
}
@@ -171,6 +174,14 @@ public class PolicyItem implements Cloneable {
this.actor = actor;
}
+ public String getTargetResourceId() {
+ return targetResourceId;
+ }
+
+ public void setTargetResourceId(String targetResourceId) {
+ this.targetResourceId = targetResourceId;
+ }
+
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
diff --git a/src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html b/src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html
index 4f7a77d4..00e16751 100644
--- a/src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html
+++ b/src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html
@@ -23,14 +23,15 @@
<style>
-#deletePolicy{
- height:34px;
- background-color:#dddd;
+#deletePolicy {
+ height: 34px;
+ background-color: #dddd;
}
-.disabled{
+.disabled {
background-color: #dddd;
}
+
.fileUpload {
position: relative;
overflow: hidden;
@@ -60,61 +61,62 @@
margin-top: 17px;
}
-.modelSearchBox{
- position:absolute;
+.modelSearchBox {
+ position: absolute;
padding: 25px 12px;
}
-label{
- text-align:right;
- vertical-align:middle;
+label {
+ text-align: right;
+ vertical-align: middle;
}
-.leftPolicyPanel{
+.leftPolicyPanel {
padding: 0 10px 0 0;
}
-#createNewPolicy{
- height:34px;
- width:120px; /*84*/
- background-color:#f2bfab;
+#createNewPolicy {
+ height: 34px;
+ width: 120px; /*84*/
+ background-color: #f2bfab;
}
-.idError{
- color:red;
- padding:50px 0px;
- text-align:center;
- display:none;
+.idError {
+ color: red;
+ padding: 50px 0px;
+ text-align: center;
+ display: none;
}
-.policyPanel{
+.policyPanel {
background-color: #f5f5f5;
padding: 15px 5px 0 5px;
}
-.form-group.clearfix{
- display:-webkit-flex;
- display: flex;
+.form-group.clearfix {
+ display: -webkit-flex;
+ display: flex;
align-items: center;
}
-label{
- margin-bottom:0px;
+label {
+ margin-bottom: 0px;
}
-#policySearch{
+#policySearch {
height: 33px;
font-size: 12px;
padding: 2px 2px 2px 30px;
margin-bottom: 5px;
- width:100%;
+ width: 100%;
}
-#policyTable{
+
+#policyTable {
cursor: pointer;
- width:100%;
+ width: 100%;
}
-#policyTable tr{
+#policyTable tr {
border-bottom: 1px solid #ddd;
border-collapse: collapse;
text-align: left;
@@ -122,22 +124,21 @@ label{
font-weight: normal;
}
-#policyTable td{
+#policyTable td {
padding: 8px 10px;
}
-#policyTable tr.highlight{
+#policyTable tr.highlight {
background-color: #f5f5f5;
font-weight: bold;
font-size: 13px;
}
-#policyTableHolder{
- height:200px;
- width: 100%;
- overflow:auto;
+#policyTableHolder {
+ height: 200px;
+ width: 100%;
+ overflow: auto;
}
-
</style>
<script type="text/javascript">
@@ -163,128 +164,136 @@ label{
</script>
- <div attribute-test="policywindowproperties" id="configure-widgets"
- class="disabled-block-container">
+<div attribute-test="policywindowproperties" id="configure-widgets"
+ class="disabled-block-container">
<div attribute-test="policywindowpropertiesh" class="modal-header">
<button type="button" class="close" ng-click="close(false)"
aria-hidden="true" style="margin-top: -3px">&times;</button>
<h4>Operational Policy</h4>
- </div>
-
-
+ </div>
+
+
<div class="modal-body">
- <div attribute-test="policywindowpropertiesb" class="modal-body row">
-
- <div class="leftPolicyPanel">
- <div class="panel panel-default">
+ <div attribute-test="policywindowpropertiesb" class="modal-body row">
+
+ <div class="leftPolicyPanel">
+ <div class="panel panel-default">
<i class="glyphicon glyphicon-search modelSearchBox"></i>
<input type="text" id="policySearch" onkeyup="searchPolicyList()"
- placeholder="Search ...">
- <div id="policyTableHolder">
- <table id="policyTable"></table>
+ placeholder="Search ...">
+ <div id="policyTableHolder">
+ <table id="policyTable"></table>
+ </div>
</div>
- </div>
- <div style="float:left">
+ <div style="float: left">
<button type="button" id="createNewPolicy" class="btn btn-sm">New Policy</button></span>
- </div>
- <div style="float:right">
+ </div>
+ <div style="float: right">
<button type="button" id="deletePolicy" class="btn btn-sm glyphicon glyphicon-trash" disabled></button></span>
- </div>
+ </div>
<div id="repeatIdError" class="idError">Error: This Policy name is already taken.</div>
<div id="newIdError" class="idError">Error: Please rename your new Policy.</div>
<div id="spaceError" class="idError">Error: Spaces are not allowed in the ID.</div>
- </div>
-
+ </div>
+
<div class="panel panel-default col-sm-9 policyPanel" style="display:none;">
- <form id="Timeoutform" class="form-horizontal">
- <div>
- <div class="form-group clearfix row">
- <label class="col-sm-2">Name</label>
- <div class="col-sm-3" style="padding:0px;">
+ <form id="Timeoutform" class="form-horizontal">
+ <div>
+ <div class="form-group clearfix row">
+ <label class="col-sm-2">Name</label>
+ <div class="col-sm-3" style="padding: 0px;">
<input type="text" id="pname" name="pname" maxlength="48" placeholder="Enter Unique Name" class="form-control">
- </div>
-
- <label class="col-sm-1">ID</label>
- <div class="col-sm-1" style="padding:0px;">
+ </div>
+
+ <label class="col-sm-1">ID</label>
+ <div class="col-sm-1" style="padding: 0px;">
<input onkeydown="return false;" type="text" id="pid" name="pid" class="form-control" readonly>
- </div>
-
+ </div>
+
<label for="userID" class="col-sm-3" style="padding-left:5px;padding-right:10px;">Overall Time Limit</label>
- <div class="col-sm-2" style="padding-left:0px;">
+ <div class="col-sm-2" style="padding-left: 0px;">
<input type="text" maxlength="10" onkeypress="return isNumberKey(event)"
class="form-control" id="timeout" name="timeout">
- </div>
+ </div>
+ </div>
</div>
+ </form>
+ <div class="panel-heading" style="background-color: white;">
+ <ul id="nav_Tabs" class="nav nav-tabs">
+ <li class><a id="add_one_more" href="#desc_tab"><span
+ class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></li>
+ </ul>
</div>
- </form>
- <div class="panel-heading" style="background-color: white;">
- <ul id="nav_Tabs" class="nav nav-tabs">
- <li class><a id="add_one_more" href="#desc_tab"><span
- class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></li>
- </ul>
- </div>
- <div class="panel-body">
- <div class="tab-content">
- <div id="properties_tab" class="tab-pane fade in active"></div>
+ <div class="panel-body">
+ <div class="tab-content">
+ <div id="properties_tab" class="tab-pane fade in active"></div>
+ </div>
</div>
</div>
- </div>
-
- <span id="formSpan" style="display: none">
- <form class="saveProps" class="form-horizontal">
- <div>
- <div class="form-group clearfix" >
- <label class="col-sm-4 control-label" for="recipe">Recipe</label>
- <div class="col-sm-8">
+
+ <span id="formSpan" style="display: none">
+ <form class="saveProps" class="form-horizontal">
+ <div>
+ <div class="form-group clearfix">
+ <label class="col-sm-4 control-label" for="recipe">Recipe</label>
+ <div class="col-sm-8">
<select class="form-control" name="recipe" id="recipe" enableFilter="true"></select>
+ </div>
</div>
- </div>
- <div class="form-group clearfix">
- <label for="maxRetries" class="col-sm-4 control-label">
- Max Retries</label>
- <div class="col-sm-8">
+ <div class="form-group clearfix">
+ <label for="maxRetries" class="col-sm-4 control-label">
+ Max Retries</label>
+ <div class="col-sm-8">
<input type="text" maxlength="5" class="form-control" id="maxRetries"
onkeypress="return isNumberKey(event)"
- name="maxRetries"> </input>
+ name="maxRetries"> </input>
+ </div>
</div>
- </div>
- <div class="form-group clearfix" >
- <label for="retryTimeLimit" class="col-sm-4 control-label" >
- Retry Time Limit</label>
- <div class="col-sm-8">
+ <div class="form-group clearfix">
+ <label for="retryTimeLimit" class="col-sm-4 control-label">
+ Retry Time Limit</label>
+ <div class="col-sm-8">
<input type="text" maxlength="5" class="form-control" id="retryTimeLimit"
onkeypress="return isNumberKey(event)"
- name="retryTimeLimit"></input>
+ name="retryTimeLimit"></input>
+ </div>
</div>
- </div>
- <div style="display:none;" class="form-group clearfix">
+ <div style="display: none;" class="form-group clearfix">
<label for="_id" class="col-sm-4 control-label">
PolicyID</label>
- <div class="col-sm-8">
+ <div class="col-sm-8">
<input type="text" onkeydown="return false;" class="form-control" id="_id"
name="_id" value=""></input>
+ </div>
</div>
- </div>
- <div class="form-group clearfix">
- <label for="parentPolicy" class="col-sm-4 control-label">
- Parent Policy</label>
- <div class="col-sm-8">
- <select class="form-control" id="parentPolicy"
+ <div class="form-group clearfix">
+ <label for="parentPolicy" class="col-sm-4 control-label">
+ Parent Policy</label>
+ <div class="col-sm-8">
+ <select class="form-control" id="parentPolicy"
name="parentPolicy" enableFilter="true"><option value=""></option></select>
+ </div>
</div>
- </div>
- <div class="form-group clearfix">
+ <div class="form-group clearfix">
<label for="parentPolicyConditions" class="col-sm-4 control-label">
Parent Policy Conditions</label>
- <div class="col-sm-8">
- <select class="form-control" id="parentPolicyConditions"
- name="parentPolicyConditions" multiple></select>
+ <div class="col-sm-8">
+ <select class="form-control" id="parentPolicyConditions"
+ name="parentPolicyConditions" multiple></select>
+ </div>
+ </div>
+ <div class="form-group clearfix">
+ <label for="targetResourceId" class="col-sm-4 control-label">
+ Target ResourceId</label>
+ <div class="col-sm-8">
+ <input type="text" class="form-control" id="targetResourceId"
+ name="targetResourceId"> </input>
+ </div>
</div>
</div>
- </div>
- </form>
- </span>
- </div>
+ </form>
+ </span>
+ </div>
</div>
<div attribute-test="policywindowpropertiesf" class="modal-footer">
@@ -293,7 +302,7 @@ label{
<button ng-click="close(true)" id="close_button"
class="btn btn-primary">Cancel</button>
</div>
-
+
<script>
//Basically this method will add a new form. All forms share the same class. When you want one form to show(active form) the other forms get the
// css attribute display:none
diff --git a/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqIT.java b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqIT.java
new file mode 100644
index 00000000..e57c9dde
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqIT.java
@@ -0,0 +1,89 @@
+/*-
+ * ============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.it;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.clamp.clds.AbstractIT;
+import org.onap.clamp.clds.client.req.OperationalPolicyReq;
+import org.onap.clamp.clds.model.CldsEvent;
+import org.onap.clamp.clds.model.prop.ModelProperties;
+import org.onap.clamp.clds.model.prop.Policy;
+import org.onap.clamp.clds.model.prop.PolicyChain;
+import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.policy.api.AttributeType;
+import org.onap.policy.controlloop.policy.builder.BuilderException;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+@TestPropertySource(locations = "classpath:application-no-camunda.properties")
+public class OperationPolicyReqIT extends AbstractIT {
+
+ @Test
+ public void formatAttributesTest() throws IOException, BuilderException {
+ String modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json");
+ String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json");
+ ModelProperties prop = new ModelProperties("testModel", "controlNameTest", CldsEvent.ACTION_SUBMIT, true,
+ modelBpmnProp, modelProp);
+ List<Map<AttributeType, Map<String, String>>> attributes = new ArrayList<>();
+ if (prop.getType(Policy.class).isFound()) {
+ for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) {
+
+ attributes.add(OperationalPolicyReq.formatAttributes(refProp, prop, prop.getType(Policy.class).getId(),
+ policyChain));
+ }
+ }
+ assertFalse(attributes.isEmpty());
+ assertTrue(attributes.size() == 2);
+ // now validate the Yaml, to do so we replace the dynamic ID by a known
+ // key so that we can compare it
+ String yaml = URLDecoder.decode(attributes.get(0).get(AttributeType.RULE).get("ControlLoopYaml"), "UTF-8");
+ yaml = yaml.replaceAll("trigger_policy: (.*)", "trigger_policy: <generatedId>");
+ yaml = yaml.replaceAll("id: (.*)", "id: <generatedId>");
+ yaml = yaml.replaceAll("success: (.*)", "success: <generatedId>");
+
+ assertEquals(ResourceFileUtil.getResourceAsString("example/operational-policy/yaml-policy-chain-1.yaml"), yaml);
+
+ yaml = URLDecoder.decode(attributes.get(1).get(AttributeType.RULE).get("ControlLoopYaml"), "UTF-8");
+ yaml = yaml.replaceAll("trigger_policy: (.*)", "trigger_policy: <generatedId>");
+ yaml = yaml.replaceAll("id: (.*)", "id: <generatedId>");
+ yaml = yaml.replaceAll("success: (.*)", "success: <generatedId>");
+
+ assertEquals(ResourceFileUtil.getResourceAsString("example/operational-policy/yaml-policy-chain-2.yaml"), yaml);
+ }
+}
diff --git a/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java b/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java
index efeae00d..f87bd37d 100644
--- a/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java
+++ b/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java
@@ -75,6 +75,11 @@ public class ModelPropertiesTest {
assertEquals(1, policy.getPolicyChains().size());
assertEquals("0", policy.getPolicyChains().get(0).getPolicyId());
assertEquals(1, policy.getPolicyChains().get(0).getPolicyItems().size());
+ assertEquals("resourceid", policy.getPolicyChains().get(0).getPolicyItems().get(0).getTargetResourceId());
+ assertEquals(180, policy.getPolicyChains().get(0).getPolicyItems().get(0).getRetryTimeLimit());
+ assertEquals(3, policy.getPolicyChains().get(0).getPolicyItems().get(0).getMaxRetries());
+ assertEquals("", policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicy());
+ assertEquals(null, policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicyConditions());
Tca tca = prop.getType(Tca.class);
assertTrue(tca.isFound());
diff --git a/src/test/resources/example/model-properties/modelBpmnProp.json b/src/test/resources/example/model-properties/modelBpmnProp.json
index 413d3400..3b86ad79 100644
--- a/src/test/resources/example/model-properties/modelBpmnProp.json
+++ b/src/test/resources/example/model-properties/modelBpmnProp.json
@@ -125,6 +125,12 @@
"value": [
""
]
+ },
+ {
+ "name": "targetResourceId",
+ "value": [
+ "resourceid"
+ ]
}
]
]
diff --git a/src/test/resources/example/model-properties/modelBpmnPropWithGlobal.json b/src/test/resources/example/model-properties/modelBpmnPropWithGlobal.json
index 3846f7cf..fba99c6f 100644
--- a/src/test/resources/example/model-properties/modelBpmnPropWithGlobal.json
+++ b/src/test/resources/example/model-properties/modelBpmnPropWithGlobal.json
@@ -165,7 +165,8 @@
"Failure_Exception": "Failure: Exception",
"Failure": "Failure: Other",
"Success": "Success"
- }
+ },
+ "targetResourceId": "resourceid"
},
"shared": {
"byService": {
diff --git a/src/test/resources/example/modelProp.json b/src/test/resources/example/modelProp.json
index 8b8e984f..c2262f52 100644
--- a/src/test/resources/example/modelProp.json
+++ b/src/test/resources/example/modelProp.json
@@ -42,73 +42,6 @@
}
],
- "HighlandPark_":
- [
- [
- {
- "name": "topicPublishes",
- "value": "DCAE-HIGHLANDPARK-EVENT-OUTPUT-VOIP"
- }
- ],
-
- {
- "serviceConfigurations":
- [
- [
- {
- "name": "alarmCondition",
- "value":
- [
- "Reports a transient alarm condition when an incoming ACR message is in conflict with former ACR in one diameter session"
- ]
- },
-
- {
- "name": "eventSourceType",
- "value":
- [
- "f5BigIP"
- ]
- },
-
- {
- "name": "eventSeverity",
- "value":
- [
- "NORMAL"
- ]
- }
- ],
-
- [
- {
- "name": "alarmCondition",
- "value":
- [
- "Reports a transient alarm condition when an incoming ACR message is in conflict with former ACR in one diameter session"
- ]
- },
-
- {
- "name": "eventSourceType",
- "value":
- [
- "f5BigIP"
- ]
- },
-
- {
- "name": "eventSeverity",
- "value":
- [
- "NORMAL"
- ]
- }
- ]
- ]
- }
- ],
-
"StringMatch_":
{
"Group1":
@@ -472,6 +405,13 @@
[
""
]
+ },
+ {
+ "name": "targetResourceId",
+ "value":
+ [
+ "resource-id"
+ ]
}
],
@@ -525,6 +465,13 @@
"Failure_Exception",
"Failure"
]
+ },
+ {
+ "name": "targetResourceId",
+ "value":
+ [
+ "resource-id"
+ ]
}
]
]
@@ -590,6 +537,13 @@
[
""
]
+ },
+ {
+ "name": "targetResourceId",
+ "value":
+ [
+ "resource-id"
+ ]
}
],
@@ -643,6 +597,13 @@
"Failure_Exception",
"Failure"
]
+ },
+ {
+ "name": "targetResourceId",
+ "value":
+ [
+ "resource-id"
+ ]
}
]
]
diff --git a/src/test/resources/example/modelPropForPolicy.json b/src/test/resources/example/modelPropForPolicy.json
index 6923e1a6..bf348092 100644
--- a/src/test/resources/example/modelPropForPolicy.json
+++ b/src/test/resources/example/modelPropForPolicy.json
@@ -87,6 +87,13 @@
[
""
]
+ },
+ {
+ "name": "targetResourceId",
+ "value":
+ [
+ "resource-id"
+ ]
}
],
@@ -140,6 +147,13 @@
"Failure_Exception",
"Failure"
]
+ },
+ {
+ "name": "targetResourceId",
+ "value":
+ [
+ "resource-id"
+ ]
}
]
]
@@ -205,6 +219,13 @@
[
""
]
+ },
+ {
+ "name": "targetResourceId",
+ "value":
+ [
+ "resource-id"
+ ]
}
],
@@ -258,6 +279,13 @@
"Failure_Exception",
"Failure"
]
+ },
+ {
+ "name": "targetResourceId",
+ "value":
+ [
+ "resource-id"
+ ]
}
]
]
diff --git a/src/test/resources/example/operational-policy/yaml-policy-chain-1.yaml b/src/test/resources/example/operational-policy/yaml-policy-chain-1.yaml
new file mode 100644
index 00000000..029cfbb7
--- /dev/null
+++ b/src/test/resources/example/operational-policy/yaml-policy-chain-1.yaml
@@ -0,0 +1,112 @@
+!!org.onap.policy.controlloop.policy.ControlLoopPolicy
+controlLoop:
+ abatement: false
+ controlLoopName: controlNameTest
+ resources:
+ - resourceInvariantUUID: null
+ resourceName: 6c7aaec2-59eb-41d9-8681-b7f976ab668d
+ resourceType: VF
+ resourceUUID: null
+ resourceVersion: null
+ services:
+ - serviceInvariantUUID: null
+ serviceName: 0f983e18-4603-4bb4-a98c-e29691fb16a1
+ serviceUUID: null
+ serviceVersion: null
+ timeout: 500
+ trigger_policy: <generatedId>
+ version: 2.0.0
+policies:
+- actor: AOTS
+ description: checkENodeBTicketHours Policy - the trigger (no parent) policy - created by CLDS
+ failure: FINAL_FAILURE
+ failure_exception: FINAL_FAILURE_EXCEPTION
+ failure_guard: FINAL_FAILURE_GUARD
+ failure_retries: FINAL_FAILURE_RETRIES
+ failure_timeout: FINAL_FAILURE_TIMEOUT
+ id: <generatedId>
+ name: checkENodeBTicketHours Policy
+ operationsAccumulateParams: null
+ payload:
+ timeWindow: '35'
+ recipe: checkENodeBTicketHours
+ retry: 0
+ success: <generatedId>
+ target:
+ resourceID: resource-id
+ type: VM
+ timeout: 120
+- actor: AOTS
+ description: checkEquipmentStatus Policy - triggered conditionally by checkENodeBTicketHours Policy - created by CLDS
+ failure: FINAL_FAILURE
+ failure_exception: FINAL_FAILURE_EXCEPTION
+ failure_guard: FINAL_FAILURE_GUARD
+ failure_retries: FINAL_FAILURE_RETRIES
+ failure_timeout: FINAL_FAILURE_TIMEOUT
+ id: <generatedId>
+ name: checkEquipmentStatus Policy
+ operationsAccumulateParams: null
+ payload: null
+ recipe: checkEquipmentStatus
+ retry: 0
+ success: <generatedId>
+ target:
+ resourceID: resource-id
+ type: VM
+ timeout: 120
+- actor: AOTS
+ description: checkEimStatus Policy - triggered conditionally by checkEquipmentStatus Policy - created by CLDS
+ failure: FINAL_FAILURE
+ failure_exception: FINAL_FAILURE_EXCEPTION
+ failure_guard: FINAL_FAILURE_GUARD
+ failure_retries: FINAL_FAILURE_RETRIES
+ failure_timeout: FINAL_FAILURE_TIMEOUT
+ id: <generatedId>
+ name: checkEimStatus Policy
+ operationsAccumulateParams: null
+ payload: null
+ recipe: checkEimStatus
+ retry: 0
+ success: <generatedId>
+ target:
+ resourceID: resource-id
+ type: VM
+ timeout: 120
+- actor: AOTS
+ description: checkMaintenanceWindow Policy - triggered conditionally by checkEimStatus Policy - created by CLDS
+ failure: FINAL_FAILURE
+ failure_exception: FINAL_FAILURE_EXCEPTION
+ failure_guard: FINAL_FAILURE_GUARD
+ failure_retries: FINAL_FAILURE_RETRIES
+ failure_timeout: FINAL_FAILURE_TIMEOUT
+ id: <generatedId>
+ name: checkMaintenanceWindow Policy
+ operationsAccumulateParams: null
+ payload: null
+ recipe: checkMaintenanceWindow
+ retry: 0
+ success: <generatedId>
+ target:
+ resourceID: resource-id
+ type: VM
+ timeout: 120
+- actor: SDNR
+ description: Reset Policy - triggered conditionally by checkMaintenanceWindow Policy - created by CLDS
+ failure: FINAL_FAILURE
+ failure_exception: FINAL_FAILURE_EXCEPTION
+ failure_guard: FINAL_FAILURE_GUARD
+ failure_retries: FINAL_FAILURE_RETRIES
+ failure_timeout: FINAL_FAILURE_TIMEOUT
+ id: <generatedId>
+ name: Reset Policy
+ operationsAccumulateParams:
+ limit: 2
+ period: 10s
+ payload: null
+ recipe: Reset
+ retry: 3
+ success: <generatedId>
+ target:
+ resourceID: resource-id
+ type: VM
+ timeout: 180
diff --git a/src/test/resources/example/operational-policy/yaml-policy-chain-2.yaml b/src/test/resources/example/operational-policy/yaml-policy-chain-2.yaml
new file mode 100644
index 00000000..029cfbb7
--- /dev/null
+++ b/src/test/resources/example/operational-policy/yaml-policy-chain-2.yaml
@@ -0,0 +1,112 @@
+!!org.onap.policy.controlloop.policy.ControlLoopPolicy
+controlLoop:
+ abatement: false
+ controlLoopName: controlNameTest
+ resources:
+ - resourceInvariantUUID: null
+ resourceName: 6c7aaec2-59eb-41d9-8681-b7f976ab668d
+ resourceType: VF
+ resourceUUID: null
+ resourceVersion: null
+ services:
+ - serviceInvariantUUID: null
+ serviceName: 0f983e18-4603-4bb4-a98c-e29691fb16a1
+ serviceUUID: null
+ serviceVersion: null
+ timeout: 500
+ trigger_policy: <generatedId>
+ version: 2.0.0
+policies:
+- actor: AOTS
+ description: checkENodeBTicketHours Policy - the trigger (no parent) policy - created by CLDS
+ failure: FINAL_FAILURE
+ failure_exception: FINAL_FAILURE_EXCEPTION
+ failure_guard: FINAL_FAILURE_GUARD
+ failure_retries: FINAL_FAILURE_RETRIES
+ failure_timeout: FINAL_FAILURE_TIMEOUT
+ id: <generatedId>
+ name: checkENodeBTicketHours Policy
+ operationsAccumulateParams: null
+ payload:
+ timeWindow: '35'
+ recipe: checkENodeBTicketHours
+ retry: 0
+ success: <generatedId>
+ target:
+ resourceID: resource-id
+ type: VM
+ timeout: 120
+- actor: AOTS
+ description: checkEquipmentStatus Policy - triggered conditionally by checkENodeBTicketHours Policy - created by CLDS
+ failure: FINAL_FAILURE
+ failure_exception: FINAL_FAILURE_EXCEPTION
+ failure_guard: FINAL_FAILURE_GUARD
+ failure_retries: FINAL_FAILURE_RETRIES
+ failure_timeout: FINAL_FAILURE_TIMEOUT
+ id: <generatedId>
+ name: checkEquipmentStatus Policy
+ operationsAccumulateParams: null
+ payload: null
+ recipe: checkEquipmentStatus
+ retry: 0
+ success: <generatedId>
+ target:
+ resourceID: resource-id
+ type: VM
+ timeout: 120
+- actor: AOTS
+ description: checkEimStatus Policy - triggered conditionally by checkEquipmentStatus Policy - created by CLDS
+ failure: FINAL_FAILURE
+ failure_exception: FINAL_FAILURE_EXCEPTION
+ failure_guard: FINAL_FAILURE_GUARD
+ failure_retries: FINAL_FAILURE_RETRIES
+ failure_timeout: FINAL_FAILURE_TIMEOUT
+ id: <generatedId>
+ name: checkEimStatus Policy
+ operationsAccumulateParams: null
+ payload: null
+ recipe: checkEimStatus
+ retry: 0
+ success: <generatedId>
+ target:
+ resourceID: resource-id
+ type: VM
+ timeout: 120
+- actor: AOTS
+ description: checkMaintenanceWindow Policy - triggered conditionally by checkEimStatus Policy - created by CLDS
+ failure: FINAL_FAILURE
+ failure_exception: FINAL_FAILURE_EXCEPTION
+ failure_guard: FINAL_FAILURE_GUARD
+ failure_retries: FINAL_FAILURE_RETRIES
+ failure_timeout: FINAL_FAILURE_TIMEOUT
+ id: <generatedId>
+ name: checkMaintenanceWindow Policy
+ operationsAccumulateParams: null
+ payload: null
+ recipe: checkMaintenanceWindow
+ retry: 0
+ success: <generatedId>
+ target:
+ resourceID: resource-id
+ type: VM
+ timeout: 120
+- actor: SDNR
+ description: Reset Policy - triggered conditionally by checkMaintenanceWindow Policy - created by CLDS
+ failure: FINAL_FAILURE
+ failure_exception: FINAL_FAILURE_EXCEPTION
+ failure_guard: FINAL_FAILURE_GUARD
+ failure_retries: FINAL_FAILURE_RETRIES
+ failure_timeout: FINAL_FAILURE_TIMEOUT
+ id: <generatedId>
+ name: Reset Policy
+ operationsAccumulateParams:
+ limit: 2
+ period: 10s
+ payload: null
+ recipe: Reset
+ retry: 3
+ success: <generatedId>
+ target:
+ resourceID: resource-id
+ type: VM
+ timeout: 180