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.onap.so.client.orchestration;
23 import java.util.Optional;
25 import org.onap.so.bpmn.common.InjectionHelper;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
30 import org.onap.so.client.aai.AAIObjectPlurals;
31 import org.onap.so.client.aai.AAIObjectType;
32 import org.onap.so.client.aai.AAIResourcesClient;
33 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
34 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
35 import org.onap.so.client.aai.mapper.AAIObjectMapper;
36 import org.onap.so.db.catalog.beans.OrchestrationStatus;
37 import org.onap.so.logger.MsoLogger;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.stereotype.Component;
42 public class AAIServiceInstanceResources {
43 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAIServiceInstanceResources.class);
46 private InjectionHelper injectionHelper;
49 private AAIObjectMapper aaiObjectMapper;
51 public boolean existsServiceInstance(ServiceInstance serviceInstance) {
52 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
53 serviceInstance.getServiceInstanceId());
54 return injectionHelper.getAaiClient().exists(serviceInstanceURI);
57 public void createServiceInstance(ServiceInstance serviceInstance, Customer customer) {
58 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
59 customer.getGlobalCustomerId(), customer.getServiceSubscription().getServiceType(), serviceInstance.getServiceInstanceId());
60 serviceInstance.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
61 org.onap.aai.domain.yang.ServiceInstance AAIServiceInstance = aaiObjectMapper.mapServiceInstance(serviceInstance);
62 injectionHelper.getAaiClient().createIfNotExists(serviceInstanceURI, Optional.of(AAIServiceInstance));
66 * Create ServiceSubscription in A&AI
69 public void createServiceSubscription(Customer customer) {
70 AAIResourceUri serviceSubscriptionURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION,
71 customer.getGlobalCustomerId(),customer.getServiceSubscription().getServiceType());
72 org.onap.aai.domain.yang.ServiceSubscription serviceSubscription = aaiObjectMapper.mapServiceSubscription(customer.getServiceSubscription());
73 injectionHelper.getAaiClient().createIfNotExists(serviceSubscriptionURI , Optional.of(serviceSubscription));
76 public void deleteServiceInstance(ServiceInstance serviceInstance) {
77 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
78 serviceInstance.getServiceInstanceId());
79 injectionHelper.getAaiClient().delete(serviceInstanceURI);
82 public void createProject(Project project) {
83 AAIResourceUri projectURI = AAIUriFactory.createResourceUri(AAIObjectType.PROJECT, project.getProjectName());
84 org.onap.aai.domain.yang.Project AAIProject = aaiObjectMapper.mapProject(project);
85 injectionHelper.getAaiClient().createIfNotExists(projectURI, Optional.of(AAIProject));
88 public void createProjectandConnectServiceInstance(Project project, ServiceInstance serviceInstance) {
89 AAIResourceUri projectURI = AAIUriFactory.createResourceUri(AAIObjectType.PROJECT, project.getProjectName());
90 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
91 serviceInstance.getServiceInstanceId());
92 org.onap.aai.domain.yang.Project AAIProject = aaiObjectMapper.mapProject(project);
93 injectionHelper.getAaiClient().createIfNotExists(projectURI, Optional.of(AAIProject)).connect(projectURI, serviceInstanceURI);
96 public void createOwningEntity(OwningEntity owningEntity) {
97 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY,
98 owningEntity.getOwningEntityId());
99 org.onap.aai.domain.yang.OwningEntity AAIOwningEntity = aaiObjectMapper.mapOwningEntity(owningEntity);
100 injectionHelper.getAaiClient().createIfNotExists(owningEntityURI, Optional.of(AAIOwningEntity));
103 public boolean existsOwningEntity(OwningEntity owningEntity) {
104 AAIResourceUri owningEntityUri = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY,
105 owningEntity.getOwningEntityId());
106 return injectionHelper.getAaiClient().exists(owningEntityUri);
109 public boolean existsOwningEntityName(String owningEntityName) {
110 AAIResourceUri owningEntityUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.OWNING_ENTITIES).queryParam("owning-entity-name", owningEntityName);
111 AAIResourcesClient aaiRC = injectionHelper.getAaiClient();
112 return aaiRC.exists(owningEntityUri);
115 public void connectOwningEntityandServiceInstance(OwningEntity owningEntity, ServiceInstance serviceInstance) {
116 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY,
117 owningEntity.getOwningEntityId());
118 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
119 serviceInstance.getServiceInstanceId());
120 injectionHelper.getAaiClient().connect(owningEntityURI, serviceInstanceURI);
123 public void createOwningEntityandConnectServiceInstance(OwningEntity owningEntity,
124 ServiceInstance serviceInstance) {
125 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY,
126 owningEntity.getOwningEntityId());
127 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
128 serviceInstance.getServiceInstanceId());
129 org.onap.aai.domain.yang.OwningEntity AAIOwningEntity = aaiObjectMapper.mapOwningEntity(owningEntity);
130 injectionHelper.getAaiClient().createIfNotExists(owningEntityURI, Optional.of(AAIOwningEntity)).connect(owningEntityURI,
134 public void updateOrchestrationStatusServiceInstance(ServiceInstance serviceInstance, OrchestrationStatus orchestrationStatus){
135 ServiceInstance copiedServiceInstance = serviceInstance.shallowCopyId();
137 copiedServiceInstance.setOrchestrationStatus(orchestrationStatus);
138 copiedServiceInstance.setServiceInstanceName(serviceInstance.getServiceInstanceName());
139 serviceInstance.setOrchestrationStatus(orchestrationStatus);
140 updateServiceInstance(copiedServiceInstance);
143 public void updateServiceInstance(ServiceInstance serviceInstance) {
144 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
145 org.onap.aai.domain.yang.ServiceInstance AAIServiceInstance = aaiObjectMapper.mapServiceInstance(serviceInstance);
146 injectionHelper.getAaiClient().update(serviceInstanceURI, AAIServiceInstance);