Search in sources :

Example 66 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project mesosFramework by zhizuqiu.

the class SchedulerService method getJobsFromMustache.

/**
 * 从模板中获取jobs,并用环境变量填充
 */
public static Jobs getJobsFromMustache() {
    Long logTime = System.currentTimeMillis();
    if (AppDataStore.getConfig().getStoreMustachePath() == null) {
        logger.info("[" + logTime + "]" + "getStoreMustachePath is null , skip");
        return null;
    }
    String mustachePath = AppDataStore.getConfig().getStoreMustachePath();
    Map<String, String> envs = System.getenv();
    Jobs jobs;
    String json = Tools.initMustache(envs, mustachePath);
    if (json == null) {
        logger.info("initMustache json is null");
        return null;
    } else {
        logger.info(json);
    }
    try {
        jobs = new Gson().fromJson(json, Jobs.class);
    } catch (JsonSyntaxException e) {
        logger.error("fromJson  exception->" + e.getMessage());
        return null;
    }
    return jobs;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Jobs(com.chinaunicom.rundocker.bean.returnparm.Jobs) Gson(com.google.gson.Gson) ByteString(com.google.protobuf.ByteString)

Example 67 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException 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 68 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException 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 69 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException 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 70 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project mesosFramework by zhizuqiu.

the class EtcdService method getJobsFromEtcd.

public Boolean getJobsFromEtcd(Long logTime) {
    logger.info("[" + logTime + "]" + "---------------------");
    logger.info("[" + logTime + "]" + "start getJobsFromEtcd");
    // 获取队列所有节点
    List<Node> jobNode = getNodes(logTime, AppDataStore.getConfig().getFrameworkName() + StaticStr.JOBS_PATH);
    if (jobNode == null) {
        logger.info("[" + logTime + "]" + "node is null");
        return false;
    }
    Map<String, DockerJob> jobMap = new HashMap<>();
    for (Node node : jobNode) {
        DockerJob job;
        try {
            job = new Gson().fromJson(node.getValue(), DockerJob.class);
        } catch (JsonSyntaxException e) {
            logger.error("[" + logTime + "]" + "getJobsFromEtcd->" + node.getKey() + "->JsonSyntaxException:" + e.getMessage());
            continue;
        }
        if (job == null) {
            continue;
        }
        String id = job.getId();
        String key = Tools.getStringByJsonpathRecursion(id.replaceAll("/", "."));
        jobMap.put(key, job);
    }
    AppDataStore.jobsPutAll(jobMap);
    // 获取队列所有节点
    List<Node> statusNodes = getNodes(logTime, AppDataStore.getConfig().getFrameworkName() + JOBSTATUS_PATH);
    if (statusNodes == null) {
        logger.info("[" + logTime + "]" + "node is null");
        return false;
    }
    Map<String, DockerStatus> statusMap = new HashMap<>();
    for (Node node : statusNodes) {
        DockerStatus jobStatus;
        try {
            jobStatus = new Gson().fromJson(node.getValue(), DockerStatus.class);
        } catch (JsonSyntaxException e) {
            logger.error("[" + logTime + "]" + "getJobsFromEtcd->" + node.getKey() + "->JsonSyntaxException:" + e.getMessage());
            continue;
        }
        if (jobStatus == null) {
            continue;
        }
        String id = jobStatus.getId();
        String key = Tools.getStringByJsonpathRecursion(id.replaceAll("/", "."));
        statusMap.put(key, jobStatus);
    }
    AppDataStore.statusPutAll(statusMap);
    return true;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) HashMap(java.util.HashMap) ResponseNode(com.chinaunicom.etcd.v2.model.ResponseNode) Node(com.chinaunicom.etcd.v2.model.Node) DockerStatus(com.chinaunicom.rundocker.bean.DockerStatus) Gson(com.google.gson.Gson) DockerJob(com.chinaunicom.rundocker.bean.DockerJob)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)379 Gson (com.google.gson.Gson)169 IOException (java.io.IOException)83 HashMap (java.util.HashMap)68 JsonElement (com.google.gson.JsonElement)62 JsonObject (com.google.gson.JsonObject)58 ArrayList (java.util.ArrayList)46 JsonParser (com.google.gson.JsonParser)42 GsonBuilder (com.google.gson.GsonBuilder)38 Cursor (android.database.Cursor)33 InputStreamReader (java.io.InputStreamReader)30 Map (java.util.Map)30 BadRequestException (co.cask.cdap.common.BadRequestException)28 JsonArray (com.google.gson.JsonArray)28 Path (javax.ws.rs.Path)28 Reader (java.io.Reader)26 Type (java.lang.reflect.Type)23 JsonIOException (com.google.gson.JsonIOException)21 FileReader (java.io.FileReader)21 File (java.io.File)19