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;
26 import org.onap.so.bpmn.common.InjectionHelper;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
31 import org.onap.so.client.aai.AAIObjectPlurals;
32 import org.onap.so.client.aai.AAIObjectType;
33 import org.onap.so.client.aai.AAIResourcesClient;
34 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
35 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
36 import org.onap.so.client.aai.mapper.AAIObjectMapper;
37 import org.onap.so.db.catalog.beans.OrchestrationStatus;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.stereotype.Component;
44 public class AAIServiceInstanceResources {
45 private static final Logger logger = LoggerFactory.getLogger(AAIServiceInstanceResources.class);
48 private InjectionHelper injectionHelper;
51 private AAIObjectMapper aaiObjectMapper;
53 public boolean existsServiceInstance(ServiceInstance serviceInstance) {
54 AAIResourceUri serviceInstanceURI =
55 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
56 return injectionHelper.getAaiClient().exists(serviceInstanceURI);
59 public void createServiceInstance(ServiceInstance serviceInstance, Customer customer) {
60 AAIResourceUri serviceInstanceURI =
61 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, customer.getGlobalCustomerId(),
62 customer.getServiceSubscription().getServiceType(), serviceInstance.getServiceInstanceId());
63 serviceInstance.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
64 org.onap.aai.domain.yang.ServiceInstance AAIServiceInstance =
65 aaiObjectMapper.mapServiceInstance(serviceInstance);
66 injectionHelper.getAaiClient().createIfNotExists(serviceInstanceURI, Optional.of(AAIServiceInstance));
70 * Create ServiceSubscription in A&AI
74 public void createServiceSubscription(Customer customer) {
75 AAIResourceUri serviceSubscriptionURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION,
76 customer.getGlobalCustomerId(), customer.getServiceSubscription().getServiceType());
77 org.onap.aai.domain.yang.ServiceSubscription serviceSubscription =
78 aaiObjectMapper.mapServiceSubscription(customer.getServiceSubscription());
79 injectionHelper.getAaiClient().createIfNotExists(serviceSubscriptionURI, Optional.of(serviceSubscription));
82 public void deleteServiceInstance(ServiceInstance serviceInstance) {
83 AAIResourceUri serviceInstanceURI =
84 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
85 injectionHelper.getAaiClient().delete(serviceInstanceURI);
88 public void createProject(Project project) {
89 AAIResourceUri projectURI = AAIUriFactory.createResourceUri(AAIObjectType.PROJECT, project.getProjectName());
90 org.onap.aai.domain.yang.Project AAIProject = aaiObjectMapper.mapProject(project);
91 injectionHelper.getAaiClient().createIfNotExists(projectURI, Optional.of(AAIProject));
94 public void createProjectandConnectServiceInstance(Project project, ServiceInstance serviceInstance) {
95 AAIResourceUri projectURI = AAIUriFactory.createResourceUri(AAIObjectType.PROJECT, project.getProjectName());
96 AAIResourceUri serviceInstanceURI =
97 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
98 org.onap.aai.domain.yang.Project AAIProject = aaiObjectMapper.mapProject(project);
99 injectionHelper.getAaiClient().createIfNotExists(projectURI, Optional.of(AAIProject)).connect(projectURI,
103 public void createOwningEntity(OwningEntity owningEntity) {
104 AAIResourceUri owningEntityURI =
105 AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntity.getOwningEntityId());
106 org.onap.aai.domain.yang.OwningEntity AAIOwningEntity = aaiObjectMapper.mapOwningEntity(owningEntity);
107 injectionHelper.getAaiClient().createIfNotExists(owningEntityURI, Optional.of(AAIOwningEntity));
110 public boolean existsOwningEntity(OwningEntity owningEntity) {
111 AAIResourceUri owningEntityUri =
112 AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntity.getOwningEntityId());
113 return injectionHelper.getAaiClient().exists(owningEntityUri);
116 public boolean existsOwningEntityName(String owningEntityName) {
117 AAIResourceUri owningEntityUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.OWNING_ENTITY)
118 .queryParam("owning-entity-name", owningEntityName);
119 AAIResourcesClient aaiRC = injectionHelper.getAaiClient();
120 return aaiRC.exists(owningEntityUri);
123 public void connectOwningEntityandServiceInstance(OwningEntity owningEntity, ServiceInstance serviceInstance) {
124 AAIResourceUri owningEntityURI =
125 AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntity.getOwningEntityId());
126 AAIResourceUri serviceInstanceURI =
127 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
128 injectionHelper.getAaiClient().connect(owningEntityURI, serviceInstanceURI);
131 public void createOwningEntityandConnectServiceInstance(OwningEntity owningEntity,
132 ServiceInstance serviceInstance) {
133 AAIResourceUri owningEntityURI =
134 AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntity.getOwningEntityId());
135 AAIResourceUri serviceInstanceURI =
136 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
137 org.onap.aai.domain.yang.OwningEntity AAIOwningEntity = aaiObjectMapper.mapOwningEntity(owningEntity);
138 injectionHelper.getAaiClient().createIfNotExists(owningEntityURI, Optional.of(AAIOwningEntity))
139 .connect(owningEntityURI, serviceInstanceURI);
142 public void updateOrchestrationStatusServiceInstance(ServiceInstance serviceInstance,
143 OrchestrationStatus orchestrationStatus) {
144 ServiceInstance copiedServiceInstance = serviceInstance.shallowCopyId();
146 copiedServiceInstance.setOrchestrationStatus(orchestrationStatus);
147 copiedServiceInstance.setServiceInstanceName(serviceInstance.getServiceInstanceName());
148 serviceInstance.setOrchestrationStatus(orchestrationStatus);
149 updateServiceInstance(copiedServiceInstance);
152 public void updateServiceInstance(ServiceInstance serviceInstance) {
153 AAIResourceUri serviceInstanceURI =
154 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
155 org.onap.aai.domain.yang.ServiceInstance AAIServiceInstance =
156 aaiObjectMapper.mapServiceInstance(serviceInstance);
157 injectionHelper.getAaiClient().update(serviceInstanceURI, AAIServiceInstance);