summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2019-08-23 07:45:27 -0700
committersebdet <sebastien.determe@intl.att.com>2019-08-23 08:35:15 -0700
commit3142c70fb7530c444c891674fe55c6a9b236dfb3 (patch)
tree807ba054b1fea1af52cdc3bc45b4baa2ea9134a7 /src/main/java/org
parent5e2b077e496ca28e9f91fc12cecb872228c81816 (diff)
Fix the log status
Fix the way the code (camel) computes the global loop state + introduce level in component state for that Issue-ID: CLAMP-384 Change-Id: I83a9306eabacfc1f118df6b828e521ee59d19b5f Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main/java/org')
-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
3 files changed, 100 insertions, 26 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();
}
}