use of com.nokia.dempsy.config.ClusterDefinition in project Dempsy by Dempsy.
the class TestFullApp method testSeparateClustersInOneVm.
@Test
public void testSeparateClustersInOneVm() throws Throwable {
// now start each cluster
ctx[0] = "fullApp/Dempsy-FullUp.xml";
Map<ClusterId, DempsyHolder> dempsys = new HashMap<ClusterId, DempsyHolder>();
try {
ApplicationDefinition ad = new FullApplication().getTopology();
ad.initialize();
List<ClusterDefinition> clusters = ad.getClusterDefinitions();
for (int i = clusters.size() - 1; i >= 0; i--) {
ClusterDefinition cluster = clusters.get(i);
CheckCluster.toCheckAgainst = cluster.getClusterId();
DempsyHolder cur = new DempsyHolder();
cur.clusterid = cluster.getClusterId();
cur.actx = new ClassPathXmlApplicationContext(ctx);
cur.actx.registerShutdownHook();
cur.dempsy = (Dempsy) cur.actx.getBean("dempsy");
cur.dempsy.start();
dempsys.put(cluster.getClusterId(), cur);
}
// get the last FullApplication in the processing chain.
ClassPathXmlApplicationContext actx = dempsys.get(new ClusterId(FullApplication.class.getSimpleName(), MyRankMp.class.getSimpleName())).actx;
final FullApplication app = (FullApplication) actx.getBean("app");
// this checks that the throughput works.
assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() {
@Override
public boolean conditionMet(Object o) {
return app.finalMessageCount.get() > 100;
}
}));
} finally {
ctx[0] = dempsyConfig;
for (DempsyHolder cur : dempsys.values()) {
cur.dempsy.stop();
cur.actx.close();
}
}
}
use of com.nokia.dempsy.config.ClusterDefinition in project Dempsy by Dempsy.
the class Router method registerOutbound.
@Override
public void registerOutbound(RoutingStrategy.Outbound outbound, Collection<Class<?>> classes) {
synchronized (outbound) {
unregisterOutbound(outbound);
ClusterId clusterId = outbound.getClusterId();
if (classes != null && classes.size() > 0) {
// find the appropriate ClusterDefinition
ClusterDefinition curClusterDef = applicationDefinition.getClusterDefinition(clusterId);
if (curClusterDef != null) {
// create a corresponding ClusterRouter
@SuppressWarnings("unchecked") ClusterRouter clusterRouter = new ClusterRouter((Serializer<Object>) curClusterDef.getSerializer(), outbound);
for (Class<?> clazz : classes) {
// potential
Set<ClusterRouter> cur = Collections.newSetFromMap(new ConcurrentHashMap<ClusterRouter, Boolean>());
Set<ClusterRouter> tmp = routerMap.putIfAbsent(clazz, cur);
if (tmp != null)
cur = tmp;
cur.add(clusterRouter);
}
} else {
logger.error("Couldn't find the ClusterDefinition for " + clusterId + " while registering the Outbound " + SafeString.objectDescription(outbound) + " given the ApplicationDefinition " + applicationDefinition);
}
}
}
}
use of com.nokia.dempsy.config.ClusterDefinition in project Dempsy by Dempsy.
the class Router method initialize.
/**
* Prior to the {@link Router} being used it needs to be initialized.
*/
public void initialize() throws ClusterInfoException, DempsyException {
// applicationDefinition cannot be null because the constructor checks
// put all of the cluster definitions into a map for easy lookup
Map<ClusterId, ClusterDefinition> defs = new HashMap<ClusterId, ClusterDefinition>();
for (ClusterDefinition clusterDef : applicationDefinition.getClusterDefinitions()) defs.put(clusterDef.getClusterId(), clusterDef);
// now see about the one that we are.
ClusterDefinition currentClusterDef = null;
if (currentCluster != null) {
currentClusterDef = defs.get(currentCluster);
if (currentClusterDef == null)
throw new DempsyException("This Dempsy instance seems to be misconfigured. While this VM thinks it's an instance of " + currentCluster + " the application it's configured with doesn't contain this cluster definition. The application configuration consists of: " + applicationDefinition);
}
// get the set of explicit destinations if they exist
Set<ClusterId> explicitClusterDestinations = (currentClusterDef != null && currentClusterDef.hasExplicitDestinations()) ? new HashSet<ClusterId>() : null;
if (explicitClusterDestinations != null)
explicitClusterDestinations.addAll(Arrays.asList(currentClusterDef.getDestinations()));
// then those are the only ones we want to consider
for (ClusterDefinition clusterDef : applicationDefinition.getClusterDefinitions()) {
if ((explicitClusterDestinations == null || explicitClusterDestinations.contains(clusterDef.getClusterId())) && !clusterDef.isRouteAdaptorType()) {
RoutingStrategy strategy = (RoutingStrategy) clusterDef.getRoutingStrategy();
ClusterId clusterId = clusterDef.getClusterId();
if (strategy == null)
throw new DempsyException("Could not retrieve the routing strategy for " + SafeString.valueOf(clusterId));
// This create will result in a callback on the Router as the Outbound.Coordinator with a
// registration event. The Outbound may (will) call back on the Router to retrieve the
// MpClusterSession and register itself with the appropriate cluster.
outbounds.add(strategy.createOutbound(this, mpClusterSession, clusterId));
}
}
//-------------------------------------------------------------------------------------
}
use of com.nokia.dempsy.config.ClusterDefinition in project Dempsy by Dempsy.
the class TestFullApp method testFailover.
@Test
public void testFailover() throws Throwable {
// now start each cluster
ctx[0] = "fullApp/Dempsy-FullUp.xml";
Map<ClusterId, DempsyHolder> dempsys = new HashMap<ClusterId, DempsyHolder>();
DempsyHolder spare = new DempsyHolder();
try {
ApplicationDefinition ad = new FullApplication().getTopology();
ad.initialize();
List<ClusterDefinition> clusters = ad.getClusterDefinitions();
for (int i = clusters.size() - 1; i >= 0; i--) {
ClusterDefinition cluster = clusters.get(i);
CheckCluster.toCheckAgainst = cluster.getClusterId();
DempsyHolder cur = new DempsyHolder();
cur.clusterid = cluster.getClusterId();
cur.actx = new ClassPathXmlApplicationContext(ctx);
cur.actx.registerShutdownHook();
cur.dempsy = (Dempsy) cur.actx.getBean("dempsy");
cur.dempsy.start();
dempsys.put(cluster.getClusterId(), cur);
}
// get the last FullApplication in the processing chain.
ClassPathXmlApplicationContext actx = dempsys.get(new ClusterId(FullApplication.class.getSimpleName(), MyRankMp.class.getSimpleName())).actx;
final FullApplication app = (FullApplication) actx.getBean("app");
// this checks that the throughput works.
assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() {
@Override
public boolean conditionMet(Object o) {
return app.finalMessageCount.get() > 100;
}
}));
// now start another MyMp cluster.
spare = new DempsyHolder();
spare.clusterid = new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName());
CheckCluster.toCheckAgainst = spare.clusterid;
spare.actx = new ClassPathXmlApplicationContext(ctx);
spare.dempsy = (Dempsy) spare.actx.getBean("dempsy");
spare.dempsy.start();
Dempsy.Application.Cluster cluster = spare.dempsy.getCluster(spare.clusterid);
Dempsy.Application.Cluster.Node node = cluster.getNodes().get(0);
final StatsCollector collector = node.getStatsCollector();
// we are going to create another node of the MyMp via a test hack
cluster = spare.dempsy.getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName()));
node = cluster.getNodes().get(0);
final MyMp spareprototype = (MyMp) node.getMpContainer().getPrototype();
// TODO, see if we really need that check, and if so, implement
// an alternate way to get it, since with the stats collector rework
// we no longer use an independent MetricsRegistry per StatsCollector
// instance.
assertEquals(0, ((MetricGetters) collector).getDispatchedMessageCount());
assertEquals(0, spareprototype.myMpReceived.get());
// now bring down the original
DempsyHolder original = dempsys.get(spare.clusterid);
final MyMp originalprototype = (MyMp) original.dempsy.getCluster(spare.clusterid).getNodes().get(0).getMpContainer().getPrototype();
final long originalNumMessages = originalprototype.myMpReceived.get();
// makes sure the message count is still advancing
assertTrue(poll(baseTimeoutMillis, app, new Condition<Object>() {
@Override
public boolean conditionMet(Object o) {
return originalprototype.myMpReceived.get() > originalNumMessages;
}
}));
// check one more time
assertEquals(0, spareprototype.myMpReceived.get());
// now stop the original ... the spare should pick up.
original.dempsy.stop();
// there's a race condition between the stop returning and the last message
// being processed.
// we need to check that a certain amount of time passes during which no more messages have been received.
// if we haven't seen a message in 1/2 second then we
final long numMillisecondsWithoutAMessage = 500;
// will assume that the messages have stopped.
// now we wait until at least numMillisecondsWithoutAMessage goes by without the myMpReceived
// being incremented. This must happen within the baseTimeoutMillis or this check is
// considered failed.
poll(baseTimeoutMillis + numMillisecondsWithoutAMessage, originalprototype, new Condition<Object>() {
long startCheckingTime = System.currentTimeMillis();
long lastMessage = originalprototype.myMpReceived.get();
@Override
public boolean conditionMet(Object o) {
if (originalprototype.myMpReceived.get() != lastMessage) {
startCheckingTime = System.currentTimeMillis();
lastMessage = originalprototype.myMpReceived.get();
return false;
} else
return (System.currentTimeMillis() - startCheckingTime) > numMillisecondsWithoutAMessage;
}
});
// now check to see if the new one picked up.
assertTrue(poll(baseTimeoutMillis, app, new Condition<Object>() {
@Override
public boolean conditionMet(Object o) {
return spareprototype.myMpReceived.get() > 10;
}
}));
} finally {
ctx[0] = dempsyConfig;
for (DempsyHolder cur : dempsys.values()) {
cur.dempsy.stop();
cur.actx.close();
}
if (spare.dempsy != null)
spare.dempsy.stop();
if (spare.actx != null)
spare.actx.close();
}
}
use of com.nokia.dempsy.config.ClusterDefinition in project Dempsy by Dempsy.
the class TestRouterClusterManagement method init.
@Before
public void init() throws Throwable {
onodes = System.setProperty("min_nodes_for_cluster", "1");
oslots = System.setProperty("total_slots_for_cluster", "20");
final ClusterId clusterId = new ClusterId("test", "test-slot");
Destination destination = new Destination() {
};
ApplicationDefinition app = new ApplicationDefinition(clusterId.getApplicationName());
DecentralizedRoutingStrategy strategy = new DecentralizedRoutingStrategy(1, 1);
app.setRoutingStrategy(strategy);
app.setSerializer(new JavaSerializer<Object>());
ClusterDefinition cd = new ClusterDefinition(clusterId.getMpClusterName());
cd.setMessageProcessorPrototype(new GoodTestMp());
app.add(cd);
app.initialize();
LocalClusterSessionFactory mpfactory = new LocalClusterSessionFactory();
ClusterInfoSession session = mpfactory.createSession();
TestUtils.createClusterLevel(clusterId, session);
// fake the inbound side setup
inbound = strategy.createInbound(session, clusterId, new Dempsy() {
public List<Class<?>> gm(ClusterDefinition clusterDef) {
return super.getAcceptedMessages(clusterDef);
}
}.gm(cd), destination, new RoutingStrategy.Inbound.KeyspaceResponsibilityChangeListener() {
@Override
public void keyspaceResponsibilityChanged(Inbound inbound, boolean less, boolean more) {
}
});
routerFactory = new Router(app);
routerFactory.setClusterSession(session);
routerFactory.setCurrentCluster(clusterId);
routerFactory.initialize();
}
Aggregations