Search in sources :

Example 1 with DatabusV3MultiPartitionRegistration

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

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

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

DatabusV3MultiPartitionRegistration (com.linkedin.databus.client.pub.DatabusV3MultiPartitionRegistration)3 DatabusV3Registration (com.linkedin.databus.client.pub.DatabusV3Registration)3 DbusPartitionInfo (com.linkedin.databus.client.pub.DbusPartitionInfo)2 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)2 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DbusPartitionInfoImpl (com.linkedin.databus.client.DbusPartitionInfoImpl)1 InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1