Search in sources :

Example 1 with Task

use of com.chinaunicom.rundocker.bean.returnparm.Task in project mesosFramework by zhizuqiu.

the class RestHandler method stopTask.

/**
 * 停止任务,如url?id=/2048/1
 *
 * @param mapParam 请求参数
 * @param response 请求响应
 * @return 返回参数
 */
@HttpMap(path = "/tasks", paramType = HttpMap.ParamType.URL_DATA, method = HttpMap.Method.DELETE)
public Task stopTask(Map<String, String> mapParam, DefaultFullHttpResponse response) {
    Task task = new Task();
    if (mapParam == null || mapParam.isEmpty()) {
        response.setStatus(BAD_REQUEST);
        return task;
    }
    String id = mapParam.get("id");
    if (id == null || id.trim().isEmpty()) {
        response.setStatus(BAD_REQUEST);
        return task;
    }
    Task taskTemp = stopOneTask(id);
    if (taskTemp != null) {
        task = taskTemp;
    }
    return task;
}
Also used : Task(com.chinaunicom.rundocker.bean.returnparm.Task) HttpMap(com.zhizuqiu.nettyrestful.annotation.HttpMap)

Example 2 with Task

use of com.chinaunicom.rundocker.bean.returnparm.Task in project mesosFramework by zhizuqiu.

the class RestHandler method stopTasks.

/**
 * 停止多个
 *
 * @param jsonParam 请求参数
 * @param response  请求响应
 * @return 返回参数
 */
@HttpMap(path = "/tasks", paramType = HttpMap.ParamType.JSON, method = HttpMap.Method.DELETE)
public List<Task> stopTasks(String jsonParam, DefaultFullHttpResponse response) {
    List<Task> list = new ArrayList<>();
    if (jsonParam == null) {
        return list;
    }
    BaseIds ids = null;
    try {
        ids = new Gson().fromJson(jsonParam, BaseIds.class);
    } catch (JsonSyntaxException e) {
        response.setStatus(INTERNAL_SERVER_ERROR);
    }
    if (ids == null) {
        return list;
    }
    for (String id : ids.getIds()) {
        Task task = stopOneTask(id);
        if (task != null) {
            list.add(task);
        }
    }
    return list;
}
Also used : Task(com.chinaunicom.rundocker.bean.returnparm.Task) JsonSyntaxException(com.google.gson.JsonSyntaxException) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) HttpMap(com.zhizuqiu.nettyrestful.annotation.HttpMap)

Example 3 with Task

use of com.chinaunicom.rundocker.bean.returnparm.Task in project mesosFramework by zhizuqiu.

the class RestHandler method deleteJobs.

/**
 * 删除多个任务
 *
 * @param jsonParam 请求参数
 * @param response  请求响应
 * @return 返回参数
 */
@HttpMap(path = "/jobs", paramType = HttpMap.ParamType.JSON, method = HttpMap.Method.DELETE)
public List<Task> deleteJobs(String jsonParam, DefaultFullHttpResponse response) {
    List<Task> list = new ArrayList<>();
    if (jsonParam == null) {
        return list;
    }
    BaseIds ids = null;
    try {
        ids = new Gson().fromJson(jsonParam, BaseIds.class);
    } catch (JsonSyntaxException e) {
        response.setStatus(INTERNAL_SERVER_ERROR);
    }
    if (ids == null) {
        return list;
    }
    for (String id : ids.getIds()) {
        Task task = deleteOneJob(id);
        if (task != null) {
            list.add(task);
        }
    }
    return list;
}
Also used : Task(com.chinaunicom.rundocker.bean.returnparm.Task) JsonSyntaxException(com.google.gson.JsonSyntaxException) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) HttpMap(com.zhizuqiu.nettyrestful.annotation.HttpMap)

Example 4 with Task

use of com.chinaunicom.rundocker.bean.returnparm.Task in project mesosFramework by zhizuqiu.

the class RestHandler method startTasks.

/**
 * 启动多个
 *
 * @param jsonParam 请求参数
 * @param response  请求响应
 * @return 返回参数
 */
@HttpMap(path = "/tasks", paramType = HttpMap.ParamType.JSON, method = HttpMap.Method.PUT)
public List<Task> startTasks(String jsonParam, DefaultFullHttpResponse response) {
    List<Task> list = new ArrayList<>();
    if (jsonParam == null) {
        return list;
    }
    BaseIds ids = null;
    try {
        ids = new Gson().fromJson(jsonParam, BaseIds.class);
    } catch (JsonSyntaxException e) {
        response.setStatus(INTERNAL_SERVER_ERROR);
    }
    if (ids == null) {
        return list;
    }
    for (String id : ids.getIds()) {
        Task task = startOneTask(id);
        if (task != null) {
            list.add(task);
        }
    }
    // 判断是否还有任务未下发,是则请求offer
    if (!SchedulerService.checkAllAppsIsAccept()) {
        AppDataStore.getSchedulerDriver().reviveOffers();
        logger.info("reviveOffers");
    }
    return list;
}
Also used : Task(com.chinaunicom.rundocker.bean.returnparm.Task) JsonSyntaxException(com.google.gson.JsonSyntaxException) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) HttpMap(com.zhizuqiu.nettyrestful.annotation.HttpMap)

Example 5 with Task

use of com.chinaunicom.rundocker.bean.returnparm.Task in project mesosFramework by zhizuqiu.

the class RestHandler method stopOneTask.

/**
 * 停止一个
 */
private Task stopOneTask(String id) {
    Task task = new Task();
    task.setId(id);
    String key = Tools.getStringByJsonpathRecursion(id.trim().replaceAll("/", "."));
    DockerStatus dockerStatus = AppDataStore.statusGet(key);
    if (dockerStatus == null) {
        return null;
    }
    if (dockerStatus.getStatus() != JobState.RUNNING && dockerStatus.getStatus() != JobState.STAGING) {
        return task;
    }
    Protos.TaskID taskID = Protos.TaskID.newBuilder().setValue(key).build();
    AppDataStore.getSchedulerDriver().killTask(taskID);
    return task;
}
Also used : Task(com.chinaunicom.rundocker.bean.returnparm.Task) Protos(org.apache.mesos.Protos) DockerStatus(com.chinaunicom.rundocker.bean.DockerStatus)

Aggregations

Task (com.chinaunicom.rundocker.bean.returnparm.Task)9 HttpMap (com.zhizuqiu.nettyrestful.annotation.HttpMap)6 DockerStatus (com.chinaunicom.rundocker.bean.DockerStatus)3 Gson (com.google.gson.Gson)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 ArrayList (java.util.ArrayList)3 Protos (org.apache.mesos.Protos)2 DockerJob (com.chinaunicom.rundocker.bean.DockerJob)1