private String buildRootPath(final String id) { return RepositoryPathUtils.buildZookeeperRootPath(rootPathPrefix, id); } }
private HmilyCompensationVO buildByNodePath(final String rootPath, final String zNodePath) { try { byte[] content = zooKeeper.getData(RepositoryPathUtils.buildZookeeperRootPath(rootPath, zNodePath), false, new Stat()); final CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(content, CoordinatorRepositoryAdapter.class); return ConvertHelper.buildVO(adapter); } catch (KeeperException | InterruptedException | HmilyException e) { e.printStackTrace(); } return null; }
@Override public Boolean batchRemove(final List<String> ids, final String appName) { if (CollectionUtils.isEmpty(ids) || StringUtils.isBlank(appName)) { return Boolean.FALSE; } final String rootPathPrefix = RepositoryPathUtils.buildZookeeperPathPrefix(appName); ids.stream().map(id -> { try { final String path = RepositoryPathUtils.buildZookeeperRootPath(rootPathPrefix, id); byte[] content = zooKeeper.getData(path, false, new Stat()); final CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(content, CoordinatorRepositoryAdapter.class); zooKeeper.delete(path, adapter.getVersion()); return 1; } catch (Exception e) { e.printStackTrace(); return -1; } }).count(); return Boolean.TRUE; }
@Override public int updateStatus(final String id, final Integer status) { final String path = RepositoryPathUtils.buildZookeeperRootPath(rootPathPrefix, id); try { byte[] content = zooKeeper.getData(path, false, new Stat()); if (content != null) { final CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(content, CoordinatorRepositoryAdapter.class); adapter.setStatus(status); zooKeeper.setData(path, objectSerializer.serialize(adapter), -1); } return ROWS; } catch (Exception e) { e.printStackTrace(); return FAIL_ROWS; } }
@Override public Boolean updateRetry(final String id, final Integer retry, final String appName) { if (StringUtils.isBlank(id) || StringUtils.isBlank(appName) || Objects.isNull(retry)) { return Boolean.FALSE; } final String rootPathPrefix = RepositoryPathUtils.buildZookeeperPathPrefix(appName); final String path = RepositoryPathUtils.buildZookeeperRootPath(rootPathPrefix, id); try { byte[] content = zooKeeper.getData(path, false, new Stat()); final CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(content, CoordinatorRepositoryAdapter.class); adapter.setLastTime(DateUtils.getDateYYYY()); adapter.setRetriedCount(retry); zooKeeper.create(path, objectSerializer.serialize(adapter), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); return Boolean.TRUE; } catch (Exception e) { e.printStackTrace(); } return Boolean.FALSE; }
@Override public int updateParticipant(final HmilyTransaction hmilyTransaction) { final String path = RepositoryPathUtils.buildZookeeperRootPath(rootPathPrefix, hmilyTransaction.getTransId()); try { byte[] content = zooKeeper.getData(path, false, new Stat()); if (content != null) { final CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(content, CoordinatorRepositoryAdapter.class); adapter.setContents(objectSerializer.serialize(hmilyTransaction.getHmilyParticipants())); zooKeeper.setData(path, objectSerializer.serialize(adapter), -1); } return ROWS; } catch (Exception e) { e.printStackTrace(); return FAIL_ROWS; } }