use of com.vip.saturn.job.console.domain.MoveNamespaceBatchStatus in project Saturn by vipshop.
the class NamespaceZkClusterMappingServiceImpl method moveNamespaceBatchTo.
@Override
public void moveNamespaceBatchTo(final String namespaces, final String zkClusterKeyNew, final String lastUpdatedBy, final boolean updateDBOnly) throws SaturnJobConsoleException {
final List<String> namespaceList = new ArrayList<>();
String[] split = namespaces.split(",");
if (split != null) {
for (String tmp : split) {
String namespace = tmp.trim();
if (!namespace.isEmpty()) {
namespaceList.add(namespace);
}
}
}
int size = namespaceList.size();
final MoveNamespaceBatchStatus moveNamespaceBatchStatus = new MoveNamespaceBatchStatus(size);
temporarySharedStatusService.delete(ShareStatusModuleNames.MOVE_NAMESPACE_BATCH_STATUS);
temporarySharedStatusService.create(ShareStatusModuleNames.MOVE_NAMESPACE_BATCH_STATUS, gson.toJson(moveNamespaceBatchStatus));
moveNamespaceBatchThreadPool.execute(new Runnable() {
@Override
public void run() {
try {
for (String namespace : namespaceList) {
try {
moveNamespaceBatchStatus.setMoving(namespace);
temporarySharedStatusService.update(ShareStatusModuleNames.MOVE_NAMESPACE_BATCH_STATUS, gson.toJson(moveNamespaceBatchStatus));
moveNamespaceTo(namespace, zkClusterKeyNew, lastUpdatedBy, updateDBOnly);
moveNamespaceBatchStatus.incrementSuccessCount();
} catch (SaturnJobConsoleException e) {
if (("The namespace(" + namespace + ") is in " + zkClusterKeyNew).equals(e.getMessage())) {
moveNamespaceBatchStatus.incrementIgnoreCount();
} else {
moveNamespaceBatchStatus.incrementFailCount();
}
} finally {
moveNamespaceBatchStatus.setMoving("");
moveNamespaceBatchStatus.decrementUnDoCount();
temporarySharedStatusService.update(ShareStatusModuleNames.MOVE_NAMESPACE_BATCH_STATUS, gson.toJson(moveNamespaceBatchStatus));
}
}
} finally {
moveNamespaceBatchStatus.setFinished(true);
temporarySharedStatusService.update(ShareStatusModuleNames.MOVE_NAMESPACE_BATCH_STATUS, gson.toJson(moveNamespaceBatchStatus));
}
}
});
}
use of com.vip.saturn.job.console.domain.MoveNamespaceBatchStatus in project Saturn by vipshop.
the class NamespaceZkClusterMappingController method getMoveNamespaceBatchStatus.
@RequestMapping(value = "getMoveNamespaceBatchStatus", method = RequestMethod.GET)
public RequestResult getMoveNamespaceBatchStatus(HttpServletRequest request) {
RequestResult requestResult = new RequestResult();
try {
Thread.sleep(400L);
MoveNamespaceBatchStatus moveNamespaceBatchStatus = namespaceZkClusterMappingService.getMoveNamespaceBatchStatus();
if (moveNamespaceBatchStatus == null) {
throw new SaturnJobConsoleException("The MoveNamespaceBatchStatus is not existing in db");
}
requestResult.setSuccess(true);
requestResult.setObj(moveNamespaceBatchStatus);
} catch (Throwable t) {
LOGGER.error(t.getMessage(), t);
requestResult.setSuccess(false);
requestResult.setMessage(t.toString());
}
return requestResult;
}
Aggregations