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.CBAMScaleVnfRequest;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse;
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.constant.ScaleType;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AddResource;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.ResourceDefinition;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.beans.factory.annotation.Autowired;
40 public class ScaleVnfContinueRunnable implements Runnable {
41 private static final Logger logger = LoggerFactory.getLogger(ScaleVnfContinueRunnable.class);
44 private CbamMgmrInf cbamMgmr;
46 private NslcmMgmrInf nslcmMgmr;
48 private ScaleVnfRequest driverRequest;
49 private String vnfInstanceId;
53 private VnfmJobExecutionMapper jobDbMgmr;
55 private Driver2CbamRequestConverter requestConverter;
57 public ScaleVnfContinueRunnable(String vnfmId, ScaleVnfRequest 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;
69 private void handleGrant(){
71 NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest();
72 nslcmMgmr.grantVnf(grantRequest);
73 } catch (Exception e) {
74 logger.error("ScaleVnfContinueRunnable --> handleGrant error.", e);
85 private CBAMScaleVnfResponse handleScale() {
86 CBAMScaleVnfResponse cbamResponse = null;
88 CBAMScaleVnfRequest scaleReq = requestConverter.scaleReqconvert(driverRequest);
89 cbamResponse = cbamMgmr.scaleVnf(scaleReq, vnfInstanceId);
90 handleCbamScaleResponse(cbamResponse, jobId);
91 } catch (Exception e) {
92 logger.error("ScaleVnfContinueRunnable --> handleScale error.", e);
98 private void handleCbamScaleResponse(CBAMScaleVnfResponse cbamResponse, String jobId) {
99 VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.parseLong(jobId));
101 jobInfo.setVnfmExecutionId(cbamResponse.getId());
102 if(CommonEnum.OperationStatus.FAILED == cbamResponse.getStatus()) {
103 jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_ERROR);
106 jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_PROCESSING);
108 jobDbMgmr.update(jobInfo);
111 private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() {
112 NslcmGrantVnfRequest request = new NslcmGrantVnfRequest();
114 request.setVnfInstanceId(vnfInstanceId);
115 if(ScaleType.SCALE_OUT == driverRequest.getType()) {
116 request.setLifecycleOperation(LifecycleOperation.Scaleout);
118 request.setLifecycleOperation(LifecycleOperation.Scalein);
120 request.setJobId(jobId);
122 ResourceDefinition resource = getFreeVnfResource();
123 List<ResourceDefinition> resourceList = new ArrayList<ResourceDefinition>();
124 resourceList.add(resource);
125 request.setRemoveResource(resourceList);
130 private ResourceDefinition getFreeVnfResource() {
131 ResourceDefinition def = new ResourceDefinition();
132 def.setVnfInstanceId(vnfInstanceId);
134 List<AddResource> resources = new ArrayList<>();
135 AddResource res = new AddResource();
138 res.setResourceDefinitionId(2);
140 def.setAddResource(resources);
144 public void setDriverRequest(ScaleVnfRequest driverRequest) {
145 this.driverRequest = driverRequest;
148 public void setVnfInstanceId(String vnfInstanceId) {
149 this.vnfInstanceId = vnfInstanceId;
152 public void setJobId(String jobId) {
156 public void setRequestConverter(Driver2CbamRequestConverter requestConverter) {
157 this.requestConverter = requestConverter;