--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright © 2021 Orange and others. All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html -->
+<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>binding-parent</artifactId>
+ <version>7.0.5</version>
+ <relativePath />
+ </parent>
+ <groupId>org.opendaylight.transportpce</groupId>
+ <artifactId>transportpce-dmaap-client</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <description>client to send message to Dmaap message router</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>transportpce-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-binding-api</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-proxy-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.inject</groupId>
+ <artifactId>jersey-hk2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.datatype</groupId>
+ <artifactId>jackson-datatype-jsr310</artifactId>
+ </dependency>
+ <!-- Testing dependencies -->
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework</groupId>
+ <artifactId>jersey-test-framework-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.impl;
+
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.transportpce.dmaap.client.listener.NbiNotificationsListenerImpl;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.NbiNotificationsListener;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DmaapClientProvider {
+ private static final Logger LOG = LoggerFactory.getLogger(DmaapClientProvider.class);
+ private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
+ private NotificationService notificationService;
+ private final String baseUrl;
+ private final String username;
+ private final String password;
+
+ public DmaapClientProvider(NotificationService notificationService, String baseUrl,
+ String username, String password) {
+ this.notificationService = notificationService;
+ this.baseUrl = baseUrl;
+ this.username = username;
+ this.password = password;
+ }
+
+ /**
+ * Method called when the blueprint container is created.
+ */
+ public void init() {
+ LOG.info("DmaapClientProvider Session Initiated");
+ listenerRegistration = notificationService.registerNotificationListener(
+ new NbiNotificationsListenerImpl(baseUrl, username, password));
+ }
+
+ /**
+ * Method called when the blueprint container is destroyed.
+ */
+ public void close() {
+ listenerRegistration.close();
+ LOG.info("DmaapClientProvider Closed");
+ }
+
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.listener;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.glassfish.jersey.client.proxy.WebResourceFactory;
+import org.glassfish.jersey.jackson.JacksonFeature;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.opendaylight.transportpce.dmaap.client.resource.EventsApi;
+import org.opendaylight.transportpce.dmaap.client.resource.config.JsonConfigurator;
+import org.opendaylight.transportpce.dmaap.client.resource.model.CreatedEvent;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.NbiNotificationsListener;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NbiNotificationsListenerImpl implements NbiNotificationsListener {
+ private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
+ private String topic = "unauthenticated.TPCE";
+ private EventsApi api;
+
+ public NbiNotificationsListenerImpl(String baseUrl, String username, String password) {
+ LOG.info("Dmaap server {} for user {}", baseUrl, username);
+ Client client = ClientBuilder.newClient();
+ if (username != null && username.isBlank() && password != null && !password.isBlank()) {
+ HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basic(username, password);
+ client.register(authFeature);
+ topic = "authenticated.TPCE";
+ }
+ client.register(new LoggingFeature(java.util.logging.Logger.getLogger(this.getClass().getName())))
+ .register(JacksonFeature.class).register(JsonConfigurator.class);
+ api = WebResourceFactory.newResource(EventsApi.class, client.target(baseUrl));
+
+ }
+
+ @Override
+ public void onPublishNotificationService(PublishNotificationService notification) {
+ try {
+ CreatedEvent response = api.sendEvent(topic, notification);
+ LOG.info("Response received {}", response);
+ } catch (WebApplicationException e) {
+ LOG.warn("Cannot send event {}", notification, e);
+ }
+
+ }
+
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.opendaylight.transportpce.dmaap.client.resource.model.CreatedEvent;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationService;
+
+@Path("/events")
+public interface EventsApi {
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/{topic}")
+ CreatedEvent sendEvent(@PathParam("topic") String topic, PublishNotificationService event);
+
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.config;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import javax.ws.rs.ext.ContextResolver;
+
+public class JsonConfigurator implements ContextResolver<ObjectMapper> {
+
+ private final ObjectMapper mapper;
+
+ public JsonConfigurator() {
+ mapper = new ObjectMapper();
+ mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
+ mapper.registerModule(new JavaTimeModule());
+ mapper.registerModule(new PublishNotificationServiceModule());
+ }
+
+ @Override
+ public ObjectMapper getContext(Class<?> type) {
+ return mapper;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.config;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import java.io.IOException;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.lgx.Lgx;
+
+// This class is a temporary workaround while waiting jackson
+// support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
+public class LgxSerializer extends StdSerializer<Lgx> {
+ private static final long serialVersionUID = 1L;
+
+ public LgxSerializer() {
+ super(Lgx.class);
+ }
+
+ @Override
+ public void serialize(Lgx value, JsonGenerator gen, SerializerProvider provider) throws IOException {
+ if (value != null) {
+ gen.writeStartObject();
+ gen.writeStringField("lgx-port-rack", value.getLgxPortRack());
+ gen.writeStringField("lgx-port-shelf", value.getLgxPortShelf());
+ gen.writeStringField("lgx-device-name", value.getLgxDeviceName());
+ gen.writeStringField("lgx-port-name", value.getLgxPortName());
+ gen.writeEndObject();
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.config;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import java.io.IOException;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.port.Port;
+
+// This class is a temporary workaround while waiting jackson
+// support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
+public class PortSerializer extends StdSerializer<Port> {
+ private static final long serialVersionUID = 1L;
+
+ public PortSerializer() {
+ super(Port.class);
+ }
+
+ @Override
+ public void serialize(Port value, JsonGenerator gen, SerializerProvider provider) throws IOException {
+ if (value != null) {
+ gen.writeStartObject();
+ gen.writeStringField("port-rack", value.getPortRack());
+ gen.writeStringField("port-shelf", value.getPortShelf());
+ gen.writeStringField("port-device-name", value.getPortDeviceName());
+ gen.writeStringField("port-name", value.getPortName());
+ gen.writeStringField("port-type", value.getPortType());
+ gen.writeEndObject();
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.config;
+
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.datatype.jsr310.PackageVersion;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirection;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirection;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.lgx.Lgx;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.port.Port;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.notification.service.ServiceAEnd;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.notification.service.ServiceZEnd;
+
+//This class is a temporary workaround while waiting jackson
+//support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
+public class PublishNotificationServiceModule extends SimpleModule {
+
+ private static final long serialVersionUID = 1L;
+
+ public PublishNotificationServiceModule() {
+ super(PackageVersion.VERSION);
+ addSerializer(PublishNotificationService.class, new PublishNotificationServiceSerializer());
+ addSerializer(Lgx.class, new LgxSerializer());
+ addSerializer(Port.class, new PortSerializer());
+ addSerializer(RxDirection.class, new RxDirectionSerializer());
+ addSerializer(TxDirection.class, new TxDirectionSerializer());
+ addSerializer(ServiceAEnd.class, new ServiceAEndSerializer());
+ addSerializer(ServiceZEnd.class, new ServiceZEndSerializer());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.config;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import java.io.IOException;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationService;
+
+// This class is a temporary workaround while waiting jackson
+// support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
+public class PublishNotificationServiceSerializer extends StdSerializer<PublishNotificationService> {
+ private static final long serialVersionUID = 1L;
+
+ public PublishNotificationServiceSerializer() {
+ super(PublishNotificationService.class);
+ }
+
+ @Override
+ public void serialize(PublishNotificationService value, JsonGenerator gen, SerializerProvider provider)
+ throws IOException {
+ if (value != null) {
+ gen.writeStartObject();
+ gen.writeStringField("common-id", value.getCommonId());
+ gen.writeStringField("message", value.getMessage());
+ gen.writeStringField("response-failed", value.getResponseFailed());
+ gen.writeStringField("service-name", value.getServiceName());
+ gen.writeStringField("topic", value.getTopic());
+ if (value.getOperationalState() != null) {
+ gen.writeStringField("operational-state", value.getOperationalState().getName());
+ }
+ gen.writeObjectField("service-a-end", value.getServiceAEnd());
+ gen.writeObjectField("service-z-end", value.getServiceZEnd());
+ gen.writeEndObject();
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.config;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import java.io.IOException;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirection;
+
+// This class is a temporary workaround while waiting jackson
+// support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
+public class RxDirectionSerializer extends StdSerializer<RxDirection> {
+ private static final long serialVersionUID = 1L;
+
+ public RxDirectionSerializer() {
+ super(RxDirection.class);
+ }
+
+ @Override
+ public void serialize(RxDirection value, JsonGenerator gen, SerializerProvider provider) throws IOException {
+ if (value != null) {
+ gen.writeStartObject();
+ if (value.getPort() != null) {
+ gen.writeObjectField("port", value.getPort());
+ }
+ if (value.getLgx() != null) {
+ gen.writeObjectField("lgx", value.getLgx());
+ }
+ gen.writeEndObject();
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.config;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import java.io.IOException;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.notification.service.ServiceAEnd;
+
+// This class is a temporary workaround while waiting jackson
+// support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
+public class ServiceAEndSerializer extends StdSerializer<ServiceAEnd> {
+ private static final long serialVersionUID = 1L;
+
+ public ServiceAEndSerializer() {
+ super(ServiceAEnd.class);
+ }
+
+ @Override
+ public void serialize(ServiceAEnd value, JsonGenerator gen, SerializerProvider provider) throws IOException {
+ if (value != null) {
+ gen.writeStartObject();
+ gen.writeStringField("clli", value.getClli());
+ if (value.getServiceFormat() != null) {
+ gen.writeStringField("service-format", value.getServiceFormat().getName());
+ }
+ if (value.getNodeId() != null) {
+ gen.writeStringField("node-id", value.getNodeId().getValue());
+ }
+ if (value.getServiceRate() != null) {
+ gen.writeNumberField("service-rate", value.getServiceRate().intValue());
+ }
+ if (value.getOpticType() != null) {
+ gen.writeStringField("optic-type", value.getOpticType().getName());
+ }
+ if (value.getTxDirection() != null) {
+ gen.writeObjectField("tx-direction", value.getTxDirection());
+ }
+ if (value.getRxDirection() != null) {
+ gen.writeObjectField("rx-direction", value.getRxDirection());
+ }
+ gen.writeEndObject();
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.config;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import java.io.IOException;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.notification.service.ServiceZEnd;
+
+// This class is a temporary workaround while waiting jackson
+// support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
+public class ServiceZEndSerializer extends StdSerializer<ServiceZEnd> {
+ private static final long serialVersionUID = 1L;
+
+ public ServiceZEndSerializer() {
+ super(ServiceZEnd.class);
+ }
+
+ @Override
+ public void serialize(ServiceZEnd value, JsonGenerator gen, SerializerProvider provider) throws IOException {
+ if (value != null) {
+ gen.writeStartObject();
+ gen.writeStringField("clli", value.getClli());
+ if (value.getServiceFormat() != null) {
+ gen.writeStringField("service-format", value.getServiceFormat().getName());
+ }
+ if (value.getNodeId() != null) {
+ gen.writeStringField("node-id", value.getNodeId().getValue());
+ }
+ if (value.getServiceRate() != null) {
+ gen.writeNumberField("service-rate", value.getServiceRate().intValue());
+ }
+ if (value.getOpticType() != null) {
+ gen.writeStringField("optic-type", value.getOpticType().getName());
+ }
+ if (value.getTxDirection() != null) {
+ gen.writeObjectField("tx-direction", value.getTxDirection());
+ }
+ if (value.getRxDirection() != null) {
+ gen.writeObjectField("rx-direction", value.getRxDirection());
+ }
+ gen.writeEndObject();
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.config;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import java.io.IOException;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirection;
+
+// This class is a temporary workaround while waiting jackson
+// support in yang tools https://git.opendaylight.org/gerrit/c/yangtools/+/94852
+public class TxDirectionSerializer extends StdSerializer<TxDirection> {
+ private static final long serialVersionUID = 1L;
+
+ public TxDirectionSerializer() {
+ super(TxDirection.class);
+ }
+
+ @Override
+ public void serialize(TxDirection value, JsonGenerator gen, SerializerProvider provider) throws IOException {
+ if (value != null) {
+ gen.writeStartObject();
+ if (value.getPort() != null) {
+ gen.writeObjectField("port", value.getPort());
+ }
+ if (value.getLgx() != null) {
+ gen.writeObjectField("lgx", value.getLgx());
+ }
+ gen.writeEndObject();
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class CreatedEvent {
+
+ @JsonProperty("serverTimeMs")
+ private Integer serverTimeMs;
+
+ @JsonProperty("count")
+ private Integer count;
+
+ public Integer getServerTimeMs() {
+ return serverTimeMs;
+ }
+
+ public void setServerTimeMs(Integer serverTimeMs) {
+ this.serverTimeMs = serverTimeMs;
+ }
+
+ public Integer getCount() {
+ return count;
+ }
+
+ public void setCount(Integer count) {
+ this.count = count;
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder()
+ .append("CreatedEvent [serverTimeMs=")
+ .append(serverTimeMs).append(", count=")
+ .append(count).append("]")
+ .toString();
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!-- Copyright © 2021 Orange and others. All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
+ odl:use-default-for-reference-types="true">
+ <cm:property-placeholder persistent-id="org.opendaylight.transportpce.dmaap" update-strategy="reload">
+ <cm:default-properties>
+ <cm:property name="dmaap.baseUrl" value="http://localhost:8080" />
+ <cm:property name="dmaap.username" value="" />
+ <cm:property name="dmaap.password" value="" />
+ </cm:default-properties>
+ </cm:property-placeholder>
+ <reference id="notificationService" interface="org.opendaylight.mdsal.binding.api.NotificationService"/>
+
+ <bean id="provider"
+ class="org.opendaylight.transportpce.dmaap.client.impl.DmaapClientProvider"
+ init-method="init" destroy-method="close">
+ <argument ref="notificationService" />
+ <argument value="${dmaap.baseUrl}"></argument>
+ <argument value="${dmaap.username}"></argument>
+ <argument value="${dmaap.password}"></argument>
+ </bean>
+</blueprint>
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.impl;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.transportpce.dmaap.client.listener.NbiNotificationsListenerImpl;
+
+
+public class DmaapClientProviderTest {
+
+ @Mock
+ private NotificationService notificationService;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.openMocks(this);
+
+ }
+
+ @Test
+ public void testInitRegisterNbiNotificationsToRpcRegistry() {
+ DmaapClientProvider provider = new DmaapClientProvider(notificationService, "http://localhost", "username", "password");
+ provider.init();
+ (verify(notificationService, times(1)))
+ .registerNotificationListener(Mockito.any(NbiNotificationsListenerImpl.class));
+ }
+
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.listener;
+
+import static org.junit.Assert.assertEquals;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
+import java.util.List;
+import javax.ws.rs.core.Application;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.junit.Test;
+import org.opendaylight.transportpce.dmaap.client.resource.EventsApiStub;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.NbiNotificationsListener;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationServiceBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.notification.service.ServiceAEndBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.notification.service.ServiceZEndBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.slf4j.LoggerFactory;
+
+public class NbiNotificationsListenerImplTest extends JerseyTest {
+ @Override
+ protected Application configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+ enable(TestProperties.DUMP_ENTITY);
+ return new ResourceConfig(EventsApiStub.class);
+ }
+
+ @Test
+ public void onPublishNotificationServiceTest() {
+ Logger logger = (Logger) LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
+ ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
+ listAppender.start();
+ logger.addAppender(listAppender);
+ NbiNotificationsListener listener = new NbiNotificationsListenerImpl("http://localhost:9998", null, null);
+ PublishNotificationService notification = new PublishNotificationServiceBuilder().setCommonId("CommonId")
+ .setMessage("Service implemented")
+ .setOperationalState(State.InService)
+ .setTopic("topic")
+ .setConnectionType(ConnectionType.Service)
+ .setServiceAEnd(new ServiceAEndBuilder()
+ .setClli("clli")
+ .setNodeId(new org.opendaylight.yang.gen.v1.http
+ .org.openroadm.common.node.types.rev181130.NodeIdType("nodeidtype"))
+ .setServiceFormat(ServiceFormat.Ethernet)
+ .setServiceRate(Uint32.valueOf(100))
+ .setRxDirection(new RxDirectionBuilder().build())
+ .setTxDirection(new TxDirectionBuilder().build())
+ .build())
+ .setServiceZEnd(new ServiceZEndBuilder()
+ .setClli("clli")
+ .setNodeId(new org.opendaylight.yang.gen.v1.http
+ .org.openroadm.common.node.types.rev181130.NodeIdType("nodeidtype"))
+ .setServiceFormat(ServiceFormat.Ethernet)
+ .setServiceRate(Uint32.valueOf(100))
+ .setRxDirection(new RxDirectionBuilder().build())
+ .setTxDirection(new TxDirectionBuilder().build())
+ .build())
+ .build();
+ listener.onPublishNotificationService(notification);
+ // as onPublishNotificationService is a void method, we check log message to be sur everything went well
+ List<ILoggingEvent> logsList = listAppender.list;
+ assertEquals("Response received CreatedEvent [serverTimeMs=1, count=1]", logsList.get(1).getFormattedMessage());
+
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.dmaap.client.resource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.opendaylight.transportpce.dmaap.client.resource.model.CreatedEvent;
+
+@Path("/events")
+public class EventsApiStub {
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/{topic}")
+ public CreatedEvent sendEvent(@PathParam("topic") String topic, String event) {
+ CreatedEvent response = new CreatedEvent();
+ response.setCount(1);
+ response.setServerTimeMs(1);
+ return response;
+ }
+
+}
<module>servicehandler</module>
<module>tapi</module>
<module>nbinotifications</module>
+ <module>dmaap-client</module>
<module>features</module>
<module>karaf</module>
</modules>