Commit includes ControlLoopPolicy API and bugfixes
[policy/engine.git] / ECOMP-ControlloopPolicy / src / main / java / org / openecomp / policy / controlloop / policy / ControlLoop.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.policy.controlloop.policy;
22
23 import java.util.LinkedList;
24 import java.util.List;
25
26 import org.openecomp.policy.asdc.Resource;
27 import org.openecomp.policy.asdc.Service;
28
29 public class ControlLoop {
30         
31         private static String VERSION = "2.0.0";
32
33         private String controlLoopName;
34         private String version = VERSION;
35         private List<Service> services;
36         private List<Resource> resources;
37         private String trigger_policy = FinalResult.FINAL_OPENLOOP.toString();
38         private Integer timeout;
39         private Boolean abatement = false;
40         
41         public ControlLoop() {
42                 // Empty Constructor.
43         }
44         
45         public static String getVERSION(){
46                 return ControlLoop.VERSION;
47         }
48         
49         public String getControlLoopName() {
50                 return controlLoopName;
51         }
52
53         public void setControlLoopName(String controlLoopName) {
54                 this.controlLoopName = controlLoopName;
55         }
56
57         public List<Service> getServices() {
58                 return services;
59         }
60
61         public void setServices(List<Service> services) {
62                 this.services = services;
63         }
64
65         public List<Resource> getResources() {
66                 return resources;
67         }
68
69         public void setResources(List<Resource> resources) {
70                 this.resources = resources;
71         }
72
73         public String getTrigger_policy() {
74                 return trigger_policy;
75         }
76
77         public void setTrigger_policy(String trigger_policy) {
78                 this.trigger_policy = trigger_policy;
79         }
80
81         public Integer getTimeout() {
82                 return timeout;
83         }
84
85         public void setTimeout(Integer timeout) {
86                 this.timeout = timeout;
87         }
88
89         public Boolean getAbatement() {
90                 return abatement;
91         }
92
93         public void setAbatement(Boolean abatement) {
94                 this.abatement = abatement;
95         }
96
97         public String getVersion() {
98                 return version;
99         }
100         
101         public void setVersion(String version){
102                 this.version = version;
103         }
104
105         public ControlLoop(ControlLoop controlLoop) {
106                 this.controlLoopName = controlLoop.controlLoopName;
107                 this.services = new LinkedList<>();
108                 if (controlLoop.services != null) {
109                         for (Service service : controlLoop.services) {
110                                 this.services.add(service);
111                         }
112                 }
113                 this.resources = new LinkedList<>();
114                 if (controlLoop.resources != null) {
115                         for (Resource resource: controlLoop.resources) {
116                                 this.resources.add(resource);
117                         }
118                 }
119                 this.trigger_policy = controlLoop.trigger_policy;
120                 this.timeout = controlLoop.timeout;
121                 this.abatement = controlLoop.abatement;
122         }
123         @Override
124         public String toString() {
125                 return "ControlLoop [controlLoopName=" + controlLoopName + ", version=" + version + ", services=" + services
126                                 + ", resources=" + resources + ", trigger_policy=" + trigger_policy + ", timeout="
127                                 + timeout + ", abatement=" + abatement + "]";
128         }
129         @Override
130         public int hashCode() {
131                 final int prime = 31;
132                 int result = 1;
133                 result = prime * result + ((controlLoopName == null) ? 0 : controlLoopName.hashCode());
134                 result = prime * result + ((resources == null) ? 0 : resources.hashCode());
135                 result = prime * result + ((services == null) ? 0 : services.hashCode());
136                 result = prime * result + ((timeout == null) ? 0 : timeout.hashCode());
137                 result = prime * result + ((trigger_policy == null) ? 0 : trigger_policy.hashCode());
138                 result = prime * result + ((version == null) ? 0 : version.hashCode());
139                 result = prime * result + ((abatement == null) ? 0 : abatement.hashCode());
140                 return result;
141         }
142         @Override
143         public boolean equals(Object obj) {
144                 if (this == obj)
145                         return true;
146                 if (obj == null)
147                         return false;
148                 if (getClass() != obj.getClass())
149                         return false;
150                 ControlLoop other = (ControlLoop) obj;
151                 if (controlLoopName == null) {
152                         if (other.controlLoopName != null)
153                                 return false;
154                 } else if (!controlLoopName.equals(other.controlLoopName))
155                         return false;
156                 if (resources == null) {
157                         if (other.resources != null)
158                                 return false;
159                 } else if (!resources.equals(other.resources))
160                         return false;
161                 if (services == null) {
162                         if (other.services != null)
163                                 return false;
164                 } else if (!services.equals(other.services))
165                         return false;
166                 if (timeout == null) {
167                         if (other.timeout != null)
168                                 return false;
169                 } else if (!timeout.equals(other.timeout))
170                         return false;
171                 if (trigger_policy == null) {
172                         if (other.trigger_policy != null)
173                                 return false;
174                 } else if (!trigger_policy.equals(other.trigger_policy))
175                         return false;
176                 if (version == null) {
177                         if (other.version != null)
178                                 return false;
179                 } else if (!version.equals(other.version))
180                         return false;
181                 if (abatement == null) {
182                         if (other.abatement != null)
183                                 return false;
184                 } else if (!abatement.equals(other.abatement))
185                         return false;
186                 return true;
187         }
188         
189 }