aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-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
5 files changed, 191 insertions, 123 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>