Add modify vnf feature on driver
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / adaptor / Driver2CbamRequestConverter.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor;
18
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;
24
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;
41
42 import com.google.gson.Gson;
43
44 @Component
45 public class Driver2CbamRequestConverter {
46
47         public CBAMCreateVnfRequest createReqConvert(InstantiateVnfRequest driverRequest) {
48                 CBAMCreateVnfRequest request = new CBAMCreateVnfRequest();
49
50                 request.setVnfdId(driverRequest.getVnfdId());
51                 request.setName(driverRequest.getVnfInstanceName());
52                 request.setDescription(driverRequest.getVnfInstanceDescription());
53                 return request;
54         }
55
56         public CBAMInstantiateVnfRequest instantiateRequestConvert(InstantiateVnfRequest driverRequest,
57                         NslcmGrantVnfResponse nslc, GrantInfo grant, VimComputeResourceFlavour vimco) throws Exception {
58         Gson gson = new Gson();
59                 String inputJson = readcbamInputInfoFromJsonFile();
60                 CBAMInstantiateVnfRequest request = gson.fromJson(inputJson, CBAMInstantiateVnfRequest.class);
61                 
62                 return request;
63         }
64
65         private String readcbamInputInfoFromJsonFile() throws IOException {
66                 String filePath = "/etc/vnfpkginfo/cbam_input.json";
67                 String fileContent = CommonUtil.getJsonStrFromFile(filePath);
68
69                 return fileContent;
70         }
71
72         public CBAMTerminateVnfRequest terminateReqConvert(TerminateVnfRequest driverRequest) {
73                 CBAMTerminateVnfRequest request = new CBAMTerminateVnfRequest();
74                 request.setTerminationType(driverRequest.getTerminationType());
75                 request.setGracefulTerminationTimeout(driverRequest.getGracefulTerminationTimeout());
76                 return request;
77         }
78
79         public CBAMHealVnfRequest healReqConvert(HealVnfRequest driverRequest) {
80                 CBAMHealVnfRequest request = new CBAMHealVnfRequest();
81                 request.setCause("");
82                 request.setAdditionalParams("");
83                 return request;
84         }
85
86         public CBAMScaleVnfRequest scaleReqconvert(ScaleVnfRequest driverRequest) {
87                 CBAMScaleVnfRequest request = new CBAMScaleVnfRequest();
88                 if (driverRequest.getType().equals(ScaleType.SCALE_OUT)) {
89                         request.setType(ScaleDirection.OUT);
90                 } else {
91                         request.setType(ScaleDirection.IN);
92                 }
93                 request.setAspectId(driverRequest.getAspectId());
94                 request.setNumberOfSteps(driverRequest.getNumberOfSteps());
95                 request.setAdditionalParams(driverRequest.getAdditionalParam());
96                 return request;
97         }
98
99 }