Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getGroups method #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</developers>

<properties>
<feign-version>6.1.3</feign-version>
<feign-version>8.11.0</feign-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
45 changes: 27 additions & 18 deletions src/main/java/mesosphere/marathon/client/Marathon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,23 +13,23 @@
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;
import mesosphere.marathon.client.model.v2.Result;
import mesosphere.marathon.client.utils.MarathonException;
import feign.RequestLine;

public interface Marathon {
// Apps
@RequestLine("GET /v2/apps")
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();
Expand All @@ -38,31 +38,37 @@ 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;

// Tasks

Expand All @@ -71,18 +77,18 @@ DeleteAppTaskResponse deleteAppTask(@Named("app_id") String appId,
List<Deployment> 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();
Expand All @@ -92,6 +98,9 @@ DeleteAppTaskResponse deleteAppTask(@Named("app_id") String appId,
// Server Info
@RequestLine("GET /v2/info")
GetServerInfoResponse getServerInfo();

@RequestLine("GET /v2/leader")
GetServerInfoResponse getLeader();

// Miscellaneous

Expand Down
116 changes: 116 additions & 0 deletions src/main/java/mesosphere/marathon/client/model/v2/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,121 @@ public void setHealthChecks(List<HealthCheck> 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<Port> portMappings = new ArrayList<Port>();
private List<Parameter> parameters = new ArrayList<Parameter>();
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<Volume> volumes = new ArrayList<Volume>();

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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}