Search in sources :

Example 6 with RetryPolicy

use of org.apache.curator.RetryPolicy 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();
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) MaaSConfig(org.apache.metron.maas.config.MaaSConfig) RetryPolicy(org.apache.curator.RetryPolicy) ServiceDiscoverer(org.apache.metron.maas.discovery.ServiceDiscoverer) Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 7 with RetryPolicy

use of org.apache.curator.RetryPolicy 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();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CuratorFramework(org.apache.curator.framework.CuratorFramework) List(java.util.List) RetryPolicy(org.apache.curator.RetryPolicy) ServiceDiscoverer(org.apache.metron.maas.discovery.ServiceDiscoverer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractMap(java.util.AbstractMap) File(java.io.File)

Example 8 with RetryPolicy

use of org.apache.curator.RetryPolicy in project metron by apache.

the class MaasIntegrationTest method setupBeforeClass.

@BeforeClass
public static void setupBeforeClass() throws Exception {
    UnitTestHelper.setJavaLoggingLevel(Level.SEVERE);
    LOG.info("Starting up YARN cluster");
    zkServerComponent = new ZKServerComponent();
    yarnComponent = new YarnComponent().withApplicationMasterClass(ApplicationMaster.class).withTestName(MaasIntegrationTest.class.getSimpleName());
    runner = new ComponentRunner.Builder().withComponent("yarn", yarnComponent).withComponent("zk", zkServerComponent).withMillisecondsBetweenAttempts(15000).withNumRetries(10).build();
    runner.start();
    String zookeeperUrl = zkServerComponent.getConnectionString();
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy);
    client.start();
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ZKServerComponent(org.apache.metron.integration.components.ZKServerComponent) YarnComponent(org.apache.metron.integration.components.YarnComponent) RetryPolicy(org.apache.curator.RetryPolicy) BeforeClass(org.junit.BeforeClass)

Example 9 with RetryPolicy

use of org.apache.curator.RetryPolicy 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);
    @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();
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy) Cleanup(lombok.Cleanup) IOException(java.io.IOException)

Example 10 with RetryPolicy

use of org.apache.curator.RetryPolicy in project flink by apache.

the class KafkaTestEnvironmentImpl method createCuratorClient.

/**
	 * Only for the 0.8 server we need access to the zk client.
	 */
public CuratorFramework createCuratorClient() {
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(100, 10);
    CuratorFramework curatorClient = CuratorFrameworkFactory.newClient(standardProps.getProperty("zookeeper.connect"), retryPolicy);
    curatorClient.start();
    return curatorClient;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy)

Aggregations

RetryPolicy (org.apache.curator.RetryPolicy)26 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)21 CuratorFramework (org.apache.curator.framework.CuratorFramework)12 IOException (java.io.IOException)6 ACLProvider (org.apache.curator.framework.api.ACLProvider)5 DefaultZooKeeperClient (com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient)4 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)4 TestingServer (org.apache.curator.test.TestingServer)4 Before (org.junit.Before)4 AuthInfo (org.apache.curator.framework.AuthInfo)3 MaaSConfig (org.apache.metron.maas.config.MaaSConfig)3 ServiceDiscoverer (org.apache.metron.maas.discovery.ServiceDiscoverer)3 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)2 CuratorClientFactoryImpl (com.spotify.helios.servicescommon.coordination.CuratorClientFactoryImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 RetryNTimes (org.apache.curator.retry.RetryNTimes)2