org.I0Itec.zkclient.exception.ZkNodeExistsException Java Examples

The following examples show how to use org.I0Itec.zkclient.exception.ZkNodeExistsException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaskStatusServiceImpl.java    From DataLink with Apache License 2.0 6 votes vote down vote up
@Override
public void addStatus(TaskStatus status) throws TaskConflictException {
    DLinkZkUtils zkUtils = DLinkZkUtils.get();
    String statusPath = DLinkZkPathDef.getTaskStatusNode(status.getId());

    byte[] bytes = JSON.toJSONBytes(status);
    try {
        zkUtils.zkClient().createPersistent(DLinkZkPathDef.getTaskNode(status.getId()), true);
        zkUtils.zkClient().create(statusPath, bytes, CreateMode.EPHEMERAL);
    } catch (ZkNodeExistsException e) {
        byte[] data = zkUtils.zkClient().readData(statusPath, true);
        if (data != null) {
            TaskStatus otherTaskStatus = JSON.parseObject(data, TaskStatus.class);
            throw new TaskConflictException(status.getId(), status.getWorkerId(), otherTaskStatus.getWorkerId(),
                    status.getExecutionId(), otherTaskStatus.getExecutionId());
        } else {
            addStatus(status);
        }
    }
}
 
Example #2
Source File: ZkTopicStore.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
private void createStrimziTopicsPath() {
    zk.create("/strimzi", null, acl, CreateMode.PERSISTENT, result -> {
        if (result.failed()) {
            if (!(result.cause() instanceof ZkNodeExistsException)) {
                LOGGER.error("Error creating {}", "/strimzi", result.cause());
                throw new RuntimeException(result.cause());
            }
        }
        zk.create(topicsPath, null, acl, CreateMode.PERSISTENT, result2 -> {
            if (result2.failed()) {
                if (!(result2.cause() instanceof ZkNodeExistsException)) {
                    LOGGER.error("Error creating {}", topicsPath, result2.cause());
                    throw new RuntimeException(result2.cause());
                }
            }
        });
    });
}
 
Example #3
Source File: ZkclientZookeeperClient.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public void createEphemeral(String path) {
    try {
        client.createEphemeral(path);
    } catch (ZkNodeExistsException e) {
    }
}
 
Example #4
Source File: ZkClientZkClient.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
protected String createEphemeral(String path, Object data, boolean sequential) {
    try {
        if (sequential) {
            return zkClient.createEphemeralSequential(path, data);
        } else {
            zkClient.createEphemeral(path, data);
            return path;
        }
    } catch (ZkNodeExistsException ignored) {
    }
    return null;
}
 
Example #5
Source File: ZkClientZkClient.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
protected String createEphemeral(String path, boolean sequential) {
    try {
        if (sequential) {
            return zkClient.createEphemeralSequential(path, true);
        } else {
            zkClient.createEphemeral(path);
            return path;
        }
    } catch (ZkNodeExistsException ignored) {
    }
    return null;
}
 
Example #6
Source File: ZkClientZkClient.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
protected String createPersistent(String path, Object data, boolean sequential) {
    try {
        if (sequential) {
            return zkClient.createPersistentSequential(path, data);
        } else {
            zkClient.createPersistent(path, data);
            return path;
        }
    } catch (ZkNodeExistsException ignored) {
    }
    return null;
}
 
Example #7
Source File: ZkClientZkClient.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
protected String createPersistent(String path, boolean sequential) {
    try {
        if (sequential) {
            return zkClient.createPersistentSequential(path, true);
        } else {
            zkClient.createPersistent(path, true);
            return path;
        }
    } catch (ZkNodeExistsException ignored) {
    }
    return null;
}
 
Example #8
Source File: ZkClient.java    From brooklin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Ensure that all the paths in the given full path String are created
 * @param path the zk path
 */
public void ensurePath(String path) {
  if (path == null) {
    return;
  }

  // if the path exists, return
  if (this.exists(path)) {
    return;
  }

  // paths to create in the stack
  Stack<String> pstack = new Stack<>();

  // push paths in stack because we need to create from parent to children
  while (!exists(path)) {
    pstack.push(path);
    path = path.substring(0, path.lastIndexOf(ZK_PATH_SEPARATOR));
    if (path.isEmpty()) {
      path = ZK_PATH_SEPARATOR;
    }
  }

  while (!pstack.empty()) {
    String p = pstack.pop();

    // double check the existence of the path to avoid herd effect
    if (exists(p)) {
      continue;
    }

    LOG.info("creating path in zookeeper: {}", p);
    try {
      this.createPersistent(p);
    } catch (ZkNodeExistsException e) {
      LOG.info(e.getMessage());
    }
  }
}
 
Example #9
Source File: ZkTopicStore.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public Future<Void> create(Topic topic) {
    Promise<Void> handler = Promise.promise();
    byte[] data = TopicSerialization.toJson(topic);
    String topicPath = getTopicPath(topic.getTopicName());
    LOGGER.debug("create znode {}", topicPath);
    zk.create(topicPath, data, acl, CreateMode.PERSISTENT, result -> {
        if (result.failed() && result.cause() instanceof ZkNodeExistsException) {
            handler.handle(Future.failedFuture(new EntityExistsException()));
        } else {
            handler.handle(result);
        }
    });
    return handler.future();
}
 
Example #10
Source File: AutoTopicWhitelistingManager.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
private void maybeCreateZkPath(String path) {
  try {
    _zkClient.createPersistent(path, true);
  } catch (ZkNodeExistsException e) {
    LOGGER.debug("Path={} is created in zk already", path);
  }
}
 
Example #11
Source File: BrokerFailureDetector.java    From cruise-control with BSD 2-Clause "Simplified" License 5 votes vote down vote up
void startDetection() {
  try {
    _zkClient.createPersistent(_failedBrokersZkPath);
  } catch (ZkNodeExistsException znee) {
    // let it go.
  }
  // Load the failed broker information from zookeeper.
  loadPersistedFailedBrokerList();
  // Detect broker failures.
  detectBrokerFailures(false);
  _zkClient.subscribeChildChanges(BrokerIdsZNode.path(), new BrokerFailureListener());
}
 
Example #12
Source File: ZkclientZookeeperClient.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public void createPersistent(String path) {
    try {
        client.createPersistent(path);
    } catch (ZkNodeExistsException e) {
    }
}
 
Example #13
Source File: ZkclientZookeeperClient.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public void createEphemeral(String path) {
	try {
		client.createEphemeral(path);
	} catch (ZkNodeExistsException e) {
	}
}
 
Example #14
Source File: ZkclientZookeeperClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void createPersistent(String path) {
	try {
		client.createPersistent(path, true);
	} catch (ZkNodeExistsException e) {
	}
}
 
Example #15
Source File: ZkclientZookeeperClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void createEphemeral(String path) {
	try {
		client.createEphemeral(path);
	} catch (ZkNodeExistsException e) {
	}
}
 
Example #16
Source File: ZkclientZookeeperClient.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public void createPersistent(String path) {
	try {
		client.createPersistent(path, true);
	} catch (ZkNodeExistsException e) {
	}
}
 
Example #17
Source File: ZkclientZookeeperClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void createEphemeral(String path) {
	try {
		client.createEphemeral(path);
	} catch (ZkNodeExistsException e) {
	}
}
 
Example #18
Source File: ZkclientZookeeperClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void createPersistent(String path) {
	try {
		client.createPersistent(path, true);
	} catch (ZkNodeExistsException e) {
	}
}
 
Example #19
Source File: ZkclientZookeeperClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void createPersistent(String path) {
	try {
		client.createPersistent(path, true);
	} catch (ZkNodeExistsException e) {
	}
}
 
Example #20
Source File: ZkclientZookeeperClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void createEphemeral(String path) {
	try {
		client.createEphemeral(path);
	} catch (ZkNodeExistsException e) {
	}
}
 
Example #21
Source File: ZkclientZookeeperClient.java    From JobX with Apache License 2.0 4 votes vote down vote up
public void createEphemeral(String path) {
    try {
        client.createEphemeral(path);
    } catch (ZkNodeExistsException e) {
    }
}
 
Example #22
Source File: ZkclientZookeeperClient.java    From JobX with Apache License 2.0 4 votes vote down vote up
public void createPersistent(String path) {
    try {
        client.createPersistent(path, true);
    } catch (ZkNodeExistsException e) {
    }
}