2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.client.orchestration;
25 import java.util.Optional;
27 import org.onap.so.bpmn.common.InjectionHelper;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
32 import org.onap.so.client.aai.AAIObjectPlurals;
33 import org.onap.so.client.aai.AAIObjectType;
34 import org.onap.so.client.aai.AAIResourcesClient;
35 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
36 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
37 import org.onap.so.client.aai.mapper.AAIObjectMapper;
38 import org.onap.so.db.catalog.beans.OrchestrationStatus;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.stereotype.Component;
45 public class AAIServiceInstanceResources {
46 private static final Logger logger = LoggerFactory.getLogger(AAIServiceInstanceResources
50 private InjectionHelper injectionHelper;
53 private AAIObjectMapper aaiObjectMapper;
55 public boolean existsServiceInstance(ServiceInstance serviceInstance) {
56 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
57 serviceInstance.getServiceInstanceId());
58 return injectionHelper.getAaiClient().exists(serviceInstanceURI);
61 public void createServiceInstance(ServiceInstance serviceInstance, Customer customer) {
62 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
63 customer.getGlobalCustomerId(), customer.getServiceSubscription().getServiceType(), serviceInstance.getServiceInstanceId());
64 serviceInstance.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
65 org.onap.aai.domain.yang.ServiceInstance AAIServiceInstance = aaiObjectMapper.mapServiceInstance(serviceInstance);
66 injectionHelper.getAaiClient().createIfNotExists(serviceInstanceURI, Optional.of(AAIServiceInstance));
70 * Create ServiceSubscription in A&AI
73 public void createServiceSubscription(Customer customer) {
74 AAIResourceUri serviceSubscriptionURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION,
75 customer.getGlobalCustomerId(),customer.getServiceSubscription().getServiceType());
76 org.onap.aai.domain.yang.ServiceSubscription serviceSubscription = aaiObjectMapper.mapServiceSubscription(customer.getServiceSubscription());
77 injectionHelper.getAaiClient().createIfNotExists(serviceSubscriptionURI , Optional.of(serviceSubscription));
80 public void deleteServiceInstance(ServiceInstance serviceInstance) {
81 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
82 serviceInstance.getServiceInstanceId());
83 injectionHelper.getAaiClient().delete(serviceInstanceURI);
86 public void createProject(Project project) {
87 AAIResourceUri projectURI = AAIUriFactory.createResourceUri(AAIObjectType.PROJECT, project.getProjectName());
88 org.onap.aai.domain.yang.Project AAIProject = aaiObjectMapper.mapProject(project);
89 injectionHelper.getAaiClient().createIfNotExists(projectURI, Optional.of(AAIProject));
92 public void createProjectandConnectServiceInstance(Project project, ServiceInstance serviceInstance) {
93 AAIResourceUri projectURI = AAIUriFactory.createResourceUri(AAIObjectType.PROJECT, project.getProjectName());
94 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
95 serviceInstance.getServiceInstanceId());
96 org.onap.aai.domain.yang.Project AAIProject = aaiObjectMapper.mapProject(project);
97 injectionHelper.getAaiClient().createIfNotExists(projectURI, Optional.of(AAIProject)).connect(projectURI, serviceInstanceURI);
100 public void createOwningEntity(OwningEntity owningEntity) {
101 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY,
102 owningEntity.getOwningEntityId());
103 org.onap.aai.domain.yang.OwningEntity AAIOwningEntity = aaiObjectMapper.mapOwningEntity(owningEntity);
104 injectionHelper.getAaiClient().createIfNotExists(owningEntityURI, Optional.of(AAIOwningEntity));
107 public boolean existsOwningEntity(OwningEntity owningEntity) {
108 AAIResourceUri owningEntityUri = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY,
109 owningEntity.getOwningEntityId());
110 return injectionHelper.getAaiClient().exists(owningEntityUri);
113 public boolean existsOwningEntityName(String owningEntityName) {
114 AAIResourceUri owningEntityUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.OWNING_ENTITY).queryParam("owning-entity-name", owningEntityName);
115 AAIResourcesClient aaiRC = injectionHelper.getAaiClient();
116 return aaiRC.exists(owningEntityUri);
119 public void connectOwningEntityandServiceInstance(OwningEntity owningEntity, ServiceInstance serviceInstance) {
120 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY,
121 owningEntity.getOwningEntityId());
122 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
123 serviceInstance.getServiceInstanceId());
124 injectionHelper.getAaiClient().connect(owningEntityURI, serviceInstanceURI);
127 public void createOwningEntityandConnectServiceInstance(OwningEntity owningEntity,
128 ServiceInstance serviceInstance) {
129 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY,
130 owningEntity.getOwningEntityId());
131 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
132 serviceInstance.getServiceInstanceId());
133 org.onap.aai.domain.yang.OwningEntity AAIOwningEntity = aaiObjectMapper.mapOwningEntity(owningEntity);
134 injectionHelper.getAaiClient().createIfNotExists(owningEntityURI, Optional.of(AAIOwningEntity)).connect(owningEntityURI,
138 public void updateOrchestrationStatusServiceInstance(ServiceInstance serviceInstance, OrchestrationStatus orchestrationStatus){
139 ServiceInstance copiedServiceInstance = serviceInstance.shallowCopyId();
141 copiedServiceInstance.setOrchestrationStatus(orchestrationStatus);
142 copiedServiceInstance.setServiceInstanceName(serviceInstance.getServiceInstanceName());
143 serviceInstance.setOrchestrationStatus(orchestrationStatus);
144 updateServiceInstance(copiedServiceInstance);
147 public void updateServiceInstance(ServiceInstance serviceInstance) {
148 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
149 org.onap.aai.domain.yang.ServiceInstance AAIServiceInstance = aaiObjectMapper.mapServiceInstance(serviceInstance);
150 injectionHelper.getAaiClient().update(serviceInstanceURI, AAIServiceInstance);