6477c0678e4e676c1eff79e41fdf94b6370354bb
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
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.ccsdk.apps.blueprintsprocessor.selfservice.api
18
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
34
35 @RestController
36 @RequestMapping("/api/v1/execution-service")
37 class ExecutionServiceController {
38
39     @Autowired
40     lateinit var executionServiceHandler: ExecutionServiceHandler
41
42     @RequestMapping(path = ["/ping"], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE])
43     @ResponseBody
44     fun ping(): Mono<String> {
45         return Mono.just("Success")
46     }
47
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")
50     @ResponseBody
51     fun upload(@RequestPart("file") parts: Mono<FilePart>): Mono<String> {
52         return parts
53             .filter { it is FilePart }
54             .ofType(FilePart::class.java)
55             .flatMap(executionServiceHandler::upload)
56     }
57
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")
61     @ResponseBody
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.")
65         }
66         return executionServiceHandler.processSync(executionServiceInput)
67     }
68 }