Kafka Integration Application (Fix Javadoc errors + review comments)

1. Refactored the application into two java projects api and app as per convention
2. Deleted the onos-app-gpb project. The proto files are consolidated in the
   incubator-protobuf project as per suggestions.
3. Some code to translate ONOS Event pojo messages to GPB format.
4. Implementation of Subscribe and Unsubscribe APIs.
5. Minor changes due to review comments from 9212 and 9053
6. Refactored the proto fileso that its a 1:1 mapping between the core type to proto message.

Change-Id: I2bcc0de96150f838ccfe9e49293fe61d94062628
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventExporterService.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventExporterService.java
new file mode 100644
index 0000000..e203697
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventExporterService.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2016-present Open Networking Laboratory
+ * Licensed 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.onosproject.kafkaintegration.api;
+
+import org.onosproject.kafkaintegration.api.dto.EventSubscriber;
+import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId;
+import org.onosproject.kafkaintegration.errors.InvalidApplicationException;
+import org.onosproject.kafkaintegration.errors.InvalidGroupIdException;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * APIs for subscribing to Onos Event Messages.
+ */
+@Beta
+public interface EventExporterService {
+
+    /**
+     * Registers the external application to receive events generated in ONOS.
+     *
+     * @param appName Application Name
+     * @return unique consumer group identifier
+     */
+    EventSubscriberGroupId registerListener(String appName);
+
+    /**
+     * Removes the Registered Listener.
+     *
+     * @param appName Application Name
+     */
+    void unregisterListener(String appName);
+
+    /**
+     * Allows registered listener to subscribe for a specific event type.
+     *
+     * @param subscriber Subscription data containing the event type
+     * @throws InvalidGroupIdException
+     * @throws InvalidApplicationException
+     */
+    void subscribe(EventSubscriber subscriber)
+            throws InvalidGroupIdException, InvalidApplicationException;
+
+    /**
+     * Allows the registered listener to unsubscribe for a specific event.
+     *
+     * @param subscriber Subscription data containing the event type
+     * @throws InvalidGroupIdException
+     * @throws InvalidApplicationException
+     */
+    void unsubscribe(EventSubscriber subscriber)
+            throws InvalidGroupIdException, InvalidApplicationException;
+}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/ExportableEventListener.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/ExportableEventListener.java
new file mode 100644
index 0000000..8aae1b7
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/ExportableEventListener.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2016 Open Networking Laboratory
+ * Licensed 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.onosproject.kafkaintegration.api;
+
+import org.onosproject.event.EventListener;
+import org.onosproject.kafkaintegration.api.dto.OnosEvent;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * API for listeners to listen for Events generated by the ONOS event listener.
+ * At present the only listener will be a Kafka Manager or Module whose sole
+ * purpose is to publish the received data to a Kafka message bus.
+ *
+ */
+@Beta
+public interface ExportableEventListener extends EventListener<OnosEvent> {
+
+}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/EventSubscriber.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/EventSubscriber.java
new file mode 100644
index 0000000..95647e7
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/EventSubscriber.java
@@ -0,0 +1,99 @@
+/**
+ * Copyright 2016-present Open Networking Laboratory
+ * Licensed 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.onosproject.kafkaintegration.api.dto;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+
+import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
+
+/**
+ * Representation of a subscription to an event type.
+ *
+ */
+public final class EventSubscriber {
+    private final String appName;
+    private final EventSubscriberGroupId subscriberGroupId;
+    private final Type eventType;
+
+    /**
+     * Creates a new Event Subscriber.
+     *
+     * @param name Application Name
+     * @param groupId Subscriber group id of the application
+     * @param eventType ONOS event type
+     */
+    public EventSubscriber(String name, EventSubscriberGroupId groupId,
+                           Type eventType) {
+        this.appName = checkNotNull(name);
+        this.subscriberGroupId = checkNotNull(groupId);
+        this.eventType = checkNotNull(eventType);
+    }
+
+    /**
+     * Returns the Application Name.
+     *
+     * @return application name
+     */
+    public String appName() {
+        return appName;
+    }
+
+    /**
+     * Returns the Subscriber Group Id.
+     *
+     * @return Subscriber Group Id
+     */
+    public EventSubscriberGroupId subscriberGroupId() {
+        return subscriberGroupId;
+    }
+
+    /**
+     * Returns the Event type.
+     *
+     * @return ONOS Event Type
+     */
+    public Type eventType() {
+        return eventType;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(appName, subscriberGroupId, eventType);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o instanceof EventSubscriber) {
+            EventSubscriber sub = (EventSubscriber) o;
+            if (sub.appName.equals(appName)
+                    && sub.subscriberGroupId.equals(subscriberGroupId)
+                    && sub.eventType.equals(eventType)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this).add("appName", appName)
+                .addValue(subscriberGroupId.toString())
+                .add("eventType", eventType).toString();
+    }
+}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/EventSubscriberGroupId.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/EventSubscriberGroupId.java
new file mode 100644
index 0000000..e0dd204
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/EventSubscriberGroupId.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright 2016-present Open Networking Laboratory
+ * Licensed 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.onosproject.kafkaintegration.api.dto;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+import java.util.UUID;
+
+/**
+ * Wrapper Object for storing the consumer group id. Group ids are used by
+ * external applications when consuming events from Kafka server.
+ *
+ */
+public final class EventSubscriberGroupId {
+    private final UUID id;
+
+    /**
+     * Creates a new Subscriber Group Id.
+     *
+     * @param uuid representing the group id.
+     */
+    public EventSubscriberGroupId(UUID uuid) {
+        id = checkNotNull(uuid);
+    }
+
+    /**
+     * Returns the Group Id of the subscriber.
+     *
+     * @return uuid representing the group id.
+     */
+    public UUID getId() {
+        return id;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o instanceof EventSubscriberGroupId) {
+            EventSubscriberGroupId sub = (EventSubscriberGroupId) o;
+            if (sub.id.equals(id)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(id);
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this).add("subscriberGroupId", id).toString();
+    }
+}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/OnosEvent.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/OnosEvent.java
new file mode 100644
index 0000000..ff1d27e
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/OnosEvent.java
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2016-present Open Networking Laboratory
+ * Licensed 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.onosproject.kafkaintegration.api.dto;
+
+import org.onosproject.event.AbstractEvent;
+
+import com.google.protobuf.GeneratedMessage;
+
+/**
+ * Represents the converted Onos Event data into GPB format.
+ *
+ */
+public class OnosEvent extends AbstractEvent<OnosEvent.Type, GeneratedMessage> {
+
+    /**
+     * Creates a new Onos Event.
+     *
+     * @param type The Type of Onos Event
+     * @param subject Protobuf message corresponding to the Onos Event
+     */
+    public OnosEvent(Type type, GeneratedMessage subject) {
+        super(type, subject);
+    }
+
+    /**
+     * List of Event Types supported.
+     */
+    public enum Type {
+        DEVICE, LINK;
+    }
+}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/package-info.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/package-info.java
new file mode 100644
index 0000000..9066935
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/package-info.java
@@ -0,0 +1,18 @@
+/**
+ * Copyright 2016-present Open Networking Laboratory Licensed 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.
+ */
+
+/**
+ * Immutable Data Transfer Objects.
+ */
+package org.onosproject.kafkaintegration.api.dto;
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/package-info.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/package-info.java
new file mode 100644
index 0000000..250108c
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/package-info.java
@@ -0,0 +1,18 @@
+/**
+ * Copyright 2016-present Open Networking Laboratory Licensed 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.
+ */
+
+/**
+ * API definitions for the Application.
+ */
+package org.onosproject.kafkaintegration.api;
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/InvalidApplicationException.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/InvalidApplicationException.java
new file mode 100644
index 0000000..290f537
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/InvalidApplicationException.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright 2016-present Open Networking Laboratory
+ * Licensed 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.onosproject.kafkaintegration.errors;
+
+/**
+ * Represents that an unregistered application trying to subscribe to ONOS
+ * events.
+ *
+ */
+public class InvalidApplicationException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+
+    public InvalidApplicationException(String message) {
+        super(message);
+    }
+
+}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/InvalidGroupIdException.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/InvalidGroupIdException.java
new file mode 100644
index 0000000..fd0657b
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/InvalidGroupIdException.java
@@ -0,0 +1,29 @@
+/**
+ * Copyright 2016-present Open Networking Laboratory
+ * Licensed 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.onosproject.kafkaintegration.errors;
+
+/**
+ * The groupId given by the external application is already in use by another
+ * application or groupId does not exist.
+ *
+ */
+public class InvalidGroupIdException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+
+    public InvalidGroupIdException(String message) {
+        super(message);
+    }
+}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/UnsupportedEventException.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/UnsupportedEventException.java
new file mode 100644
index 0000000..73312b4
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/UnsupportedEventException.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright 2016-present Open Networking Laboratory
+ * Licensed 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.onosproject.kafkaintegration.errors;
+
+/**
+ * Event Type requested for subscription is not supported/available for export.
+ *
+ */
+public class UnsupportedEventException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+
+    public UnsupportedEventException(String message) {
+        super(message);
+    }
+}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/package-info.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/package-info.java
new file mode 100644
index 0000000..35773da
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/errors/package-info.java
@@ -0,0 +1,19 @@
+/**
+ * Copyright 2016-present Open Networking Laboratory Licensed 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.
+ */
+
+/**
+ * Application specific Exception classes.
+ *
+ */
+package org.onosproject.kafkaintegration.errors;