You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sirona.apache.org by rm...@apache.org on 2013/11/20 09:29:36 UTC
svn commit: r1543732 - in /incubator/sirona/trunk:
agent/store/cube/src/main/java/org/apache/sirona/cube/
agent/store/cube/src/test/java/org/apache/sirona/cube/
core/src/main/java/org/apache/sirona/
core/src/main/java/org/apache/sirona/configuration/io...
Author: rmannibucau
Date: Wed Nov 20 08:29:35 2013
New Revision: 1543732
URL: http://svn.apache.org/r1543732
Log:
SIRONA-4 adding Localhosts utility + cassandra agent stores
Added:
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/util/Localhosts.java
incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/CassandraAgentDataStoreFactory.java
- copied, changed from r1543721, incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/CassandraCollectorDataStoreFactory.java
incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/
incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/counter/
incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/counter/CassandraCounterDataStore.java
incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/gauge/
incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/gauge/CassandraGaugeDataStore.java
incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/status/
incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/status/CassandraStatusDataStore.java
incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/
incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/CounterDataStoreTest.java
incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/GaugeDataStoreTest.java
incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/StatusDataStoreTest.java
Modified:
incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeBuilder.java
incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/CubeDataStoreTest.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/Role.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/configuration/ioc/IoCs.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/counters/DefaultCounter.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/AggregatedCollectorCounter.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/CollectorCounter.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/status/PeriodicNodeStatusDataStore.java
incubator/sirona/trunk/core/src/test/java/org/apache/sirona/status/ValidationTest.java
incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/collector/CassandraSirona.java
incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/collector/counter/CassandraCollectorCounterDataStore.java
Modified: incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeBuilder.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeBuilder.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeBuilder.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeBuilder.java Wed Nov 20 08:29:35 2013
@@ -18,6 +18,7 @@ package org.apache.sirona.cube;
import org.apache.sirona.SironaException;
import org.apache.sirona.configuration.ioc.AutoSet;
+import org.apache.sirona.util.Localhosts;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
@@ -27,14 +28,10 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.xml.bind.DatatypeConverter;
import java.io.FileInputStream;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.security.KeyStore;
@AutoSet
public class CubeBuilder {
- private static final String DEFAULT_MARKER = "sirona";
-
private String proxyHost;
private int proxyPort;
private String collector;
@@ -54,11 +51,7 @@ public class CubeBuilder {
public synchronized Cube build() {
if (marker == null) {
- try {
- marker = InetAddress.getLocalHost().getHostName();
- } catch (final UnknownHostException e) {
- marker = DEFAULT_MARKER;
- }
+ marker = Localhosts.get();
}
if (sslKeyStore != null || sslTrustStore != null) {
Modified: incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/CubeDataStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/CubeDataStoreTest.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/CubeDataStoreTest.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/CubeDataStoreTest.java Wed Nov 20 08:29:35 2013
@@ -16,28 +16,28 @@
*/
package org.apache.sirona.cube;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Locale;
-
import org.apache.sirona.Role;
import org.apache.sirona.counters.Counter;
import org.apache.sirona.gauges.Gauge;
import org.apache.sirona.repositories.Repository;
+import org.apache.sirona.util.Localhosts;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Locale;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
public class CubeDataStoreTest {
private CubeServer server;
private Gauge.LoaderHelper gauges;
@@ -80,7 +80,7 @@ public class CubeDataStoreTest {
Thread.sleep(1500);
}
- final String host = InetAddress.getLocalHost().getHostName();
+ final String host = Localhosts.get();
final Collection<String> messages = server.getMessages();
final Collection<Double> gauges = new ArrayList<Double>(4);
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/Role.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/Role.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/Role.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/Role.java Wed Nov 20 08:29:35 2013
@@ -81,28 +81,21 @@ public class Role implements Comparable<
return false;
}
- Role role = (Role) o;
+ final Role role = Role.class.cast(o);
+ return name.equals(role.name);
- if (!name.equals(role.name)) {
- return false;
- }
-
- return true;
}
/**
* {@inheritDoc}
*/
+ @Override
public int compareTo(final Role o) {
return name.compareTo(o.name);
}
@Override
public String toString() {
- final StringBuilder sb = new StringBuilder("Role{");
- sb.append("name='").append(name).append('\'');
- sb.append(", unit=").append(unit);
- sb.append('}');
- return sb.toString();
+ return "Role{" + "name='" + name + '\'' + ", unit=" + unit + '}';
}
}
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/configuration/ioc/IoCs.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/configuration/ioc/IoCs.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/configuration/ioc/IoCs.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/configuration/ioc/IoCs.java Wed Nov 20 08:29:35 2013
@@ -101,27 +101,35 @@ public final class IoCs {
private static <T> T internalProcessInstance(final T instance) throws IllegalAccessException, InvocationTargetException {
final Class<?> loadedClass = instance.getClass();
- for (final Method m : loadedClass.getMethods()) {
- if (m.getAnnotation(Created.class) != null) {
- m.invoke(instance);
- } else if (m.getAnnotation(Destroying.class) != null) {
- if (shutdownHook == null == Configuration.is(Configuration.CONFIG_PROPERTY_PREFIX + "shutdown.hook", true)) {
- shutdownHook = new Thread() {
- @Override
- public void run() {
- shutdown();
- }
- };
- Runtime.getRuntime().addShutdownHook(shutdownHook);
- }
- INSTANCES.add(new ToDestroy(m, instance));
- }
- }
+ // autoset before invoking @Created
if (loadedClass.getAnnotation(AutoSet.class) != null) {
autoSet(instance, loadedClass);
}
+ Class<?> clazz = loadedClass;
+ while (clazz != null && !Object.class.equals(clazz)) {
+ for (final Method m : clazz.getDeclaredMethods()) {
+ if (m.getAnnotation(Created.class) != null) {
+ m.setAccessible(true);
+ m.invoke(instance);
+ } else if (m.getAnnotation(Destroying.class) != null) {
+ m.setAccessible(true);
+ if (shutdownHook == null == Configuration.is(Configuration.CONFIG_PROPERTY_PREFIX + "shutdown.hook", true)) {
+ shutdownHook = new Thread() {
+ @Override
+ public void run() {
+ shutdown();
+ }
+ };
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ }
+ INSTANCES.add(new ToDestroy(m, instance));
+ }
+ }
+ clazz = clazz.getSuperclass();
+ }
+
return instance;
}
@@ -181,6 +189,9 @@ public final class IoCs {
if (long.class.equals(type)) {
return Long.parseLong(value);
}
+ if (boolean.class.equals(type)) {
+ return Boolean.parseBoolean(value);
+ }
throw new IllegalArgumentException("Type " + type.getName() + " not supported");
}
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/counters/DefaultCounter.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/counters/DefaultCounter.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/counters/DefaultCounter.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/counters/DefaultCounter.java Wed Nov 20 08:29:35 2013
@@ -203,4 +203,22 @@ public class DefaultCounter implements C
", statistics=" + statistics +
'}';
}
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!Counter.class.isInstance(o)) {
+ return false;
+ }
+
+ final Counter that = Counter.class.cast(o);
+ return key.equals(that.getKey());
+ }
+
+ @Override
+ public int hashCode() {
+ return key.hashCode();
+ }
}
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java Wed Nov 20 08:29:35 2013
@@ -47,7 +47,7 @@ public class GaugeDataStoreAdapter imple
@Override
public Collection<Role> gauges() {
- return Collections.emptyList();
+ return gauges.keySet();
}
@Override
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/AggregatedCollectorCounter.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/AggregatedCollectorCounter.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/AggregatedCollectorCounter.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/AggregatedCollectorCounter.java Wed Nov 20 08:29:35 2013
@@ -29,7 +29,7 @@ import java.util.concurrent.locks.Lock;
public class AggregatedCollectorCounter extends CollectorCounter implements AggregatedCounter {
private final ConcurrentMap<String, LeafCollectorCounter> aggregation = new ConcurrentHashMap<String, LeafCollectorCounter>(50);
- public AggregatedCollectorCounter(Key key) {
+ public AggregatedCollectorCounter(final Key key) {
super(key);
}
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/CollectorCounter.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/CollectorCounter.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/CollectorCounter.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/CollectorCounter.java Wed Nov 20 08:29:35 2013
@@ -180,4 +180,22 @@ public abstract class CollectorCounter i
workLock.unlock();
}
}
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!Counter.class.isInstance(o)) {
+ return false;
+ }
+
+ final Counter that = Counter.class.cast(o);
+ return key.equals(that.getKey());
+ }
+
+ @Override
+ public int hashCode() {
+ return key.hashCode();
+ }
}
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/status/PeriodicNodeStatusDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/status/PeriodicNodeStatusDataStore.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/status/PeriodicNodeStatusDataStore.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/status/PeriodicNodeStatusDataStore.java Wed Nov 20 08:29:35 2013
@@ -17,6 +17,7 @@
package org.apache.sirona.store.status;
import org.apache.sirona.configuration.Configuration;
+import org.apache.sirona.configuration.ioc.Created;
import org.apache.sirona.configuration.ioc.Destroying;
import org.apache.sirona.status.NodeStatus;
import org.apache.sirona.status.NodeStatusReporter;
@@ -38,15 +39,23 @@ public class PeriodicNodeStatusDataStore
private static final Logger LOGGER = Logger.getLogger(PeriodicNodeStatusDataStore.class.getName());
private final AtomicReference<BatchFuture> scheduledTask = new AtomicReference<BatchFuture>();
- private final AtomicReference<NodeStatus> status = new AtomicReference<NodeStatus>();
- private final HashMap<String, NodeStatus> statusAsMap = new HashMap<String, NodeStatus>();
- private final NodeStatusReporter nodeStatusReporter;
+ protected final AtomicReference<NodeStatus> status = new AtomicReference<NodeStatus>();
+ protected final HashMap<String, NodeStatus> statusAsMap = new HashMap<String, NodeStatus>();
+ protected final NodeStatusReporter nodeStatusReporter;
public PeriodicNodeStatusDataStore() {
- nodeStatusReporter = new NodeStatusReporter();
+ nodeStatusReporter = newNodeStatusReporter();
+ }
+
+ @Created
+ public void run() {
reload();
}
+ protected NodeStatusReporter newNodeStatusReporter() {
+ return new NodeStatusReporter();
+ }
+
@Destroying
public void shutdown() {
final BatchFuture task = scheduledTask.get();
Added: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/util/Localhosts.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/util/Localhosts.java?rev=1543732&view=auto
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/util/Localhosts.java (added)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/util/Localhosts.java Wed Nov 20 08:29:35 2013
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.util;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class Localhosts {
+ private static final String value;
+ static {
+ String tmp;
+ try {
+ tmp = InetAddress.getLocalHost().getHostName();
+ } catch (final UnknownHostException e) {
+ tmp = "sirona"; // default
+ }
+ value = tmp;
+ }
+
+ private Localhosts() {
+ // no-op
+ }
+
+ public static String get() {
+ return value;
+ }
+}
Modified: incubator/sirona/trunk/core/src/test/java/org/apache/sirona/status/ValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/test/java/org/apache/sirona/status/ValidationTest.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/test/java/org/apache/sirona/status/ValidationTest.java (original)
+++ incubator/sirona/trunk/core/src/test/java/org/apache/sirona/status/ValidationTest.java Wed Nov 20 08:29:35 2013
@@ -16,6 +16,7 @@
*/
package org.apache.sirona.status;
+import org.apache.sirona.configuration.ioc.IoCs;
import org.apache.sirona.spi.SpiTestImpl;
import org.apache.sirona.store.status.PeriodicNodeStatusDataStore;
import org.junit.Test;
@@ -37,12 +38,12 @@ public class ValidationTest {
@Test
public void periodicNodeReporter() throws InterruptedException {
- final PeriodicNodeStatusDataStore store = new PeriodicNodeStatusDataStore() {
+ final PeriodicNodeStatusDataStore store = IoCs.processInstance(new PeriodicNodeStatusDataStore() {
@Override
protected int getPeriod(final String name) {
return 100;
}
- };
+ });
Thread.sleep(200);
assertEquals(Status.OK, store.statuses().values().iterator().next().getStatus());
Copied: incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/CassandraAgentDataStoreFactory.java (from r1543721, incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/CassandraCollectorDataStoreFactory.java)
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/CassandraAgentDataStoreFactory.java?p2=incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/CassandraAgentDataStoreFactory.java&p1=incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/CassandraCollectorDataStoreFactory.java&r1=1543721&r2=1543732&rev=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/CassandraCollectorDataStoreFactory.java (original)
+++ incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/CassandraAgentDataStoreFactory.java Wed Nov 20 08:29:35 2013
@@ -16,13 +16,17 @@
*/
package org.apache.sirona.cassandra;
-import org.apache.sirona.cassandra.collector.counter.CassandraCollectorCounterDataStore;
-import org.apache.sirona.cassandra.collector.gauge.CassandraCollectorGaugeDataStore;
-import org.apache.sirona.cassandra.collector.status.CassandraCollectorNodeStatusDataStore;
+import org.apache.sirona.cassandra.agent.counter.CassandraCounterDataStore;
+import org.apache.sirona.cassandra.agent.gauge.CassandraGaugeDataStore;
+import org.apache.sirona.cassandra.agent.status.CassandraStatusDataStore;
+import org.apache.sirona.configuration.ioc.IoCs;
import org.apache.sirona.store.DelegateDataStoreFactory;
-public class CassandraCollectorDataStoreFactory extends DelegateDataStoreFactory {
- public CassandraCollectorDataStoreFactory() {
- super(new CassandraCollectorCounterDataStore(), new CassandraCollectorGaugeDataStore(), new CassandraCollectorNodeStatusDataStore());
+public class CassandraAgentDataStoreFactory extends DelegateDataStoreFactory {
+ public CassandraAgentDataStoreFactory() {
+ super(
+ IoCs.processInstance(new CassandraCounterDataStore()),
+ IoCs.processInstance(new CassandraGaugeDataStore()),
+ IoCs.processInstance(new CassandraStatusDataStore()));
}
}
Added: incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/counter/CassandraCounterDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/counter/CassandraCounterDataStore.java?rev=1543732&view=auto
==============================================================================
--- incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/counter/CassandraCounterDataStore.java (added)
+++ incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/counter/CassandraCounterDataStore.java Wed Nov 20 08:29:35 2013
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.cassandra.agent.counter;
+
+import org.apache.sirona.cassandra.collector.counter.CassandraCollectorCounterDataStore;
+import org.apache.sirona.configuration.ioc.AutoSet;
+import org.apache.sirona.configuration.ioc.Created;
+import org.apache.sirona.counters.Counter;
+import org.apache.sirona.math.M2AwareStatisticalSummary;
+import org.apache.sirona.store.counter.BatchCounterDataStore;
+import org.apache.sirona.util.Localhosts;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+@AutoSet // for marker
+public class CassandraCounterDataStore extends BatchCounterDataStore {
+ private final CassandraCollectorCounterDataStore delegate = new CassandraCollectorCounterDataStore();
+ protected String marker;
+ protected boolean readFromStore = true;
+
+ @Created
+ protected void initMarkerIfNotAlreadyDone() {
+ if (marker == null) {
+ marker = Localhosts.get();
+ }
+ }
+
+ @Override
+ protected void pushCountersByBatch(final Collection<Counter> instances) {
+ for (final Counter counter : instances) {
+ delegate.getOrCreateCounter(counter.getKey(), marker)
+ .update(new M2AwareStatisticalSummary(
+ counter.getMean(), counter.getVariance(), counter.getHits(),
+ counter.getMax(), counter.getMin(), counter.getSum(), counter.getSecondMoment()),
+ counter.currentConcurrency().get());
+ }
+ }
+
+ @Override
+ public Collection<Counter> getCounters() {
+ final Collection<Counter> all = new HashSet<Counter>();
+ if (readFromStore) {
+ all.addAll(delegate.getCounters());
+ }
+ all.addAll(super.getCounters()); // override by more recent ones
+ return all;
+ }
+}
Added: incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/gauge/CassandraGaugeDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/gauge/CassandraGaugeDataStore.java?rev=1543732&view=auto
==============================================================================
--- incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/gauge/CassandraGaugeDataStore.java (added)
+++ incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/gauge/CassandraGaugeDataStore.java Wed Nov 20 08:29:35 2013
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.cassandra.agent.gauge;
+
+import org.apache.sirona.Role;
+import org.apache.sirona.cassandra.collector.gauge.CassandraCollectorGaugeDataStore;
+import org.apache.sirona.configuration.ioc.AutoSet;
+import org.apache.sirona.configuration.ioc.Created;
+import org.apache.sirona.store.gauge.BatchGaugeDataStoreAdapter;
+import org.apache.sirona.store.gauge.GaugeValuesRequest;
+import org.apache.sirona.util.Localhosts;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.SortedMap;
+
+@AutoSet
+public class CassandraGaugeDataStore extends BatchGaugeDataStoreAdapter {
+ private final CassandraCollectorGaugeDataStore delegate = new CassandraCollectorGaugeDataStore();
+ protected String marker;
+ protected boolean readFromStore = true;
+
+ @Created
+ protected void initMarkerIfNeeded() {
+ if (marker == null) {
+ marker = Localhosts.get();
+ }
+ }
+
+ @Override
+ protected void pushGauges(final Map<Role, Measure> gauges) {
+ for (final Map.Entry<Role, Measure> entry : gauges.entrySet()) {
+ final Role role = entry.getKey();
+ final Measure measure = entry.getValue();
+
+ delegate.createOrNoopGauge(role, marker);
+ delegate.addToGauge(role, measure.getTime(), measure.getValue(), marker);
+ }
+ }
+
+ @Override
+ public SortedMap<Long, Double> getGaugeValues(final GaugeValuesRequest gaugeValuesRequest) {
+ return delegate.getGaugeValues(gaugeValuesRequest, marker);
+ }
+
+ @Override
+ public Collection<Role> gauges() {
+ final Collection<Role> all = new HashSet<Role>();
+ if (readFromStore) {
+ all.addAll(delegate.gauges());
+ }
+ all.addAll(super.gauges()); // override by more recent ones
+ return all;
+ }
+}
Added: incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/status/CassandraStatusDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/status/CassandraStatusDataStore.java?rev=1543732&view=auto
==============================================================================
--- incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/status/CassandraStatusDataStore.java (added)
+++ incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/agent/status/CassandraStatusDataStore.java Wed Nov 20 08:29:35 2013
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.cassandra.agent.status;
+
+import org.apache.sirona.cassandra.collector.status.CassandraCollectorNodeStatusDataStore;
+import org.apache.sirona.configuration.ioc.AutoSet;
+import org.apache.sirona.configuration.ioc.Created;
+import org.apache.sirona.status.NodeStatus;
+import org.apache.sirona.store.status.PeriodicNodeStatusDataStore;
+import org.apache.sirona.util.Localhosts;
+
+import java.util.Map;
+
+@AutoSet
+public class CassandraStatusDataStore extends PeriodicNodeStatusDataStore {
+ private final CassandraCollectorNodeStatusDataStore delegate = new CassandraCollectorNodeStatusDataStore();
+ protected String marker;
+ protected boolean readFromStore = true;
+
+ @Created
+ protected void initMarkerIfNeeded() {
+ if (marker == null) {
+ marker = Localhosts.get();
+ }
+ }
+
+ @Override
+ protected void reportStatus(final NodeStatus nodeStatus) {
+ delegate.store(marker, nodeStatus);
+ }
+
+ @Override
+ public Map<String, NodeStatus> statuses() {
+ final NodeStatus localStatus = status.get();
+ if (readFromStore) {
+ final Map<String, NodeStatus> statuses = delegate.statuses();
+ if (localStatus == null) {
+ return statuses;
+ }
+ statuses.put(marker, localStatus);
+ return statuses;
+ }
+ return super.statuses();
+ }
+}
Modified: incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/collector/CassandraSirona.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/collector/CassandraSirona.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/collector/CassandraSirona.java (original)
+++ incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/collector/CassandraSirona.java Wed Nov 20 08:29:35 2013
@@ -18,7 +18,6 @@ package org.apache.sirona.cassandra.coll
import me.prettyprint.cassandra.model.ConfigurableConsistencyLevel;
import me.prettyprint.cassandra.serializers.SerializerTypeInferer;
-import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.cassandra.service.StringKeyIterator;
import me.prettyprint.cassandra.service.ThriftKsDef;
@@ -26,13 +25,10 @@ import me.prettyprint.hector.api.Cluster
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.Serializer;
import me.prettyprint.hector.api.beans.HColumn;
-import me.prettyprint.hector.api.beans.OrderedRows;
-import me.prettyprint.hector.api.beans.Row;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.ComparatorType;
import me.prettyprint.hector.api.factory.HFactory;
import org.apache.sirona.cassandra.CassandraBuilder;
-import org.apache.sirona.cassandra.DynamicDelegatedSerializer;
import org.apache.sirona.configuration.ioc.Destroying;
import org.apache.sirona.configuration.ioc.IoCs;
Modified: incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/collector/counter/CassandraCollectorCounterDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/collector/counter/CassandraCollectorCounterDataStore.java?rev=1543732&r1=1543731&r2=1543732&view=diff
==============================================================================
--- incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/collector/counter/CassandraCollectorCounterDataStore.java (original)
+++ incubator/sirona/trunk/server/store/cassandra/src/main/java/org/apache/sirona/cassandra/collector/counter/CassandraCollectorCounterDataStore.java Wed Nov 20 08:29:35 2013
@@ -199,6 +199,10 @@ public class CassandraCollectorCounterDa
return cassandra.generateKey(key.getRole().getName(), key.getRole().getUnit().getName(), key.getName(), marker);
}
+ public CassandraSirona getCassandra() {
+ return cassandra;
+ }
+
protected static Number getOrDefault(final DynamicDelegatedSerializer delegatedSerializer, final HColumn<?, ?> col, final Serializer<?> serializer) {
delegatedSerializer.setDelegate(serializer);
if (col == null || col.getValue() == null) {
Added: incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/CounterDataStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/CounterDataStoreTest.java?rev=1543732&view=auto
==============================================================================
--- incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/CounterDataStoreTest.java (added)
+++ incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/CounterDataStoreTest.java Wed Nov 20 08:29:35 2013
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.cassandra.local;
+
+import org.apache.sirona.Role;
+import org.apache.sirona.cassandra.agent.counter.CassandraCounterDataStore;
+import org.apache.sirona.cassandra.framework.CassandraRunner;
+import org.apache.sirona.counters.Counter;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Collection;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(CassandraRunner.class)
+public class CounterDataStoreTest {
+ @Test
+ public void getCounters() throws InterruptedException {
+ final CassandraCounterDataStore store = new CassandraCounterDataStore() {
+ protected void initMarkerIfNotAlreadyDone() {
+ marker = "test";
+ }
+
+ @Override
+ protected int getPeriod(final String prefix) {
+ return 100;
+ }
+ };
+
+ assertEquals(0, store.getCounters().size());
+
+ final Counter counter = store.getOrCreateCounter(new Counter.Key(Role.FAILURES, "oops"));
+ counter.add(150);
+ counter.updateConcurrency(5);
+
+ Thread.sleep(250);
+
+ final Collection<Counter> counters = store.getCounters();
+ assertEquals(1, counters.size());
+
+ final Counter c = counters.iterator().next();
+ assertEquals(counter, c); // compare only key
+ assertEquals(5, c.getMaxConcurrency());
+ assertEquals(150., c.getMax(), 0.);
+ assertEquals(1, c.getHits());
+ }
+}
Added: incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/GaugeDataStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/GaugeDataStoreTest.java?rev=1543732&view=auto
==============================================================================
--- incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/GaugeDataStoreTest.java (added)
+++ incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/GaugeDataStoreTest.java Wed Nov 20 08:29:35 2013
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.cassandra.local;
+
+import org.apache.sirona.Role;
+import org.apache.sirona.cassandra.agent.counter.CassandraCounterDataStore;
+import org.apache.sirona.cassandra.agent.gauge.CassandraGaugeDataStore;
+import org.apache.sirona.cassandra.framework.CassandraRunner;
+import org.apache.sirona.configuration.ioc.Created;
+import org.apache.sirona.configuration.ioc.IoCs;
+import org.apache.sirona.counters.Counter;
+import org.apache.sirona.gauges.Gauge;
+import org.apache.sirona.repositories.Repository;
+import org.apache.sirona.store.gauge.GaugeValuesRequest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Collection;
+import java.util.SortedMap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(CassandraRunner.class)
+public class GaugeDataStoreTest {
+ @Test
+ public void gauges() throws InterruptedException, IllegalAccessException {
+ final CassandraGaugeDataStore store = IoCs.processInstance(new CassandraGaugeDataStore() {
+ @Created
+ protected void forceMarker() {
+ marker = "test";
+ }
+
+ @Override
+ protected int getPeriod(final String prefix) {
+ return 100;
+ }
+ });
+
+ assertEquals(0, store.gauges().size());
+
+ final Gauge gauge = new Gauge() {
+ @Override
+ public Role role() {
+ return Role.FAILURES;
+ }
+
+ @Override
+ public double value() {
+ return 5;
+ }
+ };
+ store.createOrNoopGauge(gauge.role());
+ store.addGauge(gauge);
+
+ Thread.sleep(250);
+ store.shutdown();
+
+ final Collection<Role> gauges = store.gauges();
+ assertEquals(1, gauges.size());
+
+ assertEquals(gauge.role(), gauges.iterator().next());
+ final SortedMap<Long,Double> gaugeValues = store.getGaugeValues(new GaugeValuesRequest(0, System.currentTimeMillis(), Role.FAILURES));
+ assertTrue(gaugeValues.size() > 0);
+ assertEquals(5., gaugeValues.values().iterator().next(), 0.);
+
+ store.gaugeStopped(gauge.role());
+ }
+}
Added: incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/StatusDataStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/StatusDataStoreTest.java?rev=1543732&view=auto
==============================================================================
--- incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/StatusDataStoreTest.java (added)
+++ incubator/sirona/trunk/server/store/cassandra/src/test/java/org/apache/sirona/cassandra/local/StatusDataStoreTest.java Wed Nov 20 08:29:35 2013
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.cassandra.local;
+
+import org.apache.sirona.cassandra.agent.status.CassandraStatusDataStore;
+import org.apache.sirona.cassandra.framework.CassandraRunner;
+import org.apache.sirona.configuration.ioc.Created;
+import org.apache.sirona.configuration.ioc.IoCs;
+import org.apache.sirona.status.NodeStatus;
+import org.apache.sirona.status.NodeStatusReporter;
+import org.apache.sirona.status.Status;
+import org.apache.sirona.status.ValidationResult;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Date;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(CassandraRunner.class)
+public class StatusDataStoreTest {
+ @Test
+ public void statuses() throws InterruptedException, IllegalAccessException {
+ final CassandraStatusDataStore store = IoCs.processInstance(new CassandraStatusDataStore() {
+ @Created
+ protected void forceMarker() {
+ marker = "test";
+ }
+
+ @Override
+ protected NodeStatusReporter newNodeStatusReporter() {
+ return new NodeStatusReporter() {
+ @Override
+ public synchronized NodeStatus computeStatus() {
+ return new NodeStatus(new ValidationResult[]{new ValidationResult("sample", Status.OK, "msg")}, new Date());
+ }
+ };
+ }
+
+ @Override
+ protected int getPeriod(final String prefix) {
+ return 100;
+ }
+ });
+
+ assertEquals(0, store.statuses().size());
+
+ Thread.sleep(250);
+ store.shutdown();
+
+ final Map<String,NodeStatus> statuses = store.statuses();
+ assertEquals(1, statuses.size());
+ assertTrue(statuses.containsKey("test"));
+
+ final ValidationResult[] results = statuses.get("test").getResults();
+ assertEquals(1, results.length);
+
+ final ValidationResult validationResult = results[0];
+ assertEquals("sample", validationResult.getName());
+ assertEquals("msg", validationResult.getMessage());
+ assertEquals(Status.OK, validationResult.getStatus());
+ }
+}