2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor;
19 import java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.List;
23 import org.apache.http.client.ClientProtocolException;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfResponse;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.LifecycleOperation;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmNotifyLCMEventsRequest;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.ResourceDefinition;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.VnfPackageInfo;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
39 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 public class InstantiateVnfContinueRunnable implements Runnable {
45 private static final Logger logger = LoggerFactory.getLogger(InstantiateVnfContinueRunnable.class);
46 private CbamMgmrInf cbamMgmr;
47 private CatalogMgmrInf catalogMgmr;
48 private NslcmMgmrInf nslcmMgmr;
50 private InstantiateVnfRequest driverRequest;
51 private String vnfInstanceId;
54 private VnfmJobExecutionRepository jobDbMgmr;
56 private Driver2CbamRequestConverter requestConverter;
58 public InstantiateVnfContinueRunnable(InstantiateVnfRequest driverRequest, String vnfInstanceId, String jobId,
59 NslcmMgmrInf nslcmMgmr, CatalogMgmrInf catalogMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionRepository dbManager)
61 this.driverRequest = driverRequest;
62 this.vnfInstanceId = vnfInstanceId;
64 this.nslcmMgmr = nslcmMgmr;
65 this.catalogMgmr = catalogMgmr;
66 this.cbamMgmr = cbamMgmr;
67 this.requestConverter = requestConverter;
68 this.jobDbMgmr = dbManager;
73 NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest();
74 NslcmGrantVnfResponse grantResponse = nslcmMgmr.grantVnf(grantRequest);
75 handleNslcmGrantResponse(grantResponse);
77 //step 2: query vnfPackage uri
78 VnfPackageInfo vnfPackageInfo = catalogMgmr.queryVnfPackage(driverRequest.getVnfPackageId());
80 //step 5: instantiate vnf
81 CBAMInstantiateVnfRequest instantiateReq = requestConverter.InstantiateReqConvert(driverRequest, grantResponse, null, null);
82 CBAMInstantiateVnfResponse cbamInstantiateResponse = cbamMgmr.instantiateVnf(instantiateReq, vnfInstanceId);
83 handleCbamInstantiateResponse(cbamInstantiateResponse, jobId);
85 NslcmNotifyLCMEventsRequest nslcmNotifyReq = buildNslcmNotifyLCMEventsRequest(cbamInstantiateResponse);
86 nslcmMgmr.notifyVnf(nslcmNotifyReq, vnfInstanceId);
88 } catch (ClientProtocolException e) {
89 logger.error("InstantiateVnfContinueRunnable run error ClientProtocolException", e);
90 } catch (IOException e) {
91 logger.error("InstantiateVnfContinueRunnable run error IOException", e);
96 private NslcmNotifyLCMEventsRequest buildNslcmNotifyLCMEventsRequest(CBAMInstantiateVnfResponse cbamInstantiateResponse) {
97 NslcmNotifyLCMEventsRequest request = new NslcmNotifyLCMEventsRequest();
98 if(CommonEnum.OperationStatus.STARTED == cbamInstantiateResponse.getStatus())
100 request.setStatus(CommonEnum.status.start);
104 request.setStatus(CommonEnum.status.result);
106 //TODO the following are for the result
107 // request.setAffectedVnfc(affectedVnfc);
108 // request.setAffectedVI(affectedVI);
109 // request.setAffectedVirtualStorage(affectedVirtualStorage);
112 request.setVnfInstanceId(vnfInstanceId);
113 request.setOperation(CommonConstants.NSLCM_OPERATION_INSTANTIATE);
114 request.setJobId(jobId);
118 private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() {
119 NslcmGrantVnfRequest request = new NslcmGrantVnfRequest();
121 request.setVnfInstanceId(vnfInstanceId);
122 request.setLifecycleOperation(LifecycleOperation.Instantiate);
123 request.setJobId(jobId);
125 ResourceDefinition resource = getFreeVnfResource();
126 List<ResourceDefinition> resourceList = new ArrayList<ResourceDefinition>();
127 resourceList.add(resource);
128 request.setAddResource(resourceList);
133 private ResourceDefinition getFreeVnfResource() {
134 // TODO Auto-generated method stub
138 private void handleCbamInstantiateResponse(CBAMInstantiateVnfResponse cbamInstantiateResponse, String jobId) {
139 VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.getLong(jobId));
141 jobInfo.setVnfmExecutionId(cbamInstantiateResponse.getId());
142 jobDbMgmr.save(jobInfo);
145 private void handleNslcmGrantResponse(NslcmGrantVnfResponse grantResponse) {
146 // TODO Auto-generated method stub