0c519ef29f020b58b279e4eb06292009da7e7c4d
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.aai.groovyflows;
24
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.Optional;
28
29 import org.onap.aai.domain.yang.OwningEntities;
30 import org.onap.aai.domain.yang.OwningEntity;
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.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 public class AAICreateResources {
40         
41         private static final Logger logger = LoggerFactory.getLogger(AAICreateResources.class);
42
43         public void createAAIProject (String projectName, String serviceInstance){
44                 AAIResourceUri projectURI = AAIUriFactory.createResourceUri(AAIObjectType.PROJECT, projectName);
45                 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
46                 AAIResourcesClient aaiRC = new AAIResourcesClient();      
47                 aaiRC.createIfNotExists(projectURI, Optional.empty()).connect(projectURI, serviceInstanceURI);
48                 
49         }
50         
51         public void createAAIOwningEntity(String owningEntityId, String owningEntityName,String serviceInstance){
52                 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
53                 AAIResourceUri serviceInstanceURI = AAIUriFactory.createNodesUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
54                 Map<String, String> hashMap= new HashMap<>();
55                 hashMap.put("owning-entity-name", owningEntityName);    
56                 AAIResourcesClient aaiRC = new AAIResourcesClient();
57                 aaiRC.createIfNotExists(owningEntityURI, Optional.of(hashMap)).connect(owningEntityURI, serviceInstanceURI);
58         }
59
60         public boolean existsOwningEntity(String owningEntityId){
61                 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
62                 AAIResourcesClient aaiRC = new AAIResourcesClient();      
63                 return aaiRC.exists(owningEntityURI);
64         }
65         
66         protected OwningEntities getOwningEntityName(String owningEntityName){
67                 
68                 AAIResourcesClient aaiRC = new AAIResourcesClient();
69                 return aaiRC.get(OwningEntities.class,
70                                 AAIUriFactory
71                                                 .createResourceUri(AAIObjectPlurals.OWNING_ENTITY)
72                                                 .queryParam("owning-entity-name", owningEntityName))
73                                 .orElseGet(() -> {
74                                         logger.debug("No Owning Entity matched by name");
75                                         return null;
76                                 });
77                 
78         }
79         
80         public Optional<OwningEntity> getOwningEntityNames(String owningEntityName) throws Exception{
81                 OwningEntity owningEntity = null;
82                 OwningEntities owningEntities = null;
83                 owningEntities = getOwningEntityName(owningEntityName);
84
85                 if (owningEntities == null) {
86                         return Optional.empty();
87                 } else if (owningEntities.getOwningEntity().size() > 1) {
88                         throw new Exception("Multiple OwningEntities Returned");
89                 } else {
90                         owningEntity = owningEntities.getOwningEntity().get(0);
91                 }
92                 return Optional.of(owningEntity);
93         }
94         
95         public void connectOwningEntityandServiceInstance (String owningEntityId, String serviceInstance){
96                 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
97                 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
98                 AAIResourcesClient aaiRC = new AAIResourcesClient();
99                 aaiRC.connect(owningEntityURI, serviceInstanceURI);
100         }
101         
102         public void createAAIPlatform(String platformName,String vnfId){
103                 AAIResourceUri platformURI = AAIUriFactory.createResourceUri(AAIObjectType.PLATFORM, platformName);
104                 AAIResourceUri genericVnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF,vnfId);
105                 AAIResourcesClient aaiRC = new AAIResourcesClient();                              
106                 aaiRC.createIfNotExists(platformURI, Optional.empty()).connect(platformURI, genericVnfURI);
107         }
108         
109         public void createAAILineOfBusiness(String lineOfBusiness,String vnfId){
110                 AAIResourceUri lineOfBusinessURI = AAIUriFactory.createResourceUri(AAIObjectType.LINE_OF_BUSINESS, lineOfBusiness);
111                 AAIResourceUri genericVnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF,vnfId);
112                 AAIResourcesClient aaiRC = new AAIResourcesClient();                              
113                 aaiRC.createIfNotExists(lineOfBusinessURI, Optional.empty()).connect(lineOfBusinessURI, genericVnfURI);
114         }
115         public void createAAIServiceInstance(String globalCustomerId, String serviceType, String serviceInstanceId){
116                 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustomerId,serviceType,serviceInstanceId);
117                 AAIResourcesClient aaiRC = new AAIResourcesClient();      
118                 aaiRC.createIfNotExists(serviceInstanceURI, Optional.empty());
119         }
120         
121 }