View Javadoc
1   package info.mikethomas.fahservices.service;
2   
3   /*
4    * #%L
5    * This file is part of FAHServices.
6    * %%
7    * Copyright (C) 2014 - 2024 Mike Thomas <mikepthomas@outlook.com>
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import info.mikethomas.jfold.Connection;
26  
27  import io.swagger.v3.oas.annotations.Operation;
28  import io.swagger.v3.oas.annotations.Parameter;
29  import io.swagger.v3.oas.annotations.media.Schema;
30  import io.swagger.v3.oas.annotations.responses.ApiResponse;
31  import io.swagger.v3.oas.annotations.tags.Tag;
32  
33  import org.springframework.beans.factory.annotation.Autowired;
34  import org.springframework.http.HttpStatus;
35  import org.springframework.http.MediaType;
36  import org.springframework.http.ResponseEntity;
37  import org.springframework.web.bind.annotation.PathVariable;
38  import org.springframework.web.bind.annotation.RequestMapping;
39  import org.springframework.web.bind.annotation.RequestMethod;
40  import org.springframework.web.bind.annotation.ResponseBody;
41  import org.springframework.web.bind.annotation.RestController;
42  
43  /**
44   * REST Web Service.
45   *
46   * @author Michael Thomas (mikepthomas@outlook.com)
47   * @version $Id: $Id
48   */
49  @RestController("slot-add")
50  @Tag(name = "Slot Add", description = "Add a new slot.")
51  public class SlotAddResource {
52  
53      @Autowired
54      private Connection connection;
55  
56      /**
57       * Retrieves representation of an instance of
58       * info.mikethomas.fahservices.service.SlotAddResource.
59       *
60       * @param type Slot type
61       * @return an instance of java.lang.String
62       */
63      @Operation(summary = "slot-add {type}", description = "Add a new slot.", responses = {
64              @ApiResponse(responseCode = "200", description = "OK")
65      })
66      @RequestMapping(
67              value = "/slot-add/{type}",
68              method = RequestMethod.POST,
69              produces = {
70                  MediaType.APPLICATION_JSON_VALUE,
71                  MediaType.APPLICATION_XML_VALUE,
72                  MediaType.TEXT_XML_VALUE
73              })
74      @ResponseBody
75      public ResponseEntity<String> getSlotAdd(
76              @Parameter(description = "slot type", required = true, schema =
77                      @Schema(allowableValues = { "CPU", "GPU" })
78              )
79              @PathVariable("type") final String type) {
80          connection.slotAdd(type);
81          return new ResponseEntity<>(HttpStatus.OK);
82      }
83  }