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
|
/*-
* ============LICENSE_START=======================================================
* Copyright 2021 Huawei Technologies Co., Ltd.
* ================================================================================
* 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.
* ============LICENSE_END=========================================================
*/
package org.onap.so.multicloudsimulator.controller;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MediaType;
import org.apache.commons.io.IOUtils;
import org.onap.so.multicloudsimulator.beans.InstanceOutput;
import org.onap.so.multicloudsimulator.beans.MulticloudCreateResponse;
import org.onap.so.multicloudsimulator.beans.MulticloudInstanceRequest;
import org.onap.so.multicloudsimulator.beans.InstanceResponse;
import org.onap.so.multicloudsimulator.beans.InstanceNameOutput;
import org.onap.so.multicloudsimulator.beans.MulticloudRequest;
import org.springframework.http.ResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import java.io.IOException;
import java.io.InputStream;
import static org.onap.so.multicloudsimulator.utils.Constants.BASE_URL;
@RestController
public class MultiCloudController {
public static final String X_HTTP_METHOD_OVERRIDE = "X-HTTP-Method-Override";
private static final Logger LOGGER = LoggerFactory.getLogger(MultiCloudController.class);
@PostMapping("/v1/instance")
public ResponseEntity<?> createInstance(@RequestBody MulticloudInstanceRequest req) {
LOGGER.info("MultiCloud createInstance ");
final InstanceResponse InstanceResponse = new InstanceResponse();
LOGGER.info("Calling v1 instance method");
return ResponseEntity.ok(req);
}
@GetMapping(value = BASE_URL + "/{cloud-owner}/{cloud-region-id}/infra_workload",
produces = { MediaType.APPLICATION_JSON })
public ResponseEntity<?> getInstance(@PathVariable("cloud-owner") String cloudOwner,
@PathVariable("cloud-region-id") String cloudRegionId,
@RequestParam(value = "depth", required = false, defaultValue = "0") Integer depth,
@RequestParam(name = "format", required = false) final String name, final HttpServletRequest request)
throws Exception {
LOGGER.info("found CloudOwner {}", cloudOwner);
LOGGER.info("found cloudRegionId {}", cloudRegionId);
LOGGER.info("found name {}", name);
final InputStream instanceOutput = InstanceOutput.getInstance();
final String output = IOUtils.toString(instanceOutput, "utf-8");
return ResponseEntity.ok(output);
}
@PostMapping(value = BASE_URL + "/{cloud-owner}/{cloud-region-id}/infra_workload",
consumes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML },
produces = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseEntity<?> postCreateInstance(@RequestBody final MulticloudCreateResponse inputRequest,
@PathVariable("cloud-owner") final String cloudOwner,
@PathVariable("cloud-region-id") final String cloudRegionId,
@RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String xHttpHeaderOverride,
final HttpServletRequest request) throws IOException {
LOGGER.info("Calling postCreateInstance");
inputRequest.setWorkloadStatusReason(null);
inputRequest.setWorkloadId("sad_sammet");
inputRequest.setTemplateType("heat");
inputRequest.setWorkloadStatus("CREATE_COMPLETE");
return ResponseEntity.status(201).body(inputRequest);
}
@GetMapping(value = BASE_URL + "/{cloud-owner}/{cloud-region-id}/infra_workload/{workload-id}",
produces = {MediaType.APPLICATION_JSON })
public ResponseEntity<?> getInstanceName(@PathVariable("cloud-owner") final String cloudOwner,
@PathVariable("cloud-region-id") final String cloudRegionId, @PathVariable("workload-id") final String workloadId,
@RequestParam(value = "depth", required = false, defaultValue = "0") final Integer depth,
@RequestParam(name = "format", required = false) final String name, final HttpServletRequest request)
throws Exception {
LOGGER.info("Calling getInstanceName");
LOGGER.info("found CloudOwner {}", cloudOwner);
LOGGER.info("found cloudRegionId {}", cloudRegionId);
LOGGER.info("found name {}", name);
final InputStream instanceNameOutput = InstanceNameOutput.getInstanceName();
final String output = IOUtils.toString(instanceNameOutput, "utf-8");
return ResponseEntity.ok(output);
}
@PostMapping(value = BASE_URL + "/{cloud-owner}/{cloud-region-id}/infra_workload/{workload-id}",
consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML },
produces = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseEntity<?> postCreateInstanceName(@RequestBody final MulticloudRequest inputRequest,
@PathVariable("cloud-owner") final String cloudOwner, @PathVariable("workload-id") String workloadId,
@PathVariable("cloud-region-id") final String cloudRegionId,
@RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String xHttpHeaderOverride,
final HttpServletRequest request) throws IOException {
LOGGER.info("Calling postCreateInstanceName");
return ResponseEntity.status(405).build();
}
}
|