use of com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException in project pinpoint by naver.
the class ZookeeperClusterService method setUp.
@Override
public void setUp() {
logger.info("pinpoint-collector cluster setUp");
switch(this.serviceState.getCurrentState()) {
case NEW:
if (this.serviceState.changeStateInitializing()) {
logger.info("{} initialization started.", this.getClass().getSimpleName());
ClusterManagerWatcher watcher = new ClusterManagerWatcher();
this.client = new CuratorZookeeperClient(config.getClusterAddress(), config.getClusterSessionTimeout(), watcher);
try {
this.client.connect();
} catch (PinpointZookeeperException e) {
throw new RuntimeException("ZookeeperClient connect failed", e);
}
final String connectedAgentZNodePath = ZKPaths.makePath(config.getCollectorZNodePath(), serverIdentifier);
this.profilerClusterManager = new ZookeeperProfilerClusterManager(client, connectedAgentZNodePath, clusterPointRouter.getTargetClusterPointRepository());
this.profilerClusterManager.start();
this.webClusterManager = new ZookeeperClusterManager(client, webZNodePath, clusterConnectionManager);
this.webClusterManager.start();
this.serviceState.changeStateStarted();
logger.info("{} initialization completed.", this.getClass().getSimpleName());
if (client.isConnected()) {
watcher.handleConnected();
}
}
break;
case INITIALIZING:
logger.info("{} already initializing.", this.getClass().getSimpleName());
break;
case STARTED:
logger.info("{} already started.", this.getClass().getSimpleName());
break;
case DESTROYING:
throw new IllegalStateException("Already destroying.");
case STOPPED:
throw new IllegalStateException("Already stopped.");
case ILLEGAL_STATE:
throw new IllegalStateException("Invalid State.");
}
}
use of com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException in project pinpoint by naver.
the class CuratorZookeeperClient method createPath.
@Override
public void createPath(String value) throws PinpointZookeeperException {
checkState();
String path = getPath(value, false);
logger.debug("createPath() started. value:{}, path:{}", value, path);
CuratorFramework curator = connectionManager.getCuratorFramework();
Stat stat = null;
try {
stat = curator.checkExists().forPath(path);
} catch (Exception e) {
ZookeeperExceptionResolver.resolveAndThrow(e);
}
if (stat == null) {
try {
curator.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path);
} catch (KeeperException.NodeExistsException nodeExists) {
// skip
} catch (Exception e) {
ZookeeperExceptionResolver.resolveAndThrow(e);
}
}
}
use of com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException in project pinpoint by naver.
the class CuratorZookeeperClient method createNode0.
private void createNode0(CreateNodeMessage message, boolean orSet) throws PinpointZookeeperException {
checkState();
try {
CuratorFramework curator = connectionManager.getCuratorFramework();
CreateBuilder createBuilder = curator.create();
if (message.isCreatingParentPathsIfNeeded()) {
createBuilder.creatingParentsIfNeeded();
}
if (orSet) {
createBuilder.orSetData();
}
String nodePath = message.getNodePath();
byte[] data = message.getData();
createBuilder.withMode(CreateMode.EPHEMERAL).forPath(nodePath, data);
} catch (Exception e) {
ZookeeperExceptionResolver.resolveAndThrow(e);
}
}
use of com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException in project pinpoint by naver.
the class CuratorZookeeperClient method checkState.
private void checkState() throws PinpointZookeeperException {
if (!isConnected()) {
notConnectedStatus.update();
if (reconnectCondition.check(notConnectedStatus)) {
notConnectedStatus.reset();
try {
final org.apache.curator.CuratorZookeeperClient zookeeperClient = connectionManager.getCuratorFramework().getZookeeperClient();
logger.warn("ConnectionState looks something wrong. It will be reset.");
zookeeperClient.reset();
return;
} catch (Exception e) {
logger.warn("Could not reset connection. cause:{}", e.getMessage(), e);
}
}
final ConnectionState connectionState = connectionManager.getConnectionState();
throw new ConnectionException("Instance must be connected. connectionState:" + connectionState);
} else {
notConnectedStatus.reset();
}
}
use of com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException in project pinpoint by naver.
the class CuratorZookeeperClient method getChildNodeList.
@Override
public List<String> getChildNodeList(String value, boolean watch) throws PinpointZookeeperException {
checkState();
String path = getPath(value, true);
logger.debug("getChildNodeList() started. path:{}, watch:{}", path, watch);
try {
CuratorFramework curator = connectionManager.getCuratorFramework();
final GetChildrenBuilder children = curator.getChildren();
if (watch) {
return children.usingWatcher(zookeeperEventWatcher).forPath(path);
} else {
return children.forPath(path);
}
} catch (KeeperException.NoNodeException noNode) {
// skip
} catch (Exception e) {
ZookeeperExceptionResolver.resolveAndThrow(e);
}
return Collections.emptyList();
}
Aggregations