From 45e325616c6227b0759bc6084550b5c160bbf15b Mon Sep 17 00:00:00 2001 From: rkorland Date: Tue, 27 Oct 2015 08:03:20 -0700 Subject: [PATCH 1/4] add getGroups method --- src/main/java/mesosphere/marathon/client/Marathon.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/mesosphere/marathon/client/Marathon.java b/src/main/java/mesosphere/marathon/client/Marathon.java index 592018e..fad4795 100644 --- a/src/main/java/mesosphere/marathon/client/Marathon.java +++ b/src/main/java/mesosphere/marathon/client/Marathon.java @@ -13,6 +13,7 @@ import mesosphere.marathon.client.model.v2.GetAppsResponse; import mesosphere.marathon.client.model.v2.GetEventSubscriptionRegisterResponse; import mesosphere.marathon.client.model.v2.GetEventSubscriptionsResponse; +import mesosphere.marathon.client.model.v2.GetGroupsResponse; import mesosphere.marathon.client.model.v2.GetServerInfoResponse; import mesosphere.marathon.client.model.v2.GetTasksResponse; import mesosphere.marathon.client.model.v2.Group; @@ -63,6 +64,9 @@ DeleteAppTaskResponse deleteAppTask(@Named("app_id") String appId, @RequestLine("GET /v2/groups/{id}") Group getGroup(@Named("id") String id) throws MarathonException; + + @RequestLine("GET /v2/groups") + GetGroupsResponse getGroups() throws MarathonException; // Tasks From 0da3ebdae3c6bcaee09a46dfb570002723ccbc0c Mon Sep 17 00:00:00 2001 From: rkorland Date: Tue, 3 Nov 2015 05:43:39 +0200 Subject: [PATCH 2/4] add DockerAppBuilder --- .../marathon/client/model/v2/App.java | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/src/main/java/mesosphere/marathon/client/model/v2/App.java b/src/main/java/mesosphere/marathon/client/model/v2/App.java index 1750805..d8b2c39 100644 --- a/src/main/java/mesosphere/marathon/client/model/v2/App.java +++ b/src/main/java/mesosphere/marathon/client/model/v2/App.java @@ -173,5 +173,121 @@ public void setHealthChecks(List healthChecks) { public String toString() { return ModelUtils.toString(this); } + + public static DockerAppBuilder dockerAppBuilder(String appId, String dockerImage, Double cpus, Double mem, Integer instances){ + return new DockerAppBuilder(appId, dockerImage, cpus, mem, instances); + } + + public static class DockerAppBuilder { + + private Collection portMappings = new ArrayList(); + private List parameters = new ArrayList(); + private String network = "BRIDGE"; + private String appId = null; + private Integer instances = 1; + private String dockerImage = null; + private Double cpus = null; + private Double mem = null; + private boolean forcePullImage = false; + private boolean privileged = false; + private Collection volumes = new ArrayList(); + + public DockerAppBuilder(String appId, String dockerImage, Double cpus, Double mem, Integer instances) { + this.appId = appId; + this.dockerImage = dockerImage; + this.cpus = cpus; + this.mem = mem; + this.instances = instances; + } + + public DockerAppBuilder instances(Integer instances) { + this.instances = instances; + return this; + } + + public DockerAppBuilder paramter(String key, String value){ + Parameter parameter = new Parameter(key, value); + parameters.add(parameter); + return this; + } + + public DockerAppBuilder volume(String containerPath, String hostPath, String mode){ + Volume volume = new Volume(); + volume.setContainerPath(containerPath); + volume.setHostPath(hostPath); + volume.setMode(mode); + volumes.add(volume); + return this; + } + + public DockerAppBuilder volume(String containerPath, String hostPath){ + volume(containerPath, hostPath, null); + return this; + } + + public DockerAppBuilder portMappings(Integer containerPort, Integer hostPort) { + Port port = buildPort(containerPort, hostPort); + portMappings.add(port); + return this; + } + + public DockerAppBuilder portMappings(Integer containerPort) { + portMappings(containerPort, null); + return this; + } + private Port buildPort(Integer containerPort, Integer hostPort) { + Port port = new Port(containerPort); + port.setHostPort(hostPort); + return port; + } + + public DockerAppBuilder network(String network) { + this.network = network; + return this; + } + + public DockerAppBuilder forcePullImage(boolean forcePullImage){ + this.forcePullImage = forcePullImage; + return this; + } + + public DockerAppBuilder privileged(boolean privileged){ + this.privileged = privileged; + return this; + } + + public App build() { + Docker docker = new Docker(); + docker.setImage(dockerImage); + docker.setForcePullImage(forcePullImage); + docker.setPrivileged(privileged); + docker.setNetwork(network); + + if (!portMappings.isEmpty()) { + docker.setPortMappings(portMappings); + } + + if(!parameters.isEmpty()){ + docker.setParameters(parameters); + } + + Container container = new Container(); + container.setType("DOCKER"); + container.setDocker(docker); + + if(!volumes.isEmpty()){ + container.setVolumes(volumes); + } + + App app = new App(); + app.setId(appId); + app.setInstances(instances); + app.setCpus(cpus); + app.setMem(mem); + app.setContainer(container); + + return app; + } + } } From 2826aec4a1b89f760df5b3e746a32609025a289e Mon Sep 17 00:00:00 2001 From: rkorland Date: Tue, 3 Nov 2015 05:44:14 +0200 Subject: [PATCH 3/4] update to feign 8.11.0 and add method updateGroup --- pom.xml | 2 +- .../mesosphere/marathon/client/Marathon.java | 38 ++++++++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index a6cbf0b..0293311 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ - 6.1.3 + 8.11.0 UTF-8 diff --git a/src/main/java/mesosphere/marathon/client/Marathon.java b/src/main/java/mesosphere/marathon/client/Marathon.java index fad4795..f5394e3 100644 --- a/src/main/java/mesosphere/marathon/client/Marathon.java +++ b/src/main/java/mesosphere/marathon/client/Marathon.java @@ -2,8 +2,8 @@ import java.util.List; -import javax.inject.Named; - +import feign.Param; +import feign.RequestLine; import mesosphere.marathon.client.model.v2.App; import mesosphere.marathon.client.model.v2.DeleteAppTaskResponse; import mesosphere.marathon.client.model.v2.DeleteAppTasksResponse; @@ -19,7 +19,6 @@ import mesosphere.marathon.client.model.v2.Group; import mesosphere.marathon.client.model.v2.Result; import mesosphere.marathon.client.utils.MarathonException; -import feign.RequestLine; public interface Marathon { // Apps @@ -27,10 +26,10 @@ public interface Marathon { GetAppsResponse getApps(); @RequestLine("GET /v2/apps/{id}") - GetAppResponse getApp(@Named("id") String id) throws MarathonException; + GetAppResponse getApp(@Param("id") String id) throws MarathonException; @RequestLine("GET /v2/apps/{id}/tasks") - GetAppTasksResponse getAppTasks(@Named("id") String id); + GetAppTasksResponse getAppTasks(@Param("id") String id); @RequestLine("GET /v2/tasks") GetTasksResponse getTasks(); @@ -39,31 +38,34 @@ public interface Marathon { App createApp(App app) throws MarathonException; @RequestLine("PUT /v2/apps/{app_id}") - void updateApp(@Named("app_id") String appId, App app); + void updateApp(@Param("app_id") String appId, App app); @RequestLine("POST /v2/apps/{id}/restart?force={force}") - void restartApp(@Named("id") String id,@Named("force") boolean force); + void restartApp(@Param("id") String id,@Param("force") boolean force); @RequestLine("DELETE /v2/apps/{id}") - Result deleteApp(@Named("id") String id) throws MarathonException; + Result deleteApp(@Param("id") String id) throws MarathonException; @RequestLine("DELETE /v2/apps/{app_id}/tasks?host={host}&scale={scale}") - DeleteAppTasksResponse deleteAppTasks(@Named("app_id") String appId, - @Named("host") String host, @Named("scale") String scale); + DeleteAppTasksResponse deleteAppTasks(@Param("app_id") String appId, + @Param("host") String host, @Param("scale") String scale); @RequestLine("DELETE /v2/apps/{app_id}/tasks/{task_id}?scale={scale}") - DeleteAppTaskResponse deleteAppTask(@Named("app_id") String appId, - @Named("task_id") String taskId, @Named("scale") String scale); + DeleteAppTaskResponse deleteAppTask(@Param("app_id") String appId, + @Param("task_id") String taskId, @Param("scale") String scale); // Groups @RequestLine("POST /v2/groups") Result createGroup(Group group) throws MarathonException; + @RequestLine("PUT /v2/groups/{id}") + Result updateGroup(@Param("id") String id, Group group) throws MarathonException; + @RequestLine("DELETE /v2/groups/{id}") - Result deleteGroup(@Named("id") String id) throws MarathonException; + Result deleteGroup(@Param("id") String id) throws MarathonException; @RequestLine("GET /v2/groups/{id}") - Group getGroup(@Named("id") String id) throws MarathonException; + Group getGroup(@Param("id") String id) throws MarathonException; @RequestLine("GET /v2/groups") GetGroupsResponse getGroups() throws MarathonException; @@ -75,18 +77,18 @@ DeleteAppTaskResponse deleteAppTask(@Named("app_id") String appId, List getDeployments(); @RequestLine("DELETE /v2/deployments/{deploymentId}") - void cancelDeploymentAndRollback(@Named("deploymentId") String id); + void cancelDeploymentAndRollback(@Param("deploymentId") String id); @RequestLine("DELETE /v2/deployments/{deploymentId}?force=true") - void cancelDeployment(@Named("deploymentId") String id); + void cancelDeployment(@Param("deploymentId") String id); // Event Subscriptions @RequestLine("POST /v2/eventSubscriptions?callbackUrl={url}") - public GetEventSubscriptionRegisterResponse register(@Named("url") String url); + public GetEventSubscriptionRegisterResponse register(@Param("url") String url); @RequestLine("DELETE /v2/eventSubscriptions?callbackUrl={url}") - public GetEventSubscriptionRegisterResponse unregister(@Named("url") String url); + public GetEventSubscriptionRegisterResponse unregister(@Param("url") String url); @RequestLine("GET /v2/eventSubscriptions") public GetEventSubscriptionsResponse subscriptions(); From 8cfb3321bb6f390dcacf35e3beda2b5f90888f2d Mon Sep 17 00:00:00 2001 From: rkorland Date: Thu, 12 Nov 2015 08:48:44 +0200 Subject: [PATCH 4/4] add getLeader --- .../mesosphere/marathon/client/Marathon.java | 3 +++ .../client/model/v2/GetLeaderResponse.java | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/main/java/mesosphere/marathon/client/model/v2/GetLeaderResponse.java diff --git a/src/main/java/mesosphere/marathon/client/Marathon.java b/src/main/java/mesosphere/marathon/client/Marathon.java index f5394e3..99cecf2 100644 --- a/src/main/java/mesosphere/marathon/client/Marathon.java +++ b/src/main/java/mesosphere/marathon/client/Marathon.java @@ -98,6 +98,9 @@ DeleteAppTaskResponse deleteAppTask(@Param("app_id") String appId, // Server Info @RequestLine("GET /v2/info") GetServerInfoResponse getServerInfo(); + + @RequestLine("GET /v2/leader") + GetServerInfoResponse getLeader(); // Miscellaneous diff --git a/src/main/java/mesosphere/marathon/client/model/v2/GetLeaderResponse.java b/src/main/java/mesosphere/marathon/client/model/v2/GetLeaderResponse.java new file mode 100644 index 0000000..7fa90b6 --- /dev/null +++ b/src/main/java/mesosphere/marathon/client/model/v2/GetLeaderResponse.java @@ -0,0 +1,20 @@ +package mesosphere.marathon.client.model.v2; + +import mesosphere.marathon.client.utils.ModelUtils; + +public class GetLeaderResponse { + private String leader; + + public String getLeader() { + return leader; + } + + public void setLeader(String leader) { + this.leader = leader; + } + + @Override + public String toString() { + return ModelUtils.toString(this); + } +}