From 02deb34080a76f5e329f4b06cecf03cf6ea9da43 Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Fri, 9 Aug 2024 13:47:05 -0700 Subject: [PATCH] Update to 1.3.0. Added support for multiple etcd discovery clients (for multiple etcd servers --- cnf/ext/defaults.bnd | 7 +- org.eclipse.ecf.provider.etcd3/.classpath | 7 +- org.eclipse.ecf.provider.etcd3/bnd.bnd | 143 +++++++++++++++++- .../eclipse/ecf/provider/etcd3/Activator.java | 72 +-------- .../container/Etcd3DiscoveryContainer.java | 1 + .../Etcd3DiscoveryContainerConfig.java | 2 + .../ecf/provider/etcd3/test/TestMyCode.java | 22 +++ 7 files changed, 181 insertions(+), 73 deletions(-) create mode 100644 org.eclipse.ecf.provider.etcd3/src/test/java/org/eclipse/ecf/provider/etcd3/test/TestMyCode.java diff --git a/cnf/ext/defaults.bnd b/cnf/ext/defaults.bnd index 299fb10..2a1230e 100644 --- a/cnf/ext/defaults.bnd +++ b/cnf/ext/defaults.bnd @@ -49,7 +49,12 @@ url = https://raw.githubusercontent.com/ECF/grpc-RemoteServicesProvider/master/build/; \ pretty = true; \ name = ECF gRPC Distribution Provider - + +-plugin.repository: \ + aQute.bnd.repository.p2.provider.P2Repository;\ + name="Eclipse Local";\ + url="file:///c:/eclipse.4.28/eclipse/";\ + location="${workspace}/cnf/cache/stable/EclipseLocal" -runsystemcapabilities.dflt: ${native_capability} debug-bundles: \ diff --git a/org.eclipse.ecf.provider.etcd3/.classpath b/org.eclipse.ecf.provider.etcd3/.classpath index 0724e33..39a4e32 100644 --- a/org.eclipse.ecf.provider.etcd3/.classpath +++ b/org.eclipse.ecf.provider.etcd3/.classpath @@ -6,8 +6,9 @@ - - - + + + + diff --git a/org.eclipse.ecf.provider.etcd3/bnd.bnd b/org.eclipse.ecf.provider.etcd3/bnd.bnd index e8d296e..dbdb01b 100644 --- a/org.eclipse.ecf.provider.etcd3/bnd.bnd +++ b/org.eclipse.ecf.provider.etcd3/bnd.bnd @@ -26,15 +26,30 @@ org.eclipse.equinox.concurrent,\ wrapped.com.google.protobuf.protobuf-java,\ slf4j.api,\ - reactive-streams + reactive-streams,\ + osgi.core,\ + org.osgi.service.component.annotations,\ + biz.aQute.launchpad +target-dir generated${if;${driver;eclipse};;/${driver}} +src src/main/java, src/main/resources, src-gen/main/java +testsrc src/test/java +bin target/classes +testbin target/test-classes + +-testpath: \ + osgi.enroute.junit.wrapper, \ + biz.aQute.launchpad + +-tester: biz.aQute.tester.junit-platform + javac.source=17 javac.target=17 package-version = 1.0.2 -Bundle-Version: 1.2.0.${tstamp} +Bundle-Version: 1.3.0.${tstamp} --runfw: org.apache.felix.framework;version='[7.0.0,7.0.0]' +-runfw: org.apache.felix.framework;version='[7.0.5,7.0.5]' -runee: JavaSE-17 Import-Package: com.google.common.util.concurrent;version="26.0", org.osgi.framework, * @@ -50,5 +65,125 @@ Export-Package: \ org.eclipse.ecf.provider.etcd3.grpc.api.auth,\ org.eclipse.ecf.provider.etcd3.identity,\ org.eclipse.ecf.provider.etcd3.grpc.client,\ - org.eclipse.ecf.provider.etcd3.container + org.eclipse.ecf.provider.etcd3.container,\ + org.eclipse.ecf.provider.etcd3.test -privatepackage: org.eclipse.ecf.provider.etcd3 + +-runrequires: \ + bnd.identity;id='org.apache.aries.spifly.dynamic.bundle',\ + bnd.identity;id='org.eclipse.ecf.provider.grpc',\ + bnd.identity;id='org.eclipse.ecf.provider.grpc.console',\ + osgi.identity;filter:='(osgi.identity=org.eclipse.ecf.osgi.services.distribution)',\ + osgi.identity;filter:='(osgi.identity=org.eclipse.ecf.provider.etcd3)',\ + osgi.identity;filter:='(osgi.identity=org.eclipse.ecf.osgi.services.remoteserviceadmin.console)',\ + osgi.identity;filter:='(osgi.identity=org.apache.felix.log)',\ + osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)',\ + osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\ + bnd.identity;id='org.apache.felix.eventadmin',\ + osgi.identity;filter:='(osgi.identity=org.eclipse.ecf.provider.etcd3)',\ + bnd.identity;id='io.netty.resolver',\ + bnd.identity;id='io.netty.codec-http2',\ + bnd.identity;id='io.netty.transport',\ + bnd.identity;id='io.netty.handler-proxy',\ + bnd.identity;id='io.netty.codec-socks',\ + bnd.identity;id='wrapped.io.grpc.grpc-netty',\ + bnd.identity;id='wrapped.io.grpc.grpc-api',\ + bnd.identity;id='wrapped.com.google.errorprone.error_prone_annotations',\ + bnd.identity;id='wrapped.io.grpc.grpc-services',\ + bnd.identity;id='wrapped.io.grpc.grpc-protobuf-lite',\ + bnd.identity;id='wrapped.io.perfmark.perfmark-api',\ + bnd.identity;id='wrapped.org.apache.tomcat.annotations-api',\ + bnd.identity;id='wrapped.org.codehaus.mojo.animal-sniffer-annotations',\ + bnd.identity;id=junit-platform-commons,\ + bnd.identity;id=junit-platform-engine,\ + bnd.identity;id=junit-platform-launcher,\ + bnd.identity;id=junit-platform-runner,\ + bnd.identity;id=junit-platform-suite-api,\ + bnd.identity;id=junit-platform-suite-commons,\ + bnd.identity;id=junit-platform-suite-engine + +-runstartlevel: \ + order = leastdependencieslast, \ + begin = 1 + +-runvm: -Decf.discovery.etcd3.usePlaintext=true\n\ + -Decf.discovery.etcd3.hostname=localhost\n\ + -Decf.discovery.etcd3.port=2379 +-runprogramargs: console consoleLog +-runbundles: \ + wrapped.org.codehaus.mojo.animal-sniffer-annotations;version='[1.23.0,1.23.1)';startlevel=1,\ + org.eclipse.ecf.provider.grpc.console;version='[1.0.3,1.0.4)';startlevel=11,\ + org.eclipse.ecf.provider.grpc;version='[1.5.2,1.5.3)';startlevel=21,\ + wrapped.io.grpc.grpc-services;version='[1.54.0,1.54.1)';startlevel=31,\ + wrapped.io.grpc.grpc-core;version='[1.54.0,1.54.1)';startlevel=41,\ + wrapped.io.grpc.grpc-api;version='[1.54.0,1.54.1)';startlevel=51,\ + wrapped.io.grpc.grpc-netty;version='[1.54.0,1.54.1)';startlevel=61,\ + wrapped.io.perfmark.perfmark-api;version='[0.26.0,0.26.1)';startlevel=71,\ + wrapped.com.google.errorprone.error_prone_annotations;version='[2.9.0,2.9.1)';startlevel=81,\ + org.eclipse.ecf.provider.etcd3;version=snapshot;startlevel=91,\ + wrapped.io.grpc.grpc-protobuf;version='[1.54.0,1.54.1)';startlevel=101,\ + wrapped.io.grpc.grpc-protobuf-lite;version='[1.54.0,1.54.1)';startlevel=111,\ + wrapped.com.google.protobuf.protobuf-java;version='[3.22.2,3.22.3)';startlevel=121,\ + org.json;version='[1.0.0,1.0.1)';startlevel=131,\ + org.apache.felix.scr;version='[2.2.10,2.2.11)';startlevel=141,\ + org.osgi.service.component;version='[1.5.1,1.5.2)';startlevel=151,\ + com.salesforce.servicelibs.rx3grpc-stub;version='[1.2.4,1.2.5)';startlevel=161,\ + io.reactivex.rxjava3.rxjava;version='[3.1.6,3.1.7)';startlevel=171,\ + com.salesforce.servicelibs.reactive-grpc-common;version='[1.2.4,1.2.5)';startlevel=181,\ + wrapped.io.grpc.grpc-stub;version='[1.54.0,1.54.1)';startlevel=191,\ + wrapped.org.apache.tomcat.annotations-api;version='[6.0.53,6.0.54)';startlevel=201,\ + wrapped.io.grpc.grpc-context;version='[1.54.0,1.54.1)';startlevel=211,\ + reactive-streams;version='[1.0.4,1.0.5)';startlevel=221,\ + com.google.guava;version='[31.1.0,31.1.1)';startlevel=231,\ + com.google.guava.failureaccess;version='[1.0.2,1.0.3)';startlevel=241,\ + biz.aQute.launchpad;version='[7.0.0,7.0.1)';startlevel=251,\ + slf4j.simple;version='[2.0.9,2.0.10)';startlevel=261,\ + slf4j.api;version='[2.0.13,2.0.14)';startlevel=271,\ + biz.aQute.bnd.util;version='[7.1.0,7.1.1)';startlevel=281,\ + org.eclipse.ecf.osgi.services.remoteserviceadmin.console;version='[1.3.1,1.3.2)';startlevel=291,\ + org.eclipse.ecf.console;version='[1.4.0,1.4.1)';startlevel=301,\ + org.eclipse.ecf.osgi.services.distribution;version='[2.1.700,2.1.701)';startlevel=311,\ + org.eclipse.ecf.osgi.services.remoteserviceadmin;version='[4.9.3,4.9.4)';startlevel=321,\ + org.osgi.service.remoteserviceadmin;version='[1.1.0,1.1.1)';startlevel=331,\ + org.eclipse.ecf.remoteservice;version='[8.14.0,8.14.1)';startlevel=341,\ + org.eclipse.ecf.remoteservice.asyncproxy;version='[2.1.200,2.1.201)';startlevel=351,\ + osgi.promise;version='[8.1.0,8.1.1)';startlevel=361,\ + org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy;version='[1.0.102,1.0.103)';startlevel=371,\ + org.eclipse.ecf.discovery;version='[5.2.0,5.2.1)';startlevel=381,\ + org.eclipse.ecf;version='[3.11.0,3.11.1)';startlevel=391,\ + org.eclipse.equinox.concurrent;version='[1.2.200,1.2.201)';startlevel=401,\ + org.eclipse.core.jobs;version='[3.15.100,3.15.101)';startlevel=411,\ + org.eclipse.ecf.identity;version='[3.10.0,3.10.1)';startlevel=421,\ + org.eclipse.equinox.common;version='[3.15.100,3.15.101)';startlevel=431,\ + org.eclipse.equinox.supplement;version='[1.10.700,1.10.701)';startlevel=441,\ + org.apache.felix.gogo.shell;version='[1.1.4,1.1.5)';startlevel=451,\ + org.apache.felix.gogo.command;version='[1.1.2,1.1.3)';startlevel=461,\ + org.apache.felix.gogo.runtime;version='[1.1.6,1.1.7)';startlevel=471,\ + org.apache.felix.eventadmin;version='[1.6.4,1.6.5)';startlevel=481,\ + org.apache.felix.log;version='[1.3.0,1.3.1)';startlevel=491,\ + org.apache.aries.spifly.dynamic.bundle;version='[1.3.7,1.3.8)';startlevel=2,\ + org.objectweb.asm.util;version='[9.7.0,9.7.1)';startlevel=511,\ + org.objectweb.asm.tree.analysis;version='[9.7.0,9.7.1)';startlevel=521,\ + org.objectweb.asm.commons;version='[9.7.0,9.7.1)';startlevel=531,\ + org.objectweb.asm.tree;version='[9.7.0,9.7.1)';startlevel=541,\ + org.objectweb.asm;version='[9.7.0,9.7.1)';startlevel=551,\ + junit-platform-suite-engine;version='[1.9.3,1.9.4)';startlevel=561,\ + junit-platform-runner;version='[1.9.3,1.9.4)';startlevel=571,\ + org.junit;version='[4.13.2,4.13.3)';startlevel=581,\ + org.hamcrest.core;version='[1.3.0,1.3.1)';startlevel=591,\ + junit-platform-suite-commons;version='[1.9.3,1.9.4)';startlevel=601,\ + junit-platform-suite-api;version='[1.9.3,1.9.4)';startlevel=611,\ + junit-platform-launcher;version='[1.9.3,1.9.4)';startlevel=621,\ + junit-platform-engine;version='[1.9.3,1.9.4)';startlevel=631,\ + org.opentest4j;version='[1.2.0,1.2.1)';startlevel=641,\ + junit-platform-commons;version='[1.9.3,1.9.4)';startlevel=651,\ + io.netty.handler-proxy;version='[4.1.68,4.1.69)';startlevel=661,\ + io.netty.codec-socks;version='[4.1.68,4.1.69)';startlevel=671,\ + io.netty.codec-http2;version='[4.1.68,4.1.69)';startlevel=681,\ + io.netty.codec-http;version='[4.1.68,4.1.69)';startlevel=691,\ + io.netty.handler;version='[4.1.68,4.1.69)';startlevel=701,\ + io.netty.codec;version='[4.1.68,4.1.69)';startlevel=711,\ + io.netty.transport;version='[4.1.68,4.1.69)';startlevel=721,\ + io.netty.resolver;version='[4.1.68,4.1.69)';startlevel=731,\ + io.netty.buffer;version='[4.1.68,4.1.69)';startlevel=741,\ + io.netty.common;version='[4.1.68,4.1.69)';startlevel=751 diff --git a/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/Activator.java b/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/Activator.java index 7e7e1b2..4e9046d 100644 --- a/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/Activator.java +++ b/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/Activator.java @@ -8,29 +8,17 @@ ******************************************************************************/ package org.eclipse.ecf.provider.etcd3; -import java.util.Hashtable; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.ecf.core.ContainerConnectException; -import org.eclipse.ecf.core.ContainerCreateException; import org.eclipse.ecf.core.ContainerTypeDescription; import org.eclipse.ecf.core.IContainerFactory; +import org.eclipse.ecf.core.identity.IDFactory; import org.eclipse.ecf.core.identity.Namespace; -import org.eclipse.ecf.core.util.SystemLogService; -import org.eclipse.ecf.discovery.IDiscoveryAdvertiser; -import org.eclipse.ecf.discovery.IDiscoveryLocator; import org.eclipse.ecf.provider.etcd3.container.Etcd3DiscoveryContainer; import org.eclipse.ecf.provider.etcd3.container.Etcd3DiscoveryContainerConfig; import org.eclipse.ecf.provider.etcd3.container.Etcd3DiscoveryContainerInstantiator; import org.eclipse.ecf.provider.etcd3.identity.Etcd3Namespace; -import org.osgi.framework.Bundle; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceFactory; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.log.LogService; import org.osgi.util.tracker.ServiceTracker; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +27,7 @@ public class Activator implements BundleActivator { public static final String PLUGIN_ID = "org.eclipse.ecf.provider.etcd3"; //$NON-NLS-1$ private static final Logger logger = LoggerFactory.getLogger(Activator.class); - + private static Activator plugin; public static Activator getDefault() { @@ -52,7 +40,6 @@ public static BundleContext getContext() { return context; } - private Etcd3DiscoveryContainer container; private ServiceTracker cfTracker; @SuppressWarnings("unchecked") @@ -60,7 +47,10 @@ public void start(BundleContext ctxt) throws Exception { plugin = this; context = ctxt; // Register Namespace - context.registerService(Namespace.class, new Etcd3Namespace(), null); + + Etcd3Namespace.INSTANCE = new Etcd3Namespace(); + context.registerService(Namespace.class, Etcd3Namespace.INSTANCE, null); + IDFactory.getDefault().addNamespace(Etcd3Namespace.INSTANCE); // register ContainerTypeDescription context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(Etcd3DiscoveryContainerInstantiator.NAME, @@ -68,45 +58,7 @@ public void start(BundleContext ctxt) throws Exception { null); // Only create/setup if not explicitly disabled if (!Boolean.parseBoolean(System.getProperty(Etcd3DiscoveryContainerConfig.ETCD_DISABLED_PROP, "false"))) { - logger.debug("starting Etcd3 discovery provider"); - @SuppressWarnings("rawtypes") - final Hashtable props = new Hashtable(); - props.put(IDiscoveryLocator.CONTAINER_NAME, Etcd3DiscoveryContainerInstantiator.NAME); - context.registerService( - new String[] { IDiscoveryAdvertiser.class.getName(), IDiscoveryLocator.class.getName() }, - new ServiceFactory() { - public Etcd3DiscoveryContainer getService(Bundle bundle, - ServiceRegistration registration) { - if (container == null) { - try { - container = (Etcd3DiscoveryContainer) getContainerFactory() - .createContainer(Etcd3DiscoveryContainerInstantiator.NAME); - logger.debug("Etcd3 discovery container created with name="+ Etcd3DiscoveryContainerInstantiator.NAME); - } catch (ContainerCreateException e) { - logger.error("Could not create Etcd3 discovery="+ Etcd3DiscoveryContainerInstantiator.NAME, e); - container = null; - } - } - // Connect - try { - container.connect(null, null); - logger.debug("Etcd3 discovery container connected with name="+ Etcd3DiscoveryContainerInstantiator.NAME); - } catch (ContainerConnectException e) { - logger.error("Could not connect Etcd3 discovery="+ Etcd3DiscoveryContainerInstantiator.NAME, e); - container = null; - } - return container; - } - - public void ungetService(Bundle bundle, - ServiceRegistration registration, - Etcd3DiscoveryContainer service) { - if (container != null) { - container.disconnect(); - container = null; - } - } - }, props); + context.registerService(new String[] { Etcd3DiscoveryContainerConfig.class.getName()},Etcd3DiscoveryContainerConfig.newBuilder().build(),null); } else { logger.debug("Etcd3 discovery provider DISABLED"); } @@ -121,14 +73,4 @@ public void stop(BundleContext context) throws Exception { plugin = null; } - @SuppressWarnings("unchecked") - IContainerFactory getContainerFactory() { - if (cfTracker == null) { - cfTracker = new ServiceTracker(context, IContainerFactory.class, - null); - cfTracker.open(); - } - return (IContainerFactory) cfTracker.getService(); - } - } diff --git a/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/container/Etcd3DiscoveryContainer.java b/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/container/Etcd3DiscoveryContainer.java index ccd98db..30454f8 100644 --- a/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/container/Etcd3DiscoveryContainer.java +++ b/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/container/Etcd3DiscoveryContainer.java @@ -302,6 +302,7 @@ public void subscribe(FlowableEmitter emitter) throws Exception { ContainerConnectException e1 = new ContainerConnectException( "Cannot connect to Etcd3 server "+ uri, e); e1.setStackTrace(e.getStackTrace()); + logEtcdError("connect","Etcd3 connection error", e); throw e1; } diff --git a/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/container/Etcd3DiscoveryContainerConfig.java b/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/container/Etcd3DiscoveryContainerConfig.java index 32deb27..59cb8cb 100644 --- a/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/container/Etcd3DiscoveryContainerConfig.java +++ b/org.eclipse.ecf.provider.etcd3/src/main/java/org/eclipse/ecf/provider/etcd3/container/Etcd3DiscoveryContainerConfig.java @@ -16,11 +16,13 @@ import org.eclipse.ecf.core.identity.IDFactory; import org.eclipse.ecf.discovery.DiscoveryContainerConfig; import org.eclipse.ecf.discovery.identity.ServiceIDFactory; +import org.eclipse.ecf.provider.etcd3.Activator; import org.eclipse.ecf.provider.etcd3.identity.Etcd3Namespace; import org.eclipse.ecf.provider.etcd3.identity.Etcd3ServiceID; import io.grpc.Channel; import io.grpc.ManagedChannelBuilder; +import org.osgi.util.tracker.ServiceTracker; public class Etcd3DiscoveryContainerConfig extends DiscoveryContainerConfig { diff --git a/org.eclipse.ecf.provider.etcd3/src/test/java/org/eclipse/ecf/provider/etcd3/test/TestMyCode.java b/org.eclipse.ecf.provider.etcd3/src/test/java/org/eclipse/ecf/provider/etcd3/test/TestMyCode.java new file mode 100644 index 0000000..2f01c60 --- /dev/null +++ b/org.eclipse.ecf.provider.etcd3/src/test/java/org/eclipse/ecf/provider/etcd3/test/TestMyCode.java @@ -0,0 +1,22 @@ +package org.eclipse.ecf.provider.etcd3.test; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import aQute.launchpad.Launchpad; +import aQute.launchpad.LaunchpadBuilder; +import aQute.launchpad.Service; +import aQute.launchpad.junit.LaunchpadRunner; +@RunWith(LaunchpadRunner.class) +public class TestMyCode extends junit.framework.TestCase { + + LaunchpadBuilder builder = new LaunchpadBuilder().runfw("org.apache.felix.framework").debug(); + + @Service + Launchpad launchpad; + + @Test + public void testMyCode() throws Exception { + launchpad.report(); + } +} \ No newline at end of file