2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.clds.model;
26 import java.util.List;
28 import javax.ws.rs.BadRequestException;
30 import com.google.gson.annotations.Expose;
33 * Represent a DCAE Event.
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";
46 private String serviceUuid;
48 private String resourceUuid;
50 private String artifactName; // controlName.yml
52 private List<CldsModelInstance> instances;
55 * Transform a DCAE Event Action to a CldsEvent.actionCd.
57 * @return The clds action.
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
76 } else if (event.equals(EVENT_UNDEPLOYMENT)) {
77 return CldsEvent.ACTION_UNDEPLOY;
80 throw new BadRequestException("event value not valid: " + event);
84 * Derive the controlName from the artifactName.
86 * @return the controlName
88 public String getControlName() {
89 if (artifactName != null && artifactName.endsWith(ARTIFACT_NAME_SUFFIX)) {
90 return artifactName.substring(0, artifactName.length() - ARTIFACT_NAME_SUFFIX.length());
92 throw new BadRequestException("artifactName value not valid (expecting it to end with "
93 + ARTIFACT_NAME_SUFFIX + "): " + artifactName);
102 public String getEvent() {
109 * @param event the event to set
111 public void setEvent(String event) {
116 * Get the serviceUUID.
118 * @return the serviceUUID
120 public String getServiceUUID() {
125 * Set the serviceUUID.
127 * @param serviceUUID the serviceUUID to set
129 public void setServiceUUID(String serviceUuid) {
130 this.serviceUuid = serviceUuid;
134 * Get the resourceUUID.
136 * @return the resourceUUID
138 public String getResourceUUID() {
143 * Set the resourceUUID.
145 * @param resourceUUID the resourceUUID to set
147 public void setResourceUUID(String resourceUuid) {
148 this.resourceUuid = resourceUuid;
152 * Get the artifact name.
154 * @return the artifactName
156 public String getArtifactName() {
161 * Set the artifact name.
163 * @param artifactName the artifactName to set
165 public void setArtifactName(String artifactName) {
166 this.artifactName = artifactName;
170 * Get the list of instances.
172 * @return The list of model instances
174 public List<CldsModelInstance> getInstances() {
179 * Set the list of model instances.
181 * @param instances The list of model instances to set
183 public void setInstances(List<CldsModelInstance> instances) {
184 this.instances = instances;