/** * Performs basic validation of a path for a create request. * Throws if the path is not valid and returns the parent path. * @throws BadArgumentsException */ private String validatePathForCreate(String path, long sessionId) throws BadArgumentsException { int lastSlash = path.lastIndexOf('/'); if (lastSlash == -1 || path.indexOf('\0') != -1 || failCreate) { LOG.info("Invalid path %s with session 0x%s", path, Long.toHexString(sessionId)); throw new KeeperException.BadArgumentsException(path); } return path.substring(0, lastSlash); }
public void checkAddressDuplicate(QuorumServer s) throws BadArgumentsException { List<InetSocketAddress> otherAddrs = new ArrayList<InetSocketAddress>(); otherAddrs.add(s.addr); otherAddrs.add(s.clientAddr); otherAddrs.add(s.electionAddr); otherAddrs = excludedSpecialAddresses(otherAddrs); for (InetSocketAddress my: this.myAddrs) { for (InetSocketAddress other: otherAddrs) { if (my.equals(other)) { String error = String.format("%s of server.%d conflicts %s of server.%d", my, this.id, other, s.id); throw new BadArgumentsException(error); } } } }
private void validatePath(String path, long sessionId) throws BadArgumentsException { try { PathUtils.validatePath(path); } catch(IllegalArgumentException ie) { LOG.info("Invalid path {} with session 0x{}, reason: {}", path, Long.toHexString(sessionId), ie.getMessage()); throw new BadArgumentsException(path); } }
String path = existsRequest.getPath(); if (path.indexOf('\0') != -1) { throw new KeeperException.BadArgumentsException();
LOG.info("Invalid path " + path + " with session 0x" + Long.toHexString(request.sessionId)); throw new KeeperException.BadArgumentsException(path); LOG.info("Invalid path " + path + " with session 0x" + Long.toHexString(request.sessionId)); throw new KeeperException.BadArgumentsException(path); if (lastSlash == -1 || path.indexOf('\0') != -1 || zks.getZKDatabase().isSpecialPath(path)) { throw new KeeperException.BadArgumentsException(path);
return new OperationTimeoutException(); case BADARGUMENTS: return new BadArgumentsException(); case APIERROR: return new APIErrorException();
/** * Map an integer value to a CreateMode value */ static public CreateMode fromFlag(int flag) throws KeeperException { switch(flag) { case 0: return CreateMode.PERSISTENT; case 1: return CreateMode.EPHEMERAL; case 2: return CreateMode.PERSISTENT_SEQUENTIAL; case 3: return CreateMode.EPHEMERAL_SEQUENTIAL ; default: LOG.error("Received an invalid flag value to convert to a CreateMode"); throw new KeeperException.BadArgumentsException(); } } }
public synchronized void delete(String path, int expectedVersion) throws KeeperException { if (isRootPath(path)) { throw new KeeperException.BadArgumentsException(path); } String relativePath = stripRootFromPath(path); root.deleteDescendant(relativePath, expectedVersion); }
String path = existsRequest.getPath(); if (path.indexOf('\0') != -1) { throw new KeeperException.BadArgumentsException();
LOG.info("Invalid path " + path + " with session 0x" + Long.toHexString(request.sessionId)); throw new KeeperException.BadArgumentsException(path); if (lastSlash == -1 || path.indexOf('\0') != -1 || zks.getZKDatabase().isSpecialPath(path)) { throw new KeeperException.BadArgumentsException(path);
return new OperationTimeoutException(); case BADARGUMENTS: return new BadArgumentsException(); case APIERROR: return new APIErrorException();
request.qv.setVersion(request.getHdr().getZxid()); } catch (IOException | ConfigException e) { throw new KeeperException.BadArgumentsException(e.getMessage()); String msg = "Incremental reconfiguration requested but last configuration seen has a non-majority quorum system"; LOG.warn(msg); throw new KeeperException.BadArgumentsException(msg); throw new KeeperException.BadArgumentsException("Wrong format of server string"); QuorumServer qs = new QuorumServer(sid, parts[1]); if (qs.clientAddr == null || qs.electionAddr == null || qs.addr == null) { throw new KeeperException.BadArgumentsException("Wrong format of server string - each server should have 3 ports specified"); throw new KeeperException.BadArgumentsException("Reconfiguration failed"); String msg = "Reconfig failed - new configuration must include at least 2 followers"; LOG.warn(msg); throw new KeeperException.BadArgumentsException(msg); } else if (request.qv.getVotingMembers().size() < 1) { String msg = "Reconfig failed - new configuration must include at least 1 follower"; LOG.warn(msg); throw new KeeperException.BadArgumentsException(msg);
path = existsRequest.getPath(); if (path.indexOf('\0') != -1) { throw new KeeperException.BadArgumentsException();
return new ReconfigInProgress(); case BADARGUMENTS: return new BadArgumentsException(); case APIERROR: return new APIErrorException();
/** * Map an integer value to a CreateMode value */ static public CreateMode fromFlag(int flag) throws KeeperException { switch(flag) { case 0: return CreateMode.PERSISTENT; case 1: return CreateMode.EPHEMERAL; case 2: return CreateMode.PERSISTENT_SEQUENTIAL; case 3: return CreateMode.EPHEMERAL_SEQUENTIAL ; default: String errMsg = "Received an invalid flag value: " + flag + " to convert to a CreateMode"; LOG.error(errMsg); throw new KeeperException.BadArgumentsException(errMsg); } } }
private void validateCreateRequest(String path, CreateMode createMode, Request request, long ttl) throws KeeperException { if (createMode.isTTL() && !EphemeralType.extendedEphemeralTypesEnabled()) { throw new KeeperException.UnimplementedException(); } try { EphemeralType.validateTTL(createMode, ttl); } catch (IllegalArgumentException e) { throw new BadArgumentsException(path); } if (createMode.isEphemeral()) { // Exception is set when local session failed to upgrade // so we just need to report the error if (request.getException() != null) { throw request.getException(); } zks.sessionTracker.checkGlobalSession(request.sessionId, request.getOwner()); } else { zks.sessionTracker.checkSession(request.sessionId, request.getOwner()); } }
private void validatePath(String path, long sessionId) throws BadArgumentsException { try { PathUtils.validatePath(path); } catch(IllegalArgumentException ie) { LOG.info("Invalid path " + path + " with session 0x" + Long.toHexString(sessionId) + ", reason: " + ie.getMessage()); throw new BadArgumentsException(path); } }
/** * Map an integer value to a CreateMode value */ static public CreateMode fromFlag(int flag) throws KeeperException { switch(flag) { case 0: return CreateMode.PERSISTENT; case 1: return CreateMode.EPHEMERAL; case 2: return CreateMode.PERSISTENT_SEQUENTIAL; case 3: return CreateMode.EPHEMERAL_SEQUENTIAL ; case 4: return CreateMode.CONTAINER; case 5: return CreateMode.PERSISTENT_WITH_TTL; case 6: return CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL; default: String errMsg = "Received an invalid flag value: " + flag + " to convert to a CreateMode"; LOG.error(errMsg); throw new KeeperException.BadArgumentsException(errMsg); } }
private String getParentPathAndValidate(String path) throws BadArgumentsException { int lastSlash = path.lastIndexOf('/'); if (lastSlash == -1 || path.indexOf('\0') != -1 || zks.getZKDatabase().isSpecialPath(path)) { throw new BadArgumentsException(path); } return path.substring(0, lastSlash); }