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/06 18:27:27 UTC
svn commit: r1539405 - in /incubator/sirona/trunk: ./ agent/ agent/pull/
agent/pull/src/ agent/pull/src/main/ agent/pull/src/main/java/
agent/pull/src/main/java/org/ agent/pull/src/main/java/org/apache/
agent/pull/src/main/java/org/apache/sirona/ agent...
Author: rmannibucau
Date: Wed Nov 6 17:27:26 2013
New Revision: 1539405
URL: http://svn.apache.org/r1539405
Log:
basic agent for pulling (in webapps) - need timers on collector + a way to register an agent + doc
Added:
incubator/sirona/trunk/agent/pull/
incubator/sirona/trunk/agent/pull/pom.xml
incubator/sirona/trunk/agent/pull/src/
incubator/sirona/trunk/agent/pull/src/main/
incubator/sirona/trunk/agent/pull/src/main/java/
incubator/sirona/trunk/agent/pull/src/main/java/org/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/gauge/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/gauge/PullGaugeManager.java
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/registration/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/registration/SironaPullAgentRegistration.java
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/servlet/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/servlet/PullServlet.java
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/store/
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/store/PullDataStoreFactory.java
incubator/sirona/trunk/agent/pull/src/main/resources/
incubator/sirona/trunk/agent/pull/src/main/resources/META-INF/
incubator/sirona/trunk/agent/pull/src/main/resources/META-INF/services/
incubator/sirona/trunk/agent/pull/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer
incubator/sirona/trunk/agent/pull/src/test/
incubator/sirona/trunk/agent/pull/src/test/java/
incubator/sirona/trunk/agent/pull/src/test/java/org/
incubator/sirona/trunk/agent/pull/src/test/java/org/apache/
incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/
incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/
incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/
incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/
incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/PullAnswerTest.java
incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/
incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/FakeValidation.java
incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/ReFakeValidation.java
incubator/sirona/trunk/agent/pull/src/test/resources/
incubator/sirona/trunk/agent/pull/src/test/resources/META-INF/
incubator/sirona/trunk/agent/pull/src/test/resources/META-INF/services/
incubator/sirona/trunk/agent/pull/src/test/resources/META-INF/services/org.apache.sirona.status.Validation
incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java
- copied, changed from r1539369, incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java
incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java
- copied, changed from r1539369, incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java
- copied, changed from r1539369, incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/RemoteGaugeDataStore.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java
- copied, changed from r1539369, incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStore.java
Removed:
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/RemoteGaugeDataStore.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStore.java
Modified:
incubator/sirona/trunk/agent/pom.xml
incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/Cube.java
incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeCounterDataStore.java
incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeNodeStatusDataStore.java
incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteDataStoreFactory.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/Gauge.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeManager.java
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/repositories/DefaultRepository.java
incubator/sirona/trunk/pom.xml
incubator/sirona/trunk/server/collector/src/main/java/org/apache/sirona/collector/server/Collector.java
incubator/sirona/trunk/src/site/markdown/configuration.md
Modified: incubator/sirona/trunk/agent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pom.xml?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/pom.xml (original)
+++ incubator/sirona/trunk/agent/pom.xml Wed Nov 6 17:27:26 2013
@@ -33,5 +33,6 @@
<modules>
<module>performance</module>
<module>store</module>
+ <module>pull</module>
</modules>
</project>
Added: incubator/sirona/trunk/agent/pull/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/pom.xml?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/pom.xml (added)
+++ incubator/sirona/trunk/agent/pull/pom.xml Wed Nov 6 17:27:26 2013
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>sirona-agent</artifactId>
+ <groupId>org.apache.sirona</groupId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>sirona-pull</artifactId>
+ <name>Apache Sirona Incubator :: Agent :: Pull</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-servlet_3.0_spec</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.sirona</groupId>
+ <artifactId>sirona-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sirona</groupId>
+ <artifactId>sirona-cube</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.json-lib</groupId>
+ <artifactId>json-lib</artifactId>
+ <version>2.4</version>
+ <classifier>jdk15</classifier>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/gauge/PullGaugeManager.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/gauge/PullGaugeManager.java?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/gauge/PullGaugeManager.java (added)
+++ incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/gauge/PullGaugeManager.java Wed Nov 6 17:27:26 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.agent.webapp.pull.gauge;
+
+import org.apache.sirona.gauges.Gauge;
+import org.apache.sirona.gauges.GaugeManager;
+
+import java.util.Collection;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+public class PullGaugeManager implements GaugeManager {
+ private final Collection<Gauge> gauges = new CopyOnWriteArrayList<Gauge>();
+
+ @Override
+ public void stop() {
+ gauges.clear();
+ }
+
+ @Override
+ public void addGauge(final Gauge gauge) {
+ gauges.add(gauge);
+ }
+
+ @Override
+ public void stopGauge(final Gauge gauge) {
+ gauges.remove(gauge);
+ }
+
+ public Collection<Gauge> getGauges() {
+ return gauges;
+ }
+}
Added: incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/registration/SironaPullAgentRegistration.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/registration/SironaPullAgentRegistration.java?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/registration/SironaPullAgentRegistration.java (added)
+++ incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/registration/SironaPullAgentRegistration.java Wed Nov 6 17:27:26 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.agent.webapp.pull.registration;
+
+import org.apache.sirona.agent.webapp.pull.servlet.PullServlet;
+import org.apache.sirona.configuration.Configuration;
+
+import javax.servlet.ServletContainerInitializer;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRegistration;
+import java.util.Set;
+
+public class SironaPullAgentRegistration implements ServletContainerInitializer {
+ private static final String DEFAULT_MAPPING = "/sirona/pull";
+
+ @Override
+ public void onStartup(final Set<Class<?>> classes, final ServletContext ctx) throws ServletException {
+ final ServletRegistration.Dynamic dynamic = ctx.addServlet("Sirona Pull Agent", PullServlet.class.getName());
+ dynamic.setLoadOnStartup(1);
+ dynamic.addMapping(Configuration.getProperty(Configuration.CONFIG_PROPERTY_PREFIX + "agent.pull.mapping", DEFAULT_MAPPING));
+ }
+}
Added: incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java (added)
+++ incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java Wed Nov 6 17:27:26 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.agent.webapp.pull.repository;
+
+import org.apache.sirona.agent.webapp.pull.gauge.PullGaugeManager;
+import org.apache.sirona.configuration.Configuration;
+import org.apache.sirona.cube.Cube;
+import org.apache.sirona.cube.CubeBuilder;
+import org.apache.sirona.gauges.Gauge;
+import org.apache.sirona.gauges.GaugeDataStoreAdapter;
+import org.apache.sirona.gauges.GaugeManager;
+import org.apache.sirona.repositories.DefaultRepository;
+import org.apache.sirona.repositories.Repository;
+import org.apache.sirona.status.NodeStatus;
+import org.apache.sirona.status.NodeStatusReporter;
+import org.apache.sirona.store.counter.InMemoryCounterDataStore;
+import org.apache.sirona.store.status.EmptyStatuses;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class PullRepository extends DefaultRepository {
+ private static final char START_ARRAY = '[';
+ private static final char END_ARRAY = ']';
+
+ private final Cube cube;
+
+ public PullRepository() {
+ super(new InMemoryCounterDataStore(), new GaugeDataStoreAdapter(), new EmptyStatuses());
+ cube = Configuration.findOrCreateInstance(CubeBuilder.class).build();
+ }
+
+ @Override
+ protected GaugeManager findGaugeManager() {
+ return new PullGaugeManager();
+ }
+
+ public Collection<Gauge> getGauges() {
+ if (gaugeManager == null) {
+ return Collections.emptyList();
+ }
+ return PullGaugeManager.class.cast(gaugeManager).getGauges();
+ }
+
+ public String snapshot() {
+ final long time = System.currentTimeMillis();
+
+ final StringBuilder answer = cube.newEventStream();
+
+ // counters
+ answer.append(cube.counterSnapshot(Repository.INSTANCE.counters()));
+
+ // gauges
+ for (final Gauge g : getGauges()) {
+ answer.append(cube.gaugeSnapshot(time, g.role(), g.value()));
+ }
+
+ // status
+ final NodeStatus status = new NodeStatusReporter().computeStatus();
+ answer.append(cube.statusSnapshot(time, status));
+
+ // remove last ','
+ if (answer.length() == 0) {
+ return Character.toString(START_ARRAY) + END_ARRAY;
+ }
+ answer.setLength(answer.length() - 1);
+ return START_ARRAY + answer.toString() + END_ARRAY;
+ }
+}
Added: incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/servlet/PullServlet.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/servlet/PullServlet.java?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/servlet/PullServlet.java (added)
+++ incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/servlet/PullServlet.java Wed Nov 6 17:27:26 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.agent.webapp.pull.servlet;
+
+import org.apache.sirona.agent.webapp.pull.repository.PullRepository;
+import org.apache.sirona.repositories.Repository;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class PullServlet extends HttpServlet {
+ private static final String APPLICATION_JSON = "application/json";
+
+ private PullRepository repository;
+
+ @Override
+ public void init() throws ServletException {
+ repository = PullRepository.class.cast(Repository.INSTANCE);
+ }
+
+ @Override
+ protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
+ resp.setContentType(APPLICATION_JSON);
+ resp.getWriter().write(repository.snapshot());
+ }
+}
Added: incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/store/PullDataStoreFactory.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/store/PullDataStoreFactory.java?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/store/PullDataStoreFactory.java (added)
+++ incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/store/PullDataStoreFactory.java Wed Nov 6 17:27:26 2013
@@ -0,0 +1,28 @@
+/*
+ * 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.agent.webapp.pull.store;
+
+import org.apache.sirona.store.DelegateDataStoreFactory;
+import org.apache.sirona.store.counter.InMemoryCounterDataStore;
+import org.apache.sirona.store.gauge.InMemoryGaugeDataStore;
+import org.apache.sirona.store.status.EmptyStatuses;
+
+public class PullDataStoreFactory extends DelegateDataStoreFactory {
+ public PullDataStoreFactory() {
+ super(new InMemoryCounterDataStore(), new InMemoryGaugeDataStore(), new EmptyStatuses());
+ }
+}
Added: incubator/sirona/trunk/agent/pull/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer (added)
+++ incubator/sirona/trunk/agent/pull/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer Wed Nov 6 17:27:26 2013
@@ -0,0 +1 @@
+org.apache.sirona.agent.webapp.pull.registration.SironaPullAgentRegistration
Added: incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/PullAnswerTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/PullAnswerTest.java?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/PullAnswerTest.java (added)
+++ incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/PullAnswerTest.java Wed Nov 6 17:27:26 2013
@@ -0,0 +1,94 @@
+/*
+ * 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.agent.webapp.pull;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+import net.sf.json.JSONSerializer;
+import org.apache.sirona.Role;
+import org.apache.sirona.agent.webapp.pull.repository.PullRepository;
+import org.apache.sirona.counters.Counter;
+import org.apache.sirona.counters.Unit;
+import org.apache.sirona.gauges.Gauge;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+public class PullAnswerTest {
+ @Test
+ public void json() {
+ final JSONArray snapshotJson = JSONArray.class.cast(
+ JSONSerializer.toJSON(createRepo().snapshot().replaceAll("\"time\": \"[^\"]*\"", "\"time\": \"assert\"").replaceAll("\"marker\": \"[^\"]*\"", "\"marker\": \"ubuntu\"")));
+ assertEquals(8, snapshotJson.size());
+
+ final Collection<Integer> counters = new LinkedList<Integer>();
+ final Collection<String> gauges = new LinkedList<String>();
+ final Collection<String> validations = new LinkedList<String>();
+ for (int i = 0; i < 8; i++) {
+ final JSONObject object = JSONObject.class.cast(snapshotJson.get(i));
+ final Object type = object.get("type");
+ final JSONObject data = JSONObject.class.cast(object.get("data"));
+ if ("counter".equals(type)) {
+ counters.add(Number.class.cast(data.get("max")).intValue());
+ } if ("gauge".equals(type)) {
+ gauges.add(String.class.cast(data.get("role")));
+ } if ("validation".equals(type)) {
+ validations.add(String.class.cast(data.get("name")));
+ }
+ }
+
+ assertEquals(3, counters.size());
+ assertTrue(counters.contains(0));
+ assertTrue(counters.contains(1));
+ assertTrue(counters.contains(2));
+
+ assertTrue(gauges.contains("gaugerole"));
+
+ assertTrue(validations.contains("fake"));
+ assertTrue(validations.contains("refake"));
+ }
+
+ private static PullRepository createRepo() {
+ final PullRepository repo = new PullRepository();
+ for (int i = 0; i < 3; i++) {
+ repo.getCounter(new Counter.Key(Role.PERFORMANCES, "counter#" + i)).add(i);
+ }
+ repo.addGauge(new Gauge() {
+ public int value = 0;
+
+ @Override
+ public Role role() {
+ return new Role("gaugerole", Unit.UNARY);
+ }
+
+ @Override
+ public double value() {
+ return value++;
+ }
+
+ @Override
+ public long period() {
+ return -1;
+ }
+ });
+ return repo;
+ }
+}
Added: incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/FakeValidation.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/FakeValidation.java?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/FakeValidation.java (added)
+++ incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/FakeValidation.java Wed Nov 6 17:27:26 2013
@@ -0,0 +1,28 @@
+/*
+ * 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.agent.webapp.pull.validation;
+
+import org.apache.sirona.status.Status;
+import org.apache.sirona.status.Validation;
+import org.apache.sirona.status.ValidationResult;
+
+public class FakeValidation implements Validation {
+ @Override
+ public ValidationResult validate() {
+ return new ValidationResult("fake", Status.OK, "descr");
+ }
+}
Added: incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/ReFakeValidation.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/ReFakeValidation.java?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/ReFakeValidation.java (added)
+++ incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/validation/ReFakeValidation.java Wed Nov 6 17:27:26 2013
@@ -0,0 +1,28 @@
+/*
+ * 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.agent.webapp.pull.validation;
+
+import org.apache.sirona.status.Status;
+import org.apache.sirona.status.Validation;
+import org.apache.sirona.status.ValidationResult;
+
+public class ReFakeValidation implements Validation {
+ @Override
+ public ValidationResult validate() {
+ return new ValidationResult("refake", Status.OK, "descr");
+ }
+}
Added: incubator/sirona/trunk/agent/pull/src/test/resources/META-INF/services/org.apache.sirona.status.Validation
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/test/resources/META-INF/services/org.apache.sirona.status.Validation?rev=1539405&view=auto
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/test/resources/META-INF/services/org.apache.sirona.status.Validation (added)
+++ incubator/sirona/trunk/agent/pull/src/test/resources/META-INF/services/org.apache.sirona.status.Validation Wed Nov 6 17:27:26 2013
@@ -0,0 +1,2 @@
+org.apache.sirona.agent.webapp.pull.validation.FakeValidation
+org.apache.sirona.agent.webapp.pull.validation.ReFakeValidation
Modified: incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/Cube.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/Cube.java?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/Cube.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/Cube.java Wed Nov 6 17:27:26 2013
@@ -16,6 +16,11 @@
*/
package org.apache.sirona.cube;
+import org.apache.sirona.Role;
+import org.apache.sirona.counters.Counter;
+import org.apache.sirona.status.NodeStatus;
+import org.apache.sirona.status.ValidationResult;
+
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
import java.io.OutputStream;
@@ -25,6 +30,7 @@ import java.net.Proxy;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
@@ -37,6 +43,22 @@ import java.util.logging.Logger;
public class Cube {
private static final Logger LOGGER = Logger.getLogger(Cube.class.getName());
+ private static final String COUNTER_TYPE = "counter";
+ private static final String GAUGE_TYPE = "gauge";
+ private static final String VALIDATION_TYPE = "validation";
+
+ private static final String NAME = "name";
+ private static final String ROLE = "role";
+ private static final String UNIT = "unit";
+ private static final String CONCURRENCY = "concurrency";
+ private static final String MEAN = "mean";
+ private static final String VARIANCE = "variance";
+ private static final String HITS = "hits";
+ private static final String MAX = "max";
+ private static final String MIN = "min";
+ private static final String SUM = "sum";
+ private static final String M_2 = "m2";
+
private static final String JSON_BASE = "{" +
"\"type\": \"%s\"," +
"\"time\": \"%s\"," +
@@ -178,4 +200,46 @@ public class Cube {
return simpleDateFormat;
}
+ public StringBuilder counterSnapshot(final Collection<Counter> instances) {
+ final long ts = System.currentTimeMillis();
+ final StringBuilder events = newEventStream();
+ for (final Counter counter : instances) {
+ buildEvent(events, COUNTER_TYPE, ts, new MapBuilder()
+ .add(NAME, counter.getKey().getName())
+ .add(ROLE, counter.getKey().getRole().getName())
+ .add(UNIT, counter.getKey().getRole().getUnit().getName())
+ // minimum metrics to be able to aggregate counters later
+ .add(CONCURRENCY, counter.currentConcurrency().intValue())
+ .add(MEAN, counter.getMean())
+ .add(VARIANCE, counter.getVariance())
+ .add(HITS, counter.getHits())
+ .add(MAX, counter.getMax())
+ .add(MIN, counter.getMin())
+ .add(SUM, counter.getSum())
+ .add(M_2, counter.getSecondMoment())
+ .map());
+ }
+ return events;
+ }
+
+ public StringBuilder gaugeSnapshot(final long time, final Role role, final double value) {
+ return buildEvent(new StringBuilder(), GAUGE_TYPE, time,
+ new MapBuilder()
+ .add("value", value)
+ .add("role", role.getName())
+ .add("unit", role.getUnit().getName())
+ .map());
+ }
+
+ public StringBuilder statusSnapshot(final long ts, final NodeStatus nodeStatus) {
+ final StringBuilder events = newEventStream();
+ for (final ValidationResult result : nodeStatus.getResults()) {
+ buildEvent(events, VALIDATION_TYPE, ts, new MapBuilder()
+ .add("message", result.getMessage())
+ .add("status", result.getStatus().name())
+ .add("name", result.getName())
+ .map());
+ }
+ return events;
+ }
}
Modified: incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeCounterDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeCounterDataStore.java?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeCounterDataStore.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeCounterDataStore.java Wed Nov 6 17:27:26 2013
@@ -23,42 +23,10 @@ import org.apache.sirona.store.counter.B
import java.util.Collection;
public class CubeCounterDataStore extends BatchCounterDataStore {
- private static final String COUNTER_TYPE = "counter";
-
- private static final String NAME = "name";
- private static final String ROLE = "role";
- private static final String UNIT = "unit";
- private static final String CONCURRENCY = "concurrency";
- private static final String MEAN = "mean";
- private static final String VARIANCE = "variance";
- private static final String HITS = "hits";
- private static final String MAX = "max";
- private static final String MIN = "min";
- private static final String SUM = "sum";
- private static final String M_2 = "m2";
-
private final Cube cube = Configuration.findOrCreateInstance(CubeBuilder.class).build();
@Override
protected synchronized void pushCountersByBatch(final Collection<Counter> instances) {
- final long ts = System.currentTimeMillis();
- final StringBuilder events = cube.newEventStream();
- for (final Counter counter : instances) {
- cube.buildEvent(events, COUNTER_TYPE, ts, new MapBuilder()
- .add(NAME, counter.getKey().getName())
- .add(ROLE, counter.getKey().getRole().getName())
- .add(UNIT, counter.getKey().getRole().getUnit().getName())
- // minimum metrics to be able to aggregate counters later
- .add(CONCURRENCY, counter.currentConcurrency().intValue())
- .add(MEAN, counter.getMean())
- .add(VARIANCE, counter.getVariance())
- .add(HITS, counter.getHits())
- .add(MAX, counter.getMax())
- .add(MIN, counter.getMin())
- .add(SUM, counter.getSum())
- .add(M_2, counter.getSecondMoment())
- .map());
- }
- cube.post(events);
+ cube.post(cube.counterSnapshot(instances));
}
}
Copied: incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java (from r1539369, incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java)
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java?p2=incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java&p1=incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java&r1=1539369&r2=1539405&rev=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java Wed Nov 6 17:27:26 2013
@@ -18,28 +18,20 @@ package org.apache.sirona.cube;
import org.apache.sirona.Role;
import org.apache.sirona.configuration.Configuration;
-import org.apache.sirona.gauges.RemoteGaugeDataStore;
+import org.apache.sirona.gauges.GaugeDataStoreAdapter;
import java.util.logging.Level;
import java.util.logging.Logger;
-public class CubeGaugeDataStore extends RemoteGaugeDataStore {
+public class CubeGaugeDataStore extends GaugeDataStoreAdapter {
private static final Logger LOGGER = Logger.getLogger(CubeGaugeDataStore.class.getName());
- private static final String GAUGE_TYPE = "gauge";
-
private final Cube cube = Configuration.findOrCreateInstance(CubeBuilder.class).build();
@Override
public void addToGauge(final Role role, final long time, final double value) {
try {
- cube.post(
- cube.buildEvent(new StringBuilder(), GAUGE_TYPE, time,
- new MapBuilder()
- .add("value", value)
- .add("role", role.getName())
- .add("unit", role.getUnit().getName())
- .map()));
+ cube.post(cube.gaugeSnapshot(time, role, value));
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
Modified: incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeNodeStatusDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeNodeStatusDataStore.java?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeNodeStatusDataStore.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeNodeStatusDataStore.java Wed Nov 6 17:27:26 2013
@@ -18,25 +18,13 @@ package org.apache.sirona.cube;
import org.apache.sirona.configuration.Configuration;
import org.apache.sirona.status.NodeStatus;
-import org.apache.sirona.status.ValidationResult;
import org.apache.sirona.store.status.PeriodicNodeStatusDataStore;
public class CubeNodeStatusDataStore extends PeriodicNodeStatusDataStore {
- private static final String VALIDATION_TYPE = "validation";
-
private final Cube cube = Configuration.findOrCreateInstance(CubeBuilder.class).build();
@Override
protected void reportStatus(final NodeStatus nodeStatus) {
- final long ts = System.currentTimeMillis();
- final StringBuilder events = cube.newEventStream();
- for (final ValidationResult result : nodeStatus.getResults()) {
- cube.buildEvent(events, VALIDATION_TYPE, ts, new MapBuilder()
- .add("message", result.getMessage())
- .add("status", result.getStatus().name())
- .add("name", result.getName())
- .map());
- }
- cube.post(events);
+ cube.post(cube.statusSnapshot(System.currentTimeMillis(), nodeStatus));
}
}
Modified: incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteDataStoreFactory.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteDataStoreFactory.java?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteDataStoreFactory.java (original)
+++ incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteDataStoreFactory.java Wed Nov 6 17:27:26 2013
@@ -16,11 +16,15 @@
*/
package org.apache.sirona.graphite;
+import org.apache.sirona.configuration.Configuration;
import org.apache.sirona.store.DelegateDataStoreFactory;
import org.apache.sirona.store.status.EmptyStatuses;
public class GraphiteDataStoreFactory extends DelegateDataStoreFactory {
public GraphiteDataStoreFactory() {
- super(new GraphiteCounterDataStore(), new GraphiteGaugeDataStore(), new EmptyStatuses());
+ super(
+ Configuration.processInstance(new GraphiteCounterDataStore()),
+ Configuration.processInstance(new GraphiteGaugeDataStore()),
+ new EmptyStatuses());
}
}
Copied: incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java (from r1539369, incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java)
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java?p2=incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java&p1=incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java&r1=1539369&r2=1539405&rev=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java (original)
+++ incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java Wed Nov 6 17:27:26 2013
@@ -18,7 +18,7 @@ package org.apache.sirona.graphite;
import org.apache.sirona.Role;
import org.apache.sirona.configuration.Configuration;
-import org.apache.sirona.store.gauge.AggregatedGaugeDataStore;
+import org.apache.sirona.store.gauge.AggregatedGaugeDataStoreAdapter;
import org.apache.sirona.store.gauge.Value;
import java.io.IOException;
@@ -26,7 +26,7 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
-public class GraphiteGaugeDataStore extends AggregatedGaugeDataStore {
+public class GraphiteGaugeDataStore extends AggregatedGaugeDataStoreAdapter {
private static final Logger LOGGER = Logger.getLogger(GraphiteGaugeDataStore.class.getName());
private static final String GAUGE_PREFIX = "gauge-";
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/Gauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/Gauge.java?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/Gauge.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/Gauge.java Wed Nov 6 17:27:26 2013
@@ -73,7 +73,7 @@ public interface Gauge {
}
}
- private void addGauge(Gauge g) {
+ private void addGauge(final Gauge g) {
Repository.INSTANCE.addGauge(g);
gauges.add(g);
}
Copied: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java (from r1539369, incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/RemoteGaugeDataStore.java)
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java?p2=incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java&p1=incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/RemoteGaugeDataStore.java&r1=1539369&r2=1539405&rev=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/RemoteGaugeDataStore.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java Wed Nov 6 17:27:26 2013
@@ -24,14 +24,19 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Map;
-public abstract class RemoteGaugeDataStore implements GaugeDataStore {
+public class GaugeDataStoreAdapter implements GaugeDataStore {
@Override
- public Map<Long, Double> getGaugeValues(GaugeValuesRequest gaugeValuesRequest) {
+ public Map<Long, Double> getGaugeValues(final GaugeValuesRequest gaugeValuesRequest) {
return Collections.emptyMap();
}
@Override
- public void createOrNoopGauge(Role role) {
+ public void createOrNoopGauge(final Role role) {
+ // no-op
+ }
+
+ @Override
+ public void addToGauge(final Role role, final long time, final double value) {
// no-op
}
@@ -41,7 +46,7 @@ public abstract class RemoteGaugeDataSto
}
@Override
- public Role findGaugeRole(String name) {
+ public Role findGaugeRole(final String name) {
return null;
}
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeManager.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeManager.java?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeManager.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeManager.java Wed Nov 6 17:27:26 2013
@@ -25,5 +25,5 @@ public interface GaugeManager {
void addGauge(Gauge gauge);
- void stopGauge(Gauge role);
+ void stopGauge(Gauge gauge);
}
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/repositories/DefaultRepository.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/repositories/DefaultRepository.java?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/repositories/DefaultRepository.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/repositories/DefaultRepository.java Wed Nov 6 17:27:26 2013
@@ -42,26 +42,74 @@ import java.util.Collection;
import java.util.Map;
public class DefaultRepository implements Repository {
- private final CounterDataStore counterDataStore;
- private final NodeStatusDataStore nodeStatusDataStore;
- private final CommonGaugeDataStore gaugeDataStore;
- private final GaugeManager gaugeManager;
+ protected final CounterDataStore counterDataStore;
+ protected final NodeStatusDataStore nodeStatusDataStore;
+ protected final CommonGaugeDataStore gaugeDataStore;
+ protected final GaugeManager gaugeManager;
public DefaultRepository() {
- CounterDataStore counter = null;
- try {
- counter = Configuration.findOrCreateInstance(CounterDataStore.class);
- } catch (final MonitoringException e) {
- // no-op
+ this(findCounterDataStore(), findGaugeDataStore(), findStatusDataStore());
+ }
+
+ protected DefaultRepository(final CounterDataStore counter, final CommonGaugeDataStore gauge, final NodeStatusDataStore status) {
+ this.counterDataStore = counter;
+ this.gaugeDataStore = gauge;
+ this.nodeStatusDataStore = status;
+
+ if (CollectorCounterStore.class.isInstance(counter)) {
+ Configuration.setSingletonInstance(CollectorCounterStore.class, counter);
+ } else {
+ Configuration.setSingletonInstance(CounterDataStore.class, counter);
}
- if (counter == null) {
+ if (CollectorGaugeDataStore.class.isInstance(gauge)) {
+ Configuration.setSingletonInstance(CollectorGaugeDataStore.class, gauge);
+ } else {
+ Configuration.setSingletonInstance(GaugeDataStore.class, gauge);
+ }
+ if (CollectorNodeStatusDataStore.class.isInstance(status)) {
+ Configuration.setSingletonInstance(CollectorNodeStatusDataStore.class, status);
+ } else {
+ Configuration.setSingletonInstance(NodeStatusDataStore.class, status);
+ }
+
+ this.gaugeManager = findGaugeManager();
+
+ if (Configuration.is(Configuration.CONFIG_PROPERTY_PREFIX + "core.gauge.activated", true)) {
+ addGauge(new CPUGauge());
+ addGauge(new UsedMemoryGauge());
+ }
+ }
+
+ protected GaugeManager findGaugeManager() {
+ final GaugeManager manager;
+ if (GaugeDataStore.class.isInstance(gaugeDataStore)) {
+ GaugeManager mgr;
try {
- counter = Configuration.findOrCreateInstance(CollectorCounterStore.class);
+ mgr = Configuration.findOrCreateInstance(GaugeManager.class);
} catch (final MonitoringException e) {
- // no-op
+ mgr = new DefaultGaugeManager();
}
+ manager = mgr;
+ } else {
+ manager = null;
}
+ return manager;
+ }
+ private static NodeStatusDataStore findStatusDataStore() {
+ NodeStatusDataStore status = null;
+ try {
+ status = Configuration.findOrCreateInstance(NodeStatusDataStore.class);
+ } catch (final MonitoringException e) {
+ // no-op
+ }
+ if (status == null) {
+ status = Configuration.findOrCreateInstance(DataStoreFactory.class).getNodeStatusDataStore();
+ }
+ return status;
+ }
+
+ private static CommonGaugeDataStore findGaugeDataStore() {
CommonGaugeDataStore gauge = null;
try {
gauge = Configuration.findOrCreateInstance(GaugeDataStore.class);
@@ -75,61 +123,30 @@ public class DefaultRepository implement
// no-op
}
}
+ if (gauge == null) {
+ gauge = Configuration.findOrCreateInstance(DataStoreFactory.class).getGaugeDataStore();
+ }
+ return gauge;
+ }
- NodeStatusDataStore status = null;
+ private static CounterDataStore findCounterDataStore() {
+ CounterDataStore counter = null;
try {
- status = Configuration.findOrCreateInstance(NodeStatusDataStore.class);
+ counter = Configuration.findOrCreateInstance(CounterDataStore.class);
} catch (final MonitoringException e) {
// no-op
}
-
if (counter == null) {
- counter = Configuration.findOrCreateInstance(DataStoreFactory.class).getCounterDataStore();
- if (CollectorCounterStore.class.isInstance(counter)) {
- Configuration.setSingletonInstance(CollectorCounterStore.class, counter);
- } else {
- Configuration.setSingletonInstance(CounterDataStore.class, counter);
- }
- }
-
- if (gauge == null) {
- gauge = Configuration.findOrCreateInstance(DataStoreFactory.class).getGaugeDataStore();
- if (CollectorGaugeDataStore.class.isInstance(gauge)) {
- Configuration.setSingletonInstance(CollectorGaugeDataStore.class, gauge);
- } else {
- Configuration.setSingletonInstance(GaugeDataStore.class, gauge);
- }
- }
-
- if (status == null) {
- status = Configuration.findOrCreateInstance(DataStoreFactory.class).getNodeStatusDataStore();
- if (CollectorNodeStatusDataStore.class.isInstance(status)) {
- Configuration.setSingletonInstance(CollectorNodeStatusDataStore.class, status);
- } else {
- Configuration.setSingletonInstance(NodeStatusDataStore.class, status);
- }
- }
-
- this.counterDataStore = counter;
- this.gaugeDataStore = gauge;
- this.nodeStatusDataStore = status;
-
- if (GaugeDataStore.class.isInstance(this.gaugeDataStore)) {
- GaugeManager mgr;
try {
- mgr = Configuration.findOrCreateInstance(GaugeManager.class);
+ counter = Configuration.findOrCreateInstance(CollectorCounterStore.class);
} catch (final MonitoringException e) {
- mgr = new DefaultGaugeManager();
+ // no-op
}
- this.gaugeManager = mgr;
- } else {
- this.gaugeManager = null;
}
-
- if (Configuration.is(Configuration.CONFIG_PROPERTY_PREFIX + "core.gauge.activated", true)) {
- addGauge(new CPUGauge());
- addGauge(new UsedMemoryGauge());
+ if (counter == null) {
+ counter = Configuration.findOrCreateInstance(DataStoreFactory.class).getCounterDataStore();
}
+ return counter;
}
@Configuration.Destroying
Copied: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java (from r1539369, incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStore.java)
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java?p2=incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java&p1=incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStore.java&r1=1539369&r2=1539405&rev=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStore.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java Wed Nov 6 17:27:26 2013
@@ -19,7 +19,7 @@ package org.apache.sirona.store.gauge;
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
import org.apache.sirona.Role;
import org.apache.sirona.configuration.Configuration;
-import org.apache.sirona.gauges.RemoteGaugeDataStore;
+import org.apache.sirona.gauges.GaugeDataStoreAdapter;
import org.apache.sirona.store.BatchFuture;
import org.apache.sirona.util.DaemonThreadFactory;
@@ -34,14 +34,14 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
-public abstract class AggregatedGaugeDataStore extends RemoteGaugeDataStore {
- private static final Logger LOGGER = Logger.getLogger(AggregatedGaugeDataStore.class.getName());
+public abstract class AggregatedGaugeDataStoreAdapter extends GaugeDataStoreAdapter {
+ private static final Logger LOGGER = Logger.getLogger(AggregatedGaugeDataStoreAdapter.class.getName());
private final ConcurrentMap<Role, SummaryStatistics> gauges = new ConcurrentHashMap<Role, SummaryStatistics>();
protected final BatchFuture scheduledTask;
- public AggregatedGaugeDataStore() {
+ public AggregatedGaugeDataStoreAdapter() {
final String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH).replace("gaugedatastore", "");
final long period = getPeriod(name);
Modified: incubator/sirona/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/pom.xml?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/pom.xml (original)
+++ incubator/sirona/trunk/pom.xml Wed Nov 6 17:27:26 2013
@@ -292,6 +292,11 @@
</dependency>
<dependency>
<groupId>org.apache.sirona</groupId>
+ <artifactId>sirona-cube</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sirona</groupId>
<artifactId>sirona-aop</artifactId>
<version>${project.version}</version>
</dependency>
Modified: incubator/sirona/trunk/server/collector/src/main/java/org/apache/sirona/collector/server/Collector.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/collector/src/main/java/org/apache/sirona/collector/server/Collector.java?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/server/collector/src/main/java/org/apache/sirona/collector/server/Collector.java (original)
+++ incubator/sirona/trunk/server/collector/src/main/java/org/apache/sirona/collector/server/Collector.java Wed Nov 6 17:27:26 2013
@@ -41,6 +41,7 @@ import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
@@ -99,9 +100,23 @@ public class Collector extends HttpServl
final Event[] events = mapper.readValue(req.getInputStream(), Event[].class);
if (events != null && events.length > 0) {
try {
- if (VALIDATION.equals(events[0].getType())) {
- final Collection<ValidationResult> results = new ArrayList<ValidationResult>(events.length);
- for (final Event event : events) {
+ final Collection<Event> validations = new LinkedList<Event>();
+ for (final Event event : events) {
+ final String type = event.getType();
+ if (VALIDATION.equals(type)) {
+ validations.add(event);
+ } else if (COUNTER.equals(type)) {
+ updateCounter(event);
+ } else if (GAUGE.equals(type)) {
+ updateGauge(event);
+ } else {
+ LOGGER.info("Unexpected type '" + type + "', skipping");
+ }
+ }
+
+ if (validations.size() > 0) {
+ final Collection<ValidationResult> results = new ArrayList<ValidationResult>(validations.size());
+ for (final Event event : validations) {
final Map<String, Object> data = event.getData();
results.add(new ValidationResult(
(String) data.get("name"),
@@ -110,18 +125,6 @@ public class Collector extends HttpServl
}
final NodeStatus status = new NodeStatus(results.toArray(new ValidationResult[results.size()]));
statusDataStore.store((String) events[0].getData().get("marker"), status);
- } else {
- for (final Event event : events) {
- final String type = event.getType();
-
- if (COUNTER.equals(type)) {
- updateCounter(event);
- } else if (GAUGE.equals(type)) {
- updateGauge(event);
- } else {
- LOGGER.info("Unexpected type '" + type + "', skipping");
- }
- }
}
} catch (final Exception e) {
resp.setStatus(HttpURLConnection.HTTP_BAD_REQUEST);
Modified: incubator/sirona/trunk/src/site/markdown/configuration.md
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/src/site/markdown/configuration.md?rev=1539405&r1=1539404&r2=1539405&view=diff
==============================================================================
--- incubator/sirona/trunk/src/site/markdown/configuration.md (original)
+++ incubator/sirona/trunk/src/site/markdown/configuration.md Wed Nov 6 17:27:26 2013
@@ -84,3 +84,7 @@ or to call manually `Configuration.shutd
* org.apache.sirona.tomee.gauges.activated: a boolean to deactivate tomee guages (stateless pool stat)
* org.apache.sirona.tomee.validations.activated: a boolean to deactivate tomee validations (datasource validation by validation query)
+
+# Pull
+
+* org.apache.sirona.agent.pull.mapping: the servlet mapping, default to `/sirona/pull`