From 134c2783366bbeb92c62a135d799cb39787c63d1 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Wed, 3 Dec 2014 17:28:21 -0500 Subject: [PATCH] Add LicenseVersion to track version closes elastic/elasticsearch#23 Original commit: elastic/x-pack-elasticsearch@d606beeb148d4da7620bcf6dc4560b266267322c --- .../java/org/elasticsearch/license/core/License.java | 11 ++++++++--- .../elasticsearch/license/licensor/LicenseSigner.java | 5 +---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/license/core/License.java b/core/src/main/java/org/elasticsearch/license/core/License.java index 0aa7d2c1857..4e913377e95 100644 --- a/core/src/main/java/org/elasticsearch/license/core/License.java +++ b/core/src/main/java/org/elasticsearch/license/core/License.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.license.core; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -20,6 +21,8 @@ import java.io.IOException; * Provides serialization/deserialization & validation methods for license object */ public class License implements ToXContent { + public final static int VERSION_START = 1; + public final static int VERSION_CURRENT = VERSION_START; private final String uid; private final String issuer; @@ -142,7 +145,10 @@ public class License implements ToXContent { } static License readLicense(StreamInput in) throws IOException { - in.readVInt(); // Version for future extensibility + int version = in.readVInt(); // Version for future extensibility + if (version > VERSION_CURRENT) { + throw new ElasticsearchException("Unknown license version found, please upgrade all nodes to the latest elasticsearch-license plugin"); + } Builder builder = builder(); builder.uid(in.readString()); builder.type(in.readString()); @@ -158,7 +164,7 @@ public class License implements ToXContent { } public void writeTo(StreamOutput out) throws IOException { - out.writeVInt(VERSION); + out.writeVInt(VERSION_CURRENT); out.writeString(uid); out.writeString(type); out.writeString(subscriptionType); @@ -206,7 +212,6 @@ public class License implements ToXContent { return builder; } - private final static int VERSION = 1; final static class Fields { static final String STATUS = "status"; diff --git a/licensor/src/main/java/org/elasticsearch/license/licensor/LicenseSigner.java b/licensor/src/main/java/org/elasticsearch/license/licensor/LicenseSigner.java index 10f6ee80169..19b8a735855 100644 --- a/licensor/src/main/java/org/elasticsearch/license/licensor/LicenseSigner.java +++ b/licensor/src/main/java/org/elasticsearch/license/licensor/LicenseSigner.java @@ -30,9 +30,6 @@ import java.util.Set; */ public class LicenseSigner { - private final static int VERSION_START = 0; - private final static int VERSION = VERSION_START; - private final static int MAGIC_LENGTH = 13; private final Path publicKeyPath; @@ -78,7 +75,7 @@ public class LicenseSigner { byte[] bytes = new byte[4 + 4 + MAGIC_LENGTH + 4 + hash.length + 4 + signedContent.length]; ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); - byteBuffer.putInt(VERSION) + byteBuffer.putInt(License.VERSION_CURRENT) .putInt(magic.length) .put(magic) .putInt(hash.length)