From fa4d2c215cddfbf4cf6648480a959cd8da270fd8 Mon Sep 17 00:00:00 2001 From: Francois Le Droff Date: Fri, 18 Mar 2022 20:14:03 +0100 Subject: [PATCH] merging with master --- aem/README.md | 2 +- aem/events_mgmt_aem/README.md | 20 ++ aem/events_mgmt_aem/pom.xml | 191 ++++++++++++++++++ .../event/management/EventMetadataStatus.java | 47 +++++ .../EventMetadataStatusServlet.java | 33 +++ .../EventMetadataStatusSupplier.java | 19 ++ .../management/EventMetadataSupplier.java | 28 +++ .../EventProviderConfigStatusServlet.java | 33 +++ .../EventProviderConfigSupplier.java | 24 +++ .../EventProviderRegistrationService.java | 28 +++ .../EventProviderRegistrationStatus.java | 33 +++ ...ventProviderRegistrationStatusServlet.java | 33 +++ .../EventMetadataStatusSupplierImpl.java | 80 ++++++++ .../internal/EventMetadataSupplierImpl.java | 74 +++++++ .../EventProviderConfigSupplierImpl.java | 127 ++++++++++++ .../EventProviderRegistrationServiceImpl.java | 136 +++++++++++++ .../management/ocd/ApiManagementConfig.java | 26 +++ .../management/ocd/EventMetadataConfig.java | 35 ++++ .../management/ocd/EventProviderConfig.java | 38 ++++ aem/pom.xml | 4 +- 20 files changed, 1008 insertions(+), 3 deletions(-) create mode 100644 aem/events_mgmt_aem/README.md create mode 100644 aem/events_mgmt_aem/pom.xml create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatus.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatusServlet.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatusSupplier.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataSupplier.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderConfigStatusServlet.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderConfigSupplier.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationService.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationStatus.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationStatusServlet.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventMetadataStatusSupplierImpl.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventMetadataSupplierImpl.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventProviderConfigSupplierImpl.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventProviderRegistrationServiceImpl.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/ApiManagementConfig.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/EventMetadataConfig.java create mode 100644 aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/EventProviderConfig.java diff --git a/aem/README.md b/aem/README.md index 8b9a188e..2d12a75b 100644 --- a/aem/README.md +++ b/aem/README.md @@ -8,7 +8,7 @@ This project is the multi-modules project hosting Adobe I/O Events and AEM conne * [`com.adobe.aio.aem.core`](./core_aem) is a Java OSGI bundle hosting OSGI Components wrapping [`aio-lib-java-core`](../core) and [`aio-lib-java-ims`](../ims) * [`com.adobe.aio.aem.event.management`](./events_mgmt_aem) is a Java OSGI bundle hosting OSGI Components wrapping [`aio-lib-java-events-mgmt`](../events_mgmt_aem) * [`com.adobe.aio.aem.event.publish`](./events_ingress_aem) is a Java OSGI bundle hosting OSGI Components wrapping [`aio-lib-java-events-ingress`](../events_ingress) -* [`aio-aem-events`](./aio-aem-events)] is an AEM package containing all the OSGI bundles listed above, with their default configuration, enabling AEM and Adobe I/O Events integration. +* [`aio-aem-events`](./aio-aem-events) is an AEM package containing all the OSGI bundles listed above, with their default configuration, enabling AEM and Adobe I/O Events integration. ## Builds diff --git a/aem/events_mgmt_aem/README.md b/aem/events_mgmt_aem/README.md new file mode 100644 index 00000000..322c90cc --- /dev/null +++ b/aem/events_mgmt_aem/README.md @@ -0,0 +1,20 @@ +# `com.adobe.aio.aem.event.management` + +`com.adobe.aio.aem.event.management` is a Java OSGI bundle hosting OSGI Components +wrapping [`aio-lib-java-events-mgmt`](../../events_mgmt_aem) + +## Builds + +This Library is build with [maven](https://maven.apache.org/) + +### Contributing + +Contributions are welcomed! Read the [Contributing Guide](../.github/CONTRIBUTING.md) for more +information. + +### Licensing + +This project is licensed under the Apache V2 License. See [LICENSE](../LICENSE.md) for more +information. + + diff --git a/aem/events_mgmt_aem/pom.xml b/aem/events_mgmt_aem/pom.xml new file mode 100644 index 00000000..b6ac8b5d --- /dev/null +++ b/aem/events_mgmt_aem/pom.xml @@ -0,0 +1,191 @@ + + + + 4.0.0 + + + aio-aem + com.adobe + ../pom.xml + 0.0.13-SNAPSHOT + + + com.adobe.aio.aem.event.management + Adobe I/O - AEM Events Management - OSGI bundle + Adobe I/O - AEM Events Management - OSGI bundle + + + + com.adobe.aio.aem.core + com.adobe + provided + ${project.version} + + + aio-lib-java-events-mgmt + com.adobe + provided + ${project.version} + + + + + uber-jar + apis + com.adobe.aem + + + org.apache.sling.servlets.annotations + org.apache.sling + + + jcr + javax.jcr + + + + org.osgi.service.metatype.annotations + org.osgi + + + org.osgi.service.component.annotations + org.osgi + + + org.osgi.service.component + org.osgi + + + org.osgi.service.cm + org.osgi + + + org.osgi.framework + org.osgi + + + org.osgi.annotation.versioning + org.osgi + + + + + + javax.servlet-api + javax.servlet + + + slf4j-api + org.slf4j + + + commons-lang3 + org.apache.commons + + + commons-text + org.apache.commons + + + jackson-databind + com.fasterxml.jackson.core + + + + + junit-dep + junit + + + slf4j-simple + org.slf4j + + + + + + + sling-maven-plugin + org.apache.sling + + + bnd-maven-plugin + + + org.apache.sling.caconfig.bnd-plugin + org.apache.sling + 1.0.2 + + + + + + + + + bnd-process + + bnd-process + + + biz.aQute.bnd + + + bnd-baseline-maven-plugin + + false + + + + + baseline + + baseline + + + biz.aQute.bnd + + + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + org.apache.maven.plugins + + + + + + src/main/resources + true + + + + + diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatus.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatus.java new file mode 100644 index 00000000..8f354bdc --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatus.java @@ -0,0 +1,47 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management; + +import com.adobe.aio.event.management.model.EventMetadata; + +public class EventMetadataStatus { + + private final EventMetadata configuredEventMetadata; + private final EventMetadata registeredEventMetadata; + private final Throwable error; + + public EventMetadataStatus(final EventMetadataSupplier eventMetadataSupplier) { + configuredEventMetadata = eventMetadataSupplier.getConfiguredEventMetadata(); + registeredEventMetadata = eventMetadataSupplier.getRegisteredEventMetadata(); + error = eventMetadataSupplier.getError(); + } + + public EventMetadata getConfiguredEventMetadata() { + return configuredEventMetadata; + } + + public boolean isUp() { + return (error == null && configuredEventMetadata != null && registeredEventMetadata != null); + } + + public EventMetadata getRegisteredEventMetadata() { + return registeredEventMetadata; + } + + public String getError() { + if (error != null) { + return error.getClass().getSimpleName() + ":" + error.getMessage(); + } else { + return null; + } + } +} diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatusServlet.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatusServlet.java new file mode 100644 index 00000000..d8d78b7b --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatusServlet.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management; + +import com.adobe.aio.aem.status.Status; +import com.adobe.aio.aem.status.StatusServlet; +import javax.servlet.Servlet; +import org.apache.sling.servlets.annotations.SlingServletPaths; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +@Component(immediate = true, service = Servlet.class) +@SlingServletPaths("/bin/aio/event_metadata.json") +public class EventMetadataStatusServlet extends StatusServlet { + + @Reference + private EventMetadataStatusSupplier eventMetadataSupplier; + + @Override + public Status getStatus() { + return eventMetadataSupplier.getStatus(); + } +} + diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatusSupplier.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatusSupplier.java new file mode 100644 index 00000000..931b8167 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataStatusSupplier.java @@ -0,0 +1,19 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management; + + +import com.adobe.aio.aem.status.StatusSupplier; + +public interface EventMetadataStatusSupplier extends StatusSupplier { + +} diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataSupplier.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataSupplier.java new file mode 100644 index 00000000..75645d4c --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventMetadataSupplier.java @@ -0,0 +1,28 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management; + +import com.adobe.aio.event.management.model.EventMetadata; + +public interface EventMetadataSupplier { + + /** + * defined in aio-evem-events package default osgi cfg.json file: com.adobe.io.event.management.internal.EventMetadataSupplierImpl-ping.cfg.json + */ + String PING_EVENT_CODE = "ping"; + + EventMetadata getRegisteredEventMetadata(); + + EventMetadata getConfiguredEventMetadata(); + + Throwable getError(); +} diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderConfigStatusServlet.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderConfigStatusServlet.java new file mode 100644 index 00000000..6a232de6 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderConfigStatusServlet.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management; + +import com.adobe.aio.aem.status.Status; +import com.adobe.aio.aem.status.StatusServlet; +import javax.servlet.Servlet; +import org.apache.sling.servlets.annotations.SlingServletPaths; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +@Component(immediate = true, service = Servlet.class) +@SlingServletPaths("/bin/aio/provider_config.json") +public class EventProviderConfigStatusServlet extends StatusServlet { + + @Reference + private EventProviderConfigSupplier eventProviderInputModelSupplier; + + @Override + public Status getStatus() { + return eventProviderInputModelSupplier.getStatus(); + } +} + diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderConfigSupplier.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderConfigSupplier.java new file mode 100644 index 00000000..912092f9 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderConfigSupplier.java @@ -0,0 +1,24 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management; + +import com.adobe.aio.aem.status.StatusSupplier; +import com.adobe.aio.event.management.model.ProviderInputModel; +import java.net.URL; + + +public interface EventProviderConfigSupplier extends StatusSupplier { + + ProviderInputModel getProviderInputModel(); + + URL getRootUrl(); +} diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationService.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationService.java new file mode 100644 index 00000000..a7788632 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationService.java @@ -0,0 +1,28 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management; + +import com.adobe.aio.aem.status.StatusSupplier; +import com.adobe.aio.event.management.model.EventMetadata; +import com.adobe.aio.event.management.model.Provider; + +/** + * AEM has to register against Adobe I/O Events API management, in order to be assigned a + * providerId, and then to be able to register its event metadata + */ +public interface EventProviderRegistrationService extends StatusSupplier { + + Provider getRegisteredProvider(); + + EventMetadata registerEventMetadata(EventMetadata eventMetadata); + +} \ No newline at end of file diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationStatus.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationStatus.java new file mode 100644 index 00000000..03d952d2 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationStatus.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management; + +import com.adobe.aio.aem.status.Status; +import com.adobe.aio.aem.status.StatusServlet; +import javax.servlet.Servlet; +import org.apache.sling.servlets.annotations.SlingServletPaths; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +@Component(immediate = true, service = Servlet.class) +@SlingServletPaths("/bin/aio/provider.json") +public class EventProviderRegistrationStatus extends StatusServlet { + + @Reference + private EventProviderRegistrationService eventProviderRegistrationService; + + @Override + public Status getStatus() { + return eventProviderRegistrationService.getStatus(); + } +} + diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationStatusServlet.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationStatusServlet.java new file mode 100644 index 00000000..212de475 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/EventProviderRegistrationStatusServlet.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management; + +import com.adobe.aio.aem.status.Status; +import com.adobe.aio.aem.status.StatusServlet; +import javax.servlet.Servlet; +import org.apache.sling.servlets.annotations.SlingServletPaths; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +@Component(immediate = true, service = Servlet.class) +@SlingServletPaths("/bin/aio/provider.json") +public class EventProviderRegistrationStatusServlet extends StatusServlet { + + @Reference + private EventProviderRegistrationService eventProviderRegistrationService; + + @Override + public Status getStatus() { + return eventProviderRegistrationService.getStatus(); + } +} + diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventMetadataStatusSupplierImpl.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventMetadataStatusSupplierImpl.java new file mode 100644 index 00000000..a0630cce --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventMetadataStatusSupplierImpl.java @@ -0,0 +1,80 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management.internal; + +import com.adobe.aio.aem.event.management.EventMetadataStatus; +import com.adobe.aio.aem.event.management.EventMetadataStatusSupplier; +import com.adobe.aio.aem.event.management.EventMetadataSupplier; +import com.adobe.aio.aem.status.Status; +import com.adobe.aio.event.management.model.EventMetadata; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Component(property = { + "label = Adobe I/O Events' Event Metadata Status Supplier Service", + "description = Adobe I/O Events' Event Metadata Status Supplier Service" +} +) +public class EventMetadataStatusSupplierImpl implements EventMetadataStatusSupplier { + + private final Logger log = LoggerFactory.getLogger(getClass()); + private final Map eventMetadataStatusByEventCode = new ConcurrentHashMap<>(); + @Reference( + service = EventMetadataSupplier.class, + policy = ReferencePolicy.DYNAMIC, + cardinality = ReferenceCardinality.MULTIPLE, + bind = "bindEventMetadata", + unbind = "unbindEventMetadata") + private volatile List eventMetadataSuppliers; + + protected synchronized void bindEventMetadata( + final EventMetadataSupplier eventMetadataSupplier) { + EventMetadata eventMetadata = eventMetadataSupplier.getConfiguredEventMetadata(); + eventMetadataStatusByEventCode.put(eventMetadata.getEventCode(), + new EventMetadataStatus(eventMetadataSupplier)); + } + + protected void unbindEventMetadata( + final EventMetadataSupplier eventMetadataBuilder) { + log.debug("won't delete I/O event metadata when unbinding/shutting-down"); + } + + @Override + public Status getStatus() { + Map details = new HashMap<>(1); + try { + if (eventMetadataStatusByEventCode.isEmpty()) { + return new Status(Status.INVALID_CONFIG, null, "Missing event metadata configuration"); + } else { + details.putAll(eventMetadataStatusByEventCode); + boolean isUp = eventMetadataStatusByEventCode.values().stream() + .allMatch(EventMetadataStatus::isUp); + return new Status(isUp, details); + } + } catch (Exception e) { + return new Status(Status.DOWN, details, e); + } + } + +} + + + + diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventMetadataSupplierImpl.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventMetadataSupplierImpl.java new file mode 100644 index 00000000..233909a2 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventMetadataSupplierImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management.internal; + +import com.adobe.aio.aem.event.management.EventMetadataSupplier; +import com.adobe.aio.aem.event.management.EventProviderRegistrationService; +import com.adobe.aio.aem.event.management.ocd.EventMetadataConfig; +import com.adobe.aio.event.management.model.EventMetadata; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Component(service = EventMetadataSupplier.class, property = { + "label = Adobe I/O Events' Event Metadata Supplier Service", + "description = Adobe I/O Events' Event Metadata Supplier Service" +} +) +@Designate(ocd = EventMetadataConfig.class, factory = true) +public class EventMetadataSupplierImpl implements EventMetadataSupplier { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Reference + EventProviderRegistrationService eventProviderRegistrationService; + + private EventMetadata configuredEventMetadata; + private EventMetadata registeredEventMetadata; + private Throwable error; + + @Activate + protected void activate(EventMetadataConfig eventMetadataConfig) { + try { + configuredEventMetadata = EventMetadata.builder() + .description(eventMetadataConfig.aio_event_description()) + .label(eventMetadataConfig.aio_event_label()) + .eventCode(eventMetadataConfig.aio_event_code()) + .build(); + registeredEventMetadata = + eventProviderRegistrationService.registerEventMetadata(configuredEventMetadata); + } catch (Exception e) { + log.error("Adobe I/O Events' Event Metadata Supplier Service Activation Error: {}", + e.getMessage(), e); + error = e; + } + } + + @Override + public EventMetadata getRegisteredEventMetadata() { + return registeredEventMetadata; + } + + @Override + public EventMetadata getConfiguredEventMetadata() { + return this.configuredEventMetadata; + } + + @Override + public Throwable getError() { + return this.error; + } + +} diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventProviderConfigSupplierImpl.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventProviderConfigSupplierImpl.java new file mode 100644 index 00000000..9dcaa4f9 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventProviderConfigSupplierImpl.java @@ -0,0 +1,127 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management.internal; + +import com.adobe.aio.aem.event.management.EventProviderConfigSupplier; +import com.adobe.aio.aem.event.management.ocd.EventProviderConfig; +import com.adobe.aio.aem.status.Status; +import com.adobe.aio.aem.util.ResourceResolverWrapper; +import com.adobe.aio.aem.util.ResourceResolverWrapperFactory; +import com.adobe.aio.event.management.model.ProviderInputModel; +import com.adobe.aio.exception.AIOException; +import com.day.cq.commons.Externalizer; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Modified; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Component(service = EventProviderConfigSupplier.class, + property = {"label = Adobe I/O Events' Provider Config Supplier", + "description = Adobe I/O Events' Provider Config Supplier"}) +@Designate(ocd = EventProviderConfig.class) +public class EventProviderConfigSupplierImpl implements EventProviderConfigSupplier { + + static final String AEM_PROVIDER_METADATA_ID = "aem"; + static final String AEM_CLOUD_DOMAIN_SUFFIX = ".adobeaemcloud.com"; + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Reference + Externalizer externalizerService; + + @Reference + private ResourceResolverWrapperFactory resourceResolverWrapperFactory; + + private String externalizerName; + private URL rootUrl; + private ProviderInputModel providerInputModel; + private Throwable error; + + static String getInstanceId(URL url) { + int indexOfAdobeAemCloudDomain = url.getHost().lastIndexOf(AEM_CLOUD_DOMAIN_SUFFIX); + if (indexOfAdobeAemCloudDomain > 1) { + return url.getHost().substring(0, indexOfAdobeAemCloudDomain); + // we are on `aem as a cloud` domain let's use only the specific host prefix + } else if (url.getHost().contains("localhost")) { + // we are on localhost let's make this developer friendly and append the port number + return url.getHost() + url.getPort(); + } else { + return url.getHost(); + } + } + + @Activate + @Modified + protected void activate(EventProviderConfig configuration) { + try { + this.externalizerName = configuration.externalizerName(); + this.rootUrl = resolveRootUrl(); + this.providerInputModel = getProviderInputModel(configuration, rootUrl); + } catch (Exception e) { + log.error("Adobe I/O Events' Provider Config Supplier activation error: {}" + , e.getMessage(), e); + error = e; + } + } + + @Override + public Status getStatus() { + Map details = new HashMap<>(1); + details.put("externalizer_name", externalizerName); + details.put("root_url", rootUrl != null ? rootUrl.toString() : null); + details.put("provider_input_model", providerInputModel); + return new Status(details, error); + } + + @Override + public ProviderInputModel getProviderInputModel() { + return this.providerInputModel; + } + + @Override + public URL getRootUrl() { + return rootUrl; + } + + private URL resolveRootUrl() { + try (ResourceResolverWrapper resourceResolverWrapper = resourceResolverWrapperFactory.getWrapper()) { + return new URL( + externalizerService.externalLink(resourceResolverWrapper.getResolver(), externalizerName, + "/")); + } catch (Exception e) { + throw new AIOException + ("Cannot look up the Adobe I/O Event providers instanceId due to " + e.getMessage(), e); + } + } + + private ProviderInputModel getProviderInputModel( + final EventProviderConfig providerConfig, + final URL rootUrl) { + String instanceId = getInstanceId(rootUrl); + return ProviderInputModel.builder() + .instanceId(instanceId) + .providerMetadataId(AEM_PROVIDER_METADATA_ID) + .label(providerConfig.aio_provider_label().isEmpty() ? instanceId + : providerConfig.aio_provider_label()) + .description(providerConfig.aio_provider_description().isEmpty() ? "AEM " + instanceId + : providerConfig.aio_provider_description()) + .docsUrl(providerConfig.aio_provider_docs_url()) + .build(); + } + +} diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventProviderRegistrationServiceImpl.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventProviderRegistrationServiceImpl.java new file mode 100644 index 00000000..74ec28a7 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/internal/EventProviderRegistrationServiceImpl.java @@ -0,0 +1,136 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management.internal; + + +import com.adobe.aio.aem.auth.JWTAuthInterceptorSupplier; +import com.adobe.aio.aem.event.management.EventProviderConfigSupplier; +import com.adobe.aio.aem.event.management.EventProviderRegistrationService; +import com.adobe.aio.aem.event.management.ocd.ApiManagementConfig; +import com.adobe.aio.aem.status.Status; +import com.adobe.aio.aem.workspace.WorkspaceSupplier; +import com.adobe.aio.event.management.ProviderService; +import com.adobe.aio.event.management.model.EventMetadata; +import com.adobe.aio.event.management.model.Provider; +import com.adobe.aio.exception.AIOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import org.apache.commons.lang3.StringUtils; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.Designate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +@Component(property = { + "label = Adobe I/O Events' Provider Registration Service", + "description = Adobe I/O Events' Provider Provider Registration Servic"}) +@Designate(ocd = ApiManagementConfig.class) +public class EventProviderRegistrationServiceImpl implements EventProviderRegistrationService { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Reference + private WorkspaceSupplier workspaceSupplier; + + @Reference + private JWTAuthInterceptorSupplier jwtAuthInterceptorSupplier; + + @Reference + private EventProviderConfigSupplier eventProviderInputModelSupplier; + + private ProviderService providerService; + private String providerId; + private String apiManagementUrl; + + @Activate + protected void activate(ApiManagementConfig config) { + this.apiManagementUrl = config.aio_api_management_url(); + try { + registerProvider(); + } catch (Exception e) { + log.error("Adobe I/O Events Provider Registration Error: {}", e.getMessage(), e); + } + } + + @Override + public Status getStatus() { + Map details = new HashMap<>(1); + try { + details.put("workspace_status", workspaceSupplier.getStatus()); + details.put("jwt_status", jwtAuthInterceptorSupplier.getStatus()); + details.put("provider_input_status", eventProviderInputModelSupplier.getStatus()); + details.put("api_management_url", this.apiManagementUrl); + //details.put("providers",providerService.getProviders()); + details.put("provider_already_registered", this.isProviderRegistered()); + details.put("provider", this.getRegisteredProvider()); + return new Status(Status.UP, details); + } catch (Exception e) { + return new Status(Status.DOWN, details, e); + } + } + + @Override + public EventMetadata registerEventMetadata(final EventMetadata eventMetadata) { + return getProviderService().createEventMetadata(this.providerId, eventMetadata) + .orElseThrow(() -> new AIOException("Error creating a new Adobe I/O Events Metadata, " + + "your workspace or provider metadata are unknown to Adobe I/O Events." + + " Please check your configurations.")); + //we may get 404 while POST-ing or PUT-ing when metadata are not found + } + + private Provider registerProvider() { + Optional createdProvider = getProviderService().createOrUpdateProvider( + eventProviderInputModelSupplier.getProviderInputModel()); + if (createdProvider.isPresent()) { + this.providerId = createdProvider.get().getId(); + return createdProvider.get(); + } else { //we may get 404 while POST-ing or PUT-ing when metadata are not found + throw new AIOException("Error creating a new Adobe I/O Events Provider, " + + "your workspace or provider metadata are unknown to Adobe I/O Events." + + " Please check your configurations."); + } + } + + @Override + public Provider getRegisteredProvider() { + if (!isProviderRegistered()) { + log.warn("The Adobe I/O Events Provider was not registered yet, trying registering it..."); + return registerProvider(); + } else { + return getProviderService().findProviderById(this.providerId) + .orElseThrow(() -> new AIOException("Error looking up the Adobe I/O Events Provider " + + "previously successfully registered.")); + } + } + + private boolean isProviderRegistered() { + return !StringUtils.isEmpty(this.providerId); + } + + + private ProviderService getProviderService() { + if (this.providerService == null) { + this.providerService = ProviderService.builder() + .authInterceptor(jwtAuthInterceptorSupplier.getJWTAuthInterceptor()) + .workspace(workspaceSupplier.getWorkspace()) + .url(apiManagementUrl) + .build(); + } + return this.providerService; + } + + +} \ No newline at end of file diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/ApiManagementConfig.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/ApiManagementConfig.java new file mode 100644 index 00000000..15d68aa2 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/ApiManagementConfig.java @@ -0,0 +1,26 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management.ocd; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "Adobe I/O Events' API Configuration", + description = "Adobe I/O Events' API Configuration") +public @interface ApiManagementConfig { + + @AttributeDefinition(name = "Adobe API Management URL", + description = "prod: https://api.adobe.io | stage: https://api-stage.adobe.io") + String aio_api_management_url() default "https://api.adobe.io"; + + +} diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/EventMetadataConfig.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/EventMetadataConfig.java new file mode 100644 index 00000000..b4e5aee8 --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/EventMetadataConfig.java @@ -0,0 +1,35 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management.ocd; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "Adobe I/O Events' Event Metadata", + description = "Adobe I/O Events' Event Metadata") +public @interface EventMetadataConfig { + + String EMPTY = ""; + + @AttributeDefinition(name = "Adobe I/O Event Code", + description = "Adobe I/O Event Code (a code unique to your Event provider, i.e. unique to your AEM instance/cluster") + String aio_event_code() default EMPTY; + + @AttributeDefinition(name = "Adobe I/O Event Label", + description = "Adobe I/O Event Label as it will appear on the Adobe I/O Developer Console") + String aio_event_label() default EMPTY; + + @AttributeDefinition(name = "Adobe I/O Event Label", + description = "Adobe I/O Event Description as it will appear on the Adobe I/O Developer Console") + String aio_event_description() default EMPTY; + +} diff --git a/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/EventProviderConfig.java b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/EventProviderConfig.java new file mode 100644 index 00000000..2ccb77bb --- /dev/null +++ b/aem/events_mgmt_aem/src/main/java/com/adobe/aio/aem/event/management/ocd/EventProviderConfig.java @@ -0,0 +1,38 @@ +/* + * Copyright 2017 Adobe. All rights reserved. + * This file is licensed 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 REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.adobe.aio.aem.event.management.ocd; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "Adobe I/O Events' Provider Configuration", + description = "Adobe I/O Events' Provider Configuration") +public @interface EventProviderConfig { + + @AttributeDefinition(name = "AEM Externalizer Name", + description = "AEM Link externalizer name (used to compute the aio provider instanceId") + String externalizerName() default "author"; + + // Event Provider related + @AttributeDefinition(name = "Event Provider Label (Optional)", + description = "Please provide a label of your choice for your Custom Events Provider. If empty, the label will be set using the Externalizer URL") + String aio_provider_label() default ""; + + @AttributeDefinition(name = "Event Provider Description (Optional)", + description = "Please provide a description of your Custom Events Provider. If empty, the description will be set using the Externalizer URL") + String aio_provider_description() default ""; + + @AttributeDefinition(name = "Event Provider Documentation URL (Optional)", + description = "your custom documentation URL") + String aio_provider_docs_url() default "https://developer.adobe.com/events/docs/guides/using/aem/"; + +} \ No newline at end of file diff --git a/aem/pom.xml b/aem/pom.xml index bc8ad071..d225bd94 100644 --- a/aem/pom.xml +++ b/aem/pom.xml @@ -34,8 +34,8 @@ lib_osgi core_aem -