{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/65984591","id":65984591,"diff_hunk":"@@ -0,0 +1,164 @@\n+/*\n+ * Licensed to Elasticsearch under one or more contributor\n+ * license agreements. See the NOTICE file distributed with\n+ * this work for additional information regarding copyright\n+ * ownership. Elasticsearch licenses this file to you under\n+ * the Apache License, Version 2.0 (the \"License\"); you may\n+ * 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,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+package org.elasticsearch.action.admin.indices.rollover;\n+\n+import org.elasticsearch.ElasticsearchParseException;\n+import org.elasticsearch.action.ActionRequestValidationException;\n+import org.elasticsearch.action.IndicesRequest;\n+import org.elasticsearch.action.support.IndicesOptions;\n+import org.elasticsearch.action.support.master.AcknowledgedRequest;\n+import org.elasticsearch.common.bytes.BytesReference;\n+import org.elasticsearch.common.io.stream.StreamInput;\n+import org.elasticsearch.common.io.stream.StreamOutput;\n+import org.elasticsearch.common.xcontent.XContentFactory;\n+import org.elasticsearch.common.xcontent.XContentParser;\n+import org.elasticsearch.common.xcontent.XContentType;\n+\n+import java.io.IOException;\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.Map;\n+\n+import static org.elasticsearch.action.ValidateActions.addValidationError;\n+\n+/**\n+ * Request class to swap index under an alias given some predicates\n+ * TODO: documentation\n+ */\n+public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implements IndicesRequest {\n+\n+    private String sourceAlias;\n+    private String optionalTargetAlias;\n+    private List<Condition> conditions = new ArrayList<>();\n+\n+    RolloverRequest() {}\n+\n+    public RolloverRequest(String sourceAlias, String optionalTargetAlias) {\n+        this.sourceAlias = sourceAlias;\n+        this.optionalTargetAlias = optionalTargetAlias;\n+    }\n+\n+    @Override\n+    public ActionRequestValidationException validate() {\n+        ActionRequestValidationException validationException = null;\n+        if (sourceAlias == null) {\n+            validationException = addValidationError(\"source alias is missing\", validationException);\n+        }\n+        return validationException;\n+    }\n+\n+    @Override\n+    public void readFrom(StreamInput in) throws IOException {\n+        super.readFrom(in);\n+        sourceAlias = in.readString();\n+        optionalTargetAlias = in.readOptionalString();\n+        int size = in.readVInt();\n+        for (int i = 0; i < size; i++) {\n+            Condition.ConditionType type = Condition.ConditionType.fromId(in.readByte());\n+            long value = in.readLong();\n+            this.conditions.add(new Condition(type, value));\n+        }\n+    }\n+\n+    @Override\n+    public void writeTo(StreamOutput out) throws IOException {\n+        super.writeTo(out);\n+        out.writeString(sourceAlias);\n+        out.writeOptionalString(optionalTargetAlias);\n+        out.writeVInt(conditions.size());\n+        for (Condition condition : conditions) {\n+            out.writeByte(condition.getType().getId());\n+            out.writeLong(condition.getValue());\n+        }\n+    }\n+\n+    @Override\n+    public String[] indices() {\n+        return new String[] {sourceAlias};\n+    }\n+\n+    @Override\n+    public IndicesOptions indicesOptions() {\n+        return IndicesOptions.strictSingleIndexNoExpandForbidClosed();\n+    }\n+\n+    public void setSourceAlias(String sourceAlias) {\n+        this.sourceAlias = sourceAlias;\n+    }\n+\n+    public void setOptionalTargetAlias(String optionalTargetAlias) {\n+        this.optionalTargetAlias = optionalTargetAlias;\n+    }\n+\n+    public void addMaxIndexAgeCondition(String age) {\n+        addCondition(Condition.ConditionType.MAX_AGE, Condition.ConditionType.parseFromString(Condition.ConditionType.MAX_AGE, age));\n+    }\n+\n+    public void addMaxIndexDocsCondition(String docs) {\n+        addCondition(Condition.ConditionType.MAX_DOCS, Condition.ConditionType.parseFromString(Condition.ConditionType.MAX_DOCS, docs));\n+    }\n+\n+    public void addMaxIndexSizeCondition(String size) {\n+        addCondition(Condition.ConditionType.MAX_SIZE, Condition.ConditionType.parseFromString(Condition.ConditionType.MAX_SIZE, size));","path":"core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java","position":null,"original_position":118,"commit_id":"d8d60d294ea89a4e94749a86b394257bb431ee84","original_commit_id":"a30437f2505a1599bffd14be7a36c67489687dad","user":{"login":"areek","id":753679,"avatar_url":"https://avatars.githubusercontent.com/u/753679?v=3","gravatar_id":"","url":"https://api.github.com/users/areek","html_url":"https://github.com/areek","followers_url":"https://api.github.com/users/areek/followers","following_url":"https://api.github.com/users/areek/following{/other_user}","gists_url":"https://api.github.com/users/areek/gists{/gist_id}","starred_url":"https://api.github.com/users/areek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/areek/subscriptions","organizations_url":"https://api.github.com/users/areek/orgs","repos_url":"https://api.github.com/users/areek/repos","events_url":"https://api.github.com/users/areek/events{/privacy}","received_events_url":"https://api.github.com/users/areek/received_events","type":"User","site_admin":false},"body":"nuked the Index size condition as per simon's comment","created_at":"2016-06-06T22:57:59Z","updated_at":"2016-06-06T22:57:59Z","html_url":"https://github.com/elastic/elasticsearch/pull/18732#discussion_r65984591","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/18732","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/65984591"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/18732#discussion_r65984591"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/18732"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/18732","id":72563149,"html_url":"https://github.com/elastic/elasticsearch/pull/18732","diff_url":"https://github.com/elastic/elasticsearch/pull/18732.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/18732.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/18732","number":18732,"state":"open","locked":false,"title":"Add rollover API to switch index aliases given some predicates","user":{"login":"areek","id":753679,"avatar_url":"https://avatars.githubusercontent.com/u/753679?v=3","gravatar_id":"","url":"https://api.github.com/users/areek","html_url":"https://github.com/areek","followers_url":"https://api.github.com/users/areek/followers","following_url":"https://api.github.com/users/areek/following{/other_user}","gists_url":"https://api.github.com/users/areek/gists{/gist_id}","starred_url":"https://api.github.com/users/areek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/areek/subscriptions","organizations_url":"https://api.github.com/users/areek/orgs","repos_url":"https://api.github.com/users/areek/repos","events_url":"https://api.github.com/users/areek/events{/privacy}","received_events_url":"https://api.github.com/users/areek/received_events","type":"User","site_admin":false},"body":"This adds a `_rollover` API (https://github.com/elastic/elasticsearch/issues/18647) to swap the index pointed through an alias, \r\ngiven some predicates are satisfied. \r\nThe API expects an alias which points to a single index. Upon satisfying \r\nall the provide conditions (`max_age`, `max_docs` and `max_size` of the index), \r\nthe alias is changed to point to a new index. \r\nThe new index name is generated using the following:\r\n - if the old index name is not in `{index_name_prefix}_{num}`, \r\n   appending a numerical value to the old index name (`{old_index}_{num}`) \r\n - if the old index name has the `{index_name_prefix}_{num}` format, \r\n   the new index is named as `{index_name_prefix}_{num+1}`\r\n\r\nIf the new index does not exist, then the API automatically creates the index \r\n(index settings can be configured only through matching index templates for now). \r\nWhen the given conditions are not met, the response returns with the same index\r\nname for both `old_index` and `new_index`.\r\n\r\nWould love to get some feedback on the implementation.\r\nWIP: documentation\r\n\r\ncloses #18647\r\n","created_at":"2016-06-03T20:11:26Z","updated_at":"2016-06-06T22:57:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bd9c84cc7fd44158c0ed1f11eda67c29e8102254","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/18732/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/18732/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/18732/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/d8d60d294ea89a4e94749a86b394257bb431ee84","head":{"label":"areek:enhancement/rollover_api","ref":"enhancement/rollover_api","sha":"d8d60d294ea89a4e94749a86b394257bb431ee84","user":{"login":"areek","id":753679,"avatar_url":"https://avatars.githubusercontent.com/u/753679?v=3","gravatar_id":"","url":"https://api.github.com/users/areek","html_url":"https://github.com/areek","followers_url":"https://api.github.com/users/areek/followers","following_url":"https://api.github.com/users/areek/following{/other_user}","gists_url":"https://api.github.com/users/areek/gists{/gist_id}","starred_url":"https://api.github.com/users/areek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/areek/subscriptions","organizations_url":"https://api.github.com/users/areek/orgs","repos_url":"https://api.github.com/users/areek/repos","events_url":"https://api.github.com/users/areek/events{/privacy}","received_events_url":"https://api.github.com/users/areek/received_events","type":"User","site_admin":false},"repo":{"id":16661385,"name":"elasticsearch","full_name":"areek/elasticsearch","owner":{"login":"areek","id":753679,"avatar_url":"https://avatars.githubusercontent.com/u/753679?v=3","gravatar_id":"","url":"https://api.github.com/users/areek","html_url":"https://github.com/areek","followers_url":"https://api.github.com/users/areek/followers","following_url":"https://api.github.com/users/areek/following{/other_user}","gists_url":"https://api.github.com/users/areek/gists{/gist_id}","starred_url":"https://api.github.com/users/areek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/areek/subscriptions","organizations_url":"https://api.github.com/users/areek/orgs","repos_url":"https://api.github.com/users/areek/repos","events_url":"https://api.github.com/users/areek/events{/privacy}","received_events_url":"https://api.github.com/users/areek/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/areek/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/areek/elasticsearch","forks_url":"https://api.github.com/repos/areek/elasticsearch/forks","keys_url":"https://api.github.com/repos/areek/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/areek/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/areek/elasticsearch/teams","hooks_url":"https://api.github.com/repos/areek/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/areek/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/areek/elasticsearch/events","assignees_url":"https://api.github.com/repos/areek/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/areek/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/areek/elasticsearch/tags","blobs_url":"https://api.github.com/repos/areek/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/areek/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/areek/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/areek/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/areek/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/areek/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/areek/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/areek/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/areek/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/areek/elasticsearch/subscription","commits_url":"https://api.github.com/repos/areek/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/areek/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/areek/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/areek/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/areek/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/areek/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/areek/elasticsearch/merges","archive_url":"https://api.github.com/repos/areek/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/areek/elasticsearch/downloads","issues_url":"https://api.github.com/repos/areek/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/areek/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/areek/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/areek/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/areek/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/areek/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/areek/elasticsearch/deployments","created_at":"2014-02-09T06:24:53Z","updated_at":"2015-12-09T01:17:39Z","pushed_at":"2016-06-06T22:54:31Z","git_url":"git://github.com/areek/elasticsearch.git","ssh_url":"git@github.com:areek/elasticsearch.git","clone_url":"https://github.com/areek/elasticsearch.git","svn_url":"https://github.com/areek/elasticsearch","homepage":"http://elasticsearch.org","size":210137,"stargazers_count":1,"watchers_count":1,"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":1,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"92c6d78d4a17213ebed306f7f7646041bb0fcfe4","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/elasticsearch/deployments","created_at":"2010-02-08T13:20:56Z","updated_at":"2016-06-06T17:21:46Z","pushed_at":"2016-06-06T22:54:32Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":322321,"stargazers_count":16837,"watchers_count":16837,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5687,"mirror_url":null,"open_issues_count":1075,"forks":5687,"open_issues":1075,"watchers":16837,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/18732"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/18732"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/18732"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/18732/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/18732/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/18732/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/d8d60d294ea89a4e94749a86b394257bb431ee84"}}}}
{"actor":{"display_login":"areek"}}