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 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.model;
26 import java.util.List;
28 import javax.ws.rs.BadRequestException;
31 * Represent a DCAE Event.
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";
42 private String serviceUUID;
43 private String resourceUUID;
44 private String artifactName; // controlName.yml
45 private List<CldsModelInstance> instances;
48 * Transform a DCAE Event Action to a CldsEvent.actionCd
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
69 } else if (event.equals(EVENT_UNDEPLOYMENT)) {
70 return CldsEvent.ACTION_UNDEPLOY;
73 throw new BadRequestException("event value not valid: " + event);
77 * Derive the controlName from the artifactName.
79 * @return the controlName
81 public String getControlName() {
82 if (artifactName != null && artifactName.endsWith(ARTIFACT_NAME_SUFFIX)) {
83 return artifactName.substring(0, artifactName.length() - ARTIFACT_NAME_SUFFIX.length());
85 throw new BadRequestException("artifactName value not valid (expecting it to end with "
86 + ARTIFACT_NAME_SUFFIX + "): " + artifactName);
93 public String getEvent() {
101 public void setEvent(String event) {
106 * @return the serviceUUID
108 public String getServiceUUID() {
114 * the serviceUUID to set
116 public void setServiceUUID(String serviceUUID) {
117 this.serviceUUID = serviceUUID;
121 * @return the resourceUUID
123 public String getResourceUUID() {
128 * @param resourceUUID
129 * the resourceUUID to set
131 public void setResourceUUID(String resourceUUID) {
132 this.resourceUUID = resourceUUID;
136 * @return the artifactName
138 public String getArtifactName() {
143 * @param artifactName
144 * the artifactName to set
146 public void setArtifactName(String artifactName) {
147 this.artifactName = artifactName;
150 public List<CldsModelInstance> getInstances() {
154 public void setInstances(List<CldsModelInstance> instances) {
155 this.instances = instances;