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);
}
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();
}
}
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);
}
Aggregations