Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / java / org / onap / so / bpmn / infrastructure / aai / AAICreateResources.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.aai;
22
23 import java.util.HashMap;
24 import java.util.Map;
25 import java.util.Optional;
26
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
28 import org.onap.so.client.aai.AAIObjectType;
29 import org.onap.so.client.aai.AAIResourcesClient;
30 import org.onap.so.client.aai.entities.AAIResultWrapper;
31 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
32 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
33
34 public class AAICreateResources extends AAIResource {
35
36
37         public void createAAIProject (String projectName, String serviceInstance){
38                 AAIResourceUri projectURI = AAIUriFactory.createResourceUri(AAIObjectType.PROJECT, projectName);
39                 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
40                 getAaiClient().createIfNotExists(projectURI, Optional.empty()).connect(projectURI, serviceInstanceURI);
41                 
42         }
43         
44         public void createAAIOwningEntity(String owningEntityId, String owningEntityName,String serviceInstance){
45                 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
46                 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
47                 Map<String, String> hashMap= new HashMap<>();
48                 hashMap.put("owning-entity-name", owningEntityName);    
49                 getAaiClient().createIfNotExists(owningEntityURI, Optional.of(hashMap)).connect(owningEntityURI, serviceInstanceURI);
50         }
51
52         public boolean existsOwningEntity(String owningEntityId){
53                 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
54                 return getAaiClient().exists(owningEntityURI);
55         }
56         
57         public void connectOwningEntityandServiceInstance (String owningEntityId, String serviceInstance){
58                 AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntityId);
59                 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance);
60                 getAaiClient().connect(owningEntityURI, serviceInstanceURI);
61         }
62         
63         public void createAAIPlatform(String platformName,String vnfId){
64                 AAIResourceUri platformURI = AAIUriFactory.createResourceUri(AAIObjectType.PLATFORM, platformName);
65                 AAIResourceUri genericVnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF,vnfId);
66                 getAaiClient().createIfNotExists(platformURI, Optional.empty()).connect(platformURI, genericVnfURI);
67         }
68         
69         public void createAAILineOfBusiness(String lineOfBusiness,String vnfId){
70                 AAIResourceUri lineOfBusinessURI = AAIUriFactory.createResourceUri(AAIObjectType.LINE_OF_BUSINESS, lineOfBusiness);
71                 AAIResourceUri genericVnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF,vnfId);
72                 getAaiClient().createIfNotExists(lineOfBusinessURI, Optional.empty()).connect(lineOfBusinessURI, genericVnfURI);
73         }
74         public void createAAIServiceInstance(String globalCustomerId, String serviceType, String serviceInstanceId){
75                 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustomerId,serviceType,serviceInstanceId);
76                 getAaiClient().createIfNotExists(serviceInstanceURI, Optional.empty());
77         }
78         
79         public Optional<GenericVnf> getVnfInstance(String vnfId){
80                 try{
81                         AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
82                         AAIResultWrapper aaiResponse = getAaiClient().get(vnfURI);
83                         Optional<GenericVnf> vnf = aaiResponse.asBean(GenericVnf.class);
84                         return vnf;
85                 } catch (Exception ex){
86                         return Optional.empty();
87                 }
88         }
89         
90 }