1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*-
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
* Copyright (C) 2019 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============================================
* ===================================================================
*
*/
package org.onap.policy.clamp.loop.components.external;
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. 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 implements Comparable<ExternalComponentState> {
@Expose
private String stateName;
@Expose
private String description;
private int stateLevel;
/**
* Constructor taking stateName, description and its level.
*
* @param stateName The stateName in string
* @param description The description in string
* @param level The level, higher value has higher priority and can't be
* down-graded
*/
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() {
}
public String getStateName() {
return stateName;
}
public String getDescription() {
return description;
}
@Override
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());
}
}
|