@Override
 public Response toResponse(Exception exception) {
   MDCBuilder.buildMdcContext();
   LOGGER.error(exception.getMessage(), exception);
   return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
       .entity(new ExceptionResult("Internal server error"))
       .build();
 }
 @Override
 protected StackFailureContext createFlowContext(
     String flowId, StateContext<S, E> stateContext, StackFailureEvent payload) {
   Flow flow = getFlow(flowId);
   Stack stack = stackService.getById(payload.getStackId());
   MDCBuilder.buildMdcContext(stack);
   flow.setFlowFailed();
   return new StackFailureContext(flowId, stack);
 }
예제 #3
0
 @ApiOperation(
     value = StackOpDescription.POST_PUBLIC,
     produces = ContentType.JSON,
     notes = Notes.STACK_NOTES)
 @RequestMapping(value = "account/stacks", method = RequestMethod.POST)
 @ResponseBody
 public ResponseEntity<IdJson> createAccountStack(
     @ModelAttribute("user") CbUser user, @RequestBody @Valid StackRequest stackRequest) {
   MDCBuilder.buildUserMdcContext(user);
   return createStack(user, stackRequest, true);
 }
예제 #4
0
 @ApiOperation(
     value = StackOpDescription.GET_PRIVATE,
     produces = ContentType.JSON,
     notes = Notes.STACK_NOTES)
 @RequestMapping(value = "user/stacks", method = RequestMethod.GET)
 @ResponseBody
 public ResponseEntity<Set<StackResponse>> getPrivateStacks(@ModelAttribute("user") CbUser user) {
   MDCBuilder.buildUserMdcContext(user);
   Set<Stack> stacks = stackService.retrievePrivateStacks(user);
   return new ResponseEntity<>(convertStacks(stacks), HttpStatus.OK);
 }
예제 #5
0
 @ApiOperation(
     value = StackOpDescription.GET_STATUS_BY_ID,
     produces = ContentType.JSON,
     notes = Notes.STACK_NOTES)
 @RequestMapping(value = "stacks/{id}/status", method = RequestMethod.GET)
 @ResponseBody
 public ResponseEntity<Map<String, Object>> getStackStatus(
     @ModelAttribute("user") CbUser user, @PathVariable Long id) {
   MDCBuilder.buildUserMdcContext(user);
   Map<String, Object> statusMap = conversionService.convert(stackService.get(id), Map.class);
   return new ResponseEntity<>(statusMap, HttpStatus.OK);
 }
예제 #6
0
 @ApiOperation(
     value = StackOpDescription.GET_PUBLIC_BY_NAME,
     produces = ContentType.JSON,
     notes = Notes.STACK_NOTES)
 @RequestMapping(value = "account/stacks/{name}", method = RequestMethod.GET)
 @ResponseBody
 public ResponseEntity<StackResponse> getStackInPublic(
     @ModelAttribute("user") CbUser user, @PathVariable String name) {
   MDCBuilder.buildUserMdcContext(user);
   Stack stack = stackService.getPublicStack(name, user);
   StackResponse stackJson = conversionService.convert(stack, StackResponse.class);
   return new ResponseEntity<>(stackJson, HttpStatus.OK);
 }
예제 #7
0
 @ApiOperation(
     value = EventOpDescription.GET_BY_TIMESTAMP,
     produces = ContentType.JSON,
     notes = Notes.EVENT_NOTES)
 @RequestMapping(method = RequestMethod.GET, value = "/events")
 @ResponseBody
 public ResponseEntity<List<CloudbreakEventsJson>> events(
     @ModelAttribute("user") CbUser user,
     @RequestParam(value = "since", required = false) Long since) {
   MDCBuilder.buildUserMdcContext(user);
   List<CloudbreakEventsJson> cloudbreakEvents =
       cloudbreakEventsFacade.retrieveEvents(user.getUserId(), since);
   return new ResponseEntity<>(cloudbreakEvents, HttpStatus.OK);
 }
예제 #8
0
 @ApiOperation(
     value = StackOpDescription.DELETE_INSTANCE_BY_ID,
     produces = ContentType.JSON,
     notes = Notes.STACK_NOTES)
 @RequestMapping(value = "stacks/{stackId}/{instanceId}", method = RequestMethod.DELETE)
 @ResponseBody
 public ResponseEntity<String> deleteInstance(
     @ModelAttribute("user") CbUser user,
     @PathVariable("stackId") Long stackId,
     @PathVariable("instanceId") String instanceId) {
   MDCBuilder.buildMdcContext(user);
   stackService.removeInstance(user, stackId, instanceId);
   return new ResponseEntity<>(HttpStatus.NO_CONTENT);
 }
예제 #9
0
 @ApiOperation(
     value = StackOpDescription.VALIDATE,
     produces = ContentType.JSON,
     notes = Notes.STACK_NOTES)
 @RequestMapping(value = "stacks/validate", method = RequestMethod.POST)
 @ResponseBody
 public ResponseEntity<IdJson> validateStack(
     @ModelAttribute("user") CbUser user,
     @RequestBody @Valid StackValidationRequest stackValidationRequest) {
   MDCBuilder.buildUserMdcContext(user);
   StackValidation stackValidation =
       conversionService.convert(stackValidationRequest, StackValidation.class);
   stackService.validateStack(stackValidation);
   return new ResponseEntity<>(HttpStatus.OK);
 }
예제 #10
0
 private ResponseEntity<IdJson> createStack(
     CbUser user, StackRequest stackRequest, boolean publicInAccount) {
   Stack stack = conversionService.convert(stackRequest, Stack.class);
   MDCBuilder.buildMdcContext(stack);
   stack =
       stackDecorator.decorate(
           stack,
           stackRequest.getCredentialId(),
           stackRequest.getConsulServerCount(),
           stackRequest.getNetworkId(),
           stackRequest.getSecurityGroupId());
   stack.setPublicInAccount(publicInAccount);
   validateAccountPreferences(stack, user);
   stack = stackService.create(user, stack);
   return new ResponseEntity<>(new IdJson(stack.getId()), HttpStatus.CREATED);
 }
예제 #11
0
 @ApiOperation(
     value = StackOpDescription.DELETE_PUBLIC_BY_NAME,
     produces = ContentType.JSON,
     notes = Notes.STACK_NOTES)
 @RequestMapping(value = "account/stacks/{name}", method = RequestMethod.DELETE)
 @ResponseBody
 public ResponseEntity<TemplateResponse> deletePublicStack(
     @ModelAttribute("user") CbUser user,
     @PathVariable String name,
     @RequestParam(value = "forced", required = false, defaultValue = "false") Boolean forced) {
   MDCBuilder.buildUserMdcContext(user);
   if (forced) {
     stackService.forceDelete(name, user);
   } else {
     stackService.delete(name, user);
   }
   return new ResponseEntity<>(HttpStatus.NO_CONTENT);
 }
예제 #12
0
 @ApiOperation(
     value = StackOpDescription.PUT_BY_ID,
     produces = ContentType.JSON,
     notes = Notes.STACK_NOTES)
 @RequestMapping(value = "stacks/{id}", method = RequestMethod.PUT)
 @ResponseBody
 public ResponseEntity<String> updateStack(
     @ModelAttribute("user") CbUser user,
     @PathVariable Long id,
     @Valid @RequestBody UpdateStackJson updateRequest) {
   MDCBuilder.buildUserMdcContext(user);
   if (updateRequest.getStatus() != null) {
     stackService.updateStatus(id, updateRequest.getStatus());
     return new ResponseEntity<>(HttpStatus.NO_CONTENT);
   } else {
     Integer scalingAdjustment = updateRequest.getInstanceGroupAdjustment().getScalingAdjustment();
     validateAccountPreferences(id, scalingAdjustment);
     stackService.updateNodeCount(id, updateRequest.getInstanceGroupAdjustment());
     return new ResponseEntity<>(HttpStatus.NO_CONTENT);
   }
 }