This is an automated email from the ASF dual-hosted git repository. amichair pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/aries-rsa.git
commit d924b2c3b05101958b2d89321e71c32df78b1843 Author: Amichai Rothman <[email protected]> AuthorDate: Thu Apr 30 01:58:56 2026 +0300 ARIES-2206 Delete redundant eapub module (EventAdmin publishing is already implemented in rsa core module's EventAdminSender) --- eapub/Readme.md | 3 - eapub/bnd.bnd | 18 -- eapub/pom.xml | 45 ----- .../java/org/apache/aries/rsa/eapub/Activator.java | 39 ---- .../apache/aries/rsa/eapub/EventAdminHelper.java | 151 ---------------- .../aries/rsa/eapub/EventAdminHelperTest.java | 196 --------------------- features/src/main/resources/features.xml | 1 - pom.xml | 1 - 8 files changed, 454 deletions(-) diff --git a/eapub/Readme.md b/eapub/Readme.md deleted file mode 100644 index 5fd3dbf9..00000000 --- a/eapub/Readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# Remote Service Admin EventAdmin Publisher - -Is used to publish EventAdmin events for Remote Service Admin events notifications. diff --git a/eapub/bnd.bnd b/eapub/bnd.bnd deleted file mode 100644 index c8925571..00000000 --- a/eapub/bnd.bnd +++ /dev/null @@ -1,18 +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. -Bundle-Activator: org.apache.aries.rsa.eapub.Activator diff --git a/eapub/pom.xml b/eapub/pom.xml deleted file mode 100644 index 04738044..00000000 --- a/eapub/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ -<?xml version='1.0' encoding='UTF-8' ?> -<!-- - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.aries.rsa</groupId> - <artifactId>org.apache.aries.rsa.parent</artifactId> - <version>2.0.0-SNAPSHOT</version> - <relativePath>../parent/pom.xml</relativePath> - </parent> - <artifactId>org.apache.aries.rsa.eapub</artifactId> - <packaging>jar</packaging> - <name>Aries Remote Service Admin Event Publisher</name> - <description>The Remote Service Event Admin Publisher</description> - - <properties> - <topDirectoryLocation>..</topDirectoryLocation> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.aries.rsa</groupId> - <artifactId>org.apache.aries.rsa.spi</artifactId> - <scope>provided</scope> - </dependency> - </dependencies> - -</project> \ No newline at end of file diff --git a/eapub/src/main/java/org/apache/aries/rsa/eapub/Activator.java b/eapub/src/main/java/org/apache/aries/rsa/eapub/Activator.java deleted file mode 100644 index e1a8df5c..00000000 --- a/eapub/src/main/java/org/apache/aries/rsa/eapub/Activator.java +++ /dev/null @@ -1,39 +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.eapub; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener; - -public class Activator implements BundleActivator { - - private ServiceRegistration<RemoteServiceAdminListener> registration; - - public void start(BundleContext bundlecontext) throws Exception { - registration = bundlecontext.registerService( - RemoteServiceAdminListener.class, new EventAdminHelper(bundlecontext), null); - } - - public void stop(BundleContext context) throws Exception { - registration.unregister(); - } - -} diff --git a/eapub/src/main/java/org/apache/aries/rsa/eapub/EventAdminHelper.java b/eapub/src/main/java/org/apache/aries/rsa/eapub/EventAdminHelper.java deleted file mode 100644 index 88c19be6..00000000 --- a/eapub/src/main/java/org/apache/aries/rsa/eapub/EventAdminHelper.java +++ /dev/null @@ -1,151 +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.eapub; - -import java.util.HashMap; -import java.util.Map; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.Version; -import org.osgi.service.event.Event; -import org.osgi.service.event.EventAdmin; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class EventAdminHelper implements RemoteServiceAdminListener { - - private static final Logger LOG = LoggerFactory.getLogger(EventAdminHelper.class); - - private BundleContext bctx; - - public EventAdminHelper(BundleContext bc) { - bctx = bc; - } - - private Event createEvent(Map<String, Object> props, String type) { - String topic = "org/osgi/service/remoteserviceadmin/" + type; - props.put("bundle", bctx.getBundle()); - props.put("bundle.id", bctx.getBundle().getBundleId()); - props.put("bundle.symbolicname", bctx.getBundle().getSymbolicName()); - - String version = bctx.getBundle().getHeaders().get("Bundle-Version"); - Version v = version != null ? new Version(version) : Version.emptyVersion; - setIfNotNull(props, "bundle.version", v); - - return new Event(topic, props); - } - - @Override - public void remoteAdminEvent(RemoteServiceAdminEvent rsae) { - String topic = remoteServiceAdminEventTypeToString(rsae.getType()); - - Map<String, Object> props = new HashMap<>(); - setIfNotNull(props, "cause", rsae.getException()); - - EndpointDescription endpoint = null; - if (rsae.getImportReference() != null) { - endpoint = rsae.getImportReference().getImportedEndpoint(); - setIfNotNull(props, "import.registration", endpoint); - } else if (rsae.getExportReference() != null) { - endpoint = rsae.getExportReference().getExportedEndpoint(); - setIfNotNull(props, "export.registration", endpoint); - } - - if (endpoint != null) { - setIfNotNull(props, "service.remote.id", endpoint.getServiceId()); - setIfNotNull(props, "service.remote.uuid", endpoint.getFrameworkUUID()); - setIfNotNull(props, "service.remote.uri", endpoint.getId()); - setIfNotNull(props, "objectClass", endpoint.getInterfaces().toArray(new String[0])); - setIfNotNull(props, "service.imported.configs", endpoint.getConfigurationTypes()); - } - props.put("timestamp", System.currentTimeMillis()); - props.put("event", rsae); - - Event event = createEvent(props, topic); - notifyEventAdmins(topic, event); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - private void notifyEventAdmins(String topic, Event event) { - ServiceReference[] refs = null; - try { - refs = bctx.getAllServiceReferences(EventAdmin.class.getName(), null); - } catch (InvalidSyntaxException e) { - LOG.error("Failed to get EventAdmin: {}", e.getMessage(), e); - } - - if (refs != null) { - LOG.debug("Publishing event to {} EventAdmins; Topic:[{}]", refs.length, topic); - for (ServiceReference serviceReference : refs) { - EventAdmin eventAdmin = (EventAdmin) bctx.getService(serviceReference); - try { - eventAdmin.postEvent(event); - } finally { - if (eventAdmin != null) { - bctx.ungetService(serviceReference); - } - } - } - } - } - - private <K, V> void setIfNotNull(Map<K, V> map, K key, V val) { - if (val != null) { - map.put(key, val); - } - } - - private static String remoteServiceAdminEventTypeToString(int type) { - String retval; - switch (type) { - case RemoteServiceAdminEvent.EXPORT_ERROR: - retval = "EXPORT_ERROR"; - break; - case RemoteServiceAdminEvent.EXPORT_REGISTRATION: - retval = "EXPORT_REGISTRATION"; - break; - case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION: - retval = "EXPORT_UNREGISTRATION"; - break; - case RemoteServiceAdminEvent.EXPORT_WARNING: - retval = "EXPORT_WARNING"; - break; - case RemoteServiceAdminEvent.IMPORT_ERROR: - retval = "IMPORT_ERROR"; - break; - case RemoteServiceAdminEvent.IMPORT_REGISTRATION: - retval = "IMPORT_REGISTRATION"; - break; - case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION: - retval = "IMPORT_UNREGISTRATION"; - break; - case RemoteServiceAdminEvent.IMPORT_WARNING: - retval = "IMPORT_WARNING"; - break; - default: - retval = "UNKNOWN_EVENT"; - } - return retval; - } -} diff --git a/eapub/src/test/java/org/apache/aries/rsa/eapub/EventAdminHelperTest.java b/eapub/src/test/java/org/apache/aries/rsa/eapub/EventAdminHelperTest.java deleted file mode 100644 index 0965b164..00000000 --- a/eapub/src/test/java/org/apache/aries/rsa/eapub/EventAdminHelperTest.java +++ /dev/null @@ -1,196 +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.eapub; - -import java.util.Arrays; -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.List; -import java.util.UUID; - -import org.easymock.EasyMock; -import org.easymock.IAnswer; -import org.junit.Assert; -import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.Version; -import org.osgi.service.event.Event; -import org.osgi.service.event.EventAdmin; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.ExportReference; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class EventAdminHelperTest { - - @Test - public void testPublishNotification() throws Exception { - final EndpointDescription epd = EasyMock.createNiceMock(EndpointDescription.class); - EasyMock.expect(epd.getServiceId()).andReturn(Long.MAX_VALUE).anyTimes(); - final String uuid = UUID.randomUUID().toString(); - EasyMock.expect(epd.getFrameworkUUID()).andReturn(uuid).anyTimes(); - EasyMock.expect(epd.getId()).andReturn("foo://bar").anyTimes(); - final List<String> interfaces = Arrays.asList("org.foo.Bar", "org.boo.Far"); - EasyMock.expect(epd.getInterfaces()).andReturn(interfaces).anyTimes(); - EasyMock.expect(epd.getConfigurationTypes()).andReturn(Arrays.asList("org.apache.cxf.ws")).anyTimes(); - EasyMock.replay(epd); - final ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.replay(sref); - final ExportReference er = EasyMock.createNiceMock(ExportReference.class); - EasyMock.expect(er.getExportedEndpoint()).andReturn(epd).anyTimes(); - EasyMock.expect(er.getExportedService()).andReturn(sref).anyTimes(); - EasyMock.replay(er); - - final Bundle bundle = EasyMock.createNiceMock(Bundle.class); - EasyMock.expect(bundle.getBundleId()).andReturn(42L).anyTimes(); - EasyMock.expect(bundle.getSymbolicName()).andReturn("test.bundle").anyTimes(); - Dictionary<String, String> headers = new Hashtable<>(); - headers.put("Bundle-Version", "1.2.3.test"); - EasyMock.expect(bundle.getHeaders()).andReturn(headers).anyTimes(); - EasyMock.replay(bundle); - - EventAdmin ea = EasyMock.createNiceMock(EventAdmin.class); - ea.postEvent(EasyMock.anyObject()); - EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { - @Override - public Object answer() throws Throwable { - Event event = (Event) EasyMock.getCurrentArguments()[0]; - - Assert.assertEquals("org/osgi/service/remoteserviceadmin/EXPORT_REGISTRATION", event.getTopic()); - Assert.assertSame(bundle, event.getProperty("bundle")); - Assert.assertEquals(42L, event.getProperty("bundle.id")); - Assert.assertEquals("test.bundle", event.getProperty("bundle.symbolicname")); - Assert.assertEquals(new Version(1, 2, 3, "test"), event.getProperty("bundle.version")); - Assert.assertNull(event.getProperty("cause")); - Assert.assertEquals(epd, event.getProperty("export.registration")); - - Assert.assertEquals(Long.MAX_VALUE, event.getProperty("service.remote.id")); - Assert.assertEquals(uuid, event.getProperty("service.remote.uuid")); - Assert.assertEquals("foo://bar", event.getProperty("service.remote.uri")); - Assert.assertArrayEquals(interfaces.toArray(new String[]{}), - (String[]) event.getProperty("objectClass")); - - Assert.assertNotNull(event.getProperty("timestamp")); - - RemoteServiceAdminEvent rsae = (RemoteServiceAdminEvent) event.getProperty("event"); - Assert.assertNull(rsae.getException()); - Assert.assertEquals(RemoteServiceAdminEvent.EXPORT_REGISTRATION, rsae.getType()); - Assert.assertSame(bundle, rsae.getSource()); - ExportReference er = rsae.getExportReference(); - Assert.assertSame(epd, er.getExportedEndpoint()); - Assert.assertSame(sref, er.getExportedService()); - - return null; - } - }); - EasyMock.replay(ea); - - ServiceReference eaSref = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.replay(eaSref); - - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - EasyMock.expect(bc.getBundle()).andReturn(bundle).anyTimes(); - EasyMock.expect(bc.getAllServiceReferences(EventAdmin.class.getName(), null)) - .andReturn(new ServiceReference[] {eaSref}).anyTimes(); - EasyMock.expect(bc.getService(eaSref)).andReturn(ea).anyTimes(); - EasyMock.replay(bc); - - RemoteServiceAdminEvent event = new RemoteServiceAdminEvent( - RemoteServiceAdminEvent.EXPORT_REGISTRATION, - bundle, - er, - null - ); - new EventAdminHelper(bc).remoteAdminEvent(event); - EasyMock.verify(epd, sref, er, ea, eaSref, bc); - } - - @Test - public void testPublishErrorNotification() throws Exception { - final EndpointDescription epd = EasyMock.createNiceMock(EndpointDescription.class); - EasyMock.expect(epd.getInterfaces()).andReturn(Arrays.asList("org.foo.Bar")).anyTimes(); - EasyMock.replay(epd); - final ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.replay(sref); - final ExportReference er = EasyMock.createNiceMock(ExportReference.class); - EasyMock.expect(er.getExportedEndpoint()).andReturn(epd).anyTimes(); - EasyMock.expect(er.getExportedService()).andReturn(sref).anyTimes(); - EasyMock.replay(er); - - final Bundle bundle = EasyMock.createNiceMock(Bundle.class); - EasyMock.expect(bundle.getBundleId()).andReturn(42L).anyTimes(); - EasyMock.expect(bundle.getSymbolicName()).andReturn("test.bundle").anyTimes(); - EasyMock.expect(bundle.getHeaders()).andReturn(new Hashtable<>()).anyTimes(); - EasyMock.replay(bundle); - - final Exception exportException = new Exception(); - - EventAdmin ea = EasyMock.createNiceMock(EventAdmin.class); - ea.postEvent(EasyMock.anyObject()); - EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { - @Override - public Object answer() throws Throwable { - Event event = (Event) EasyMock.getCurrentArguments()[0]; - - Assert.assertEquals("org/osgi/service/remoteserviceadmin/EXPORT_ERROR", event.getTopic()); - Assert.assertSame(bundle, event.getProperty("bundle")); - Assert.assertEquals(42L, event.getProperty("bundle.id")); - Assert.assertEquals("test.bundle", event.getProperty("bundle.symbolicname")); - Assert.assertEquals(new Version("0"), event.getProperty("bundle.version")); - Assert.assertSame(exportException, event.getProperty("cause")); - Assert.assertEquals(epd, event.getProperty("export.registration")); - Assert.assertArrayEquals(new String[]{"org.foo.Bar"}, - (String[]) event.getProperty("objectClass")); - - RemoteServiceAdminEvent rsae = (RemoteServiceAdminEvent) event.getProperty("event"); - Assert.assertSame(exportException, rsae.getException()); - Assert.assertEquals(RemoteServiceAdminEvent.EXPORT_ERROR, rsae.getType()); - Assert.assertSame(bundle, rsae.getSource()); - ExportReference er = rsae.getExportReference(); - Assert.assertSame(epd, er.getExportedEndpoint()); - Assert.assertSame(sref, er.getExportedService()); - - return null; - } - }); - EasyMock.replay(ea); - - ServiceReference eaSref = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.replay(eaSref); - - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - - EasyMock.expect(bc.getBundle()).andReturn(bundle).anyTimes(); - EasyMock.expect(bc.getAllServiceReferences(EventAdmin.class.getName(), null)) - .andReturn(new ServiceReference[] {eaSref}).anyTimes(); - EasyMock.expect(bc.getService(eaSref)).andReturn(ea).anyTimes(); - EasyMock.replay(bc); - - RemoteServiceAdminEvent event = new RemoteServiceAdminEvent( - RemoteServiceAdminEvent.EXPORT_ERROR, - bundle, - er, - exportException - ); - new EventAdminHelper(bc).remoteAdminEvent(event); - EasyMock.verify(epd, sref, er, ea, eaSref, bc); - } -} diff --git a/features/src/main/resources/features.xml b/features/src/main/resources/features.xml index b2abff4d..3c98c196 100644 --- a/features/src/main/resources/features.xml +++ b/features/src/main/resources/features.xml @@ -26,7 +26,6 @@ <bundle>mvn:org.apache.aries.rsa/org.apache.aries.rsa.core/${project.version}</bundle> <bundle>mvn:org.apache.aries.rsa/org.apache.aries.rsa.topology-manager/${project.version}</bundle> <bundle>mvn:org.apache.aries.rsa.discovery/org.apache.aries.rsa.discovery.command/${project.version}</bundle> - <bundle>mvn:org.apache.aries.rsa/org.apache.aries.rsa.eapub/${project.version}</bundle> </feature> <feature name="aries-rsa-provider-tcp" version="${project.version}"> diff --git a/pom.xml b/pom.xml index 108f9cc7..0762c969 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,6 @@ <module>parent</module> <module>spi</module> <module>rsa</module> - <module>eapub</module> <module>topology-manager</module> <module>provider</module> <module>discovery</module>
