use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project knox by apache.
the class RemoteConfigurationRegistryClientServiceTest method testZooKeeperWithSimpleRegistryConfig.
/**
* Test a configuration for a secure remote registry, included in the gateway configuration.
*/
@Test
public void testZooKeeperWithSimpleRegistryConfig() throws Exception {
final String AUTH_TYPE = "digest";
final String REGISTRY_CLIENT_NAME = "zk-registry-name";
final String PRINCIPAL = "knox";
final String PWD = "knoxtest";
final String CRED_ALIAS = "zkCredential";
// Configure and start a secure ZK cluster
TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD);
try {
// Create the setup client for the test cluster, and initialize the test znodes
CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
// Mock configuration
GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
final String registryConfigValue = GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString() + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE + "=" + AUTH_TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL + "=" + PRINCIPAL + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS + "=" + CRED_ALIAS;
EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME)).andReturn(registryConfigValue).anyTimes();
EasyMock.expect(config.getRemoteRegistryConfigurationNames()).andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes();
EasyMock.replay(config);
doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config, CRED_ALIAS, PWD);
} finally {
zkCluster.stop();
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project twister2 by DSC-SPIDAL.
the class ZKUtil method connectToServer.
/**
* connect to ZooKeeper server
* @param config
* @return
*/
public static CuratorFramework connectToServer(Config config) {
String zkServerAddress = ZKContext.zooKeeperServerIP(config);
String zkServerPort = ZKContext.zooKeeperServerPort(config);
String zkServer = zkServerAddress + ":" + zkServerPort;
try {
CuratorFramework client = CuratorFrameworkFactory.newClient(zkServer, new ExponentialBackoffRetry(1000, 3));
client.start();
LOG.log(Level.INFO, "Connected to ZooKeeper server: " + zkServer);
return client;
} catch (Exception e) {
LOG.log(Level.SEVERE, "Could not connect to ZooKeeper server" + zkServer, e);
throw new RuntimeException(e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.
the class FabricDiscoveryAgent method call.
@Override
public Object call() throws Exception {
LOG.info("Using local ZKClient");
managedZkClient = true;
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(System.getProperty("zookeeper.url", "localhost:2181")).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(10000);
String password = System.getProperty("zookeeper.password", "admin");
if (password != null && !password.isEmpty()) {
builder.aclProvider(new CuratorACLManager());
builder.authorization("digest", ("fabric:" + password).getBytes());
}
CuratorFramework client = builder.build();
client.start();
client.getZookeeperClient().blockUntilConnectedOrTimedOut();
return client;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.
the class FabricDiscoveryServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
CuratorFramework curator = this.curator;
if (curator == null) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Not attached to Fabric");
return;
}
try {
String groupName = req.getPathInfo();
if (groupName == null) {
groupName = "";
}
if (groupName.startsWith("/")) {
int start = 0;
while (groupName.charAt(start) == '/') {
start++;
}
int end = groupName.length();
while (groupName.charAt(end - 1) == '/') {
end--;
}
groupName = groupName.substring(start, end);
}
LOG.debug("discovery request for group name={}", groupName);
// To avoid hammering ZooKeeper if we get to many HTTP requests back to back,
// lets cache results.
CacheEntry cacheEntry = cache.get(groupName);
long now = System.currentTimeMillis();
if (cacheEntry == null || cacheEntry.timestamp + cacheTimeout < now) {
try {
Map<String, ActiveMQNode> members = ZooKeeperGroup.members(MAPPER, curator, "/fabric/registry/clusters/amq/" + groupName, ActiveMQNode.class);
HashSet<String> masters = new HashSet<String>();
StringBuilder buff = new StringBuilder();
for (ActiveMQNode node : members.values()) {
if (!masters.contains(node.getId())) {
for (int i = 0; i < node.services.length; i++) {
String url = node.services[i];
url = ZooKeeperUtils.getSubstitutedData(curator, url);
buff.append(url);
buff.append('\n');
}
masters.add(node.getId());
}
}
cacheEntry = new CacheEntry(buff.toString(), now);
} catch (Exception e) {
cacheEntry = new CacheEntry(null, now);
}
cache.put(groupName, cacheEntry);
}
if (cacheEntry.result != null) {
resp.getWriter().print(cacheEntry.result.toString());
} else {
resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Group not found");
}
} catch (Exception e) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred: " + e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project coprhd-controller by CoprHD.
the class CoordinatorClientImpl method start.
@Override
public void start() throws IOException {
if (_zkConnection.curator().isStarted()) {
return;
}
_zkConnection.curator().getConnectionStateListenable().addListener(new org.apache.curator.framework.state.ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework client, final ConnectionState newState) {
log.info("Entering stateChanged method : {}", newState);
_connectionStateWorker.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
Iterator<ConnectionStateListener> it = _listener.iterator();
while (it.hasNext()) {
ConnectionStateListener listener = it.next();
try {
switch(newState) {
case RECONNECTED:
case CONNECTED:
{
listener.connectionStateChanged(ConnectionStateListener.State.CONNECTED);
break;
}
case LOST:
case SUSPENDED:
{
listener.connectionStateChanged(ConnectionStateListener.State.DISCONNECTED);
break;
}
}
} catch (Exception e) {
log.warn("Connection listener threw", e);
}
}
return null;
}
});
}
});
_zkConnection.connect();
// writing local node to zk
initInetAddressEntry();
try {
checkAndCreateSiteSpecificSection();
String servicePath = getServicePath();
EnsurePath path = new EnsurePath(servicePath);
path.ensure(_zkConnection.curator().getZookeeperClient());
} catch (Exception e) {
// desired
if ((_connectionStateWorker != null) && (!_connectionStateWorker.isShutdown())) {
_connectionStateWorker.shutdownNow();
}
if (nodeChangeWorker != null && !nodeChangeWorker.isShutdown()) {
nodeChangeWorker.shutdownNow();
}
throw CoordinatorException.fatals.errorConnectingCoordinatorService(e);
}
}
Aggregations