Add LicenseVersion to track version

closes elastic/elasticsearch#23

Original commit: elastic/x-pack-elasticsearch@d606beeb14
This commit is contained in:
Areek Zillur 2014-12-03 17:28:21 -05:00
parent b08f459c57
commit 134c278336
2 changed files with 9 additions and 7 deletions

View File

@ -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";

View File

@ -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)