Create entities and classes 25/7525/2
authorGuangrong Fu <fu.guangrong@zte.com.cn>
Tue, 15 Aug 2017 00:26:02 +0000 (08:26 +0800)
committerGuangrong Fu <fu.guangrong@zte.com.cn>
Tue, 15 Aug 2017 00:39:19 +0000 (08:39 +0800)
Create a class for subscription.
Create an entity class (VesAlarm).

Change-Id: I5fc952d841325f51e0c03bb5a9eab3fde5389128
Issue-ID: HOLMES-23
Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Subscriber.java [new file with mode: 0644]
holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/VesAlarm.java [new file with mode: 0644]

diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Subscriber.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Subscriber.java
new file mode 100644 (file)
index 0000000..bef3c2b
--- /dev/null
@@ -0,0 +1,69 @@
+/*\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.holmes.common.dmaap;\r
+\r
+import java.util.Collections;\r
+import java.util.List;\r
+import javax.ws.rs.client.Client;\r
+import javax.ws.rs.client.ClientBuilder;\r
+import javax.ws.rs.client.WebTarget;\r
+import javax.ws.rs.core.Response;\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+import org.glassfish.jersey.client.ClientConfig;\r
+import org.onap.holmes.common.dmaap.entity.VesAlarm;\r
+import org.onap.holmes.common.exception.CorrelationException;\r
+\r
+@Getter\r
+@Setter\r
+public class Subscriber {\r
+    /**\r
+     * The number of milliseconds to wait for messages if none are immediately\r
+     * available. This should normally be used, and set at 15000 or higher.\r
+     */\r
+    private int timeout = 15000;\r
+\r
+    /**\r
+     * The maximum number of messages to return\r
+     */\r
+    private int limit = 100;\r
+\r
+    private boolean secure;\r
+    private String topic;\r
+    private String url;\r
+    private String consumerGroup = "g0";\r
+    private String consumer = "u1";\r
+    private String authInfo;\r
+    private String authExpDate;\r
+\r
+    List<VesAlarm> subscribe() throws CorrelationException {\r
+        Client client = ClientBuilder.newClient(new ClientConfig());\r
+        WebTarget webTarget = client.target(url);\r
+        Response response = webTarget.path(topic).path(consumerGroup).path(consumer).request().get();\r
+\r
+        try {\r
+            return extractAlarms(response);\r
+        }\r
+        catch (Exception e) {\r
+            throw new CorrelationException("Failed to convert the response data to VES alarms.", e);\r
+        }\r
+    }\r
+\r
+    private List<VesAlarm> extractAlarms(Response response) {\r
+        return Collections.emptyList();\r
+    }\r
+}\r
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/VesAlarm.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/VesAlarm.java
new file mode 100644 (file)
index 0000000..b49fac2
--- /dev/null
@@ -0,0 +1,29 @@
+/*\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.holmes.common.dmaap.entity;\r
+\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+\r
+@Getter\r
+@Setter\r
+public class VesAlarm {\r
+    private String eventId;\r
+    private String sourceId;\r
+    private String specificProblem;\r
+    private long alarmRaisedTime;\r
+}\r