Search in sources :

Example 1 with MoveNamespaceBatchStatus

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));
            }
        }
    });
}
Also used : MoveNamespaceBatchStatus(com.vip.saturn.job.console.domain.MoveNamespaceBatchStatus) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 2 with 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;
}
Also used : MoveNamespaceBatchStatus(com.vip.saturn.job.console.domain.MoveNamespaceBatchStatus) RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MoveNamespaceBatchStatus (com.vip.saturn.job.console.domain.MoveNamespaceBatchStatus)2 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)2 RequestResult (com.vip.saturn.job.console.domain.RequestResult)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1