Search in sources :

Example 1 with DatabusV3Registration

use of com.linkedin.databus.client.pub.DatabusV3Registration 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 2 with DatabusV3Registration

use of com.linkedin.databus.client.pub.DatabusV3Registration 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 DatabusV3Registration

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

the class ClientStatsRequestProcessor method processBootstrapEventsRegistrationV3.

private void processBootstrapEventsRegistrationV3(DatabusRequest request) throws IOException, RequestProcessingException {
    DatabusV3Registration reg = findV3Registration(request, BOOTSTRAP_EVENTS_REG_KEY_PREFIX);
    writeJsonObjectToResponse(reg.getBootstrapEventStats().getTotalStats(), request);
}
Also used : DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration)

Example 4 with DatabusV3Registration

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

the class ClientStateRequestProcessor method getV3ClusterPartitions.

/**
   * Get the list of partitions hosted by this client for the V3 cluster.
   * 
   * @param cluster
   *          V3 CLuster for which we need to find out the partitions.
   * @return
   * @throws RequestProcessingException
   *           when unable to find the cluster.
   */
private Collection<PartitionInfo> getV3ClusterPartitions(String cluster) throws RequestProcessingException {
    DatabusV3MultiPartitionRegistration reg = getV3ClusterRegistration(cluster);
    List<PartitionInfo> partitions = new ArrayList<PartitionInfo>();
    Map<PhysicalPartition, DatabusV3Registration> regMap = reg.getPartionRegs();
    for (Entry<PhysicalPartition, DatabusV3Registration> e : regMap.entrySet()) {
        PartitionInfo p = new PartitionInfo(e.getKey().getId(), e.getValue().getRegistrationId());
        partitions.add(p);
    }
    return partitions;
}
Also used : DatabusV3MultiPartitionRegistration(com.linkedin.databus.client.pub.DatabusV3MultiPartitionRegistration) DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration) ArrayList(java.util.ArrayList) DbusPartitionInfo(com.linkedin.databus.client.pub.DbusPartitionInfo) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Example 5 with DatabusV3Registration

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

the class ClientStateRequestProcessor method getAllTopLevelV3Registrations.

/**
   * Returns all the top-level V3 registrations. 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, 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.
   * 
   * @return collection of top-level registrations (V3)
   */
private Collection<RegInfo> getAllTopLevelV3Registrations() {
    /**
     * 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.
     */
    Map<RegistrationId, RegInfo> regListMap = new HashMap<RegistrationId, RegInfo>();
    /**
     * The _client.getRegistrationIdMap() has all registrations in one place. Top-Level
     * Registrations = Only those registrations whose getParent() == null.
     */
    Map<RegistrationId, DatabusV3Registration> regMap = _client.getRegistrationIdMap();
    for (Entry<RegistrationId, DatabusV3Registration> e : regMap.entrySet()) {
        RegInfo regInfo = null;
        DatabusV3Registration r = e.getValue();
        // If not top-level, skip
        if (null != r.getParentRegistration()) {
            continue;
        }
        Map<DbusPartitionInfo, RegInfo> childR = null;
        if (r instanceof DatabusV3MultiPartitionRegistration) {
            // ass the children regs to parent.
            Map<PhysicalPartition, DatabusV3Registration> childRegs = ((DatabusV3MultiPartitionRegistration) r).getPartionRegs();
            childR = new HashMap<DbusPartitionInfo, RegInfo>();
            for (Entry<PhysicalPartition, DatabusV3Registration> e2 : childRegs.entrySet()) {
                childR.put(new DbusPartitionInfoImpl(e2.getKey().getId()), new RegInfo(e.getValue().getState().name(), e.getValue().getRegistrationId(), e.getValue().getStatus(), null, e.getValue().getSubscriptions()));
            }
        }
        regInfo = new RegInfo(r.getState().name(), r.getRegistrationId(), r.getStatus(), null, r.getSubscriptions(), true, childR);
        regListMap.put(e.getKey(), regInfo);
    }
    return regListMap.values();
}
Also used : DatabusV3MultiPartitionRegistration(com.linkedin.databus.client.pub.DatabusV3MultiPartitionRegistration) HashMap(java.util.HashMap) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration) DbusPartitionInfoImpl(com.linkedin.databus.client.DbusPartitionInfoImpl) DbusPartitionInfo(com.linkedin.databus.client.pub.DbusPartitionInfo) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Aggregations

DatabusV3Registration (com.linkedin.databus.client.pub.DatabusV3Registration)14 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)7 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)4 DatabusV3MultiPartitionRegistration (com.linkedin.databus.client.pub.DatabusV3MultiPartitionRegistration)3 HashMap (java.util.HashMap)3 DbusPartitionInfo (com.linkedin.databus.client.pub.DbusPartitionInfo)2 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)2 InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)2 RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 DatabusSourcesConnection (com.linkedin.databus.client.DatabusSourcesConnection)1 DbusPartitionInfoImpl (com.linkedin.databus.client.DbusPartitionInfoImpl)1 RegistrationStatsInfo (com.linkedin.databus.client.monitoring.RegistrationStatsInfo)1 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)1 Collection (java.util.Collection)1 List (java.util.List)1