{"action":"created","comment":{"url":"https://api.github.com/repos/telstra/open-kilda/pulls/comments/190717735","pull_request_review_id":123149364,"id":190717735,"diff_hunk":"@@ -0,0 +1,166 @@\n+/* Copyright 2017 Telstra Open Source\n+ *\n+ *   Licensed under the Apache License, Version 2.0 (the \"License\");\n+ *   you may not use this file except in compliance with the License.\n+ *   You may obtain a copy of the License at\n+ *\n+ *       http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ *   Unless required by applicable law or agreed to in writing, software\n+ *   distributed under the License is distributed on an \"AS IS\" BASIS,\n+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ *   See the License for the specific language governing permissions and\n+ *   limitations under the License.\n+ */\n+\n+package org.openkilda.wfm.topology.nbworker.bolts;\n+\n+import org.openkilda.messaging.info.event.IslChangeType;\n+import org.openkilda.messaging.info.event.IslInfoData;\n+import org.openkilda.messaging.info.event.PathNode;\n+import org.openkilda.messaging.nbtopology.request.GetLinksRequest;\n+import org.openkilda.messaging.nbtopology.request.LinksBaseRequest;\n+import org.openkilda.pce.provider.Auth;\n+import org.openkilda.wfm.AbstractBolt;\n+import org.openkilda.wfm.error.AbstractException;\n+\n+import com.google.common.collect.Lists;\n+import org.apache.storm.task.OutputCollector;\n+import org.apache.storm.task.TopologyContext;\n+import org.apache.storm.topology.OutputFieldsDeclarer;\n+import org.apache.storm.tuple.Fields;\n+import org.apache.storm.tuple.Tuple;\n+import org.neo4j.driver.v1.AccessMode;\n+import org.neo4j.driver.v1.Driver;\n+import org.neo4j.driver.v1.Record;\n+import org.neo4j.driver.v1.Session;\n+import org.neo4j.driver.v1.StatementResult;\n+import org.neo4j.driver.v1.Value;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Optional;\n+\n+public class LinkOperationsBolt extends AbstractBolt {\n+\n+    private static final Logger LOGGER = LoggerFactory.getLogger(LinkOperationsBolt.class);\n+\n+    private Driver driver;\n+    private final Auth neoAuth;\n+\n+    public LinkOperationsBolt(Auth neoAuth) {\n+        this.neoAuth = neoAuth;\n+    }\n+\n+    @Override\n+    public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {\n+        this.driver = neoAuth.getDriver();\n+        super.prepare(stormConf, context, collector);\n+    }\n+\n+\n+    @Override\n+    protected void handleInput(Tuple input) throws AbstractException {\n+        LinksBaseRequest request = (LinksBaseRequest) input.getValueByField(\"request\");\n+        final String correlationId = input.getStringByField(\"correlationId\");\n+\n+        LOGGER.debug(\"Received read request with correlationId {}\", correlationId);\n+        try (Session session = driver.session(request.isReadRequest() ? AccessMode.READ : AccessMode.WRITE)) {\n+            List result = null;\n+            if (request instanceof GetLinksRequest) {\n+                result = getAllLinks(session);\n+            } else {\n+                LOGGER.warn(\"Received unsupported Links request: {}\", correlationId);\n+            }\n+\n+            LOGGER.debug(\"Processed read request with correlationId {}\", correlationId);\n+            getOutput().emit(Lists.newArrayList(result, correlationId));\n+        }\n+\n+    }\n+\n+    private List<IslInfoData> getAllLinks(Session session) {\n+        LOGGER.debug(\"Getting ISLs...\");\n+        String q =\n+                \"MATCH (:switch)-[isl:isl]->(:switch) \"\n+                        + \"RETURN \"\n+                        + \"isl.src_switch as src_switch, \"\n+                        + \"isl.src_port as src_port, \"\n+                        + \"isl.dst_switch as dst_switch, \"\n+                        + \"isl.dst_port as dst_port, \"\n+                        + \"isl.speed as speed, \"\n+                        + \"isl.max_bandwidth as max_bandwidth, \"\n+                        + \"isl.latency as latency, \"\n+                        + \"isl.available_bandwidth as available_bandwidth, \"\n+                        + \"isl.status as status\";\n+\n+        StatementResult queryResults = session.run(q);\n+        List<IslInfoData> results = new ArrayList<>();\n+        for (Record record : queryResults.list()) {\n+            LOGGER.debug(\"Reading record... {}\", record);\n+            // max_bandwidth not used in IslInfoData\n+            PathNode src = new PathNode();\n+            src.setSwitchId(record.get(\"src_switch\").asString());\n+            src.setPortNo(parseIntValue(record.get(\"src_port\")));\n+            src.setSegLatency(parseIntValue(record.get(\"latency\")));\n+            PathNode dst = new PathNode();\n+            dst.setSwitchId(record.get(\"dst_switch\").asString());\n+            dst.setPortNo(parseIntValue(record.get(\"dst_port\")));\n+            dst.setSegLatency(parseIntValue(record.get(\"latency\")));\n+\n+            List<PathNode> pathNodes = new ArrayList<>();\n+            pathNodes.add(src);\n+            pathNodes.add(dst);\n+\n+            IslChangeType state = getStatus(record.get(\"status\").asString());\n+            IslInfoData isl = new IslInfoData(\n+                    parseIntValue(record.get(\"latency\")),\n+                    pathNodes,\n+                    parseIntValue(record.get(\"speed\")),\n+                    state,\n+                    parseIntValue(record.get(\"available_bandwidth\"))\n+            );\n+            isl.setTimestamp(System.currentTimeMillis());\n+\n+            results.add(isl);\n+            LOGGER.info(\"Result ISL: {}\", isl);\n+","path":"services/wfm/src/main/java/org/openkilda/wfm/topology/nbworker/bolts/LinkOperationsBolt.java","position":130,"original_position":130,"commit_id":"a9b667d6cb2048185ade24d8a2a6210cb8e48bfd","original_commit_id":"a9b667d6cb2048185ade24d8a2a6210cb8e48bfd","user":{"login":"surabujin","id":2862761,"avatar_url":"https://avatars2.githubusercontent.com/u/2862761?v=4","gravatar_id":"","url":"https://api.github.com/users/surabujin","html_url":"https://github.com/surabujin","followers_url":"https://api.github.com/users/surabujin/followers","following_url":"https://api.github.com/users/surabujin/following{/other_user}","gists_url":"https://api.github.com/users/surabujin/gists{/gist_id}","starred_url":"https://api.github.com/users/surabujin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surabujin/subscriptions","organizations_url":"https://api.github.com/users/surabujin/orgs","repos_url":"https://api.github.com/users/surabujin/repos","events_url":"https://api.github.com/users/surabujin/events{/privacy}","received_events_url":"https://api.github.com/users/surabujin/received_events","type":"User","site_admin":false},"body":"why style check allow empty line here?..","created_at":"2018-05-24T20:18:09Z","updated_at":"2018-05-24T20:33:26Z","html_url":"https://github.com/telstra/open-kilda/pull/797#discussion_r190717735","pull_request_url":"https://api.github.com/repos/telstra/open-kilda/pulls/797","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/telstra/open-kilda/pulls/comments/190717735"},"html":{"href":"https://github.com/telstra/open-kilda/pull/797#discussion_r190717735"},"pull_request":{"href":"https://api.github.com/repos/telstra/open-kilda/pulls/797"}}},"pull_request":{"url":"https://api.github.com/repos/telstra/open-kilda/pulls/797","id":188856909,"html_url":"https://github.com/telstra/open-kilda/pull/797","diff_url":"https://github.com/telstra/open-kilda/pull/797.diff","patch_url":"https://github.com/telstra/open-kilda/pull/797.patch","issue_url":"https://api.github.com/repos/telstra/open-kilda/issues/797","number":797,"state":"open","locked":false,"title":"#769: implemented additional topology for read operations from neo4j. fixed getting all switches / ISLs","user":{"login":"nikitacherevko","id":6116378,"avatar_url":"https://avatars2.githubusercontent.com/u/6116378?v=4","gravatar_id":"","url":"https://api.github.com/users/nikitacherevko","html_url":"https://github.com/nikitacherevko","followers_url":"https://api.github.com/users/nikitacherevko/followers","following_url":"https://api.github.com/users/nikitacherevko/following{/other_user}","gists_url":"https://api.github.com/users/nikitacherevko/gists{/gist_id}","starred_url":"https://api.github.com/users/nikitacherevko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikitacherevko/subscriptions","organizations_url":"https://api.github.com/users/nikitacherevko/orgs","repos_url":"https://api.github.com/users/nikitacherevko/repos","events_url":"https://api.github.com/users/nikitacherevko/events{/privacy}","received_events_url":"https://api.github.com/users/nikitacherevko/received_events","type":"User","site_admin":false},"body":"Fixed loading all switches and all links lists.\r\n\r\nCloses #769 ","created_at":"2018-05-17T20:47:21Z","updated_at":"2018-05-24T20:33:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3d711fe8cd4bd1258025a256afd5ecd54b52604e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":935982807,"url":"https://api.github.com/repos/telstra/open-kilda/labels/C/CACHE","name":"C/CACHE","color":"cf6fe2","default":false},{"id":935983223,"url":"https://api.github.com/repos/telstra/open-kilda/labels/C/FLOW","name":"C/FLOW","color":"e0cd62","default":false},{"id":936014286,"url":"https://api.github.com/repos/telstra/open-kilda/labels/C/NB","name":"C/NB","color":"31ed3e","default":false},{"id":937212582,"url":"https://api.github.com/repos/telstra/open-kilda/labels/C/NBWORKER","name":"C/NBWORKER","color":"f2879b","default":false},{"id":935983828,"url":"https://api.github.com/repos/telstra/open-kilda/labels/C/STATS","name":"C/STATS","color":"8fefcf","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/telstra/open-kilda/pulls/797/commits","review_comments_url":"https://api.github.com/repos/telstra/open-kilda/pulls/797/comments","review_comment_url":"https://api.github.com/repos/telstra/open-kilda/pulls/comments{/number}","comments_url":"https://api.github.com/repos/telstra/open-kilda/issues/797/comments","statuses_url":"https://api.github.com/repos/telstra/open-kilda/statuses/a9b667d6cb2048185ade24d8a2a6210cb8e48bfd","head":{"label":"telstra:fix/nb-worker","ref":"fix/nb-worker","sha":"a9b667d6cb2048185ade24d8a2a6210cb8e48bfd","user":{"login":"telstra","id":3914896,"avatar_url":"https://avatars2.githubusercontent.com/u/3914896?v=4","gravatar_id":"","url":"https://api.github.com/users/telstra","html_url":"https://github.com/telstra","followers_url":"https://api.github.com/users/telstra/followers","following_url":"https://api.github.com/users/telstra/following{/other_user}","gists_url":"https://api.github.com/users/telstra/gists{/gist_id}","starred_url":"https://api.github.com/users/telstra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telstra/subscriptions","organizations_url":"https://api.github.com/users/telstra/orgs","repos_url":"https://api.github.com/users/telstra/repos","events_url":"https://api.github.com/users/telstra/events{/privacy}","received_events_url":"https://api.github.com/users/telstra/received_events","type":"Organization","site_admin":false},"repo":{"id":104974693,"name":"open-kilda","full_name":"telstra/open-kilda","owner":{"login":"telstra","id":3914896,"avatar_url":"https://avatars2.githubusercontent.com/u/3914896?v=4","gravatar_id":"","url":"https://api.github.com/users/telstra","html_url":"https://github.com/telstra","followers_url":"https://api.github.com/users/telstra/followers","following_url":"https://api.github.com/users/telstra/following{/other_user}","gists_url":"https://api.github.com/users/telstra/gists{/gist_id}","starred_url":"https://api.github.com/users/telstra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telstra/subscriptions","organizations_url":"https://api.github.com/users/telstra/orgs","repos_url":"https://api.github.com/users/telstra/repos","events_url":"https://api.github.com/users/telstra/events{/privacy}","received_events_url":"https://api.github.com/users/telstra/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/telstra/open-kilda","description":"OpenKilda is an open-source OpenFlow controller initially designed for use in a global network with high control-plane latency and a heavy emphasis on latency-centric data path optimisation.","fork":false,"url":"https://api.github.com/repos/telstra/open-kilda","forks_url":"https://api.github.com/repos/telstra/open-kilda/forks","keys_url":"https://api.github.com/repos/telstra/open-kilda/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telstra/open-kilda/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telstra/open-kilda/teams","hooks_url":"https://api.github.com/repos/telstra/open-kilda/hooks","issue_events_url":"https://api.github.com/repos/telstra/open-kilda/issues/events{/number}","events_url":"https://api.github.com/repos/telstra/open-kilda/events","assignees_url":"https://api.github.com/repos/telstra/open-kilda/assignees{/user}","branches_url":"https://api.github.com/repos/telstra/open-kilda/branches{/branch}","tags_url":"https://api.github.com/repos/telstra/open-kilda/tags","blobs_url":"https://api.github.com/repos/telstra/open-kilda/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telstra/open-kilda/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telstra/open-kilda/git/refs{/sha}","trees_url":"https://api.github.com/repos/telstra/open-kilda/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telstra/open-kilda/statuses/{sha}","languages_url":"https://api.github.com/repos/telstra/open-kilda/languages","stargazers_url":"https://api.github.com/repos/telstra/open-kilda/stargazers","contributors_url":"https://api.github.com/repos/telstra/open-kilda/contributors","subscribers_url":"https://api.github.com/repos/telstra/open-kilda/subscribers","subscription_url":"https://api.github.com/repos/telstra/open-kilda/subscription","commits_url":"https://api.github.com/repos/telstra/open-kilda/commits{/sha}","git_commits_url":"https://api.github.com/repos/telstra/open-kilda/git/commits{/sha}","comments_url":"https://api.github.com/repos/telstra/open-kilda/comments{/number}","issue_comment_url":"https://api.github.com/repos/telstra/open-kilda/issues/comments{/number}","contents_url":"https://api.github.com/repos/telstra/open-kilda/contents/{+path}","compare_url":"https://api.github.com/repos/telstra/open-kilda/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telstra/open-kilda/merges","archive_url":"https://api.github.com/repos/telstra/open-kilda/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telstra/open-kilda/downloads","issues_url":"https://api.github.com/repos/telstra/open-kilda/issues{/number}","pulls_url":"https://api.github.com/repos/telstra/open-kilda/pulls{/number}","milestones_url":"https://api.github.com/repos/telstra/open-kilda/milestones{/number}","notifications_url":"https://api.github.com/repos/telstra/open-kilda/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telstra/open-kilda/labels{/name}","releases_url":"https://api.github.com/repos/telstra/open-kilda/releases{/id}","deployments_url":"https://api.github.com/repos/telstra/open-kilda/deployments","created_at":"2017-09-27T05:13:18Z","updated_at":"2018-05-24T15:25:43Z","pushed_at":"2018-05-24T19:36:36Z","git_url":"git://github.com/telstra/open-kilda.git","ssh_url":"git@github.com:telstra/open-kilda.git","clone_url":"https://github.com/telstra/open-kilda.git","svn_url":"https://github.com/telstra/open-kilda","homepage":"","size":38864,"stargazers_count":24,"watchers_count":24,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":23,"mirror_url":null,"archived":false,"open_issues_count":192,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":23,"open_issues":192,"watchers":24,"default_branch":"develop"}},"base":{"label":"telstra:develop","ref":"develop","sha":"0e9018f92d70a620fb1c1115fe6bdb23b459d1ca","user":{"login":"telstra","id":3914896,"avatar_url":"https://avatars2.githubusercontent.com/u/3914896?v=4","gravatar_id":"","url":"https://api.github.com/users/telstra","html_url":"https://github.com/telstra","followers_url":"https://api.github.com/users/telstra/followers","following_url":"https://api.github.com/users/telstra/following{/other_user}","gists_url":"https://api.github.com/users/telstra/gists{/gist_id}","starred_url":"https://api.github.com/users/telstra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telstra/subscriptions","organizations_url":"https://api.github.com/users/telstra/orgs","repos_url":"https://api.github.com/users/telstra/repos","events_url":"https://api.github.com/users/telstra/events{/privacy}","received_events_url":"https://api.github.com/users/telstra/received_events","type":"Organization","site_admin":false},"repo":{"id":104974693,"name":"open-kilda","full_name":"telstra/open-kilda","owner":{"login":"telstra","id":3914896,"avatar_url":"https://avatars2.githubusercontent.com/u/3914896?v=4","gravatar_id":"","url":"https://api.github.com/users/telstra","html_url":"https://github.com/telstra","followers_url":"https://api.github.com/users/telstra/followers","following_url":"https://api.github.com/users/telstra/following{/other_user}","gists_url":"https://api.github.com/users/telstra/gists{/gist_id}","starred_url":"https://api.github.com/users/telstra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telstra/subscriptions","organizations_url":"https://api.github.com/users/telstra/orgs","repos_url":"https://api.github.com/users/telstra/repos","events_url":"https://api.github.com/users/telstra/events{/privacy}","received_events_url":"https://api.github.com/users/telstra/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/telstra/open-kilda","description":"OpenKilda is an open-source OpenFlow controller initially designed for use in a global network with high control-plane latency and a heavy emphasis on latency-centric data path optimisation.","fork":false,"url":"https://api.github.com/repos/telstra/open-kilda","forks_url":"https://api.github.com/repos/telstra/open-kilda/forks","keys_url":"https://api.github.com/repos/telstra/open-kilda/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telstra/open-kilda/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telstra/open-kilda/teams","hooks_url":"https://api.github.com/repos/telstra/open-kilda/hooks","issue_events_url":"https://api.github.com/repos/telstra/open-kilda/issues/events{/number}","events_url":"https://api.github.com/repos/telstra/open-kilda/events","assignees_url":"https://api.github.com/repos/telstra/open-kilda/assignees{/user}","branches_url":"https://api.github.com/repos/telstra/open-kilda/branches{/branch}","tags_url":"https://api.github.com/repos/telstra/open-kilda/tags","blobs_url":"https://api.github.com/repos/telstra/open-kilda/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telstra/open-kilda/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telstra/open-kilda/git/refs{/sha}","trees_url":"https://api.github.com/repos/telstra/open-kilda/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telstra/open-kilda/statuses/{sha}","languages_url":"https://api.github.com/repos/telstra/open-kilda/languages","stargazers_url":"https://api.github.com/repos/telstra/open-kilda/stargazers","contributors_url":"https://api.github.com/repos/telstra/open-kilda/contributors","subscribers_url":"https://api.github.com/repos/telstra/open-kilda/subscribers","subscription_url":"https://api.github.com/repos/telstra/open-kilda/subscription","commits_url":"https://api.github.com/repos/telstra/open-kilda/commits{/sha}","git_commits_url":"https://api.github.com/repos/telstra/open-kilda/git/commits{/sha}","comments_url":"https://api.github.com/repos/telstra/open-kilda/comments{/number}","issue_comment_url":"https://api.github.com/repos/telstra/open-kilda/issues/comments{/number}","contents_url":"https://api.github.com/repos/telstra/open-kilda/contents/{+path}","compare_url":"https://api.github.com/repos/telstra/open-kilda/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telstra/open-kilda/merges","archive_url":"https://api.github.com/repos/telstra/open-kilda/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telstra/open-kilda/downloads","issues_url":"https://api.github.com/repos/telstra/open-kilda/issues{/number}","pulls_url":"https://api.github.com/repos/telstra/open-kilda/pulls{/number}","milestones_url":"https://api.github.com/repos/telstra/open-kilda/milestones{/number}","notifications_url":"https://api.github.com/repos/telstra/open-kilda/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telstra/open-kilda/labels{/name}","releases_url":"https://api.github.com/repos/telstra/open-kilda/releases{/id}","deployments_url":"https://api.github.com/repos/telstra/open-kilda/deployments","created_at":"2017-09-27T05:13:18Z","updated_at":"2018-05-24T15:25:43Z","pushed_at":"2018-05-24T19:36:36Z","git_url":"git://github.com/telstra/open-kilda.git","ssh_url":"git@github.com:telstra/open-kilda.git","clone_url":"https://github.com/telstra/open-kilda.git","svn_url":"https://github.com/telstra/open-kilda","homepage":"","size":38864,"stargazers_count":24,"watchers_count":24,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":23,"mirror_url":null,"archived":false,"open_issues_count":192,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":23,"open_issues":192,"watchers":24,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/telstra/open-kilda/pulls/797"},"html":{"href":"https://github.com/telstra/open-kilda/pull/797"},"issue":{"href":"https://api.github.com/repos/telstra/open-kilda/issues/797"},"comments":{"href":"https://api.github.com/repos/telstra/open-kilda/issues/797/comments"},"review_comments":{"href":"https://api.github.com/repos/telstra/open-kilda/pulls/797/comments"},"review_comment":{"href":"https://api.github.com/repos/telstra/open-kilda/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/telstra/open-kilda/pulls/797/commits"},"statuses":{"href":"https://api.github.com/repos/telstra/open-kilda/statuses/a9b667d6cb2048185ade24d8a2a6210cb8e48bfd"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"surabujin"}}