Search in sources :

Example 76 with ExponentialBackoffRetry

use of 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();
    }
}
Also used : Configuration(com.moilioncircle.redis.replicator.Configuration) RocketMQRedisProducer(org.apache.rocketmq.redis.replicator.mq.RocketMQRedisProducer) RdbVisitor(com.moilioncircle.redis.replicator.rdb.RdbVisitor) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) RedisReplicator(com.moilioncircle.redis.replicator.RedisReplicator) DEPLOY_MODEL_SINGLE(org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.DEPLOY_MODEL_SINGLE) LeaderSelector(org.apache.curator.framework.recipes.leader.LeaderSelector) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) REDIS_URI(org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.REDIS_URI) EventListener(com.moilioncircle.redis.replicator.event.EventListener) AbstractReplicator(com.moilioncircle.redis.replicator.AbstractReplicator) Logger(org.slf4j.Logger) Module(com.moilioncircle.redis.replicator.rdb.datatype.Module) IOException(java.io.IOException) ROOT_DIR(org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.ROOT_DIR) Command(com.moilioncircle.redis.replicator.cmd.Command) Configure(org.apache.rocketmq.redis.replicator.conf.Configure) CloseListener(com.moilioncircle.redis.replicator.CloseListener) Objects(java.util.Objects) DEPLOY_MODEL(org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.DEPLOY_MODEL) CuratorFramework(org.apache.curator.framework.CuratorFramework) CONFIG_PROP_ZK_ADDRESS(org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.CONFIG_PROP_ZK_ADDRESS) RedisSocketReplicator(com.moilioncircle.redis.replicator.RedisSocketReplicator) Replicator(com.moilioncircle.redis.replicator.Replicator) ModuleParser(com.moilioncircle.redis.replicator.rdb.module.ModuleParser) CommandName(com.moilioncircle.redis.replicator.cmd.CommandName) CommandParser(com.moilioncircle.redis.replicator.cmd.CommandParser) RedisURI(com.moilioncircle.redis.replicator.RedisURI) LeaderSelectorListenerAdapter(org.apache.curator.framework.recipes.leader.LeaderSelectorListenerAdapter) CuratorFrameworkFactory.newClient(org.apache.curator.framework.CuratorFrameworkFactory.newClient) ExceptionListener(com.moilioncircle.redis.replicator.ExceptionListener) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) LeaderSelector(org.apache.curator.framework.recipes.leader.LeaderSelector) LeaderSelectorListenerAdapter(org.apache.curator.framework.recipes.leader.LeaderSelectorListenerAdapter) RedisSocketReplicator(com.moilioncircle.redis.replicator.RedisSocketReplicator) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 77 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project pravega by pravega.

the class StoreClientFactory method createZKClient.

@VisibleForTesting
static CuratorFramework createZKClient(ZKClientConfig zkClientConfig, Supplier<Boolean> canRetry, Consumer<Void> expiryHandler, ZKClientFactory zkClientFactory) {
    if (zkClientConfig.isSecureConnectionToZooKeeper()) {
        ZKTLSUtils.setSecureZKClientProperties(zkClientConfig.getTrustStorePath(), JKSHelper.loadPasswordFrom(zkClientConfig.getTrustStorePasswordPath()));
    }
    RetryWrapper retryPolicy = new RetryWrapper(new ExponentialBackoffRetry(zkClientConfig.getInitialSleepInterval(), zkClientConfig.getMaxRetries(), CURATOR_MAX_SLEEP_MS), canRetry);
    // Create and initialize the curator client framework.
    CuratorFramework zkClient = CuratorFrameworkFactory.builder().connectString(zkClientConfig.getConnectionString()).namespace(zkClientConfig.getNamespace()).zookeeperFactory(zkClientFactory).retryPolicy(retryPolicy).sessionTimeoutMs(zkClientConfig.getSessionTimeoutMs()).build();
    zkClient.getConnectionStateListenable().addListener((client1, newState) -> {
        if (newState.equals(ConnectionState.LOST)) {
            expiryHandler.accept(null);
        }
    });
    zkClient.start();
    return zkClient;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 78 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project pravega by pravega.

the class ControllerServiceWithStreamTest method setup.

@Before
public void setup() {
    try {
        zkServer = new TestingServerStarter().start();
    } catch (Exception e) {
        log.error("Error starting ZK server", e);
    }
    zkClient = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), new ExponentialBackoffRetry(200, 10, 5000));
    zkClient.start();
    streamStore = spy(getStore());
    kvtStore = spy(getKVTStore());
    BucketStore bucketStore = StreamStoreFactory.createZKBucketStore(zkClient, executor);
    TaskMetadataStore taskMetadataStore = TaskStoreFactory.createZKStore(zkClient, executor);
    connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(URI.create("tcp://localhost")).build());
    GrpcAuthHelper disabledAuthHelper = GrpcAuthHelper.getDisabledAuthHelper();
    SegmentHelper segmentHelperMock = SegmentHelperMock.getSegmentHelperMock();
    StreamMetrics.initialize();
    TransactionMetrics.initialize();
    EventHelper helperMock = EventHelperMock.getEventHelperMock(executor, "host", ((AbstractStreamMetadataStore) streamStore).getHostTaskIndex());
    streamMetadataTasks = new StreamMetadataTasks(streamStore, bucketStore, taskMetadataStore, segmentHelperMock, executor, "host", disabledAuthHelper, helperMock);
    kvtMetadataTasks = spy(new TableMetadataTasks(kvtStore, segmentHelperMock, executor, executor, "host", GrpcAuthHelper.getDisabledAuthHelper(), helperMock));
    streamTransactionMetadataTasks = new StreamTransactionMetadataTasks(streamStore, segmentHelperMock, executor, "host", disabledAuthHelper);
    StreamRequestHandler streamRequestHandler = new StreamRequestHandler(new AutoScaleTask(streamMetadataTasks, streamStore, executor), new ScaleOperationTask(streamMetadataTasks, streamStore, executor), new UpdateStreamTask(streamMetadataTasks, streamStore, bucketStore, executor), new SealStreamTask(streamMetadataTasks, streamTransactionMetadataTasks, streamStore, executor), new DeleteStreamTask(streamMetadataTasks, streamStore, bucketStore, executor), new TruncateStreamTask(streamMetadataTasks, streamStore, executor), new CreateReaderGroupTask(streamMetadataTasks, streamStore, executor), new DeleteReaderGroupTask(streamMetadataTasks, streamStore, executor), new UpdateReaderGroupTask(streamMetadataTasks, streamStore, executor), streamStore, new DeleteScopeTask(streamMetadataTasks, streamStore, kvtStore, kvtMetadataTasks, executor), executor);
    streamMetadataTasks.setRequestEventWriter(new ControllerEventStreamWriterMock(streamRequestHandler, executor));
    consumer = new ControllerService(kvtStore, kvtMetadataTasks, streamStore, bucketStore, streamMetadataTasks, streamTransactionMetadataTasks, segmentHelperMock, executor, null, requestTracker);
}
Also used : DeleteScopeTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteScopeTask) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CreateReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.CreateReaderGroupTask) AutoScaleTask(io.pravega.controller.server.eventProcessor.requesthandlers.AutoScaleTask) ControllerEventStreamWriterMock(io.pravega.controller.mocks.ControllerEventStreamWriterMock) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) TableMetadataTasks(io.pravega.controller.task.KeyValueTable.TableMetadataTasks) BucketStore(io.pravega.controller.store.stream.BucketStore) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) SealStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask) TestingServerStarter(io.pravega.test.common.TestingServerStarter) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) DeleteReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteReaderGroupTask) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) ScaleOperationTask(io.pravega.controller.server.eventProcessor.requesthandlers.ScaleOperationTask) ExecutionException(java.util.concurrent.ExecutionException) StreamRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.StreamRequestHandler) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) DeleteStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteStreamTask) UpdateReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateReaderGroupTask) EventHelper(io.pravega.controller.task.EventHelper) TruncateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.TruncateStreamTask) Before(org.junit.Before)

Example 79 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project metron by apache.

the class MaasIntegrationTest method setupBeforeClass.

@BeforeAll
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)

Example 80 with ExponentialBackoffRetry

use of 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();
        }
    }
}
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)

Aggregations

ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)181 CuratorFramework (org.apache.curator.framework.CuratorFramework)107 RetryPolicy (org.apache.curator.RetryPolicy)46 Before (org.junit.Before)26 TestingCluster (org.apache.curator.test.TestingCluster)23 Test (org.testng.annotations.Test)23 IOException (java.io.IOException)18 TestingServer (org.apache.curator.test.TestingServer)18 Timing (org.apache.curator.test.Timing)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)12 ACLProvider (org.apache.curator.framework.api.ACLProvider)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 ConnectionState (org.apache.curator.framework.state.ConnectionState)11 ExecutorService (java.util.concurrent.ExecutorService)10 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)10 TestingServerStarter (io.pravega.test.common.TestingServerStarter)9 KeeperException (org.apache.zookeeper.KeeperException)8 HashMap (java.util.HashMap)7