@@ -68,43 +68,24 @@ ResponseEntity kek() {
6868 * @param diskQuota Maximum amount of allocated memory on the disk
6969 * @return Json object with data
7070 */
71- @ PostMapping ("container/create" )
72- public @ ResponseBody
73- ResponseEntity createContainer (@ RequestParam ("dockerimage" ) String dockerImage , @ RequestParam ("exposedports" ) Integer exposedPorts , @ RequestParam ("hostports" ) Integer hostPorts , @ RequestParam ("name" ) String name , @ RequestParam ("rammemory" ) Long ramMemory , @ RequestParam ("diskquota" ) Long diskQuota ) {
74- HttpHeaders headers = new HttpHeaders ();
75- headers .setContentType (MediaType .APPLICATION_JSON );
76- org .json .JSONObject response = srvClient .createAndRunContainer (srvClient .generateCreateConfig (dockerImage , exposedPorts , hostPorts , ramMemory , diskQuota ), name );
77- int status ;
78- if (response .get ("status" ).toString ().equals ("204" )) {
79- status = 200 ;
80- List <Containers > containers = new ArrayList <>();
81- Images images = imagesRepository .getFirstByName (dockerImage );
82- containers .add (new Containers (name , response .get ("id" ).toString (), images , exposedPorts , hostPorts , ramMemory , diskQuota , linkClient .encrypt (String .valueOf (hostPorts )), 1 , Instant .now ().getEpochSecond ()));
83- containers .forEach (containersRepository ::save );
84- } else {
85- status = Integer .valueOf (response .get ("status" ).toString ());
86- }
87- return new ResponseEntity <>(response .toString (), headers , HttpStatus .valueOf (status ));
88- }
89-
90- @ GetMapping ("container/new" )
71+ @ GetMapping ("container/create" )
9172 public @ ResponseBody
9273 ResponseEntity createContainerForUser (@ RequestParam ("dockerimage" ) String dockerImage , @ RequestParam ("exposedports" ) Integer exposedPorts , @ RequestParam ("hostports" ) Integer hostPorts , @ RequestParam ("name" ) String name , @ RequestParam ("rammemory" ) Long ramMemory , @ RequestParam ("diskquota" ) Long diskQuota , @ CookieValue ("id" ) String id ) {
9374 HttpHeaders headers = new HttpHeaders ();
9475 headers .setContentType (MediaType .APPLICATION_JSON );
95- org .json .JSONObject response = srvClient .createAndRunContainer (srvClient .generateCreateConfig (dockerImage , exposedPorts , hostPorts , ramMemory , diskQuota ), name );
76+ Images images = imagesRepository .getFirstById (Integer .valueOf (dockerImage ));
77+
78+ org .json .JSONObject response = srvClient .createAndRunContainer (srvClient .generateCreateConfig (images .getName (), exposedPorts , hostPorts , ramMemory , diskQuota ), name );
9679 int status ;
9780 if (response .get ("status" ).toString ().equals ("204" )) {
9881 status = 200 ;
9982 List <Containers > containers = new ArrayList <>();
100- Images images = imagesRepository . getFirstByName ( dockerImage );
101- Containers newContainer = new Containers (name , response .get ("id" ).toString (), images , exposedPorts , hostPorts , ramMemory , diskQuota , "XD" , 1 , Instant .now ().getEpochSecond ());
83+
84+ Containers newContainer = new Containers (name , response .get ("id" ).toString (), images , exposedPorts , hostPorts , ramMemory , diskQuota , linkClient . encrypt ( String . valueOf ( hostPorts )) , 1 , Instant .now ().getEpochSecond ());
10285 containers .add (newContainer );
10386 containers .forEach (containersRepository ::save );
104-
10587 try {
106- // TODO: 01/06/2019 oczekuje integera, a dajemy mu longa, pojebane
107- Users users = usersRepository .getOne ((long ) Integer .parseInt (id ));
88+ Users users = usersRepository .getFirstById (Integer .parseInt (id ));
10889 users .getContainers ().add (newContainer );
10990 usersRepository .save (users );
11091 } catch (NumberFormatException e ) {
0 commit comments