Remove ECOMP in headers
[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 /**
31  * Represent a DCAE Event.
32  */
33 public class DcaeEvent {
34     // this is an event we (clds) sends to dcae
35     public static final String      EVENT_CREATED        = "created";
36     public static final String      EVENT_DISTRIBUTION   = "distribute";
37     public static final String      EVENT_DEPLOYMENT     = "deployment";
38     public static final String      EVENT_UNDEPLOYMENT   = "undeployment";
39     public static final String      ARTIFACT_NAME_SUFFIX = ".yml";
40
41     private String                  event;
42     private String                  serviceUUID;
43     private String                  resourceUUID;
44     private String                  artifactName;                         // controlName.yml
45     private List<CldsModelInstance> instances;
46
47     /**
48      * Transform a DCAE Event Action to a CldsEvent.actionCd
49      *
50      * @return
51      */
52     public String getCldsActionCd() {
53         if (event == null || event.length() == 0) {
54             throw new BadRequestException("action null or empty");
55         } else if (event.equalsIgnoreCase(EVENT_CREATED)) {
56             return CldsEvent.ACTION_CREATE;
57         } else if (event.equalsIgnoreCase(EVENT_DISTRIBUTION)) {
58             return CldsEvent.ACTION_DISTRIBUTE;
59         } else if (event.equalsIgnoreCase(EVENT_DEPLOYMENT) && (instances == null || instances.size() == 0)) {
60             return CldsEvent.ACTION_DEPLOY;
61         } else if (event.equalsIgnoreCase(EVENT_DEPLOYMENT)) {
62             return CldsEvent.ACTION_DEPLOY;
63             // EVENT_UNDEPLOYMENT is defunct - DCAE Proxy will not undeploy
64             // individual instances. It will send an empty list of
65             // deployed instances to indicate all have been removed. Or it will
66             // send an updated list to indicate those that
67             // are still deployed with any not on the list considered
68             // undeployed.
69         } else if (event.equals(EVENT_UNDEPLOYMENT)) {
70             return CldsEvent.ACTION_UNDEPLOY;
71         }
72
73         throw new BadRequestException("event value not valid: " + event);
74     }
75
76     /**
77      * Derive the controlName from the artifactName.
78      *
79      * @return the controlName
80      */
81     public String getControlName() {
82         if (artifactName != null && artifactName.endsWith(ARTIFACT_NAME_SUFFIX)) {
83             return artifactName.substring(0, artifactName.length() - ARTIFACT_NAME_SUFFIX.length());
84         } else {
85             throw new BadRequestException("artifactName value not valid (expecting it to end with "
86                     + ARTIFACT_NAME_SUFFIX + "): " + artifactName);
87         }
88     }
89
90     /**
91      * @return the event
92      */
93     public String getEvent() {
94         return event;
95     }
96
97     /**
98      * @param event
99      *            the event to set
100      */
101     public void setEvent(String event) {
102         this.event = event;
103     }
104
105     /**
106      * @return the serviceUUID
107      */
108     public String getServiceUUID() {
109         return serviceUUID;
110     }
111
112     /**
113      * @param serviceUUID
114      *            the serviceUUID to set
115      */
116     public void setServiceUUID(String serviceUUID) {
117         this.serviceUUID = serviceUUID;
118     }
119
120     /**
121      * @return the resourceUUID
122      */
123     public String getResourceUUID() {
124         return resourceUUID;
125     }
126
127     /**
128      * @param resourceUUID
129      *            the resourceUUID to set
130      */
131     public void setResourceUUID(String resourceUUID) {
132         this.resourceUUID = resourceUUID;
133     }
134
135     /**
136      * @return the artifactName
137      */
138     public String getArtifactName() {
139         return artifactName;
140     }
141
142     /**
143      * @param artifactName
144      *            the artifactName to set
145      */
146     public void setArtifactName(String artifactName) {
147         this.artifactName = artifactName;
148     }
149
150     public List<CldsModelInstance> getInstances() {
151         return instances;
152     }
153
154     public void setInstances(List<CldsModelInstance> instances) {
155         this.instances = instances;
156     }
157
158 }