Add Expose annotation
[clamp.git] / src / main / java / org / onap / clamp / clds / model / DcaeEvent.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.model;
25
26 import java.util.List;
27
28 import javax.ws.rs.BadRequestException;
29
30 import com.google.gson.annotations.Expose;
31
32 /**
33  * Represent a DCAE Event.
34  */
35 public class DcaeEvent {
36         // this is an event we (clds) sends to dcae
37         public static final String EVENT_CREATED = "created";
38         public static final String EVENT_DISTRIBUTION = "distribute";
39         public static final String EVENT_DEPLOYMENT = "deployment";
40         public static final String EVENT_UNDEPLOYMENT = "undeployment";
41         public static final String ARTIFACT_NAME_SUFFIX = ".yml";
42
43         @Expose
44         private String event;
45         @Expose
46         private String serviceUuid;
47         @Expose
48         private String resourceUuid;
49         @Expose
50         private String artifactName; // controlName.yml
51         @Expose
52         private List<CldsModelInstance> instances;
53
54         /**
55          * Transform a DCAE Event Action to a CldsEvent.actionCd.
56          *
57          * @return The clds action.
58          */
59         public String getCldsActionCd() {
60                 if (event == null || event.length() == 0) {
61                         throw new BadRequestException("action null or empty");
62                 } else if (event.equalsIgnoreCase(EVENT_CREATED)) {
63                         return CldsEvent.ACTION_CREATE;
64                 } else if (event.equalsIgnoreCase(EVENT_DISTRIBUTION)) {
65                         return CldsEvent.ACTION_DISTRIBUTE;
66                 } else if (event.equalsIgnoreCase(EVENT_DEPLOYMENT) && (instances == null || instances.isEmpty())) {
67                         return CldsEvent.ACTION_DEPLOY;
68                 } else if (event.equalsIgnoreCase(EVENT_DEPLOYMENT)) {
69                         return CldsEvent.ACTION_DEPLOY;
70                         // EVENT_UNDEPLOYMENT is defunct - DCAE Proxy will not undeploy
71                         // individual instances. It will send an empty list of
72                         // deployed instances to indicate all have been removed. Or it will
73                         // send an updated list to indicate those that
74                         // are still deployed with any not on the list considered
75                         // undeployed.
76                 } else if (event.equals(EVENT_UNDEPLOYMENT)) {
77                         return CldsEvent.ACTION_UNDEPLOY;
78                 }
79
80                 throw new BadRequestException("event value not valid: " + event);
81         }
82
83         /**
84          * Derive the controlName from the artifactName.
85          *
86          * @return the controlName
87          */
88         public String getControlName() {
89                 if (artifactName != null && artifactName.endsWith(ARTIFACT_NAME_SUFFIX)) {
90                         return artifactName.substring(0, artifactName.length() - ARTIFACT_NAME_SUFFIX.length());
91                 } else {
92                         throw new BadRequestException("artifactName value not valid (expecting it to end with "
93                                         + ARTIFACT_NAME_SUFFIX + "): " + artifactName);
94                 }
95         }
96
97         /**
98          * Get the event.
99          * 
100          * @return the event
101          */
102         public String getEvent() {
103                 return event;
104         }
105
106         /**
107          * Set the event.
108          * 
109          * @param event the event to set
110          */
111         public void setEvent(String event) {
112                 this.event = event;
113         }
114
115         /**
116          * Get the serviceUUID.
117          * 
118          * @return the serviceUUID
119          */
120         public String getServiceUUID() {
121                 return serviceUuid;
122         }
123
124         /**
125          * Set the serviceUUID.
126          * 
127          * @param serviceUUID the serviceUUID to set
128          */
129         public void setServiceUUID(String serviceUuid) {
130                 this.serviceUuid = serviceUuid;
131         }
132
133         /**
134          * Get the resourceUUID.
135          * 
136          * @return the resourceUUID
137          */
138         public String getResourceUUID() {
139                 return resourceUuid;
140         }
141
142         /**
143          * Set the resourceUUID.
144          * 
145          * @param resourceUUID the resourceUUID to set
146          */
147         public void setResourceUUID(String resourceUuid) {
148                 this.resourceUuid = resourceUuid;
149         }
150
151         /**
152          * Get the artifact name.
153          * 
154          * @return the artifactName
155          */
156         public String getArtifactName() {
157                 return artifactName;
158         }
159
160         /**
161          * Set the artifact name.
162          * 
163          * @param artifactName the artifactName to set
164          */
165         public void setArtifactName(String artifactName) {
166                 this.artifactName = artifactName;
167         }
168
169         /**
170          * Get the list of instances.
171          * 
172          * @return The list of model instances
173          */
174         public List<CldsModelInstance> getInstances() {
175                 return instances;
176         }
177
178         /**
179          * Set the list of model instances.
180          * 
181          * @param instances The list of model instances to set
182          */
183         public void setInstances(List<CldsModelInstance> instances) {
184                 this.instances = instances;
185         }
186 }