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=========================================================
21 package org.openecomp.mso.client.orchestration;
23 import java.util.Optional;
24 import java.util.logging.Logger;
26 import org.modelmapper.ModelMapper;
27 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;
28 import org.openecomp.mso.client.aai.AAIResourcesClient;
29 import org.openecomp.mso.client.aai.entities.AAIEntityObject;
30 import org.openecomp.mso.client.aai.objects.AAIOwningEntity;
31 import org.openecomp.mso.client.aai.objects.AAIProject;
32 import org.openecomp.mso.client.aai.objects.AAIServiceInstance;
34 public class AAIOrchestrator {
36 private static Logger LOGGER = Logger.getLogger("AAIOrchestrator");
38 public void createServiceInstance(ServiceDecomposition serviceDecomp) {
40 ModelMapper modelMapper = new ModelMapper();
41 AAIEntityObject serviceInstance = modelMapper.map(serviceDecomp.getServiceInstance(), AAIServiceInstance.class);
42 AAIResourcesClient aaiRC = this.getClient();
43 aaiRC.createIfNotExists(serviceInstance.getUri(), Optional.of(serviceInstance));
44 }catch(Exception ex) {
45 String msg = "Failed to create service instance in A&AI.";
46 throw new IllegalStateException(msg);
50 public void deleteServiceInstance(ServiceDecomposition serviceDecomp) {
52 ModelMapper modelMapper = new ModelMapper();
53 AAIEntityObject serviceInstance = modelMapper.map(serviceDecomp.getServiceInstance(), AAIServiceInstance.class);
54 AAIResourcesClient aaiRC = this.getClient();
55 aaiRC.delete(serviceInstance.getUri());
56 } catch (Exception ex) {
57 String msg = "Failed to delete service instance in A&AI.";
58 throw new IllegalStateException(msg);
62 public void createProject(ServiceDecomposition serviceDecomp) {
64 ModelMapper modelMapper = new ModelMapper();
65 AAIEntityObject project = modelMapper.map(serviceDecomp.getProject(), AAIProject.class);
66 AAIResourcesClient aaiRC = this.getClient();
67 aaiRC.createIfNotExists(project.getUri(), Optional.of(project));
68 }catch(Exception ex) {
69 String msg = "Failed to create project in A&AI.";
70 throw new IllegalStateException(msg); }
73 public void createProjectandConnectServiceInstance(ServiceDecomposition serviceDecomp) {
75 ModelMapper modelMapper = new ModelMapper();
76 AAIEntityObject project = modelMapper.map(serviceDecomp.getProject(), AAIProject.class);
77 AAIEntityObject serviceInstance = modelMapper.map(serviceDecomp.getServiceInstance(), AAIServiceInstance.class);
78 AAIResourcesClient aaiRC = this.getClient();
79 aaiRC.createIfNotExists(project.getUri(), Optional.of(project)).connect(project.getUri(), serviceInstance.getUri());
80 } catch(Exception ex) {
81 String msg = "Failed to create project and connect service instance in A&AI.";
82 throw new IllegalStateException(msg);
86 public void createOwningEntity(ServiceDecomposition serviceDecomp) {
88 ModelMapper modelMapper = new ModelMapper();
89 AAIEntityObject owningEntity = modelMapper.map(serviceDecomp.getOwningEntity(), AAIOwningEntity.class);
90 AAIResourcesClient aaiRC = this.getClient();
91 aaiRC.createIfNotExists(owningEntity.getUri(), Optional.of(owningEntity));
92 }catch(Exception ex) {
93 String msg = "Failed to create owning entity in A&AI.";
94 throw new IllegalStateException(msg);
98 public void createOwningEntityandConnectServiceInstance(ServiceDecomposition serviceDecomp) {
100 ModelMapper modelMapper = new ModelMapper();
101 AAIEntityObject owningEntity = modelMapper.map(serviceDecomp.getOwningEntity(), AAIOwningEntity.class);
102 AAIEntityObject serviceInstance = modelMapper.map(serviceDecomp.getServiceInstance(), AAIServiceInstance.class);
103 AAIResourcesClient aaiRC = this.getClient();
104 aaiRC.createIfNotExists(owningEntity.getUri(), Optional.of(owningEntity)).connect(owningEntity.getUri(), serviceInstance.getUri());
105 }catch(Exception ex) {
106 String msg = "Failed to create owning entity and connect service instance in A&AI.";
107 throw new IllegalStateException(msg); }
110 protected AAIResourcesClient getClient() {
111 return new AAIResourcesClient();