remove trial package

Original commit: elastic/x-pack-elasticsearch@0b194a31a1
This commit is contained in:
Areek Zillur 2014-10-27 11:30:53 -04:00
parent c5c6de5864
commit 93607c8403
3 changed files with 0 additions and 322 deletions

View File

@ -1,88 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.license.plugin.core.trial;
import org.apache.commons.codec.binary.Base64;
import org.elasticsearch.license.core.LicensesCharset;
import java.nio.ByteBuffer;
import java.util.Set;
import static org.elasticsearch.license.plugin.core.trial.TrialLicensesBuilder.trialLicensesBuilder;
public class TrialLicenseUtils {
public static TrialLicenses.TrialLicense fromEncodedTrialLicense(String encodedTrialLicense) {
byte[] encodedBytes = Base64.decodeBase64(encodedTrialLicense);
ByteBuffer byteBuffer = ByteBuffer.wrap(encodedBytes);
int uidLen = byteBuffer.getInt();
byte[] uidBytes = new byte[uidLen];
byteBuffer.get(uidBytes);
String uid = new String(uidBytes, LicensesCharset.UTF_8);
int issuedToLen = byteBuffer.getInt();
byte[] issuedToBytes = new byte[issuedToLen];
byteBuffer.get(issuedToBytes);
String issuedTo = new String(issuedToBytes, LicensesCharset.UTF_8);
int featureLen = byteBuffer.getInt();
byte[] featureBytes = new byte[featureLen];
byteBuffer.get(featureBytes);
String feature = new String(featureBytes, LicensesCharset.UTF_8);
int maxNodes = byteBuffer.getInt();
long issueDate = byteBuffer.getLong();
long expiryDate = byteBuffer.getLong();
return TrialLicensesBuilder.trialLicenseBuilder()
.uid(uid)
.issuedTo(issuedTo)
.feature(feature)
.maxNodes(maxNodes)
.issueDate(issueDate)
.expiryDate(expiryDate)
.build();
}
public static String toEncodedTrialLicense(TrialLicenses.TrialLicense trialLicense) {
byte[] uidBytes = trialLicense.uid().getBytes(LicensesCharset.UTF_8);
byte[] featureBytes = trialLicense.feature().getBytes(LicensesCharset.UTF_8);
byte[] issuedToBytes = trialLicense.issuedTo().getBytes(LicensesCharset.UTF_8);
// uid len + uid bytes + issuedTo len + issuedTo bytes + feature bytes length + feature bytes + maxNodes + issueDate + expiryDate
int len = 4 + uidBytes.length + 4 + issuedToBytes.length + 4 + featureBytes.length + 4 + 8 + 8;
final byte[] encodedLicense = new byte[len];
ByteBuffer byteBuffer = ByteBuffer.wrap(encodedLicense);
byteBuffer.putInt(uidBytes.length);
byteBuffer.put(uidBytes);
byteBuffer.putInt(issuedToBytes.length);
byteBuffer.put(issuedToBytes);
byteBuffer.putInt(featureBytes.length);
byteBuffer.put(featureBytes);
byteBuffer.putInt(trialLicense.maxNodes());
byteBuffer.putLong(trialLicense.issueDate());
byteBuffer.putLong(trialLicense.expiryDate());
return Base64.encodeBase64String(encodedLicense);
}
public static TrialLicenses fromEncodedTrialLicenses(String[] encodedTrialLicenses) {
final TrialLicensesBuilder trialLicensesBuilder = trialLicensesBuilder();
for (String encodedTrialLicense : encodedTrialLicenses) {
trialLicensesBuilder.license(fromEncodedTrialLicense(encodedTrialLicense));
}
return trialLicensesBuilder.build();
}
public static TrialLicenses fromEncodedTrialLicenses(Set<String> encodedTrialLicenses) {
return fromEncodedTrialLicenses(encodedTrialLicenses.toArray(new String[encodedTrialLicenses.size()]));
}
}

View File

@ -1,31 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.license.plugin.core.trial;
import java.util.Collection;
public interface TrialLicenses extends Iterable<TrialLicenses.TrialLicense> {
public Collection<TrialLicense> trialLicenses();
public TrialLicense getTrialLicense(String feature);
public interface TrialLicense {
public String issuedTo();
public String feature();
public long issueDate();
public long expiryDate();
public int maxNodes();
public String uid();
}
}

View File

@ -1,203 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.license.plugin.core.trial;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.license.core.DateUtils;
import org.elasticsearch.license.core.ESLicense;
import java.util.Collection;
import java.util.Iterator;
import java.util.UUID;
import static org.elasticsearch.license.plugin.core.trial.TrialLicenses.TrialLicense;
public class TrialLicensesBuilder {
public static TrialLicenses EMPTY = trialLicensesBuilder().build();
public static final String ISSUER = "elasticsearch";
public static final ESLicense.Type TYPE = ESLicense.Type.TRIAL;
public static final ESLicense.SubscriptionType SUBSCRIPTION_TYPE = ESLicense.SubscriptionType.NONE;
public static TrialLicensesBuilder trialLicensesBuilder() {
return new TrialLicensesBuilder();
}
public static TrialLicenseBuilder trialLicenseBuilder() {
return new TrialLicenseBuilder();
}
public static TrialLicenses merge(TrialLicenses trialLicenses, TrialLicenses mergeTrialLicenses) {
if (trialLicenses == null && mergeTrialLicenses == null) {
throw new IllegalArgumentException("both licenses can not be null");
} else if (trialLicenses == null) {
return mergeTrialLicenses;
} else if (mergeTrialLicenses == null) {
return trialLicenses;
} else {
return trialLicensesBuilder()
.licenses(trialLicenses.trialLicenses())
.licenses(mergeTrialLicenses.trialLicenses())
.build();
}
}
private final ImmutableMap.Builder<String, TrialLicense> licenseBuilder;
public TrialLicensesBuilder() {
licenseBuilder = ImmutableMap.builder();
}
public TrialLicensesBuilder license(TrialLicense trialLicense) {
licenseBuilder.put(trialLicense.feature(), trialLicense);
return this;
}
public TrialLicensesBuilder licenses(TrialLicenses trialLicenses) {
return licenses(trialLicenses.trialLicenses());
}
public TrialLicensesBuilder licenses(Collection<TrialLicense> trialLicenses) {
for (TrialLicense trialLicense : trialLicenses) {
license(trialLicense);
}
return this;
}
public TrialLicenses build() {
final ImmutableMap<String, TrialLicense> licenseMap = licenseBuilder.build();
return new TrialLicenses() {
@Override
public Collection<TrialLicense> trialLicenses() {
return licenseMap.values();
}
@Override
public TrialLicense getTrialLicense(String feature) {
return licenseMap.get(feature);
}
@Override
public Iterator<TrialLicense> iterator() {
return licenseMap.values().iterator();
}
};
}
public static class TrialLicenseBuilder {
private String featureType;
private long expiryDate = -1;
private long issueDate = -1;
private TimeValue duration;
private int maxNodes = -1;
private String uid = null;
private String issuedTo;
public TrialLicenseBuilder() {
}
public TrialLicenseBuilder uid(String uid) {
this.uid = uid;
return this;
}
public TrialLicenseBuilder issuedTo(String issuedTo) {
this.issuedTo = issuedTo;
return this;
}
public TrialLicenseBuilder maxNodes(int maxNodes) {
this.maxNodes = maxNodes;
return this;
}
public TrialLicenseBuilder feature(String featureType) {
this.featureType = featureType;
return this;
}
public TrialLicenseBuilder issueDate(long issueDate) {
this.issueDate = issueDate;
return this;
}
public TrialLicenseBuilder duration(TimeValue duration) {
this.duration = duration;
return this;
}
public TrialLicenseBuilder expiryDate(long expiryDate) {
this.expiryDate = expiryDate;
return this;
}
public TrialLicense build() {
verify();
if (expiryDate == -1) {
expiryDate = issueDate + duration.millis();
}
if (uid == null) {
uid = UUID.randomUUID().toString();
}
return new TrialLicense() {
@Override
public String issuedTo() {
return issuedTo;
}
@Override
public String feature() {
return featureType;
}
@Override
public long issueDate() {
return issueDate;
}
@Override
public long expiryDate() {
return expiryDate;
}
@Override
public int maxNodes() {
return maxNodes;
}
@Override
public String uid() {
return uid;
}
};
}
private void verify() {
String msg = null;
if (issuedTo == null) {
msg = "issuedTo has to be set";
} else if (featureType == null) {
msg = "feature has to be set";
} else if (issueDate == -1) {
msg = "issueDate has to be set";
} else if (duration == null && expiryDate == -1) {
msg = "duration or expiryDate has to be set";
} else if (maxNodes == -1) {
msg = "maxNodes has to be set";
}
if (msg != null) {
throw new IllegalArgumentException(msg);
}
}
}
}