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 handleCbamTerminateResponse(cbamResponse, jobId);
78 cbamMgmr.deleteVnf(vnfInstanceId);
80 NslcmNotifyLCMEventsRequest nslcmNotifyReq = buildNslcmNotifyLCMEventsRequest(cbamResponse);
82 nslcmMgmr.notifyVnf(nslcmNotifyReq, vnfInstanceId);
84 } catch (ClientProtocolException e) {
85 logger.error("TerminateVnfContinueRunnable run error ClientProtocolException", e);
86 } catch (IOException e) {
87 logger.error("TerminateVnfContinueRunnable run error IOException", e);
92 private void handleCbamTerminateResponse(CBAMTerminateVnfResponse cbamResponse, String jobId) {
93 VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.getLong(jobId));
95 jobInfo.setVnfmExecutionId(cbamResponse.getId());
96 if(CommonEnum.OperationStatus.FAILED ==cbamResponse.getStatus()) {
97 jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_ERROR);
99 jobDbMgmr.save(jobInfo);
102 private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() {
103 NslcmGrantVnfRequest request = new NslcmGrantVnfRequest();
105 request.setVnfInstanceId(vnfInstanceId);
106 request.setLifecycleOperation(LifecycleOperation.Instantiate);
107 request.setJobId(jobId);
109 ResourceDefinition resource = getFreeVnfResource();
110 List<ResourceDefinition> resourceList = new ArrayList<ResourceDefinition>();
111 resourceList.add(resource);
112 request.setRemoveResource(resourceList);
117 private ResourceDefinition getFreeVnfResource() {
118 // TODO Auto-generated method stub
122 private NslcmNotifyLCMEventsRequest buildNslcmNotifyLCMEventsRequest(CBAMTerminateVnfResponse cbamResponse) {
123 NslcmNotifyLCMEventsRequest request = new NslcmNotifyLCMEventsRequest();
124 if(CommonEnum.OperationStatus.STARTED == cbamResponse.getStatus())
126 request.setStatus(CommonEnum.status.start);
130 request.setStatus(CommonEnum.status.result);
132 //TODO the following are for the result
133 // request.setAffectedVnfc(affectedVnfc);
134 // request.setAffectedVI(affectedVI);
135 // request.setAffectedVirtualStorage(affectedVirtualStorage);
138 request.setVnfInstanceId(vnfInstanceId);
139 request.setOperation(CommonConstants.NSLCM_OPERATION_TERMINATE);
140 request.setJobId(jobId);
144 private void handleNslcmGrantResponse(NslcmGrantVnfResponse grantResponse) {
145 // TODO Auto-generated method stub