2  * Copyright 2016-2017, Nokia Corporation
 
   4  * Licensed under the Apache License, Version 2.0 (the "License");
 
   5  * you may not use this file except in compliance with the License.
 
   6  * You may obtain a copy of the License at
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  10  * Unless required by applicable law or agreed to in writing, software
 
  11  * distributed under the License is distributed on an "AS IS" BASIS,
 
  12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13  * See the License for the specific language governing permissions and
 
  14  * limitations under the License.
 
  17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor;
 
  19 import java.io.BufferedInputStream;
 
  20 import java.io.FileInputStream;
 
  21 import java.io.FileNotFoundException;
 
  22 import java.io.IOException;
 
  23 import java.io.InputStream;
 
  25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest;
 
  26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest;
 
  27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest;
 
  28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest;
 
  29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest;
 
  30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.util.CommonUtil;
 
  31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleDirection;
 
  32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType;
 
  33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse;
 
  34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.GrantInfo;
 
  35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.VimComputeResourceFlavour;
 
  36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest;
 
  37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest;
 
  38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest;
 
  39 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest;
 
  40 import org.springframework.stereotype.Component;
 
  42 import com.google.gson.Gson;
 
  45 public class Driver2CbamRequestConverter {
 
  47         public CBAMCreateVnfRequest createReqConvert(InstantiateVnfRequest driverRequest) {
 
  48                 CBAMCreateVnfRequest request = new CBAMCreateVnfRequest();
 
  50                 request.setVnfdId(driverRequest.getVnfdId());
 
  51                 request.setName(driverRequest.getVnfInstanceName());
 
  52                 request.setDescription(driverRequest.getVnfInstanceDescription());
 
  56         public CBAMInstantiateVnfRequest instantiateRequestConvert(InstantiateVnfRequest driverRequest,
 
  57                         NslcmGrantVnfResponse nslc, GrantInfo grant, VimComputeResourceFlavour vimco) throws IOException {
 
  58         Gson gson = new Gson();
 
  59                 String inputJson = readcbamInputInfoFromJsonFile();
 
  60                 CBAMInstantiateVnfRequest request = gson.fromJson(inputJson, CBAMInstantiateVnfRequest.class);
 
  65         private String readcbamInputInfoFromJsonFile() throws IOException {
 
  66                 String filePath = "/etc/vnfpkginfo/cbam_input.json";
 
  67                 String fileContent = CommonUtil.getJsonStrFromFile(filePath);
 
  72         public CBAMTerminateVnfRequest terminateReqConvert(TerminateVnfRequest driverRequest) {
 
  73                 CBAMTerminateVnfRequest request = new CBAMTerminateVnfRequest();
 
  74 //              request.setTerminationType(driverRequest.getTerminationType().toUpperCase());
 
  75                 request.setTerminationType("FORCEFUL");
 
  76                 request.setGracefulTerminationTimeout(driverRequest.getGracefulTerminationTimeout());
 
  80         public CBAMHealVnfRequest healReqConvert(HealVnfRequest driverRequest) {
 
  81                 CBAMHealVnfRequest request = new CBAMHealVnfRequest();
 
  83                 request.setAdditionalParams("");
 
  87         public CBAMScaleVnfRequest scaleReqconvert(ScaleVnfRequest driverRequest) {
 
  88                 CBAMScaleVnfRequest request = new CBAMScaleVnfRequest();
 
  89                 if (driverRequest.getType().equals(ScaleType.SCALE_OUT)) {
 
  90                         request.setType(ScaleDirection.OUT);
 
  92                         request.setType(ScaleDirection.IN);
 
  94                 request.setAspectId(driverRequest.getAspectId());
 
  95                 request.setNumberOfSteps(driverRequest.getNumberOfSteps());
 
  96                 request.setAdditionalParams(driverRequest.getAdditionalParam());
 
 100 //      public static void main(String[] argv) throws IOException {
 
 101 //              Gson gson = new Gson();
 
 102 //              String filePath = "D:\\cbam_input.json";
 
 103 //              String inputJson = readcbamInputInfo(filePath);
 
 104 //              CBAMInstantiateVnfRequest request = gson.fromJson(inputJson, CBAMInstantiateVnfRequest.class);
 
 105 //              System.out.println(gson.toJson(request));
 
 108 //      public static String readcbamInputInfo(String filePath) throws IOException {
 
 109 //              InputStream ins = null;
 
 110 //        BufferedInputStream bins = null;
 
 111 //        String fileContent = "";
 
 112 //        String fileName = filePath;
 
 115 //            ins = new FileInputStream(fileName);
 
 116 //            bins = new BufferedInputStream(ins);
 
 118 //            byte[] contentByte = new byte[ins.available()];
 
 119 //            int num = bins.read(contentByte);
 
 122 //                fileContent = new String(contentByte);
 
 124 //        } catch(FileNotFoundException e) {
 
 125 //              e.printStackTrace();;
 
 130 //            if(bins != null) {
 
 134 //              return fileContent;