Search in sources :

Example 1 with DatabusMultiPartitionRegistration

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

use of com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration in project databus by linkedin.

the class ClientStateRequestProcessor method getAllTopLevelV2Registrations.

/**
   * Returns all the top-level V2 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 V2 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 (V2)
   */
private Collection<RegInfo> getAllTopLevelV2Registrations() {
    List<RegInfo> regList = new ArrayList<RegInfo>();
    Collection<DatabusRegistration> regs = _client.getAllRegistrations();
    for (DatabusRegistration r : regs) {
        RegInfo regInfo = null;
        if (r instanceof DatabusMultiPartitionRegistration) {
            Map<DbusPartitionInfo, DatabusRegistration> childRegs = ((DatabusMultiPartitionRegistration) r).getPartitionRegs();
            Map<DbusPartitionInfo, RegInfo> childR = new HashMap<DbusPartitionInfo, RegInfo>();
            for (Entry<DbusPartitionInfo, DatabusRegistration> e : childRegs.entrySet()) {
                childR.put(e.getKey(), new RegInfo(e.getValue().getState().name(), e.getValue().getRegistrationId(), e.getValue().getStatus(), e.getValue().getFilterConfig(), e.getValue().getSubscriptions()));
            }
            regInfo = new RegInfo(r.getState().name(), r.getRegistrationId(), r.getStatus(), r.getFilterConfig(), r.getSubscriptions(), true, childR);
        } else {
            regInfo = new RegInfo(r.getState().name(), r.getRegistrationId(), r.getStatus(), r.getFilterConfig(), r.getSubscriptions());
        }
        regList.add(regInfo);
    }
    return regList;
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) DatabusMultiPartitionRegistration(com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DbusPartitionInfo(com.linkedin.databus.client.pub.DbusPartitionInfo)

Example 3 with DatabusMultiPartitionRegistration

use of com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration in project databus by linkedin.

the class ClientStatsRequestProcessor method findRegistration.

private DatabusRegistration findRegistration(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();
    for (DatabusRegistration r : regs) {
        if (regId.equals(r.getRegistrationId()))
            return r;
        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 4 with DatabusMultiPartitionRegistration

use of com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration in project databus by linkedin.

the class DatabusHttpClientImpl method getAllClientClusters.

/**
   * Fetch all the client clusters which have been registered in this client instance keyed by their
   * registrationIds. This has been overridden by V3 client to provide both V2 and V3 clusters.
   *
   * Only a copy of the registration ids are returned. Hence modifying the registration ids should not
   * affect the global Registration Id map.
   * @return Client clusters registered in this client instance keyed by their registration ids.
   */
public Map<RegistrationId, DbusClusterInfo> getAllClientClusters() {
    Map<RegistrationId, DbusClusterInfo> clusters = new HashMap<RegistrationId, DbusClusterInfo>();
    Collection<DatabusMultiPartitionRegistration> regs = getAllClientClusterRegistrations();
    for (DatabusMultiPartitionRegistration reg : regs) {
        if (reg instanceof DatabusV2ClusterRegistrationImpl) {
            DatabusV2ClusterRegistrationImpl r = (DatabusV2ClusterRegistrationImpl) reg;
            clusters.put(new RegistrationId(r.getRegistrationId().getId()), r.getClusterInfo());
        }
    }
    return clusters;
}
Also used : DatabusV2ClusterRegistrationImpl(com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl) DbusClusterInfo(com.linkedin.databus.client.pub.DbusClusterInfo) HashMap(java.util.HashMap) DatabusMultiPartitionRegistration(com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId)

Aggregations

DatabusMultiPartitionRegistration (com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration)4 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)3 DbusPartitionInfo (com.linkedin.databus.client.pub.DbusPartitionInfo)3 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)3 RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)2 HashMap (java.util.HashMap)2 DbusClusterInfo (com.linkedin.databus.client.pub.DbusClusterInfo)1 DatabusV2ClusterRegistrationImpl (com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl)1 ArrayList (java.util.ArrayList)1