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