Search in sources :

Example 1 with HeartbeatConfig

use of org.mobicents.tools.heartbeat.api.HeartbeatConfig in project load-balancer by RestComm.

the class TcpWorstCaseAffinityTest method setUp.

@Before
public void setUp() throws Exception {
    shootist = new Shootist(ListeningPoint.TCP, 5060);
    balancer = new BalancerRunner();
    LoadBalancerConfiguration lbConfig = new LoadBalancerConfiguration();
    lbConfig.getSipConfiguration().getInternalLegConfiguration().setTcpPort(5065);
    lbConfig.getSipConfiguration().getExternalLegConfiguration().setTcpPort(5060);
    lbConfig.getSipConfiguration().getAlgorithmConfiguration().setAlgorithmClass(WorstCaseUdpTestAffinityAlgorithm.class.getName());
    lbConfig.getSipConfiguration().getAlgorithmConfiguration().setEarlyDialogWorstCase(true);
    HeartbeatConfig rmiConfig = new HeartbeatConfigRmi();
    lbConfig.setHeartbeatConfiguration(rmiConfig);
    balancer.start(lbConfig);
    for (int q = 0; q < servers.length; q++) {
        servers[q] = new AppServerWithRmi("node" + q, 4060 + q, "127.0.0.1", 2000, 5060, 5065, "0", ListeningPoint.TCP);
        servers[q].start();
    }
    Thread.sleep(5000);
}
Also used : HeartbeatConfig(org.mobicents.tools.heartbeat.api.HeartbeatConfig) HeartbeatConfigRmi(org.mobicents.tools.heartbeat.rmi.HeartbeatConfigRmi) AppServerWithRmi(org.mobicents.tools.sip.balancer.AppServerWithRmi) BalancerRunner(org.mobicents.tools.sip.balancer.BalancerRunner) LoadBalancerConfiguration(org.mobicents.tools.configuration.LoadBalancerConfiguration) Shootist(org.mobicents.tools.sip.balancer.operation.Shootist) WorstCaseUdpTestAffinityAlgorithm(org.mobicents.tools.sip.balancer.WorstCaseUdpTestAffinityAlgorithm) ListeningPoint(javax.sip.ListeningPoint) Before(org.junit.Before)

Example 2 with HeartbeatConfig

use of org.mobicents.tools.heartbeat.api.HeartbeatConfig in project load-balancer by RestComm.

the class SipBalancerShutdownHook method start.

public void start(LoadBalancerConfiguration lbConfig) {
    if (statsReporter == null)
        statsReporter = new RestcommStatsReporter();
    String ipAddress = lbConfig.getCommonConfiguration().getHost();
    if (ipAddress == null) {
        ipAddress = lbConfig.getSipConfiguration().getInternalLegConfiguration().getHost();
    }
    if (ipAddress == null) {
        ipAddress = lbConfig.getSipConfiguration().getExternalLegConfiguration().getHost();
    }
    InetAddress addr = null;
    try {
        addr = InetAddress.getByName(ipAddress);
    } catch (UnknownHostException e) {
        logger.error("Couldn't get the InetAddress from the host " + ipAddress, e);
        return;
    }
    balancerContext.securityRequired = lbConfig.getCommonConfiguration().getSecurityRequired();
    if (balancerContext.securityRequired) {
        balancerContext.login = lbConfig.getCommonConfiguration().getLogin();
        balancerContext.password = lbConfig.getCommonConfiguration().getPassword();
    }
    balancerContext.algorithmClassName = lbConfig.getSipConfiguration().getAlgorithmConfiguration().getAlgorithmClass();
    balancerContext.terminateTLSTraffic = lbConfig.getSslConfiguration().getTerminateTLSTraffic();
    balancerContext.smppToProviderAlgorithmClassName = lbConfig.getSmppConfiguration().getSmppToProviderAlgorithmClass();
    if (lbConfig.getSmppConfiguration().isMuxMode())
        balancerContext.smppToNodeAlgorithmClassName = lbConfig.getSmppConfiguration().getSmppToNodeAlgorithmClass();
    balancerContext.shutdownTimeout = lbConfig.getCommonConfiguration().getShutdownTimeout();
    try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        RouterImpl.setRegister(reg);
        reg = new NodeRegisterImpl(addr);
        reg.balancerRunner = this;
        reg.setNodeExpirationTaskInterval(lbConfig.getCommonConfiguration().getHeartbeatInterval());
        reg.setNodeExpiration(lbConfig.getCommonConfiguration().getNodeTimeout());
        if (logger.isInfoEnabled()) {
            logger.info("Node timeout" + " = " + reg.getNodeExpiration());
            logger.info("Heartbeat interval" + " = " + reg.getNodeExpirationTaskInterval());
        }
        if (logger.isDebugEnabled()) {
            logger.debug("LB will use next class for registry nodes : " + lbConfig.getHeartbeatConfigurationClass());
        }
        HeartbeatConfig heartbeatConfig = lbConfig.getHeartbeatConfiguration();
        if (heartbeatConfig == null) {
            logger.warn("Configuration of heartbeat is not set, we will use http heartbeat protocol default values");
            heartbeatConfig = new HeartbeatConfigHttp();
        }
        balancerContext.nodeCommunicationProtocolClassName = heartbeatConfig.getProtocolClassName();
        reg.startRegistry(heartbeatConfig);
        if (logger.isDebugEnabled()) {
            logger.debug("adding shutdown hook");
        }
        String statisticsServer = Version.getVersionProperty(STATISTICS_SERVER);
        if (statisticsServer == null || !statisticsServer.contains("http")) {
            statisticsServer = DEFAULT_STATISTICS_SERVER;
        }
        // define remote server address (optionally)
        statsReporter.setRemoteServer(statisticsServer);
        String projectName = System.getProperty("RestcommProjectName", "loadbalancer");
        String projectType = System.getProperty("RestcommProjectType", "community");
        String projectVersion = System.getProperty("RestcommProjectVersion", Version.getVersionProperty(Version.RELEASE_VERSION));
        if (logger.isDebugEnabled()) {
            logger.debug("Restcomm Stats " + projectName + " " + projectType + " " + projectVersion);
        }
        statsReporter.setProjectName(projectName);
        statsReporter.setProjectType(projectType);
        statsReporter.setVersion(projectVersion);
        // define periodicy - default to once a day
        statsReporter.start(86400, TimeUnit.SECONDS);
        Version.printVersion();
        sipForwarder = new SIPBalancerForwarder(lbConfig, this, reg);
        sipForwarder.start();
        if (lbConfig.getHttpConfiguration().getHttpPort() != null) {
            httpBalancerForwarder = new HttpBalancerForwarder();
            httpBalancerForwarder.balancerRunner = this;
            try {
                httpBalancerForwarder.start();
            } catch (org.jboss.netty.channel.ChannelException e) {
                logger.warn("HTTP forwarder could not be restarted.");
            }
        }
        // register the sip balancer
        ObjectName on = new ObjectName(SIP_BALANCER_JMX_NAME);
        if (server.isRegistered(on)) {
            server.unregisterMBean(on);
        }
        server.registerMBean(this, on);
        shutdownHook = new SipBalancerShutdownHook(this);
        Runtime.getRuntime().addShutdownHook(shutdownHook);
    } catch (Exception e) {
        logger.error("An unexpected error occurred while starting the load balancer", e);
        return;
    }
    if (lbConfig.getSmppConfiguration().getSmppPort() != null) {
        smppBalancerRunner = new SmppBalancerRunner(this);
        smppBalancerRunner.start();
    }
}
Also used : HeartbeatConfig(org.mobicents.tools.heartbeat.api.HeartbeatConfig) HttpBalancerForwarder(org.mobicents.tools.http.balancer.HttpBalancerForwarder) UnknownHostException(java.net.UnknownHostException) UnknownHostException(java.net.UnknownHostException) ObjectName(javax.management.ObjectName) SmppBalancerRunner(org.mobicents.tools.smpp.balancer.core.SmppBalancerRunner) RestcommStatsReporter(org.restcomm.commons.statistics.reporter.RestcommStatsReporter) HeartbeatConfigHttp(org.mobicents.tools.heartbeat.impl.HeartbeatConfigHttp) InetAddress(java.net.InetAddress) MBeanServer(javax.management.MBeanServer)

Example 3 with HeartbeatConfig

use of org.mobicents.tools.heartbeat.api.HeartbeatConfig in project load-balancer by RestComm.

the class NodeGracefulShutdownRmiTest method setUp.

@Before
public void setUp() throws Exception {
    shootist1 = new Shootist(ListeningPoint.TCP, 5060, 5033);
    shootist2 = new Shootist(ListeningPoint.TCP, 5060, 5034);
    balancer = new BalancerRunner();
    LoadBalancerConfiguration lbConfig = new LoadBalancerConfiguration();
    lbConfig.getSipConfiguration().getExternalLegConfiguration().setUdpPort(5060);
    lbConfig.getSipConfiguration().getInternalLegConfiguration().setTcpPort(5065);
    lbConfig.getSipConfiguration().getAlgorithmConfiguration().setAlgorithmClass(UserBasedAlgorithm.class.getCanonicalName());
    lbConfig.getSipConfiguration().getAlgorithmConfiguration().setSipHeaderAffinityKey("To");
    HeartbeatConfig heartbeatConfig = new HeartbeatConfigRmi();
    lbConfig.setHeartbeatConfiguration(heartbeatConfig);
    balancer.start(lbConfig);
    for (int q = 0; q < servers.length; q++) {
        servers[q] = new AppServerWithRmi("node" + q, 4060 + q, "127.0.0.1", 2000, 5060, 5065, "0", ListeningPoint.TCP);
        servers[q].start();
    }
    Thread.sleep(2000);
}
Also used : HeartbeatConfig(org.mobicents.tools.heartbeat.api.HeartbeatConfig) HeartbeatConfigRmi(org.mobicents.tools.heartbeat.rmi.HeartbeatConfigRmi) BalancerRunner(org.mobicents.tools.sip.balancer.BalancerRunner) LoadBalancerConfiguration(org.mobicents.tools.configuration.LoadBalancerConfiguration) Shootist(org.mobicents.tools.sip.balancer.operation.Shootist) ListeningPoint(javax.sip.ListeningPoint) Before(org.junit.Before)

Aggregations

HeartbeatConfig (org.mobicents.tools.heartbeat.api.HeartbeatConfig)3 ListeningPoint (javax.sip.ListeningPoint)2 Before (org.junit.Before)2 LoadBalancerConfiguration (org.mobicents.tools.configuration.LoadBalancerConfiguration)2 HeartbeatConfigRmi (org.mobicents.tools.heartbeat.rmi.HeartbeatConfigRmi)2 BalancerRunner (org.mobicents.tools.sip.balancer.BalancerRunner)2 Shootist (org.mobicents.tools.sip.balancer.operation.Shootist)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 HeartbeatConfigHttp (org.mobicents.tools.heartbeat.impl.HeartbeatConfigHttp)1 HttpBalancerForwarder (org.mobicents.tools.http.balancer.HttpBalancerForwarder)1 AppServerWithRmi (org.mobicents.tools.sip.balancer.AppServerWithRmi)1 WorstCaseUdpTestAffinityAlgorithm (org.mobicents.tools.sip.balancer.WorstCaseUdpTestAffinityAlgorithm)1 SmppBalancerRunner (org.mobicents.tools.smpp.balancer.core.SmppBalancerRunner)1 RestcommStatsReporter (org.restcomm.commons.statistics.reporter.RestcommStatsReporter)1