summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/clamp/loop/components/external/ExternalComponent.java6
-rw-r--r--src/main/java/org/onap/clamp/loop/components/external/ExternalComponentState.java60
-rw-r--r--src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java60
-rw-r--r--src/main/resources/clds/camel/routes/loop-flows.xml157
-rw-r--r--src/main/resources/clds/camel/routes/policy-flows.xml31
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopToJsonTest.java34
6 files changed, 208 insertions, 140 deletions
diff --git a/src/main/java/org/onap/clamp/loop/components/external/ExternalComponent.java b/src/main/java/org/onap/clamp/loop/components/external/ExternalComponent.java
index a8aae2038..2be707fe4 100644
--- a/src/main/java/org/onap/clamp/loop/components/external/ExternalComponent.java
+++ b/src/main/java/org/onap/clamp/loop/components/external/ExternalComponent.java
@@ -28,9 +28,7 @@ import com.google.gson.annotations.Expose;
import org.apache.camel.Exchange;
/**
- *
- * SHould be abstract but Gson can't instantiate it if it's an abstract
- *
+ * Should be abstract but Gson can't instantiate it if it's an abstract.
*/
public class ExternalComponent {
@Expose
@@ -49,7 +47,7 @@ public class ExternalComponent {
}
public ExternalComponentState computeState(Exchange camelExchange) {
- return new ExternalComponentState("INIT", "no desc");
+ return new ExternalComponentState("INIT", "no desc", 0);
}
public ExternalComponent(ExternalComponentState initialState) {
diff --git a/src/main/java/org/onap/clamp/loop/components/external/ExternalComponentState.java b/src/main/java/org/onap/clamp/loop/components/external/ExternalComponentState.java
index 6a723c24e..a220ee1d4 100644
--- a/src/main/java/org/onap/clamp/loop/components/external/ExternalComponentState.java
+++ b/src/main/java/org/onap/clamp/loop/components/external/ExternalComponentState.java
@@ -29,18 +29,26 @@ import com.google.gson.annotations.Expose;
* This is a transient state reflecting the deployment status of a component. It
* can be Policy, DCAE, or whatever... This is object is generic. Clamp is now
* stateless, so it triggers the different components at runtime, the status per
- * component is stored here.
+ * component is stored here. The state level is used to re-compute the global
+ * state when multiple sub states are required for that computation (generally
+ * provided sequentially to the method computeState from the camel routes.
*
*/
-public class ExternalComponentState {
+public class ExternalComponentState implements Comparable<ExternalComponentState> {
@Expose
private String stateName;
@Expose
private String description;
+ private int stateLevel;
- public ExternalComponentState(String stateName, String description) {
+ public ExternalComponentState(String stateName, String description, int level) {
this.stateName = stateName;
this.description = description;
+ this.stateLevel = level;
+ }
+
+ public ExternalComponentState(String stateName, String description) {
+ this(stateName, description, 0);
}
public ExternalComponentState() {
@@ -58,4 +66,50 @@ public class ExternalComponentState {
public String toString() {
return stateName;
}
+
+ public int getLevel() {
+ return stateLevel;
+ }
+
+ public void setLevel(int priority) {
+ this.stateLevel = priority;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((stateName == null) ? 0 : stateName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ExternalComponentState other = (ExternalComponentState) obj;
+ if (stateName == null) {
+ if (other.stateName != null)
+ return false;
+ } else if (!stateName.equals(other.stateName))
+ return false;
+ return true;
+ }
+
+ /**
+ * This method compares this object by using the level of them.
+ *
+ * @param stateToCompare The state to compare to the current object
+ * @return If the one given in input has a higher level than the current object
+ * it returns -1, 1 otherwise and 0 if equals.
+ */
+ @Override
+ public int compareTo(ExternalComponentState stateToCompare) {
+ return Integer.compare(this.getLevel(), stateToCompare.getLevel());
+ }
+
}
diff --git a/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java b/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java
index acd6115fe..68d598b5f 100644
--- a/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java
+++ b/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java
@@ -44,17 +44,22 @@ public class PolicyComponent extends ExternalComponent {
@Transient
private static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyComponent.class);
+ public static final ExternalComponentState IN_ERROR = new ExternalComponentState("IN_ERROR",
+ "There was an error during the sending to policy, the policy engine may be corrupted or inconsistent", 100);
public static final ExternalComponentState NOT_SENT = new ExternalComponentState("NOT_SENT",
- "The policies defined have NOT yet been created on the policy engine");
+ "The policies defined have NOT yet been created on the policy engine", 90);
public static final ExternalComponentState SENT = new ExternalComponentState("SENT",
- "The policies defined have been created but NOT deployed on the policy engine");
+ "The policies defined have been created but NOT deployed on the policy engine", 50);
public static final ExternalComponentState SENT_AND_DEPLOYED = new ExternalComponentState("SENT_AND_DEPLOYED",
- "The policies defined have been created and deployed on the policy engine");
- public static final ExternalComponentState IN_ERROR = new ExternalComponentState("IN_ERROR",
- "There was an error during the sending to policy, the policy engine may be corrupted or inconsistent");
+ "The policies defined have been created and deployed on the policy engine", 10);
public PolicyComponent() {
- super(NOT_SENT);
+ /*
+ * We assume it's good by default as we will receive the state for each policy
+ * on by one, each time we increase the level we can't decrease it anymore.
+ * That's why it starts with the lowest one SENT_AND_DEPLOYED.
+ */
+ super(SENT_AND_DEPLOYED);
}
@Override
@@ -103,21 +108,38 @@ public class PolicyComponent extends ExternalComponent {
return policyNamesList;
}
+ private static ExternalComponentState findNewState(boolean found, boolean deployed) {
+
+ ExternalComponentState newState = NOT_SENT;
+ if (found && deployed) {
+ newState = SENT_AND_DEPLOYED;
+ } else if (found) {
+ newState = SENT;
+ } else if (deployed) {
+ newState = IN_ERROR;
+ }
+ return newState;
+ }
+
+ private static ExternalComponentState mergeStates(ExternalComponentState oldState,
+ ExternalComponentState newState) {
+ return (oldState.compareTo(newState) < 0) ? newState : oldState;
+ }
+
+ /**
+ * This is a method that expect the results of the queries getPolicy and
+ * getPolicyDeployed for a unique policy (op,guard, config, etc ...). It
+ * re-computes the global policy state for each policy results given. Therefore
+ * this method is called multiple times from the camel route and must be reset
+ * for a new global policy state retrieval. The state to compute the global
+ * policy state is stored in this class.
+ *
+ */
@Override
public ExternalComponentState computeState(Exchange camelExchange) {
- boolean oneNotFound = (boolean) camelExchange.getIn().getExchange().getProperty("atLeastOnePolicyNotFound");
- boolean oneNotDeployed = (boolean) camelExchange.getIn().getExchange()
- .getProperty("atLeastOnePolicyNotDeployed");
-
- if (oneNotFound && oneNotDeployed) {
- this.setState(NOT_SENT);
- } else if (!oneNotFound && oneNotDeployed) {
- this.setState(SENT);
- } else if (!oneNotFound && !oneNotDeployed) {
- this.setState(SENT_AND_DEPLOYED);
- } else {
- this.setState(IN_ERROR);
- }
+ this.setState(mergeStates(this.getState(),
+ findNewState((boolean) camelExchange.getIn().getExchange().getProperty("policyFound"),
+ (boolean) camelExchange.getIn().getExchange().getProperty("policyDeployed"))));
return this.getState();
}
}
diff --git a/src/main/resources/clds/camel/routes/loop-flows.xml b/src/main/resources/clds/camel/routes/loop-flows.xml
index ede899e71..922d5f164 100644
--- a/src/main/resources/clds/camel/routes/loop-flows.xml
+++ b/src/main/resources/clds/camel/routes/loop-flows.xml
@@ -5,9 +5,7 @@
<simple>${header.loopName}</simple>
</setBody>
<setProperty propertyName="loopObject">
- <method
- ref="org.onap.clamp.loop.LoopService"
- method="getLoop" />
+ <method ref="org.onap.clamp.loop.LoopService" method="getLoop" />
</setProperty>
<when>
@@ -15,26 +13,24 @@
<setHeader headerName="CamelHttpResponseCode">
<constant>404</constant>
</setHeader>
- <log
- loggingLevel="WARNING"
- message="Loop not found in database: ${body}" />
+ <log loggingLevel="WARN" message="Loop not found in database: ${body}" />
<stop />
</when>
</route>
+
<route id="update-policy-status-for-loop">
<from uri="direct:update-policy-status-for-loop" />
- <setProperty propertyName="atLeastOnePolicyNotFound">
- <simple resultType="java.lang.Boolean">false</simple>
- </setProperty>
- <setProperty propertyName="atLeastOnePolicyNotDeployed">
- <simple resultType="java.lang.Boolean">false</simple>
- </setProperty>
<setProperty propertyName="policyComponent">
<simple>${exchangeProperty[loopObject].getComponent('POLICY')}
</simple>
</setProperty>
- <log
- loggingLevel="INFO"
+ <setProperty propertyName="policyFound">
+ <simple resultType="java.lang.Boolean">true</simple>
+ </setProperty>
+ <setProperty propertyName="policyDeployed">
+ <simple resultType="java.lang.Boolean">true</simple>
+ </setProperty>
+ <log loggingLevel="INFO"
message="Processing all MICRO-SERVICES policies defined in loop ${exchangeProperty[loopObject].getName()}" />
<split>
<simple>${exchangeProperty[loopObject].getMicroServicePolicies()}
@@ -48,29 +44,11 @@
<setBody>
<constant>null</constant>
</setBody>
- <log
- loggingLevel="INFO"
+ <log loggingLevel="INFO"
message="Processing Micro Service Policy: ${exchangeProperty[policyName]} of type ${exchangeProperty[policyType]}" />
- <setProperty propertyName="raiseHttpExceptionFlag">
- <simple resultType="java.lang.Boolean">false</simple>
- </setProperty>
- <to uri="direct:get-policy" />
- <when>
- <simple> ${header.CamelHttpResponseCode} != 200 </simple>
- <setProperty propertyName="atLeastOnePolicyNotFound">
- <simple resultType="java.lang.Boolean">true</simple>
- </setProperty>
- </when>
- <to uri="direct:get-deployment-policy" />
- <when>
- <simple> ${header.CamelHttpResponseCode} != 200 </simple>
- <setProperty propertyName="atLeastOnePolicyNotDeployed">
- <simple resultType="java.lang.Boolean">true</simple>
- </setProperty>
- </when>
+ <to uri="direct:verify-one-policy" />
</split>
- <log
- loggingLevel="INFO"
+ <log loggingLevel="INFO"
message="Processing all OPERATIONAL policies defined in loop ${exchangeProperty[loopObject].getName()}" />
<split>
<simple>${exchangeProperty[loopObject].getOperationalPolicies()}
@@ -87,29 +65,10 @@
<setBody>
<constant>null</constant>
</setBody>
- <log
- loggingLevel="INFO"
+ <log loggingLevel="INFO"
message="Processing Micro Service Policy: ${exchangeProperty[policyName]} of type ${exchangeProperty[policyType]}" />
- <setProperty propertyName="raiseHttpExceptionFlag">
- <simple resultType="java.lang.Boolean">false</simple>
- </setProperty>
- <to uri="direct:get-policy" />
- <when>
- <simple> ${header.CamelHttpResponseCode} != 200 </simple>
- <setProperty propertyName="atLeastOnePolicyNotFound">
- <simple resultType="java.lang.Boolean">true</simple>
- </setProperty>
- </when>
- <to uri="direct:get-deployment-policy" />
- <when>
- <simple> ${header.CamelHttpResponseCode} != 200 </simple>
- <setProperty propertyName="atLeastOnePolicyNotDeployed">
- <simple resultType="java.lang.Boolean">true</simple>
- </setProperty>
- </when>
-
- <log
- loggingLevel="INFO"
+ <to uri="direct:verify-one-policy" />
+ <log loggingLevel="INFO"
message="Processing all GUARD policies defined in loop ${exchangeProperty[loopObject].getName()}" />
<split>
<simple>${exchangeProperty[operationalPolicy].createGuardPolicyPayloads().entrySet()}
@@ -123,42 +82,23 @@
<setBody>
<constant>null</constant>
</setBody>
- <log
- loggingLevel="INFO"
+ <log loggingLevel="INFO"
message="Processing Guard Policy: ${exchangeProperty[policyName]} of type ${exchangeProperty[policyType]}" />
- <setProperty propertyName="raiseHttpExceptionFlag">
- <simple resultType="java.lang.Boolean">false</simple>
- </setProperty>
- <to uri="direct:get-policy" />
- <when>
- <simple> ${header.CamelHttpResponseCode} != 200 </simple>
- <setProperty propertyName="atLeastOnePolicyNotFound">
- <simple resultType="java.lang.Boolean">true</simple>
- </setProperty>
- </when>
- <to uri="direct:get-deployment-policy" />
- <when>
- <simple> ${header.CamelHttpResponseCode} != 200 </simple>
- <setProperty propertyName="atLeastOnePolicyNotDeployed">
- <simple resultType="java.lang.Boolean">true</simple>
- </setProperty>
- </when>
+ <to uri="direct:verify-one-policy" />
</split>
</split>
<setProperty propertyName="policyState">
- <simple> ${exchangeProperty[policyComponent].computeState(*)}
+ <simple> ${exchangeProperty[policyComponent].getState()}
</simple>
</setProperty>
- <log
- loggingLevel="INFO"
+ <log loggingLevel="INFO"
message="Policy state set to: ${exchangeProperty[policyState].getStateName()}" />
<to
uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('Policy state set to: ${exchangeProperty[policyState].getStateName()}','INFO','POLICY',${exchangeProperty[loopObject]})" />
</route>
<route id="update-dcae-status-for-loop">
<from uri="direct:update-dcae-status-for-loop" />
- <log
- loggingLevel="INFO"
+ <log loggingLevel="INFO"
message="Updating DCAE status for loop: ${exchangeProperty[loopObject].getName()}" />
<setProperty propertyName="dcaeComponent">
<simple>${exchangeProperty[loopObject].getComponent('DCAE')}</simple>
@@ -175,8 +115,7 @@
<simple> ${header.CamelHttpResponseCode} == 200 </simple>
<convertBodyTo type="java.lang.String" />
<setProperty propertyName="dcaeResponse">
- <method
- ref="org.onap.clamp.loop.components.external.DcaeComponent"
+ <method ref="org.onap.clamp.loop.components.external.DcaeComponent"
method="convertDcaeResponse(${body})" />
</setProperty>
</when>
@@ -186,8 +125,7 @@
<simple> ${exchangeProperty[dcaeComponent].computeState(*)}
</simple>
</setProperty>
- <log
- loggingLevel="INFO"
+ <log loggingLevel="INFO"
message="DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - DCAE message: ${exchangeProperty[dcaeResponse].getError()}" />
<to
uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - message: ${exchangeProperty[dcaeResponse].getError()}','INFO','DCAE',${exchangeProperty[loopObject]})" />
@@ -195,53 +133,78 @@
</route>
<route id="direct:update-loop-state">
<from uri="direct:update-loop-state" />
- <log
- loggingLevel="INFO"
+ <log loggingLevel="INFO"
message="Updating status for loop: ${exchangeProperty[loopObject].getName()}" />
<choice>
<when>
- <simple>${exchangeProperty['dcaeState'].getStateName()} == 'BLUEPRINT_DEPLOYED' and ${exchangeProperty['policyState'].getStateName()} == 'NOT_SENT'</simple>
+ <simple>${exchangeProperty['dcaeState'].getStateName()} ==
+ 'BLUEPRINT_DEPLOYED' and ${exchangeProperty['policyState'].getStateName()}
+ == 'NOT_SENT'
+ </simple>
<to
uri="bean:org.onap.clamp.loop.LoopService?method=updateLoopState(${exchangeProperty[loopObject]},'DESIGN')" />
</when>
<when>
- <simple>${exchangeProperty['dcaeState'].getStateName()} == 'IN_ERROR' or ${exchangeProperty['dcaeState'].getStateName()} == 'MICROSERVICE_INSTALLATION_FAILED'</simple>
+ <simple>${exchangeProperty['dcaeState'].getStateName()} == 'IN_ERROR' or
+ ${exchangeProperty['dcaeState'].getStateName()} ==
+ 'MICROSERVICE_INSTALLATION_FAILED'
+ </simple>
<to
uri="bean:org.onap.clamp.loop.LoopService?method=updateLoopState(${exchangeProperty[loopObject]},'IN_ERROR')" />
</when>
<when>
- <simple>${exchangeProperty['dcaeState'].getStateName()} == 'MICROSERVICE_UNINSTALLATION_FAILED' or ${exchangeProperty['policyState'].getStateName()} == 'IN_ERROR'</simple>
+ <simple>${exchangeProperty['dcaeState'].getStateName()} ==
+ 'MICROSERVICE_UNINSTALLATION_FAILED' or
+ ${exchangeProperty['policyState'].getStateName()} == 'IN_ERROR'
+ </simple>
<to
uri="bean:org.onap.clamp.loop.LoopService?method=updateLoopState(${exchangeProperty[loopObject]},'IN_ERROR')" />
</when>
<when>
- <simple>${exchangeProperty['dcaeState'].getStateName()} == 'MICROSERVICE_INSTALLED_SUCCESSFULLY' and ${exchangeProperty['policyState'].getStateName()} == 'SENT_AND_DEPLOYED'</simple>
+ <simple>${exchangeProperty['dcaeState'].getStateName()} ==
+ 'MICROSERVICE_INSTALLED_SUCCESSFULLY' and
+ ${exchangeProperty['policyState'].getStateName()} == 'SENT_AND_DEPLOYED'
+ </simple>
<to
uri="bean:org.onap.clamp.loop.LoopService?method=updateLoopState(${exchangeProperty[loopObject]},'RUNNING')" />
</when>
<when>
- <simple>${exchangeProperty['dcaeState'].getStateName()} == 'MICROSERVICE_INSTALLED_SUCCESSFULLY' and ${exchangeProperty['policyState'].getStateName()} == 'SENT'</simple>
+ <simple>${exchangeProperty['dcaeState'].getStateName()} ==
+ 'MICROSERVICE_INSTALLED_SUCCESSFULLY' and
+ ${exchangeProperty['policyState'].getStateName()} == 'SENT'
+ </simple>
<to
uri="bean:org.onap.clamp.loop.LoopService?method=updateLoopState(${exchangeProperty[loopObject]},'STOPPED')" />
</when>
<when>
- <simple>${exchangeProperty['dcaeState'].getStateName()} == 'BLUEPRINT_DEPLOYED' or ${exchangeProperty['dcaeState'].getStateName()} == 'MICROSERVICE_UNINSTALLED_SUCCESSFULLY' and ${exchangeProperty['policyState'].getStateName()} == 'SENT_AND_DEPLOYED'</simple>
+ <simple>${exchangeProperty['dcaeState'].getStateName()} ==
+ 'BLUEPRINT_DEPLOYED' or ${exchangeProperty['dcaeState'].getStateName()} ==
+ 'MICROSERVICE_UNINSTALLED_SUCCESSFULLY' and
+ ${exchangeProperty['policyState'].getStateName()} == 'SENT_AND_DEPLOYED'
+ </simple>
<to
uri="bean:org.onap.clamp.loop.LoopService?method=updateLoopState(${exchangeProperty[loopObject]},'SUBMITTED')" />
</when>
<when>
- <simple>${exchangeProperty['dcaeState'].getStateName()} == 'PROCESSING_MICROSERVICE_INSTALLATION' or ${exchangeProperty['dcaeState'].getStateName()} == 'PROCESSING_MICROSERVICE_UNINSTALLATION' and ${exchangeProperty['policyState'].getStateName()} == 'SENT_AND_DEPLOYED'</simple>
+ <simple>${exchangeProperty['dcaeState'].getStateName()} ==
+ 'PROCESSING_MICROSERVICE_INSTALLATION' or
+ ${exchangeProperty['dcaeState'].getStateName()} ==
+ 'PROCESSING_MICROSERVICE_UNINSTALLATION' and
+ ${exchangeProperty['policyState'].getStateName()} == 'SENT_AND_DEPLOYED'
+ </simple>
<to
uri="bean:org.onap.clamp.loop.LoopService?method=updateLoopState(${exchangeProperty[loopObject]},'WAITING')" />
</when>
<when>
- <simple>${exchangeProperty['dcaeState'].getStateName()} == 'MICROSERVICE_INSTALLED_SUCCESSFULLY' and ${exchangeProperty['policyState'].getStateName()} != 'NOT_SENT'</simple>
+ <simple>${exchangeProperty['dcaeState'].getStateName()} ==
+ 'MICROSERVICE_INSTALLED_SUCCESSFULLY' and
+ ${exchangeProperty['policyState'].getStateName()} != 'NOT_SENT'
+ </simple>
<to
uri="bean:org.onap.clamp.loop.LoopService?method=updateLoopState(${exchangeProperty[loopObject]},'DEPLOYED')" />
</when>
</choice>
- <log
- loggingLevel="INFO"
+ <log loggingLevel="INFO"
message="New loop state is: ${exchangeProperty[loopObject].getLastComputedState().toString()}" />
<to
uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('New loop state is: ${exchangeProperty[loopObject].getLastComputedState().toString()}','INFO',${exchangeProperty[loopObject]})" />
diff --git a/src/main/resources/clds/camel/routes/policy-flows.xml b/src/main/resources/clds/camel/routes/policy-flows.xml
index 5d5861547..b6f30c37c 100644
--- a/src/main/resources/clds/camel/routes/policy-flows.xml
+++ b/src/main/resources/clds/camel/routes/policy-flows.xml
@@ -1,5 +1,36 @@
<routes xmlns="http://camel.apache.org/schema/spring">
+ <route id="verify-one-policy">
+ <from uri="direct:verify-one-policy" />
+ <setProperty propertyName="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <to uri="direct:get-policy" />
+ <when>
+ <simple> ${header.CamelHttpResponseCode} != 200 </simple>
+ <setProperty propertyName="policyFound">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <log loggingLevel="WARN"
+ message="At least one policy has not been found on policy engine: ${exchangeProperty[policyName]}" />
+ </when>
+ <setProperty propertyName="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <to uri="direct:get-deployment-policy" />
+ <when>
+ <simple> ${header.CamelHttpResponseCode} != 200 </simple>
+ <setProperty propertyName="policyDeployed">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <log loggingLevel="WARN"
+ message="At least one policy has not been deployed on policy engine: ${exchangeProperty[policyName]}" />
+ </when>
+ <setProperty propertyName="newPolicyState">
+ <simple>${exchangeProperty[policyComponent].computeState(*)}</simple>
+ </setProperty>
+ </route>
+
<route id="get-policy">
<from uri="direct:get-policy" />
<doTry>
diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
index c9350c610..3010fe50b 100644
--- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
+++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
@@ -54,7 +54,7 @@ public class LoopToJsonTest {
}
private Loop getLoop(String name, String svgRepresentation, String blueprint, String globalPropertiesJson,
- String dcaeId, String dcaeUrl, String dcaeBlueprintId) {
+ String dcaeId, String dcaeUrl, String dcaeBlueprintId) {
Loop loop = new Loop(name, blueprint, svgRepresentation);
loop.setGlobalPropertiesJson(new Gson().fromJson(globalPropertiesJson, JsonObject.class));
loop.setLastComputedState(LoopState.DESIGN);
@@ -65,9 +65,9 @@ public class LoopToJsonTest {
}
private MicroServicePolicy getMicroServicePolicy(String name, String modelType, String jsonRepresentation,
- String policyTosca, String jsonProperties, boolean shared) {
+ String policyTosca, String jsonProperties, boolean shared) {
MicroServicePolicy microService = new MicroServicePolicy(name, modelType, policyTosca, shared,
- gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>());
+ gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>());
microService.setProperties(new Gson().fromJson(jsonProperties, JsonObject.class));
return microService;
@@ -82,13 +82,13 @@ public class LoopToJsonTest {
@Test
public void loopGsonTest() throws IOException {
Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
- "123456789", "https://dcaetest.org", "UUID-blueprint");
+ "123456789", "https://dcaetest.org", "UUID-blueprint");
OperationalPolicy opPolicy = this.getOperationalPolicy(
- ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest");
+ ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest");
loopTest.addOperationalPolicy(opPolicy);
MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "",
- "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
- "{\"param1\":\"value1\"}", true);
+ "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+ "{\"param1\":\"value1\"}", true);
loopTest.addMicroServicePolicy(microServicePolicy);
LoopLog loopLog = getLoopLog(LogType.INFO, "test message", loopTest);
loopTest.addLog(loopLog);
@@ -99,11 +99,11 @@ public class LoopToJsonTest {
Loop loopTestDeserialized = JsonUtils.GSON_JPA_MODEL.fromJson(jsonSerialized, Loop.class);
assertNotNull(loopTestDeserialized);
assertThat(loopTestDeserialized).isEqualToIgnoringGivenFields(loopTest, "svgRepresentation", "blueprint",
- "components");
+ "components");
assertThat(loopTestDeserialized.getComponent("DCAE").getState())
- .isEqualToComparingFieldByField(loopTest.getComponent("DCAE").getState());
- assertThat(loopTestDeserialized.getComponent("POLICY").getState())
- .isEqualToComparingFieldByField(loopTest.getComponent("POLICY").getState());
+ .isEqualToComparingFieldByField(loopTest.getComponent("DCAE").getState());
+ assertThat(loopTestDeserialized.getComponent("POLICY").getState()).isEqualToComparingOnlyGivenFields(
+ loopTest.getComponent("POLICY").getState(), "stateName", "description");
// svg and blueprint not exposed so wont be deserialized
assertThat(loopTestDeserialized.getBlueprint()).isEqualTo(null);
assertThat(loopTestDeserialized.getSvgRepresentation()).isEqualTo(null);
@@ -112,22 +112,22 @@ public class LoopToJsonTest {
assertThat(loopTestDeserialized.getMicroServicePolicies()).containsExactly(microServicePolicy);
assertThat(loopTestDeserialized.getLoopLogs()).containsExactly(loopLog);
assertThat((LoopLog) loopTestDeserialized.getLoopLogs().toArray()[0]).isEqualToIgnoringGivenFields(loopLog,
- "loop");
+ "loop");
}
@Test
public void createPoliciesPayloadPdpGroupTest() throws IOException {
Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
- "123456789", "https://dcaetest.org", "UUID-blueprint");
+ "123456789", "https://dcaetest.org", "UUID-blueprint");
OperationalPolicy opPolicy = this.getOperationalPolicy(
- ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest");
+ ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest");
loopTest.addOperationalPolicy(opPolicy);
MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "",
- "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
- "{\"param1\":\"value1\"}", true);
+ "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+ "{\"param1\":\"value1\"}", true);
loopTest.addMicroServicePolicy(microServicePolicy);
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/pdp-group-policy-payload.json"),
- PolicyComponent.createPoliciesPayloadPdpGroup(loopTest), false);
+ PolicyComponent.createPoliciesPayloadPdpGroup(loopTest), false);
}
}