步骤:
1、访问marathon下载源码地址为 https://github.com/mesosphere/marathon-client
2、修改Marathon类 此处多添加一个GET ping 的方法
===============================================================================================
package mesosphere.marathon.client;
import java.util.List;
import javax.inject.Named;
import mesosphere.marathon.client.model.v2.App;
import mesosphere.marathon.client.model.v2.DeleteAppTaskResponse;
import mesosphere.marathon.client.model.v2.DeleteAppTasksResponse;
import mesosphere.marathon.client.model.v2.Deployment;
import mesosphere.marathon.client.model.v2.GetAppResponse;
import mesosphere.marathon.client.model.v2.GetAppTasksResponse;
import mesosphere.marathon.client.model.v2.GetAppsResponse;
import mesosphere.marathon.client.model.v2.GetQueuesResponse;
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 {
//ping IP
@RequestLine("GET /ping")
void ping();
// Apps
@RequestLine("GET /v2/apps")
GetAppsResponse getApps();
@RequestLine("GET /v2/apps/{id}")
GetAppResponse getApp(@Named("id") String id) throws MarathonException;
@RequestLine("GET /v2/apps/{id}/tasks")
GetAppTasksResponse getAppTasks(@Named("id") String id);
@RequestLine("POST /v2/apps/{app_id}/restart")
Result reStartApp(@Named("app_id") String app_id) throws MarathonException;
@RequestLine("GET /v2/tasks")
GetTasksResponse getTasks();
@RequestLine("POST /v2/apps")
App createApp(App app) throws MarathonException;
@RequestLine("PUT /v2/apps/{app_id}")
void updateApp(@Named("app_id") String appId, App app) throws MarathonException;
@RequestLine("PUT /v2/apps/{app_id}?force=true")
void forceUpdateApp(@Named("app_id") String appId, App app) throws MarathonException;
@RequestLine("DELETE /v2/apps/{id}")
Result deleteApp(@Named("id") String id) throws MarathonException;
@RequestLine("DELETE /v2/apps/{id}?force=true")
Result forceDeleteApp(@Named("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);
@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);
// Groups
@RequestLine("POST /v2/groups")
Result createGroup(Group group) throws MarathonException;
@RequestLine("PUT /v2/groups/{id}")
Result updateGroup(@Named("id") String id, Group group) throws MarathonException;
@RequestLine("PUT /v2/groups/{id}?force=true")
Result forceUpdateGroup(@Named("id") String id, Group group) throws MarathonException;
@RequestLine("DELETE /v2/groups/{id}")
Result deleteGroup(@Named("id") String id) throws MarathonException;
@RequestLine("DELETE /v2/groups/{id}?force=true")
Result forceDeleteGroup(@Named("id") String id) throws MarathonException;
@RequestLine("GET /v2/groups/{id}")
Group getGroup(@Named("id") String id) throws MarathonException;
// Tasks
// Deployments
@RequestLine("GET /v2/deployments")
List<Deployment> getDeployments();
@RequestLine("DELETE /v2/deployments/{deploymentId}")
void cancelDeploymentAndRollback(@Named("deploymentId") String id);
@RequestLine("DELETE /v2/deployments/{deploymentId}?force=true")
void cancelDeployment(@Named("deploymentId") String id);
// Event Subscriptions
// Queue
@RequestLine("GET /v2/queue")
GetQueuesResponse getQueues() throws MarathonException;
// Server Info
@RequestLine("GET /v2/info")
GetServerInfoResponse getServerInfo();
// Miscellaneous
}
=============================================================================================
3、修改MarathonClient类 重载方法getInstance();
package mesosphere.marathon.client;
}
4、test
public class Test {
public static void main(String[] args){
String url = "http://ip:端口号";
Map<String,List<String>> urlConfs = new HashMap<String, List<String>>();
List<String> list = new ArrayList<String>();
list.add(url);
urlConfs.put("1", list);
Marathon marathon = MarathonClient.getInstance("1", urlConfs);
List<Deployment> list3 = marathon.getDeployments();
System.out.println(ModelUtils.toString(list3));
for(Deployment dep : list3){
System.out.println(dep.toString());
marathon.cancelDeployment(dep.getId());
}
}
5、所需jar包
feign.jar和inject.jar
文档中有可下载