Java Code Examples for com.google.common.net.HostAndPort#toString()

The following examples show how to use com.google.common.net.HostAndPort#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingularityLeaderLatch.java    From Singularity with Apache License 2.0 6 votes vote down vote up
@Inject
public SingularityLeaderLatch(
  CuratorFramework curatorFramework,
  Set<LeaderLatchListener> listeners,
  @Named(SingularityMainModule.HTTP_HOST_AND_PORT) HostAndPort httpHostAndPort
)
  throws Exception {
  super(
    checkNotNull(curatorFramework, "curatorFramework is null"),
    LEADER_PATH,
    httpHostAndPort.toString()
  );
  checkNotNull(listeners, "listeners is null");
  for (LeaderLatchListener listener : listeners) {
    addListener(listener);
  }
}
 
Example 2
Source File: PDClient.java    From tikv-client-lib-java with Apache License 2.0 6 votes vote down vote up
private boolean createLeaderWrapper(String leaderUrlStr) {
  try {
    URL tURL = new URL(leaderUrlStr);
    HostAndPort newLeader = HostAndPort.fromParts(tURL.getHost(), tURL.getPort());
    leaderUrlStr = newLeader.toString();
    if (leaderWrapper != null && leaderUrlStr.equals(leaderWrapper.getLeaderInfo())) {
      return true;
    }

    // create new Leader
    ManagedChannel clientChannel = session.getChannel(leaderUrlStr);
    leaderWrapper =
      new LeaderWrapper(
          leaderUrlStr,
          PDGrpc.newBlockingStub(clientChannel),
          PDGrpc.newStub(clientChannel),
          System.nanoTime());
  } catch (MalformedURLException e) {
    logger.error("Error updating leader.", e);
    return false;
  }
  logger.info(String.format("Switched to new leader: %s", leaderWrapper));
  return true;
}
 
Example 3
Source File: CompactionControlMonitorManager.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Inject
CompactionControlMonitorManager(LifeCycleRegistry lifeCycle,
                                @LocalCompactionControl CompactionControlSource compactionControlSource,
                                @GlobalFullConsistencyZooKeeper CuratorFramework curator,
                                @SelfHostAndPort HostAndPort self,
                                Clock clock,
                                LeaderServiceTask dropwizardTask,
                                final MetricRegistry metricRegistry) {
    LeaderService leaderService = new LeaderService(
            curator,
            "/leader/compaction-control-monitor",
            self.toString(),
            "Leader-CompactionControlMonitor",
            30, TimeUnit.MINUTES,
            () -> new CompactionControlMonitor(compactionControlSource, clock, metricRegistry)
    );

    ServiceFailureListener.listenTo(leaderService, metricRegistry);
    dropwizardTask.register("stash-runtime-monitor", leaderService);
    lifeCycle.manage(new ManagedGuavaService(leaderService));
}
 
Example 4
Source File: ScanUploadSchedulingService.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Inject
public ScanUploadSchedulingService(@ScannerZooKeeper CuratorFramework curator, @SelfHostAndPort HostAndPort selfHostAndPort,
                                   final ScanUploader scanUploader, final List<ScheduledDailyScanUpload> scheduledScans,
                                   final ScanCountListener scanCountListener, final StashRequestManager stashRequestManager,
                                   LifeCycleRegistry lifecycle, LeaderServiceTask leaderServiceTask,
                                   final MetricRegistry metricRegistry,
                                   final Clock clock) {
    super(curator, LEADER_DIR, selfHostAndPort.toString(), SERVICE_NAME, 1, TimeUnit.MINUTES,
            new Supplier<Service>() {
                @Override
                public Service get() {
                    return new DelegateSchedulingService(scanUploader, stashRequestManager, scheduledScans, scanCountListener, clock);
                }
            });

    ServiceFailureListener.listenTo(this, metricRegistry);
    leaderServiceTask.register(SERVICE_NAME, this);
    lifecycle.manage(new ManagedGuavaService(this));
}
 
Example 5
Source File: ScanUploadMonitor.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Inject
public ScanUploadMonitor(@ScannerZooKeeper CuratorFramework curator, @SelfHostAndPort HostAndPort selfHostAndPort,
                         final ScanWorkflow scanWorkflow, final ScanStatusDAO scanStatusDAO,
                         final ScanWriterGenerator scanWriterGenerator,
                         final StashStateListener stashStateListener, final ScanCountListener scanCountListener,
                         final DataTools dataTools, LifeCycleRegistry lifecycle, LeaderServiceTask leaderServiceTask,
                         MetricRegistry metricRegistry, @DelegateCompactionControl CompactionControlSource compactionControlSource, DataCenters dataCenters) {
    super(curator, LEADER_DIR, selfHostAndPort.toString(), SERVICE_NAME, 1, TimeUnit.MINUTES,
            new Supplier<Service>() {
                @Override
                public Service get() {
                    return new LocalScanUploadMonitor(scanWorkflow, scanStatusDAO,
                            scanWriterGenerator, stashStateListener, scanCountListener, dataTools, compactionControlSource, dataCenters);
                }
            });

    ServiceFailureListener.listenTo(this, metricRegistry);
    leaderServiceTask.register(SERVICE_NAME, this);
    lifecycle.manage(new ManagedGuavaService(this));
}
 
Example 6
Source File: TableEventProcessorManager.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Inject
public TableEventProcessorManager(LeaderServiceTask leaderServiceTask,
                                  @MegabusZookeeper CuratorFramework curator,
                                  @SelfHostAndPort HostAndPort selfHostAndPort,
                                  @TableEventRegistrationId String tableEventRegistrationId,
                                  TableEventRegistry tableEventRegistry,
                                  TableEventTools tableEventTools,
                                  KafkaCluster kafkaCluster,
                                  @MegabusRefTopic Topic refTopic,
                                  ObjectMapper objectMapper,
                                  MetricRegistry metricRegistry) {
    super(curator, LEADER_DIR, selfHostAndPort.toString(), SERVICE_NAME, 10, TimeUnit.MINUTES,
            () -> new TableEventProcessor(tableEventRegistrationId, tableEventRegistry, metricRegistry, tableEventTools,
                    kafkaCluster.producer(), objectMapper, refTopic));
    ServiceFailureListener.listenTo(this, metricRegistry);
    leaderServiceTask.register(SERVICE_NAME, this);
}
 
Example 7
Source File: MegabusRefSubscriptionMonitorManager.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Inject
MegabusRefSubscriptionMonitorManager(LifeCycleRegistry lifeCycle,
                                     final DatabusEventStore eventStore,
                                     @MegabusZookeeper CuratorFramework curator,
                                     @SelfHostAndPort HostAndPort self,
                                     LeaderServiceTask dropwizardTask,
                                     final MetricRegistry metricRegistry,
                                     @MegabusApplicationId String applicationId,
                                     @NumRefPartitions int numRefPartitions) {
    LeaderService leaderService = new LeaderService(
            curator, LEADER_DIR, self.toString(), "Leader-RefSubscriptionMonitor", 1, TimeUnit.MINUTES,
            () -> new MegabusRefSubscriptionMonitor(eventStore, metricRegistry, applicationId, numRefPartitions));
    ServiceFailureListener.listenTo(leaderService, metricRegistry);
    dropwizardTask.register("ref-subscription-monitor", leaderService);
    lifeCycle.manage(new ManagedGuavaService(leaderService));
}
 
Example 8
Source File: MegabusRefResolver.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Inject
public MegabusRefResolver(DataProvider dataProvider, Topic megabusRefTopic,
                          Topic megabusResolvedTopic,
                          Topic retryRefTopic,
                          Topic missingRefTopic,
                          KafkaCluster kafkaCluster, Clock clock,
                          HostAndPort hostAndPort,
                          String refResolverConsumerGroup,
                          MetricRegistry metricRegistry) {
    super(SERVICE_NAME, kafkaCluster, hostAndPort.toString(),
            refResolverConsumerGroup, megabusRefTopic.getPartitions(), metricRegistry);

    _dataProvider = requireNonNull(dataProvider, "dataProvider");
    _megabusRefTopic = requireNonNull(megabusRefTopic, "megabusRefTopic");
    _megabusResolvedTopic = requireNonNull(megabusResolvedTopic, "megabusResolvedTopic");
    _retryRefTopic = requireNonNull(retryRefTopic, "retryRefTopic");
    _missingRefTopic = requireNonNull(missingRefTopic, "missingRefTopic");

    _clock = requireNonNull(clock, "clock");

    _redundantMeter = metricRegistry.meter(getMetricName("redundantUpdates"));
    _discardedMeter = metricRegistry.meter(getMetricName("discardedUpdates"));
    _pendingMeter = metricRegistry.meter(getMetricName("pendingUpdates"));
    _errorProcessingMeter = metricRegistry.meter(getMetricName("errors"));
    _processingLatencyHisto = metricRegistry.histogram(getMetricName("processing-latency-ms"));
}
 
Example 9
Source File: MinSplitSizeCleanupMonitor.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Inject
public MinSplitSizeCleanupMonitor(@DataStoreZooKeeper CuratorFramework curator, @SelfHostAndPort HostAndPort selfHostAndPort,
                                  LeaderServiceTask leaderServiceTask, LifeCycleRegistry lifecycle,
                                  @MinSplitSizeMap MapStore<DataStoreMinSplitSize> minSplitSizeMap, Clock clock) {
    super(curator, LEADER_DIR, selfHostAndPort.toString(), SERVICE_NAME, 1, TimeUnit.MINUTES,
            () -> new MinSplitSizeCleanupService(minSplitSizeMap, clock));
    leaderServiceTask.register(SERVICE_NAME, this);
    lifecycle.manage(new ManagedGuavaService(this));
}
 
Example 10
Source File: ZooKeeperTestSupport.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
public ZooKeeperTestSupport(final HostAndPort hostAndPort) throws Exception {
    final int sessionTimeout = 3000;
    zk = new ZooKeeper(hostAndPort.toString(), sessionTimeout, new Watcher() {
        @Override
        public void process(WatchedEvent event) {
            if (event.getState() == Event.KeeperState.SyncConnected) {
                LOG.debug("Connected to ZooKeeper at {}", hostAndPort);
                connSignal.countDown();
            } else {
                LOG.info("WatchedEvent at {}: {}", hostAndPort, event.getState());
            }
        }
    });
    connSignal.await();
}
 
Example 11
Source File: MegabusRefProducerManager.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Inject
public MegabusRefProducerManager(LeaderServiceTask leaderServiceTask,
                                 @MegabusZookeeper CuratorFramework curator,
                                 @MegabusRefTopic Topic refTopic,
                                 @SelfHostAndPort HostAndPort hostAndPort,
                                 Clock clock,
                                 final MegabusRefProducerConfiguration refProducerConfiguration,
                                 final DatabusFactory databusFactory,
                                 DatabusEventStore databusEventStore,
                                 final @SystemIdentity String systemId,
                                 @MegabusApplicationId String applicationId,
                                 final RateLimitedLogFactory logFactory,
                                 @NumRefPartitions int numRefPartitions,
                                 final MetricRegistry metricRegistry,
                                 KafkaCluster kafkaCluster,
                                 ObjectMapper objectMapper) {

    // Since the megabus reads from the databus's internal event store. We forward the refs directly onto a
    // kafka-based ref topic. We use a partitioned leader service to evenly balance the partitions among the megabus
    // servers.
    super(curator, LEADER_DIR, hostAndPort.toString(),
            "PartitionedLeaderSelector-MegabusRefProducer", numRefPartitions, 1, 1, TimeUnit.MINUTES,
            partition -> new MegabusRefProducer(refProducerConfiguration, databusEventStore,
                            logFactory, metricRegistry, kafkaCluster.producer(), objectMapper, refTopic,
                            ChannelNames.getMegabusRefProducerChannel(applicationId, partition), Integer.toString(partition)), clock);

    _databus = requireNonNull(databusFactory).forOwner(systemId);
    _numRefPartitions = numRefPartitions;
    _applicationId = requireNonNull(applicationId);

    for (LeaderService leaderService : getPartitionLeaderServices()) {
        ServiceFailureListener.listenTo(leaderService, metricRegistry);
    }

    leaderServiceTask.register(SERVICE_NAME, this);
}
 
Example 12
Source File: MissingRefDelayProcessor.java    From emodb with Apache License 2.0 5 votes vote down vote up
public MissingRefDelayProcessor(Topic retryRefTopic,
                                Topic missingRefTopic,
                                KafkaCluster kafkaCluster,
                                Clock clock,
                                HostAndPort hostAndPort,
                                String delayProcessorConsumerGroup,
                                MetricRegistry metricRegistry) {
    super(SERVICE_NAME, kafkaCluster, hostAndPort.toString(),
            delayProcessorConsumerGroup, 1, metricRegistry);

    _retryRefTopic = requireNonNull(retryRefTopic, "retryRefTopic");
    _missingRefTopic = requireNonNull(missingRefTopic, "missingRefTopic");
    _clock = requireNonNull(clock, "clock");
}
 
Example 13
Source File: MegabusBootWorkflowManager.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Inject
public MegabusBootWorkflowManager(@MegabusZookeeper CuratorFramework curator,
                                  @SelfHostAndPort HostAndPort selfHostAndPort,
                                  LifeCycleRegistry lifeCycle,
                                  LeaderServiceTask leaderServiceTask,
                                  @MegabusRefResolverService Service refResolverService,
                                  @MissingRefDelayService Service missingRefDelayService,
                                  @TableEventRegistrationService Service tableEventRegistrationService,
                                  MegabusBootDAO megabusBootDAO,
                                  @MegabusApplicationId String megabusApplicationId,
                                  @MegabusTopic Topic megabusTopic,
                                  MegabusRefProducerManager refProducerManager,
                                  @TableEventProcessorService Service tableEventProcessorService,
                                  MegabusBootDAO statusDAO) {
    _applicationId = megabusApplicationId;
    _bootInitiater = new LeaderService(curator, LEADER_DIR, selfHostAndPort.toString(),
            MegabusBootInitiater.SERVICE_NAME, 1, TimeUnit.MINUTES,
            () -> new MegabusBootInitiater(megabusBootDAO, megabusApplicationId, megabusTopic, refProducerManager));
    _megabusBootDAO = megabusBootDAO;
    _missingRefDelayService = missingRefDelayService;
    _refResolverService = refResolverService;
    _tableEventRegistrationService = tableEventRegistrationService;
    _tableEventProcessorService = tableEventProcessorService;
    _refProducerManager = refProducerManager;
    _bootCoordinator = Executors.newSingleThreadScheduledExecutor();
    lifeCycle.manage(this);
}
 
Example 14
Source File: HintsPollerManager.java    From emodb with Apache License 2.0 5 votes vote down vote up
public List<LeaderService> getLeaderServices(final Map<String, ValueStore<Long>> timestampCache,
                                             CuratorFramework curator,
                                             HostAndPort self,
                                             final Map<String, HintsPollerCQLSession> cqlSessionForHintsPollerMap,
                                             final ClusterHintsPoller clusterHintsPoller,
                                             LeaderServiceTask dropwizardTask,
                                             final MetricRegistry metricRegistry) {
    _leaderServiceList = Lists.newArrayList();
    String serverId = self.toString(); // For debugging

    // Start one hints poller for each data store cluster
    for (final Map.Entry<String, HintsPollerCQLSession> entry : cqlSessionForHintsPollerMap.entrySet()) {
        final String clusterName = entry.getKey();
        final Session session = entry.getValue().getCqlSession();
        String zkLeaderPath = "/leader/hints/" + clusterName;
        String threadName = "Leader-HintsPoller-" + clusterName;
        LeaderService leaderService = new LeaderService(
                curator, zkLeaderPath, serverId, threadName, 1, TimeUnit.MINUTES,
                new Supplier<Service>() {
                    @Override
                    public Service get() {
                        return new HintsPollerService(clusterName, timestampCache.get(clusterName), session, clusterHintsPoller, metricRegistry);
                    }
                });
        ServiceFailureListener.listenTo(leaderService, metricRegistry);
        dropwizardTask.register("hints-" + clusterName, leaderService);
        _leaderServiceList.add(leaderService);
    }

    return _leaderServiceList;
}
 
Example 15
Source File: MaintenanceSchedulerManager.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Inject
public MaintenanceSchedulerManager(LifeCycleRegistry lifeCycle,
                                   final MaintenanceDAO tableDao,
                                   final Optional<TableMutexManager> tableMutexManager,
                                   @CurrentDataCenter final String selfDataCenter,
                                   @CachingTableDAORegistry final CacheRegistry cacheRegistry,
                                   @Maintenance final CuratorFramework curator,
                                   @SelfHostAndPort final HostAndPort self,
                                   final LeaderServiceTask dropwizardTask,
                                   final MoveTableTask moveTableTask,
                                   @TableChangesEnabled ValueStore<Boolean> tableChangesEnabled,
                                   @Maintenance final String scope,
                                   final MetricRegistry metricRegistry) {
    final Supplier<Service> maintenanceServiceFactory = new Supplier<Service>() {
        @Override
        public Service get() {
            return new MaintenanceScheduler(tableDao, tableMutexManager, selfDataCenter, cacheRegistry, moveTableTask);
        }
    };

    // Now start the maintenance scheduler subject to winning a leader election.
    Supplier<LeaderService> leaderServiceFactory = new Supplier<LeaderService>() {
        @Override
        public LeaderService get() {
            LeaderService service = new LeaderService(
                    curator, "/leader/table-maintenance", self.toString(),
                    "Leader-TableMaintenance-" + scope, 1, TimeUnit.MINUTES,
                    maintenanceServiceFactory);
            ServiceFailureListener.listenTo(service, metricRegistry);
            dropwizardTask.register(scope.toLowerCase() + "-maintenance", service);
            return service;
        }
    };

    // Turn everything on and off based on a boolean flag in ZooKeeper.
    lifeCycle.manage(new GuavaServiceController(tableChangesEnabled, leaderServiceFactory));
}
 
Example 16
Source File: ZookeeperUtils.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public static String buildQuorumEntry(HostAndPort hostAndPort,
  int defaultPort) {
  String s = hostAndPort.toString();
  if (hostAndPort.hasPort()) {
    return s;
  } else {
    return s + ":" + defaultPort;
  }
}
 
Example 17
Source File: PartitionAwareServiceFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
public PartitionAwareServiceFactory(Class<S> serviceClass, MultiThreadedServiceFactory<S> delegate, S local,
                                    HostAndPort self, HealthCheckRegistry healthCheckRegistry,
                                    MetricRegistry metricRegistry) {
    _serviceClass = checkNotNull(serviceClass, "serviceClass");
    _delegate = checkNotNull(delegate, "delegate");
    _local = checkNotNull(local, "local");
    _localId = self.toString();
    _healthCheckRegistry = healthCheckRegistry;
    _errorMeter = metricRegistry.meter(MetricRegistry.name("bv.emodb.web.partition-forwarding",
            serviceClass.getSimpleName(), "errors"));
}
 
Example 18
Source File: Origin.java    From styx with Apache License 2.0 5 votes vote down vote up
Origin(String originId, String host) {
    HostAndPort hostAndPort = HostAndPort.fromString(host);

    this.originId = Id.id(originId);
    this.host = hostAndPort.getHost();
    this.port = hostAndPort.getPort();
    this.hostAsString = hostAndPort.toString();
    this.applicationId = GENERIC_APP;
    this.hashCode = Objects.hash(this.host, this.originId);
}
 
Example 19
Source File: Transport.java    From presto with Apache License 2.0 4 votes vote down vote up
private static TTransportException rewriteException(TTransportException e, HostAndPort address)
{
    String message = e.getMessage() != null ? format("%s: %s", address, e.getMessage()) : address.toString();
    return new TTransportException(e.getType(), message, e);
}
 
Example 20
Source File: PushGatewayProvider.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PushGateway get() {
    final HostAndPort address = configuration.getAddress().withDefaultPort(9091);

    return new PushGateway(address.toString());
}