You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2018/02/08 16:41:06 UTC

[6/9] aries-rsa git commit: [ARIES-1775] Remove DiscoveryPlugin

[ARIES-1775] Remove DiscoveryPlugin


Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/fa57fb2b
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/fa57fb2b
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/fa57fb2b

Branch: refs/heads/master
Commit: fa57fb2b9374e1bbe00f563caaca4e22c08535eb
Parents: ed5adf8
Author: Christian Schneider <cs...@adobe.com>
Authored: Wed Feb 7 11:16:38 2018 +0100
Committer: Christian Schneider <cs...@adobe.com>
Committed: Thu Feb 8 17:40:34 2018 +0100

----------------------------------------------------------------------
 .../zookeeper/publish/DiscoveryPlugin.java      |  54 ----------
 .../publish/PublishingEndpointListener.java     |  27 -----
 .../publish/PublishingEndpointListenerTest.java | 103 -------------------
 3 files changed, 184 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/fa57fb2b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/DiscoveryPlugin.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/DiscoveryPlugin.java b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/DiscoveryPlugin.java
deleted file mode 100644
index 41afbf2..0000000
--- a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/DiscoveryPlugin.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * 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.aries.rsa.discovery.zookeeper.publish;
-
-import java.util.Map;
-
-/**
- * This interface allows transformation of service registration information before it is pushed into the ZooKeeper
- * discovery system.
- * It can be useful for situations where a host name or port number needs to be changed in cases where the host running
- * the service is known differently from the outside to what the local Java process thinks it is.
- * Extra service properties can also be added to the registration which can be useful to refine the remote service
- * lookup process. <p>
- *
- * DiscoveryPlugins use the OSGi WhiteBoard pattern. To add one to the system, register an instance under this interface
- * with the OSGi Service Registry. All registered DiscoveryPlugin instances are visited and given a chance to
- * process the information before it is pushed into ZooKeeper. <p>
- *
- * Note that the changes made using this plugin do not modify the local service registration.
- *
- */
-public interface DiscoveryPlugin {
-
-    /**
-     * Process service registration information. Plugins can change this information before it is published into the
-     * ZooKeeper discovery system.
-     *
-     * @param mutableProperties A map of service registration properties. The map is mutable and any changes to the map
-     * will be reflected in the ZooKeeper registration.
-     * @param endpointKey The key under which the service is registered in ZooKeeper. This key typically has the
-     * following format: hostname#port##context. While the actual value of this key is not actually used by the
-     * system (people can use it as a hint to understand where the service is located), the value <i>must</i> be
-     * unique for all services of a given type.
-     * @return The <tt>endpointKey</tt> value to be used. If there is no need to change this simply return the value
-     * of the <tt>endpointKey</tt> parameter.
-     */
-    String process(Map<String, Object> mutableProperties, String endpointKey);
-}

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/fa57fb2b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListener.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListener.java b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListener.java
index 6dc0a08..c3bf01f 100644
--- a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListener.java
+++ b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListener.java
@@ -66,7 +66,6 @@ public class PublishingEndpointListener implements EndpointEventListener, Endpoi
     private boolean closed;
     private final EndpointDescriptionParser endpointDescriptionParser;
 
-    private ServiceTracker<DiscoveryPlugin, DiscoveryPlugin> discoveryPluginTracker;
     private ServiceRegistration<?> listenerReg;
 
     public PublishingEndpointListener(ZooKeeper zk, BundleContext bctx) {
@@ -75,9 +74,6 @@ public class PublishingEndpointListener implements EndpointEventListener, Endpoi
     }
     
     public void start(BundleContext bctx) {
-        discoveryPluginTracker = new ServiceTracker<DiscoveryPlugin, DiscoveryPlugin>(bctx, 
-                DiscoveryPlugin.class, null);
-            discoveryPluginTracker.open();
         Dictionary<String, String> props = new Hashtable<String, String>();
         String uuid = bctx.getProperty(Constants.FRAMEWORK_UUID);
         props.put(EndpointEventListener.ENDPOINT_LISTENER_SCOPE, 
@@ -124,15 +120,6 @@ public class PublishingEndpointListener implements EndpointEventListener, Endpoi
         String endpointKey = getKey(endpoint);
         Map<String, Object> props = new HashMap<String, Object>(endpoint.getProperties());
 
-        // process plugins
-        Object[] plugins = discoveryPluginTracker.getServices();
-        if (plugins != null) {
-            for (Object plugin : plugins) {
-                if (plugin instanceof DiscoveryPlugin) {
-                    endpointKey = ((DiscoveryPlugin)plugin).process(props, endpointKey);
-                }
-            }
-        }
         LOG.info("Changing endpoint in zookeeper: {}", endpoint);
         for (String name : interfaces) {
             String path = Utils.getZooKeeperPath(name);
@@ -173,17 +160,6 @@ public class PublishingEndpointListener implements EndpointEventListener, Endpoi
                                                                   InterruptedException, IOException {
         Collection<String> interfaces = endpoint.getInterfaces();
         String endpointKey = getKey(endpoint);
-        Map<String, Object> props = new HashMap<String, Object>(endpoint.getProperties());
-
-        // process plugins
-        Object[] plugins = discoveryPluginTracker != null ? discoveryPluginTracker.getServices() : null;
-        if (plugins != null) {
-            for (Object plugin : plugins) {
-                if (plugin instanceof DiscoveryPlugin) {
-                    endpointKey = ((DiscoveryPlugin)plugin).process(props, endpointKey);
-                }
-            }
-        }
         LOG.info("Exporting endpoint to zookeeper: {}", endpoint);
         for (String name : interfaces) {
             String path = Utils.getZooKeeperPath(name);
@@ -283,8 +259,5 @@ public class PublishingEndpointListener implements EndpointEventListener, Endpoi
             }
             endpoints.clear();
         }
-        if (discoveryPluginTracker != null) {
-            discoveryPluginTracker.close();
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/fa57fb2b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerTest.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerTest.java b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerTest.java
index fcdc9f7..b7debf6 100644
--- a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerTest.java
+++ b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerTest.java
@@ -20,27 +20,17 @@ package org.apache.aries.rsa.discovery.zookeeper.publish;
 
 import static org.easymock.EasyMock.expect;
 
-import java.io.ByteArrayOutputStream;
-import java.lang.reflect.Field;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
-import org.apache.aries.rsa.discovery.endpoint.EndpointDescriptionParser;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.easymock.EasyMock;
-import org.easymock.IAnswer;
 import org.easymock.IMocksControl;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.EndpointEvent;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
@@ -73,49 +63,6 @@ public class PublishingEndpointListenerTest extends TestCase {
         c.verify();
     }
 
-    public void testDiscoveryPlugin() throws Exception {
-        BundleContext ctx = EasyMock.createMock(BundleContext.class);
-        stubCreateFilter(ctx);
-        ctx.addServiceListener(EasyMock.isA(ServiceListener.class),
-                EasyMock.eq("(objectClass=" + DiscoveryPlugin.class.getName() + ")"));
-
-        ServiceReference<DiscoveryPlugin> sr1 = createAppendPlugin(ctx);
-        ServiceReference<DiscoveryPlugin> sr2 = createPropertyPlugin(ctx);
-
-        EasyMock.expect(ctx.getServiceReferences(DiscoveryPlugin.class.getName(), null))
-                .andReturn(new ServiceReference[]{sr1, sr2}).anyTimes();
-        EasyMock.replay(ctx);
-
-        EndpointDescription endpoint = createEndpoint();
-
-        Map<String, Object> expectedProps = new HashMap<String, Object>(endpoint.getProperties());
-        expectedProps.put("endpoint.id", "http://google.de:80/test/sub/appended");
-        expectedProps.put("foo", "bar");
-        expectedProps.put("service.imported", "true");
-
-        final ZooKeeper zk = EasyMock.createNiceMock(ZooKeeper.class);
-        String expectedFullPath = "/osgi/service_registry/org/foo/myClass/some.machine#9876##test";
-        
-        EndpointDescription epd = new EndpointDescription(expectedProps);
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        new EndpointDescriptionParser().writeEndpoint(epd, bos);
-        byte[] data = bos.toByteArray();
-        expectCreated(zk, expectedFullPath, EasyMock.aryEq(data));
-        EasyMock.replay(zk);
-
-        PublishingEndpointListener eli = new PublishingEndpointListener(zk, ctx);
-
-        List<EndpointDescription> endpoints = getEndpoints(eli);
-        assertEquals("Precondition", 0, endpoints.size());
-        eli.endpointChanged(new EndpointEvent(EndpointEvent.ADDED, endpoint), null);
-        assertEquals(1, endpoints.size());
-
-        //TODO enable
-        //EasyMock.verify(zk);
-    }
-
-
-
     public void testClose() throws KeeperException, InterruptedException {
         IMocksControl c = EasyMock.createNiceControl();
         BundleContext ctx = c.createMock(BundleContext.class);
@@ -133,56 +80,6 @@ public class PublishingEndpointListenerTest extends TestCase {
         c.verify();
     }
 
-    @SuppressWarnings("unchecked")
-    private ServiceReference<DiscoveryPlugin> createAppendPlugin(BundleContext ctx) {
-        DiscoveryPlugin plugin1 = new DiscoveryPlugin() {
-            public String process(Map<String, Object> mutableProperties, String endpointKey) {
-                String eid = (String) mutableProperties.get("endpoint.id");
-                mutableProperties.put("endpoint.id", eid + "/appended");
-                return endpointKey;
-            }
-        };
-        ServiceReference<DiscoveryPlugin> sr1 = EasyMock.createMock(ServiceReference.class);
-        EasyMock.expect(ctx.getService(sr1)).andReturn(plugin1).anyTimes();
-        return sr1;
-    }
-
-    @SuppressWarnings("unchecked")
-    private ServiceReference<DiscoveryPlugin> createPropertyPlugin(BundleContext ctx) {
-        DiscoveryPlugin plugin2 = new DiscoveryPlugin() {
-            public String process(Map<String, Object> mutableProperties, String endpointKey) {
-                mutableProperties.put("foo", "bar");
-                return endpointKey.replaceAll("localhost", "some.machine");
-            }
-        };
-        ServiceReference<DiscoveryPlugin> sr2 = EasyMock.createMock(ServiceReference.class);
-        EasyMock.expect(ctx.getService(sr2)).andReturn(plugin2).anyTimes();
-        return sr2;
-    }
-
-    @SuppressWarnings("unchecked")
-    private List<EndpointDescription> getEndpoints(PublishingEndpointListener eli) throws Exception {
-        Field field = eli.getClass().getDeclaredField("endpoints");
-        field.setAccessible(true);
-        return (List<EndpointDescription>) field.get(eli);
-    }
-
-    private void stubCreateFilter(BundleContext ctx) throws InvalidSyntaxException {
-        EasyMock.expect(ctx.createFilter(EasyMock.isA(String.class))).andAnswer(new IAnswer<Filter>() {
-            public Filter answer() throws Throwable {
-                return FrameworkUtil.createFilter((String) EasyMock.getCurrentArguments()[0]);
-            }
-        }).anyTimes();
-    }
-
-    private void expectCreated(ZooKeeper zk, String path, byte[] dataMatcher) throws KeeperException, InterruptedException {
-        expect(zk.create(EasyMock.eq(path), 
-                         dataMatcher, 
-                         EasyMock.eq(Ids.OPEN_ACL_UNSAFE),
-                         EasyMock.eq(CreateMode.EPHEMERAL)))
-            .andReturn("");
-    }
-    
     private void expectCreated(ZooKeeper zk, String path) throws KeeperException, InterruptedException {
         expect(zk.create(EasyMock.eq(path), 
                          (byte[])EasyMock.anyObject(),