{"action":"created","comment":{"url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/comments/46427360","id":46427360,"diff_hunk":"@@ -132,90 +140,164 @@ public Environment setUp(final AbstractBuild build, final Launcher launcher, fin\n             String finalGroup = applyMacro(build, listener, f.group);\n             String finalLabel = applyMacro(build, listener, f.label);\n             finalDeviceFilters.add(new DeviceFilter(finalGroup, finalLabel));\n+\n         }\n \n-        String buildIdentifier = String.format(\"%s_%s\", finalMemTotal, finalBuildURL);\n+\n+        String buildIdentifier = String.format(\"%s_%s\", finalMemTotal, UrlHandler.removeBewit(finalBuildURL));\n+\n+       //    printDeviceDetails(finalMemTotal, finalBuildURL, finalDeviceFilters);\n \n         APIDevice device = null;\n \n         APIDeviceSession session = null;\n \n-        int retries = descriptor.getFlashRetries();\n-        do {\n+        Long sessionId = null;\n+\n+        Long testRunId = null;\n \n+        if(opensConnections) {\n+            logger.info(\"Flash device and open connection immediately\");\n+\n+            ArrayList<DeviceFilter> searchFilters = (ArrayList<DeviceFilter>) finalDeviceFilters.clone();\n+            searchFilters.add(new DeviceFilter(BUILD_IDENTIFIER_LABEL_GROUP, buildIdentifier));\n             try {\n-                device = getDevice(build, launcher, logger, client, finalDeviceFilters, buildIdentifier, finalBuildURL, finalMemTotal, finalFlashProjectName);\n+                //check if there is device available so no need to flash\n+                device = searchDevice(logger, client, searchFilters, false);\n             } catch (APIException e) {\n-                logger.error(\"Failed to retrieve device by build id \" + e.getMessage());\n-                throw new IOException(e);\n-            } catch (FlashTimeoutException fte) {\n-                logger.warn(fte.getMessage());\n+                e.printStackTrace();\n+            }\n+\n+            if (device != null) {\n+                logger.info(\"Found device \" + device.getDisplayName());\n+                Map<String, String> deviceSessionsParams = new HashMap<String, String>();\n+                deviceSessionsParams.put(\"deviceModelId\", device.getId().toString());\n+                deviceSessionsParams.put(\"timeout\", descriptor.getSessionTimeout().toString());\n+\n+                try {\n+                    session = client.post(\"/me/device-sessions\", deviceSessionsParams, APIDeviceSession.class);\n+                    sessionId = session.getId();\n+                } catch (APIException e) {\n+                    //allow to continue if device lock can't be created otherwise throw IOException\n+                    if (e.getStatus() != 400) {\n+                        logger.info(\"Failed to start device session \" + e.getMessage());\n+                        throw new IOException(e);\n+                    }\n+                }\n+\n+                if (session != null && !waitUntilDeviceSessionIsRunning(session, WAIT_FOR_DEVICE_SESSION)) {\n+                    logger.info(\"Timeout when waiting for device session \" + session.getId());\n+                    releaseDeviceSession(logger, client, session.getId(), testRunId);\n+                    session = null;\n+                    sessionId = null;\n+\n+                }\n+\n             }\n-            if(device == null) {\n-                continue;\n+            APITestRun testRun = null;\n+            int retries = descriptor.getFlashRetries();\n+            //Check if session was not found if not, start project run\n+            if(session == null) {\n+                do {\n+                    try {\n+                        testRun = flashAndOpenConnection(build, launcher, logger, client, finalDeviceFilters, finalBuildURL, finalMemTotal, finalFlashProjectName);\n+                        if(testRun != null) {\n+                            testRunId = testRun.getId();\n+                            sessionId = testRun.getDeviceRunsResource().getEntity().getData().get(0).getDeviceSessionId();\n+                            device = testRun.getDeviceRunsResource().getEntity().getData().get(0).getDevice();","path":"src/main/java/jenkins/plugins/testdroid/DeviceSessionWrapper.java","position":108,"original_position":108,"commit_id":"6806278ba116744c5aa2d92599f1dc601e32c759","original_commit_id":"6806278ba116744c5aa2d92599f1dc601e32c759","user":{"login":"JohanLorenzo","id":5907366,"avatar_url":"https://avatars.githubusercontent.com/u/5907366?v=3","gravatar_id":"","url":"https://api.github.com/users/JohanLorenzo","html_url":"https://github.com/JohanLorenzo","followers_url":"https://api.github.com/users/JohanLorenzo/followers","following_url":"https://api.github.com/users/JohanLorenzo/following{/other_user}","gists_url":"https://api.github.com/users/JohanLorenzo/gists{/gist_id}","starred_url":"https://api.github.com/users/JohanLorenzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohanLorenzo/subscriptions","organizations_url":"https://api.github.com/users/JohanLorenzo/orgs","repos_url":"https://api.github.com/users/JohanLorenzo/repos","events_url":"https://api.github.com/users/JohanLorenzo/events{/privacy}","received_events_url":"https://api.github.com/users/JohanLorenzo/received_events","type":"User","site_admin":false},"body":"Same question as [this one](https://github.com/JohanLorenzo/testdroid-marionette-plugin/pull/2/files#r46427310)","created_at":"2015-12-02T15:26:21Z","updated_at":"2015-12-02T15:26:21Z","html_url":"https://github.com/JohanLorenzo/testdroid-marionette-plugin/pull/2#discussion_r46427360","pull_request_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/comments/46427360"},"html":{"href":"https://github.com/JohanLorenzo/testdroid-marionette-plugin/pull/2#discussion_r46427360"},"pull_request":{"href":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/2","id":52272429,"html_url":"https://github.com/JohanLorenzo/testdroid-marionette-plugin/pull/2","diff_url":"https://github.com/JohanLorenzo/testdroid-marionette-plugin/pull/2.diff","patch_url":"https://github.com/JohanLorenzo/testdroid-marionette-plugin/pull/2.patch","issue_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/issues/2","number":2,"state":"open","locked":false,"title":"Feature direct connection","user":{"login":"srautiai","id":1098080,"avatar_url":"https://avatars.githubusercontent.com/u/1098080?v=3","gravatar_id":"","url":"https://api.github.com/users/srautiai","html_url":"https://github.com/srautiai","followers_url":"https://api.github.com/users/srautiai/followers","following_url":"https://api.github.com/users/srautiai/following{/other_user}","gists_url":"https://api.github.com/users/srautiai/gists{/gist_id}","starred_url":"https://api.github.com/users/srautiai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srautiai/subscriptions","organizations_url":"https://api.github.com/users/srautiai/orgs","repos_url":"https://api.github.com/users/srautiai/repos","events_url":"https://api.github.com/users/srautiai/events{/privacy}","received_events_url":"https://api.github.com/users/srautiai/received_events","type":"User","site_admin":false},"body":"This feature adds checkbox under advanced settings where project name is specified. If checkbox is checked plugin opens queries adb/marionette port status after the flashing is completed without opening a new session. Note. The project needs to be configured to use this feature also in cloud, currently \"flash-fxos-task-cluster\" project is the one which support this. ","created_at":"2015-12-01T15:32:57Z","updated_at":"2015-12-02T15:26:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f69cd8785c2c35bd6b97232d9990e9cb36dcf858","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/2/commits","review_comments_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/2/comments","review_comment_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/issues/2/comments","statuses_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/statuses/6806278ba116744c5aa2d92599f1dc601e32c759","head":{"label":"srautiai:feature_direct_connection","ref":"feature_direct_connection","sha":"6806278ba116744c5aa2d92599f1dc601e32c759","user":{"login":"srautiai","id":1098080,"avatar_url":"https://avatars.githubusercontent.com/u/1098080?v=3","gravatar_id":"","url":"https://api.github.com/users/srautiai","html_url":"https://github.com/srautiai","followers_url":"https://api.github.com/users/srautiai/followers","following_url":"https://api.github.com/users/srautiai/following{/other_user}","gists_url":"https://api.github.com/users/srautiai/gists{/gist_id}","starred_url":"https://api.github.com/users/srautiai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srautiai/subscriptions","organizations_url":"https://api.github.com/users/srautiai/orgs","repos_url":"https://api.github.com/users/srautiai/repos","events_url":"https://api.github.com/users/srautiai/events{/privacy}","received_events_url":"https://api.github.com/users/srautiai/received_events","type":"User","site_admin":false},"repo":{"id":29211833,"name":"testdroid-marionette-plugin","full_name":"srautiai/testdroid-marionette-plugin","owner":{"login":"srautiai","id":1098080,"avatar_url":"https://avatars.githubusercontent.com/u/1098080?v=3","gravatar_id":"","url":"https://api.github.com/users/srautiai","html_url":"https://github.com/srautiai","followers_url":"https://api.github.com/users/srautiai/followers","following_url":"https://api.github.com/users/srautiai/following{/other_user}","gists_url":"https://api.github.com/users/srautiai/gists{/gist_id}","starred_url":"https://api.github.com/users/srautiai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srautiai/subscriptions","organizations_url":"https://api.github.com/users/srautiai/orgs","repos_url":"https://api.github.com/users/srautiai/repos","events_url":"https://api.github.com/users/srautiai/events{/privacy}","received_events_url":"https://api.github.com/users/srautiai/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/srautiai/testdroid-marionette-plugin","description":"Jenkins plugin for managing a Testdroid device session with Marionette enabled","fork":true,"url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin","forks_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/forks","keys_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/teams","hooks_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/hooks","issue_events_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/events","assignees_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/tags","blobs_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/languages","stargazers_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/stargazers","contributors_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/contributors","subscribers_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/subscribers","subscription_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/subscription","commits_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/merges","archive_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/downloads","issues_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/labels{/name}","releases_url":"https://api.github.com/repos/srautiai/testdroid-marionette-plugin/releases{/id}","created_at":"2015-01-13T21:21:44Z","updated_at":"2015-04-07T18:45:31Z","pushed_at":"2015-12-01T07:16:36Z","git_url":"git://github.com/srautiai/testdroid-marionette-plugin.git","ssh_url":"git@github.com:srautiai/testdroid-marionette-plugin.git","clone_url":"https://github.com/srautiai/testdroid-marionette-plugin.git","svn_url":"https://github.com/srautiai/testdroid-marionette-plugin","homepage":null,"size":256,"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":"JohanLorenzo:bug-1221510","ref":"bug-1221510","sha":"baae5574e05e1042fccaa77d774fabaf081db450","user":{"login":"JohanLorenzo","id":5907366,"avatar_url":"https://avatars.githubusercontent.com/u/5907366?v=3","gravatar_id":"","url":"https://api.github.com/users/JohanLorenzo","html_url":"https://github.com/JohanLorenzo","followers_url":"https://api.github.com/users/JohanLorenzo/followers","following_url":"https://api.github.com/users/JohanLorenzo/following{/other_user}","gists_url":"https://api.github.com/users/JohanLorenzo/gists{/gist_id}","starred_url":"https://api.github.com/users/JohanLorenzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohanLorenzo/subscriptions","organizations_url":"https://api.github.com/users/JohanLorenzo/orgs","repos_url":"https://api.github.com/users/JohanLorenzo/repos","events_url":"https://api.github.com/users/JohanLorenzo/events{/privacy}","received_events_url":"https://api.github.com/users/JohanLorenzo/received_events","type":"User","site_admin":false},"repo":{"id":40293667,"name":"testdroid-marionette-plugin","full_name":"JohanLorenzo/testdroid-marionette-plugin","owner":{"login":"JohanLorenzo","id":5907366,"avatar_url":"https://avatars.githubusercontent.com/u/5907366?v=3","gravatar_id":"","url":"https://api.github.com/users/JohanLorenzo","html_url":"https://github.com/JohanLorenzo","followers_url":"https://api.github.com/users/JohanLorenzo/followers","following_url":"https://api.github.com/users/JohanLorenzo/following{/other_user}","gists_url":"https://api.github.com/users/JohanLorenzo/gists{/gist_id}","starred_url":"https://api.github.com/users/JohanLorenzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohanLorenzo/subscriptions","organizations_url":"https://api.github.com/users/JohanLorenzo/orgs","repos_url":"https://api.github.com/users/JohanLorenzo/repos","events_url":"https://api.github.com/users/JohanLorenzo/events{/privacy}","received_events_url":"https://api.github.com/users/JohanLorenzo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JohanLorenzo/testdroid-marionette-plugin","description":"Jenkins plugin for managing a Testdroid device session with Marionette enabled","fork":true,"url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin","forks_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/forks","keys_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/teams","hooks_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/hooks","issue_events_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/events","assignees_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/tags","blobs_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/languages","stargazers_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/stargazers","contributors_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/contributors","subscribers_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/subscribers","subscription_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/subscription","commits_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/merges","archive_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/downloads","issues_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/labels{/name}","releases_url":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/releases{/id}","created_at":"2015-08-06T08:27:15Z","updated_at":"2015-08-06T08:27:16Z","pushed_at":"2015-12-01T15:32:57Z","git_url":"git://github.com/JohanLorenzo/testdroid-marionette-plugin.git","ssh_url":"git@github.com:JohanLorenzo/testdroid-marionette-plugin.git","clone_url":"https://github.com/JohanLorenzo/testdroid-marionette-plugin.git","svn_url":"https://github.com/JohanLorenzo/testdroid-marionette-plugin","homepage":null,"size":324,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/2"},"html":{"href":"https://github.com/JohanLorenzo/testdroid-marionette-plugin/pull/2"},"issue":{"href":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/issues/2"},"comments":{"href":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/JohanLorenzo/testdroid-marionette-plugin/statuses/6806278ba116744c5aa2d92599f1dc601e32c759"}}}}