blob: 77936e50d6bf648ecab0d35852b7e5f851f0859e [file] [log] [blame]
Aharoni, Pavel (pa0916)8c70f072018-11-18 00:07:12 +02001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21package org.onap.osam.controller;
22
23import com.fasterxml.jackson.annotation.JsonAutoDetect;
24import lombok.AllArgsConstructor;
25import lombok.Getter;
26import lombok.NoArgsConstructor;
27import lombok.Setter;
28import lombok.extern.slf4j.Slf4j;
29import org.onap.osam.job.AsyncJobService;
30import org.springframework.beans.factory.annotation.Autowired;
31import org.springframework.boot.jackson.JsonComponent;
32import org.springframework.http.HttpStatus;
33import org.springframework.http.ResponseEntity;
34import org.springframework.web.bind.annotation.PostMapping;
35import org.springframework.web.bind.annotation.RequestBody;
36import org.springframework.web.bind.annotation.RequestMapping;
37import org.springframework.web.bind.annotation.RestController;
38
39import java.util.List;
40import java.util.UUID;
41
42@RestController
43@RequestMapping("/async")
44@Slf4j
45public class AsyncJobDemoController extends AbstractController{
46 private AsyncJobService asyncJobService;
47
48 @Autowired
49 public AsyncJobDemoController(AsyncJobService asyncJobService) {
50 super(log);
51 this.asyncJobService = asyncJobService;
52 }
53
54 @PostMapping("/chassis")
55 public ResponseEntity<String> createChassisWithAsyncJob(@RequestBody AsyncJobDemoControllerData data){
56 try {
57 final List<UUID> asyncJob = asyncJobService.pushBulkJob("demoUser", data.getIsRootJobSuccessful(), data.getIsRootDependantOnChildren());
58 return new ResponseEntity<String>(asyncJob.get(0).toString(), HttpStatus.OK);
59 }catch (Exception e){
60 return super.proceedException(e);
61 }
62 }
63
64
65 @AllArgsConstructor
66 @NoArgsConstructor
67 @Setter
68 @Getter
69 @JsonAutoDetect
70 public static class AsyncJobDemoControllerData {
71 private Boolean isRootJobSuccessful;
72 private Boolean isRootDependantOnChildren;
73 }
74}