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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations