brooklyn.entity.nosql.cassandra.CassandraNodeImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brooklyn-software-nosql Show documentation
Show all versions of brooklyn-software-nosql Show documentation
Brooklyn entities for NoSQL data store software entities
/*
* Copyright 2012-2013 by Cloudsoft Corp.
*/
package brooklyn.entity.nosql.cassandra;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import javax.management.ObjectName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import brooklyn.entity.Entity;
import brooklyn.entity.basic.SoftwareProcessImpl;
import brooklyn.event.feed.jmx.JmxAttributePollConfig;
import brooklyn.event.feed.jmx.JmxFeed;
import brooklyn.event.feed.jmx.JmxHelper;
import brooklyn.util.MutableMap;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
/**
* Implementation of {@link CassandraNode}.
*/
public class CassandraNodeImpl extends SoftwareProcessImpl implements CassandraNode {
private static final Logger log = LoggerFactory.getLogger(CassandraNodeImpl.class);
public CassandraNodeImpl() {
this(MutableMap.of(), null);
}
public CassandraNodeImpl(Map, ?> properties) {
this(properties, null);
}
public CassandraNodeImpl(Entity parent) {
this(MutableMap.of(), parent);
}
public CassandraNodeImpl(Map, ?> properties, Entity parent) {
super(properties, parent);
}
public Integer getGossipPort() { return getAttribute(CassandraNode.GOSSIP_PORT); }
public Integer getSslGossipPort() { return getAttribute(CassandraNode.SSL_GOSSIP_PORT); }
public Integer getThriftPort() { return getAttribute(CassandraNode.THRIFT_PORT); }
public String getClusterName() { return getAttribute(CassandraNode.CLUSTER_NAME); }
public Long getToken() { return getAttribute(CassandraNode.TOKEN); }
public String getSeeds() { return getConfig(CassandraNode.SEEDS); }
@Override
public Class getDriverInterface() {
return CassandraNodeDriver.class;
}
private volatile JmxFeed jmxFeed;
private JmxHelper jmxHelper;
private ObjectName storageServiceMBean = JmxHelper.createObjectName("org.apache.cassandra.db:type=StorageService");
private ObjectName readStageMBean = JmxHelper.createObjectName("org.apache.cassandra.request:type=ReadStage");
private ObjectName mutationStageMBean = JmxHelper.createObjectName("org.apache.cassandra.request:type=MutationStage");
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void connectSensors() {
super.connectSensors();
jmxHelper = new JmxHelper(this);
jmxFeed = JmxFeed.builder()
.entity(this)
.period(500, TimeUnit.MILLISECONDS)
.helper(jmxHelper)
.pollAttribute(new JmxAttributePollConfig(SERVICE_UP)
.objectName(storageServiceMBean)
.attributeName("Initialized")
.onSuccess(Functions.forPredicate(Predicates.notNull()))
.onError(Functions.constant(false)))
.pollAttribute(new JmxAttributePollConfig(TOKEN)
.objectName(storageServiceMBean)
.attributeName("TokenToEndpointMap")
.onSuccess((Function) new Function