Search in sources :

Example 6 with Task

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

the class RestHandler method startTask.

/**
 * 启动任务,如url?id=/2048/1
 *
 * @param mapParam 请求参数
 * @param response 请求响应
 * @return 返回参数
 */
@HttpMap(path = "/tasks", paramType = HttpMap.ParamType.URL_DATA, method = HttpMap.Method.PUT)
public Task startTask(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 = startOneTask(id);
    if (taskTemp != null) {
        task = taskTemp;
    }
    // 判断是否还有任务未下发,是则请求offer
    if (!SchedulerService.checkAllAppsIsAccept()) {
        AppDataStore.getSchedulerDriver().reviveOffers();
        logger.info("reviveOffers");
    }
    return task;
}
Also used : Task(com.chinaunicom.rundocker.bean.returnparm.Task) HttpMap(com.zhizuqiu.nettyrestful.annotation.HttpMap)

Example 7 with Task

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

the class RestHandler method startOneTask.

/**
 * 启动一个
 */
private Task startOneTask(String id) {
    Task task = new Task();
    task.setId(id);
    task.setId(id);
    String key = Tools.getStringByJsonpathRecursion(id.trim().replaceAll("/", "."));
    DockerStatus dockerStatus = AppDataStore.statusGet(key);
    if (dockerStatus == null) {
        return null;
    }
    DockerJob dockerJob = AppDataStore.jobsGet(key);
    if (dockerJob == null) {
        return null;
    }
    if (dockerStatus.canRunAgain(dockerJob.getRetries())) {
        dockerStatus.setSubmitted(false);
        dockerStatus.setTryCount(0);
    }
    return task;
}
Also used : Task(com.chinaunicom.rundocker.bean.returnparm.Task) DockerStatus(com.chinaunicom.rundocker.bean.DockerStatus) DockerJob(com.chinaunicom.rundocker.bean.DockerJob)

Example 8 with Task

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

the class RestHandler method deleteOneJob.

/**
 * 删除一个
 */
private Task deleteOneJob(String id) {
    Task task = new Task();
    task.setId(id);
    String key = Tools.getStringByJsonpathRecursion(id.trim().replaceAll("/", "."));
    // 停止
    Protos.TaskID taskID = Protos.TaskID.newBuilder().setValue(key).build();
    AppDataStore.getSchedulerDriver().killTask(taskID);
    DockerStatus dockerStatus = AppDataStore.statusGet(key);
    if (dockerStatus != null) {
        dockerStatus.setStatus(JobState.WAIT_DELETE);
    } else {
        logger.error("delete app not exists");
        return null;
    }
    return task;
}
Also used : Task(com.chinaunicom.rundocker.bean.returnparm.Task) Protos(org.apache.mesos.Protos) DockerStatus(com.chinaunicom.rundocker.bean.DockerStatus)

Example 9 with Task

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

the class RestHandler method deleteJob.

/**
 * 删除单个任务
 */
@HttpMap(path = "/jobs", paramType = HttpMap.ParamType.URL_DATA, method = HttpMap.Method.DELETE)
public Task deleteJob(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 = deleteOneJob(id);
    if (taskTemp != null) {
        task = taskTemp;
    }
    return task;
}
Also used : Task(com.chinaunicom.rundocker.bean.returnparm.Task) HttpMap(com.zhizuqiu.nettyrestful.annotation.HttpMap)

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