public void create(String path, byte[] data, List<ACL> acl, CreateMode mode) throws Exception { transactionFinal = transactionFinal.create() .withMode(mode).withACL(acl).forPath(path, data).and(); }
SafeTransaction(List<ACL> fencingACL, String fencingNodePath) throws Exception { this.fencingNodePath = fencingNodePath; CuratorTransaction transaction = curator.inTransaction(); transactionFinal = transaction.create() .withMode(CreateMode.PERSISTENT).withACL(fencingACL) .forPath(fencingNodePath, new byte[0]).and(); }
@Override public ACLPathAndBytesable<CuratorTransactionBridge> withMode(CreateMode mode) { return new ACLPathAndBytesableDecorator<>(inner.withMode(mode)); }
public void addFinishedApplication(String appId, String queue, String yarnState, String yarnStatus, String user, String name) { String path = zkRoot + "/jobs/" + appId; try { if (curator.checkExists().forPath(path) != null) { curator.delete().deletingChildrenIfNeeded().forPath(path); } name = name.replace("/", "_"); if (name.length() > 50) { name = name.substring(0, 50); } CuratorTransactionBridge result = curator.inTransaction().create().withMode(CreateMode.PERSISTENT).forPath(path, ZKStateConstant.AppStatus.INIT.toString().getBytes("UTF-8")); result = result.and().create().withMode(CreateMode.PERSISTENT).forPath(path + "/info", String.format("%s/%s/%s/%s/%s", queue, yarnState, yarnStatus, user, name).getBytes("UTF-8")); result.and().commit(); } catch (Exception e) { LOG.error("fail adding finished application", e); throw new RuntimeException(e); } }
@Timed public QueuedRequestId enqueueRequest(BaragonRequest request, InternalRequestStates state) throws NodeExistsException { final long start = System.currentTimeMillis(); final String queuedRequestPath = String.format(REQUEST_ENQUEUE_FORMAT, request.getLoadBalancerService().getServiceId(), request.getLoadBalancerRequestId()); final String requestPath = String.format(REQUEST_FORMAT, request.getLoadBalancerRequestId()); final String requestStatePath = String.format(REQUEST_STATE_FORMAT, request.getLoadBalancerRequestId()); try { if (!nodeExists(REQUESTS_FORMAT)) { createNode(REQUESTS_FORMAT); } if (!nodeExists(REQUEST_QUEUE_FORMAT)) { createNode(REQUEST_QUEUE_FORMAT); } byte[] requestBytes = objectMapper.writeValueAsBytes(request); byte[] stateBytes = objectMapper.writeValueAsBytes(state); Collection<CuratorTransactionResult> results = curatorFramework.inTransaction() .create().forPath(requestPath, requestBytes).and() .create().forPath(requestStatePath, stateBytes).and() .create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(queuedRequestPath) .and().commit(); log(OperationType.WRITE, Optional.of(3), Optional.of(requestBytes.length + stateBytes.length), start, String.format("Transaction Paths [%s + %s + %s]", requestPath, requestStatePath, queuedRequestPath)); return QueuedRequestId.fromString(ZKPaths.getNodeFromPath(Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(org.apache.curator.framework.api.transaction.OperationType.CREATE, queuedRequestPath)) .getResultPath())); } catch (NodeExistsException nee) { throw nee; } catch (Exception e) { throw new RuntimeException(e); } }
.delete().forPath(itemPath) .and() .create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(makeRequeueItemPath(itemPath), bytes) .and() .commit();