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.bpmn.infrastructure.aai;
23 import java.util.HashMap;
25 import java.util.Optional;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
27 import org.onap.aaiclient.client.aai.AAIObjectType;
28 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
29 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
30 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class AAICreateResources extends AAIResource {
36 private static final Logger logger = LoggerFactory.getLogger(AAICreateResources.class);
38 public void createAAIProject(String projectName, String serviceInstance) {
39 AAIResourceUri projectURI = AAIUriFactory.createResourceUri(AAIObjectType.PROJECT, projectName);
40 AAIResourceUri serviceInstanceURI =
41 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
42 getAaiClient().createIfNotExists(projectURI, Optional.empty()).connect(projectURI, serviceInstanceURI);
46 public void createAAIOwningEntity(String owningEntityId, String owningEntityName, String serviceInstance) {
47 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
48 AAIResourceUri serviceInstanceURI =
49 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
50 Map<String, String> hashMap = new HashMap<>();
51 hashMap.put("owning-entity-name", owningEntityName);
52 getAaiClient().createIfNotExists(owningEntityURI, Optional.of(hashMap)).connect(owningEntityURI,
56 public boolean existsOwningEntity(String owningEntityId) {
57 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
58 return getAaiClient().exists(owningEntityURI);
61 public void connectOwningEntityandServiceInstance(String owningEntityId, String serviceInstance) {
62 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
63 AAIResourceUri serviceInstanceURI =
64 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
65 getAaiClient().connect(owningEntityURI, serviceInstanceURI);
68 public void createAAIPlatform(String platformName, String vnfId) {
69 AAIResourceUri platformURI = AAIUriFactory.createResourceUri(AAIObjectType.PLATFORM, platformName);
70 AAIResourceUri genericVnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
71 getAaiClient().createIfNotExists(platformURI, Optional.empty()).connect(platformURI, genericVnfURI);
74 public void createAAILineOfBusiness(String lineOfBusiness, String vnfId) {
75 AAIResourceUri lineOfBusinessURI =
76 AAIUriFactory.createResourceUri(AAIObjectType.LINE_OF_BUSINESS, lineOfBusiness);
77 AAIResourceUri genericVnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
78 getAaiClient().createIfNotExists(lineOfBusinessURI, Optional.empty()).connect(lineOfBusinessURI, genericVnfURI);
81 public void createAAIServiceInstance(String globalCustomerId, String serviceType, String serviceInstanceId) {
82 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
83 globalCustomerId, serviceType, serviceInstanceId);
84 getAaiClient().createIfNotExists(serviceInstanceURI, Optional.empty());
87 public Optional<GenericVnf> getVnfInstance(String vnfId) {
89 AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
90 AAIResultWrapper aaiResponse = getAaiClient().get(vnfURI);
91 Optional<GenericVnf> vnf = aaiResponse.asBean(GenericVnf.class);
93 } catch (Exception ex) {
94 logger.error("Exception in getVnfInstance", ex);
95 return Optional.empty();