diff options
author | yufei_zhou <yufei.zhou@nokia-sbell.com> | 2018-02-12 15:17:27 +0800 |
---|---|---|
committer | yufei_zhou <yufei.zhou@nokia-sbell.com> | 2018-02-12 15:52:49 +0800 |
commit | e29ba7011fd255cdd9780b1d5859b1f1d5c981e5 (patch) | |
tree | 436cbda610823050d3f664e3eb5d1870c2b4ac9f /nokia | |
parent | 834ea30c777cbb481e24200f168128e4885fd7bd (diff) |
Improve unit-test coverage
Change-Id: I734ed2d92e8ba00f0fb9ee6085835472352cc5e6
Issue-ID: VFC-724
Signed-off-by: yufei_zhou <yufei.zhou@nokia-sbell.com>
Diffstat (limited to 'nokia')
54 files changed, 2659 insertions, 559 deletions
diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/pom.xml b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/pom.xml index 410c2e97..08685b46 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/pom.xml +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/pom.xml @@ -41,10 +41,12 @@ </properties> <dependencies> + <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> + --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> @@ -81,16 +83,18 @@ <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> +<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> - <groupId>org.apache.tomcat.embed</groupId> - <artifactId>tomcat-embed-jasper</artifactId> - <scope>provided</scope> - </dependency> + <groupId>org.apache.tomcat.embed</groupId> + <artifactId>tomcat-embed-jasper</artifactId> + <scope>provided</scope> + </dependency> + --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> @@ -137,6 +141,12 @@ <artifactId>zt-zip</artifactId> <version>1.12</version> </dependency> + + <dependency> + <groupId>org.mybatis.spring.boot</groupId> + <artifactId>mybatis-spring-boot-starter</artifactId> + <version>1.3.1</version> + </dependency> <dependency> <groupId>ca.juliusdavies</groupId> diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/VfcadaptorApplication.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/VfcadaptorApplication.java index c93b107b..d88b5d7e 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/VfcadaptorApplication.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/VfcadaptorApplication.java @@ -16,6 +16,8 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @@ -28,8 +30,9 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @ComponentScan @SuppressWarnings(value="all") public class VfcadaptorApplication { + private static final Logger logger = LoggerFactory.getLogger(VfcadaptorApplication.class); - public final static void main(String[] args) { + public static void main(String[] args) { SpringApplication.run(VfcadaptorApplication.class, args); } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java index 7bb18efd..c153095b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java @@ -15,9 +15,6 @@ */ package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; -import java.util.ArrayList; -import java.util.List; - import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse; @@ -25,10 +22,12 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.OperationExecution; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.OperationExecution.OperationType; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.OperStatusVnfResponse; @@ -36,15 +35,19 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.QueryVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.entity.ResponseDescriptor; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.entity.ResponseHistoryList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class Cbam2DriverResponseConverter { + private static final Logger logger = LoggerFactory.getLogger(Cbam2DriverResponseConverter.class); + @Autowired + private VnfmJobExecutionMapper jobDbManager; @Autowired - private VnfmJobExecutionRepository jobDbManager; + private AdaptorEnv adaptorEnv; public InstantiateVnfResponse createRspConvert(CBAMCreateVnfResponse cbamResponse, Long jobId) { @@ -61,7 +64,8 @@ public class Cbam2DriverResponseConverter { jobInfo.setVnfmInterfceName(CommonConstants.NSLCM_OPERATION_TERMINATE); jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_START); - VnfmJobExecutionInfo jobInfo1 = (VnfmJobExecutionInfo) jobDbManager.save(jobInfo); + jobDbManager.insert(jobInfo); + VnfmJobExecutionInfo jobInfo1 = (VnfmJobExecutionInfo) jobDbManager.findNewestJobInfo(); Long jobId = jobInfo1.getJobId(); TerminateVnfResponse response = new TerminateVnfResponse(); response.setJobId(jobId.longValue() + ""); @@ -82,51 +86,37 @@ public class Cbam2DriverResponseConverter { return vnf; } - public OperStatusVnfResponse operRspConvert(OperationExecution oper) { - + public OperStatusVnfResponse operRspConvert(OperationExecution oper, String jobId) { OperStatusVnfResponse response = new OperStatusVnfResponse(); - ResponseDescriptor er = new ResponseDescriptor(); - if (oper.getStatus() == CommonEnum.OperationStatus.STARTED ) { + if (oper.getStatus() == CommonEnum.OperationStatus.STARTED) { er.setStatusDescription("Vim is processing"); er.setStatus("started"); - int progress; - if(OperationType.INSTANTIATE == oper.getOperationType()) - { - progress = OperateTaskProgress.getInstantiateProgress(); - } else { - progress = OperateTaskProgress.getTerminateProgress(); - } - + int progress = calculateProgress(oper, jobId); + er.setProgress("" + progress); - er.setResponseId("" + + progress); + er.setResponseId("" + +progress); } else if (oper.getStatus() == CommonEnum.OperationStatus.FINISHED) { er.setStatus("finished"); er.setProgress("100"); er.setResponseId("100"); - - } else if (oper.getStatus() == CommonEnum.OperationStatus.OTHER) { + + } else if (oper.getStatus() == CommonEnum.OperationStatus.OTHER) { er.setStatus("processing"); er.setStatusDescription("Vim is processing"); - - int progress; - if(OperationType.INSTANTIATE == oper.getOperationType()) - { - progress = OperateTaskProgress.getInstantiateProgress(); - } else { - progress = OperateTaskProgress.getTerminateProgress(); - } - + + int progress = calculateProgress(oper, jobId); + er.setProgress("" + progress); - er.setResponseId("" + + progress); - + er.setResponseId("" + +progress); + } else { - er.setStatus("error"); + er.setStatus("error"); er.setStatus("finished"); er.setProgress("100"); er.setResponseId("100"); } - + er.setErrorCode("null"); response.setResponseDescriptor(er); @@ -139,9 +129,47 @@ public class Cbam2DriverResponseConverter { return response; } - public ScaleVnfResponse scaleRspConvert(CBAMScaleVnfResponse cbamResponse) { + public ScaleVnfResponse scaleRspConvert(CBAMScaleVnfResponse cbamResponse,ScaleType type) { + VnfmJobExecutionInfo jobInfo = new VnfmJobExecutionInfo(); + jobInfo.setVnfInstanceId(cbamResponse.getId()); + if (type.equals(ScaleType.SCALE_OUT)) { + jobInfo.setVnfmInterfceName(CommonConstants.NSLCM_OPERATION_SCALE_OUT); + } else { + jobInfo.setVnfmInterfceName(CommonConstants.NSLCM_OPERATION_SCALE_IN); + } + jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_START); + + jobDbManager.insert(jobInfo); + VnfmJobExecutionInfo jobInfo1 = (VnfmJobExecutionInfo) jobDbManager.findNewestJobInfo(); + Long jobId = jobInfo1.getJobId(); ScaleVnfResponse response = new ScaleVnfResponse(); - response.setJobId("1"); + + response.setJobId(jobId.longValue() + ""); return response; } + + public int calculateProgress(OperationExecution oper, String jobId) { + long nowTime = System.currentTimeMillis(); + VnfmJobExecutionInfo jobInfo = jobDbManager.findOne(Long.parseLong(jobId)); + int initialProgress = adaptorEnv.getInitialProgress(); + + if (OperationType.INSTANTIATE == oper.getOperationType()) { + double instantiateProgress = (nowTime - jobInfo.getOperateStartTime()) + / adaptorEnv.getInstantiateTimeInterval(); + initialProgress = (int) (instantiateProgress + initialProgress); + } else if (OperationType.TERMINATE == oper.getOperationType()) { + double terminateProgress = (nowTime - jobInfo.getOperateStartTime()) + / adaptorEnv.getTerminateTimeInterval(); + initialProgress = (int) (terminateProgress + initialProgress); + } else { + initialProgress = 0; + } + return initialProgress; + + } + + public void setAdaptorEnv(AdaptorEnv adaptorEnv) { + this.adaptorEnv = adaptorEnv; + } + } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/HealVnfContinueRunnable.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/HealVnfContinueRunnable.java new file mode 100644 index 00000000..9338a056 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/HealVnfContinueRunnable.java @@ -0,0 +1,160 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.LifecycleOperation; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AddResource; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.ResourceDefinition; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +public class HealVnfContinueRunnable implements Runnable { + private static final Logger logger = LoggerFactory.getLogger(HealVnfContinueRunnable.class); + + @Autowired + private CbamMgmrInf cbamMgmr; + @Autowired + private NslcmMgmrInf nslcmMgmr; + + private HealVnfRequest driverRequest; + private String vnfInstanceId; + private String jobId; + private String vnfmId; + @Autowired + private VnfmJobExecutionMapper jobDbMgmr; + + private Driver2CbamRequestConverter requestConverter; + + + public HealVnfContinueRunnable(String vnfmId, HealVnfRequest driverRequest, String vnfInstanceId, String jobId, + NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper dbManager) + { + this.driverRequest = driverRequest; + this.vnfInstanceId = vnfInstanceId; + this.nslcmMgmr = nslcmMgmr; + this.cbamMgmr = cbamMgmr; + this.requestConverter = requestConverter; + this.jobId = jobId; + this.jobDbMgmr = dbManager; + this.vnfmId = vnfmId; + } + + private void handleGrant(){ + try { + NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest(); + nslcmMgmr.grantVnf(grantRequest); + } catch (Exception e) { + logger.error("HealVnfContinueRunnable --> handleGrant error.", e); + } + } + + public void run() { + handleGrant(); + handleHeal(); + } + + + + private CBAMHealVnfResponse handleHeal() { + CBAMHealVnfResponse cbamResponse = null; + try { + CBAMHealVnfRequest modifyReq = requestConverter.healReqConvert(driverRequest); + cbamResponse = cbamMgmr.healVnf(modifyReq, vnfInstanceId); + handleCbamHealResponse(cbamResponse, jobId); + } catch (Exception e) { + logger.error("HealVnfContinueRunnable --> handleHeal error.", e); + } + + return cbamResponse; + } + + private void handleCbamHealResponse(CBAMHealVnfResponse cbamResponse, String jobId) { + VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.parseLong(jobId)); + + jobInfo.setVnfmExecutionId(cbamResponse.getId()); + if(CommonEnum.OperationStatus.FAILED == cbamResponse.getStatus()) { + jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_ERROR); + } + else { + jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_PROCESSING); + } + jobDbMgmr.update(jobInfo); + } + + private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() { + NslcmGrantVnfRequest request = new NslcmGrantVnfRequest(); + + request.setVnfInstanceId(vnfInstanceId); + request.setLifecycleOperation(LifecycleOperation.Heal); + request.setJobId(jobId); + + ResourceDefinition resource = getFreeVnfResource(); + List<ResourceDefinition> resourceList = new ArrayList<ResourceDefinition>(); + resourceList.add(resource); + request.setRemoveResource(resourceList); + + return request; + } + + private ResourceDefinition getFreeVnfResource() { + ResourceDefinition def = new ResourceDefinition(); + def.setVnfInstanceId(vnfInstanceId); + def.setVimId("001"); + List<AddResource> resources = new ArrayList<>(); + AddResource res = new AddResource(); + res.setVdu("1"); + res.setType("vdu"); + res.setResourceDefinitionId(2); + resources.add(res); + def.setAddResource(resources); + return def; + } + + public void setDriverRequest(HealVnfRequest driverRequest) { + this.driverRequest = driverRequest; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public void setRequestConverter(Driver2CbamRequestConverter requestConverter) { + this.requestConverter = requestConverter; + } + + public void setVnfmId(String vnfmId) { + this.vnfmId = vnfmId; + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnable.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnable.java index b3c8bfe1..07c15c0e 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnable.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnable.java @@ -35,7 +35,8 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.LifecycleOperation; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfcResourceInfoMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorImpl; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmNotifyLCMEventsRequest; @@ -46,14 +47,18 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import com.google.gson.Gson; public class InstantiateVnfContinueRunnable implements Runnable { private static final Logger logger = LoggerFactory.getLogger(InstantiateVnfContinueRunnable.class); + @Autowired private CbamMgmrInf cbamMgmr; + @Autowired private CatalogMgmrInf catalogMgmr; + @Autowired private NslcmMgmrInf nslcmMgmr; private InstantiateVnfRequest driverRequest; @@ -61,14 +66,18 @@ public class InstantiateVnfContinueRunnable implements Runnable { private String jobId; private String vnfmId; - private VnfmJobExecutionRepository jobDbMgmr; +// private VnfmJobExecutionRepository jobDbMgmr; + @Autowired + private VnfmJobExecutionMapper jobDbMgmr; + @Autowired + private VnfcResourceInfoMapper vnfcDbMgmr; private Driver2CbamRequestConverter requestConverter; private Gson gson = new Gson(); public InstantiateVnfContinueRunnable(String vnfmId, InstantiateVnfRequest driverRequest, String vnfInstanceId, String jobId, - NslcmMgmrInf nslcmMgmr, CatalogMgmrInf catalogMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionRepository dbManager) + NslcmMgmrInf nslcmMgmr, CatalogMgmrInf catalogMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper dbManager, VnfcResourceInfoMapper vnfcDbMgmr) { this.driverRequest = driverRequest; this.vnfInstanceId = vnfInstanceId; @@ -79,6 +88,7 @@ public class InstantiateVnfContinueRunnable implements Runnable { this.requestConverter = requestConverter; this.jobDbMgmr = dbManager; this.vnfmId = vnfmId; + this.vnfcDbMgmr = vnfcDbMgmr; } public void run() { @@ -109,7 +119,6 @@ public class InstantiateVnfContinueRunnable implements Runnable { { instantiateFinished = true; handleCbamInstantiateResponse(exeResponse, jobId); - OperateTaskProgress.stopInstantiateTimerTask(); if (exeResponse.getStatus() == CommonEnum.OperationStatus.FINISHED) { @@ -132,7 +141,7 @@ public class InstantiateVnfContinueRunnable implements Runnable { logger.info("Start to notify LCM the instantiation result"); NslcmNotifyLCMEventsRequest nslcmNotifyReq = buildNslcmNotifyLCMEventsRequest(vnfcResources); - OperateTaskProgress.setAffectedVnfc(nslcmNotifyReq.getAffectedVnfc()); +// OperateTaskProgress.setAffectedVnfc(nslcmNotifyReq.getAffectedVnfc()); nslcmMgmr.notifyVnf(nslcmNotifyReq, vnfmId, vnfInstanceId); logger.info("End to notify LCM the instantiation result"); @@ -236,6 +245,8 @@ public class InstantiateVnfContinueRunnable implements Runnable { vnfc.setVmid(resource.getComputeResource().getResourceId()); vnfcs.add(vnfc); + + vnfcDbMgmr.insert(vnfc); } } return vnfcs; @@ -274,6 +285,7 @@ public class InstantiateVnfContinueRunnable implements Runnable { VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.parseLong(jobId)); jobInfo.setVnfmExecutionId(cbamInstantiateResponse.getId()); + long nowTime = System.currentTimeMillis(); if(CommonEnum.OperationStatus.FAILED == cbamInstantiateResponse.getStatus()){ jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_ERROR); // jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_FINISH); @@ -281,12 +293,34 @@ public class InstantiateVnfContinueRunnable implements Runnable { jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_PROCESSING); } else if(CommonEnum.OperationStatus.FINISHED == cbamInstantiateResponse.getStatus()){ jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_FINISH); + jobInfo.setOperateEndTime(nowTime); + } else{ jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_START); } - jobDbMgmr.save(jobInfo); + jobDbMgmr.update(jobInfo); + } + + public void setDriverRequest(InstantiateVnfRequest driverRequest) { + this.driverRequest = driverRequest; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public void setVnfmId(String vnfmId) { + this.vnfmId = vnfmId; + } + + public void setRequestConverter(Driver2CbamRequestConverter requestConverter) { + this.requestConverter = requestConverter; } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/OperateTaskProgress.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/OperateTaskProgress.java deleted file mode 100644 index 37e38e63..00000000 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/OperateTaskProgress.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2016-2017, Nokia Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; - -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.atomic.AtomicInteger; - -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AffectedVnfc; - -public class OperateTaskProgress { - private static AtomicInteger instantiate_progress = new AtomicInteger(10); - private static AtomicInteger terminate_progress = new AtomicInteger(20); - - private static Timer instantiateTimer; - private static Timer terminateTimer; - - private static List<AffectedVnfc> affectedVnfc; - - public static int getInstantiateProgress() { - return instantiate_progress.intValue(); - } - - public static int getTerminateProgress() { - return terminate_progress.intValue(); - } - - public static void incrementInstantiateProgress() { - instantiate_progress.incrementAndGet(); - } - - public static void incrementTerminateProgress() { - terminate_progress.incrementAndGet(); - } - - public static void startInstantiateTimerTask() { - instantiateTimer = new Timer(); - instantiate_progress.set(10); - instantiateTimer.schedule(new TimerTask() { - - @Override - public void run() { - if(instantiate_progress.intValue() < 96) { - instantiate_progress.incrementAndGet(); - } - } - - }, 1000, 60000); - } - - public static void startTerminateTimerTask() { - terminateTimer = new Timer(); - terminate_progress.set(20); - terminateTimer.schedule(new TimerTask() { - - @Override - public void run() { - if(terminate_progress.intValue() < 96) { - terminate_progress.incrementAndGet(); - } - } - - }, 1000, 8000); - } - - public static void stopTerminateTimerTask() { - terminateTimer.cancel(); - terminate_progress.set(100); - } - - public static void stopInstantiateTimerTask() { - instantiateTimer.cancel(); - instantiate_progress.set(100); - } - - public static List<AffectedVnfc> getAffectedVnfc() { - return affectedVnfc; - } - - public static void setAffectedVnfc(List<AffectedVnfc> affectedVnfc) { - OperateTaskProgress.affectedVnfc = affectedVnfc; - } -} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/ScaleVnfContinueRunnable.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/ScaleVnfContinueRunnable.java new file mode 100644 index 00000000..1f6caf83 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/ScaleVnfContinueRunnable.java @@ -0,0 +1,170 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.LifecycleOperation; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AddResource; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.ResourceDefinition; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +public class ScaleVnfContinueRunnable implements Runnable { + private static final Logger logger = LoggerFactory.getLogger(ScaleVnfContinueRunnable.class); + + @Autowired + private CbamMgmrInf cbamMgmr; + @Autowired + private NslcmMgmrInf nslcmMgmr; + + private ScaleVnfRequest driverRequest; + private String vnfInstanceId; + private String jobId; + private String vnfmId; + private ScaleType type; + @Autowired + private VnfmJobExecutionMapper jobDbMgmr; + + private Driver2CbamRequestConverter requestConverter; + + public ScaleVnfContinueRunnable(String vnfmId, ScaleVnfRequest driverRequest, String vnfInstanceId, String jobId, + NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper dbManager) + { + this.driverRequest = driverRequest; + this.vnfInstanceId = vnfInstanceId; + this.nslcmMgmr = nslcmMgmr; + this.cbamMgmr = cbamMgmr; + this.requestConverter = requestConverter; + this.jobId = jobId; + this.jobDbMgmr = dbManager; + this.vnfmId = vnfmId; + } + + private void handleGrant(){ + try { + NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest(); + nslcmMgmr.grantVnf(grantRequest); + } catch (Exception e) { + logger.error("ScaleVnfContinueRunnable --> handleGrant error.", e); + } + } + + public void run() { + handleGrant(); + handleScale(); + } + + + + private CBAMScaleVnfResponse handleScale() { + CBAMScaleVnfResponse cbamResponse = null; + try { + CBAMScaleVnfRequest scaleReq = requestConverter.scaleReqconvert(driverRequest); + cbamResponse = cbamMgmr.scaleVnf(scaleReq, vnfInstanceId); + handleCbamScaleResponse(cbamResponse, jobId); + } catch (Exception e) { + logger.error("ScaleVnfContinueRunnable --> handleScale error.", e); + } + + return cbamResponse; + } + + private void handleCbamScaleResponse(CBAMScaleVnfResponse cbamResponse, String jobId) { + VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.parseLong(jobId)); + + jobInfo.setVnfmExecutionId(cbamResponse.getId()); + if(CommonEnum.OperationStatus.FAILED == cbamResponse.getStatus()) { + jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_ERROR); + } + else { + jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_PROCESSING); + } + jobDbMgmr.update(jobInfo); + } + + private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() { + NslcmGrantVnfRequest request = new NslcmGrantVnfRequest(); + + request.setVnfInstanceId(vnfInstanceId); + if(type.equals(ScaleType.SCALE_OUT)) { + request.setLifecycleOperation(LifecycleOperation.Scaleout); + }else { + request.setLifecycleOperation(LifecycleOperation.Scalein); + } + request.setJobId(jobId); + + ResourceDefinition resource = getFreeVnfResource(); + List<ResourceDefinition> resourceList = new ArrayList<ResourceDefinition>(); + resourceList.add(resource); + request.setRemoveResource(resourceList); + + return request; + } + + private ResourceDefinition getFreeVnfResource() { + ResourceDefinition def = new ResourceDefinition(); + def.setVnfInstanceId(vnfInstanceId); + def.setVimId("001"); + List<AddResource> resources = new ArrayList<>(); + AddResource res = new AddResource(); + res.setVdu("1"); + res.setType("vdu"); + res.setResourceDefinitionId(2); + resources.add(res); + def.setAddResource(resources); + return def; + } + + public void setDriverRequest(ScaleVnfRequest driverRequest) { + this.driverRequest = driverRequest; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public void setVnfmId(String vnfmId) { + this.vnfmId = vnfmId; + } + + public void setType(ScaleType type) { + this.type = type; + } + + public void setRequestConverter(Driver2CbamRequestConverter requestConverter) { + this.requestConverter = requestConverter; + } + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/TerminateVnfContinueRunnable.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/TerminateVnfContinueRunnable.java index 13e4e3c6..e152c4b5 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/TerminateVnfContinueRunnable.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/TerminateVnfContinueRunnable.java @@ -27,7 +27,8 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.LifecycleOperation; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfcResourceInfoMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmNotifyLCMEventsRequest; @@ -38,23 +39,29 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; public class TerminateVnfContinueRunnable implements Runnable { private static final Logger logger = LoggerFactory.getLogger(TerminateVnfContinueRunnable.class); + @Autowired private CbamMgmrInf cbamMgmr; + @Autowired private NslcmMgmrInf nslcmMgmr; private TerminateVnfRequest driverRequest; private String vnfInstanceId; private String jobId; private String vnfmId; - private VnfmJobExecutionRepository jobDbMgmr; + @Autowired + private VnfmJobExecutionMapper jobDbMgmr; + @Autowired + private VnfcResourceInfoMapper vnfcDbMgmr; private Driver2CbamRequestConverter requestConverter; public TerminateVnfContinueRunnable(String vnfmId, TerminateVnfRequest driverRequest, String vnfInstanceId, String jobId, - NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionRepository dbManager) + NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper dbManager, VnfcResourceInfoMapper vnfcDbMgmr) { this.driverRequest = driverRequest; this.vnfInstanceId = vnfInstanceId; @@ -64,6 +71,7 @@ public class TerminateVnfContinueRunnable implements Runnable { this.jobId = jobId; this.jobDbMgmr = dbManager; this.vnfmId = vnfmId; + this.vnfcDbMgmr = vnfcDbMgmr; } private void handleGrant(){ @@ -104,11 +112,11 @@ public class TerminateVnfContinueRunnable implements Runnable { } private void prepareDelete(String jobId) { - OperateTaskProgress.stopTerminateTimerTask(); - + long nowTime = System.currentTimeMillis(); VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.parseLong(jobId)); jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_FINISH); - jobDbMgmr.save(jobInfo); + jobInfo.setOperateEndTime(nowTime); + jobDbMgmr.update(jobInfo); try { NslcmNotifyLCMEventsRequest nslcmNotifyReq = buildNslcmNotifyLCMEventsRequest(); @@ -141,7 +149,7 @@ public class TerminateVnfContinueRunnable implements Runnable { else { jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_PROCESSING); } - jobDbMgmr.save(jobInfo); + jobDbMgmr.update(jobInfo); } private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() { @@ -176,8 +184,8 @@ public class TerminateVnfContinueRunnable implements Runnable { private NslcmNotifyLCMEventsRequest buildNslcmNotifyLCMEventsRequest() { NslcmNotifyLCMEventsRequest request = new NslcmNotifyLCMEventsRequest(); request.setStatus(CommonEnum.status.result); - - List<AffectedVnfc> vnfcs = modifyResourceTypeAsRemove(OperateTaskProgress.getAffectedVnfc()); + List<AffectedVnfc> vnfcsFromDb = vnfcDbMgmr.getAllByInstanceId(vnfInstanceId); + List<AffectedVnfc> vnfcs = modifyResourceTypeAsRemove(vnfcsFromDb); request.setAffectedVnfc(vnfcs); request.setVnfInstanceId(vnfInstanceId); @@ -202,8 +210,23 @@ public class TerminateVnfContinueRunnable implements Runnable { return vnfcs; } - private void handleNslcmGrantResponse(NslcmGrantVnfResponse grantResponse) { - // TODO Auto-generated method stub - + public void setDriverRequest(TerminateVnfRequest driverRequest) { + this.driverRequest = driverRequest; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public void setVnfmId(String vnfmId) { + this.vnfmId = vnfmId; + } + + public void setRequestConverter(Driver2CbamRequestConverter requestConverter) { + this.requestConverter = requestConverter; } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java index dac64b7b..251c4638 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java @@ -26,19 +26,17 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.OperationExecution; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.OperationExecution.OperationType; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfcResourceInfoMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; @@ -60,80 +58,85 @@ import org.springframework.stereotype.Component; import com.google.gson.Gson; - @Component -public class VnfmDriverMgmrImpl implements VnfmDriverMgmrInf{ +public class VnfmDriverMgmrImpl implements VnfmDriverMgmrInf { private static final Logger logger = LoggerFactory.getLogger(VnfmDriverMgmrImpl.class); - + @Autowired Driver2CbamRequestConverter requestConverter; - + @Autowired Cbam2DriverResponseConverter responseConverter; - + @Autowired private CbamMgmrInf cbamMgmr; - + @Autowired private CatalogMgmrInf catalogMgmr; - + @Autowired private NslcmMgmrInf nslcmMgmr; - + @Autowired private AaiMgmrInf aaiMgmr; - + @Autowired - private VnfmJobExecutionRepository jobDbManager; - + private VnfmJobExecutionMapper jobDbManager; + + @Autowired + private VnfcResourceInfoMapper vnfcDbMgmr; + @Autowired AdaptorEnv adaptorEnv; - + @Autowired private VnfContinueProcessorInf vnfContinueProcessorInf; - + private Gson gson = new Gson(); - - public InstantiateVnfResponse instantiateVnf(InstantiateVnfRequest driverRequest, String vnfmId) throws VnfmDriverException { + + public InstantiateVnfResponse instantiateVnf(InstantiateVnfRequest driverRequest, String vnfmId) + throws VnfmDriverException { InstantiateVnfResponse driverResponse; try { driverRequest.setVnfdId(adaptorEnv.getVnfdId()); buildVnfmHttpPathById(vnfmId); - -// String dirPath = "/etc/vnfmpkg"; -// String cbamDirName = CommonUtil.getAppRoot() + dirPath; -// File cbamDirFile = new File(cbamDirName); -// String cbamPackageName = cbamDirFile.listFiles()[0].getAbsolutePath(); -// cbamMgmr.uploadVnfPackage(cbamPackageName); - - //step 3: create vnf + + // String dirPath = "/etc/vnfmpkg"; + // String cbamDirName = CommonUtil.getAppRoot() + dirPath; + // File cbamDirFile = new File(cbamDirName); + // String cbamPackageName = cbamDirFile.listFiles()[0].getAbsolutePath(); + // cbamMgmr.uploadVnfPackage(cbamPackageName); + + // step 3: create vnf CBAMCreateVnfRequest cbamRequest = requestConverter.createReqConvert(driverRequest); + logger.info("VnfmDriverMgmrImpl --> instantiateVnf, ready to create vnf on CBAM. "); CBAMCreateVnfResponse cbamResponse = cbamMgmr.createVnf(cbamRequest); String vnfInstanceId = cbamResponse.getId(); - + logger.info("VnfmDriverMgmrImpl --> instantiateVnf, vnfInstanceId is " + vnfInstanceId); Long jobId = saveCreateVnfJob(vnfInstanceId); driverResponse = responseConverter.createRspConvert(cbamResponse, jobId); - - //start the timer - OperateTaskProgress.startInstantiateTimerTask(); - - vnfContinueProcessorInf.continueInstantiateVnf(vnfmId, driverRequest, vnfInstanceId, jobId.toString(), nslcmMgmr, catalogMgmr, cbamMgmr, requestConverter, jobDbManager); - + + vnfContinueProcessorInf.continueInstantiateVnf(vnfmId, driverRequest, vnfInstanceId, jobId.toString(), + nslcmMgmr, catalogMgmr, cbamMgmr, requestConverter, jobDbManager, vnfcDbMgmr); + } catch (Exception e) { logger.error("error VnfmDriverMgmrImpl --> instantiateVnf. ", e); throw new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); } - - return driverResponse; + + return driverResponse; } - + private Long saveCreateVnfJob(String vnfInstanceId) { VnfmJobExecutionInfo jobInfo = new VnfmJobExecutionInfo(); + long nowTime = System.currentTimeMillis(); jobInfo.setVnfInstanceId(vnfInstanceId); jobInfo.setVnfmInterfceName(CommonConstants.NSLCM_OPERATION_INSTANTIATE); jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_START); + jobInfo.setOperateStartTime(nowTime); - VnfmJobExecutionInfo jobInfo1 = (VnfmJobExecutionInfo) jobDbManager.save(jobInfo); + jobDbManager.insert(jobInfo); + VnfmJobExecutionInfo jobInfo1 = (VnfmJobExecutionInfo) jobDbManager.findNewestJobInfo(); Long jobId = jobInfo1.getJobId(); return jobId; } @@ -144,28 +147,29 @@ public class VnfmDriverMgmrImpl implements VnfmDriverMgmrInf{ buildVnfmHttpPathById(vnfmId); driverResponse = generateTerminateVnfResponse(vnfInstanceId); String jobId = driverResponse.getJobId(); - - //start the timer - OperateTaskProgress.startTerminateTimerTask(); - vnfContinueProcessorInf.continueTerminateVnf(vnfmId, driverRequest, vnfInstanceId, jobId, nslcmMgmr, cbamMgmr, requestConverter, jobDbManager); - + + vnfContinueProcessorInf.continueTerminateVnf(vnfmId, driverRequest, vnfInstanceId, jobId, nslcmMgmr, + cbamMgmr, requestConverter, jobDbManager, vnfcDbMgmr); + } catch (Exception e) { logger.error("error VnfmDriverMgmrImpl --> terminateVnf. ", e); throw new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); } - - return driverResponse; + + return driverResponse; } private TerminateVnfResponse generateTerminateVnfResponse(String vnfInstanceId) { VnfmJobExecutionInfo jobInfo = new VnfmJobExecutionInfo(); + long nowTime = System.currentTimeMillis(); jobInfo.setVnfInstanceId(vnfInstanceId); jobInfo.setVnfmInterfceName(CommonConstants.NSLCM_OPERATION_TERMINATE); jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_START); - - VnfmJobExecutionInfo jobInfo1= jobDbManager.save(jobInfo); + jobInfo.setOperateStartTime(nowTime); + jobDbManager.insert(jobInfo); + VnfmJobExecutionInfo jobInfo1 = jobDbManager.findNewestJobInfo(); Long jobId = jobInfo1.getJobId(); - + TerminateVnfResponse response = new TerminateVnfResponse(); response.setJobId("" + jobId); return response; @@ -181,82 +185,124 @@ public class VnfmDriverMgmrImpl implements VnfmDriverMgmrInf{ logger.error("error VnfmDriverMgmrImpl --> queryVnf. ", e); throw new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); } - - return driverResponse; + + return driverResponse; } - public OperStatusVnfResponse getOperStatus(String vnfmId, String jobId) throws VnfmDriverException { - + public OperStatusVnfResponse getOperStatus(String vnfmId, String jobId) throws VnfmDriverException { + OperationExecution cbamResponse = null; - + try { buildVnfmHttpPathById(vnfmId); - + VnfmJobExecutionInfo jobInfo = jobDbManager.findOne(Long.parseLong(jobId)); cbamResponse = new OperationExecution(); - - if("Instantiate".equalsIgnoreCase(jobInfo.getVnfmInterfceName())) { + + if ("Instantiate".equalsIgnoreCase(jobInfo.getVnfmInterfceName())) { cbamResponse.setOperationType(OperationType.INSTANTIATE); - } - else - { + } else if ("Terminal".equalsIgnoreCase(jobInfo.getVnfmInterfceName())) { cbamResponse.setOperationType(OperationType.TERMINATE); + } else if ("Scalein".equalsIgnoreCase(jobInfo.getVnfmInterfceName()) + || "Scaleout".equalsIgnoreCase(jobInfo.getVnfmInterfceName())) { + cbamResponse.setOperationType(OperationType.SCALE); + } else { + cbamResponse.setOperationType(OperationType.HEAL); } - - if(jobInfo.getStatus().equalsIgnoreCase(CommonConstants.CBAM_OPERATION_STATUS_FINISH)) - { + + if (jobInfo.getStatus().equalsIgnoreCase(CommonConstants.CBAM_OPERATION_STATUS_FINISH)) { cbamResponse.setStatus(CommonEnum.OperationStatus.FINISHED); - } else if(jobInfo.getStatus().equalsIgnoreCase(CommonConstants.CBAM_OPERATION_STATUS_ERROR)) - { + } else if (jobInfo.getStatus().equalsIgnoreCase(CommonConstants.CBAM_OPERATION_STATUS_ERROR)) { cbamResponse.setStatus(CommonEnum.OperationStatus.FINISHED); - } - else - { + } else { cbamResponse.setStatus(CommonEnum.OperationStatus.OTHER); -// String execId = jobInfo.getVnfmExecutionId(); -// logger.info(" VnfmDriverMgmrImpl --> getOperStatus execId is " + execId); -// cbamResponse = cbamMgmr.queryOperExecution(execId); + // String execId = jobInfo.getVnfmExecutionId(); + // logger.info(" VnfmDriverMgmrImpl --> getOperStatus execId is " + execId); + // cbamResponse = cbamMgmr.queryOperExecution(execId); } - + } catch (Exception e) { logger.error("error VnfmDriverMgmrImpl --> getOperStatus. ", e); throw new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); } - - OperStatusVnfResponse response = responseConverter.operRspConvert(cbamResponse); + + OperStatusVnfResponse response = responseConverter.operRspConvert(cbamResponse, jobId); response.setJobId(jobId); - + return response; } - public ScaleVnfResponse scaleVnf(ScaleVnfRequest driverRequest, String vnfmId, String vnfInstanceId) throws VnfmDriverException { + public ScaleVnfResponse scaleVnf(ScaleVnfRequest driverRequest, String vnfmId, String vnfInstanceId) + throws VnfmDriverException { ScaleVnfResponse driverResponse; try { buildVnfmHttpPathById(vnfmId); - CBAMScaleVnfRequest cbamRequest = requestConverter.scaleReqconvert(driverRequest); - CBAMScaleVnfResponse cbamResponse = cbamMgmr.scaleVnf(cbamRequest, vnfInstanceId); - driverResponse = responseConverter.scaleRspConvert(cbamResponse); + driverResponse = generateScaleVnfResponse(vnfInstanceId, driverRequest.getType()); + String jobId = driverResponse.getJobId(); + + vnfContinueProcessorInf.continueScaleVnf(vnfmId, driverRequest, vnfInstanceId, jobId, nslcmMgmr, cbamMgmr, + requestConverter, jobDbManager); } catch (Exception e) { logger.error("error VnfmDriverMgmrImpl --> scaleVnf. ", e); throw new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); } - - return driverResponse; + + return driverResponse; } - public HealVnfResponse healVnf(HealVnfRequest driverRequest, String vnfmId, String vnfInstanceId) throws VnfmDriverException { + private ScaleVnfResponse generateScaleVnfResponse(String vnfInstanceId, ScaleType type) { + VnfmJobExecutionInfo jobInfo = new VnfmJobExecutionInfo(); + long nowTime = System.currentTimeMillis(); + jobInfo.setVnfInstanceId(vnfInstanceId); + if (type.equals(ScaleType.SCALE_OUT)) { + jobInfo.setVnfmInterfceName(CommonConstants.NSLCM_OPERATION_SCALE_OUT); + } else { + jobInfo.setVnfmInterfceName(CommonConstants.NSLCM_OPERATION_SCALE_IN); + } + jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_START); + jobInfo.setOperateStartTime(nowTime); + jobDbManager.insert(jobInfo); + VnfmJobExecutionInfo jobInfo1 = jobDbManager.findNewestJobInfo(); + Long jobId = jobInfo1.getJobId(); + + ScaleVnfResponse response = new ScaleVnfResponse(); + response.setJobId("" + jobId); + return response; + + } + + public HealVnfResponse healVnf(HealVnfRequest driverRequest, String vnfmId, String vnfInstanceId) + throws VnfmDriverException { HealVnfResponse driverResponse; try { buildVnfmHttpPathById(vnfmId); - CBAMHealVnfRequest cbamRequest = requestConverter.healReqConvert(driverRequest); - CBAMHealVnfResponse cbamResponse = cbamMgmr.healVnf(cbamRequest, vnfInstanceId); - driverResponse = responseConverter.healRspConvert(cbamResponse); + driverResponse = generateHealVnfResponse(vnfInstanceId); + String jobId = driverResponse.getJobId(); + + vnfContinueProcessorInf.continueHealVnf(vnfmId, driverRequest, vnfInstanceId, jobId, nslcmMgmr, cbamMgmr, + requestConverter, jobDbManager); } catch (Exception e) { logger.error("error VnfmDriverMgmrImpl --> healVnf. ", e); throw new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); } - - return driverResponse; + + return driverResponse; + } + + private HealVnfResponse generateHealVnfResponse(String vnfInstanceId) { + VnfmJobExecutionInfo jobInfo = new VnfmJobExecutionInfo(); + long nowTime = System.currentTimeMillis(); + jobInfo.setVnfInstanceId(vnfInstanceId); + jobInfo.setVnfmInterfceName(CommonConstants.NSLCM_OPERATION_HEAL); + jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_START); + jobInfo.setOperateStartTime(nowTime); + jobDbManager.insert(jobInfo); + VnfmJobExecutionInfo jobInfo1 = jobDbManager.findNewestJobInfo(); + Long jobId = jobInfo1.getJobId(); + + HealVnfResponse response = new HealVnfResponse(); + response.setJobId("" + jobId); + return response; } public String buildVnfmHttpPathById(String vnfmId) { @@ -268,22 +314,22 @@ public class VnfmDriverMgmrImpl implements VnfmDriverMgmrInf{ } return result; } - - public String buildVnfmHttpPathByRealId(String vnfmId) throws ClientProtocolException, IOException, VnfmDriverException { + + public String buildVnfmHttpPathByRealId(String vnfmId) + throws ClientProtocolException, IOException, VnfmDriverException { AaiVnfmInfo vnfmInfo = aaiMgmr.queryVnfm(vnfmId); logger.info("vnfmInfo in AAI is " + gson.toJson(vnfmInfo)); - if(isVnfmInfoValid(vnfmId, vnfmInfo)) - { + if (isVnfmInfoValid(vnfmId, vnfmInfo)) { throw new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); } - + EsrSystemInfo systemInfo = vnfmInfo.getEsrSystemInfoList().get(0); - + String urlHead = systemInfo.getServiceUrl(); -// adaptorEnv.setCbamApiUriFront(urlHead); -// adaptorEnv.setCbamUserName(systemInfo.getUserName()); -// adaptorEnv.setCbamPassword(systemInfo.getPassword()); - + // adaptorEnv.setCbamApiUriFront(urlHead); + // adaptorEnv.setCbamUserName(systemInfo.getUserName()); + // adaptorEnv.setCbamPassword(systemInfo.getPassword()); + return urlHead; } @@ -298,5 +344,5 @@ public class VnfmDriverMgmrImpl implements VnfmDriverMgmrInf{ public void setResponseConverter(Cbam2DriverResponseConverter responseConverter) { this.responseConverter = responseConverter; } - + } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMCreateSubscriptionRequest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMCreateSubscriptionRequest.java new file mode 100644 index 00000000..29085c14 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMCreateSubscriptionRequest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo; + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.SubscriptionAuthentication; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.SubscriptionFilter; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CBAMCreateSubscriptionRequest { + @JsonProperty("filter") + private SubscriptionFilter filter; + + @JsonProperty("callbackUrl") + private String callbackUrl; + + @JsonProperty("description") + private SubscriptionAuthentication authentication; + + public SubscriptionFilter getFilter() { + return filter; + } + + public void setFilter(SubscriptionFilter filter) { + this.filter = filter; + } + + public String getCallbackUrl() { + return callbackUrl; + } + + public void setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + } + + public SubscriptionAuthentication getAuthentication() { + return authentication; + } + + public void setAuthentication(SubscriptionAuthentication authentication) { + this.authentication = authentication; + } + + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMCreateSubscriptionResponse.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMCreateSubscriptionResponse.java new file mode 100644 index 00000000..78cd9ce0 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMCreateSubscriptionResponse.java @@ -0,0 +1,41 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo; + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription; + +public class CBAMCreateSubscriptionResponse extends Subscription{ +/* + + @JsonProperty("problemDetails") + private ProblemDetails problemDetails; + + + public ProblemDetails getProblemDetails() { + return problemDetails; + } + + public void setProblemDetails(ProblemDetails problemDetails) { + this.problemDetails = problemDetails; + } +*/ + + + + + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMGetSubscriptionRequest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMGetSubscriptionRequest.java new file mode 100644 index 00000000..1ff5e556 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMGetSubscriptionRequest.java @@ -0,0 +1,21 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo; + +public class CBAMGetSubscriptionRequest { + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMGetSubscriptionResponse.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMGetSubscriptionResponse.java new file mode 100644 index 00000000..5b6f2e17 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMGetSubscriptionResponse.java @@ -0,0 +1,49 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo; + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.OperationExecution; + +public class CBAMGetSubscriptionResponse extends OperationExecution{ +/* @JsonProperty("operationExecution") + private OperationExecution operationExecution; + + @JsonProperty("problemDetails") + private ProblemDetails problemDetails; + + public OperationExecution getOperationExecution() { + return operationExecution; + } + + public void setOperationExecution(OperationExecution operationExecution) { + this.operationExecution = operationExecution; + } + + public ProblemDetails getProblemDetails() { + return problemDetails; + } + + public void setProblemDetails(ProblemDetails problemDetails) { + this.problemDetails = problemDetails; + } +*/ + + + + + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMVnfNotificationRequest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMVnfNotificationRequest.java new file mode 100644 index 00000000..436be6e0 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMVnfNotificationRequest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo; + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfNotificationType; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CBAMVnfNotificationRequest { + @JsonProperty("notificationType") + private VnfNotificationType notificationType; + + @JsonProperty("subscriptionId") + private String subscriptionId; + + @JsonProperty("timestamp") + private String timestamp; + + @JsonProperty("vnfInstanceId") + private String vnfInstanceId; + + public VnfNotificationType getNotificationType() { + return notificationType; + } + + public void setNotificationType(VnfNotificationType notificationType) { + this.notificationType = notificationType; + } + + public String getSubscriptionId() { + return subscriptionId; + } + + public void setSubscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + + + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMVnfNotificationResponse.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMVnfNotificationResponse.java new file mode 100644 index 00000000..814324bb --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMVnfNotificationResponse.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo; + + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ProblemDetails; + +public class CBAMVnfNotificationResponse extends ProblemDetails{ +/* + + @JsonProperty("problemDetails") + private ProblemDetails problemDetails; + + + public ProblemDetails getProblemDetails() { + return problemDetails; + } + + public void setProblemDetails(ProblemDetails problemDetails) { + this.problemDetails = problemDetails; + } +*/ + + + + + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/Subscription.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/Subscription.java new file mode 100644 index 00000000..1345d72f --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/Subscription.java @@ -0,0 +1,78 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Subscription { + @JsonProperty("id") + private String id; + + @JsonProperty("lcnApiVersion") + private String lcnApiVersion; + + @JsonProperty("filter") + private SubscriptionFilter filter; + + @JsonProperty("callbackUrl") + private String callbackUrl; + + @JsonProperty("_links") + private _links _links; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getLcnApiVersion() { + return lcnApiVersion; + } + + public void setLcnApiVersion(String lcnApiVersion) { + this.lcnApiVersion = lcnApiVersion; + } + + public SubscriptionFilter getFilter() { + return filter; + } + + public void setFilter(SubscriptionFilter filter) { + this.filter = filter; + } + + public String getCallbackUrl() { + return callbackUrl; + } + + public void setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + } + + public _links get_links() { + return _links; + } + + public void set_links(_links _links) { + this._links = _links; + } + + + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/SubscriptionAuthentication.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/SubscriptionAuthentication.java new file mode 100644 index 00000000..976987a1 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/SubscriptionAuthentication.java @@ -0,0 +1,91 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SubscriptionAuthentication { + + + @JsonProperty("type") + private Type type; + + @JsonProperty("userName") + private String userName; + + @JsonProperty("password") + private String password; + + @JsonProperty("clientName") + private String clientName; + + @JsonProperty("clientPassword") + private String clientPassword; + + @JsonProperty("tokenUrl") + private String tokenUrl; + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + + public String getClientPassword() { + return clientPassword; + } + + public void setClientPassword(String clientPassword) { + this.clientPassword = clientPassword; + } + + public String getTokenUrl() { + return tokenUrl; + } + + public void setTokenUrl(String tokenUrl) { + this.tokenUrl = tokenUrl; + } + + + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/SubscriptionFilter.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/SubscriptionFilter.java new file mode 100644 index 00000000..188419ad --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/SubscriptionFilter.java @@ -0,0 +1,97 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity; + +import java.util.List; + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.OperationExecution.OperationType; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SubscriptionFilter { + + @JsonProperty("vnfdId") + private String vnfdId; + + @JsonProperty("vnfProductName") + private String vnfProductName; + + @JsonProperty("vnfSoftwareVersion") + private String vnfSoftwareVersion; + + @JsonProperty("vnfInstanceId") + private String vnfInstanceId; + + @JsonProperty("notificationTypes") + private List<VnfNotificationType> notificationTypes; + + @JsonProperty("operationType") + private List<OperationType> operationType; + + public String getVnfdId() { + return vnfdId; + } + + public void setVnfdId(String vnfdId) { + this.vnfdId = vnfdId; + } + + public String getVnfProductName() { + return vnfProductName; + } + + public void setVnfProductName(String vnfProductName) { + this.vnfProductName = vnfProductName; + } + + public String getVnfSoftwareVersion() { + return vnfSoftwareVersion; + } + + public void setVnfSoftwareVersion(String vnfSoftwareVersion) { + this.vnfSoftwareVersion = vnfSoftwareVersion; + } + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public List<VnfNotificationType> getNotificationTypes() { + return notificationTypes; + } + + public void setNotificationTypes(List<VnfNotificationType> notificationTypes) { + this.notificationTypes = notificationTypes; + } + + public List<OperationType> getOperationType() { + return operationType; + } + + public void setOperationType(List<OperationType> operationType) { + this.operationType = operationType; + } + + + + + + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/Type.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/Type.java new file mode 100644 index 00000000..5faaba1a --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/Type.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity; + +public enum Type { + NONE, + BASIC, + OAUTH2_PASSWD, + OAUTH2_CLIENT + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VnfNotificationType.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VnfNotificationType.java new file mode 100644 index 00000000..a5690eab --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VnfNotificationType.java @@ -0,0 +1,22 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity; + +public enum VnfNotificationType { + VnfIdentifierCreationNotification, VnfIdentifierDeletionNotification, + VnfLifecycleChangeNotification, VnfInfoAttributeValueChangeNotification, OtherNotification + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java index d312a867..4211dee3 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java @@ -24,9 +24,10 @@ import java.util.HashMap; import java.util.List; import org.apache.http.client.ClientProtocolException; -import org.apache.log4j.Logger; import org.json.JSONException; import org.json.JSONObject; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest; @@ -41,12 +42,17 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfcResourceInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; @@ -57,244 +63,258 @@ import com.google.gson.Gson; @Component public class CbamMgmrImpl implements CbamMgmrInf { - private static final Logger logger = Logger.getLogger(CbamMgmrImpl.class); + private static final Logger logger = LoggerFactory.getLogger(CbamMgmrImpl.class); private Gson gson = new Gson(); - - @Autowired + + @Autowired private AdaptorEnv adaptorEnv; - + @Autowired HttpClientProcessorInf httpClientProcessor; - + public String retrieveToken() throws ClientProtocolException, IOException, JSONException { String result = null; - String url= adaptorEnv.getCbamApiUriFront() + CommonConstants.CbamRetrieveTokenPath; + String url = adaptorEnv.getCbamApiUriFront() + CommonConstants.CbamRetrieveTokenPath; HashMap<String, String> map = new HashMap<>(); map.put(CommonConstants.ACCEPT, "*/*"); map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); - - String bodyPostStr = String.format(CommonConstants.CbamRetrieveTokenPostStr, adaptorEnv.getClientId(), adaptorEnv.getClientSecret(), adaptorEnv.getCbamUserName(), adaptorEnv.getCbamPassword()); - + + String bodyPostStr = String.format(CommonConstants.CbamRetrieveTokenPostStr, adaptorEnv.getClientId(), + adaptorEnv.getClientSecret(), adaptorEnv.getCbamUserName(), adaptorEnv.getCbamPassword()); + logger.debug("CbamMgmrImpl -> retrieveToken, url is " + url); logger.debug("CbamMgmrImpl -> retrieveToken, bodyPostStr is " + bodyPostStr); - + String responseStr = httpClientProcessor.process(url, RequestMethod.POST, map, bodyPostStr).getContent(); - + logger.info("CbamMgmrImpl -> retrieveToken, responseStr is " + responseStr); - + JSONObject tokenJsonObject = new JSONObject(responseStr); - + result = tokenJsonObject.getString(CommonConstants.CBAM_TOKEN_KEY); - + return result; } - - public CBAMCreateVnfResponse createVnf(CBAMCreateVnfRequest cbamRequest) throws ClientProtocolException, IOException { + + public CBAMCreateVnfResponse createVnf(CBAMCreateVnfRequest cbamRequest) + throws ClientProtocolException, IOException { String httpPath = CommonConstants.CbamCreateVnfPath; RequestMethod method = RequestMethod.POST; - + HttpResult httpResult = operateCbamHttpTask(cbamRequest, httpPath, method); String responseStr = httpResult.getContent(); - + logger.info("CbamMgmrImpl -> createVnf, responseStr is " + responseStr); int code = httpResult.getStatusCode(); - if(code == 201) { + if (code == 201) { logger.info("CbamMgmrImpl -> createVnf success"); - }else { + } else { logger.error("CbamMgmrImpl -> createVnf error "); } CBAMCreateVnfResponse response = gson.fromJson(responseStr, CBAMCreateVnfResponse.class); - + return response; } - + public CBAMModifyVnfResponse modifyVnf(CBAMModifyVnfRequest cbamRequest, String vnfInstanceId) throws ClientProtocolException, IOException { String httpPath = String.format(CommonConstants.CbamModifyVnfPath, vnfInstanceId); - + RequestMethod method = RequestMethod.PATCH; - + HttpResult httpResult = operateCbamHttpTask(cbamRequest, httpPath, method); String responseStr = httpResult.getContent(); - + logger.info("CbamMgmrImpl -> modifyVnf, responseStr is " + responseStr); int code = httpResult.getStatusCode(); - if(code == 201) { + + if(code == 202) { logger.info("CbamMgmrImpl -> modifyVnf success"); - }else { - logger.error("CbamMgmrImpl -> modifyVnf error "); + } else { + logger.error("CbamMgmrImpl -> modifyVnf error, statusCode = " + code); } CBAMModifyVnfResponse response = gson.fromJson(responseStr, CBAMModifyVnfResponse.class); return response; } - - /* (non-Javadoc) - * @see com.nokia.vfcadaptor.cbam.impl.CbamMgmrInf#instantiateVnf(com.nokia.vfcadaptor.cbam.bo.CBAMInstantiateVnfRequest, java.lang.String) + + /* + * (non-Javadoc) + * + * @see com.nokia.vfcadaptor.cbam.impl.CbamMgmrInf#instantiateVnf(com.nokia. + * vfcadaptor.cbam.bo.CBAMInstantiateVnfRequest, java.lang.String) */ - public CBAMInstantiateVnfResponse instantiateVnf(CBAMInstantiateVnfRequest cbamRequest, String vnfInstanceId) throws ClientProtocolException, IOException { + public CBAMInstantiateVnfResponse instantiateVnf(CBAMInstantiateVnfRequest cbamRequest, String vnfInstanceId) + throws ClientProtocolException, IOException { String httpPath = String.format(CommonConstants.CbamInstantiateVnfPath, vnfInstanceId); RequestMethod method = RequestMethod.POST; - + HttpResult httpResult = operateCbamHttpTask(cbamRequest, httpPath, method); String responseStr = httpResult.getContent(); - + logger.info("CbamMgmrImpl -> instantiateVnf, responseStr is " + responseStr); int code = httpResult.getStatusCode(); - if(code == 202) { - logger.info("CbamMgmrImpl -> instantiateVnf success " ); - }else { - logger.error("CbamMgmrImpl -> instantiateVnf error " ); + if (code == 202) { + logger.info("CbamMgmrImpl -> instantiateVnf success "); + } else { + logger.error("CbamMgmrImpl -> instantiateVnf error "); } CBAMInstantiateVnfResponse response = gson.fromJson(responseStr, CBAMInstantiateVnfResponse.class); - + return response; } - - public CBAMTerminateVnfResponse terminateVnf(CBAMTerminateVnfRequest cbamRequest, String vnfInstanceId) throws ClientProtocolException, IOException { + + public CBAMTerminateVnfResponse terminateVnf(CBAMTerminateVnfRequest cbamRequest, String vnfInstanceId) + throws ClientProtocolException, IOException { String httpPath = String.format(CommonConstants.CbamTerminateVnfPath, vnfInstanceId); RequestMethod method = RequestMethod.POST; - + HttpResult httpResult = operateCbamHttpTask(cbamRequest, httpPath, method); String responseStr = httpResult.getContent(); - + logger.info("CbamMgmrImpl -> terminateVnf, responseStr is " + responseStr); int code = httpResult.getStatusCode(); - if(code == 202) { - logger.info("CbamMgmrImpl -> terminateVnf sucess " ); - }else { - logger.error("CbamMgmrImpl -> terminateVnf error " ); + if (code == 202) { + logger.info("CbamMgmrImpl -> terminateVnf sucess "); + } else { + logger.error("CbamMgmrImpl -> terminateVnf error "); } CBAMTerminateVnfResponse response = gson.fromJson(responseStr, CBAMTerminateVnfResponse.class); - + return response; } - + public void deleteVnf(String vnfInstanceId) throws ClientProtocolException, IOException { String httpPath = String.format(CommonConstants.CbamDeleteVnfPath, vnfInstanceId); RequestMethod method = RequestMethod.DELETE; HttpResult httpResult = operateCbamHttpTask(null, httpPath, method); - + int code = httpResult.getStatusCode(); - if(code == 204) { + if (code == 204) { logger.info("CbamMgmrImpl -> deleteVnf success."); - }else { - logger.error("CbamMgmrImpl -> deleteVnf error. detail info is " + httpResult.getContent()); + } else { + logger.error("CbamMgmrImpl -> deleteVnf error. detail info is " + httpResult.getContent()); } - + } - - public CBAMScaleVnfResponse scaleVnf(CBAMScaleVnfRequest cbamRequest, String vnfInstanceId) throws ClientProtocolException, IOException { + + public CBAMScaleVnfResponse scaleVnf(CBAMScaleVnfRequest cbamRequest, String vnfInstanceId) + throws ClientProtocolException, IOException { String httpPath = String.format(CommonConstants.CbamScaleVnfPath, vnfInstanceId); RequestMethod method = RequestMethod.POST; - + HttpResult httpResult = operateCbamHttpTask(cbamRequest, httpPath, method); String responseStr = httpResult.getContent(); int code = httpResult.getStatusCode(); - if(code == 202) { + if (code == 202) { logger.info("CbamMgmrImpl -> scaleVnf success."); - }else { - logger.error("CbamMgmrImpl -> scaleVnf error. " ); + } else { + logger.error("CbamMgmrImpl -> scaleVnf error. "); } CBAMScaleVnfResponse response = gson.fromJson(responseStr, CBAMScaleVnfResponse.class); - + return response; } - public CBAMHealVnfResponse healVnf(CBAMHealVnfRequest cbamRequest, String vnfInstanceId) throws ClientProtocolException, IOException { + public CBAMHealVnfResponse healVnf(CBAMHealVnfRequest cbamRequest, String vnfInstanceId) + throws ClientProtocolException, IOException { String httpPath = String.format(CommonConstants.CbamHealVnfPath, vnfInstanceId); RequestMethod method = RequestMethod.POST; - + HttpResult httpResult = operateCbamHttpTask(cbamRequest, httpPath, method); String responseStr = httpResult.getContent(); - + logger.info("CbamMgmrImpl -> healVnf, responseStr is " + responseStr); int code = httpResult.getStatusCode(); - if(code == 202) { + if (code == 202) { logger.info("CbamMgmrImpl -> healVnf success."); - }else { - logger.error("CbamMgmrImpl -> healVnf error. " ); + } else { + logger.error("CbamMgmrImpl -> healVnf error. "); } CBAMHealVnfResponse response = gson.fromJson(responseStr, CBAMHealVnfResponse.class); - + return response; } - + public CBAMQueryVnfResponse queryVnf(String vnfInstanceId) throws ClientProtocolException, IOException { String httpPath = String.format(CommonConstants.CbamQueryVnfPath, vnfInstanceId); RequestMethod method = RequestMethod.GET; - + HttpResult httpResult = operateCbamHttpTask(null, httpPath, method); String responseStr = httpResult.getContent(); - + logger.info("CbamMgmrImpl -> queryVnf, responseStr is " + responseStr); int code = httpResult.getStatusCode(); - if(code == 200) { + if (code == 200) { logger.info("CbamMgmrImpl -> queryVnf success."); - }else { - logger.error("CbamMgmrImpl -> queryVnf error. " ); + } else { + logger.error("CbamMgmrImpl -> queryVnf error. "); } - + CBAMQueryVnfResponse response = gson.fromJson(responseStr, CBAMQueryVnfResponse.class); - + return response; } - + public List<VnfcResourceInfo> queryVnfcResource(String vnfInstanceId) throws ClientProtocolException, IOException { String httpPath = String.format(CommonConstants.CbamQueryVnfcResourcePath, vnfInstanceId); RequestMethod method = RequestMethod.GET; - + HttpResult httpResult = operateCbamHttpTask(null, httpPath, method); String responseStr = httpResult.getContent(); - + logger.info("CbamMgmrImpl -> queryVnfcResource, responseStr is " + responseStr); int code = httpResult.getStatusCode(); - if(code == 200) { + if (code == 200) { logger.info("CbamMgmrImpl -> queryVnfcResource success."); - }else { - logger.error("CbamMgmrImpl -> queryVnfcResource error. " ); + } else { + logger.error("CbamMgmrImpl -> queryVnfcResource error. "); } - List<VnfcResourceInfo> response = gson.fromJson(responseStr, new TypeToken<List<VnfcResourceInfo>>(){}.getType());; - + List<VnfcResourceInfo> response = gson.fromJson(responseStr, new TypeToken<List<VnfcResourceInfo>>() { + }.getType()); + ; + return response; } - public HttpResult operateCbamHttpTask(Object httpBodyObj, String httpPath, RequestMethod method) throws ClientProtocolException, IOException { + public HttpResult operateCbamHttpTask(Object httpBodyObj, String httpPath, RequestMethod method) + throws ClientProtocolException, IOException { String token = null; try { token = retrieveToken(); } catch (JSONException e) { logger.error("retrieveTokenError ", e); } - - String url= adaptorEnv.getCbamApiUriFront() + httpPath; - + + String url = adaptorEnv.getCbamApiUriFront() + httpPath; + HashMap<String, String> map = new HashMap<>(); map.put(CommonConstants.AUTHORIZATION, "bearer " + token); map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - + return httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)); } - public CBAMQueryOperExecutionResponse queryOperExecution(String execId) throws ClientProtocolException, IOException{ + public CBAMQueryOperExecutionResponse queryOperExecution(String execId) + throws ClientProtocolException, IOException { String httpPath = String.format(CommonConstants.CbamGetOperStatusPath, execId); RequestMethod method = RequestMethod.GET; - + HttpResult httpResult = operateCbamHttpTask(null, httpPath, method); String responseStr = httpResult.getContent(); - + logger.info("CbamMgmrImpl -> CBAMQueryOperExecutionResponse, responseStr is " + responseStr); - + int code = httpResult.getStatusCode(); - if(code == 200) { - logger.info("CbamMgmrImpl -> CBAMQueryOperExecutionResponse, success" ); - }else if(code == 202) { - logger.info("CbamMgmrImpl -> CBAMQueryOperExecutionResponse, ongoing" ); - }else { - logger.error("CbamMgmrImpl -> CBAMQueryOperExecutionResponse, error" ); + if (code == 200) { + logger.info("CbamMgmrImpl -> CBAMQueryOperExecutionResponse, success"); + } else if (code == 202) { + logger.info("CbamMgmrImpl -> CBAMQueryOperExecutionResponse, ongoing"); + } else { + logger.error("CbamMgmrImpl -> CBAMQueryOperExecutionResponse, error"); } - + CBAMQueryOperExecutionResponse response = gson.fromJson(responseStr, CBAMQueryOperExecutionResponse.class); - + return response; } @@ -306,22 +326,24 @@ public class CbamMgmrImpl implements CbamMgmrInf { public void uploadVnfPackage(String cbamPackageFilePath) throws ClientProtocolException, IOException { String httpPath = CommonConstants.CbamUploadVnfPackagePath; RequestMethod method = RequestMethod.POST; - + HttpResult httpResult = operateCbamHttpUploadTask(cbamPackageFilePath, httpPath, method); String responseStr = httpResult.getContent(); - - logger.info("CbamMgmrImpl -> uploadVnfPackage, statusCode is " + httpResult.getStatusCode() + ", cause is " + httpResult.getStatusCause() + ". responseStr is " + responseStr); - + + logger.info("CbamMgmrImpl -> uploadVnfPackage, statusCode is " + httpResult.getStatusCode() + ", cause is " + + httpResult.getStatusCause() + ". responseStr is " + responseStr); + int code = httpResult.getStatusCode(); - if(code == 200) { - logger.info("CbamMgmrImpl -> uploadVnfPackage, success" ); + if (code == 200) { + logger.info("CbamMgmrImpl -> uploadVnfPackage, success"); logger.info("Upload vnf package " + cbamPackageFilePath + " to CBAM is successful."); - }else { - logger.error("CbamMgmrImpl -> uploadVnfPackage, error" ); + } else { + logger.error("CbamMgmrImpl -> uploadVnfPackage, error"); } } - public HttpResult operateCbamHttpUploadTask(String filePath, String httpPath, RequestMethod method) throws ClientProtocolException, IOException { + public HttpResult operateCbamHttpUploadTask(String filePath, String httpPath, RequestMethod method) + throws ClientProtocolException, IOException { String token = null; try { token = retrieveToken(); @@ -330,107 +352,111 @@ public class CbamMgmrImpl implements CbamMgmrInf { } String url = adaptorEnv.getCbamApiUriFront() + httpPath; logger.info("start to upload file."); - String command = "/usr/bin/curl --insecure -X POST -H \"Authorization: bearer " + token + "\" --form content=@" + filePath + " " + url; + String command = "/usr/bin/curl --insecure -X POST -H \"Authorization: bearer " + token + "\" --form content=@" + + filePath + " " + url; StringBuffer respStr = execCommand(command); - -// HashMap<String, String> map = new HashMap<>(); -// map.put(CommonConstants.AUTHORIZATION, "bearer " + token); -// map.put(CommonConstants.CONTENT_TYPE, "multipart/form-data, boundary=---CFSGSSGGSGdssdfsdhd---"); -// byte[] fileBytes = CommonUtil.getBytes(filePath); -// logger.info("CbamMgmrImpl -> operateCbamHttpUploadTask, url is " + url); -// logger.info("CbamMgmrImpl -> operateCbamHttpUploadTask, token is " + token); -// logger.info("CbamMgmrImpl -> operateCbamHttpUploadTask, bodyPostStr byte lenth is " + fileBytes.length); - -// return httpClientProcessor.processBytes(url, method, map, fileBytes); - + + // HashMap<String, String> map = new HashMap<>(); + // map.put(CommonConstants.AUTHORIZATION, "bearer " + token); + // map.put(CommonConstants.CONTENT_TYPE, "multipart/form-data, + // boundary=---CFSGSSGGSGdssdfsdhd---"); + // byte[] fileBytes = CommonUtil.getBytes(filePath); + // logger.info("CbamMgmrImpl -> operateCbamHttpUploadTask, url is " + url); + // logger.info("CbamMgmrImpl -> operateCbamHttpUploadTask, token is " + token); + // logger.info("CbamMgmrImpl -> operateCbamHttpUploadTask, bodyPostStr byte + // lenth is " + fileBytes.length); + + // return httpClientProcessor.processBytes(url, method, map, fileBytes); + HttpResult hResult = new HttpResult(); hResult.setStatusCause(respStr.toString()); hResult.setContent(respStr.toString()); hResult.setStatusCode(200); return hResult; - -// String charset = "UTF-8"; -// File uploadFile1 = new File(filePath); -// String requestURL = url; -// HttpResult result = new HttpResult(); -// -// try { -// MultipartUtility multipart = new MultipartUtility(requestURL, charset); -// -// multipart.addHeaderField("User-Agent", "CodeJava"); -// multipart.addHeaderField(CommonConstants.AUTHORIZATION, "bearer " + token); -// -// multipart.addFilePart("fileUpload", uploadFile1); -// -// List<String> response = multipart.finish(); -// -// result.setContent(Arrays.deepToString(response.toArray(new String[0]))); -// result.setStatusCode(200); -// } catch (Exception ex) { -// logger.error("CbamMgmrImpl -> operateCbamHttpUploadTask, error ", ex); -// result.setStatusCode(500); -// } -// -// return result; + + // String charset = "UTF-8"; + // File uploadFile1 = new File(filePath); + // String requestURL = url; + // HttpResult result = new HttpResult(); + // + // try { + // MultipartUtility multipart = new MultipartUtility(requestURL, charset); + // + // multipart.addHeaderField("User-Agent", "CodeJava"); + // multipart.addHeaderField(CommonConstants.AUTHORIZATION, "bearer " + token); + // + // multipart.addFilePart("fileUpload", uploadFile1); + // + // List<String> response = multipart.finish(); + // + // result.setContent(Arrays.deepToString(response.toArray(new String[0]))); + // result.setStatusCode(200); + // } catch (Exception ex) { + // logger.error("CbamMgmrImpl -> operateCbamHttpUploadTask, error ", ex); + // result.setStatusCode(500); + // } + // + // return result; } private StringBuffer execCommand(String command) { logger.info("CbamMgmrImpl -> execCommand, command is " + command); StringBuffer respStr = new StringBuffer("\r\n"); try { - String os = System.getProperty("os.name"); - String[] cmd = {"cmd", "/c", command}; - if(!os.toLowerCase().startsWith("win")){ - cmd = new String[]{"/bin/sh","-c", command}; - } + String os = System.getProperty("os.name"); + String[] cmd = { "cmd", "/c", command }; + if (!os.toLowerCase().startsWith("win")) { + cmd = new String[] { "/bin/sh", "-c", command }; + } Process process = Runtime.getRuntime().exec(cmd); - Thread t=new Thread(new InputStreamRunnable(process.getErrorStream(),"ErrorStream")); - t.start(); - Thread.sleep(3000); - InputStream fis=process.getInputStream(); - InputStreamReader isr=new InputStreamReader(fis); - - BufferedReader br=new BufferedReader(isr); - String line = null; - while((line = br.readLine())!=null) - { - respStr.append(line + "\r\n"); - } - respStr.append("\r\n"); - process.waitFor(); - fis.close(); - isr.close(); - process.destroy(); - logger.info("operateCbamHttpUploadTask respStr is: " + respStr); + Thread t = new Thread(new InputStreamRunnable(process.getErrorStream(), "ErrorStream")); + t.start(); + Thread.sleep(3000); + InputStream fis = process.getInputStream(); + InputStreamReader isr = new InputStreamReader(fis); + + BufferedReader br = new BufferedReader(isr); + String line = null; + while ((line = br.readLine()) != null) { + respStr.append(line + "\r\n"); + } + respStr.append("\r\n"); + process.waitFor(); + fis.close(); + isr.close(); + process.destroy(); + logger.info("operateCbamHttpUploadTask respStr is: " + respStr); } catch (Exception e) { logger.error("operateCbamHttpUploadTask error", e); } return respStr; } - -// public static String postByHttps(String url, String body, Object contentType) { -// String result = ""; -// Protocol https = new Protocol("https", new HTTPSSecureProtocolSocketFactory(), 443); -// Protocol.registerProtocol("https", https); -// PostMethod post = new PostMethod(url); -// HttpClient client = new HttpClient(); -// try { -// post.setRequestHeader("Content-Type", contentType); -// post.setRequestBody(body); -// client.executeMethod(post); -// result = post.getResponseBodyAsString(); -// Protocol.unregisterProtocol("https"); -// return result; -// } catch (HttpException e) { -// e.printStackTrace(); -// } catch (IOException e) { -// e.printStackTrace(); -// } catch(Exception e) { -// e.printStackTrace(); -// } -// -// return "error"; -// } + + // public static String postByHttps(String url, String body, Object contentType) + // { + // String result = ""; + // Protocol https = new Protocol("https", new + // HTTPSSecureProtocolSocketFactory(), 443); + // Protocol.registerProtocol("https", https); + // PostMethod post = new PostMethod(url); + // HttpClient client = new HttpClient(); + // try { + // post.setRequestHeader("Content-Type", contentType); + // post.setRequestBody(body); + // client.executeMethod(post); + // result = post.getResponseBodyAsString(); + // Protocol.unregisterProtocol("https"); + // return result; + // } catch (HttpException e) { + // e.printStackTrace(); + // } catch (IOException e) { + // e.printStackTrace(); + // } catch(Exception e) { + // e.printStackTrace(); + // } + // + // return "error"; + // } public HttpClientProcessorInf getHttpClientProcessor() { return httpClientProcessor; @@ -439,4 +465,69 @@ public class CbamMgmrImpl implements CbamMgmrInf { public void setHttpClientProcessor(HttpClientProcessorInf httpClientProcessor) { this.httpClientProcessor = httpClientProcessor; } + + @Override + public CBAMCreateSubscriptionResponse createSubscription(CBAMCreateSubscriptionRequest subscriptionRequest) + throws ClientProtocolException, IOException { + String httpPath = String.format(CommonConstants.CbamCreateSubscriptionPath); + RequestMethod method = RequestMethod.POST; + logger.info("CbamMgmrImpl -> createSubscription, requestStr is " + gson.toJson(subscriptionRequest)); + HttpResult httpResult = operateCbamHttpTask(subscriptionRequest, httpPath, method); + String responseStr = httpResult.getContent(); + + logger.info("CbamMgmrImpl -> createSubscription, responseStr is " + responseStr); + int code = httpResult.getStatusCode(); + if (code == 201) { + logger.info("CbamMgmrImpl -> createSubscription success "); + } else { + logger.error("CbamMgmrImpl -> createSubscription error , statusCode = " + code); + } + CBAMCreateSubscriptionResponse response = gson.fromJson(responseStr, CBAMCreateSubscriptionResponse.class); + + return response; + } + + @Override + public Subscription getSubscription(String subscriptionId) throws ClientProtocolException, IOException { + String httpPath = String.format(CommonConstants.CbamGetSubscriptionPath, subscriptionId); + RequestMethod method = RequestMethod.GET; + + HttpResult httpResult = operateCbamHttpTask(null, httpPath, method); + String responseStr = httpResult.getContent(); + + logger.info("CbamMgmrImpl -> getSubscription, responseStr is " + responseStr); + int code = httpResult.getStatusCode(); + if (code == 200) { + logger.info("CbamMgmrImpl -> getSubscription success "); + } else { + logger.error("CbamMgmrImpl -> getSubscription error , statusCode = " + code); + } + Subscription response = gson.fromJson(responseStr, Subscription.class); + + return response; + } + + @Override + public CBAMVnfNotificationResponse getNotification(CBAMVnfNotificationRequest getNotificationRequest) + throws ClientProtocolException, IOException { + String httpPath = String.format(CommonConstants.CbamGetNotificationPath); + RequestMethod method = RequestMethod.GET; + + HttpResult httpResult = operateCbamHttpTask(getNotificationRequest, httpPath, method); + String responseStr = httpResult.getContent(); + + logger.info("CbamMgmrImpl -> getNotification, responseStr is " + responseStr); + int code = httpResult.getStatusCode(); + if (code == 200) { + logger.info("CbamMgmrImpl -> getNotification success "); + } else { + logger.error("CbamMgmrImpl -> getNotification error , statusCode = " + code); + } + CBAMVnfNotificationResponse response = gson.fromJson(responseStr, CBAMVnfNotificationResponse.class); + return response; + } + + + + } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java index d9203137..f8f0c400 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java @@ -43,7 +43,8 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.SslConfInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.util.CommonUtil; @@ -56,7 +57,7 @@ import com.google.gson.Gson; * */ public class MultipartUtility { - private static final Logger logger = Logger.getLogger(MultipartUtility.class); + private static final Logger logger = LoggerFactory.getLogger(MultipartUtility.class); private final String boundary; private static final String LINE_FEED = "\r\n"; private HttpsURLConnection httpConn; diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/inf/CbamMgmrInf.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/inf/CbamMgmrInf.java index fb1fd8bd..cb62689d 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/inf/CbamMgmrInf.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/inf/CbamMgmrInf.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.util.List; import org.apache.http.client.ClientProtocolException; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest; @@ -34,6 +36,9 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfcResourceInfo; public interface CbamMgmrInf { @@ -44,6 +49,12 @@ public interface CbamMgmrInf { public CBAMInstantiateVnfResponse instantiateVnf(CBAMInstantiateVnfRequest cbamRequest, String vnfInstanceId) throws ClientProtocolException, IOException; + public CBAMCreateSubscriptionResponse createSubscription(CBAMCreateSubscriptionRequest subscriptionRequest) + throws ClientProtocolException, IOException; + public Subscription getSubscription(String subscriptionId) + throws ClientProtocolException, IOException; + public CBAMVnfNotificationResponse getNotification(CBAMVnfNotificationRequest getNotificationRequest) + throws ClientProtocolException, IOException; public CBAMTerminateVnfResponse terminateVnf(CBAMTerminateVnfRequest cbamRequest, String vnfInstanceId) throws ClientProtocolException, IOException; @@ -52,7 +63,7 @@ public interface CbamMgmrInf { throws ClientProtocolException, IOException; public CBAMHealVnfResponse healVnf(CBAMHealVnfRequest cbamRequest, String vnfInstanceId) - throws ClientProtocolException, IOException; + throws ClientProtocolException, IOException; public CBAMQueryVnfResponse queryVnf(String vnfInstanceId) throws ClientProtocolException, IOException; diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/bo/AdaptorEnv.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/bo/AdaptorEnv.java index de8e9004..72e17898 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/bo/AdaptorEnv.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/bo/AdaptorEnv.java @@ -23,8 +23,9 @@ import org.springframework.stereotype.Component; public class AdaptorEnv { private String msbIp; private int msbPort; - - // service name and version of MSB services AAI/LCM/Catalog configured in application.properties + + // service name and version of MSB services AAI/LCM/Catalog configured in + // application.properties @Value("${aaiServiceNameInMsb}") private String aaiServiceNameInMsb; @@ -43,30 +44,29 @@ public class AdaptorEnv { @Value("${catalogVersionInMsb}") private String catalogVersionInMsb; - //Following uriFront is from msb query - + // Following uriFront is from msb query + private String aaiUrlInMsb; private String aaiApiUriFront; - + private String lcmUrlInMsb; private String lcmApiUriFront; - + private String catalogUrlInMsb; private String catalogApiUriFront; - - //cbamApiFront is from aai query + + // cbamApiFront is from aai query @Value("${cbamApiUriFront}") private String cbamApiUriFront; - + @Value("${cbamUserName}") private String cbamUserName; - + @Value("${cbamPassword}") private String cbamPassword; - - + private String msbApiUriFront; - + // for retrieving token from CBAM, configured in application.properties @Value("${grantType}") private String grantType; @@ -76,23 +76,37 @@ public class AdaptorEnv { @Value("${clientSecret}") private String clientSecret; - + // for granting @Value("${type}") private String type; - + @Value("${sizeOfStorage}") private String sizeOfStorage; - + @Value("${virtualMemSize}") private String virtualMemSize; - + @Value("${numVirtualCpu}") private String numVirtualCpu; - + @Value("${vnfdId}") private String vnfdId; + // for OperateTaskProcess + @Value("${initialProgress}") + private int initialProgress; + + @Value("${instantiateTimeInterval}") + private int instantiateTimeInterval; + + @Value("${terminateTimeInterval}") + private int terminateTimeInterval; + + // + @Value("${driverApiUriFront}") + private String driverApiUriFront; + public String getAaiServiceNameInMsb() { return aaiServiceNameInMsb; } @@ -301,5 +315,39 @@ public class AdaptorEnv { this.vnfdId = vnfdId; } + public int getInitialProgress() { + return initialProgress; + } + + public void setInitialProgress(int initialProgress) { + this.initialProgress = initialProgress; + } + + public int getInstantiateTimeInterval() { + return instantiateTimeInterval; + } + public void setInstantiateTimeInterval(int instantiateTimeInterval) { + this.instantiateTimeInterval = instantiateTimeInterval; + } + + public int getTerminateTimeInterval() { + return terminateTimeInterval; + } + + public void setTerminateTimeInterval(int terminateTimeInterval) { + this.terminateTimeInterval = terminateTimeInterval; + } + + public String getDriverApiUriFront() { + return driverApiUriFront; + } + + public void setDriverApiUriFront(String driverApiUriFront) { + this.driverApiUriFront = driverApiUriFront; + } + + + + } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonConstants.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonConstants.java index e9387475..a047fd78 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonConstants.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonConstants.java @@ -54,6 +54,9 @@ public class CommonConstants { public static final String CbamScaleVnfPath = "/vnfm/lcm/v3/vnfs/%s/scale"; public static final String CbamHealVnfPath="/vnfm/lcm/v3/vnfs/%s/heal"; public static final String CbamQueryVnfcResourcePath="/vnfm/lcm/v3/vnfs/%s/vnfc_resource_info"; + public static final String CbamCreateSubscriptionPath="/vnfm/lcn/v3/subscriptions"; + public static final String CbamGetSubscriptionPath="/vnfm/lcn/v3/subscriptions/%s"; + public static final String CbamGetNotificationPath="/vnfm/lcn/v3/notifications"; public static final String CbamUploadVnfPackagePath="/api/catalog/adapter/vnfpackages"; @@ -64,10 +67,11 @@ public class CommonConstants { public static final String NSLCM_OPERATION_SCALE_IN = "Scalein"; public static final String NSLCM_OPERATION_SCALE_UP = "Scaleup"; public static final String NSLCM_OPERATION_SCALE_DOWN = "Scaledown"; + public static final String NSLCM_OPERATION_HEAL = "Heal"; public static final String CBAM_OPERATION_STATUS_START = "started"; public static final String CBAM_OPERATION_STATUS_PROCESSING = "processing"; - public static final String CBAM_OPERATION_STATUS_FINISH = "finished"; + public static final String CBAM_OPERATION_STATUS_FINISH = "finished"; public static final String CBAM_OPERATION_STATUS_ERROR = "error"; //MSB diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonEnum.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonEnum.java index 06d20dec..52dbfb0e 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonEnum.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonEnum.java @@ -44,7 +44,7 @@ public class CommonEnum { // GrantVnf public enum LifecycleOperation { - Instantiate, Scaleout, Scalein, Scaleup, Scaledown, Terminal + Instantiate, Scaleout, Scalein, Scaleup, Scaledown, Terminal,Heal } public enum type { diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmJobExecutionInfo.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmJobExecutionInfo.java index cf79b052..d8058b97 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmJobExecutionInfo.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmJobExecutionInfo.java @@ -18,35 +18,41 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean; import java.io.Serializable; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; +//import javax.persistence.Column; +//import javax.persistence.Entity; +//import javax.persistence.GeneratedValue; +//import javax.persistence.GenerationType; +//import javax.persistence.Id; +//import javax.persistence.Table; -@Entity -@Table(name = "vnfm_job_execution_info") +//@Entity +//@Table(name = "vnfm_job_execution_info") public class VnfmJobExecutionInfo implements Serializable { private static final long serialVersionUID = -288015953900428312L; - @Id - @GeneratedValue(strategy=GenerationType.AUTO) - @Column(name = "job_id") +// @Id +// @GeneratedValue(strategy=GenerationType.AUTO) +// @Column(name = "job_id") private long jobId; - @Column(name = "vnfm_execution_id") +// @Column(name = "vnfm_execution_id") private String vnfmExecutionId; - @Column(name = "vnf_instance_id") +// @Column(name = "vnf_instance_id") private String vnfInstanceId; - @Column(name = "vnfm_interface_name") +// @Column(name = "vnfm_interface_name") private String vnfmInterfceName; - @Column(name = "status") +// @Column(name = "status") private String status; + +// @Column(name = "operate_start_time") + private long operateStartTime; + +// @Column(name = "operate_end_time") + private long operateEndTime; public long getJobId() { return jobId; @@ -88,6 +94,30 @@ public class VnfmJobExecutionInfo implements Serializable { this.status = status; } + + + + public static long getSerialversionuid() { + return serialVersionUID; + } + + + public long getOperateStartTime() { + return operateStartTime; + } + + public void setOperateStartTime(long operateStartTime) { + this.operateStartTime = operateStartTime; + } + + public long getOperateEndTime() { + return operateEndTime; + } + + public void setOperateEndTime(long operateEndTime) { + this.operateEndTime = operateEndTime; + } + @Override public String toString() { @@ -97,7 +127,9 @@ public class VnfmJobExecutionInfo implements Serializable { + ", vnfInstanceId = " + vnfInstanceId + ", vnfmExecutionId = " + vnfmExecutionId + ", vnfmInterfceName = " + vnfmInterfceName - + ", status = " + status + + ", status = " + status + + ", operateStartTime = "+ operateStartTime + + ", operateEndTime = "+ operateEndTime + "]"; } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmResourceInfo.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmResourceInfo.java index dadb2b9f..c40fe91d 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmResourceInfo.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmResourceInfo.java @@ -18,31 +18,31 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean; import java.io.Serializable; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name="vnfm_resource_info") +//import javax.persistence.Column; +//import javax.persistence.Entity; +//import javax.persistence.GeneratedValue; +//import javax.persistence.GenerationType; +//import javax.persistence.Id; +//import javax.persistence.Table; + +//@Entity +//@Table(name="vnfm_resource_info") public class VnfmResourceInfo implements Serializable { private static final long serialVersionUID = -288015953900428312L; - @Id - @GeneratedValue(strategy = GenerationType.AUTO) +// @Id +// @GeneratedValue(strategy = GenerationType.AUTO) private int id; - @Column(name = "type") +// @Column(name = "type") private ResourceType type; - @Column(name = "resource_definition_id") +// @Column(name = "resource_definition_id") private String resourceDefinitionId; - @Column(name = "vdu") +// @Column(name = "vdu") private String vdu; - @Column(name = "status") +// @Column(name = "status") private String status; public int getId() { diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmSubscriptionInfo.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmSubscriptionInfo.java new file mode 100644 index 00000000..b517657d --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/bean/VnfmSubscriptionInfo.java @@ -0,0 +1,55 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean; + +import java.io.Serializable; + +//import javax.persistence.Column; +//import javax.persistence.Entity; +//import javax.persistence.GeneratedValue; +//import javax.persistence.GenerationType; +//import javax.persistence.Id; +//import javax.persistence.Table; + +//@Entity +//@Table(name = "vnfm_subscription_info") +public class VnfmSubscriptionInfo implements Serializable { + private static final long serialVersionUID = -288015953900428312L; + +// @Id +// @Column(name = "id") + private String id; + + public static long getSerialversionuid() { + return serialVersionUID; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String toString() { + return " VnfmSubscriptionInfo: [ " + super.toString() + ", id = " + id + "]"; + + } + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/mapper/VnfcResourceInfoMapper.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/mapper/VnfcResourceInfoMapper.java new file mode 100644 index 00000000..74eb3cb7 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/mapper/VnfcResourceInfoMapper.java @@ -0,0 +1,47 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper; + +import java.util.List; + +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AffectedVnfc; + +@Mapper +public interface VnfcResourceInfoMapper { + @Select("SELECT * FROM vnfm_vnfc_resource_info where vnf_instance_id = #{vnfInstanceId}") + @Results({ + @Result(property = "vnfInstanceId", column = "vnf_instance_id"), + @Result(property = "vnfcInstanceId", column = "vnfc_instance_id"), + @Result(property = "vduId", column = "vdu_id"), + @Result(property = "vimid", column = "vim_id"), + @Result(property = "vmid", column = "vm_id"), + @Result(property = "changeType", column = "change_type") + }) + List<AffectedVnfc> getAllByInstanceId(String vnfInstanceId); + + @Insert("INSERT INTO vnfm_vnfc_resource_info(vnf_instance_id,vnfc_instance_id,vdu_id,vim_id, vm_id, change_type) VALUES(#{vnfInstanceId}, #{vnfcInstanceId}, #{vduId}, #{vimid}, #{vmid}, #{changeType})") + void insert(AffectedVnfc resource); + + @Delete("DELETE FROM vnfm_vnfc_resource_info WHERE vnf_instance_id = #{vnfcInstanceId}") + void deleteByInstanceId(String vnfcInstanceId); +}
\ No newline at end of file diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/mapper/VnfmJobExecutionMapper.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/mapper/VnfmJobExecutionMapper.java new file mode 100644 index 00000000..c95c49c2 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/mapper/VnfmJobExecutionMapper.java @@ -0,0 +1,76 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper; + +import java.util.List; + +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; + +@Mapper +public interface VnfmJobExecutionMapper { + @Select("SELECT * FROM vnfm_job_execution_info") + @Results({ + @Result(property = "jobId", column = "job_id"), + @Result(property = "vnfmExecutionId", column = "vnfm_execution_id"), + @Result(property = "vnfInstanceId", column = "vnf_instance_id"), + @Result(property = "vnfmInterfceName", column = "vnfm_interface_name"), + @Result(property = "status", column = "status"), + @Result(property = "operateStartTime", column = "operate_start_time"), + @Result(property = "operateEndTime", column = "operate_end_time") + }) + List<VnfmJobExecutionInfo> getAll(); + + @Select("SELECT * FROM vnfm_job_execution_info WHERE job_id = #{jobId}") + @Results({ + @Result(property = "jobId", column = "job_id"), + @Result(property = "vnfmExecutionId", column = "vnfm_execution_id"), + @Result(property = "vnfInstanceId", column = "vnf_instance_id"), + @Result(property = "vnfmInterfceName", column = "vnfm_interface_name"), + @Result(property = "status", column = "status"), + @Result(property = "operateStartTime", column = "operate_start_time"), + @Result(property = "operateEndTime", column = "operate_end_time") + }) + VnfmJobExecutionInfo findOne(Long jobId); + + @Insert("INSERT INTO vnfm_job_execution_info(vnfm_execution_id,vnf_instance_id,vnfm_interface_name,status,operate_start_time, operate_end_time) VALUES(#{vnfmExecutionId}, #{vnfInstanceId}, #{vnfmInterfceName}, #{status}, #{operateStartTime}, #{operateEndTime})") + void insert(VnfmJobExecutionInfo user); + + @Update("UPDATE vnfm_job_execution_info SET vnfm_execution_id=#{vnfmExecutionId},vnf_instance_id=#{vnfInstanceId},vnfm_interface_name=#{vnfmInterfceName},status=#{status},operate_start_time=#{operateStartTime}, operate_end_time=#{operateEndTime} WHERE job_id =#{jobId}") + void update(VnfmJobExecutionInfo user); + + @Delete("DELETE FROM vnfm_job_execution_info WHERE id =#{id}") + void delete(Long id); + + @Select("select * from vnfm_job_execution_info where job_id = (select max(job_id) from vnfm_job_execution_info)") + @Results({ + @Result(property = "jobId", column = "job_id"), + @Result(property = "vnfmExecutionId", column = "vnfm_execution_id"), + @Result(property = "vnfInstanceId", column = "vnf_instance_id"), + @Result(property = "vnfmInterfceName", column = "vnfm_interface_name"), + @Result(property = "status", column = "status"), + @Result(property = "operateStartTime", column = "operate_start_time"), + @Result(property = "operateEndTime", column = "operate_end_time") + }) + VnfmJobExecutionInfo findNewestJobInfo(); +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/mapper/VnfmSubscriptionsMapper.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/mapper/VnfmSubscriptionsMapper.java new file mode 100644 index 00000000..6840cf39 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/mapper/VnfmSubscriptionsMapper.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper; + +import java.util.List; + +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmSubscriptionInfo; + +@Mapper +public interface VnfmSubscriptionsMapper { + @Select("SELECT * FROM vnfm_subscription_info") + @Results({ + @Result(property = "id", column = "id"), + }) + List<VnfmSubscriptionInfo> getAll(); + + @Select("SELECT * FROM vnfm_subscription_info WHERE id = #{id}") + @Results({ + @Result(property = "id", column = "id"), + }) + VnfmSubscriptionInfo findOne(String id); + +// @Insert("INSERT INTO vnfm_subscription_info(id) VALUES(#{id})") +// void insert(VnfmJobExecutionInfo user); + + @Insert("INSERT INTO vnfm_subscription_info(id) VALUES(#{id})") + void insert(String id); + + @Delete("DELETE FROM vnfm_subscription_info WHERE id =#{id}") + void delete(String id); +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmJobExecutionRepository.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmJobExecutionRepository.java index a499f452..4726d9c2 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmJobExecutionRepository.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmJobExecutionRepository.java @@ -15,9 +15,7 @@ */ package org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; -import org.springframework.data.repository.CrudRepository; - -public interface VnfmJobExecutionRepository extends CrudRepository< VnfmJobExecutionInfo, Long> { +public interface VnfmJobExecutionRepository //extends CrudRepository< VnfmJobExecutionInfo, Long> +{ } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmResourceRepository.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmResourceRepository.java index 52d41927..1c8456bd 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmResourceRepository.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmResourceRepository.java @@ -15,9 +15,7 @@ */ package org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmResourceInfo; -import org.springframework.data.repository.CrudRepository; - -public interface VnfmResourceRepository extends CrudRepository<VnfmResourceInfo, Integer> { +public interface VnfmResourceRepository //extends CrudRepository<VnfmResourceInfo, Integer> +{ } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmSubscriptionsRepository.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmSubscriptionsRepository.java new file mode 100644 index 00000000..e5d3bd7d --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/db/repository/VnfmSubscriptionsRepository.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository; + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmSubscriptionInfo; +//import org.springframework.data.repository.CrudRepository; + +public interface VnfmSubscriptionsRepository //extends CrudRepository<VnfmSubscriptionInfo, Integer> +{ + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/CbamNofiticationSubscription.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/CbamNofiticationSubscription.java new file mode 100644 index 00000000..32cb2fa0 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/CbamNofiticationSubscription.java @@ -0,0 +1,93 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.init; + +import java.io.IOException; +import java.util.List; + +import org.apache.http.client.ClientProtocolException; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmSubscriptionInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmSubscriptionsMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +//@Order(3) +//@Component +public class CbamNofiticationSubscription implements ApplicationRunner { + private static final Logger logger = LoggerFactory.getLogger(CbamNofiticationSubscription.class); + + @Autowired + AdaptorEnv adaptorEnv; + + @Autowired + private CbamMgmrInf cbamMgmr; + + @Autowired + private VnfmSubscriptionsMapper subscriptionsMapper; + + @Override + public void run(ApplicationArguments args){ + boolean subscribed = false; + List<VnfmSubscriptionInfo> allSubscripions = subscriptionsMapper.getAll(); + if(allSubscripions != null && !allSubscripions.isEmpty()) + { + for(VnfmSubscriptionInfo subscriptionInfo : allSubscripions) + { + try { + Subscription subscription = cbamMgmr.getSubscription(subscriptionInfo.getId()); + if(subscription != null) + { + subscribed = true; + logger.info("CBAM Notification has already been subscribed with id = " + subscriptionInfo.getId()); + } + else + { + subscriptionsMapper.delete(subscriptionInfo.getId()); + } + } catch (Exception e) { + logger.error("Query or delete subscription error.", e); + } + } + } + + if(!subscribed) + { + CBAMCreateSubscriptionRequest subscriptionRequest = new CBAMCreateSubscriptionRequest(); + subscriptionRequest.setCallbackUrl(adaptorEnv.getDriverApiUriFront() + "/api/nokiavnfmdriver/v1/notifications"); + try { + CBAMCreateSubscriptionResponse createSubscription = cbamMgmr.createSubscription(subscriptionRequest); + if(createSubscription != null) + { + subscriptionsMapper.insert(createSubscription.getId()); + logger.info("CBAM Notification is successfully subscribed with id = " + createSubscription.getId()); + } + } catch (Exception e) { + logger.error("Subscribe notification error.", e); + } + } + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/EnvVariablesInitialization.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/EnvVariablesInitialization.java index 81cc281d..b9d4e878 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/EnvVariablesInitialization.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/EnvVariablesInitialization.java @@ -30,8 +30,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; +import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; +@Order(1) @Component public class EnvVariablesInitialization implements ApplicationRunner { private static final Logger logger = LoggerFactory.getLogger(EnvVariablesInitialization.class); diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/service/MsbServiceRegister.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/MsbServiceRegister.java index d9a36e08..4358fb05 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/service/MsbServiceRegister.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/MsbServiceRegister.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.onap.vfc.nfvo.driver.vnfm.svnfm.msb.service; +package org.onap.vfc.nfvo.driver.vnfm.svnfm.init; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,8 +22,10 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.msb.inf.IMsbMgmr; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; +import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; +@Order(2) @Component public class MsbServiceRegister implements ApplicationRunner{ private static final Logger logger = LoggerFactory.getLogger(MsbServiceRegister.class); diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImpl.java index e89eabe1..74fb4395 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImpl.java @@ -18,6 +18,8 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.msb.impl; import java.io.IOException; import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.http.client.ClientProtocolException; import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; @@ -35,6 +37,9 @@ import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestMethod; import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; @Component public class MsbMgmrImpl implements IMsbMgmr { @@ -82,32 +87,31 @@ public class MsbMgmrImpl implements IMsbMgmr { private String readVfcAdaptorInfoFromJsonFile() throws IOException { String filePath = "/etc/adapterInfo/vnfmadapterinfo.json"; - String fileContent = CommonUtil.getJsonStrFromFile(filePath); - + String fileContent = CommonUtil.getJsonStrFromFile(filePath); return fileContent; } @Override public void unregister() { - try { - String url = adaptorEnv.getMsbApiUriFront() + String.format(CommonConstants.MSB_UNREGISTER_SERVICE_PATH); - - HttpResult httpResult = httpClientProcessor.process(url, RequestMethod.DELETE, null, null); - String responseStr = httpResult.getContent(); - - logger.info("MsbMgmrImpl -> unregister, responseStr is " + responseStr); - if(httpResult.getStatusCode() == 204) - { - logger.info("MsbMgmrImpl -> register, Successfully "); - } - else - { - logger.error("MsbMgmrImpl -> register Error, statusCode = " + httpResult.getStatusCode()); - } - - } catch (Exception e) { - logger.error("IOException Failed to unregister nokia vnfm driver! ", e); - } +// try { +// String url = adaptorEnv.getMsbApiUriFront() + String.format(CommonConstants.MSB_UNREGISTER_SERVICE_PATH); +// +// HttpResult httpResult = httpClientProcessor.process(url, RequestMethod.DELETE, null, null); +// String responseStr = httpResult.getContent(); +// +// logger.info("MsbMgmrImpl -> unregister, responseStr is " + responseStr); +// if(httpResult.getStatusCode() == 204) +// { +// logger.info("MsbMgmrImpl -> register, Successfully "); +// } +// else +// { +// logger.error("MsbMgmrImpl -> register Error, statusCode = " + httpResult.getStatusCode()); +// } +// +// } catch (Exception e) { +// logger.error("IOException Failed to unregister nokia vnfm driver! ", e); +// } } @@ -142,9 +146,11 @@ public class MsbMgmrImpl implements IMsbMgmr { this.adaptorEnv = env; } - public static final void main(String[] args) { - MsbMgmrImpl impl = new MsbMgmrImpl(); - impl.register(); - } +// public static final void main(String[] args) { +//// MsbMgmrImpl impl = new MsbMgmrImpl(); +//// impl.register(); +// System.setProperty("catalina.base", "D:\\Install\\apache-tomcat-9.0.0.M26"); +// System.out.println(System.getProperty("catalina.base")); +// } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/bo/entity/AffectedVnfc.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/bo/entity/AffectedVnfc.java index a586cfc4..c8e1c917 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/bo/entity/AffectedVnfc.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/bo/entity/AffectedVnfc.java @@ -17,9 +17,13 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; public class AffectedVnfc { + @JsonIgnore + private String vnfInstanceId; + @JsonProperty("vnfcInstanceId") private String vnfcInstanceId; @@ -74,6 +78,14 @@ public class AffectedVnfc { public void setVmid(String vmid) { this.vmid = vmid; } + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverController.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverController.java index c51717d8..b6bf3eb0 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverController.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverController.java @@ -18,10 +18,13 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.controller; import java.io.IOException; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.apache.http.HttpStatus; +import org.apache.http.client.ClientProtocolException; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse; @@ -36,6 +39,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfmDriverMgmrInf; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -55,19 +59,24 @@ public class VnfmDriverController { @Autowired private VnfmDriverMgmrInf vnfmDriverMgmr; + @Autowired + private CbamMgmrInf cbamMgmr; + private Gson gson = new Gson(); @RequestMapping(value = "/swagger.json", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public String apidoc() throws IOException { - ClassLoader classLoader = getClass().getClassLoader(); +// String client = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getRemoteAddr(); + ClassLoader classLoader = getClass().getClassLoader(); return IOUtils.toString(classLoader.getResourceAsStream("swagger.json")); } @RequestMapping(value = "/{vnfmId}/vnfs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody + @ResponseBody public InstantiateVnfResponse instantiateVnf(@RequestBody InstantiateVnfRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse) { + MDC.put("MDCtest", "MDCtest_001"); String jsonString = gson.toJson(request); logger.info("instantiateVnf request: vnfmId = " + vnfmId + ", bodyMessage is " + jsonString); @@ -186,6 +195,31 @@ public class VnfmDriverController { return null; } + +// @RequestMapping(value = "/notifications", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) +// public CBAMVnfNotificationResponse notificationVnf(@RequestBody CBAMVnfNotificationRequest request, HttpServletResponse httpResponse) throws ClientProtocolException, Exception + @RequestMapping(value = "/notifications") +// @ResponseBody + public void notificationVnf(HttpServletRequest request, HttpServletResponse httpResponse) throws ClientProtocolException, Exception + { + +// String jsonString = gson.toJson(request); +// logger.info("notificationVnf request: bodyMessage is " + jsonString); + logger.info("notificationVnf request: bodyMessage is " + request.getMethod() + ","); + + try { +// CBAMVnfNotificationResponse response = cbamMgmr.getNotification(request); + httpResponse.setStatus(204); +// logger.info("cbamController --> notificationVnf response is " + gson.toJson(response)); +// return response; + } + catch(VnfmDriverException e) + { + processControllerException(httpResponse, e); + } + +// return null; + } private void processControllerException(HttpServletResponse httpResponse, VnfmDriverException e) { try { diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/impl/VnfContinueProcessorImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/impl/VnfContinueProcessorImpl.java index 93c52b07..b9fb3e81 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/impl/VnfContinueProcessorImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/impl/VnfContinueProcessorImpl.java @@ -19,13 +19,18 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.impl; import java.util.concurrent.Executors; import org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor.Driver2CbamRequestConverter; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor.HealVnfContinueRunnable; import org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor.InstantiateVnfContinueRunnable; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor.ScaleVnfContinueRunnable; import org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor.TerminateVnfContinueRunnable; import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfcResourceInfoMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfContinueProcessorInf; import org.springframework.stereotype.Component; @@ -34,19 +39,39 @@ import org.springframework.stereotype.Component; public class VnfContinueProcessorImpl implements VnfContinueProcessorInf{ @Override - public void continueInstantiateVnf(String vnfmId, InstantiateVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CatalogMgmrInf catalogMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionRepository jobDbManager) { + public void continueInstantiateVnf(String vnfmId, InstantiateVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CatalogMgmrInf catalogMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper jobDbManager, VnfcResourceInfoMapper vnfcDbMgmr) { InstantiateVnfContinueRunnable task = new InstantiateVnfContinueRunnable(vnfmId, driverRequest, vnfInstanceId, jobId, - nslcmMgmr, catalogMgmr, cbamMgmr, requestConverter, jobDbManager); + nslcmMgmr, catalogMgmr, cbamMgmr, requestConverter, jobDbManager, vnfcDbMgmr); Executors.newSingleThreadExecutor().submit(task); } @Override - public void continueTerminateVnf(String vnfmId, TerminateVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionRepository jobDbManager) { + public void continueTerminateVnf(String vnfmId, TerminateVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper jobDbManager, VnfcResourceInfoMapper vnfcDbMgmr) { TerminateVnfContinueRunnable task = new TerminateVnfContinueRunnable(vnfmId, driverRequest, vnfInstanceId, jobId, + nslcmMgmr, cbamMgmr, requestConverter, jobDbManager, vnfcDbMgmr); + + Executors.newSingleThreadExecutor().submit(task); + } + + @Override + public void continueScaleVnf(String vnfmId, ScaleVnfRequest driverRequest, String vnfInstanceId, String jobId, + NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, + VnfmJobExecutionMapper jobDbManager) { + ScaleVnfContinueRunnable task = new ScaleVnfContinueRunnable(vnfmId, driverRequest, vnfInstanceId, jobId, nslcmMgmr, cbamMgmr, requestConverter, jobDbManager); + Executors.newSingleThreadExecutor().submit(task); + } + + @Override + public void continueHealVnf(String vnfmId, HealVnfRequest driverRequest, String vnfInstanceId, String jobId, + NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, + VnfmJobExecutionMapper jobDbManager) { + HealVnfContinueRunnable task = new HealVnfContinueRunnable(vnfmId, driverRequest, vnfInstanceId, jobId, + nslcmMgmr, cbamMgmr, requestConverter, jobDbManager); Executors.newSingleThreadExecutor().submit(task); + } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/inf/VnfContinueProcessorInf.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/inf/VnfContinueProcessorInf.java index 6f9eb036..e0c1b6d0 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/inf/VnfContinueProcessorInf.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/inf/VnfContinueProcessorInf.java @@ -19,12 +19,17 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor.Driver2CbamRequestConverter; import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfcResourceInfoMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest; public interface VnfContinueProcessorInf { - public void continueInstantiateVnf(String vnfmId, InstantiateVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CatalogMgmrInf catalogMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionRepository jobDbManager); - public void continueTerminateVnf(String vnfmId, TerminateVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionRepository jobDbManager); + public void continueInstantiateVnf(String vnfmId, InstantiateVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CatalogMgmrInf catalogMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper jobDbManager, VnfcResourceInfoMapper vnfcDbMgmr); + public void continueTerminateVnf(String vnfmId, TerminateVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper jobDbManager, VnfcResourceInfoMapper vnfcDbMgmr); + public void continueScaleVnf(String vnfmId, ScaleVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper jobDbManager); + public void continueHealVnf(String vnfmId, HealVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionMapper jobDbManager); } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/application.properties b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/application.properties index 5665ff0b..7ed68a98 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/application.properties +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/application.properties @@ -16,21 +16,24 @@ server.error.whitelabel.enabled=false ## for MySql Database begin ## -spring.jpa.show-sql=true -spring.jpa.generate-ddl=true -spring.jpa.hibernate.ddl-auto=update -spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +#spring.jpa.show-sql=true +#spring.jpa.generate-ddl=true +#spring.jpa.hibernate.ddl-auto=update +#spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect spring.jackson.serialization.indent_output=false +#mybatis configuration +mybatis.type-aliases-package=org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean +spring.datasource.driverClassName = com.mysql.jdbc.Driver spring.datasource.username=vnfm spring.datasource.password=vnfmpass spring.datasource.url=jdbc:mysql://127.0.0.1:3306/vnfm_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=round&useSSL=false -spring.datasource.driver-class-name=com.mysql.jdbc.Driver -spring.datasource.tomcat.max-wait=30000 -spring.datasource.tomcat.max-active=20 -spring.datasource.tomcat.test-on-borrow=true +#spring.datasource.driver-class-name=com.mysql.jdbc.Driver +#spring.datasource.tomcat.max-wait=30000 +#spring.datasource.tomcat.max-active=20 +#spring.datasource.tomcat.test-on-borrow=true ## for MySql Database end ## ## for logging begin ## @@ -64,3 +67,10 @@ type=vdu sizeOfStorage=40 virtualMemSize=8192 numVirtualCpu=4 + +##OperateTaskProgress +initialProgress=10 +instantiateTimeInterval=60000 +terminateTimeInterval=8000 + +driverApiUriFront=http://127.0.0.1:8486 diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/logback.xml b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/logback.xml new file mode 100644 index 00000000..d1be476b --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/logback.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <include resource="org/springframework/boot/logging/logback/defaults.xml" /> + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg %n</pattern> + <charset>UTF-8</charset> + </encoder> + </appender> + <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${catalina.base}/logs/vfcadaptor.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${catalina.base}/logs/vfcadaptor.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>10MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %X{req.method} %X{req.remoteHost} %X{req.requestURI} [%t] %-5level %logger{50} %line - %m%n</pattern> + <charset>UTF-8</charset> <!-- 此处设置字符集 --> + </encoder> + </appender> + <root level="INFO"> + <appender-ref ref="CONSOLE"></appender-ref> + <appender-ref ref="FILE"></appender-ref> + </root> +</configuration>
\ No newline at end of file diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/webapp/WEB-INF/web.xml b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/webapp/WEB-INF/web.xml index e6aa9856..c2a984b8 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/webapp/WEB-INF/web.xml +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/webapp/WEB-INF/web.xml @@ -11,6 +11,16 @@ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> --> + <filter> + <filter-name>MDCInsertingServletFilter</filter-name> + <filter-class> + ch.qos.logback.classic.helpers.MDCInsertingServletFilter + </filter-class> + </filter> + <filter-mapping> + <filter-name>MDCInsertingServletFilter</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/HealVnfContinueRunnableTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/HealVnfContinueRunnableTest.java new file mode 100644 index 00000000..e2d431f1 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/HealVnfContinueRunnableTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; + +public class HealVnfContinueRunnableTest { + @InjectMocks + private HealVnfContinueRunnable healVnfContinueRunnable; + + @Mock + private CbamMgmrInf cbamMgmr; + + @Mock + private NslcmMgmrInf nslcmMgmr; + + @Mock + private VnfmJobExecutionMapper jobDbMgmr; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + HealVnfRequest driverRequest = new HealVnfRequest(); + Driver2CbamRequestConverter requestConverter = new Driver2CbamRequestConverter(); + String vnfInstanceId = "vnfInstanceId_001"; + String jobId = "001"; + String vnfmId = "vnfmId_001"; + + healVnfContinueRunnable.setDriverRequest(driverRequest); + healVnfContinueRunnable.setRequestConverter(requestConverter); + healVnfContinueRunnable.setVnfInstanceId(vnfInstanceId); + healVnfContinueRunnable.setJobId(jobId); + healVnfContinueRunnable.setVnfmId(vnfmId); + + NslcmGrantVnfResponse grantResponse = new NslcmGrantVnfResponse(); + CBAMHealVnfResponse cbamResponse = new CBAMHealVnfResponse(); + cbamResponse.setId("1"); + VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo(); + execInfo.setJobId(1L); + + when(nslcmMgmr.grantVnf(Mockito.any(NslcmGrantVnfRequest.class))).thenReturn(grantResponse); + when(cbamMgmr.healVnf(Mockito.any(CBAMHealVnfRequest.class), Mockito.anyString())).thenReturn(cbamResponse); + when(jobDbMgmr.findOne(Mockito.anyLong())).thenReturn(execInfo); + doNothing().when(jobDbMgmr).update(Mockito.any(VnfmJobExecutionInfo.class)); + + } + + @Test + public void testRun() + { + healVnfContinueRunnable.run(); + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnableTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnableTest.java new file mode 100644 index 00000000..d4d13458 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnableTest.java @@ -0,0 +1,115 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMModifyVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMModifyVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryOperExecutionResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ComputeResource; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfcResourceInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.OperationStatus; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfcResourceInfoMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AffectedVnfc; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; + +public class InstantiateVnfContinueRunnableTest{ + @InjectMocks + private InstantiateVnfContinueRunnable instantiateVnfContinueRunnable; + + @Mock + private CbamMgmrInf cbamMgmr; + + @Mock + private NslcmMgmrInf nslcmMgmr; + + @Mock + private VnfmJobExecutionMapper jobDbMgmr; + + @Mock + private VnfcResourceInfoMapper vnfcDbMgmr; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + InstantiateVnfRequest driverRequest = new InstantiateVnfRequest(); + Driver2CbamRequestConverter requestConverter = new Driver2CbamRequestConverter(); + + instantiateVnfContinueRunnable.setDriverRequest(driverRequest); + instantiateVnfContinueRunnable.setJobId("1"); + instantiateVnfContinueRunnable.setVnfInstanceId("001"); + instantiateVnfContinueRunnable.setVnfmId("001"); + instantiateVnfContinueRunnable.setRequestConverter(requestConverter); + + NslcmGrantVnfResponse grantResponse = new NslcmGrantVnfResponse(); + CBAMInstantiateVnfResponse cbamResponse = new CBAMInstantiateVnfResponse(); + cbamResponse.setId("1"); + CBAMModifyVnfResponse modifyResponse = new CBAMModifyVnfResponse(); + modifyResponse.setId("2"); + VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo(); + execInfo.setJobId(1L); + + CBAMQueryOperExecutionResponse exeResponse = new CBAMQueryOperExecutionResponse(); + exeResponse.setStatus(OperationStatus.FINISHED); + + List<VnfcResourceInfo> vnfcResources = new ArrayList<>(); + VnfcResourceInfo res = new VnfcResourceInfo(); + res.setId("1"); + res.setVduId("vduId"); + ComputeResource computeResource = new ComputeResource(); + computeResource.setResourceId("resourceId"); + computeResource.setResourceType("OS::Nova::Server"); + computeResource.setVimId("vimId"); + res.setComputeResource(computeResource); + + vnfcResources.add(res); + + when(nslcmMgmr.grantVnf(Mockito.any(NslcmGrantVnfRequest.class))).thenReturn(grantResponse); + when(cbamMgmr.instantiateVnf(Mockito.any(CBAMInstantiateVnfRequest.class), Mockito.anyString())).thenReturn(cbamResponse); + when(cbamMgmr.modifyVnf(Mockito.any(CBAMModifyVnfRequest.class), Mockito.anyString())).thenReturn(modifyResponse); + when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(exeResponse); + when(cbamMgmr.queryVnfcResource(Mockito.anyString())).thenReturn(vnfcResources); + when(jobDbMgmr.findOne(Mockito.anyLong())).thenReturn(execInfo); + doNothing().when(jobDbMgmr).update(Mockito.any(VnfmJobExecutionInfo.class)); + doNothing().when(vnfcDbMgmr).insert(Mockito.any(AffectedVnfc.class)); + } + + @Test + public void testRun() + { + instantiateVnfContinueRunnable.run(); + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/ScaleVnfContinueRunnableTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/ScaleVnfContinueRunnableTest.java new file mode 100644 index 00000000..b2109a13 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/ScaleVnfContinueRunnableTest.java @@ -0,0 +1,83 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest; + +public class ScaleVnfContinueRunnableTest{ + @InjectMocks + private ScaleVnfContinueRunnable scaleVnfContinueRunnable; + + @Mock + private CbamMgmrInf cbamMgmr; + + @Mock + private NslcmMgmrInf nslcmMgmr; + + @Mock + private VnfmJobExecutionMapper jobDbMgmr; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + ScaleVnfRequest driverRequest = new ScaleVnfRequest(); + driverRequest.setType(ScaleType.SCALE_IN); + Driver2CbamRequestConverter requestConverter = new Driver2CbamRequestConverter(); + + scaleVnfContinueRunnable.setDriverRequest(driverRequest); + scaleVnfContinueRunnable.setJobId("1"); + scaleVnfContinueRunnable.setType(ScaleType.SCALE_IN); + scaleVnfContinueRunnable.setVnfInstanceId("001"); + scaleVnfContinueRunnable.setVnfmId("001"); + scaleVnfContinueRunnable.setRequestConverter(requestConverter); + + NslcmGrantVnfResponse grantResponse = new NslcmGrantVnfResponse(); + CBAMScaleVnfResponse cbamResponse = new CBAMScaleVnfResponse(); + cbamResponse.setId("1"); + VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo(); + execInfo.setJobId(1L); + + when(nslcmMgmr.grantVnf(Mockito.any(NslcmGrantVnfRequest.class))).thenReturn(grantResponse); + when(cbamMgmr.scaleVnf(Mockito.any(CBAMScaleVnfRequest.class), Mockito.anyString())).thenReturn(cbamResponse); + when(jobDbMgmr.findOne(Mockito.anyLong())).thenReturn(execInfo); + doNothing().when(jobDbMgmr).update(Mockito.any(VnfmJobExecutionInfo.class)); + } + + @Test + public void testRun() + { + scaleVnfContinueRunnable.run(); + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/TermiateVnfContinueRunnableTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/TermiateVnfContinueRunnableTest.java new file mode 100644 index 00000000..96808ad7 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/TermiateVnfContinueRunnableTest.java @@ -0,0 +1,110 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMModifyVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryOperExecutionResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ComputeResource; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfcResourceInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.OperationStatus; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfcResourceInfoMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AffectedVnfc; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest; + +public class TermiateVnfContinueRunnableTest{ + @InjectMocks + private TerminateVnfContinueRunnable terminateVnfContinueRunnable; + + @Mock + private CbamMgmrInf cbamMgmr; + + @Mock + private NslcmMgmrInf nslcmMgmr; + + @Mock + private VnfmJobExecutionMapper jobDbMgmr; + + @Mock + private VnfcResourceInfoMapper vnfcDbMgmr;; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + TerminateVnfRequest driverRequest = new TerminateVnfRequest(); + Driver2CbamRequestConverter requestConverter = new Driver2CbamRequestConverter(); + + terminateVnfContinueRunnable.setDriverRequest(driverRequest); + terminateVnfContinueRunnable.setJobId("1"); + terminateVnfContinueRunnable.setVnfInstanceId("001"); + terminateVnfContinueRunnable.setVnfmId("001"); + terminateVnfContinueRunnable.setRequestConverter(requestConverter); + + NslcmGrantVnfResponse grantResponse = new NslcmGrantVnfResponse(); + CBAMTerminateVnfResponse cbamResponse = new CBAMTerminateVnfResponse(); + cbamResponse.setId("1"); + CBAMModifyVnfResponse modifyResponse = new CBAMModifyVnfResponse(); + modifyResponse.setId("2"); + VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo(); + execInfo.setJobId(1L); + + CBAMQueryOperExecutionResponse exeResponse = new CBAMQueryOperExecutionResponse(); + exeResponse.setStatus(OperationStatus.FINISHED); + + List<AffectedVnfc> vnfcResources = new ArrayList<>(); + + CBAMQueryVnfResponse cQueryVnfResponse = new CBAMQueryVnfResponse(); + cQueryVnfResponse.setInstantiationState(CommonEnum.InstantiationState.NOT_INSTANTIATED); + + when(nslcmMgmr.grantVnf(Mockito.any(NslcmGrantVnfRequest.class))).thenReturn(grantResponse); + when(cbamMgmr.terminateVnf(Mockito.any(CBAMTerminateVnfRequest.class), Mockito.anyString())).thenReturn(cbamResponse); + when(cbamMgmr.queryVnf(Mockito.anyString())).thenReturn(cQueryVnfResponse); + doNothing().when(cbamMgmr).deleteVnf(Mockito.anyString()); + + when(vnfcDbMgmr.getAllByInstanceId(Mockito.anyString())).thenReturn(vnfcResources); + when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(exeResponse); + when(jobDbMgmr.findOne(Mockito.anyLong())).thenReturn(execInfo); + doNothing().when(jobDbMgmr).update(Mockito.any(VnfmJobExecutionInfo.class)); + } + + @Test + public void testRun() + { + terminateVnfContinueRunnable.run(); + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java index b47cc4db..f3fb6f3b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java @@ -49,7 +49,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; @@ -82,7 +82,7 @@ public class VnfmDriverMgmrImplTest { private NslcmMgmrInf nslcmMgmr;; @Mock - private VnfmJobExecutionRepository jobDbManager; + private VnfmJobExecutionMapper jobDbManager; @Mock private VnfContinueProcessorInf vnfContinueProcessorInf; @@ -96,6 +96,8 @@ public class VnfmDriverMgmrImplTest { private String vnfmId = "vnfmId_001"; private String vnfInstanceId = "vnfInstanceId_001"; + private ScaleType type; + private String protocol = "https"; private String ip = "139.234.34.43"; private String port = "99"; @@ -135,7 +137,7 @@ public class VnfmDriverMgmrImplTest { execInfo.setVnfmExecutionId("executionId_001"); execInfo.setVnfInstanceId(vnfInstanceId); - when(jobDbManager.save(Mockito.any(VnfmJobExecutionInfo.class))).thenReturn(execInfo); + when(jobDbManager.findNewestJobInfo()).thenReturn(execInfo); } @Test @@ -200,6 +202,7 @@ public class VnfmDriverMgmrImplTest { VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo(); execInfo.setJobId(1L); execInfo.setVnfmExecutionId("executionId_001"); + execInfo.setStatus("finished"); when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo); CBAMQueryOperExecutionResponse cbamResponse = new CBAMQueryOperExecutionResponse(); @@ -208,7 +211,7 @@ public class VnfmDriverMgmrImplTest { cbamResponse.setGrantId("001002001"); // when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(cbamResponse); -// OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1"); + OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1"); // // Assert.assertEquals("executionId_001", response.getJobId()); } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java index 900e7021..aba3d88b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.when; import java.io.IOException; import java.util.HashMap; +import java.util.List; import org.apache.http.client.ClientProtocolException; import org.junit.Before; @@ -28,17 +29,26 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMModifyVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMModifyVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryOperExecutionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfcResourceInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpResult; @@ -61,6 +71,7 @@ public class CbamMgmrImplTest { String json = "{\"access_token\":\"1234567\"}"; HttpResult httpResult = new HttpResult(); + httpResult.setStatusCode(200); httpResult.setContent(json); when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); @@ -81,6 +92,13 @@ public class CbamMgmrImplTest { } @Test + public void testModifyVnf() throws ClientProtocolException, IOException + { + CBAMModifyVnfRequest cbamRequest = new CBAMModifyVnfRequest(); + CBAMModifyVnfResponse response = cbamMgmr.modifyVnf(cbamRequest, vnfInstanceId); + } + + @Test public void testTerminateVnf() throws ClientProtocolException, IOException { CBAMTerminateVnfRequest cbamRequest = new CBAMTerminateVnfRequest(); @@ -112,4 +130,51 @@ public class CbamMgmrImplTest { { CBAMQueryVnfResponse response = cbamMgmr.queryVnf(vnfInstanceId); } + + @Test + public void testCreateSubscription() throws ClientProtocolException, IOException + { + CBAMCreateSubscriptionRequest cbamRequest = new CBAMCreateSubscriptionRequest(); + CBAMCreateSubscriptionResponse response = cbamMgmr.createSubscription(cbamRequest); + } + + @Test + public void testGetNotification() throws ClientProtocolException, IOException + { + CBAMVnfNotificationRequest cbamRequest = new CBAMVnfNotificationRequest(); + CBAMVnfNotificationResponse response = cbamMgmr.getNotification(cbamRequest); + } + + @Test + public void testGetSubscription() throws ClientProtocolException, IOException + { + String subscriptionId = "subscriptionId_001"; + Subscription response = cbamMgmr.getSubscription(subscriptionId); + } + + @Test + public void testQueryVnfcResource() throws ClientProtocolException, IOException + { + String json = "[{'id':'id_001'}]"; + HttpResult httpResult = new HttpResult(); + httpResult.setStatusCode(200); + httpResult.setContent(json); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + List<VnfcResourceInfo> response = cbamMgmr.queryVnfcResource(vnfInstanceId); + } + + @Test + public void testQueryOperExecution() throws ClientProtocolException, IOException + { + String execId = "execId_001"; + CBAMQueryOperExecutionResponse response = cbamMgmr.queryOperExecution(execId); + } + + @Test + public void testUploadVnfPackage() throws ClientProtocolException, IOException + { + String cbamPackageFilePath = "cbamPackageFilePath_001"; + cbamMgmr.uploadVnfPackage(cbamPackageFilePath); + } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImplTest.java index aa1a0217..1b9be3b4 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImplTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImplTest.java @@ -52,6 +52,7 @@ public class MsbMgmrImplTest { String json = "{\"serviceName\":\"catalog\", \"url\":\"/api/catalog/v1\"}"; HttpResult httpResult = new HttpResult(); httpResult.setContent(json); + httpResult.setStatusCode(200); when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/service/MsbServiceRegisterTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/service/MsbServiceRegisterTest.java index 8741bc80..0319735a 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/service/MsbServiceRegisterTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/service/MsbServiceRegisterTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.init.MsbServiceRegister; import org.onap.vfc.nfvo.driver.vnfm.svnfm.msb.inf.IMsbMgmr; import org.springframework.boot.ApplicationArguments; |