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.cbam.bo.CBAMTerminateVnfRequest;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.LifecycleOperation;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmNotifyLCMEventsRequest;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.ResourceDefinition;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
43 public class TerminateVnfContinueRunnable implements Runnable {
44 private static final Logger logger = LoggerFactory.getLogger(TerminateVnfContinueRunnable.class);
46 private CbamMgmrInf cbamMgmr;
47 private NslcmMgmrInf nslcmMgmr;
49 private TerminateVnfRequest driverRequest;
50 private String vnfInstanceId;
52 private VnfmJobExecutionRepository jobDbMgmr;
54 private Driver2CbamRequestConverter requestConverter;
56 public TerminateVnfContinueRunnable(TerminateVnfRequest driverRequest, String vnfInstanceId, String jobId,
57 NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionRepository dbManager)
59 this.driverRequest = driverRequest;
60 this.vnfInstanceId = vnfInstanceId;
61 this.nslcmMgmr = nslcmMgmr;
62 this.cbamMgmr = cbamMgmr;
63 this.requestConverter = requestConverter;
65 this.jobDbMgmr = dbManager;
70 NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest();
71 NslcmGrantVnfResponse grantResponse = nslcmMgmr.grantVnf(grantRequest);
72 handleNslcmGrantResponse(grantResponse);
74 CBAMTerminateVnfRequest cbamRequest = requestConverter.terminateReqConvert(driverRequest);
75 CBAMTerminateVnfResponse cbamResponse = cbamMgmr.terminateVnf(cbamRequest, vnfInstanceId);
76 handleCbamInstantiateResponse(cbamResponse, jobId);
78 cbamMgmr.deleteVnf(vnfInstanceId);
80 NslcmNotifyLCMEventsRequest nslcmNotifyReq = buildNslcmNotifyLCMEventsRequest(cbamResponse);
81 nslcmMgmr.notifyVnf(nslcmNotifyReq, vnfInstanceId);
83 } catch (ClientProtocolException e) {
84 logger.error("TerminateVnfContinueRunnable run error ClientProtocolException", e);
85 } catch (IOException e) {
86 logger.error("TerminateVnfContinueRunnable run error IOException", e);
91 private void handleCbamInstantiateResponse(CBAMTerminateVnfResponse cbamResponse, String jobId) {
92 VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.getLong(jobId));
94 jobInfo.setVnfmExecutionId(cbamResponse.getId());
95 jobDbMgmr.save(jobInfo);
98 private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() {
99 NslcmGrantVnfRequest request = new NslcmGrantVnfRequest();
101 request.setVnfInstanceId(vnfInstanceId);
102 request.setLifecycleOperation(LifecycleOperation.Instantiate);
103 request.setJobId(jobId);
105 ResourceDefinition resource = getFreeVnfResource();
106 List<ResourceDefinition> resourceList = new ArrayList<ResourceDefinition>();
107 resourceList.add(resource);
108 request.setRemoveResource(resourceList);
113 private ResourceDefinition getFreeVnfResource() {
114 // TODO Auto-generated method stub
118 private NslcmNotifyLCMEventsRequest buildNslcmNotifyLCMEventsRequest(CBAMTerminateVnfResponse cbamResponse) {
119 NslcmNotifyLCMEventsRequest request = new NslcmNotifyLCMEventsRequest();
120 if(CommonEnum.OperationStatus.STARTED == cbamResponse.getStatus())
122 request.setStatus(CommonEnum.status.start);
126 request.setStatus(CommonEnum.status.result);
128 //TODO the following are for the result
129 // request.setAffectedVnfc(affectedVnfc);
130 // request.setAffectedVI(affectedVI);
131 // request.setAffectedVirtualStorage(affectedVirtualStorage);
134 request.setVnfInstanceId(vnfInstanceId);
135 request.setOperation(CommonConstants.NSLCM_OPERATION_TERMINATE);
136 request.setJobId(jobId);
140 private void handleNslcmGrantResponse(NslcmGrantVnfResponse grantResponse) {
141 // TODO Auto-generated method stub