summaryrefslogtreecommitdiffstats
path: root/common/onap-tosca-datatype
diff options
context:
space:
mode:
authorshiria <shiri.amichai@amdocs.com>2018-10-10 15:16:15 +0300
committerOren Kleks <orenkle@amdocs.com>2018-10-15 09:43:40 +0000
commit1f50c72eb501af42c61c4ddbb011302a6290afdb (patch)
treebea97a3203f3560ab5bbd2a38fcb7316ec3e259d /common/onap-tosca-datatype
parentb54343dc3868300178017e60e4cd2c26dc08ff24 (diff)
Fix Policy type and Policy definition
Fix policy according to TOSCA spec Change-Id: I4e3da732666dd52895c4458f0cbd16c6ca47c1cd Issue-ID: SDC-1782 Signed-off-by: shiria <shiri.amichai@amdocs.com>
Diffstat (limited to 'common/onap-tosca-datatype')
-rw-r--r--common/onap-tosca-datatype/pom.xml4
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Condition.java30
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyDefinition.java55
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyType.java77
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Trigger.java189
-rw-r--r--common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/TriggerTest.java93
-rw-r--r--common/onap-tosca-datatype/src/test/resources/mock/trigger/operationAction.yaml34
-rw-r--r--common/onap-tosca-datatype/src/test/resources/mock/trigger/wfNameAction.yaml27
8 files changed, 306 insertions, 203 deletions
diff --git a/common/onap-tosca-datatype/pom.xml b/common/onap-tosca-datatype/pom.xml
index 421aaf03af..e00394f64f 100644
--- a/common/onap-tosca-datatype/pom.xml
+++ b/common/onap-tosca-datatype/pom.xml
@@ -46,5 +46,9 @@
<version>${guava.version}</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Condition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Condition.java
new file mode 100644
index 0000000000..a394401112
--- /dev/null
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Condition.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.onap.sdc.tosca.datatypes.model;
+
+import java.util.Map;
+import lombok.Data;
+
+@Data
+public class Condition {
+
+ private Map<String,Constraint> constraint;
+ private String period;
+ private Integer evaluations;
+ private String method;
+
+}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyDefinition.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyDefinition.java
index e1c2fb468c..a9a45c4a3f 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyDefinition.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyDefinition.java
@@ -7,9 +7,9 @@
* 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.
@@ -22,51 +22,16 @@ package org.onap.sdc.tosca.datatypes.model;
import java.util.List;
import java.util.Map;
+import lombok.Data;
+@Data
public class PolicyDefinition implements Template {
- private String type;
- private String description;
- private Map<String, String> metadata;
- private Map<String, Object> properties;
- private List<String> targets;
- public String getType() {
- return type;
- }
+ private String type;
+ private String description;
+ private Map<String, String> metadata;
+ private Map<String, Object> properties;
+ private List<String> targets;
+ private Map<String, Trigger> triggers;
- public void setType(String type) {
- this.type = type;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public Map<String, String> getMetadata() {
- return metadata;
- }
-
- public void setMetadata(Map<String, String> metadata) {
- this.metadata = metadata;
- }
-
- public Map<String, Object> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String, Object> properties) {
- this.properties = properties;
- }
-
- public List<String> getTargets() {
- return targets;
- }
-
- public void setTargets(List<String> targets) {
- this.targets = targets;
- }
}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyType.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyType.java
index 54d52cceec..cd7da8614c 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyType.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/PolicyType.java
@@ -7,9 +7,9 @@
* 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.
@@ -22,73 +22,18 @@ package org.onap.sdc.tosca.datatypes.model;
import java.util.List;
import java.util.Map;
+import lombok.Data;
-
+@Data
public class PolicyType {
- private String derived_from;
- private String version;
- private Map<String, String> metadata;
- private String description;
- private Map<String, PropertyDefinition> properties;
- private List<String> targets;
- private List<Trigger> triggers;
-
- public String getDerived_from() {
- return derived_from;
- }
-
- public void setDerived_from(String derived_from) {
- this.derived_from = derived_from;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public Map<String, PropertyDefinition> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String, PropertyDefinition> properties) {
- this.properties = properties;
- }
-
- public List<String> getTargets() {
- return targets;
- }
-
- public void setTargets(List<String> targets) {
- this.targets = targets;
- }
-
- public Map<String, String> getMetadata() {
- return metadata;
- }
-
- public void setMetadata(Map<String, String> metadata) {
- this.metadata = metadata;
- }
-
- public List<Trigger> getTriggers() {
- return triggers;
- }
+ private String derived_from;
+ private String version;
+ private Map<String, String> metadata;
+ private String description;
+ private Map<String, PropertyDefinition> properties;
+ private List<String> targets;
+ private Map<String, Trigger> triggers;
- public void setTriggers(
- List<Trigger> triggers) {
- this.triggers = triggers;
- }
}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Trigger.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Trigger.java
index 92f3b30183..f5a2f66e9d 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Trigger.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/Trigger.java
@@ -2,96 +2,101 @@ package org.onap.sdc.tosca.datatypes.model;
public class Trigger {
- private String description;
- private String event_type;
- private TimeInterval schedule;
- private EventFilter target_filter;
- private Constraint condition;
- private Constraint constraint;
- private String period;
- private int evaluations;
- private String method;
- //action - String or operation?
- private Object action;
-
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getEvent_type() {
- return event_type;
- }
-
- public void setEvent_type(String event_type) {
- this.event_type = event_type;
- }
-
- public TimeInterval getSchedule() {
- return schedule;
- }
-
- public void setSchedule(TimeInterval schedule) {
- this.schedule = schedule;
- }
-
- public EventFilter getTarget_filter() {
- return target_filter;
- }
-
- public void setTarget_filter(EventFilter target_filter) {
- this.target_filter = target_filter;
- }
-
- public Constraint getCondition() {
- return condition;
- }
-
- public void setCondition(Constraint condition) {
- this.condition = condition;
- }
-
- public Constraint getConstraint() {
- return constraint;
- }
-
- public void setConstraint(Constraint constraint) {
- this.constraint = constraint;
- }
-
- public String getPeriod() {
- return period;
- }
-
- public void setPeriod(String period) {
- this.period = period;
- }
-
- public int getEvaluations() {
- return evaluations;
- }
-
- public void setEvaluations(int evaluations) {
- this.evaluations = evaluations;
- }
-
- public String getMethod() {
- return method;
- }
-
- public void setMethod(String method) {
- this.method = method;
- }
-
- public Object getAction() {
- return action;
- }
-
- public void setAction(Object action) {
- this.action = action;
- }
+ private String description;
+ private String event_type;
+ private TimeInterval schedule;
+ private EventFilter target_filter;
+ private Condition condition;
+ private Object action;
+
+ @Override
+ public int hashCode() {
+ int result = getDescription() != null ? getDescription().hashCode() : 0;
+ result = 31 * result + getEvent_type().hashCode();
+ result = 31 * result + (getSchedule() != null ? getSchedule().hashCode() : 0);
+ result = 31 * result + (getTarget_filter() != null ? getTarget_filter().hashCode() : 0);
+ result = 31 * result + (getCondition() != null ? getCondition().hashCode() : 0);
+ result = 31 * result + getAction().hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Trigger)) {
+ return false;
+ }
+
+ Trigger trigger = (Trigger) o;
+
+ if (getDescription() != null ? !getDescription().equals(trigger.getDescription()) :
+ trigger.getDescription() != null) {
+ return false;
+ }
+ if (!getEvent_type().equals(trigger.getEvent_type())) {
+ return false;
+ }
+ if (getSchedule() != null ? !getSchedule().equals(trigger.getSchedule()) : trigger.getSchedule() != null) {
+ return false;
+ }
+ if (getTarget_filter() != null ? !getTarget_filter().equals(trigger.getTarget_filter()) :
+ trigger.getTarget_filter() != null) {
+ return false;
+ }
+ if (getCondition() != null ? !getCondition().equals(trigger.getCondition()) : trigger.getCondition() != null) {
+ return false;
+ }
+ return getAction().equals(trigger.getAction());
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getEvent_type() {
+ return event_type;
+ }
+
+ public void setEvent_type(String eventType) {
+ this.event_type = eventType;
+ }
+
+ public TimeInterval getSchedule() {
+ return schedule;
+ }
+
+ public void setSchedule(TimeInterval schedule) {
+ this.schedule = schedule;
+ }
+
+ public EventFilter getTarget_filter() {
+ return target_filter;
+ }
+
+ public void setTarget_filter(EventFilter targetFilter) {
+ this.target_filter = targetFilter;
+ }
+
+ public Condition getCondition() {
+ return condition;
+ }
+
+ public void setCondition(Condition condition) {
+ this.condition = condition;
+ }
+
+ public Object getAction() {
+
+ return action;
+ }
+
+ public void setAction(Object action) {
+ this.action = action;
+ }
}
diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/TriggerTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/TriggerTest.java
new file mode 100644
index 0000000000..60886b9b42
--- /dev/null
+++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/TriggerTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.onap.sdc.tosca.datatypes.model;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
+
+
+public class TriggerTest {
+
+ public static final String TRIGGER_WF_NAME_ACTION = "/mock/trigger/wfNameAction.yaml";
+ public static final String TARGET_REQ = "reqA";
+ public static final String ACTION_WORKFLOW_VAL = "deployment_workflow";
+ public static final String POLICY_DEF_A = "policyA";
+ public static final String TRIGGER_A = "triggerA";
+ public static final String NODE_A = "nodeA";
+ public static final String TRIGGER_OPERATION_ACTION = "/mock/trigger/operationAction.yaml";
+ public static final String TARGET_CAP = "capA";
+ public static final String OPERATION_ACTION_KEY = "operationAction";
+ public static final String IMPLEMENTATION = "implementation";
+ ToscaExtensionYamlUtil toscaExtYamlUtil = new ToscaExtensionYamlUtil();
+
+ @Test
+ public void getPolicyTriggerActionWf() throws IOException {
+ String inputFile = TRIGGER_WF_NAME_ACTION;
+ ServiceTemplate serviceTemplate = getServiceTemplate(inputFile);
+
+ Map<String, PolicyDefinition> policies = serviceTemplate.getTopology_template().getPolicies();
+ Trigger trigger = policyCheck(policies);
+ Assert.assertEquals(TARGET_REQ, trigger.getTarget_filter().getRequirement());
+ Object action = trigger.getAction();
+ Assert.assertNotNull(action);
+ Assert.assertEquals(true, action instanceof String);
+ Assert.assertEquals(ACTION_WORKFLOW_VAL, action);
+ }
+
+ private ServiceTemplate getServiceTemplate(String inputPath) throws IOException {
+ try (InputStream yamlFile = toscaExtYamlUtil.loadYamlFileIs(inputPath)) {
+ return toscaExtYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
+ }
+ }
+
+ private Trigger policyCheck(Map<String, PolicyDefinition> policies) {
+ Assert.assertNotNull(policies);
+ PolicyDefinition policyDefinition = policies.get(POLICY_DEF_A);
+ Assert.assertNotNull(policyDefinition);
+ Map<String, Trigger> triggers = policyDefinition.getTriggers();
+ Assert.assertNotNull(triggers);
+ Trigger trigger = triggers.get(TRIGGER_A);
+ Assert.assertNotNull(trigger);
+ EventFilter targetFilter = trigger.getTarget_filter();
+ Assert.assertNotNull(targetFilter);
+ Assert.assertEquals(NODE_A, targetFilter.getNode());
+ return trigger;
+ }
+
+ @Test
+ public void getPolicyTriggerActionOperation() throws IOException {
+ String inputFile = TRIGGER_OPERATION_ACTION;
+ ServiceTemplate serviceTemplate = getServiceTemplate(inputFile);
+
+ Map<String, PolicyDefinition> policies = serviceTemplate.getTopology_template().getPolicies();
+ Trigger trigger = policyCheck(policies);
+ Assert.assertEquals(TARGET_CAP, trigger.getTarget_filter().getCapability());
+ Object action = trigger.getAction();
+ Assert.assertNotNull(action);
+ Assert.assertEquals(true, action instanceof Map);
+ Object operationAction = ((Map) action).get(OPERATION_ACTION_KEY);
+ Assert.assertNotNull(operationAction);
+ Assert.assertEquals(true, operationAction instanceof Map);
+ Assert.assertNotNull( ((Map)operationAction).get(IMPLEMENTATION));
+
+ }
+
+} \ No newline at end of file
diff --git a/common/onap-tosca-datatype/src/test/resources/mock/trigger/operationAction.yaml b/common/onap-tosca-datatype/src/test/resources/mock/trigger/operationAction.yaml
new file mode 100644
index 0000000000..64e2b7ab5d
--- /dev/null
+++ b/common/onap-tosca-datatype/src/test/resources/mock/trigger/operationAction.yaml
@@ -0,0 +1,34 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+
+topology_template:
+ description: topology template descroption
+
+ policies:
+ policyA:
+ type: tosca.policies.threshold
+ description: my description
+ targets: [ nodeA ]
+ triggers:
+ triggerA:
+ description: triggering event based on CPU
+ event_type: eventTypeA
+ schedule:
+ start_time: 2016-04-08T21:59:43.10-06:00
+ end_time: 2002-12-14
+ target_filter:
+ node: nodeA
+ capability: capA
+ condition:
+ constraint:
+ attName: { greater_than: 80 }
+ period: 1200 s
+ evaluations: 6
+ method: avg
+ action:
+ operationAction:
+ description: my operation
+ implementation:
+ primary: a/s/d.xml
+ inputs:
+ inputA: 3
+ inputB: {get_property: [ nodeA, propertyA ]} \ No newline at end of file
diff --git a/common/onap-tosca-datatype/src/test/resources/mock/trigger/wfNameAction.yaml b/common/onap-tosca-datatype/src/test/resources/mock/trigger/wfNameAction.yaml
new file mode 100644
index 0000000000..2c2ceb9511
--- /dev/null
+++ b/common/onap-tosca-datatype/src/test/resources/mock/trigger/wfNameAction.yaml
@@ -0,0 +1,27 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+
+topology_template:
+ description: topology template descroption
+
+ policies:
+ policyA:
+ type: tosca.policies.threshold
+ description: my description
+ targets: [ nodeA ]
+ triggers:
+ triggerA:
+ description: triggering event based on CPU
+ event_type: eventTypeA
+ schedule:
+ start_time: 2016-04-08T21:59:43.10-06:00
+ end_time: 2002-12-14
+ target_filter:
+ node: nodeA
+ requirement: reqA
+ condition:
+ constraint:
+ attName: { greater_than: 80 }
+ period: 1200 s
+ evaluations: 6
+ method: avg
+ action: deployment_workflow \ No newline at end of file