Gateway Storage: Improve it to support non breaking changes in the future, closes #191.
This commit is contained in:
parent
2cdb7bc05a
commit
b7d11f1303
|
@ -11,7 +11,7 @@ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
buildTimeStr = sdf.format(buildTime)
|
buildTimeStr = sdf.format(buildTime)
|
||||||
|
|
||||||
versionNumber = '0.7.2-SNAPSHOT'
|
versionNumber = '0.8.0-SNAPSHOT'
|
||||||
|
|
||||||
explodedDistDir = new File(distsDir, 'exploded')
|
explodedDistDir = new File(distsDir, 'exploded')
|
||||||
explodedDistLibDir = new File(explodedDistDir, 'lib')
|
explodedDistLibDir = new File(explodedDistDir, 'lib')
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.elasticsearch.util.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.util.settings.ImmutableSettings;
|
import org.elasticsearch.util.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.util.settings.Settings;
|
import org.elasticsearch.util.settings.Settings;
|
||||||
import org.elasticsearch.util.xcontent.ToXContent;
|
import org.elasticsearch.util.xcontent.ToXContent;
|
||||||
|
import org.elasticsearch.util.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.util.xcontent.XContentParser;
|
import org.elasticsearch.util.xcontent.XContentParser;
|
||||||
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
|
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
|
||||||
|
|
||||||
|
@ -210,13 +211,14 @@ public class IndexMetaData {
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
builder.startObject("mappings");
|
builder.startArray("mappings");
|
||||||
for (Map.Entry<String, String> entry : indexMetaData.mappings().entrySet()) {
|
for (Map.Entry<String, String> entry : indexMetaData.mappings().entrySet()) {
|
||||||
builder.startObject(entry.getKey());
|
XContentParser parser = XContentFactory.xContent(entry.getValue()).createParser(entry.getValue());
|
||||||
builder.field("source", entry.getValue());
|
Map<String, Object> mapping = parser.map();
|
||||||
builder.endObject();
|
parser.close();
|
||||||
|
builder.map(mapping);
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endArray();
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
@ -240,21 +242,16 @@ public class IndexMetaData {
|
||||||
}
|
}
|
||||||
builder.settings(settingsBuilder.build());
|
builder.settings(settingsBuilder.build());
|
||||||
} else if ("mappings".equals(currentFieldName)) {
|
} else if ("mappings".equals(currentFieldName)) {
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
String mappingType = parser.currentName();
|
Map<String, Object> mapping = parser.map();
|
||||||
String mappingSource = null;
|
if (mapping.size() == 1) {
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
String mappingSource = XContentFactory.jsonBuilder().map(mapping).string();
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
|
||||||
if ("source".equals(parser.currentName())) {
|
|
||||||
parser.nextToken();
|
|
||||||
mappingSource = parser.text();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mappingSource == null) {
|
if (mappingSource == null) {
|
||||||
// crap, no mapping source, warn?
|
// crap, no mapping source, warn?
|
||||||
} else {
|
} else {
|
||||||
builder.putMapping(mappingType, mappingSource);
|
builder.putMapping(mapping.keySet().iterator().next(), mappingSource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,4 +148,12 @@ public class NettyHttpRequest extends AbstractRestRequest implements HttpRequest
|
||||||
@Override public String param(String key) {
|
@Override public String param(String key) {
|
||||||
return params.get(key);
|
return params.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String param(String key, String defaultValue) {
|
||||||
|
String value = params.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ public interface Translog extends IndexShardComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A generic interface representing an operation perfomed on the transaction log.
|
* A generic interface representing an operation performed on the transaction log.
|
||||||
* Each is associated with a type.
|
* Each is associated with a type.
|
||||||
*/
|
*/
|
||||||
static interface Operation extends Streamable {
|
static interface Operation extends Streamable {
|
||||||
|
@ -191,6 +191,7 @@ public interface Translog extends IndexShardComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void readFrom(StreamInput in) throws IOException {
|
@Override public void readFrom(StreamInput in) throws IOException {
|
||||||
|
in.readVInt(); // version
|
||||||
id = in.readUTF();
|
id = in.readUTF();
|
||||||
type = in.readUTF();
|
type = in.readUTF();
|
||||||
source = new byte[in.readVInt()];
|
source = new byte[in.readVInt()];
|
||||||
|
@ -198,6 +199,7 @@ public interface Translog extends IndexShardComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
@Override public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
out.writeVInt(0); // version
|
||||||
out.writeUTF(id);
|
out.writeUTF(id);
|
||||||
out.writeUTF(type);
|
out.writeUTF(type);
|
||||||
out.writeVInt(source.length);
|
out.writeVInt(source.length);
|
||||||
|
@ -248,6 +250,7 @@ public interface Translog extends IndexShardComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void readFrom(StreamInput in) throws IOException {
|
@Override public void readFrom(StreamInput in) throws IOException {
|
||||||
|
in.readVInt(); // version
|
||||||
id = in.readUTF();
|
id = in.readUTF();
|
||||||
type = in.readUTF();
|
type = in.readUTF();
|
||||||
source = new byte[in.readVInt()];
|
source = new byte[in.readVInt()];
|
||||||
|
@ -255,6 +258,7 @@ public interface Translog extends IndexShardComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
@Override public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
out.writeVInt(0); // version
|
||||||
out.writeUTF(id);
|
out.writeUTF(id);
|
||||||
out.writeUTF(type);
|
out.writeUTF(type);
|
||||||
out.writeVInt(source.length);
|
out.writeVInt(source.length);
|
||||||
|
@ -293,10 +297,12 @@ public interface Translog extends IndexShardComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void readFrom(StreamInput in) throws IOException {
|
@Override public void readFrom(StreamInput in) throws IOException {
|
||||||
|
in.readVInt(); // version
|
||||||
uid = new Term(in.readUTF(), in.readUTF());
|
uid = new Term(in.readUTF(), in.readUTF());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
@Override public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
out.writeVInt(0); // version
|
||||||
out.writeUTF(uid.field());
|
out.writeUTF(uid.field());
|
||||||
out.writeUTF(uid.text());
|
out.writeUTF(uid.text());
|
||||||
}
|
}
|
||||||
|
@ -345,6 +351,7 @@ public interface Translog extends IndexShardComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void readFrom(StreamInput in) throws IOException {
|
@Override public void readFrom(StreamInput in) throws IOException {
|
||||||
|
in.readVInt(); // version
|
||||||
source = new byte[in.readVInt()];
|
source = new byte[in.readVInt()];
|
||||||
in.readFully(source);
|
in.readFully(source);
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
|
@ -360,6 +367,7 @@ public interface Translog extends IndexShardComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
@Override public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
out.writeVInt(0); // version
|
||||||
out.writeVInt(source.length);
|
out.writeVInt(source.length);
|
||||||
out.writeBytes(source);
|
out.writeBytes(source);
|
||||||
if (queryParserName == null) {
|
if (queryParserName == null) {
|
||||||
|
|
|
@ -33,12 +33,18 @@ public interface ToXContent {
|
||||||
|
|
||||||
public static interface Params {
|
public static interface Params {
|
||||||
String param(String key);
|
String param(String key);
|
||||||
|
|
||||||
|
String param(String key, String defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Params EMPTY_PARAMS = new Params() {
|
public static final Params EMPTY_PARAMS = new Params() {
|
||||||
@Override public String param(String key) {
|
@Override public String param(String key) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String param(String key, String defaultValue) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static class MapParams implements Params {
|
public static class MapParams implements Params {
|
||||||
|
@ -52,6 +58,14 @@ public interface ToXContent {
|
||||||
@Override public String param(String key) {
|
@Override public String param(String key) {
|
||||||
return params.get(key);
|
return params.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String param(String key, String defaultValue) {
|
||||||
|
String value = params.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toXContent(XContentBuilder builder, Params params) throws IOException;
|
void toXContent(XContentBuilder builder, Params params) throws IOException;
|
||||||
|
|
|
@ -66,13 +66,13 @@ public class ToAndFromJsonMetaDataTests {
|
||||||
MetaData parsedMetaData = MetaData.Builder.fromXContent(XContentFactory.xContent(XContentType.JSON).createParser(metaDataSource), null);
|
MetaData parsedMetaData = MetaData.Builder.fromXContent(XContentFactory.xContent(XContentType.JSON).createParser(metaDataSource), null);
|
||||||
assertThat(parsedMetaData.maxNumberOfShardsPerNode(), equalTo(2));
|
assertThat(parsedMetaData.maxNumberOfShardsPerNode(), equalTo(2));
|
||||||
|
|
||||||
IndexMetaData indexMetaData = metaData.index("test1");
|
IndexMetaData indexMetaData = parsedMetaData.index("test1");
|
||||||
assertThat(indexMetaData.numberOfShards(), equalTo(1));
|
assertThat(indexMetaData.numberOfShards(), equalTo(1));
|
||||||
assertThat(indexMetaData.numberOfReplicas(), equalTo(2));
|
assertThat(indexMetaData.numberOfReplicas(), equalTo(2));
|
||||||
assertThat(indexMetaData.settings().getAsMap().size(), equalTo(2));
|
assertThat(indexMetaData.settings().getAsMap().size(), equalTo(2));
|
||||||
assertThat(indexMetaData.mappings().size(), equalTo(0));
|
assertThat(indexMetaData.mappings().size(), equalTo(0));
|
||||||
|
|
||||||
indexMetaData = metaData.index("test2");
|
indexMetaData = parsedMetaData.index("test2");
|
||||||
assertThat(indexMetaData.numberOfShards(), equalTo(2));
|
assertThat(indexMetaData.numberOfShards(), equalTo(2));
|
||||||
assertThat(indexMetaData.numberOfReplicas(), equalTo(3));
|
assertThat(indexMetaData.numberOfReplicas(), equalTo(3));
|
||||||
assertThat(indexMetaData.settings().getAsMap().size(), equalTo(4));
|
assertThat(indexMetaData.settings().getAsMap().size(), equalTo(4));
|
||||||
|
@ -80,14 +80,14 @@ public class ToAndFromJsonMetaDataTests {
|
||||||
assertThat(indexMetaData.settings().get("setting2"), equalTo("value2"));
|
assertThat(indexMetaData.settings().get("setting2"), equalTo("value2"));
|
||||||
assertThat(indexMetaData.mappings().size(), equalTo(0));
|
assertThat(indexMetaData.mappings().size(), equalTo(0));
|
||||||
|
|
||||||
indexMetaData = metaData.index("test3");
|
indexMetaData = parsedMetaData.index("test3");
|
||||||
assertThat(indexMetaData.numberOfShards(), equalTo(1));
|
assertThat(indexMetaData.numberOfShards(), equalTo(1));
|
||||||
assertThat(indexMetaData.numberOfReplicas(), equalTo(2));
|
assertThat(indexMetaData.numberOfReplicas(), equalTo(2));
|
||||||
assertThat(indexMetaData.settings().getAsMap().size(), equalTo(2));
|
assertThat(indexMetaData.settings().getAsMap().size(), equalTo(2));
|
||||||
assertThat(indexMetaData.mappings().size(), equalTo(1));
|
assertThat(indexMetaData.mappings().size(), equalTo(1));
|
||||||
assertThat(indexMetaData.mappings().get("mapping1"), equalTo(MAPPING_SOURCE1));
|
assertThat(indexMetaData.mappings().get("mapping1"), equalTo(MAPPING_SOURCE1));
|
||||||
|
|
||||||
indexMetaData = metaData.index("test4");
|
indexMetaData = parsedMetaData.index("test4");
|
||||||
assertThat(indexMetaData.numberOfShards(), equalTo(1));
|
assertThat(indexMetaData.numberOfShards(), equalTo(1));
|
||||||
assertThat(indexMetaData.numberOfReplicas(), equalTo(2));
|
assertThat(indexMetaData.numberOfReplicas(), equalTo(2));
|
||||||
assertThat(indexMetaData.settings().getAsMap().size(), equalTo(4));
|
assertThat(indexMetaData.settings().getAsMap().size(), equalTo(4));
|
||||||
|
@ -98,6 +98,6 @@ public class ToAndFromJsonMetaDataTests {
|
||||||
assertThat(indexMetaData.mappings().get("mapping2"), equalTo(MAPPING_SOURCE2));
|
assertThat(indexMetaData.mappings().get("mapping2"), equalTo(MAPPING_SOURCE2));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String MAPPING_SOURCE1 = "{ text1: { type : \"string\" } }";
|
private static final String MAPPING_SOURCE1 = "{\"mapping1\":{\"text1\":{\"type\":\"string\"}}}";
|
||||||
private static final String MAPPING_SOURCE2 = "{ text2: { type : \"string\" } }";
|
private static final String MAPPING_SOURCE2 = "{\"mapping2\":{\"text2\":{\"type\":\"string\"}}}";
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,4 +156,12 @@ public class MemcachedRestRequest extends AbstractRestRequest {
|
||||||
@Override public Map<String, String> params() {
|
@Override public Map<String, String> params() {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String param(String key, String defaultValue) {
|
||||||
|
String value = params.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue