{"action":"created","comment":{"url":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/comments/73173002","id":73173002,"diff_hunk":"@@ -0,0 +1,212 @@\n+/*\n+ * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates\n+ * and other contributors as indicated by the @author tags.\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.hawkular.apm.server.elasticsearch;\n+\n+import java.io.IOException;\n+import java.io.StringWriter;\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.function.Function;\n+\n+import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;\n+import org.elasticsearch.action.bulk.BulkRequestBuilder;\n+import org.elasticsearch.action.bulk.BulkResponse;\n+import org.elasticsearch.action.get.GetResponse;\n+import org.elasticsearch.action.search.SearchRequestBuilder;\n+import org.elasticsearch.action.search.SearchResponse;\n+import org.elasticsearch.action.search.SearchType;\n+import org.elasticsearch.index.query.QueryBuilder;\n+import org.elasticsearch.index.query.QueryBuilders;\n+import org.elasticsearch.indices.IndexMissingException;\n+import org.elasticsearch.search.SearchHit;\n+import org.hawkular.apm.api.services.StoreException;\n+import org.hawkular.apm.server.api.model.zipkin.Span;\n+import org.hawkular.apm.server.api.services.SpanService;\n+import org.hawkular.apm.server.elasticsearch.log.MsgLogger;\n+\n+import com.fasterxml.jackson.core.JsonGenerator;\n+import com.fasterxml.jackson.core.JsonParser;\n+import com.fasterxml.jackson.databind.ObjectMapper;\n+\n+/**\n+ * @author Pavol Loffay\n+ */\n+public class SpanServiceElasticsearch implements SpanService {\n+\n+    private static final MsgLogger log = MsgLogger.LOGGER;\n+\n+    public static final String SPAN_TYPE = \"span\";\n+\n+    private static final ObjectMapper mapper = new ObjectMapper();\n+\n+    private ElasticsearchClient client = ElasticsearchClient.getSingleton();\n+\n+\n+    @Override\n+    public Span getSpan(String tenantId, String id) {\n+\n+        GetResponse response = null;\n+        try {\n+            response = client.getClient()\n+                    .prepareGet(client.getIndex(tenantId), SPAN_TYPE, id)\n+                    .setRouting(id)\n+                    .execute()\n+                    .actionGet();\n+        } catch (IndexMissingException ex) {\n+            log.errorf(\"Missing span index %s\", tenantId);\n+            return null;\n+        }\n+\n+        Span span = null;\n+        if (!response.isSourceEmpty()) {\n+            try {\n+                span = deserialize(response.getSourceAsString(), Span.class);\n+            } catch (IOException ex) {\n+                log.errorFailedToParse(ex);\n+                throw new IllegalStateException(\"Failed to deserialize span\", ex);\n+            }\n+        }\n+\n+        log.tracef(\"Get span with id[%s] is: %s\", id, span);\n+\n+        return span;\n+    }\n+\n+    @Override\n+    public List<Span> getChildren(String tenantId, String id) {\n+\n+        List<Span> spans = new ArrayList<>();\n+        final String index = client.getIndex(tenantId);\n+        try {\n+\n+            RefreshRequestBuilder refreshRequestBuilder = client.getClient()\n+                    .admin()\n+                    .indices()\n+                    .prepareRefresh(index);\n+\n+            client.getClient()\n+                    .admin()\n+                    .indices()\n+                    .refresh(refreshRequestBuilder.request())\n+                    .actionGet();\n+\n+            QueryBuilder query = QueryBuilders.termQuery(\"parentId\", id);\n+\n+            SearchRequestBuilder request = client.getClient()\n+                    .prepareSearch(index)\n+                    .setTypes(SPAN_TYPE)\n+                    .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)\n+                    .setQuery(query);\n+\n+            SearchResponse response = request.execute()\n+                    .actionGet();\n+\n+            for (SearchHit searchHitFields : response.getHits()) {\n+                try {\n+                    spans.add(deserialize(searchHitFields.getSourceAsString(), Span.class));\n+                } catch (IOException ex) {\n+                    log.errorFailedToParse(ex);\n+                    throw new IllegalStateException(\"Failed to deserialize span\", ex);\n+                }\n+            }\n+        } catch (IndexMissingException ex) {\n+            log.errorf(\"No index[%s] found, so unable to retrieve spans\", index);","path":"server/elasticsearch/src/main/java/org/hawkular/apm/server/elasticsearch/SpanServiceElasticsearch.java","position":128,"original_position":128,"commit_id":"b348becfdaa1aa9ed1ed65a5681c191e5d8aac3b","original_commit_id":"b348becfdaa1aa9ed1ed65a5681c191e5d8aac3b","user":{"login":"jpkrohling","id":13387,"avatar_url":"https://avatars.githubusercontent.com/u/13387?v=3","gravatar_id":"","url":"https://api.github.com/users/jpkrohling","html_url":"https://github.com/jpkrohling","followers_url":"https://api.github.com/users/jpkrohling/followers","following_url":"https://api.github.com/users/jpkrohling/following{/other_user}","gists_url":"https://api.github.com/users/jpkrohling/gists{/gist_id}","starred_url":"https://api.github.com/users/jpkrohling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpkrohling/subscriptions","organizations_url":"https://api.github.com/users/jpkrohling/orgs","repos_url":"https://api.github.com/users/jpkrohling/repos","events_url":"https://api.github.com/users/jpkrohling/events{/privacy}","received_events_url":"https://api.github.com/users/jpkrohling/received_events","type":"User","site_admin":false},"body":"No need to change this for the PR, though: it's your decision how you want to let callers handle this :)","created_at":"2016-08-02T15:05:27Z","updated_at":"2016-08-02T15:05:27Z","html_url":"https://github.com/hawkular/hawkular-apm/pull/500#discussion_r73173002","pull_request_url":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/500","_links":{"self":{"href":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/comments/73173002"},"html":{"href":"https://github.com/hawkular/hawkular-apm/pull/500#discussion_r73173002"},"pull_request":{"href":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/500"}}},"pull_request":{"url":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/500","id":79719078,"html_url":"https://github.com/hawkular/hawkular-apm/pull/500","diff_url":"https://github.com/hawkular/hawkular-apm/pull/500.diff","patch_url":"https://github.com/hawkular/hawkular-apm/pull/500.patch","issue_url":"https://api.github.com/repos/hawkular/hawkular-apm/issues/500","number":500,"state":"open","locked":false,"title":"HWKAPM-525 | Span Service and Elasticsearch Impl","user":{"login":"pavolloffay","id":5618424,"avatar_url":"https://avatars.githubusercontent.com/u/5618424?v=3","gravatar_id":"","url":"https://api.github.com/users/pavolloffay","html_url":"https://github.com/pavolloffay","followers_url":"https://api.github.com/users/pavolloffay/followers","following_url":"https://api.github.com/users/pavolloffay/following{/other_user}","gists_url":"https://api.github.com/users/pavolloffay/gists{/gist_id}","starred_url":"https://api.github.com/users/pavolloffay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavolloffay/subscriptions","organizations_url":"https://api.github.com/users/pavolloffay/orgs","repos_url":"https://api.github.com/users/pavolloffay/repos","events_url":"https://api.github.com/users/pavolloffay/events{/privacy}","received_events_url":"https://api.github.com/users/pavolloffay/received_events","type":"User","site_admin":false},"body":"https://issues.jboss.org/browse/HWKAPM-525\r\n\r\n\r\nReview notes:\r\n* `SpanService.store()` takes the same function as `SpanCache` to modify ids of given spans. However, modified ids are not stored in span entity but only as an index.","created_at":"2016-08-02T11:30:32Z","updated_at":"2016-08-02T15:05:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"897dc4659407a9adc4111928a5abbfb95d6458f6","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/500/commits","review_comments_url":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/500/comments","review_comment_url":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hawkular/hawkular-apm/issues/500/comments","statuses_url":"https://api.github.com/repos/hawkular/hawkular-apm/statuses/b348becfdaa1aa9ed1ed65a5681c191e5d8aac3b","head":{"label":"pavolloffay:HWKAPM-525-span-service-and-elasticsearch-impl","ref":"HWKAPM-525-span-service-and-elasticsearch-impl","sha":"b348becfdaa1aa9ed1ed65a5681c191e5d8aac3b","user":{"login":"pavolloffay","id":5618424,"avatar_url":"https://avatars.githubusercontent.com/u/5618424?v=3","gravatar_id":"","url":"https://api.github.com/users/pavolloffay","html_url":"https://github.com/pavolloffay","followers_url":"https://api.github.com/users/pavolloffay/followers","following_url":"https://api.github.com/users/pavolloffay/following{/other_user}","gists_url":"https://api.github.com/users/pavolloffay/gists{/gist_id}","starred_url":"https://api.github.com/users/pavolloffay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavolloffay/subscriptions","organizations_url":"https://api.github.com/users/pavolloffay/orgs","repos_url":"https://api.github.com/users/pavolloffay/repos","events_url":"https://api.github.com/users/pavolloffay/events{/privacy}","received_events_url":"https://api.github.com/users/pavolloffay/received_events","type":"User","site_admin":false},"repo":{"id":54576177,"name":"hawkular-apm","full_name":"pavolloffay/hawkular-apm","owner":{"login":"pavolloffay","id":5618424,"avatar_url":"https://avatars.githubusercontent.com/u/5618424?v=3","gravatar_id":"","url":"https://api.github.com/users/pavolloffay","html_url":"https://github.com/pavolloffay","followers_url":"https://api.github.com/users/pavolloffay/followers","following_url":"https://api.github.com/users/pavolloffay/following{/other_user}","gists_url":"https://api.github.com/users/pavolloffay/gists{/gist_id}","starred_url":"https://api.github.com/users/pavolloffay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavolloffay/subscriptions","organizations_url":"https://api.github.com/users/pavolloffay/orgs","repos_url":"https://api.github.com/users/pavolloffay/repos","events_url":"https://api.github.com/users/pavolloffay/events{/privacy}","received_events_url":"https://api.github.com/users/pavolloffay/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pavolloffay/hawkular-apm","description":"Business Transaction Management for Hawkular","fork":true,"url":"https://api.github.com/repos/pavolloffay/hawkular-apm","forks_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/forks","keys_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/teams","hooks_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/hooks","issue_events_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/issues/events{/number}","events_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/events","assignees_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/assignees{/user}","branches_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/branches{/branch}","tags_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/tags","blobs_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/git/refs{/sha}","trees_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/statuses/{sha}","languages_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/languages","stargazers_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/stargazers","contributors_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/contributors","subscribers_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/subscribers","subscription_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/subscription","commits_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/commits{/sha}","git_commits_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/git/commits{/sha}","comments_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/comments{/number}","issue_comment_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/issues/comments{/number}","contents_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/contents/{+path}","compare_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/merges","archive_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/downloads","issues_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/issues{/number}","pulls_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/pulls{/number}","milestones_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/milestones{/number}","notifications_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/labels{/name}","releases_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/releases{/id}","deployments_url":"https://api.github.com/repos/pavolloffay/hawkular-apm/deployments","created_at":"2016-03-23T16:34:43Z","updated_at":"2016-07-15T10:12:23Z","pushed_at":"2016-08-02T14:20:57Z","git_url":"git://github.com/pavolloffay/hawkular-apm.git","ssh_url":"git@github.com:pavolloffay/hawkular-apm.git","clone_url":"https://github.com/pavolloffay/hawkular-apm.git","svn_url":"https://github.com/pavolloffay/hawkular-apm","homepage":"","size":5646,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"hawkular:master","ref":"master","sha":"d76a9f4fad8ead20af9b1dc97d74f22b4c666014","user":{"login":"hawkular","id":10179627,"avatar_url":"https://avatars.githubusercontent.com/u/10179627?v=3","gravatar_id":"","url":"https://api.github.com/users/hawkular","html_url":"https://github.com/hawkular","followers_url":"https://api.github.com/users/hawkular/followers","following_url":"https://api.github.com/users/hawkular/following{/other_user}","gists_url":"https://api.github.com/users/hawkular/gists{/gist_id}","starred_url":"https://api.github.com/users/hawkular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hawkular/subscriptions","organizations_url":"https://api.github.com/users/hawkular/orgs","repos_url":"https://api.github.com/users/hawkular/repos","events_url":"https://api.github.com/users/hawkular/events{/privacy}","received_events_url":"https://api.github.com/users/hawkular/received_events","type":"Organization","site_admin":false},"repo":{"id":34446334,"name":"hawkular-apm","full_name":"hawkular/hawkular-apm","owner":{"login":"hawkular","id":10179627,"avatar_url":"https://avatars.githubusercontent.com/u/10179627?v=3","gravatar_id":"","url":"https://api.github.com/users/hawkular","html_url":"https://github.com/hawkular","followers_url":"https://api.github.com/users/hawkular/followers","following_url":"https://api.github.com/users/hawkular/following{/other_user}","gists_url":"https://api.github.com/users/hawkular/gists{/gist_id}","starred_url":"https://api.github.com/users/hawkular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hawkular/subscriptions","organizations_url":"https://api.github.com/users/hawkular/orgs","repos_url":"https://api.github.com/users/hawkular/repos","events_url":"https://api.github.com/users/hawkular/events{/privacy}","received_events_url":"https://api.github.com/users/hawkular/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hawkular/hawkular-apm","description":"Application Performance Management for Hawkular","fork":false,"url":"https://api.github.com/repos/hawkular/hawkular-apm","forks_url":"https://api.github.com/repos/hawkular/hawkular-apm/forks","keys_url":"https://api.github.com/repos/hawkular/hawkular-apm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hawkular/hawkular-apm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hawkular/hawkular-apm/teams","hooks_url":"https://api.github.com/repos/hawkular/hawkular-apm/hooks","issue_events_url":"https://api.github.com/repos/hawkular/hawkular-apm/issues/events{/number}","events_url":"https://api.github.com/repos/hawkular/hawkular-apm/events","assignees_url":"https://api.github.com/repos/hawkular/hawkular-apm/assignees{/user}","branches_url":"https://api.github.com/repos/hawkular/hawkular-apm/branches{/branch}","tags_url":"https://api.github.com/repos/hawkular/hawkular-apm/tags","blobs_url":"https://api.github.com/repos/hawkular/hawkular-apm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hawkular/hawkular-apm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hawkular/hawkular-apm/git/refs{/sha}","trees_url":"https://api.github.com/repos/hawkular/hawkular-apm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hawkular/hawkular-apm/statuses/{sha}","languages_url":"https://api.github.com/repos/hawkular/hawkular-apm/languages","stargazers_url":"https://api.github.com/repos/hawkular/hawkular-apm/stargazers","contributors_url":"https://api.github.com/repos/hawkular/hawkular-apm/contributors","subscribers_url":"https://api.github.com/repos/hawkular/hawkular-apm/subscribers","subscription_url":"https://api.github.com/repos/hawkular/hawkular-apm/subscription","commits_url":"https://api.github.com/repos/hawkular/hawkular-apm/commits{/sha}","git_commits_url":"https://api.github.com/repos/hawkular/hawkular-apm/git/commits{/sha}","comments_url":"https://api.github.com/repos/hawkular/hawkular-apm/comments{/number}","issue_comment_url":"https://api.github.com/repos/hawkular/hawkular-apm/issues/comments{/number}","contents_url":"https://api.github.com/repos/hawkular/hawkular-apm/contents/{+path}","compare_url":"https://api.github.com/repos/hawkular/hawkular-apm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hawkular/hawkular-apm/merges","archive_url":"https://api.github.com/repos/hawkular/hawkular-apm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hawkular/hawkular-apm/downloads","issues_url":"https://api.github.com/repos/hawkular/hawkular-apm/issues{/number}","pulls_url":"https://api.github.com/repos/hawkular/hawkular-apm/pulls{/number}","milestones_url":"https://api.github.com/repos/hawkular/hawkular-apm/milestones{/number}","notifications_url":"https://api.github.com/repos/hawkular/hawkular-apm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hawkular/hawkular-apm/labels{/name}","releases_url":"https://api.github.com/repos/hawkular/hawkular-apm/releases{/id}","deployments_url":"https://api.github.com/repos/hawkular/hawkular-apm/deployments","created_at":"2015-04-23T09:17:50Z","updated_at":"2016-08-01T00:58:50Z","pushed_at":"2016-08-02T14:20:58Z","git_url":"git://github.com/hawkular/hawkular-apm.git","ssh_url":"git@github.com:hawkular/hawkular-apm.git","clone_url":"https://github.com/hawkular/hawkular-apm.git","svn_url":"https://github.com/hawkular/hawkular-apm","homepage":"","size":5680,"stargazers_count":14,"watchers_count":14,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":3,"forks":13,"open_issues":3,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/500"},"html":{"href":"https://github.com/hawkular/hawkular-apm/pull/500"},"issue":{"href":"https://api.github.com/repos/hawkular/hawkular-apm/issues/500"},"comments":{"href":"https://api.github.com/repos/hawkular/hawkular-apm/issues/500/comments"},"review_comments":{"href":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/500/comments"},"review_comment":{"href":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hawkular/hawkular-apm/pulls/500/commits"},"statuses":{"href":"https://api.github.com/repos/hawkular/hawkular-apm/statuses/b348becfdaa1aa9ed1ed65a5681c191e5d8aac3b"}}}}
{"actor":{"display_login":"jpkrohling"}}