summaryrefslogtreecommitdiffstats
path: root/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/controller/CbamController.java
blob: 9578e75fa84da985f4fcba875a5d47eec88cd38d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * 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.controller;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.CatalogQueryVnfResponse;
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.CBAMOperExecutVnfRequest;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMOperExecutVnfResponse;
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.entity.OperationExecution;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ProblemDetails;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfInfo;
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.HttpRequestProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;

@Controller
@RequestMapping(value = "/vnfm/lcm/v3")
public class CbamController {
	private static final Logger logger = LogManager.getLogger("CbamController");
	@Autowired 
	private AdaptorEnv adaptorEnv;
	
	@Autowired
	private HttpClientBuilder httpClientBuilder;
	
	private Gson gson = new Gson();
	
	@RequestMapping(value = "/vnfs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public CBAMCreateVnfResponse createVnf(CBAMInstantiateVnfRequest request) throws ClientProtocolException, IOException
    {
		 CBAMCreateVnfResponse response = new  CBAMCreateVnfResponse();
			String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamCreateVnfPath);
			HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
			
			String responseStr = processor.process(url);
			
			logger.info("CbamMgmrImpl -> createVnf, responseStr is " + responseStr);
			
			CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
			
			
	        return response;
    }
	@RequestMapping(value = "/vnfs/{vnfInstanceId}/instantiate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public CBAMInstantiateVnfResponse initiateVnf(CBAMInstantiateVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
    {
		CBAMInstantiateVnfResponse response = new CBAMInstantiateVnfResponse();
		String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamInstantiateVnfPath,vnfInstanceId);
		HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
		
		String responseStr = processor.process(url);
		
		logger.info("CbamMgmrImpl -> initiateVnf, responseStr is " + responseStr);
		
		CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
		
		
        return response;
    }
	
	@RequestMapping(value = "/vnfs/{vnfInstanceId}/terminate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public CBAMTerminateVnfResponse terminateVnf(CBAMTerminateVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
    {
		CBAMTerminateVnfResponse response = new CBAMTerminateVnfResponse();
		String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamTerminateVnfPath,vnfInstanceId);
		HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
		
		String responseStr = processor.process(url);
		
		logger.info("CbamMgmrImpl -> terminateVnf, responseStr is " + responseStr);
		
		CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
        return response;
    }
	
	@RequestMapping(value = "/vnfs/{vnfInstanceId}/scale", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public CBAMScaleVnfResponse scaleVnf(CBAMScaleVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
    {
		CBAMScaleVnfResponse response = new CBAMScaleVnfResponse();
		String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamScaleVnfPath,vnfInstanceId);
		HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
		
		String responseStr = processor.process(url);
		
		logger.info("CbamMgmrImpl -> scaleVnf, responseStr is " + responseStr);
		
		CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
        return response;
    }

	@RequestMapping(value = "/vnfs/{vnfInstanceId}/heal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public CBAMHealVnfResponse healVnf(CBAMHealVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
    {
		 CBAMHealVnfResponse response = new  CBAMHealVnfResponse();
		 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamHealVnfPath,vnfInstanceId);
			HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
			
			String responseStr = processor.process(url);
			
			logger.info("CbamMgmrImpl -> healVnf, responseStr is " + responseStr);
			
			CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
        return response;
    }
	
	
	@RequestMapping(value = "/vnfs/{vnfInstanceId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public CBAMQueryVnfResponse queryVnf(@PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
    {
		CBAMQueryVnfResponse response = new  CBAMQueryVnfResponse();
		String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamQueryVnfPath, vnfInstanceId);
		HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
		
		String responseStr = processor.process(url);
		
		logger.info("CbamMgmrImpl -> queryVnfPackage, responseStr is " + responseStr);
		
		CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
		
		
        return response;
    }
	
	
	@RequestMapping(value = "/operation_executions/{operationExecutionId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public CBAMOperExecutVnfResponse operVnf(@PathVariable("operationExecutionId") String operationExecutionId) throws ClientProtocolException, IOException
    {
		CBAMOperExecutVnfResponse response = new  CBAMOperExecutVnfResponse();
		 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamGetOperStatusPath,operationExecutionId);
			HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
			
			String responseStr = processor.process(url);
			
			logger.info("CbamMgmrImpl -> operVnf, responseStr is " + responseStr);
			
			CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
        return response;
    }
	
	
	

}