{"action":"created","comment":{"url":"https://api.github.com/repos/hal/testsuite/pulls/comments/60465413","id":60465413,"diff_hunk":"@@ -0,0 +1,124 @@\n+/*\n+ * JBoss, Home of Professional Open Source.\n+ * Copyright 2016, Red Hat, Inc., and individual contributors\n+ * as indicated by the @author tags. See the copyright.txt file in the\n+ * distribution for a full listing of individual contributors.\n+ *\n+ * This is free software; you can redistribute it and/or modify it\n+ * under the terms of the GNU Lesser General Public License as\n+ * published by the Free Software Foundation; either version 2.1 of\n+ * the License, or (at your option) any later version.\n+ *\n+ * This software is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this software; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n+ */\n+\n+package org.jboss.hal.testsuite.testlistener;\n+\n+import static java.util.function.Function.identity;\n+import static java.util.stream.Collectors.toMap;\n+import static org.jboss.as.controller.client.helpers.ClientConstants.HOST;\n+import static org.jboss.as.controller.client.helpers.ClientConstants.SERVER;\n+import static org.jboss.as.controller.client.helpers.ClientConstants.SERVER_CONFIG;\n+import static org.jboss.as.controller.client.helpers.ClientConstants.STATUS;\n+\n+import java.io.IOException;\n+import java.util.Map;\n+import java.util.function.Function;\n+import java.util.stream.Stream;\n+\n+import org.jboss.hal.testsuite.creaper.ManagementClientProvider;\n+import org.wildfly.extras.creaper.core.online.ModelNodeResult;\n+import org.wildfly.extras.creaper.core.online.OnlineManagementClient;\n+import org.wildfly.extras.creaper.core.online.operations.Address;\n+import org.wildfly.extras.creaper.core.online.operations.admin.Administration;\n+import org.wildfly.extras.creaper.core.online.operations.Operations;\n+\n+/**\n+ * Helper class to read server state informations from model for {@link ServerStateListener}. <br />\n+ * Created by pjelinek on Apr 19, 2016\n+ */\n+public class ServerStateListenerOperations {\n+\n+    public Map<String, Map<String, String>> getServerStateMap() throws IOException {\n+        return tryWithClient(client -> {\n+            ModelReader reader = new ModelReader(client);\n+            return reader.getHostStream().collect(toMap(identity(), reader.getServerOfHostStatesFunction()));\n+        });\n+    }\n+\n+    public boolean isReloadRequired() throws IOException {\n+        return tryWithClient(client -> new Administration(client).isReloadRequired());\n+    }\n+\n+    public boolean isRestartRequired() throws IOException {\n+        return tryWithClient(client -> new Administration(client).isRestartRequired());\n+    }\n+\n+    private <T> T tryWithClient(Function<OnlineManagementClient, T> modelReadFunction) throws IOException {\n+        try (OnlineManagementClient client = ManagementClientProvider.createOnlineManagementClient()) {\n+            return modelReadFunction.apply(client);\n+        }\n+    }\n+\n+    private class ModelReader {\n+\n+        private ModelReader(OnlineManagementClient client) {\n+            this.ops = new Operations(client);\n+        }\n+\n+        private Operations ops;\n+\n+        /**\n+         * {@link Function} instance to return map of server -> status pairs for given host\n+         */\n+        private Function<String, Map<String, String>> getServerOfHostStatesFunction() {\n+            return host -> {\n+                return getServerStream(host).collect(toMap(identity(), server -> {\n+                    return readServerConfigStatus(host, server);\n+                }));\n+            };\n+        }\n+\n+        private Stream<String> getHostStream() {\n+            ModelNodeResult hostsResult = null;\n+            try {\n+                hostsResult = ops.readChildrenNames(Address.root(), HOST);\n+            } catch (IOException e) {\n+                throw new RuntimeException(\"Unable to read hosts.\", e);\n+            }\n+            hostsResult.assertDefinedValue();\n+            return hostsResult.stringListValue().stream();\n+        }\n+\n+        private Stream<String> getServerStream(String host) {\n+            ModelNodeResult serversResult;\n+            try {\n+                serversResult = ops.readChildrenNames(Address.host(host), SERVER);\n+            } catch (IOException e) {\n+                throw new RuntimeException(\"Unable to read servers of host.\", e);\n+            }\n+            serversResult.assertDefinedValue();\n+            return serversResult.stringListValue().stream();\n+        }","path":"common/src/main/java/org/jboss/hal/testsuite/testlistener/ServerStateListenerOperations.java","position":110,"original_position":110,"commit_id":"58d6c719d3cf802ed713ae480c33f45fc09a6722","original_commit_id":"58d6c719d3cf802ed713ae480c33f45fc09a6722","user":{"login":"rhatlapa","id":1469361,"avatar_url":"https://avatars.githubusercontent.com/u/1469361?v=3","gravatar_id":"","url":"https://api.github.com/users/rhatlapa","html_url":"https://github.com/rhatlapa","followers_url":"https://api.github.com/users/rhatlapa/followers","following_url":"https://api.github.com/users/rhatlapa/following{/other_user}","gists_url":"https://api.github.com/users/rhatlapa/gists{/gist_id}","starred_url":"https://api.github.com/users/rhatlapa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhatlapa/subscriptions","organizations_url":"https://api.github.com/users/rhatlapa/orgs","repos_url":"https://api.github.com/users/rhatlapa/repos","events_url":"https://api.github.com/users/rhatlapa/events{/privacy}","received_events_url":"https://api.github.com/users/rhatlapa/received_events","type":"User","site_admin":false},"body":"The same as above","created_at":"2016-04-20T18:45:38Z","updated_at":"2016-04-20T18:45:38Z","html_url":"https://github.com/hal/testsuite/pull/176#discussion_r60465413","pull_request_url":"https://api.github.com/repos/hal/testsuite/pulls/176","_links":{"self":{"href":"https://api.github.com/repos/hal/testsuite/pulls/comments/60465413"},"html":{"href":"https://github.com/hal/testsuite/pull/176#discussion_r60465413"},"pull_request":{"href":"https://api.github.com/repos/hal/testsuite/pulls/176"}}},"pull_request":{"url":"https://api.github.com/repos/hal/testsuite/pulls/176","id":67176089,"html_url":"https://github.com/hal/testsuite/pull/176","diff_url":"https://github.com/hal/testsuite/pull/176.diff","patch_url":"https://github.com/hal/testsuite/pull/176.patch","issue_url":"https://api.github.com/repos/hal/testsuite/issues/176","number":176,"state":"open","locked":false,"title":"RunListener to check server state cleanup.","user":{"login":"zebrik","id":2960907,"avatar_url":"https://avatars.githubusercontent.com/u/2960907?v=3","gravatar_id":"","url":"https://api.github.com/users/zebrik","html_url":"https://github.com/zebrik","followers_url":"https://api.github.com/users/zebrik/followers","following_url":"https://api.github.com/users/zebrik/following{/other_user}","gists_url":"https://api.github.com/users/zebrik/gists{/gist_id}","starred_url":"https://api.github.com/users/zebrik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zebrik/subscriptions","organizations_url":"https://api.github.com/users/zebrik/orgs","repos_url":"https://api.github.com/users/zebrik/repos","events_url":"https://api.github.com/users/zebrik/events{/privacy}","received_events_url":"https://api.github.com/users/zebrik/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-20T12:15:55Z","updated_at":"2016-04-20T18:45:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aced71bf9c163ad408431b3909393c85aea63525","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hal/testsuite/pulls/176/commits","review_comments_url":"https://api.github.com/repos/hal/testsuite/pulls/176/comments","review_comment_url":"https://api.github.com/repos/hal/testsuite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hal/testsuite/issues/176/comments","statuses_url":"https://api.github.com/repos/hal/testsuite/statuses/58d6c719d3cf802ed713ae480c33f45fc09a6722","head":{"label":"zebrik:debug","ref":"debug","sha":"58d6c719d3cf802ed713ae480c33f45fc09a6722","user":{"login":"zebrik","id":2960907,"avatar_url":"https://avatars.githubusercontent.com/u/2960907?v=3","gravatar_id":"","url":"https://api.github.com/users/zebrik","html_url":"https://github.com/zebrik","followers_url":"https://api.github.com/users/zebrik/followers","following_url":"https://api.github.com/users/zebrik/following{/other_user}","gists_url":"https://api.github.com/users/zebrik/gists{/gist_id}","starred_url":"https://api.github.com/users/zebrik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zebrik/subscriptions","organizations_url":"https://api.github.com/users/zebrik/orgs","repos_url":"https://api.github.com/users/zebrik/repos","events_url":"https://api.github.com/users/zebrik/events{/privacy}","received_events_url":"https://api.github.com/users/zebrik/received_events","type":"User","site_admin":false},"repo":{"id":32314358,"name":"testsuite","full_name":"zebrik/testsuite","owner":{"login":"zebrik","id":2960907,"avatar_url":"https://avatars.githubusercontent.com/u/2960907?v=3","gravatar_id":"","url":"https://api.github.com/users/zebrik","html_url":"https://github.com/zebrik","followers_url":"https://api.github.com/users/zebrik/followers","following_url":"https://api.github.com/users/zebrik/following{/other_user}","gists_url":"https://api.github.com/users/zebrik/gists{/gist_id}","starred_url":"https://api.github.com/users/zebrik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zebrik/subscriptions","organizations_url":"https://api.github.com/users/zebrik/orgs","repos_url":"https://api.github.com/users/zebrik/repos","events_url":"https://api.github.com/users/zebrik/events{/privacy}","received_events_url":"https://api.github.com/users/zebrik/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zebrik/testsuite","description":"Testsuite for the HAL management console","fork":true,"url":"https://api.github.com/repos/zebrik/testsuite","forks_url":"https://api.github.com/repos/zebrik/testsuite/forks","keys_url":"https://api.github.com/repos/zebrik/testsuite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zebrik/testsuite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zebrik/testsuite/teams","hooks_url":"https://api.github.com/repos/zebrik/testsuite/hooks","issue_events_url":"https://api.github.com/repos/zebrik/testsuite/issues/events{/number}","events_url":"https://api.github.com/repos/zebrik/testsuite/events","assignees_url":"https://api.github.com/repos/zebrik/testsuite/assignees{/user}","branches_url":"https://api.github.com/repos/zebrik/testsuite/branches{/branch}","tags_url":"https://api.github.com/repos/zebrik/testsuite/tags","blobs_url":"https://api.github.com/repos/zebrik/testsuite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zebrik/testsuite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zebrik/testsuite/git/refs{/sha}","trees_url":"https://api.github.com/repos/zebrik/testsuite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zebrik/testsuite/statuses/{sha}","languages_url":"https://api.github.com/repos/zebrik/testsuite/languages","stargazers_url":"https://api.github.com/repos/zebrik/testsuite/stargazers","contributors_url":"https://api.github.com/repos/zebrik/testsuite/contributors","subscribers_url":"https://api.github.com/repos/zebrik/testsuite/subscribers","subscription_url":"https://api.github.com/repos/zebrik/testsuite/subscription","commits_url":"https://api.github.com/repos/zebrik/testsuite/commits{/sha}","git_commits_url":"https://api.github.com/repos/zebrik/testsuite/git/commits{/sha}","comments_url":"https://api.github.com/repos/zebrik/testsuite/comments{/number}","issue_comment_url":"https://api.github.com/repos/zebrik/testsuite/issues/comments{/number}","contents_url":"https://api.github.com/repos/zebrik/testsuite/contents/{+path}","compare_url":"https://api.github.com/repos/zebrik/testsuite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zebrik/testsuite/merges","archive_url":"https://api.github.com/repos/zebrik/testsuite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zebrik/testsuite/downloads","issues_url":"https://api.github.com/repos/zebrik/testsuite/issues{/number}","pulls_url":"https://api.github.com/repos/zebrik/testsuite/pulls{/number}","milestones_url":"https://api.github.com/repos/zebrik/testsuite/milestones{/number}","notifications_url":"https://api.github.com/repos/zebrik/testsuite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zebrik/testsuite/labels{/name}","releases_url":"https://api.github.com/repos/zebrik/testsuite/releases{/id}","deployments_url":"https://api.github.com/repos/zebrik/testsuite/deployments","created_at":"2015-03-16T09:31:11Z","updated_at":"2016-01-25T10:50:34Z","pushed_at":"2016-04-20T14:08:39Z","git_url":"git://github.com/zebrik/testsuite.git","ssh_url":"git@github.com:zebrik/testsuite.git","clone_url":"https://github.com/zebrik/testsuite.git","svn_url":"https://github.com/zebrik/testsuite","homepage":null,"size":1555,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"hal:master","ref":"master","sha":"e607d52f806939ceacbb24e9ff860f5063ba8efc","user":{"login":"hal","id":4076071,"avatar_url":"https://avatars.githubusercontent.com/u/4076071?v=3","gravatar_id":"","url":"https://api.github.com/users/hal","html_url":"https://github.com/hal","followers_url":"https://api.github.com/users/hal/followers","following_url":"https://api.github.com/users/hal/following{/other_user}","gists_url":"https://api.github.com/users/hal/gists{/gist_id}","starred_url":"https://api.github.com/users/hal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hal/subscriptions","organizations_url":"https://api.github.com/users/hal/orgs","repos_url":"https://api.github.com/users/hal/repos","events_url":"https://api.github.com/users/hal/events{/privacy}","received_events_url":"https://api.github.com/users/hal/received_events","type":"Organization","site_admin":false},"repo":{"id":30184967,"name":"testsuite","full_name":"hal/testsuite","owner":{"login":"hal","id":4076071,"avatar_url":"https://avatars.githubusercontent.com/u/4076071?v=3","gravatar_id":"","url":"https://api.github.com/users/hal","html_url":"https://github.com/hal","followers_url":"https://api.github.com/users/hal/followers","following_url":"https://api.github.com/users/hal/following{/other_user}","gists_url":"https://api.github.com/users/hal/gists{/gist_id}","starred_url":"https://api.github.com/users/hal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hal/subscriptions","organizations_url":"https://api.github.com/users/hal/orgs","repos_url":"https://api.github.com/users/hal/repos","events_url":"https://api.github.com/users/hal/events{/privacy}","received_events_url":"https://api.github.com/users/hal/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hal/testsuite","description":"Testsuite for the HAL management console","fork":false,"url":"https://api.github.com/repos/hal/testsuite","forks_url":"https://api.github.com/repos/hal/testsuite/forks","keys_url":"https://api.github.com/repos/hal/testsuite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hal/testsuite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hal/testsuite/teams","hooks_url":"https://api.github.com/repos/hal/testsuite/hooks","issue_events_url":"https://api.github.com/repos/hal/testsuite/issues/events{/number}","events_url":"https://api.github.com/repos/hal/testsuite/events","assignees_url":"https://api.github.com/repos/hal/testsuite/assignees{/user}","branches_url":"https://api.github.com/repos/hal/testsuite/branches{/branch}","tags_url":"https://api.github.com/repos/hal/testsuite/tags","blobs_url":"https://api.github.com/repos/hal/testsuite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hal/testsuite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hal/testsuite/git/refs{/sha}","trees_url":"https://api.github.com/repos/hal/testsuite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hal/testsuite/statuses/{sha}","languages_url":"https://api.github.com/repos/hal/testsuite/languages","stargazers_url":"https://api.github.com/repos/hal/testsuite/stargazers","contributors_url":"https://api.github.com/repos/hal/testsuite/contributors","subscribers_url":"https://api.github.com/repos/hal/testsuite/subscribers","subscription_url":"https://api.github.com/repos/hal/testsuite/subscription","commits_url":"https://api.github.com/repos/hal/testsuite/commits{/sha}","git_commits_url":"https://api.github.com/repos/hal/testsuite/git/commits{/sha}","comments_url":"https://api.github.com/repos/hal/testsuite/comments{/number}","issue_comment_url":"https://api.github.com/repos/hal/testsuite/issues/comments{/number}","contents_url":"https://api.github.com/repos/hal/testsuite/contents/{+path}","compare_url":"https://api.github.com/repos/hal/testsuite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hal/testsuite/merges","archive_url":"https://api.github.com/repos/hal/testsuite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hal/testsuite/downloads","issues_url":"https://api.github.com/repos/hal/testsuite/issues{/number}","pulls_url":"https://api.github.com/repos/hal/testsuite/pulls{/number}","milestones_url":"https://api.github.com/repos/hal/testsuite/milestones{/number}","notifications_url":"https://api.github.com/repos/hal/testsuite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hal/testsuite/labels{/name}","releases_url":"https://api.github.com/repos/hal/testsuite/releases{/id}","deployments_url":"https://api.github.com/repos/hal/testsuite/deployments","created_at":"2015-02-02T11:54:36Z","updated_at":"2016-01-12T15:56:23Z","pushed_at":"2016-04-20T14:08:40Z","git_url":"git://github.com/hal/testsuite.git","ssh_url":"git@github.com:hal/testsuite.git","clone_url":"https://github.com/hal/testsuite.git","svn_url":"https://github.com/hal/testsuite","homepage":null,"size":2344,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":2,"forks":7,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hal/testsuite/pulls/176"},"html":{"href":"https://github.com/hal/testsuite/pull/176"},"issue":{"href":"https://api.github.com/repos/hal/testsuite/issues/176"},"comments":{"href":"https://api.github.com/repos/hal/testsuite/issues/176/comments"},"review_comments":{"href":"https://api.github.com/repos/hal/testsuite/pulls/176/comments"},"review_comment":{"href":"https://api.github.com/repos/hal/testsuite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hal/testsuite/pulls/176/commits"},"statuses":{"href":"https://api.github.com/repos/hal/testsuite/statuses/58d6c719d3cf802ed713ae480c33f45fc09a6722"}}}}