{"action":"created","comment":{"url":"https://api.github.com/repos/yegor256/rultor/pulls/comments/23610049","id":23610049,"diff_hunk":"@@ -0,0 +1,139 @@\n+/**\n+ * Copyright (c) 2009-2015, rultor.com\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met: 1) Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer. 2) Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials provided\n+ * with the distribution. 3) Neither the name of the rultor.com nor\n+ * the names of its contributors may be used to endorse or promote\n+ * products derived from this software without specific prior written\n+ * permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT\n+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL\n+ * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n+ * OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+package com.rultor.agents.ec2;\n+\n+import com.amazonaws.auth.AWSCredentials;\n+import com.amazonaws.services.ec2.AmazonEC2Client;\n+import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest;\n+import com.amazonaws.services.ec2.model.DescribeInstanceStatusResult;\n+import com.amazonaws.services.ec2.model.Instance;\n+import com.amazonaws.services.ec2.model.InstanceState;\n+import com.amazonaws.services.ec2.model.RunInstancesRequest;\n+import com.jcabi.aspects.Immutable;\n+import com.jcabi.aspects.Tv;\n+import java.io.IOException;\n+import java.util.List;\n+import java.util.concurrent.TimeUnit;\n+import javax.validation.constraints.NotNull;\n+\n+/**\n+ * Amazon EC2 instance on demand.\n+ *\n+ * @author Marton Horvath (marton.horvath@m323.org)\n+ * @version $Id$\n+ * @since 2.0\n+ */\n+@Immutable\n+public class AmazonEC2 implements Amazon {\n+    /**\n+     * AWS credentials.\n+     */\n+    private final transient AWSCredentials credentials;\n+    /**\n+     * AWS region.\n+     */\n+    private final transient String region;\n+    /**\n+     * EC2 instance type.\n+     */\n+    private final transient String itype;\n+    /**\n+     * EC2 instance key pair name.\n+     */\n+    private final transient String keyname;\n+\n+    /**\n+     * Public ctor.\n+     * @param cred Credentials\n+     * @param zone AWS region\n+     * @param type Instance type\n+     * @param key Instance key pair name\n+     * @checkstyle ParameterNumberCheck (12 lines)\n+     */\n+    public AmazonEC2(\n+        @NotNull final AWSCredentials cred,\n+        @NotNull final String zone,\n+        @NotNull final String type,\n+        @NotNull final String key) {\n+        super();\n+        this.credentials = cred;\n+        this.region = zone;\n+        this.itype = type;\n+        this.keyname = key;\n+    }\n+\n+    // @checkstyle MagicNumberCheck (30 lines)\n+    @Override\n+    public final Instance runOnDemand() throws IOException {\n+        Instance instance = null;\n+        final AmazonEC2Client client = new AmazonEC2Client(\n+            this.credentials\n+        );\n+        client.setEndpoint(this.region);\n+        final RunInstancesRequest request = this.createRequest();\n+        final List<Instance> instances = client.runInstances(\n+            request\n+        ).getReservation().getInstances();\n+        if ((instances != null) && !instances.isEmpty()) {\n+            instance = instances.get(0);\n+        }\n+        InstanceState state = instance.getState();\n+        if (state.getCode() < 16) {\n+            final DescribeInstanceStatusRequest statusreq =\n+                new DescribeInstanceStatusRequest();\n+            statusreq.withInstanceIds(instance.getInstanceId());\n+            while (state.getCode() < 16) {\n+                try {\n+                    TimeUnit.SECONDS.sleep(Tv.FIFTEEN);","path":"src/main/java/com/rultor/agents/ec2/AmazonEC2.java","position":114,"original_position":114,"commit_id":"d321d18d5438a718f438c58afa0c598ac91967ec","original_commit_id":"d321d18d5438a718f438c58afa0c598ac91967ec","user":{"login":"krzyk","id":105730,"avatar_url":"https://avatars.githubusercontent.com/u/105730?v=3","gravatar_id":"","url":"https://api.github.com/users/krzyk","html_url":"https://github.com/krzyk","followers_url":"https://api.github.com/users/krzyk/followers","following_url":"https://api.github.com/users/krzyk/following{/other_user}","gists_url":"https://api.github.com/users/krzyk/gists{/gist_id}","starred_url":"https://api.github.com/users/krzyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krzyk/subscriptions","organizations_url":"https://api.github.com/users/krzyk/orgs","repos_url":"https://api.github.com/users/krzyk/repos","events_url":"https://api.github.com/users/krzyk/events{/privacy}","received_events_url":"https://api.github.com/users/krzyk/received_events","type":"User","site_admin":false},"body":"why wait here?","created_at":"2015-01-27T14:18:42Z","updated_at":"2015-01-27T14:18:42Z","html_url":"https://github.com/yegor256/rultor/pull/760#discussion_r23610049","pull_request_url":"https://api.github.com/repos/yegor256/rultor/pulls/760","_links":{"self":{"href":"https://api.github.com/repos/yegor256/rultor/pulls/comments/23610049"},"html":{"href":"https://github.com/yegor256/rultor/pull/760#discussion_r23610049"},"pull_request":{"href":"https://api.github.com/repos/yegor256/rultor/pulls/760"}}},"pull_request":{"url":"https://api.github.com/repos/yegor256/rultor/pulls/760","id":27970728,"html_url":"https://github.com/yegor256/rultor/pull/760","diff_url":"https://github.com/yegor256/rultor/pull/760.diff","patch_url":"https://github.com/yegor256/rultor/pull/760.patch","issue_url":"https://api.github.com/repos/yegor256/rultor/issues/760","number":760,"state":"open","locked":false,"title":"Implementation for com.rultor.agents.ec2.Amazon interface - Issue #755","user":{"login":"Marczeeee","id":5758886,"avatar_url":"https://avatars.githubusercontent.com/u/5758886?v=3","gravatar_id":"","url":"https://api.github.com/users/Marczeeee","html_url":"https://github.com/Marczeeee","followers_url":"https://api.github.com/users/Marczeeee/followers","following_url":"https://api.github.com/users/Marczeeee/following{/other_user}","gists_url":"https://api.github.com/users/Marczeeee/gists{/gist_id}","starred_url":"https://api.github.com/users/Marczeeee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Marczeeee/subscriptions","organizations_url":"https://api.github.com/users/Marczeeee/orgs","repos_url":"https://api.github.com/users/Marczeeee/repos","events_url":"https://api.github.com/users/Marczeeee/events{/privacy}","received_events_url":"https://api.github.com/users/Marczeeee/received_events","type":"User","site_admin":false},"body":"Isse #755","created_at":"2015-01-24T03:13:53Z","updated_at":"2015-01-27T14:18:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"18f3b8b3014ca44e80c6ae48dcb83815deb86430","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yegor256/rultor/pulls/760/commits","review_comments_url":"https://api.github.com/repos/yegor256/rultor/pulls/760/comments","review_comment_url":"https://api.github.com/repos/yegor256/rultor/pulls/comments/{number}","comments_url":"https://api.github.com/repos/yegor256/rultor/issues/760/comments","statuses_url":"https://api.github.com/repos/yegor256/rultor/statuses/d321d18d5438a718f438c58afa0c598ac91967ec","head":{"label":"Marczeeee:master","ref":"master","sha":"d321d18d5438a718f438c58afa0c598ac91967ec","user":{"login":"Marczeeee","id":5758886,"avatar_url":"https://avatars.githubusercontent.com/u/5758886?v=3","gravatar_id":"","url":"https://api.github.com/users/Marczeeee","html_url":"https://github.com/Marczeeee","followers_url":"https://api.github.com/users/Marczeeee/followers","following_url":"https://api.github.com/users/Marczeeee/following{/other_user}","gists_url":"https://api.github.com/users/Marczeeee/gists{/gist_id}","starred_url":"https://api.github.com/users/Marczeeee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Marczeeee/subscriptions","organizations_url":"https://api.github.com/users/Marczeeee/orgs","repos_url":"https://api.github.com/users/Marczeeee/repos","events_url":"https://api.github.com/users/Marczeeee/events{/privacy}","received_events_url":"https://api.github.com/users/Marczeeee/received_events","type":"User","site_admin":false},"repo":{"id":28839643,"name":"rultor","full_name":"Marczeeee/rultor","owner":{"login":"Marczeeee","id":5758886,"avatar_url":"https://avatars.githubusercontent.com/u/5758886?v=3","gravatar_id":"","url":"https://api.github.com/users/Marczeeee","html_url":"https://github.com/Marczeeee","followers_url":"https://api.github.com/users/Marczeeee/followers","following_url":"https://api.github.com/users/Marczeeee/following{/other_user}","gists_url":"https://api.github.com/users/Marczeeee/gists{/gist_id}","starred_url":"https://api.github.com/users/Marczeeee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Marczeeee/subscriptions","organizations_url":"https://api.github.com/users/Marczeeee/orgs","repos_url":"https://api.github.com/users/Marczeeee/repos","events_url":"https://api.github.com/users/Marczeeee/events{/privacy}","received_events_url":"https://api.github.com/users/Marczeeee/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Marczeeee/rultor","description":"DevOps Team Assistant","fork":true,"url":"https://api.github.com/repos/Marczeeee/rultor","forks_url":"https://api.github.com/repos/Marczeeee/rultor/forks","keys_url":"https://api.github.com/repos/Marczeeee/rultor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Marczeeee/rultor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Marczeeee/rultor/teams","hooks_url":"https://api.github.com/repos/Marczeeee/rultor/hooks","issue_events_url":"https://api.github.com/repos/Marczeeee/rultor/issues/events{/number}","events_url":"https://api.github.com/repos/Marczeeee/rultor/events","assignees_url":"https://api.github.com/repos/Marczeeee/rultor/assignees{/user}","branches_url":"https://api.github.com/repos/Marczeeee/rultor/branches{/branch}","tags_url":"https://api.github.com/repos/Marczeeee/rultor/tags","blobs_url":"https://api.github.com/repos/Marczeeee/rultor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Marczeeee/rultor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Marczeeee/rultor/git/refs{/sha}","trees_url":"https://api.github.com/repos/Marczeeee/rultor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Marczeeee/rultor/statuses/{sha}","languages_url":"https://api.github.com/repos/Marczeeee/rultor/languages","stargazers_url":"https://api.github.com/repos/Marczeeee/rultor/stargazers","contributors_url":"https://api.github.com/repos/Marczeeee/rultor/contributors","subscribers_url":"https://api.github.com/repos/Marczeeee/rultor/subscribers","subscription_url":"https://api.github.com/repos/Marczeeee/rultor/subscription","commits_url":"https://api.github.com/repos/Marczeeee/rultor/commits{/sha}","git_commits_url":"https://api.github.com/repos/Marczeeee/rultor/git/commits{/sha}","comments_url":"https://api.github.com/repos/Marczeeee/rultor/comments{/number}","issue_comment_url":"https://api.github.com/repos/Marczeeee/rultor/issues/comments/{number}","contents_url":"https://api.github.com/repos/Marczeeee/rultor/contents/{+path}","compare_url":"https://api.github.com/repos/Marczeeee/rultor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Marczeeee/rultor/merges","archive_url":"https://api.github.com/repos/Marczeeee/rultor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Marczeeee/rultor/downloads","issues_url":"https://api.github.com/repos/Marczeeee/rultor/issues{/number}","pulls_url":"https://api.github.com/repos/Marczeeee/rultor/pulls{/number}","milestones_url":"https://api.github.com/repos/Marczeeee/rultor/milestones{/number}","notifications_url":"https://api.github.com/repos/Marczeeee/rultor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Marczeeee/rultor/labels{/name}","releases_url":"https://api.github.com/repos/Marczeeee/rultor/releases{/id}","created_at":"2015-01-06T00:51:49Z","updated_at":"2015-01-24T03:10:53Z","pushed_at":"2015-01-24T03:10:52Z","git_url":"git://github.com/Marczeeee/rultor.git","ssh_url":"git@github.com:Marczeeee/rultor.git","clone_url":"https://github.com/Marczeeee/rultor.git","svn_url":"https://github.com/Marczeeee/rultor","homepage":"www.rultor.com","size":65209,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"yegor256:master","ref":"master","sha":"02ab61d1ae5bbf3bacbbfb06d2de592481ce7473","user":{"login":"yegor256","id":526301,"avatar_url":"https://avatars.githubusercontent.com/u/526301?v=3","gravatar_id":"","url":"https://api.github.com/users/yegor256","html_url":"https://github.com/yegor256","followers_url":"https://api.github.com/users/yegor256/followers","following_url":"https://api.github.com/users/yegor256/following{/other_user}","gists_url":"https://api.github.com/users/yegor256/gists{/gist_id}","starred_url":"https://api.github.com/users/yegor256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yegor256/subscriptions","organizations_url":"https://api.github.com/users/yegor256/orgs","repos_url":"https://api.github.com/users/yegor256/repos","events_url":"https://api.github.com/users/yegor256/events{/privacy}","received_events_url":"https://api.github.com/users/yegor256/received_events","type":"User","site_admin":false},"repo":{"id":8271291,"name":"rultor","full_name":"yegor256/rultor","owner":{"login":"yegor256","id":526301,"avatar_url":"https://avatars.githubusercontent.com/u/526301?v=3","gravatar_id":"","url":"https://api.github.com/users/yegor256","html_url":"https://github.com/yegor256","followers_url":"https://api.github.com/users/yegor256/followers","following_url":"https://api.github.com/users/yegor256/following{/other_user}","gists_url":"https://api.github.com/users/yegor256/gists{/gist_id}","starred_url":"https://api.github.com/users/yegor256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yegor256/subscriptions","organizations_url":"https://api.github.com/users/yegor256/orgs","repos_url":"https://api.github.com/users/yegor256/repos","events_url":"https://api.github.com/users/yegor256/events{/privacy}","received_events_url":"https://api.github.com/users/yegor256/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yegor256/rultor","description":"DevOps Team Assistant","fork":false,"url":"https://api.github.com/repos/yegor256/rultor","forks_url":"https://api.github.com/repos/yegor256/rultor/forks","keys_url":"https://api.github.com/repos/yegor256/rultor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yegor256/rultor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yegor256/rultor/teams","hooks_url":"https://api.github.com/repos/yegor256/rultor/hooks","issue_events_url":"https://api.github.com/repos/yegor256/rultor/issues/events{/number}","events_url":"https://api.github.com/repos/yegor256/rultor/events","assignees_url":"https://api.github.com/repos/yegor256/rultor/assignees{/user}","branches_url":"https://api.github.com/repos/yegor256/rultor/branches{/branch}","tags_url":"https://api.github.com/repos/yegor256/rultor/tags","blobs_url":"https://api.github.com/repos/yegor256/rultor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yegor256/rultor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yegor256/rultor/git/refs{/sha}","trees_url":"https://api.github.com/repos/yegor256/rultor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yegor256/rultor/statuses/{sha}","languages_url":"https://api.github.com/repos/yegor256/rultor/languages","stargazers_url":"https://api.github.com/repos/yegor256/rultor/stargazers","contributors_url":"https://api.github.com/repos/yegor256/rultor/contributors","subscribers_url":"https://api.github.com/repos/yegor256/rultor/subscribers","subscription_url":"https://api.github.com/repos/yegor256/rultor/subscription","commits_url":"https://api.github.com/repos/yegor256/rultor/commits{/sha}","git_commits_url":"https://api.github.com/repos/yegor256/rultor/git/commits{/sha}","comments_url":"https://api.github.com/repos/yegor256/rultor/comments{/number}","issue_comment_url":"https://api.github.com/repos/yegor256/rultor/issues/comments/{number}","contents_url":"https://api.github.com/repos/yegor256/rultor/contents/{+path}","compare_url":"https://api.github.com/repos/yegor256/rultor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yegor256/rultor/merges","archive_url":"https://api.github.com/repos/yegor256/rultor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yegor256/rultor/downloads","issues_url":"https://api.github.com/repos/yegor256/rultor/issues{/number}","pulls_url":"https://api.github.com/repos/yegor256/rultor/pulls{/number}","milestones_url":"https://api.github.com/repos/yegor256/rultor/milestones{/number}","notifications_url":"https://api.github.com/repos/yegor256/rultor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yegor256/rultor/labels{/name}","releases_url":"https://api.github.com/repos/yegor256/rultor/releases{/id}","created_at":"2013-02-18T15:39:50Z","updated_at":"2015-01-23T14:14:24Z","pushed_at":"2015-01-23T14:14:24Z","git_url":"git://github.com/yegor256/rultor.git","ssh_url":"git@github.com:yegor256/rultor.git","clone_url":"https://github.com/yegor256/rultor.git","svn_url":"https://github.com/yegor256/rultor","homepage":"www.rultor.com","size":79658,"stargazers_count":64,"watchers_count":64,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":31,"mirror_url":null,"open_issues_count":22,"forks":31,"open_issues":22,"watchers":64,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yegor256/rultor/pulls/760"},"html":{"href":"https://github.com/yegor256/rultor/pull/760"},"issue":{"href":"https://api.github.com/repos/yegor256/rultor/issues/760"},"comments":{"href":"https://api.github.com/repos/yegor256/rultor/issues/760/comments"},"review_comments":{"href":"https://api.github.com/repos/yegor256/rultor/pulls/760/comments"},"review_comment":{"href":"https://api.github.com/repos/yegor256/rultor/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/yegor256/rultor/pulls/760/commits"},"statuses":{"href":"https://api.github.com/repos/yegor256/rultor/statuses/d321d18d5438a718f438c58afa0c598ac91967ec"}}}}