@Test public void testRunApp() { }
private Response runApp(String clusterId, String appId, Map<String, Object> data, Boolean isUpdate) { try { String command = (String) data.get("cmd"); Integer port = (Integer) data.get("port"); Float cpus = null; if (data.get("cpus") != null) { cpus = Float.parseFloat(data.get("cpus").toString()); } Float memory = null; if (data.get("memory") != null) { memory = Float.parseFloat(data.get("memory").toString()); } Integer scale = (Integer) data.get("scale"); Map<String, String> env = (Map<String, String>) data.get("beluga_env"); List<Integer> ports = null; if(port != null) { ports = new ArrayList<>(); ports.add(port); } Response response = null; if (!isUpdate) { response = marathonAPI(clusterId).deployCommandApp(appId, command, ports, cpus, memory, scale, env); } else { response = marathonAPI(clusterId).updateCommandApp(appId, command, ports, cpus, memory, scale, env); } if(response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { } else if(response.getStatus() == Response.Status.CONFLICT.getStatusCode()) { throw new ActionException("App is already running."); } else { throw new ActionException("error while deploy to marathon : [" + response.getStatus() + "] " + response.getStatusInfo()); } Map<String, Object> entity = parseMarathonResponse(response); notifyDeployment(clusterId, entity); return Response.ok().build(); } catch (Throwable t) { logger.error("", t); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(t).build(); } }
AppsAPI extends BaseAPI { private Response runApp(String clusterId, String appId, Map<String, Object> data, Boolean isUpdate) { try { String command = (String) data.get("cmd"); Integer port = (Integer) data.get("port"); Float cpus = null; if (data.get("cpus") != null) { cpus = Float.parseFloat(data.get("cpus").toString()); } Float memory = null; if (data.get("memory") != null) { memory = Float.parseFloat(data.get("memory").toString()); } Integer scale = (Integer) data.get("scale"); Map<String, String> env = (Map<String, String>) data.get("beluga_env"); List<Integer> ports = null; if(port != null) { ports = new ArrayList<>(); ports.add(port); } Response response = null; if (!isUpdate) { response = marathonAPI(clusterId).deployCommandApp(appId, command, ports, cpus, memory, scale, env); } else { response = marathonAPI(clusterId).updateCommandApp(appId, command, ports, cpus, memory, scale, env); } if(response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { } else if(response.getStatus() == Response.Status.CONFLICT.getStatusCode()) { throw new ActionException("App is already running."); } else { throw new ActionException("error while deploy to marathon : [" + response.getStatus() + "] " + response.getStatusInfo()); } Map<String, Object> entity = parseMarathonResponse(response); notifyDeployment(clusterId, entity); return Response.ok().build(); } catch (Throwable t) { logger.error("", t); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(t).build(); } } }
AppsAPI extends BaseAPI { private Response runApp(String clusterId, String appId, Map<String, Object> data, Boolean isUpdate) { try { String command = (String) data.get("cmd"); Integer port = (Integer) data.get("port"); Float cpus = null; if (data.get("cpus") != null) { cpus = Float.parseFloat(data.get("cpus").toString()); } Float memory = null; if (data.get("memory") != null) { memory = Float.parseFloat(data.get("memory").toString()); } Integer scale = (Integer) data.get("scale"); Map<String, String> env = (Map<String, String>) data.get("beluga_env"); List<Integer> ports = null; if(port != null) { ports = new ArrayList<>(); ports.add(port); } Response response = null; if (!isUpdate) { response = marathonAPI(clusterId).deployCommandApp(appId, command, ports, cpus, memory, scale, env); } else { response = marathonAPI(clusterId).updateCommandApp(appId, command, ports, cpus, memory, scale, env); } if(response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { } else if(response.getStatus() == Response.Status.CONFLICT.getStatusCode()) { throw new ActionException("App is already running."); } else { throw new ActionException("error while deploy to marathon : [" + response.getStatus() + "] " + response.getStatusInfo()); } Map<String, Object> entity = parseMarathonResponse(response); notifyDeployment(clusterId, entity); return Response.ok().build(); } catch (Throwable t) { logger.error("", t); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(t).build(); } }  }
AppsAPI extends BaseAPI { private Response runApp(String clusterId, String appId, Map<String, Object> data, Boolean isUpdate) { try { String command = (String) data.get("cmd"); Integer port = (Integer) data.get("port"); Float cpus = null; if (data.get("cpus") != null) { cpus = Float.parseFloat(data.get("cpus").toString()); } Float memory = null; if (data.get("memory") != null) { memory = Float.parseFloat(data.get("memory").toString()); } Integer scale = (Integer) data.get("scale"); Map<String, String> env = (Map<String, String>) data.get("beluga_env"); List<Integer> ports = null; if(port != null) { ports = new ArrayList<>(); ports.add(port); } Response response = null; if (!isUpdate) { response = marathonAPI(clusterId).deployCommandApp(appId, command, ports, cpus, memory, scale, env); } else { response = marathonAPI(clusterId).updateCommandApp(appId, command, ports, cpus, memory, scale, env); } if(response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { } else if(response.getStatus() == Response.Status.CONFLICT.getStatusCode()) { throw new ActionException("App is already running."); } else { throw new ActionException("error while deploy to marathon : [" + response.getStatus() + "] " + response.getStatusInfo()); } Map<String, Object> entity = parseMarathonResponse(response); notifyDeployment(clusterId, entity); return Response.ok().build(); } catch (Throwable t) { logger.error("", t); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(t).build(); } }  @GET @Path("/") Response getApps(@PathParam("clusterId") String clusterId); @GET @Path("/{id}") Response getApp(@PathParam("clusterId") String clusterId, @PathParam("id") String appId); @GET @Path("/{id}/tasks") Response getTasks(@PathParam("clusterId") String clusterId, @PathParam("id") String appId); @POST @Path("/{id}/file") @Consumes(MediaType.MULTIPART_FORM_DATA) Response uploadFile(@PathParam("clusterId") String clusterId, @PathParam("id") String appId,
                               @FormDataParam("file") InputStream uploadedInputStream,
                               @FormDataParam("file") FormDataContentDisposition fileDetail); @POST @Path("/") Response deployApp(@PathParam("clusterId") String clusterId, Map<String, Object> data); @POST @Path("/resources") Response deployResourceApp(@PathParam("clusterId") String clusterId, Map<String, Object> data); @PUT @Path("/{id}") Response updateApp(@PathParam("clusterId") String clusterId, @PathParam("id") String appId, Map<String, Object> data); @POST @Path("/{id}/restart") Response restartApp(@PathParam("clusterId") String clusterId, @PathParam("id") String appId); @DELETE @Path("/{id}") Response deleteApp(@PathParam("clusterId") String clusterId, @PathParam("id") String appId); }
AppsAPI extends BaseAPI { private Response runApp(String clusterId, String appId, Map<String, Object> data, Boolean isUpdate) { try { String command = (String) data.get("cmd"); Integer port = (Integer) data.get("port"); Float cpus = null; if (data.get("cpus") != null) { cpus = Float.parseFloat(data.get("cpus").toString()); } Float memory = null; if (data.get("memory") != null) { memory = Float.parseFloat(data.get("memory").toString()); } Integer scale = (Integer) data.get("scale"); Map<String, String> env = (Map<String, String>) data.get("beluga_env"); List<Integer> ports = null; if(port != null) { ports = new ArrayList<>(); ports.add(port); } Response response = null; if (!isUpdate) { response = marathonAPI(clusterId).deployCommandApp(appId, command, ports, cpus, memory, scale, env); } else { response = marathonAPI(clusterId).updateCommandApp(appId, command, ports, cpus, memory, scale, env); } if(response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { } else if(response.getStatus() == Response.Status.CONFLICT.getStatusCode()) { throw new ActionException("App is already running."); } else { throw new ActionException("error while deploy to marathon : [" + response.getStatus() + "] " + response.getStatusInfo()); } Map<String, Object> entity = parseMarathonResponse(response); notifyDeployment(clusterId, entity); return Response.ok().build(); } catch (Throwable t) { logger.error("", t); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(t).build(); } }  @GET @Path("/") Response getApps(@PathParam("clusterId") String clusterId); @GET @Path("/{id}") Response getApp(@PathParam("clusterId") String clusterId, @PathParam("id") String appId); @GET @Path("/{id}/tasks") Response getTasks(@PathParam("clusterId") String clusterId, @PathParam("id") String appId); @POST @Path("/{id}/file") @Consumes(MediaType.MULTIPART_FORM_DATA) Response uploadFile(@PathParam("clusterId") String clusterId, @PathParam("id") String appId,
                               @FormDataParam("file") InputStream uploadedInputStream,
                               @FormDataParam("file") FormDataContentDisposition fileDetail); @POST @Path("/") Response deployApp(@PathParam("clusterId") String clusterId, Map<String, Object> data); @POST @Path("/resources") Response deployResourceApp(@PathParam("clusterId") String clusterId, Map<String, Object> data); @PUT @Path("/{id}") Response updateApp(@PathParam("clusterId") String clusterId, @PathParam("id") String appId, Map<String, Object> data); @POST @Path("/{id}/restart") Response restartApp(@PathParam("clusterId") String clusterId, @PathParam("id") String appId); @DELETE @Path("/{id}") Response deleteApp(@PathParam("clusterId") String clusterId, @PathParam("id") String appId);  }