Search in sources :

Example 1 with RegistrationId

use of com.linkedin.databus.client.pub.RegistrationId in project databus by linkedin.

the class DatabusV2ClusterRegistrationImpl method activateOnePartition.

/**
 * Callback to activate one partition that was added
 * @param partition
 * @throws DatabusException
 */
private synchronized void activateOnePartition(DbusPartitionInfo partition) throws DatabusClientException {
    _log.info("Trying to activate partition :" + partition);
    try {
        if (regMap.containsKey(partition)) {
            _log.info("Partition (" + partition + ") is already added and is currently in state : " + regMap.get(partition).getState() + " skipping !!");
            return;
        }
        // Call factories to get consumer callbacks and server-side filter config.
        Collection<DatabusCombinedConsumer> consumers = _consumerFactory.createPartitionedConsumers(_clusterInfo, partition);
        DbusKeyCompositeFilterConfig filterConfig = null;
        if (_serverSideFilterFactory != null)
            filterConfig = _serverSideFilterFactory.createServerSideFilter(_clusterInfo, partition);
        if ((null == consumers) || (consumers.isEmpty())) {
            _log.error("ConsumerFactory for cluster (" + _clusterInfo + ") returned null or empty consumers ");
            throw new DatabusClientException("ConsumerFactory for cluster (" + _clusterInfo + ") returned null or empty consumers");
        }
        // Create Registration
        RegistrationId id = new RegistrationId(_id + "-" + partition.getPartitionId());
        CheckpointPersistenceProvider ckptProvider = createCheckpointPersistenceProvider(partition);
        DatabusV2RegistrationImpl reg = createChildRegistration(id, _client, ckptProvider);
        reg.addDatabusConsumers(consumers);
        String[] srcs = new String[_sources.size()];
        srcs = _sources.toArray(srcs);
        reg.addSubscriptions(srcs);
        regMap.put(partition, reg);
        reg.onRegister();
        // Add Server-Side Filter
        if (null != filterConfig)
            reg.withServerSideFilter(filterConfig);
        // Notify Listener
        if (null != _partitionListener)
            _partitionListener.onAddPartition(partition, reg);
        // Start the registration
        try {
            reg.start();
        } catch (DatabusClientException e) {
            _log.error("Got exception while starting the registration for partition (" + partition + ")", e);
            throw e;
        }
        // Add partition Specific metrics to cluster-merge
        _relayEventStatsMerger.addStatsCollector(id.getId(), (DbusEventsStatisticsCollector) reg.getRelayEventStats());
        _bootstrapEventStatsMerger.addStatsCollector(id.getId(), (DbusEventsStatisticsCollector) reg.getBootstrapEventStats());
        _relayCallbackStatsMerger.addStatsCollector(id.getId(), (ConsumerCallbackStats) reg.getRelayCallbackStats());
        _bootstrapCallbackStatsMerger.addStatsCollector(id.getId(), (ConsumerCallbackStats) reg.getBootstrapCallbackStats());
        _log.info("Partition (" + partition + ") started !!");
    } catch (DatabusException e) {
        _log.error("Got exception while activating partition(" + partition + ")", e);
        throw new DatabusClientException(e);
    } catch (ClusterCheckpointException e) {
        _log.error("Got exception while activating partition(" + partition + ")", e);
        throw new DatabusClientException(e);
    }
}
Also used : DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) CheckpointPersistenceProvider(com.linkedin.databus.client.pub.CheckpointPersistenceProvider) ClusterCheckpointPersistenceProvider(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider) DatabusException(com.linkedin.databus2.core.DatabusException) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) ClusterCheckpointException(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.ClusterCheckpointException)

Example 2 with RegistrationId

use of com.linkedin.databus.client.pub.RegistrationId in project databus by linkedin.

the class ClientStateRequestProcessor method processRegistrations.

/**
 * Displays all top-level registrations registered to the client (both V2 and V3).
 * Top-level registrations are those that were created as a result of one of
 * "registerXXX()" calls on databus-client. In the case of multi-partition registrations
 * (like MPRegistration, V2/V3 CLB), only the parent registration is considered the
 * top-level registration. Per-partition (child) registrations which were created as
 * part of partition migration are NOT top-level registrations.
 *
 * @param request
 *          DatabusRequest corresponding to the REST API.
 * @throws IOException
 *           when unable to write to ourput channel
 */
private void processRegistrations(DatabusRequest request) throws IOException {
    Map<String, Collection<DatabusSubscription>> regIds = new TreeMap<String, Collection<DatabusSubscription>>();
    // V2 Registration
    Collection<RegInfo> regs = getAllTopLevelV2Registrations();
    if (null != regs) {
        for (RegInfo r : regs) {
            regIds.put(r.getRegId().getId(), r.getSubs());
        }
    }
    Map<RegistrationId, DatabusV3Registration> registrationIdMap = _client.getRegistrationIdMap();
    // V3 Registration
    if (null != registrationIdMap) {
        for (Map.Entry<RegistrationId, DatabusV3Registration> entry : registrationIdMap.entrySet()) {
            DatabusV3Registration reg = entry.getValue();
            List<DatabusSubscription> dsl = reg.getSubscriptions();
            regIds.put(entry.getKey().getId(), dsl);
        }
    }
    writeJsonObjectToResponse(regIds, request);
}
Also used : RegistrationId(com.linkedin.databus.client.pub.RegistrationId) TreeMap(java.util.TreeMap) DatabusSubscription(com.linkedin.databus.core.data_model.DatabusSubscription) DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 3 with RegistrationId

use of com.linkedin.databus.client.pub.RegistrationId in project databus by linkedin.

the class ClientStateRequestProcessor method processMPRegistrations.

/**
 * Exposes the mapping between a mpRegistration -> Set of individual registrations
 */
private void processMPRegistrations(DatabusRequest request) throws IOException, RequestProcessingException {
    Map<RegistrationId, DatabusV3Registration> registrationIdMap = _client.getRegistrationIdMap();
    if (null == registrationIdMap)
        throw new InvalidRequestParamValueException(request.getName(), REGISTRATIONS_KEY, "Present only for Databus V3 clients");
    Map<String, List<String>> ridList = new TreeMap<String, List<String>>();
    for (Map.Entry<RegistrationId, DatabusV3Registration> entry : registrationIdMap.entrySet()) {
        DatabusV3Registration reg = entry.getValue();
        if (reg instanceof DatabusV3MultiPartitionRegistration) {
            Collection<DatabusV3Registration> dvrList = ((DatabusV3MultiPartitionRegistration) reg).getPartionRegs().values();
            List<String> mpRegList = new ArrayList<String>();
            for (DatabusV3Registration dvr : dvrList) {
                mpRegList.add(dvr.getRegistrationId().getId());
            }
            ridList.put(entry.getKey().getId(), mpRegList);
        }
    }
    writeJsonObjectToResponse(ridList, request);
    return;
}
Also used : DatabusV3MultiPartitionRegistration(com.linkedin.databus.client.pub.DatabusV3MultiPartitionRegistration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException) DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 4 with RegistrationId

use of com.linkedin.databus.client.pub.RegistrationId in project databus by linkedin.

the class ClientStateRequestProcessor method findV2Registration.

/**
 * Helper method to locate a databus V2 registration by its registration id. This method
 * can locate both top-level (registered by one of _dbusClient.registerXXX()) and
 * individual-partition (child) registration that are aggregated inside a top-level
 * MultiPartition registration.
 *
 * Please note that this can traverse the registration tree which is 1 level deep. In
 * other words, it will not work when we have MultiPartition registrations aggregated
 * inside another MultiPartition registrations.
 *
 * @param regId
 *          Registration Id to be located
 * @param request
 *          Databus Request corresponding to the REST call.
 * @return
 * @throws RequestProcessingException
 *           when the registration is not found.
 */
private DatabusRegistration findV2Registration(DatabusRequest request, String prefix) throws RequestProcessingException {
    String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    String registrationIdStr = category.substring(prefix.length());
    RegistrationId regId = new RegistrationId(registrationIdStr);
    Collection<DatabusRegistration> regs = _client.getAllRegistrations();
    if (null != regs) {
        for (DatabusRegistration r : regs) {
            if (regId.equals(r.getRegistrationId())) {
                return r;
            }
            /**
             * Important Note: There is an important implementation difference on which
             * registrations are stored in the global registration data-structure maintained
             * by the client (DatabusHttp[V3]ClientImpls) between V2 and V3.
             *
             * 1. In the case of V2, only top-level registrations are stored in the global
             * data-structure (DatabusHttpClientImpl.regList 2. In the case of V3, all
             * registrations are stored in the global data-structure.
             *
             * In the case of V3, this is needed so that all registrations can act on the
             * relay external view change. This can be refactored in the future by moving the
             * relay-external view change to registration impl ( reduce the complexity in
             * ClientImpl ). The V2 implementation did not have this logic and was following a
             * more intuitive structure of preserving the hierarchy. The below code handles
             * the discrepancy for V2.
             */
            if (r instanceof DatabusMultiPartitionRegistration) {
                Map<DbusPartitionInfo, DatabusRegistration> childRegs = ((DatabusMultiPartitionRegistration) r).getPartitionRegs();
                for (Entry<DbusPartitionInfo, DatabusRegistration> e : childRegs.entrySet()) {
                    if (regId.equals(e.getValue().getRegistrationId())) {
                        return e.getValue();
                    }
                }
            }
        }
    }
    throw new RequestProcessingException("Unable to find registration (" + regId + ") ");
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) DatabusMultiPartitionRegistration(com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) DbusPartitionInfo(com.linkedin.databus.client.pub.DbusPartitionInfo)

Example 5 with RegistrationId

use of com.linkedin.databus.client.pub.RegistrationId in project databus by linkedin.

the class DatabusHttpClientImpl method registerCluster.

@Override
public DatabusRegistration registerCluster(String cluster, DbusClusterConsumerFactory consumerFactory, DbusServerSideFilterFactory filterFactory, DbusPartitionListener partitionListener, String... sources) throws DatabusClientException {
    if ((null == sources) || (sources.length == 0))
        throw new DatabusClientException("Sources is empty !!");
    if (_activeClusters.contains(cluster))
        throw new DatabusClientException("Cluster :" + cluster + " has already been registed to this client instance." + " Only one registration per cluster is allowed for a databus client instance !!");
    ClusterRegistrationStaticConfig c = _clientStaticConfig.getClientCluster(cluster);
    if (null == c)
        throw new DatabusClientException("Cluster Configuration for cluster (" + cluster + ") not provided !!");
    if (null == consumerFactory)
        throw new DatabusClientException("Consumer Factory is null !!");
    ClusterCheckpointPersistenceProvider.StaticConfig ckptPersistenceProviderConfig = new ClusterCheckpointPersistenceProvider.StaticConfig(c.getZkAddr(), c.getClusterName(), c.getMaxCkptWritesSkipped(), c.getCheckpointIntervalMs());
    DbusClusterInfo clusterInfo = new DbusClusterInfo(c.getClusterName(), c.getNumPartitions(), c.getQuorum());
    RegistrationId regId = RegistrationIdGenerator.generateNewId(c.getClusterName());
    DatabusV2ClusterRegistrationImpl reg = new DatabusV2ClusterRegistrationImpl(regId, this, ckptPersistenceProviderConfig, clusterInfo, consumerFactory, filterFactory, partitionListener, sources);
    _regList.add(reg);
    reg.onRegister();
    _activeClusters.add(cluster);
    return reg;
}
Also used : DatabusV2ClusterRegistrationImpl(com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl) ClusterCheckpointPersistenceProvider(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider) DbusClusterInfo(com.linkedin.databus.client.pub.DbusClusterInfo) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) ClusterRegistrationStaticConfig(com.linkedin.databus.client.registration.ClusterRegistrationStaticConfig) ClusterRegistrationStaticConfig(com.linkedin.databus.client.registration.ClusterRegistrationStaticConfig) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException)

Aggregations

RegistrationId (com.linkedin.databus.client.pub.RegistrationId)17 DatabusV3Registration (com.linkedin.databus.client.pub.DatabusV3Registration)7 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)5 DatabusClientException (com.linkedin.databus.client.pub.DatabusClientException)4 HashMap (java.util.HashMap)4 DbusPartitionInfo (com.linkedin.databus.client.pub.DbusPartitionInfo)3 DatabusMultiPartitionRegistration (com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration)3 RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)3 ClusterCheckpointPersistenceProvider (com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider)2 DatabusCombinedConsumer (com.linkedin.databus.client.pub.DatabusCombinedConsumer)2 DatabusV3MultiPartitionRegistration (com.linkedin.databus.client.pub.DatabusV3MultiPartitionRegistration)2 DbusClusterInfo (com.linkedin.databus.client.pub.DbusClusterInfo)2 DatabusV2ClusterRegistrationImpl (com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl)2 DatabusV2RegistrationImpl (com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)2 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)2 InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 DbusPartitionInfoImpl (com.linkedin.databus.client.DbusPartitionInfoImpl)1