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.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.LifecycleOperation;
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.inf.NslcmMgmrInf;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest;
42 public class TerminateVnfContinueRunnable implements Runnable {
43 private static final Logger logger = LogManager.getLogger("TerminateVnfContinueRunnable");
45 private CbamMgmrInf cbamMgmr;
46 private NslcmMgmrInf nslcmMgmr;
48 private TerminateVnfRequest driverRequest;
49 private String vnfInstanceId;
51 private VnfmJobExecutionRepository jobDbManager;
53 private Driver2CbamRequestConverter requestConverter;
55 public TerminateVnfContinueRunnable(TerminateVnfRequest driverRequest, String vnfInstanceId, String jobId,
56 NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionRepository dbManager)
58 this.driverRequest = driverRequest;
59 this.vnfInstanceId = vnfInstanceId;
60 this.nslcmMgmr = nslcmMgmr;
61 this.cbamMgmr = cbamMgmr;
62 this.requestConverter = requestConverter;
64 this.jobDbManager = dbManager;
69 NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest();
70 NslcmGrantVnfResponse grantResponse = nslcmMgmr.grantVnf(grantRequest);
71 handleNslcmGrantResponse(grantResponse);
73 CBAMTerminateVnfRequest cbamRequest = requestConverter.terminateReqConvert(driverRequest);
74 CBAMTerminateVnfResponse cbamResponse = cbamMgmr.terminateVnf(cbamRequest, vnfInstanceId);
76 cbamMgmr.deleteVnf(vnfInstanceId);
78 NslcmNotifyLCMEventsRequest nslcmNotifyReq = buildNslcmNotifyLCMEventsRequest(cbamResponse);
79 nslcmMgmr.notifyVnf(nslcmNotifyReq, vnfInstanceId);
81 } catch (ClientProtocolException e) {
82 logger.error("TerminateVnfContinueRunnable run error ClientProtocolException", e);
83 } catch (IOException e) {
84 logger.error("TerminateVnfContinueRunnable run error IOException", e);
89 private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() {
90 NslcmGrantVnfRequest request = new NslcmGrantVnfRequest();
92 request.setVnfInstanceId(vnfInstanceId);
93 request.setLifecycleOperation(LifecycleOperation.Instantiate);
94 request.setJobId(jobId);
96 ResourceDefinition resource = getFreeVnfResource();
97 List<ResourceDefinition> resourceList = new ArrayList<ResourceDefinition>();
98 resourceList.add(resource);
99 request.setRemoveResource(resourceList);
104 private ResourceDefinition getFreeVnfResource() {
105 // TODO Auto-generated method stub
109 private NslcmNotifyLCMEventsRequest buildNslcmNotifyLCMEventsRequest(CBAMTerminateVnfResponse cbamResponse) {
110 NslcmNotifyLCMEventsRequest request = new NslcmNotifyLCMEventsRequest();
111 if(CommonEnum.OperationStatus.STARTED == cbamResponse.getStatus())
113 request.setStatus(CommonEnum.status.start);
117 request.setStatus(CommonEnum.status.result);
119 //TODO the following are for the result
120 // request.setAffectedVnfc(affectedVnfc);
121 // request.setAffectedVI(affectedVI);
122 // request.setAffectedVirtualStorage(affectedVirtualStorage);
125 request.setVnfInstanceId(vnfInstanceId);
126 request.setOperation(CommonConstants.NSLCM_OPERATION_TERMINATE);
127 request.setJobId(jobId);
131 private void handleNslcmGrantResponse(NslcmGrantVnfResponse grantResponse) {
132 // TODO Auto-generated method stub