a3df22a840b7f85eb7f8aca2c560831286cec983
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / orchestration / AAIPnfResources.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2020 Nokia 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.client.orchestration;
22
23 import java.util.Optional;
24 import org.onap.so.bpmn.common.InjectionHelper;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
27 import org.onap.aaiclient.client.aai.AAIObjectType;
28 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
29 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
30 import org.onap.so.client.aai.mapper.AAIObjectMapper;
31 import org.onap.so.db.catalog.beans.OrchestrationStatus;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Component;
34
35 @Component
36 public class AAIPnfResources {
37
38     @Autowired
39     private InjectionHelper injectionHelper;
40
41     @Autowired
42     private AAIObjectMapper aaiObjectMapper;
43
44     public void createPnfAndConnectServiceInstance(Pnf pnf, ServiceInstance serviceInstance) {
45         AAIResourceUri pnfURI = AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnf.getPnfName());
46         pnf.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
47         AAIResourceUri serviceInstanceURI =
48                 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
49         injectionHelper.getAaiClient().createIfNotExists(pnfURI, Optional.of(aaiObjectMapper.mapPnf(pnf)))
50                 .connect(pnfURI, serviceInstanceURI);
51     }
52
53     public void updateOrchestrationStatusPnf(Pnf pnf, OrchestrationStatus orchestrationStatus) {
54         AAIResourceUri pnfURI = AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnf.getPnfName());
55
56         Pnf pnfCopy = pnf.shallowCopyId();
57
58         pnf.setOrchestrationStatus(orchestrationStatus);
59         pnfCopy.setOrchestrationStatus(orchestrationStatus);
60         injectionHelper.getAaiClient().update(pnfURI, aaiObjectMapper.mapPnf(pnfCopy));
61     }
62 }