Search in sources :

Example 6 with DockerStatus

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

the class EtcdServiceTest method setStatusAtomicTest.

@Test
public void setStatusAtomicTest() {
    Long logTime = System.currentTimeMillis();
    DockerStatus dockerStatus = new DockerStatus();
    dockerStatus.init();
    dockerStatus.setCurrentTime();
    dockerStatus.setId(".2048.1");
    EtcdService.SetResult setResult = etcdService.setStatusAtomic(logTime, dockerStatus);
    System.out.println(setResult);
}
Also used : EtcdService(com.chinaunicom.rundocker.service.EtcdService) DockerStatus(com.chinaunicom.rundocker.bean.DockerStatus) Test(org.junit.Test)

Example 7 with DockerStatus

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

the class DockerScheduler method statusUpdate.

@Override
public void statusUpdate(SchedulerDriver schedulerDriver, TaskStatus taskStatus) {
    // 时间戳
    Long logTime = System.currentTimeMillis();
    logger.info("[" + logTime + "]" + "---------------------");
    logger.info("[" + logTime + "]" + "Statuses update: " + taskStatus.getState() + " from " + taskStatus.getTaskId().getValue());
    logger.info("[" + logTime + "]" + taskStatus);
    String key = taskStatus.getTaskId().getValue();
    DockerJob job = AppDataStore.jobsGet(key);
    if (job == null) {
        logger.error("收到状态的任务id不在[jobs]中");
        return;
    }
    DockerStatus jobStatus = AppDataStore.statusGet(key);
    if (jobStatus == null) {
        logger.error("收到状态的任务id不在[jobStatus]中");
        return;
    }
    // 如果是等待delete的任务,做删除操作
    if (jobStatus.getStatus() == JobState.WAIT_DELETE) {
        logger.info("this is a waiting delete app");
        // 为null时,表示没有持久卷
        String persistenceAgentid = jobStatus.get_persistenceInfo().getPersistenceAgentid();
        // 删除持久卷
        MesosService.MesosDoResult mesosDoResult = mesosService.destroy(persistenceAgentid, job);
        logger.error("mesosService.destroy() : " + mesosDoResult.toString());
        // 删除预留资源
        MesosService.MesosDoResult resultUnReserve = mesosService.unReserve(persistenceAgentid, job);
        logger.error("mesosService.unReserve() : " + mesosDoResult.toString());
        // 删除任务
        AppDataStore.remove(key);
        etcdService.deleteNodeOnlyReturnPre(logTime, AppDataStore.getConfig().getFrameworkName() + JOBS_PATH + key);
        etcdService.deleteNodeOnlyReturnPre(logTime, AppDataStore.getConfig().getFrameworkName() + JOBSTATUS_PATH + key);
    } else {
        // mesos任务状态向自定义状态的转换
        switch(taskStatus.getState()) {
            case TASK_RUNNING:
                jobStatus.started();
                jobStatus.setCurrentTime();
                jobStatus.setMessage(null);
                jobStatus.setSlaveId(taskStatus.getSlaveId().getValue());
                jobStatus = SchedulerService.setPortBindings(jobStatus, taskStatus);
                jobStatus = SchedulerService.setHealthy(job.hasHealthCheck(), jobStatus, taskStatus);
                break;
            case TASK_FINISHED:
                jobStatus.succeed();
                jobStatus.setCurrentTime();
                jobStatus.setMessage(taskStatus.getMessage());
                jobStatus.setHealthy(job.hasHealthCheck(), false);
                // portNeed
                SchedulerService.removePortNeed(key, jobStatus);
                jobStatus.clearAllPortNeed();
                SchedulerService.stopTaskWhenDependenceStop(key, false);
                break;
            case TASK_FAILED:
            case TASK_KILLED:
            case TASK_LOST:
            case TASK_ERROR:
                jobStatus.fail(job.getRetries());
                jobStatus.setCurrentTime();
                jobStatus.setMessage(taskStatus.getMessage());
                jobStatus.setHealthy(job.hasHealthCheck(), false);
                // portNeed
                SchedulerService.removePortNeed(key, jobStatus);
                jobStatus.clearAllPortNeed();
                SchedulerService.stopTaskWhenDependenceStop(key, true);
                break;
            default:
                break;
        }
        // 更新etcd中的任务状态
        EtcdService.SetResult setResult = etcdService.setStatusAtomic(logTime, jobStatus);
        switch(setResult) {
            case HAS_EXCEPTION:
                // todo 触发同步状态方法
                break;
            default:
                break;
        }
        logger.info("[" + logTime + "]" + "statusUpdate->setStatusAtomic:" + setResult);
    }
    // 判断是否还有任务未下发,是则请求offer
    if (!SchedulerService.checkAllAppsIsAccept()) {
        schedulerDriver.reviveOffers();
        logger.info("reviveOffers");
    }
}
Also used : MesosService(com.chinaunicom.rundocker.service.MesosService) EtcdService(com.chinaunicom.rundocker.service.EtcdService) DockerStatus(com.chinaunicom.rundocker.bean.DockerStatus) DockerJob(com.chinaunicom.rundocker.bean.DockerJob)

Example 8 with DockerStatus

use of com.chinaunicom.rundocker.bean.DockerStatus 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)

Example 9 with DockerStatus

use of com.chinaunicom.rundocker.bean.DockerStatus 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 10 with DockerStatus

use of com.chinaunicom.rundocker.bean.DockerStatus 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)

Aggregations

DockerStatus (com.chinaunicom.rundocker.bean.DockerStatus)16 DockerJob (com.chinaunicom.rundocker.bean.DockerJob)9 Task (com.chinaunicom.rundocker.bean.returnparm.Task)3 EtcdService (com.chinaunicom.rundocker.service.EtcdService)3 Gson (com.google.gson.Gson)3 ArrayList (java.util.ArrayList)3 Protos (org.apache.mesos.Protos)3 ResponseNode (com.chinaunicom.etcd.v2.model.ResponseNode)2 AppDataStore (com.chinaunicom.rundocker.store.AppDataStore)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 Test (org.junit.Test)2 ClientException (com.chinaunicom.etcd.v2.exception.ClientException)1 ServerException (com.chinaunicom.etcd.v2.exception.ServerException)1 Node (com.chinaunicom.etcd.v2.model.Node)1 ResponseNodeAndPrevnode (com.chinaunicom.etcd.v2.model.ResponseNodeAndPrevnode)1 HostAndPort (com.chinaunicom.rundocker.bean.HostAndPort)1 Jobs (com.chinaunicom.rundocker.bean.returnparm.Jobs)1 MesosService (com.chinaunicom.rundocker.service.MesosService)1 OfferTemp (com.chinaunicom.rundocker.service.OfferTemp)1 Config (com.chinaunicom.rundocker.store.Config)1