-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Support "enterprise" license types #49223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tvernum
merged 4 commits into
elastic:master
from
tvernum:enterprise-license/accept-put
Nov 20, 2019
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,15 +5,6 @@ | |||||
*/ | ||||||
package org.elasticsearch.license; | ||||||
|
||||||
import java.io.IOException; | ||||||
import java.io.InputStream; | ||||||
import java.nio.ByteBuffer; | ||||||
import java.util.ArrayList; | ||||||
import java.util.Base64; | ||||||
import java.util.Comparator; | ||||||
import java.util.List; | ||||||
import java.util.Locale; | ||||||
|
||||||
import org.apache.lucene.util.CollectionUtil; | ||||||
import org.elasticsearch.ElasticsearchException; | ||||||
import org.elasticsearch.ElasticsearchParseException; | ||||||
|
@@ -31,11 +22,83 @@ | |||||
import org.elasticsearch.common.xcontent.XContentType; | ||||||
import org.elasticsearch.protocol.xpack.license.LicenseStatus; | ||||||
|
||||||
import java.io.IOException; | ||||||
import java.io.InputStream; | ||||||
import java.nio.ByteBuffer; | ||||||
import java.util.ArrayList; | ||||||
import java.util.Base64; | ||||||
import java.util.Comparator; | ||||||
import java.util.List; | ||||||
import java.util.Locale; | ||||||
import java.util.stream.Collectors; | ||||||
import java.util.stream.Stream; | ||||||
|
||||||
/** | ||||||
* Data structure for license. Use {@link Builder} to build a license. | ||||||
* Provides serialization/deserialization & validation methods for license object | ||||||
*/ | ||||||
public class License implements ToXContentObject { | ||||||
|
||||||
public enum LicenseType { | ||||||
BASIC, | ||||||
STANDARD, | ||||||
GOLD, | ||||||
PLATINUM, | ||||||
ENTERPRISE, | ||||||
TRIAL; | ||||||
|
||||||
public String getTypeName() { | ||||||
return name().toLowerCase(Locale.ROOT); | ||||||
} | ||||||
|
||||||
public static LicenseType parse(String type) throws IllegalArgumentException { | ||||||
try { | ||||||
return LicenseType.valueOf(type.toUpperCase(Locale.ROOT)); | ||||||
} catch (IllegalArgumentException e) { | ||||||
throw new IllegalArgumentException("unrecognised license type [ " + type + "], supported license types are [" | ||||||
+ Stream.of(values()).map(LicenseType::getTypeName).collect(Collectors.joining(",")) + "]"); | ||||||
} | ||||||
} | ||||||
|
||||||
/** | ||||||
* Backward compatible license type parsing for older license models | ||||||
*/ | ||||||
public static LicenseType resolve(String name) { | ||||||
switch (name.toLowerCase(Locale.ROOT)) { | ||||||
case "missing": | ||||||
return null; | ||||||
case "trial": | ||||||
case "none": // bwc for 1.x subscription_type field | ||||||
case "dev": // bwc for 1.x subscription_type field | ||||||
case "development": // bwc for 1.x subscription_type field | ||||||
return TRIAL; | ||||||
case "basic": | ||||||
return BASIC; | ||||||
case "standard": | ||||||
return STANDARD; | ||||||
case "silver": | ||||||
case "gold": | ||||||
return GOLD; | ||||||
case "platinum": | ||||||
case "cloud_internal": | ||||||
case "internal": // bwc for 1.x subscription_type field | ||||||
return PLATINUM; | ||||||
case "enterprise": | ||||||
return ENTERPRISE; | ||||||
default: | ||||||
throw new IllegalArgumentException("unknown license type [" + name + "]"); | ||||||
} | ||||||
} | ||||||
|
||||||
static boolean isBasic(String typeName) { | ||||||
return BASIC.getTypeName().equals(typeName); | ||||||
} | ||||||
|
||||||
static boolean isTrial(String typeName) { | ||||||
return TRIAL.getTypeName().equals(typeName); | ||||||
} | ||||||
} | ||||||
|
||||||
public static final int VERSION_START = 1; | ||||||
public static final int VERSION_NO_FEATURE_TYPE = 2; | ||||||
public static final int VERSION_START_DATE = 3; | ||||||
|
@@ -102,28 +165,25 @@ public static int compare(OperationMode opMode1, OperationMode opMode2) { | |||||
return Integer.compare(opMode1.id, opMode2.id); | ||||||
} | ||||||
|
||||||
public static OperationMode resolve(String type) { | ||||||
switch (type.toLowerCase(Locale.ROOT)) { | ||||||
case "missing": | ||||||
return MISSING; | ||||||
case "trial": | ||||||
case "none": // bwc for 1.x subscription_type field | ||||||
case "dev": // bwc for 1.x subscription_type field | ||||||
case "development": // bwc for 1.x subscription_type field | ||||||
return TRIAL; | ||||||
case "basic": | ||||||
public static OperationMode resolve(String typeName) { | ||||||
LicenseType type = LicenseType.resolve(typeName); | ||||||
if (type == null) { | ||||||
return MISSING; | ||||||
} | ||||||
switch (type) { | ||||||
case BASIC: | ||||||
return BASIC; | ||||||
case "standard": | ||||||
case STANDARD: | ||||||
return STANDARD; | ||||||
case "silver": | ||||||
case "gold": | ||||||
case GOLD: | ||||||
return GOLD; | ||||||
case "platinum": | ||||||
case "cloud_internal": | ||||||
case "internal": // bwc for 1.x subscription_type field | ||||||
case PLATINUM: | ||||||
case ENTERPRISE: // TODO Add an explicit platinum operating mode | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return PLATINUM; | ||||||
case TRIAL: | ||||||
return TRIAL; | ||||||
default: | ||||||
throw new IllegalArgumentException("unknown type [" + type + "]"); | ||||||
throw new IllegalArgumentException("unsupported license type [" + type.getTypeName() + "]"); | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -301,7 +361,7 @@ private void validate() { | |||||
throw new IllegalStateException("maxNodes has to be set"); | ||||||
} else if (expiryDate == -1) { | ||||||
throw new IllegalStateException("expiryDate has to be set"); | ||||||
} else if (expiryDate == LicenseService.BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS && "basic".equals(type) == false) { | ||||||
} else if (expiryDate == LicenseService.BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS && LicenseType.isBasic(type) == false) { | ||||||
throw new IllegalStateException("only basic licenses are allowed to have no expiration"); | ||||||
} | ||||||
} | ||||||
|
@@ -689,6 +749,10 @@ public Builder issueDate(long issueDate) { | |||||
return this; | ||||||
} | ||||||
|
||||||
public Builder type(LicenseType type) { | ||||||
return type(type.getTypeName()); | ||||||
} | ||||||
|
||||||
public Builder type(String type) { | ||||||
this.type = type; | ||||||
return this; | ||||||
|
@@ -778,6 +842,7 @@ public Builder validate() { | |||||
} | ||||||
return this; | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.