use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project metron by apache.
the class ModelSubmission method execute.
public void execute(FileSystem fs, String... argv) throws Exception {
CommandLine cli = ModelSubmissionOptions.parse(new PosixParser(), argv);
if (ModelSubmissionOptions.LOG4J_PROPERTIES.has(cli)) {
Log4jPropertyHelper.updateLog4jConfiguration(ModelSubmission.class, ModelSubmissionOptions.LOG4J_PROPERTIES.get(cli));
}
ModelRequest request = null;
CuratorFramework client = null;
try {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
client = CuratorFrameworkFactory.newClient(ModelSubmissionOptions.ZK_QUORUM.get(cli), retryPolicy);
client.start();
MaaSConfig config = ConfigUtil.INSTANCE.read(client, ModelSubmissionOptions.ZK_ROOT.get(cli, "/metron/maas/config"), new MaaSConfig(), MaaSConfig.class);
String mode = ModelSubmissionOptions.MODE.get(cli);
if (mode.equalsIgnoreCase("ADD")) {
request = new ModelRequest() {
{
setName(ModelSubmissionOptions.NAME.get(cli));
setAction(Action.ADD);
setVersion(ModelSubmissionOptions.VERSION.get(cli));
setNumInstances(Integer.parseInt(ModelSubmissionOptions.NUM_INSTANCES.get(cli)));
setMemory(Integer.parseInt(ModelSubmissionOptions.MEMORY.get(cli)));
setPath(ModelSubmissionOptions.HDFS_MODEL_PATH.get(cli));
}
};
} else if (mode.equalsIgnoreCase("REMOVE")) {
request = new ModelRequest() {
{
setName(ModelSubmissionOptions.NAME.get(cli));
setAction(Action.REMOVE);
setNumInstances(Integer.parseInt(ModelSubmissionOptions.NUM_INSTANCES.get(cli)));
setVersion(ModelSubmissionOptions.VERSION.get(cli));
}
};
} else if (mode.equalsIgnoreCase("LIST")) {
String name = ModelSubmissionOptions.NAME.get(cli, null);
String version = ModelSubmissionOptions.VERSION.get(cli, null);
ServiceDiscoverer serviceDiscoverer = new ServiceDiscoverer(client, config.getServiceRoot());
Model model = new Model(name, version);
Map<Model, List<ModelEndpoint>> endpoints = serviceDiscoverer.listEndpoints(model);
for (Map.Entry<Model, List<ModelEndpoint>> kv : endpoints.entrySet()) {
String modelTitle = "Model " + kv.getKey().getName() + " @ " + kv.getKey().getVersion();
System.out.println(modelTitle);
for (ModelEndpoint endpoint : kv.getValue()) {
System.out.println(endpoint);
}
}
}
if (ModelSubmissionOptions.LOCAL_MODEL_PATH.has(cli)) {
File localDir = new File(ModelSubmissionOptions.LOCAL_MODEL_PATH.get(cli));
Path hdfsPath = new Path(ModelSubmissionOptions.HDFS_MODEL_PATH.get(cli));
updateHDFS(fs, localDir, hdfsPath);
}
Queue<ModelRequest> queue = config.createQueue(ImmutableMap.of(ZKQueue.ZK_CLIENT, client));
queue.enqueue(request);
} finally {
if (client != null) {
client.close();
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project metron by apache.
the class MaaSHandler method start.
public void start() throws Exception {
if (client == null) {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
client = CuratorFrameworkFactory.newClient(zkQuorum, retryPolicy);
client.start();
}
config = ConfigUtil.INSTANCE.read(client, root, new MaaSConfig(), MaaSConfig.class);
cache = new NodeCache(client, root);
cache.getListenable().addListener(() -> {
byte[] data = cache.getCurrentData().getData();
Lock wLock = lock.writeLock();
wLock.lock();
try {
config = _mapper.readValue(data, MaaSConfig.class);
} finally {
wLock.unlock();
}
});
discoverer = new ServiceDiscoverer(client, config.getServiceRoot());
discoverer.start();
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project rocketmq-externals by apache.
the class RocketMQRedisReplicator method open.
@Override
public void open() throws IOException {
if (this.replicator instanceof RedisSocketReplicator) {
boolean single = configure.getString(DEPLOY_MODEL).equals(DEPLOY_MODEL_SINGLE);
if (single) {
this.replicator.open();
} else {
String address = configure.getString(CONFIG_PROP_ZK_ADDRESS);
final CuratorFramework client = newClient(address, new ExponentialBackoffRetry(1000, 3));
client.start();
String path = ROOT_DIR + "/" + uri.getHost() + "-" + uri.getPort();
final LeaderSelector selector = new LeaderSelector(client, path, new LeaderSelectorListenerAdapter() {
@Override
public void takeLeadership(final CuratorFramework client) throws Exception {
RocketMQRedisReplicator.this.addCloseListener(r -> client.close());
replicator.open();
}
});
selector.start();
}
} else {
this.replicator.open();
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project pravega by pravega.
the class InProcPravegaCluster method cleanUpZK.
private void cleanUpZK() {
String[] pathsTobeCleaned = { "/pravega", "/hostIndex", "/store", "/taskIndex" };
RetryPolicy rp = new ExponentialBackoffRetry(1000, 3);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(zkUrl).connectionTimeoutMs(5000).sessionTimeoutMs(5000).retryPolicy(rp);
if (secureZK) {
ZKTLSUtils.setSecureZKClientProperties(jksTrustFile, "1111_aaaa");
}
@Cleanup CuratorFramework zclient = builder.build();
zclient.start();
for (String path : pathsTobeCleaned) {
try {
zclient.delete().guaranteed().deletingChildrenIfNeeded().forPath(path);
} catch (Exception e) {
log.warn("Not able to delete path {} . Exception {}", path, e.getMessage());
}
}
zclient.close();
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project pravega by pravega.
the class ClusterZKTest method deregisterNode.
@Test(timeout = TEST_TIMEOUT)
public void deregisterNode() throws Exception {
LinkedBlockingQueue<String> nodeAddedQueue = new LinkedBlockingQueue<>();
LinkedBlockingQueue<String> nodeRemovedQueue = new LinkedBlockingQueue<>();
LinkedBlockingQueue<Exception> exceptionsQueue = new LinkedBlockingQueue<>();
@Cleanup CuratorFramework client2 = CuratorFrameworkFactory.builder().connectString(zkUrl).retryPolicy(new ExponentialBackoffRetry(RETRY_SLEEP_MS, MAX_RETRY)).namespace(CLUSTER_NAME_2).build();
@Cleanup Cluster clusterListener = new ClusterZKImpl(client2, ClusterType.HOST);
clusterListener.addListener((eventType, host) -> {
switch(eventType) {
case HOST_ADDED:
nodeAddedQueue.offer(host.getIpAddr());
break;
case HOST_REMOVED:
nodeRemovedQueue.offer(host.getIpAddr());
break;
case ERROR:
exceptionsQueue.offer(new RuntimeException("Encountered error"));
break;
default:
exceptionsQueue.offer(new RuntimeException("Unhandled case"));
break;
}
});
@Cleanup CuratorFramework client = CuratorFrameworkFactory.builder().connectString(zkUrl).retryPolicy(new ExponentialBackoffRetry(RETRY_SLEEP_MS, MAX_RETRY)).namespace(CLUSTER_NAME_2).build();
// Create Add a node to the cluster.
@Cleanup Cluster clusterZKInstance1 = new ClusterZKImpl(client, ClusterType.HOST);
clusterZKInstance1.registerHost(new Host(HOST_1, PORT, null));
assertEquals(HOST_1, nodeAddedQueue.poll(5, TimeUnit.SECONDS));
clusterZKInstance1.deregisterHost(new Host(HOST_1, PORT, null));
assertEquals(HOST_1, nodeRemovedQueue.poll(5, TimeUnit.SECONDS));
Exception exception = exceptionsQueue.poll();
if (exception != null) {
throw exception;
}
}
Aggregations