Skip to content
This repository was archived by the owner on Mar 5, 2020. It is now read-only.

Commit a31537f

Browse files
committed
Api change, code improvement
1 parent cfa3d15 commit a31537f

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

src/main/java/pl/simplemethod/codebin/githubOauth/GithubRestController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
@RestController
13-
@RequestMapping("v1.0")
13+
@RequestMapping("github")
1414
public class GithubRestController {
1515

1616
@Autowired

src/main/java/pl/simplemethod/codebin/srv/SrvClient.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,32 @@ protected org.json.JSONObject restartContainer(String id) {
246246
return body;
247247
}
248248
}
249+
/**
250+
* The method returns container data
251+
*
252+
* @param id Container ID
253+
* @return Json object with status
254+
*/
255+
protected String infoContainer(String id) {
256+
org.json.JSONObject body = new org.json.JSONObject();
257+
try {
258+
HttpResponse<String> logsContainer = Unirest.get(SERVER_URL + "/v1.0/containers/" + id + "/json")
259+
.header("accept", "application/json").header("Content-Type", "application/json").asString();
260+
if (logsContainer.getStatus() != 200) {
261+
body.put("message", "Something went wrong ");
262+
body.put("status", logsContainer.getStatus());
263+
return body.toString();
264+
} else {
265+
return logsContainer.getBody();
266+
}
267+
268+
} catch (NullPointerException | org.json.JSONException | UnirestException e) {
269+
body.put("message", "Something went wrong " + e);
270+
body.put("status", 510);
271+
return body.toString();
272+
}
273+
}
274+
249275

250276
/**
251277
* The method returns container logs

src/main/java/pl/simplemethod/codebin/srv/SrvRestController.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.springframework.web.bind.annotation.*;
1010

1111
@RestController
12-
@RequestMapping("v1.0")
12+
@RequestMapping("srv")
1313
public class SrvRestController {
1414

1515
@Autowired
@@ -26,7 +26,7 @@ public class SrvRestController {
2626
* @param diskQuota Maximum amount of allocated memory on the disk
2727
* @return Json object with data
2828
*/
29-
@PostMapping("/srv/container/create")
29+
@PostMapping("container/create")
3030
public @ResponseBody
3131
ResponseEntity createContainer(@RequestParam("dockerimage") String dockerImage, @RequestParam("exposedports") Integer exposedPorts, @RequestParam("hostport") Integer hostPort, @RequestParam("name") String name, @RequestParam("rammemory") Long ramMemory, @RequestParam("diskquota") Long diskQuota) {
3232
HttpHeaders headers = new HttpHeaders();
@@ -47,7 +47,7 @@ ResponseEntity createContainer(@RequestParam("dockerimage") String dockerImage,
4747
* @param containerId Container ID
4848
* @return Json object as response
4949
*/
50-
@PostMapping("/srv/container/{ID}/restart")
50+
@PostMapping("container/{ID}/restart")
5151
public @ResponseBody
5252
ResponseEntity restartContainer(@PathVariable(value = "ID") String containerId) {
5353
HttpHeaders headers = new HttpHeaders();
@@ -57,10 +57,12 @@ ResponseEntity restartContainer(@PathVariable(value = "ID") String containerId)
5757
}
5858

5959
/**
60+
* Stop the container with the specified ID
61+
*
6062
* @param containerId Container ID
6163
* @return Json object as response
6264
*/
63-
@PostMapping("/srv/container/{ID}/stop")
65+
@PostMapping("container/{ID}/stop")
6466
public @ResponseBody
6567
ResponseEntity stopContainer(@PathVariable(value = "ID") String containerId) {
6668
HttpHeaders headers = new HttpHeaders();
@@ -75,7 +77,7 @@ ResponseEntity stopContainer(@PathVariable(value = "ID") String containerId) {
7577
* @param containerId Container ID
7678
* @return Json object as response
7779
*/
78-
@PostMapping("/srv/container/{ID}/start")
80+
@PostMapping("container/{ID}/start")
7981
public @ResponseBody
8082
ResponseEntity startContainer(@PathVariable(value = "ID") String containerId) {
8183
HttpHeaders headers = new HttpHeaders();
@@ -90,7 +92,7 @@ ResponseEntity startContainer(@PathVariable(value = "ID") String containerId) {
9092
* @param containerId Container ID
9193
* @return Json object as response
9294
*/
93-
@GetMapping("/srv/container/{ID}/logs")
95+
@GetMapping("container/{ID}/logs")
9496
public @ResponseBody
9597
ResponseEntity logsContainer(@PathVariable(value = "ID") String containerId) {
9698
HttpHeaders headers = new HttpHeaders();
@@ -101,12 +103,26 @@ ResponseEntity logsContainer(@PathVariable(value = "ID") String containerId) {
101103
return new ResponseEntity<>(replaceString, headers, HttpStatus.valueOf(201));
102104
}
103105

106+
/**
107+
* The method returns information about the container
108+
* @param containerId Container ID
109+
* @return Json object as response
110+
*/
111+
@GetMapping("container/{ID}/info")
112+
public @ResponseBody
113+
ResponseEntity infoContainer(@PathVariable(value = "ID") String containerId) {
114+
HttpHeaders headers = new HttpHeaders();
115+
headers.setContentType(MediaType.APPLICATION_JSON);
116+
String response = srvClient.infoContainer(containerId);
117+
return new ResponseEntity<>(response, headers, HttpStatus.valueOf(200));
118+
}
119+
104120
/**
105121
* The method returns information about the docker server
106122
*
107123
* @return Json object as response
108124
*/
109-
@GetMapping("/srv/info")
125+
@GetMapping("info")
110126
public @ResponseBody
111127
ResponseEntity infoDocker() {
112128
HttpHeaders headers = new HttpHeaders();
@@ -121,7 +137,7 @@ ResponseEntity infoDocker() {
121137
* @param containerId Container ID
122138
* @return Json object as response
123139
*/
124-
@DeleteMapping("/srv/container/{ID}/delete")
140+
@DeleteMapping("container/{ID}/delete")
125141
public @ResponseBody
126142
ResponseEntity deleteContainer(@PathVariable(value = "ID") String containerId) {
127143
HttpHeaders headers = new HttpHeaders();
@@ -138,7 +154,7 @@ ResponseEntity deleteContainer(@PathVariable(value = "ID") String containerId) {
138154
* @param arguments Argument to execute
139155
* @return Json object as response
140156
*/
141-
@PostMapping("/srv/container/{ID}/exec")
157+
@PostMapping("container/{ID}/exec")
142158
public @ResponseBody
143159
ResponseEntity execContainer(@PathVariable(value = "ID") String containerId, @RequestParam("path") String path, @RequestParam("argument") String arguments) {
144160
HttpHeaders headers = new HttpHeaders();

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
server.port=8080
1+
server.port=80
22
spring.main.allow-bean-definition-overriding=true
33

44
spring.security.oauth2.client.registration.github.client-id=2f5c2010372081b036ff

0 commit comments

Comments
 (0)