Aharoni, Pavel (pa0916) | 8c70f07 | 2018-11-18 00:07:12 +0200 | [diff] [blame] | 1 | /*-
|
| 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 |
|
| 21 | package org.onap.osam.controller;
|
| 22 |
|
| 23 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
| 24 | import lombok.AllArgsConstructor;
|
| 25 | import lombok.Getter;
|
| 26 | import lombok.NoArgsConstructor;
|
| 27 | import lombok.Setter;
|
| 28 | import lombok.extern.slf4j.Slf4j;
|
| 29 | import org.onap.osam.job.AsyncJobService;
|
| 30 | import org.springframework.beans.factory.annotation.Autowired;
|
| 31 | import org.springframework.boot.jackson.JsonComponent;
|
| 32 | import org.springframework.http.HttpStatus;
|
| 33 | import org.springframework.http.ResponseEntity;
|
| 34 | import org.springframework.web.bind.annotation.PostMapping;
|
| 35 | import org.springframework.web.bind.annotation.RequestBody;
|
| 36 | import org.springframework.web.bind.annotation.RequestMapping;
|
| 37 | import org.springframework.web.bind.annotation.RestController;
|
| 38 |
|
| 39 | import java.util.List;
|
| 40 | import java.util.UUID;
|
| 41 |
|
| 42 | @RestController
|
| 43 | @RequestMapping("/async")
|
| 44 | @Slf4j
|
| 45 | public 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 | }
|