ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1632255 - in /ace/trunk/org.apache.ace.log: src/org/apache/ace/log/server/servlet/ src/org/apache/ace/log/server/task/ test/org/apache/ace/log/server/servlet/
Date Thu, 16 Oct 2014 09:29:49 GMT
Author: marrs
Date: Thu Oct 16 09:29:49 2014
New Revision: 1632255

URL: http://svn.apache.org/r1632255
Log:
ACE-485 Implemented an option to only sync logs for a specific target ID.

Modified:
    ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/servlet/LogServlet.java
    ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/task/Activator.java
    ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/task/LogSyncTask.java
    ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/servlet/LogServletTest.java

Modified: ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/servlet/LogServlet.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/servlet/LogServlet.java?rev=1632255&r1=1632254&r2=1632255&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/servlet/LogServlet.java (original)
+++ ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/servlet/LogServlet.java Thu
Oct 16 09:29:49 2014
@@ -183,6 +183,14 @@ public class LogServlet extends HttpServ
             output.print(range.toRepresentation());
             return true;
         }
+        else if (targetID != null) {
+            // target id is specified, return only the ranges that match this target
+            List<Descriptor> ranges = m_store.getDescriptors(targetID);
+            for (Descriptor range : ranges) {
+                output.print(range.toRepresentation() + "\n");
+            }
+            return true;
+        }
         else if ((targetID == null) && (logID == null)) {
             // no target or log id has been specified, return all ranges
             List<Descriptor> ranges = m_store.getDescriptors();

Modified: ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/task/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/task/Activator.java?rev=1632255&r1=1632254&r2=1632255&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/task/Activator.java (original)
+++ ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/task/Activator.java Thu Oct
16 09:29:49 2014
@@ -40,6 +40,7 @@ import org.osgi.service.log.LogService;
 public class Activator extends DependencyActivatorBase implements ManagedServiceFactory {
     private static final String KEY_LOG_NAME = "name";
     private static final String KEY_MODE = "mode";
+    private static final String KEY_TARGETID = "tid";
     
     private final Map<String, Component> m_instances = new HashMap<String, Component>();
     private volatile DependencyManager m_manager;
@@ -76,15 +77,16 @@ public class Activator extends Dependenc
         else if ("pushpull".equals(modeValue)) {
         	mode = Mode.PUSHPULL;
         }
+        String targetID = (String) dict.get(KEY_TARGETID);
 
         Component oldComponent, newComponent;
         
         Properties props = new Properties();
         props.put(KEY_LOG_NAME, name);
         props.put("taskName", LogSyncTask.class.getName());
-        props.put("description", "Syncs log (name=" + name + ", mode=" + mode.toString()
+ ") with a server.");
+        props.put("description", "Syncs log (name=" + name + ", mode=" + mode.toString()
+ (targetID == null ? "" : ", targetID=" + targetID) + ") with a server.");
         String filter = "(&(" + Constants.OBJECTCLASS + "=" + LogStore.class.getName()
+ ")(name=" + name + "))";
-        LogSyncTask service = new LogSyncTask(name, name, mode);
+        LogSyncTask service = new LogSyncTask(name, name, mode, targetID);
         newComponent = m_manager.createComponent()
     		.setInterface(new String[] { Runnable.class.getName(), LogSync.class.getName() }, props)
     		.setImplementation(service)

Modified: ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/task/LogSyncTask.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/task/LogSyncTask.java?rev=1632255&r1=1632254&r2=1632255&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/task/LogSyncTask.java (original)
+++ ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/task/LogSyncTask.java Thu Oct
16 09:29:49 2014
@@ -42,6 +42,7 @@ import org.apache.ace.discovery.Discover
 import org.apache.ace.feedback.Descriptor;
 import org.apache.ace.feedback.Event;
 import org.apache.ace.log.LogSync;
+import org.apache.ace.log.server.servlet.LogServlet;
 import org.apache.ace.log.server.store.LogStore;
 import org.apache.ace.range.SortedRangeSet;
 import org.osgi.service.log.LogService;
@@ -70,13 +71,18 @@ public class LogSyncTask implements Runn
     private volatile ConnectionFactory m_connectionFactory;
     private final String m_endpoint;
     private final String m_name;
-
-    private final Mode m_mode;;
+    private final String m_targetID;
+    private final Mode m_mode;
 
     public LogSyncTask(String endpoint, String name, Mode mode) {
+    	this(endpoint, name, mode, null);
+    }
+
+    public LogSyncTask(String endpoint, String name, Mode mode, String targetID) {
         m_endpoint = endpoint;
         m_name = name;
         m_mode = mode;
+        m_targetID = targetID;
     }
 
     public String getName() {
@@ -363,7 +369,12 @@ public class LogSyncTask implements Runn
     }
 
     private URL createURL(URL host, String command) throws MalformedURLException {
-        return new URL(host, m_endpoint.concat("/").concat(command));
+    	if (m_targetID == null) {
+    		return new URL(host, m_endpoint + "/" + command);
+    	}
+    	else {
+    		return new URL(host, m_endpoint + "/" + command + "?" + TARGETID_KEY + "=" + m_targetID);
+    	}
     }
 
     private boolean isEmptyRangeSet(SortedRangeSet set) {

Modified: ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/servlet/LogServletTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/servlet/LogServletTest.java?rev=1632255&r1=1632254&r2=1632255&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/servlet/LogServletTest.java
(original)
+++ ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/servlet/LogServletTest.java
Thu Oct 16 09:29:49 2014
@@ -22,6 +22,7 @@ import static org.apache.ace.test.utils.
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -69,6 +70,18 @@ public class LogServletTest {
         assert result;
         assert (m_range.toRepresentation() + "\n").equals(output.m_text);
     }
+    
+    @Test(groups = { UNIT })
+    public void queryLogWithTargetFilter() throws Exception {
+        MockServletOutputStream output = new MockServletOutputStream();
+        boolean result = m_logServlet.handleQuery(m_range.getTargetID(), null, null, output);
+        assert result;
+        assert m_range.toRepresentation().equals(output.m_text.trim());
+        output.m_text = "";
+        result = m_logServlet.handleQuery(null, null, null, output);
+        assert result;
+        assert (m_range.toRepresentation() + "\n").equals(output.m_text);
+    }
 
     @Test(groups = { UNIT })
     public void receiveLog() throws Exception {
@@ -116,7 +129,9 @@ public class LogServletTest {
             return events;
         }
         public List<Descriptor> getDescriptors(String targetID) {
-            return null;
+        	List<Descriptor> ranges = new ArrayList<Descriptor>();
+            ranges.add(m_range);
+            return ranges;
         }
         public List<Descriptor> getDescriptors() {
             List<Descriptor> ranges = new ArrayList<Descriptor>();



Mime
View raw message