Search in sources :

Example 11 with DatabusRegistration

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

the class ClientStateRequestProcessor method pauseResumeRegistration.

/**
   * Pause or resume a V2 or V3 registration. The registration can be a top-level or
   * child-level registration 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
   *          Databus request corresponding to the REST call.
   * @param doPause
   *          true if wanted to pause, false if to be resumed
   * @throws IOException
   *           if unable to write output to channel
   * @throws RequestProcessingException
   *           when registration could not be found.
   */
private void pauseResumeRegistration(DatabusRequest request, boolean doPause) throws IOException, RequestProcessingException {
    DatabusRegistration r = null;
    DatabusV3Registration r2 = null;
    boolean found = true;
    boolean isRunning = false;
    boolean isPaused = false;
    boolean isSuspended = false;
    RegistrationId regId = null;
    RequestProcessingException rEx = null;
    RegStatePair regStatePair = null;
    try {
        r = findV2Registration(request, PAUSE_REGISTRATION);
        isRunning = r.getState().isRunning();
        isPaused = (r.getState() == DatabusRegistration.RegistrationState.PAUSED);
        isSuspended = (r.getState() == DatabusRegistration.RegistrationState.SUSPENDED_ON_ERROR);
        regId = r.getRegistrationId();
    } catch (RequestProcessingException ex) {
        found = false;
        rEx = ex;
    }
    if (!found) {
        try {
            r2 = findV3Registration(request, PAUSE_REGISTRATION);
            found = true;
            isRunning = r2.getState().isRunning();
            isPaused = (r2.getState() == RegistrationState.PAUSED);
            isSuspended = (r2.getState() == RegistrationState.SUSPENDED_ON_ERROR);
            regId = r.getRegistrationId();
        } catch (RequestProcessingException ex) {
            found = false;
            rEx = ex;
        }
    }
    if (!found)
        throw rEx;
    LOG.info("REST call to pause registration : " + regId);
    if (isRunning) {
        if (doPause) {
            if (!isPaused) {
                if (null != r) {
                    r.pause();
                    regStatePair = new RegStatePair(r.getState(), r.getRegistrationId());
                } else {
                    r2.pause();
                    regStatePair = new RegStatePair(r2.getState().name(), r2.getRegistrationId());
                }
            }
        } else {
            if (isPaused || isSuspended) {
                if (null != r) {
                    r.resume();
                    regStatePair = new RegStatePair(r.getState(), r.getRegistrationId());
                } else {
                    r2.resume();
                    regStatePair = new RegStatePair(r2.getState().name(), r2.getRegistrationId());
                }
            }
        }
    }
    writeJsonObjectToResponse(regStatePair, request);
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException)

Example 12 with DatabusRegistration

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

the class ClientStateRequestProcessor method resumeAllRegistrations.

/**
   * Resume all registrations paused or suspended (both V2 and V3 in this client instance)
   * 
   * @param request
   *          DatabusRequest corresponding to the REST call.
   * @throws IOException
   *           when unable to write the output.
   */
private void resumeAllRegistrations(DatabusRequest request) throws IOException {
    LOG.info("REST call to resume all registrations");
    /**
     * Get the top-level V2 registrations and pause them. The child-level registrations by
     * the top-level registrations that aggregates them.
     */
    Collection<DatabusRegistration> regs = _client.getAllRegistrations();
    if (null != regs) {
        for (DatabusRegistration r : regs) {
            if (r.getState().isRunning()) {
                if ((r.getState() == DatabusRegistration.RegistrationState.PAUSED) || (r.getState() == DatabusRegistration.RegistrationState.SUSPENDED_ON_ERROR))
                    r.resume();
            }
        }
    }
    /**
     * Get the top-level V3 registrations and pause them. The child-level registrations by
     * the top-level registrations that aggregates them.
     */
    Map<RegistrationId, DatabusV3Registration> regMap = _client.getRegistrationIdMap();
    Collection<RegInfo> topLevelRegs = 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.
     */
    if ((null != regMap) && (null != topLevelRegs)) {
        for (RegInfo reg : topLevelRegs) {
            DatabusV3Registration r = regMap.get(reg.getRegId());
            if (r.getState().isRunning()) {
                if ((r.getState() == RegistrationState.PAUSED) || (r.getState() == RegistrationState.SUSPENDED_ON_ERROR))
                    r.resume();
            }
        }
    }
    writeJsonObjectToResponse(getAllTopLevelRegStates(), request);
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration)

Example 13 with DatabusRegistration

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

the class ClientStateRequestProcessor method pauseAllRegistrations.

/**
   * Pause all registrations (both V2 and V3 in this client instance) which are in running
   * state.
   * 
   * @param request
   *          DatabusRequest corresponding to the REST call.
   * @throws IOException
   *           when unable to write the output.
   */
private void pauseAllRegistrations(DatabusRequest request) throws IOException {
    LOG.info("REST call to pause all registrations");
    /**
     * Get the top-level V2 registrations and pause them. The child-level registrations by
     * the top-level registrations that aggregates them.
     */
    Collection<DatabusRegistration> regs = _client.getAllRegistrations();
    if (null != regs) {
        for (DatabusRegistration r : regs) {
            if (r.getState().isRunning()) {
                if (r.getState() != DatabusRegistration.RegistrationState.PAUSED)
                    r.pause();
            }
        }
    }
    /**
     * Get the top-level V3 registrations and pause them. The child-level registrations by
     * the top-level registrations that aggregates them.
     */
    Map<RegistrationId, DatabusV3Registration> regMap = _client.getRegistrationIdMap();
    Collection<RegInfo> topLevelRegs = 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.
     */
    if ((null != regMap) && (null != topLevelRegs)) {
        for (RegInfo reg : topLevelRegs) {
            DatabusV3Registration r = regMap.get(reg.getRegId());
            if (r.getState().isRunning()) {
                if (r.getState() != RegistrationState.PAUSED)
                    r.pause();
            }
        }
    }
    writeJsonObjectToResponse(getAllTopLevelRegStates(), request);
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration)

Example 14 with DatabusRegistration

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

the class ClusterFileLoggingClient method mainFunction.

public void mainFunction(String[] args) throws Exception {
    String[] leftOverArgs = processLocalArgs(args);
    Properties startupProps = DatabusHttpClientImpl.processCommandLineArgs(leftOverArgs);
    DatabusHttpClientImpl.Config clientConfigBuilder = new DatabusHttpClientImpl.Config();
    clientConfigBuilder.getContainer().setIdFromName(MODULE + ".localhost");
    if (_enableBootStrap) {
        clientConfigBuilder.getRuntime().getBootstrap().setEnabled(true);
    }
    ConfigLoader<DatabusHttpClientImpl.StaticConfig> configLoader = new ConfigLoader<DatabusHttpClientImpl.StaticConfig>("databus.client.", clientConfigBuilder);
    String[] sources = getSources();
    StringBuilder sourcesString = new StringBuilder();
    boolean firstSrc = true;
    for (String source : sources) {
        if (!firstSrc)
            sourcesString.append(",");
        firstSrc = false;
        sourcesString.append(source);
    }
    if (_httpPort != null) {
        startupProps.put("databus.client.container.httpPort", _httpPort);
    }
    if (_jmxServicePort != null) {
        startupProps.put("databus.client.container.jmx.jmxServicePort", _jmxServicePort);
    }
    if (_checkpointFileRootDir != null) {
        startupProps.put("databus.client.checkpointPersistence.fileSystem.rootDirectory", _checkpointFileRootDir);
    }
    DatabusHttpClientImpl.StaticConfig clientConfig = configLoader.loadConfig(startupProps);
    // set up relay
    ServerInfoBuilder relayBuilder = clientConfig.getRuntime().getRelay("1");
    relayBuilder.setName("DefaultRelay");
    if (_relayHost != null) {
        relayBuilder.setHost(_relayHost);
    }
    if (_relayPort != null) {
        relayBuilder.setPort(Integer.parseInt(_relayPort));
    }
    relayBuilder.setSources(sourcesString.toString());
    // set up bootstrap
    if (_enableBootStrap) {
        ServerInfoBuilder bootstrapBuilder = clientConfig.getRuntime().getBootstrap().getService("2");
        bootstrapBuilder.setName("DefaultBootstrapServices");
        if (_bootstrapHost != null) {
            bootstrapBuilder.setHost(_bootstrapHost);
        }
        if (_bootstrapPort != null) {
            bootstrapBuilder.setPort(Integer.parseInt(_bootstrapPort));
        }
        bootstrapBuilder.setSources(sourcesString.toString());
    }
    // set up listeners
    DatabusHttpClientImpl client = new DatabusHttpClientImpl(clientConfig);
    List<DatabusRegistration> regs = new ArrayList<DatabusRegistration>();
    for (String cluster : _clusters) {
        DatabusRegistration reg = client.registerCluster(cluster, createConsumerFactory(cluster, _valueDumpFile, _eventDumpFile), createServerSideFactory(cluster), createPartitionListener(cluster), sources);
        regs.add(reg);
    }
    // add pause processor
    try {
        client.getProcessorRegistry().register(ContainerOperationProcessor.COMMAND_NAME, new ContainerOperationProcessor(null, client));
    } catch (ProcessorRegistrationConflictException e) {
        LOG.error("Failed to register " + ConsumerPauseRequestProcessor.COMMAND_NAME);
    }
    DatabusClientShutdownThread shutdownThread = new DatabusClientShutdownThread(client);
    Runtime.getRuntime().addShutdownHook(shutdownThread);
    client.startAndBlock();
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) ConfigLoader(com.linkedin.databus.core.util.ConfigLoader) ArrayList(java.util.ArrayList) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) ContainerOperationProcessor(com.linkedin.databus2.core.container.request.ContainerOperationProcessor) Properties(java.util.Properties) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder) ProcessorRegistrationConflictException(com.linkedin.databus2.core.container.request.ProcessorRegistrationConflictException)

Example 15 with DatabusRegistration

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

the class SimpleFileLoggingConsumer method mainFunction.

public void mainFunction(String[] args) throws Exception {
    String[] leftOverArgs = processLocalArgs(args);
    Properties startupProps = DatabusHttpClientImpl.processCommandLineArgs(leftOverArgs);
    DatabusHttpClientImpl.Config clientConfigBuilder = new DatabusHttpClientImpl.Config();
    clientConfigBuilder.getContainer().setIdFromName(MODULE + ".localhost");
    if (_enableBootStrap) {
        clientConfigBuilder.getRuntime().getBootstrap().setEnabled(true);
    }
    ConfigLoader<DatabusHttpClientImpl.StaticConfig> configLoader = new ConfigLoader<DatabusHttpClientImpl.StaticConfig>("databus.client.", clientConfigBuilder);
    String[] sources = addSources();
    StringBuilder sourcesString = new StringBuilder();
    boolean firstSrc = true;
    for (String source : sources) {
        if (!firstSrc)
            sourcesString.append(",");
        firstSrc = false;
        sourcesString.append(source);
    }
    if (_httpPort != null) {
        startupProps.put("databus.client.container.httpPort", _httpPort);
    }
    if (_jmxServicePort != null) {
        startupProps.put("databus.client.container.jmx.jmxServicePort", _jmxServicePort);
    }
    if (_checkpointFileRootDir != null) {
        startupProps.put("databus.client.checkpointPersistence.fileSystem.rootDirectory", _checkpointFileRootDir);
    }
    DatabusHttpClientImpl.StaticConfig clientConfig = configLoader.loadConfig(startupProps);
    // set up relay
    ServerInfoBuilder relayBuilder = clientConfig.getRuntime().getRelay("1");
    relayBuilder.setName("DefaultRelay");
    if (_relayHost != null) {
        relayBuilder.setHost(_relayHost);
    }
    if (_relayPort != null) {
        relayBuilder.setPort(Integer.parseInt(_relayPort));
    }
    relayBuilder.setSources(sourcesString.toString());
    // set up bootstrap
    if (_enableBootStrap) {
        ServerInfoBuilder bootstrapBuilder = clientConfig.getRuntime().getBootstrap().getService("2");
        bootstrapBuilder.setName("DefaultBootstrapServices");
        if (_bootstrapHost != null) {
            bootstrapBuilder.setHost(_bootstrapHost);
        }
        if (_bootstrapPort != null) {
            bootstrapBuilder.setPort(Integer.parseInt(_bootstrapPort));
        }
        bootstrapBuilder.setSources(sourcesString.toString());
    }
    // handler server side filtering, can either pass a config file or set from command line
    DbusKeyCompositeFilterConfig filterConfig = createServerSideFilterConfig(_filterConfFile, startupProps);
    // set up listeners
    DatabusHttpClientImpl client = new DatabusHttpClientImpl(clientConfig);
    // dump decoded payload values and raw (undecoded) events
    DatabusFileLoggingConsumer consumer = createTypedConsumer(_valueDumpFile, _eventDumpFile);
    if (_eventPattern != null) {
        consumer.setEventPattern(_eventPattern);
    }
    DatabusRegistration reg = client.register(consumer, sources);
    if (!(reg instanceof DatabusV2RegistrationImpl)) {
        throw new RuntimeException("Unexpected type for registration Object !!");
    }
    if (null != filterConfig)
        reg.withServerSideFilter(filterConfig);
    // add pause processor
    try {
        client.getProcessorRegistry().register(ConsumerPauseRequestProcessor.COMMAND_NAME, new ConsumerPauseRequestProcessor(null, consumer));
        client.getProcessorRegistry().register(ContainerOperationProcessor.COMMAND_NAME, new ContainerOperationProcessor(null, client));
    } catch (ProcessorRegistrationConflictException e) {
        LOG.error("Failed to register " + ConsumerPauseRequestProcessor.COMMAND_NAME);
    }
    DatabusClientShutdownThread shutdownThread = new DatabusClientShutdownThread(client);
    Runtime.getRuntime().addShutdownHook(shutdownThread);
    //this should automatically start the registration
    client.startAndBlock();
}
Also used : DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) ConfigLoader(com.linkedin.databus.core.util.ConfigLoader) DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) ContainerOperationProcessor(com.linkedin.databus2.core.container.request.ContainerOperationProcessor) Properties(java.util.Properties) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder) ProcessorRegistrationConflictException(com.linkedin.databus2.core.container.request.ProcessorRegistrationConflictException) DatabusV2RegistrationImpl(com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)

Aggregations

DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)21 DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)5 DatabusClientException (com.linkedin.databus.client.pub.DatabusClientException)5 DbusPartitionInfo (com.linkedin.databus.client.pub.DbusPartitionInfo)5 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)5 RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)5 DatabusV3Registration (com.linkedin.databus.client.pub.DatabusV3Registration)4 ArrayList (java.util.ArrayList)4 DatabusMultiPartitionRegistration (com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration)3 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)3 InetSocketAddress (java.net.InetSocketAddress)3 Test (org.testng.annotations.Test)3 AbstractDatabusCombinedConsumer (com.linkedin.databus.client.consumer.AbstractDatabusCombinedConsumer)2 ServerInfoBuilder (com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder)2 DatabusV2ClusterRegistrationImpl (com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl)2 ConfigLoader (com.linkedin.databus.core.util.ConfigLoader)2 ContainerOperationProcessor (com.linkedin.databus2.core.container.request.ContainerOperationProcessor)2 ProcessorRegistrationConflictException (com.linkedin.databus2.core.container.request.ProcessorRegistrationConflictException)2 Properties (java.util.Properties)2 DatabusSourcesConnection (com.linkedin.databus.client.DatabusSourcesConnection)1