use of com.chinaunicom.etcd.v2.exception.ClientException in project mesosFramework by zhizuqiu.
the class EtcdService method deleteNodeOnlyReturnPre.
public ReturnPre deleteNodeOnlyReturnPre(Long logTime, String key) {
boolean deleteSuccess = false;
String preValue = null;
try {
ResponseNodeAndPrevnode responseNodeAndPrevnode = etcd.deleteKey(key);
if (EtcdAction.DELETE.equals(responseNodeAndPrevnode.getAction())) {
if (responseNodeAndPrevnode.getPrevNode() != null) {
preValue = responseNodeAndPrevnode.getPrevNode().getValue();
}
deleteSuccess = true;
}
} catch (ClientException e) {
logger.error("[" + logTime + "]" + "deleteNodeOnlyReturnPre->ClientException->" + e.getDetail().getMessage());
} catch (ServerException e) {
logger.error("[" + logTime + "]" + "deleteNodeOnlyReturnPre->ServerException->" + e.getDetail().getMessage());
} catch (Exception e) {
logger.error("[" + logTime + "]" + "deleteNodeOnlyReturnPre->ServerException->" + e.getMessage());
}
return new ReturnPre(deleteSuccess, deleteSuccess ? preValue : null);
}
use of com.chinaunicom.etcd.v2.exception.ClientException in project mesosFramework by zhizuqiu.
the class EtcdService method setNodeAtomic.
/**
* 设置
*
* @param logTime 任务标识
* @param key key
* @param value value
* @return 成功与否
*/
public Boolean setNodeAtomic(Long logTime, String key, String value) {
boolean getSuccess = false;
ResponseNode responseNode;
try {
responseNode = etcd.getKey(key);
if (EtcdAction.GET.equals(responseNode.getAction())) {
getSuccess = true;
}
} catch (Exception e) {
logger.error("[" + logTime + "]" + e.getMessage());
return false;
}
if (!getSuccess) {
return false;
}
boolean setSuccess = false;
try {
ResponseNodeAndPrevnode responseNodeAndPrevnode = etcd.setKeyAtomic(key, value, String.valueOf(responseNode.getNode().getModifiedIndex()));
if (EtcdAction.SET.equals(responseNodeAndPrevnode.getAction())) {
setSuccess = true;
}
} catch (ClientException e) {
logger.error("[" + logTime + "]" + "节点赋值失败->请求无效->" + e.getDetail().getMessage());
} catch (ServerException e) {
logger.error("[" + logTime + "]" + "节点赋值失败->服务器异常->" + e.getMessage());
} catch (Exception e) {
logger.error("[" + logTime + "]" + "节点赋值失败->其他异常->" + e.getMessage());
}
return setSuccess;
}
use of com.chinaunicom.etcd.v2.exception.ClientException in project mesosFramework by zhizuqiu.
the class EtcdService method setNodeOnlyReturnPre.
/**
* 如果设置成功返回之前的value值
*
* @param logTime 任务标识
* @param key key
* @param value value
* @return 之前的值
*/
public ReturnPre setNodeOnlyReturnPre(Long logTime, String key, String value) {
boolean setSuccess = false;
String preValue = null;
try {
ResponseNodeAndPrevnode responseNodeAndPrevnode = etcd.setKey(key, value);
if (EtcdAction.SET.equals(responseNodeAndPrevnode.getAction())) {
if (responseNodeAndPrevnode.getPrevNode() != null) {
preValue = responseNodeAndPrevnode.getPrevNode().getValue();
}
setSuccess = true;
}
} catch (ClientException e) {
logger.error("[" + logTime + "]" + "setNodeOnlyReturnPre->ClientException->" + e.getDetail().getMessage());
} catch (ServerException e) {
logger.error("[" + logTime + "]" + "setNodeOnlyReturnPre->ServerException->" + e.getDetail().getMessage());
} catch (Exception e) {
logger.error("[" + logTime + "]" + "setNodeOnlyReturnPre->Exception->" + e.getMessage());
}
return new ReturnPre(setSuccess, setSuccess ? preValue : null);
}
use of com.chinaunicom.etcd.v2.exception.ClientException in project mesosFramework by zhizuqiu.
the class EtcdService method getNodes.
/**
* 从请求队列中获取请求
*
* @param logTime 任务标识
* @param queuePath 队列路径
* @return 返回请求节点,如果不存在第一个请求,返回null
*/
public List<Node> getNodes(Long logTime, String queuePath) {
try {
ResoponseAtom result = etcd.getInOdrderKeys(queuePath);
logger.debug("[" + logTime + "]" + "getNodes");
List<Node> nodes = result.getNode().getNodes();
if (nodes != null && nodes.size() > 0) {
logger.info("[" + logTime + "]" + "getNodes size:" + nodes.size());
return nodes;
}
} catch (ClientException e) {
logger.error("[" + logTime + "]" + "getNodes->ClientException->" + e.getDetail().getMessage());
return null;
} catch (ServerException e) {
logger.error("[" + logTime + "]" + "getNodes->ServerException->" + e.getDetail().getMessage());
return null;
} catch (Exception e) {
logger.error("[" + logTime + "]" + "getNodes->Exception->" + e.getMessage());
return null;
}
return new ArrayList<>();
}
use of com.chinaunicom.etcd.v2.exception.ClientException in project mesosFramework by zhizuqiu.
the class EtcdService method setStatusAtomic.
/**
* 设置任务状态,当状态更新时间 < etcd节点的时间
*
* @param logTime 任务标识
* @param jobStatus jobStatus
* @return 成功与否
*/
public SetResult setStatusAtomic(Long logTime, DockerStatus jobStatus) {
String key = AppDataStore.getConfig().getFrameworkName() + JOBSTATUS_PATH + Tools.getStringByJsonpathRecursion(jobStatus.getId().replaceAll("/", "."));
DockerStatus jobStatusTemp = null;
boolean getSuccess = false;
Integer modifiedIndex = null;
/*
* JsonSyntaxException|ClientException表示节点异常,可以直接覆盖
* ServerException|Exception表示未知异常,需要同步程序处理
*/
try {
ResponseNode responseNode = etcd.getKey(key);
if (EtcdAction.GET.equals(responseNode.getAction())) {
jobStatusTemp = new Gson().fromJson(responseNode.getNode().getValue(), DockerStatus.class);
modifiedIndex = responseNode.getNode().getModifiedIndex();
getSuccess = true;
}
} catch (JsonSyntaxException e) {
logger.error("[" + logTime + "]" + "setNodeAtomic->fromJson->JsonSyntaxException->" + e.getMessage());
getSuccess = true;
} catch (ClientException e) {
logger.error("[" + logTime + "]" + "setNodeAtomic->getKey->ClientException->" + e.getDetail().getMessage());
getSuccess = true;
} catch (ServerException e) {
logger.error("[" + logTime + "]" + "setNodeAtomic->getKey->ServerException->" + e.getDetail().getMessage());
return HAS_EXCEPTION;
} catch (Exception e) {
logger.error("[" + logTime + "]" + "setNodeAtomic->getKey->Exception->" + e.getMessage());
return HAS_EXCEPTION;
}
if (!getSuccess) {
return HAS_EXCEPTION;
}
// 如果状态更新时间<etcd节点的时间,不更新
if (jobStatusTemp != null) {
Double timestampTemp = jobStatusTemp.getTimestamp();
if (timestampTemp != null) {
Double timestamp = jobStatus.getTimestamp();
if (timestamp < timestampTemp) {
return UNNECESSARY;
}
}
}
boolean setSuccess = false;
try {
ResponseNodeAndPrevnode responseNodeAndPrevnode;
if (modifiedIndex != null) {
responseNodeAndPrevnode = etcd.setKeyAtomic(key, new Gson().toJson(jobStatus), String.valueOf(modifiedIndex));
} else {
responseNodeAndPrevnode = etcd.setKey(key, new Gson().toJson(jobStatus));
}
if (EtcdAction.COMPARE_AND_SWAP.equals(responseNodeAndPrevnode.getAction())) {
setSuccess = true;
}
} catch (ClientException e) {
logger.error("[" + logTime + "]" + "setNodeAtomic->setKeyAtomic->ClientException->" + e.getDetail().getMessage());
return HAS_EXCEPTION;
} catch (ServerException e) {
logger.error("[" + logTime + "]" + "setNodeAtomic->setKeyAtomic->ServerException->" + e.getDetail().getMessage());
return HAS_EXCEPTION;
} catch (Exception e) {
logger.error("[" + logTime + "]" + "setNodeAtomic->setKeyAtomic->Exception->" + e.getMessage());
return HAS_EXCEPTION;
}
return setSuccess ? SUCCESS : HAS_EXCEPTION;
}
Aggregations