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;
51 private String vnfmId;
52 private ScaleType type;
54 private VnfmJobExecutionMapper jobDbMgmr;
56 private Driver2CbamRequestConverter requestConverter;
58 public ScaleVnfContinueRunnable(String vnfmId, ScaleVnfRequest driverRequest, String vnfInstanceId, String jobId,
59 NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper dbManager)
61 this.driverRequest = driverRequest;
62 this.vnfInstanceId = vnfInstanceId;
63 this.nslcmMgmr = nslcmMgmr;
64 this.cbamMgmr = cbamMgmr;
65 this.requestConverter = requestConverter;
67 this.jobDbMgmr = dbManager;
71 private void handleGrant(){
73 NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest();
74 nslcmMgmr.grantVnf(grantRequest);
75 } catch (Exception e) {
76 logger.error("ScaleVnfContinueRunnable --> handleGrant error.", e);
87 private CBAMScaleVnfResponse handleScale() {
88 CBAMScaleVnfResponse cbamResponse = null;
90 CBAMScaleVnfRequest scaleReq = requestConverter.scaleReqconvert(driverRequest);
91 cbamResponse = cbamMgmr.scaleVnf(scaleReq, vnfInstanceId);
92 handleCbamScaleResponse(cbamResponse, jobId);
93 } catch (Exception e) {
94 logger.error("ScaleVnfContinueRunnable --> handleScale error.", e);
100 private void handleCbamScaleResponse(CBAMScaleVnfResponse cbamResponse, String jobId) {
101 VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.parseLong(jobId));
103 jobInfo.setVnfmExecutionId(cbamResponse.getId());
104 if(CommonEnum.OperationStatus.FAILED == cbamResponse.getStatus()) {
105 jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_ERROR);
108 jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_PROCESSING);
110 jobDbMgmr.update(jobInfo);
113 private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() {
114 NslcmGrantVnfRequest request = new NslcmGrantVnfRequest();
116 request.setVnfInstanceId(vnfInstanceId);
117 if(type.equals(ScaleType.SCALE_OUT)) {
118 request.setLifecycleOperation(LifecycleOperation.Scaleout);
120 request.setLifecycleOperation(LifecycleOperation.Scalein);
122 request.setJobId(jobId);
124 ResourceDefinition resource = getFreeVnfResource();
125 List<ResourceDefinition> resourceList = new ArrayList<ResourceDefinition>();
126 resourceList.add(resource);
127 request.setRemoveResource(resourceList);
132 private ResourceDefinition getFreeVnfResource() {
133 ResourceDefinition def = new ResourceDefinition();
134 def.setVnfInstanceId(vnfInstanceId);
136 List<AddResource> resources = new ArrayList<>();
137 AddResource res = new AddResource();
140 res.setResourceDefinitionId(2);
142 def.setAddResource(resources);
146 public void setDriverRequest(ScaleVnfRequest driverRequest) {
147 this.driverRequest = driverRequest;
150 public void setVnfInstanceId(String vnfInstanceId) {
151 this.vnfInstanceId = vnfInstanceId;
154 public void setJobId(String jobId) {
158 public void setVnfmId(String vnfmId) {
159 this.vnfmId = vnfmId;
162 public void setType(ScaleType type) {
166 public void setRequestConverter(Driver2CbamRequestConverter requestConverter) {
167 this.requestConverter = requestConverter;