You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ja...@apache.org on 2016/01/28 09:47:24 UTC
svn commit: r1727278 - in
/ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo: ./ src/
src/org/ src/org/apache/ src/org/apache/ace/ src/org/apache/ace/log/
src/org/apache/ace/log/server/ src/org/apache/ace/log/server/store/
src/org/apache...
Author: jawi
Date: Thu Jan 28 08:47:24 2016
New Revision: 1727278
URL: http://svn.apache.org/viewvc?rev=1727278&view=rev
Log:
Move these non-core parts of ACE to ACE-extras.
Added:
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.classpath (with props)
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.project (with props)
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/bnd.bnd
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/Activator.java (with props)
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/MongoLogStore.java (with props)
Modified:
ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/ (props changed)
Propchange: ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jan 28 08:47:24 2016
@@ -0,0 +1,4 @@
+.settings
+generated
+bin
+bin_test
Added: ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.classpath
URL: http://svn.apache.org/viewvc/ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.classpath?rev=1727278&view=auto
==============================================================================
--- ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.classpath (added)
+++ ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.classpath Thu Jan 28 08:47:24 2016
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="bin" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="aQute.bnd.classpath.container"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Propchange: ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.classpath
------------------------------------------------------------------------------
svn:eol-style = native
Added: ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.project
URL: http://svn.apache.org/viewvc/ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.project?rev=1727278&view=auto
==============================================================================
--- ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.project (added)
+++ ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.project Thu Jan 28 08:47:24 2016
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.apache.ace.log.server.store.mongo</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>bndtools.core.bndbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>bndtools.core.bndnature</nature>
+ </natures>
+</projectDescription>
Propchange: ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/.project
------------------------------------------------------------------------------
svn:eol-style = native
Added: ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/bnd.bnd?rev=1727278&view=auto
==============================================================================
--- ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/bnd.bnd (added)
+++ ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/bnd.bnd Thu Jan 28 08:47:24 2016
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under the terms of ASLv2 (http://www.apache.org/licenses/LICENSE-2.0).
+
+-buildpath: \
+ ${^-buildpath},\
+ osgi.core;version=6.0.0,\
+ osgi.cmpn,\
+ org.apache.felix.http.servlet-api,\
+ org.apache.felix.dependencymanager,\
+ org.apache.ace.range.api;version=latest,\
+ org.apache.ace.test;version=latest,\
+ org.apache.ace.identification.api;version=latest,\
+ org.apache.ace.discovery.api;version=latest,\
+ org.apache.ace.scheduler.api;version=latest,\
+ org.apache.ace.connectionfactory;version=latest,\
+ org.apache.ace.authentication.api;version=latest,\
+ org.amdatu.mongo,\
+ org.mongodb.mongo-java-driver,\
+ org.apache.ace.feedback.common;version=latest
+
+Private-Package: org.apache.ace.log.server.store.mongo
+Bundle-Activator: org.apache.ace.log.server.store.mongo.Activator
+Bundle-Version: 1.0.2
+Bundle-Name: Apache ACE Log Server Store Mongo
+Bundle-Description: Registers a service factory for MongoDB bases Server Log stores
Added: ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/Activator.java
URL: http://svn.apache.org/viewvc/ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/Activator.java?rev=1727278&view=auto
==============================================================================
--- ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/Activator.java (added)
+++ ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/Activator.java Thu Jan 28 08:47:24 2016
@@ -0,0 +1,96 @@
+/*
+ * 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.ace.log.server.store.mongo;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.amdatu.mongo.MongoDBService;
+import org.apache.ace.log.server.store.LogStore;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.log.LogService;
+
+public class Activator extends DependencyActivatorBase implements ManagedServiceFactory {
+ public static final String PID = "org.apache.ace.log.server.store.mongo";
+
+ private static final String LOG_NAME = "name";
+
+ private DependencyManager m_manager;
+ private final Map<String, Component> m_instances = new HashMap<String, Component>();
+ private volatile LogService m_log;
+
+ @Override
+ public void init(BundleContext context, DependencyManager manager) throws Exception {
+ m_manager = manager;
+ Properties props = new Properties();
+ props.put(Constants.SERVICE_PID, "org.apache.ace.log.server.store.factory");
+ manager.add(createComponent()
+ .setInterface(ManagedServiceFactory.class.getName(), props)
+ .setImplementation(this)
+ .add(createServiceDependency().setService(LogService.class).setRequired(false)));
+ }
+
+ @Override
+ public void destroy(BundleContext context, DependencyManager manager) throws Exception {
+ }
+
+ @Override
+ public void deleted(String pid) {
+ Component log = m_instances.remove(pid);
+ if (log != null) {
+ m_manager.remove(log);
+ }
+ }
+
+ public String getName() {
+ return "Log Store Factory";
+ }
+
+ public synchronized void updated(String pid, @SuppressWarnings("rawtypes") Dictionary dict) throws ConfigurationException {
+ String name = (String) dict.get(LOG_NAME);
+ if ((name == null) || "".equals(name)) {
+ throw new ConfigurationException(LOG_NAME, "Log name has to be specified.");
+ }
+
+ Component service = m_instances.get(pid);
+ if (service == null) {
+ Properties props = new Properties();
+ props.put(LOG_NAME, name);
+ service = m_manager.createComponent()
+ .setInterface(LogStore.class.getName(), props)
+ .setImplementation(new MongoLogStore(name))
+ .add(createServiceDependency().setService(EventAdmin.class).setRequired(false))
+ .add(createServiceDependency().setService(MongoDBService.class).setRequired(true))
+ .add(createConfigurationDependency().setPid(PID));
+ m_instances.put(pid, service);
+ m_manager.add(service);
+ } else {
+ m_log.log(LogService.LOG_INFO, "Ignoring configuration update because factory instance was already configured: " + name);
+ }
+ }
+}
\ No newline at end of file
Propchange: ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/Activator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/MongoLogStore.java
URL: http://svn.apache.org/viewvc/ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/MongoLogStore.java?rev=1727278&view=auto
==============================================================================
--- ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/MongoLogStore.java (added)
+++ ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/MongoLogStore.java Thu Jan 28 08:47:24 2016
@@ -0,0 +1,208 @@
+/*
+ * 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.ace.log.server.store.mongo;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.amdatu.mongo.MongoDBService;
+import org.apache.ace.feedback.Descriptor;
+import org.apache.ace.feedback.Event;
+import org.apache.ace.log.server.store.LogStore;
+import org.apache.ace.range.Range;
+import org.apache.ace.range.SortedRangeSet;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
+import com.mongodb.MapReduceCommand.OutputType;
+import com.mongodb.MapReduceOutput;
+
+public class MongoLogStore implements LogStore, ManagedService {
+ private static final String MAXIMUM_NUMBER_OF_EVENTS = "MaxEvents";
+
+ private final String m_logname;
+ private volatile MongoDBService m_mongoDBService;
+ private int m_maxEvents = 0;
+
+ public MongoLogStore(String logname) {
+ this.m_logname = logname;
+ }
+
+ @Override
+ public List<Event> get(Descriptor range) throws IOException {
+ DBCollection collection = m_mongoDBService.getDB().getCollection(m_logname);
+ long high = range.getRangeSet().getHigh();
+
+ BasicDBObject filter = new BasicDBObject().append("targetId", range.getTargetID()).append("logId", range.getStoreID());
+ if (high > 0) {
+ filter.append("id", new BasicDBObject("$lte", high));
+ }
+
+ DBCursor cursor = collection.find(filter);
+ cursor.sort(new BasicDBObject("id", 1));
+
+ List<Event> Events = new ArrayList<Event>();
+ while (cursor.hasNext()) {
+ DBObject event = cursor.next();
+ String targetId = (String) event.get("targetId");
+ long logId = (Long) event.get("logId");
+ long id = (Long) event.get("id");
+ long time = (Long) event.get("time");
+ int type = (Integer) event.get("type");
+
+ Map<String, String> properties = new HashMap<String, String>();
+ DBObject propertiesDbObject = (DBObject) event.get("properties");
+ for (String key : propertiesDbObject.keySet()) {
+ properties.put(key, (String) propertiesDbObject.get(key));
+ }
+
+ Events.add(new Event(targetId, logId, id, time, type, properties));
+ }
+
+ return Events;
+ }
+
+ @Override
+ public Descriptor getDescriptor(String targetID, long logID)
+ throws IOException {
+
+ DBCollection collection = m_mongoDBService.getDB().getCollection(m_logname);
+
+ BasicDBObject filter = new BasicDBObject().append("targetId", targetID)
+ .append("logId", logID);
+
+ DBCursor cursor = collection.find(filter);
+ cursor.sort(new BasicDBObject("id", -1));
+
+ long high = 1;
+ if (cursor.hasNext()) {
+ DBObject row = cursor.next();
+ high = (Long) row.get("id");
+ return new Descriptor(targetID, logID, new SortedRangeSet(
+ new Range(1, high).toRepresentation()));
+ }
+ else {
+ return new Descriptor(targetID, logID, SortedRangeSet.FULL_SET);
+ }
+ }
+
+ @Override
+ public void put(List<Event> events) throws IOException {
+ // TODO : if m_max_events > 0 then make sure there are no more than m_maxEvents
+ DBCollection collection = m_mongoDBService.getDB().getCollection(m_logname);
+
+ for (Event event : events) {
+ DBObject dbObject = new BasicDBObject()
+ .append("targetId", event.getTargetID())
+ .append("logId", event.getStoreID())
+ .append("id", event.getID())
+ .append("time", event.getTime())
+ .append("type", event.getType())
+ .append("properties", event.getProperties());
+
+ collection.save(dbObject);
+ }
+ }
+
+ @Override
+ public List<Descriptor> getDescriptors(String targetID)
+ throws IOException {
+
+ DBCollection collection = m_mongoDBService.getDB().getCollection(m_logname);
+ String m = "function() {emit(this.targetId,this.logId);}";
+ String r = "function(k, vals) {var result = {target: k, logIds: []}; vals.forEach(function(value) { result.logIds.push(value)}); return result;}";
+ DBObject filter = new BasicDBObject();
+ if (targetID != null) {
+ filter.put("targetId", targetID);
+ }
+ MapReduceOutput mapReduce = collection.mapReduce(m, r, null, OutputType.INLINE, filter);
+ Iterator<DBObject> iterator = mapReduce.results().iterator();
+
+ List<Descriptor> descriptors = new ArrayList<Descriptor>();
+ while (iterator.hasNext()) {
+ DBObject row = iterator.next();
+ DBObject value = (DBObject) row.get("value");
+ String targetId = (String) value.get("target");
+ @SuppressWarnings("unchecked")
+ List<Long> logIds = (List<Long>) value.get("logIds");
+ Set<Long> logIdsFiltered = new HashSet<Long>();
+ logIdsFiltered.addAll(logIds);
+
+ for (long logId : logIdsFiltered) {
+ descriptors.add(getDescriptor(targetId, logId));
+ }
+ }
+
+ return descriptors;
+ }
+
+ @Override
+ public List<Descriptor> getDescriptors() throws IOException {
+ return getDescriptors(null);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public void updated(Dictionary settings) throws ConfigurationException {
+ if (settings != null) {
+ String maximumNumberOfEvents = (String) settings.get(MAXIMUM_NUMBER_OF_EVENTS);
+ if (maximumNumberOfEvents != null) {
+ try {
+ m_maxEvents = Integer.parseInt(maximumNumberOfEvents);
+ } catch (NumberFormatException nfe) {
+ throw new ConfigurationException(MAXIMUM_NUMBER_OF_EVENTS, "is not a number");
+ }
+ }
+ }
+ }
+
+ @Override
+ public void clean() throws IOException {
+ // TODO if m_max_events > 0 then remove all events from the mongo store where there are more than m_maxEvents
+ }
+
+ @Override
+ public Event put(String targetID, int type, Dictionary props) throws IOException {
+ // TODO add an event to the appropriate store
+ return null;
+ }
+
+ @Override
+ public void setLowestID(String targetID, long logID, long lowestID) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public long getLowestID(String targetID, long logID) throws IOException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
Propchange: ace/sandbox/jawi/ace-extra/org.apache.ace.log.server.store.mongo/src/org/apache/ace/log/server/store/mongo/MongoLogStore.java
------------------------------------------------------------------------------
svn:eol-style = native