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.util.ArrayList;
20 import java.util.List;
22 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.LifecycleOperation;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AddResource;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.ResourceDefinition;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Autowired;
39 public class HealVnfContinueRunnable implements Runnable {
40 private static final Logger logger = LoggerFactory.getLogger(HealVnfContinueRunnable.class);
43 private CbamMgmrInf cbamMgmr;
45 private NslcmMgmrInf nslcmMgmr;
47 private HealVnfRequest driverRequest;
48 private String vnfInstanceId;
50 private String vnfmId;
52 private VnfmJobExecutionMapper jobDbMgmr;
54 private Driver2CbamRequestConverter requestConverter;
57 public HealVnfContinueRunnable(String inVnfmId, HealVnfRequest driverRequest, String vnfInstanceId, String jobId,
58 NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper dbManager)
60 this.driverRequest = driverRequest;
61 this.vnfInstanceId = vnfInstanceId;
62 this.nslcmMgmr = nslcmMgmr;
63 this.cbamMgmr = cbamMgmr;
64 this.requestConverter = requestConverter;
66 this.jobDbMgmr = dbManager;
67 this.vnfmId = inVnfmId;
70 private void handleGrant(){
72 NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest();
73 nslcmMgmr.grantVnf(grantRequest);
74 } catch (Exception e) {
75 logger.error("HealVnfContinueRunnable --> handleGrant error.", e);
86 private CBAMHealVnfResponse handleHeal() {
87 CBAMHealVnfResponse cbamResponse = null;
89 CBAMHealVnfRequest modifyReq = requestConverter.healReqConvert();
90 cbamResponse = cbamMgmr.healVnf(modifyReq, vnfInstanceId);
91 handleCbamHealResponse(cbamResponse, jobId);
92 } catch (Exception e) {
93 logger.error("HealVnfContinueRunnable --> handleHeal error.", e);
99 private void handleCbamHealResponse(CBAMHealVnfResponse cbamResponse, String jobId) {
100 VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.parseLong(jobId));
102 jobInfo.setVnfmExecutionId(cbamResponse.getId());
103 if(CommonEnum.OperationStatus.FAILED == cbamResponse.getStatus()) {
104 jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_ERROR);
107 jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_PROCESSING);
109 jobDbMgmr.update(jobInfo);
112 private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() {
113 NslcmGrantVnfRequest request = new NslcmGrantVnfRequest();
115 request.setVnfInstanceId(vnfInstanceId);
116 request.setLifecycleOperation(LifecycleOperation.Heal);
117 request.setJobId(jobId);
119 ResourceDefinition resource = getFreeVnfResource();
120 List<ResourceDefinition> resourceList = new ArrayList<>();
121 resourceList.add(resource);
122 request.setRemoveResource(resourceList);
127 private ResourceDefinition getFreeVnfResource() {
128 ResourceDefinition def = new ResourceDefinition();
129 def.setVnfInstanceId(vnfInstanceId);
131 List<AddResource> resources = new ArrayList<>();
132 AddResource res = new AddResource();
135 res.setResourceDefinitionId(2);
137 def.setAddResource(resources);
141 public void setDriverRequest(HealVnfRequest driverRequest) {
142 this.driverRequest = driverRequest;
145 public void setVnfInstanceId(String vnfInstanceId) {
146 this.vnfInstanceId = vnfInstanceId;
149 public void setJobId(String jobId) {
153 public void setRequestConverter(Driver2CbamRequestConverter requestConverter) {
154 this.requestConverter = requestConverter;
157 public void setVnfmId(String inVnfmId) {
158 this.vnfmId = inVnfmId;