blob: 77936e50d6bf648ecab0d35852b7e5f851f0859e [file] [log] [blame]
/*-
* ============LICENSE_START=======================================================
* OSAM
* ================================================================================
* Copyright (C) 2018 AT&T
* ================================================================================
* 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.osam.controller;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.onap.osam.job.AsyncJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.UUID;
@RestController
@RequestMapping("/async")
@Slf4j
public class AsyncJobDemoController extends AbstractController{
private AsyncJobService asyncJobService;
@Autowired
public AsyncJobDemoController(AsyncJobService asyncJobService) {
super(log);
this.asyncJobService = asyncJobService;
}
@PostMapping("/chassis")
public ResponseEntity<String> createChassisWithAsyncJob(@RequestBody AsyncJobDemoControllerData data){
try {
final List<UUID> asyncJob = asyncJobService.pushBulkJob("demoUser", data.getIsRootJobSuccessful(), data.getIsRootDependantOnChildren());
return new ResponseEntity<String>(asyncJob.get(0).toString(), HttpStatus.OK);
}catch (Exception e){
return super.proceedException(e);
}
}
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
@JsonAutoDetect
public static class AsyncJobDemoControllerData {
private Boolean isRootJobSuccessful;
private Boolean isRootDependantOnChildren;
}
}