2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.adapters.vnf;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
27 import com.gigaspaces.aria.rest.client.AriaClient;
28 import com.gigaspaces.aria.rest.client.AriaClientFactory;
29 import com.gigaspaces.aria.rest.client.ExecutionDetails;
30 import com.gigaspaces.aria.rest.client.Input;
31 import com.gigaspaces.aria.rest.client.InputImpl;
32 import com.gigaspaces.aria.rest.client.Output;
33 import com.gigaspaces.aria.rest.client.Service;
34 import com.gigaspaces.aria.rest.client.ServiceTemplate;
35 import com.gigaspaces.aria.rest.client.ServiceTemplateImpl;
36 import org.openecomp.mso.logger.MessageEnum;
37 import org.openecomp.mso.logger.MsoLogger;
38 import org.openecomp.mso.openstack.exceptions.MsoAdapterException;
39 import org.openecomp.mso.openstack.exceptions.MsoException;
40 import org.openecomp.mso.vdu.utils.VduBlueprint;
41 import org.openecomp.mso.vdu.utils.VduInfo;
42 import org.openecomp.mso.vdu.utils.VduPlugin;
43 import org.openecomp.mso.vdu.utils.VduStatus;
46 * ARIA VDU Plugin. Pluggable interface for the ARIA REST API to support TOSCA
52 public class AriaVduPlugin implements VduPlugin {
53 private static final String API_VERSION = "0.1";
54 private static final MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
55 private AriaClient client=null;
56 private Map<String,Integer> templateIds = new HashMap<>();
57 private Map<String,Integer> serviceIds = new HashMap<>();
58 private Map<String,Map<String,Object>> inputsCache = new HashMap<>();
60 public AriaVduPlugin() {
64 public AriaVduPlugin( String host, int port) {
66 client = new AriaClientFactory().createRestClient("http", host, port, API_VERSION);
68 logger.error (MessageEnum.RA_CREATE_VNF_ERR, "", "", "", "", "aria", MsoLogger.ErrorCode.AvailabilityError, "Connection to ARIA REST API failed", e);
74 * Instantiate VDU in ARIA. <code>vduInstanceName</code> is used for both service template
75 * name and service name.<
77 @SuppressWarnings("unchecked")
79 public VduInfo instantiateVdu(String cloudSiteId, String tenantId, String vduInstanceName,
80 VduBlueprint vduBlueprint, Map<String, ? extends Object> inputs, String environmentFile, int timeoutMinutes,
81 boolean suppressBackout) throws MsoException {
83 VduInfo vinfo = new VduInfo(vduInstanceName);
84 byte[] csar = new CSAR(vduBlueprint).create();
85 ServiceTemplate template = new ServiceTemplateImpl( vduInstanceName, csar);
87 client.install_service_template(template);
90 logger.error(MessageEnum.RA_CREATE_VNF_ERR, "","","","", vduInstanceName, MsoLogger.ErrorCode.BusinessProcesssError,
91 "instantiate vdu via csar failed", e);
92 throw new MsoAdapterException(e.getMessage());
101 for(ServiceTemplate stemplate:(List<ServiceTemplate>)client.list_service_templates()) {
102 if(stemplate.getName().equals(vduInstanceName)) {
103 templateId = stemplate.getId();
106 List<Input> sinputs = new ArrayList<Input>();
107 for(Map.Entry<String, ? extends Object> entry: inputs.entrySet()) {
108 Input inp = new InputImpl(entry.getKey(),entry.getValue().toString(),"");
111 client.create_service(templateId, vduInstanceName, sinputs);
114 logger.error(MessageEnum.RA_CREATE_VNF_ERR, "","","","", vduInstanceName, MsoLogger.ErrorCode.BusinessProcesssError,
115 "aria service creation failed", e);
116 throw new MsoAdapterException(e.getMessage());
119 // Get the service ID and cache it
120 int sid = getServiceId(vduInstanceName);
121 serviceIds.put(vduInstanceName, sid);
128 client.start_execution( sid, "install", new ExecutionDetails());
131 logger.error(MessageEnum.RA_CREATE_VNF_ERR, "","","","", vduInstanceName, MsoLogger.ErrorCode.BusinessProcesssError,
132 "aria install workflow failed", e);
133 throw new MsoAdapterException(e.getMessage());
137 * Get the outputs and return
141 Map<String,Object> voutputs = getOutputs(sid);
143 VduInfo vi = new VduInfo(vduInstanceName);
144 vi.setInputs((Map<String,Object>)inputs);
145 inputsCache.put(vduInstanceName,vi.getInputs());
146 vi.setOutputs(voutputs);
147 vi.setStatus(VduStatus.INSTANTIATED);
151 logger.error(MessageEnum.RA_CREATE_VNF_ERR, "","","","", vduInstanceName, MsoLogger.ErrorCode.BusinessProcesssError,
152 "aria service output fetch failed", e);
153 throw new MsoAdapterException(e.getMessage());
159 * Queries ARIA for VDU status. vduInstanceId used as template and service name in ARIA (by convention).
162 public VduInfo queryVdu(String cloudSiteId, String tenantId, String vduInstanceId) throws MsoException {
164 throw new MsoAdapterException("Internal error: no ARIA connection found");
167 VduInfo vif = new VduInfo(vduInstanceId);
168 Integer sid = serviceIds.get(vduInstanceId);
170 // service doesn't exist
171 vif.setStatus(VduStatus.NOTFOUND);
174 Service service = client.get_service(sid);
175 if(service == null) {
176 throw new MsoAdapterException(String.format("Internal error: cached service id %s not found in ARIA",sid));
178 Map<String,Object> voutputs = getOutputs(sid);
179 vif.setOutputs(voutputs);
180 vif.setInputs(inputsCache.get(vduInstanceId));
181 vif.setStatus(VduStatus.INSTANTIATED);
186 public VduInfo deleteVdu(String cloudSiteId, String tenantId, String vduInstanceId, int timeoutMinutes,
187 boolean keepBlueprintLoaded) throws MsoException {
190 throw new MsoAdapterException("Internal error: no ARIA connection found");
192 Integer sid = serviceIds.get(vduInstanceId);
193 VduInfo vif = new VduInfo(vduInstanceId);
195 // service doesn't exist
196 vif.setStatus(VduStatus.NOTFOUND);
204 client.start_execution( sid, "uninstall", new ExecutionDetails());
207 logger.error(MessageEnum.RA_CREATE_VNF_ERR, "","","","", vduInstanceId, MsoLogger.ErrorCode.BusinessProcesssError,
208 "aria uninstall workflow failed", e);
209 throw new MsoAdapterException(e.getMessage());
216 client.delete_service(sid);
219 logger.error(MessageEnum.RA_CREATE_VNF_ERR, "","","","", vduInstanceId, MsoLogger.ErrorCode.BusinessProcesssError,
220 String.format("aria service delete failed. Service id: %d",sid), e);
221 throw new MsoAdapterException(e.getMessage());
225 * Delete the blueprint
228 client.delete_service_template(templateIds.get(vduInstanceId));
231 logger.error(MessageEnum.RA_CREATE_VNF_ERR, "","","","", vduInstanceId, MsoLogger.ErrorCode.BusinessProcesssError,
232 "aria template delete failed", e);
233 throw new MsoAdapterException(e.getMessage());
236 vif.setStatus(VduStatus.DELETED);
241 * Deployment update not possible with ARIA
244 public VduInfo updateVdu(String cloudSiteId, String tenantId, String vduInstanceId, VduBlueprint vduBlueprint,
245 Map<String, ? extends Object> inputs, String environmentFile, int timeoutMinutes) throws MsoException {
246 throw new MsoAdapterException("NOT IMPLEMENTED");
250 * Nonsensical in the context of ARIA: blueprint lifespan = vdulifespan
253 public boolean isBlueprintLoaded(String cloudSiteId, String vduModelId) throws MsoException {
254 throw new MsoAdapterException("NOT IMPLEMENTED");
258 * Nonsensical in the context of ARIA: blueprint lifespan = vdulifespan
261 public void uploadBlueprint(String cloudSiteId, VduBlueprint vduBlueprint, boolean failIfExists)
262 throws MsoException {
263 throw new MsoAdapterException("NOT IMPLEMENTED");
267 public boolean blueprintUploadSupported() {
276 * Gets and repacks service outputs for internal use
277 * @param sid the service id (ARIA service id)
280 private Map<String,Object> getOutputs(int sid) {
281 @SuppressWarnings("unchecked")
282 List<Output> outputs=(List<Output>)client.list_service_outputs(sid);
283 Map<String,Object> voutputs = new HashMap<>();
284 for(Output output: outputs) {
285 voutputs.put(output.getName(), output.getValue());
290 @SuppressWarnings("unchecked")
291 private int getServiceId(String service_name) throws MsoAdapterException{
293 List<Service> services = (List<Service>)client.list_services();
294 for(Service service:services) {
295 if(service.getName().equals(service_name)) {
296 sid = service.getId();
300 throw new MsoAdapterException(String.format("Internal error: just created service not found: %s",service_name));