2 * Copyright © 2017-2018 AT&T Intellectual Property.
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.ccsdk.apps.blueprintsprocessor.selfservice.api
19 import io.swagger.annotations.ApiOperation
20 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC
21 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
22 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput
23 import org.springframework.beans.factory.annotation.Autowired
24 import org.springframework.http.MediaType
25 import org.springframework.http.codec.multipart.FilePart
26 import org.springframework.web.bind.annotation.PostMapping
27 import org.springframework.web.bind.annotation.RequestBody
28 import org.springframework.web.bind.annotation.RequestMapping
29 import org.springframework.web.bind.annotation.RequestMethod
30 import org.springframework.web.bind.annotation.RequestPart
31 import org.springframework.web.bind.annotation.ResponseBody
32 import org.springframework.web.bind.annotation.RestController
33 import reactor.core.publisher.Mono
36 @RequestMapping("/api/v1/execution-service")
37 class ExecutionServiceController {
40 lateinit var executionServiceHandler: ExecutionServiceHandler
42 @RequestMapping(path = ["/ping"], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE])
44 fun ping(): Mono<String> {
45 return Mono.just("Success")
48 @PostMapping(path = ["/upload"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
49 @ApiOperation(value = "Upload CBA", notes = "Takes a File and load it in the runtime database")
51 fun upload(@RequestPart("file") parts: Mono<FilePart>): Mono<String> {
53 .filter { it is FilePart }
54 .ofType(FilePart::class.java)
55 .flatMap(executionServiceHandler::upload)
58 @RequestMapping(path = ["/process"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE])
59 @ApiOperation(value = "Resolve Resource Mappings",
60 notes = "Takes the blueprint information and process as per the payload")
62 fun process(@RequestBody executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
63 if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) {
64 throw IllegalStateException("Can't process async request through the REST endpoint. Use gRPC for async processing.")
66 return executionServiceHandler.processSync(executionServiceInput)