[jira] [Resolved] (ACE-486) Add a method to the server LogStore to create new events

2014-10-17 Thread Marcel Offermans (JIRA)

 [ 
https://issues.apache.org/jira/browse/ACE-486?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Marcel Offermans resolved ACE-486.
--
Resolution: Fixed

Implemented this, and added a test for it.

> Add a method to the server LogStore to create new events
> 
>
> Key: ACE-486
> URL: https://issues.apache.org/jira/browse/ACE-486
> Project: ACE
>  Issue Type: Improvement
>  Components: Log
>Reporter: Marcel Offermans
>Assignee: Marcel Offermans
>
> Currently, the server based LogStore has a service interface that was 
> designed to only support replication scenarios. However, in some cases it 
> could be beneficial if this store also supported adding new events, such as 
> when a server or relay also wants to log audit data (or something else).
> Therefore it makes sense to support a method to create new events, similar to 
> the method that is available in the target LogStore.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


svn commit: r1632545 - in /ace/trunk/org.apache.ace.log: src/org/apache/ace/log/server/store/ src/org/apache/ace/log/server/store/impl/ src/org/apache/ace/log/server/store/mongo/ test/org/apache/ace/l

2014-10-17 Thread marrs
Author: marrs
Date: Fri Oct 17 11:52:59 2014
New Revision: 1632545

URL: http://svn.apache.org/r1632545
Log:
ACE-486 Added a put() method to create a new event. Also extended tests. Did 
not implement this for the MongoDB backed store.

Modified:

ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/LogStore.java

ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/impl/LogStoreImpl.java

ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/mongo/MongoLogStore.java

ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/servlet/LogServletTest.java

ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/store/impl/ServerLogStoreTester.java

Modified: 
ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/LogStore.java
URL: 
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/LogStore.java?rev=1632545&r1=1632544&r2=1632545&view=diff
==
--- 
ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/LogStore.java 
(original)
+++ 
ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/LogStore.java 
Fri Oct 17 11:52:59 2014
@@ -19,6 +19,7 @@
 package org.apache.ace.log.server.store;
 
 import java.io.IOException;
+import java.util.Dictionary;
 import java.util.List;
 
 import org.apache.ace.feedback.Descriptor;
@@ -101,4 +102,15 @@ public interface LogStore
  * @throws IOException in case of any error
  */
 public void clean() throws IOException;
+
+/**
+ * Create a new event out of the given type and properties. Write it to 
the store and return it.
+ *
+ * @param targetID the targetID of this event.
+ * @param type the type of the event.
+ * @param props the properties of the event.
+ * @return the created event that has been persisted.
+ * @throws java.io.IOException in case of any IO error.
+ */
+public Event put(String targetID, int type, Dictionary props) throws 
IOException;
 }
\ No newline at end of file

Modified: 
ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/impl/LogStoreImpl.java
URL: 
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/impl/LogStoreImpl.java?rev=1632545&r1=1632544&r2=1632545&view=diff
==
--- 
ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/impl/LogStoreImpl.java
 (original)
+++ 
ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/impl/LogStoreImpl.java
 Fri Oct 17 11:52:59 2014
@@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingExcept
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Dictionary;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -36,7 +37,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.locks.LockSupport;
 
 import org.apache.ace.feedback.Descriptor;
 import org.apache.ace.feedback.Event;
@@ -144,12 +144,21 @@ public class LogStoreImpl implements Log
 }
 
 public Descriptor getDescriptor(String targetID, long logID) throws 
IOException {
+return getDescriptorInternal(targetID, logID, true);
+}
+
+private Descriptor getDescriptorInternal(String targetID, long logID) 
throws IOException {
+   return getDescriptorInternal(targetID, logID, false);
+}
+
+private Descriptor getDescriptorInternal(String targetID, long logID, 
boolean lock) throws IOException {
 Long high = m_fileToID.get(new File(new File(m_dir, 
targetIDToFilename(targetID)), String.valueOf(logID)).getAbsolutePath());
 if (high != null) {
 Range r = new Range(1, high);
 return new Descriptor(targetID, logID, new 
SortedRangeSet(r.toRepresentation()));
 }
-List events = get(new Descriptor(targetID, logID, 
SortedRangeSet.FULL_SET));
+Descriptor descriptor = new Descriptor(targetID, logID, 
SortedRangeSet.FULL_SET);
+   List events = lock ? get(descriptor) : 
getInternal(descriptor);
 
 long[] idsArray = new long[events.size()];
 int i = 0;
@@ -480,4 +489,43 @@ public class LogStoreImpl implements Log
 lockedLogs.remove(logID);
 }
 }
+
+@Override
+public Event put(String targetID, int type, Dictionary dict) throws 
IOException {
+Map props = new HashMap();
+Enumeration keys = dict.keys();
+while (keys.hasMoreElements()) {
+String key = (String) keys.nextElement();
+props.put(key, (String) dict.get(key));
+}
+List descriptors = getDescriptors(targetID);
+// sort and pick highest
+Descriptor descriptor = null;
+long