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 org.jboss.resteasy.spi.BadRequestException;
28 import java.util.List;
31 * Represent a DCAE Event.
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";
41 private String serviceUUID;
42 private String resourceUUID;
43 private String artifactName; // controlName.yml
44 private List<CldsModelInstance> instances;
47 * Transform a DCAE Event Action to a CldsEvent.actionCd
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;
69 throw new BadRequestException("event value not valid: " + event);
73 * Derive the controlName from the artifactName.
75 * @return the controlName
77 public String getControlName() {
78 if (artifactName != null && artifactName.endsWith(ARTIFACT_NAME_SUFFIX)) {
79 return artifactName.substring(0, artifactName.length() - ARTIFACT_NAME_SUFFIX.length());
81 throw new BadRequestException("artifactName value not valid (expecting it to end with " + ARTIFACT_NAME_SUFFIX + "): " + artifactName);
88 public String getEvent() {
93 * @param event the event to set
95 public void setEvent(String event) {
100 * @return the serviceUUID
102 public String getServiceUUID() {
107 * @param serviceUUID the serviceUUID to set
109 public void setServiceUUID(String serviceUUID) {
110 this.serviceUUID = serviceUUID;
114 * @return the resourceUUID
116 public String getResourceUUID() {
121 * @param resourceUUID the resourceUUID to set
123 public void setResourceUUID(String resourceUUID) {
124 this.resourceUUID = resourceUUID;
128 * @return the artifactName
130 public String getArtifactName() {
135 * @param artifactName the artifactName to set
137 public void setArtifactName(String artifactName) {
138 this.artifactName = artifactName;
141 public List<CldsModelInstance> getInstances() {
145 public void setInstances(List<CldsModelInstance> instances) {
146 this.instances = instances;