update to make elasticsearch 2.0 the minumim required version
This change makes the license plugin compatible with elasticseach-2.0.0-SNAPSHOT. This project now uses the elasticsearch-parent pom to standardize the build with core. As part of this, the Java security manager is enabled and all tests pass with the security manager enabled. Closes elastic/elasticsearch#46 Original commit: elastic/x-pack-elasticsearch@5f471ea298
This commit is contained in:
parent
092bdbe0c9
commit
5758ca3c7b
|
@ -14,4 +14,19 @@
|
|||
<properties>
|
||||
<license.basedir combine.self="override">${project.parent.basedir}</license.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.carrotsearch.randomizedtesting</groupId>
|
||||
<artifactId>junit4-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>tests</id>
|
||||
<phase/>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
107
core/pom.xml
107
core/pom.xml
|
@ -25,113 +25,6 @@
|
|||
<plugin>
|
||||
<groupId>com.carrotsearch.randomizedtesting</groupId>
|
||||
<artifactId>junit4-maven-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>tests</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>junit4</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<dir>${project.basedir}/target</dir>
|
||||
<classesDirectory>${project.basedir}/target/classes</classesDirectory>
|
||||
<heartbeat>20</heartbeat>
|
||||
<jvmOutputAction>pipe,warn</jvmOutputAction>
|
||||
<leaveTemporary>true</leaveTemporary>
|
||||
<listeners>
|
||||
<report-ant-xml mavenExtensions="true"
|
||||
dir="${project.build.directory}/surefire-reports"/>
|
||||
<report-text
|
||||
showThrowable="true"
|
||||
showStackTraces="true"
|
||||
showOutput="${tests.output}"
|
||||
showStatusOk="false"
|
||||
showStatusError="true"
|
||||
showStatusFailure="true"
|
||||
showStatusIgnored="true"
|
||||
showSuiteSummary="true"
|
||||
timestamps="false"/>
|
||||
<report-execution-times historyLength="20" file="${basedir}/${execution.hint.file}"/>
|
||||
</listeners>
|
||||
<assertions>
|
||||
<enable/>
|
||||
<disable package="${tests.assertion.disabled}"/>
|
||||
<!-- pass org.elasticsearch to run without assertions -->
|
||||
</assertions>
|
||||
<parallelism>${tests.jvms}</parallelism>
|
||||
<balancers>
|
||||
<execution-times>
|
||||
<fileset dir="${basedir}" includes="${execution.hint.file}"/>
|
||||
</execution-times>
|
||||
</balancers>
|
||||
<includes>
|
||||
<include>**/*Tests.class</include>
|
||||
<include>**/*Test.class</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*.class</exclude>
|
||||
<exclude>**/*StressTest.class</exclude>
|
||||
</excludes>
|
||||
<jvmArgs>
|
||||
<param>-Xmx${tests.heap.size}</param>
|
||||
<param>-Xms${tests.heap.size}</param>
|
||||
<param>-Xss256k</param>
|
||||
<param>-XX:MaxPermSize=128m</param>
|
||||
<param>-XX:MaxDirectMemorySize=512m</param>
|
||||
<param>-Des.logger.prefix=</param>
|
||||
</jvmArgs>
|
||||
<shuffleOnSlave>${tests.shuffle}</shuffleOnSlave>
|
||||
<sysouts>${tests.verbose}</sysouts>
|
||||
<seed>${tests.seed}</seed>
|
||||
<haltOnFailure>${tests.failfast}</haltOnFailure>
|
||||
<uniqueSuiteNames>false</uniqueSuiteNames>
|
||||
<systemProperties>
|
||||
<java.io.tmpdir>.</java.io.tmpdir>
|
||||
<!-- we use '.' since this is different per JVM-->
|
||||
<!-- RandomizedTesting library system properties -->
|
||||
<tests.bwc>${tests.bwc}</tests.bwc>
|
||||
<tests.bwc.path>${tests.bwc.path}</tests.bwc.path>
|
||||
<tests.bwc.version>${tests.bwc.version}</tests.bwc.version>
|
||||
<tests.jvm.argline>${tests.jvm.argline}</tests.jvm.argline>
|
||||
<tests.processors>${tests.processors}</tests.processors>
|
||||
<tests.appendseed>${tests.appendseed}</tests.appendseed>
|
||||
<tests.iters>${tests.iters}</tests.iters>
|
||||
<tests.maxfailures>${tests.maxfailures}</tests.maxfailures>
|
||||
<tests.failfast>${tests.failfast}</tests.failfast>
|
||||
<tests.class>${tests.class}</tests.class>
|
||||
<tests.method>${tests.method}</tests.method>
|
||||
<tests.nightly>${tests.nightly}</tests.nightly>
|
||||
<tests.verbose>${tests.verbose}</tests.verbose>
|
||||
<tests.badapples>${tests.badapples}</tests.badapples>
|
||||
<tests.weekly>${tests.weekly}</tests.weekly>
|
||||
<tests.slow>${tests.slow}</tests.slow>
|
||||
<tests.awaitsfix>${tests.awaitsfix}</tests.awaitsfix>
|
||||
<tests.slow>${tests.slow}</tests.slow>
|
||||
<tests.timeoutSuite>${tests.timeoutSuite}</tests.timeoutSuite>
|
||||
<tests.showSuccess>${tests.showSuccess}</tests.showSuccess>
|
||||
<tests.integration>${tests.integration}</tests.integration>
|
||||
<tests.client.ratio>${tests.client.ratio}</tests.client.ratio>
|
||||
<tests.enable_mock_modules>${tests.enable_mock_modules}</tests.enable_mock_modules>
|
||||
<tests.assertion.disabled>${tests.assertion.disabled}</tests.assertion.disabled>
|
||||
<tests.rest>${tests.rest}</tests.rest>
|
||||
<tests.rest.suite>${tests.rest.suite}</tests.rest.suite>
|
||||
<tests.rest.blacklist>${tests.rest.blacklist}</tests.rest.blacklist>
|
||||
<tests.rest.spec>${tests.rest.spec}</tests.rest.spec>
|
||||
<tests.network>${tests.network}</tests.network>
|
||||
<tests.cluster>${tests.cluster}</tests.cluster>
|
||||
<tests.heap.size>${tests.heap.size}</tests.heap.size>
|
||||
<tests.filter>${tests.filter}</tests.filter>
|
||||
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
|
||||
<es.node.mode>${es.node.mode}</es.node.mode>
|
||||
<es.logger.level>${es.logger.level}</es.logger.level>
|
||||
<tests.security.manager>${tests.security.manager}</tests.security.manager>
|
||||
<tests.compatibility>${tests.compatibility}</tests.compatibility>
|
||||
<java.awt.headless>true</java.awt.headless>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
import org.elasticsearch.license.core.shaded.CryptUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -115,8 +114,8 @@ public class LicenseVerifier {
|
|||
}
|
||||
|
||||
private static byte[] getPublicKeyContentFromResource(String resource) {
|
||||
try (InputStream inputStream = LicenseVerifier.class.getResourceAsStream(resource)) {
|
||||
return Streams.copyToByteArray(inputStream);
|
||||
try {
|
||||
return Streams.copyToBytesFromClasspath(resource);
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
|
|
@ -8,14 +8,12 @@ package org.elasticsearch.license.core;
|
|||
import org.elasticsearch.common.joda.DateMathParser;
|
||||
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
||||
import org.elasticsearch.common.joda.Joda;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.*;
|
||||
|
@ -59,12 +57,22 @@ public class TestUtils {
|
|||
assertThat(license1.maxNodes(), equalTo(license2.maxNodes()));
|
||||
}
|
||||
|
||||
public static String dateMathString(String time, long now) {
|
||||
return dateTimeFormatter.print(dateMathParser.parse(time, now));
|
||||
public static String dateMathString(String time, final long now) {
|
||||
return dateTimeFormatter.print(dateMathParser.parse(time, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return now;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static long dateMath(String time, long now) {
|
||||
return dateMathParser.parse(time, now);
|
||||
public static long dateMath(String time, final long now) {
|
||||
return dateMathParser.parse(time, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return now;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static LicenseSpec generateRandomLicenseSpec() {
|
||||
|
|
109
licensor/pom.xml
109
licensor/pom.xml
|
@ -34,7 +34,6 @@
|
|||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/releases/</outputDirectory>
|
||||
</configuration>
|
||||
|
@ -57,7 +56,6 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>for-exec</id>
|
||||
|
@ -78,113 +76,6 @@
|
|||
<plugin>
|
||||
<groupId>com.carrotsearch.randomizedtesting</groupId>
|
||||
<artifactId>junit4-maven-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>tests</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>junit4</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<dir>${project.basedir}/target</dir>
|
||||
<classesDirectory>${project.basedir}/target/classes</classesDirectory>
|
||||
<heartbeat>20</heartbeat>
|
||||
<jvmOutputAction>pipe,warn</jvmOutputAction>
|
||||
<leaveTemporary>true</leaveTemporary>
|
||||
<listeners>
|
||||
<report-ant-xml mavenExtensions="true"
|
||||
dir="${project.build.directory}/surefire-reports"/>
|
||||
<report-text
|
||||
showThrowable="true"
|
||||
showStackTraces="true"
|
||||
showOutput="${tests.output}"
|
||||
showStatusOk="false"
|
||||
showStatusError="true"
|
||||
showStatusFailure="true"
|
||||
showStatusIgnored="true"
|
||||
showSuiteSummary="true"
|
||||
timestamps="false"/>
|
||||
<report-execution-times historyLength="20" file="${basedir}/${execution.hint.file}"/>
|
||||
</listeners>
|
||||
<assertions>
|
||||
<enable/>
|
||||
<disable package="${tests.assertion.disabled}"/>
|
||||
<!-- pass org.elasticsearch to run without assertions -->
|
||||
</assertions>
|
||||
<parallelism>${tests.jvms}</parallelism>
|
||||
<balancers>
|
||||
<execution-times>
|
||||
<fileset dir="${basedir}" includes="${execution.hint.file}"/>
|
||||
</execution-times>
|
||||
</balancers>
|
||||
<includes>
|
||||
<include>**/*Tests.class</include>
|
||||
<include>**/*Test.class</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*.class</exclude>
|
||||
<exclude>**/*StressTest.class</exclude>
|
||||
</excludes>
|
||||
<jvmArgs>
|
||||
<param>-Xmx${tests.heap.size}</param>
|
||||
<param>-Xms${tests.heap.size}</param>
|
||||
<param>-Xss256k</param>
|
||||
<param>-XX:MaxPermSize=128m</param>
|
||||
<param>-XX:MaxDirectMemorySize=512m</param>
|
||||
<param>-Des.logger.prefix=</param>
|
||||
</jvmArgs>
|
||||
<shuffleOnSlave>${tests.shuffle}</shuffleOnSlave>
|
||||
<sysouts>${tests.verbose}</sysouts>
|
||||
<seed>${tests.seed}</seed>
|
||||
<haltOnFailure>${tests.failfast}</haltOnFailure>
|
||||
<uniqueSuiteNames>false</uniqueSuiteNames>
|
||||
<systemProperties>
|
||||
<java.io.tmpdir>.</java.io.tmpdir>
|
||||
<!-- we use '.' since this is different per JVM-->
|
||||
<!-- RandomizedTesting library system properties -->
|
||||
<tests.bwc>${tests.bwc}</tests.bwc>
|
||||
<tests.bwc.path>${tests.bwc.path}</tests.bwc.path>
|
||||
<tests.bwc.version>${tests.bwc.version}</tests.bwc.version>
|
||||
<tests.jvm.argline>${tests.jvm.argline}</tests.jvm.argline>
|
||||
<tests.processors>${tests.processors}</tests.processors>
|
||||
<tests.appendseed>${tests.appendseed}</tests.appendseed>
|
||||
<tests.iters>${tests.iters}</tests.iters>
|
||||
<tests.maxfailures>${tests.maxfailures}</tests.maxfailures>
|
||||
<tests.failfast>${tests.failfast}</tests.failfast>
|
||||
<tests.class>${tests.class}</tests.class>
|
||||
<tests.method>${tests.method}</tests.method>
|
||||
<tests.nightly>${tests.nightly}</tests.nightly>
|
||||
<tests.verbose>${tests.verbose}</tests.verbose>
|
||||
<tests.badapples>${tests.badapples}</tests.badapples>
|
||||
<tests.weekly>${tests.weekly}</tests.weekly>
|
||||
<tests.slow>${tests.slow}</tests.slow>
|
||||
<tests.awaitsfix>${tests.awaitsfix}</tests.awaitsfix>
|
||||
<tests.slow>${tests.slow}</tests.slow>
|
||||
<tests.timeoutSuite>${tests.timeoutSuite}</tests.timeoutSuite>
|
||||
<tests.showSuccess>${tests.showSuccess}</tests.showSuccess>
|
||||
<tests.integration>${tests.integration}</tests.integration>
|
||||
<tests.client.ratio>${tests.client.ratio}</tests.client.ratio>
|
||||
<tests.enable_mock_modules>${tests.enable_mock_modules}</tests.enable_mock_modules>
|
||||
<tests.assertion.disabled>${tests.assertion.disabled}</tests.assertion.disabled>
|
||||
<tests.rest>${tests.rest}</tests.rest>
|
||||
<tests.rest.suite>${tests.rest.suite}</tests.rest.suite>
|
||||
<tests.rest.blacklist>${tests.rest.blacklist}</tests.rest.blacklist>
|
||||
<tests.rest.spec>${tests.rest.spec}</tests.rest.spec>
|
||||
<tests.network>${tests.network}</tests.network>
|
||||
<tests.cluster>${tests.cluster}</tests.cluster>
|
||||
<tests.heap.size>${tests.heap.size}</tests.heap.size>
|
||||
<tests.filter>${tests.filter}</tests.filter>
|
||||
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
|
||||
<es.node.mode>${es.node.mode}</es.node.mode>
|
||||
<es.logger.level>${es.logger.level}</es.logger.level>
|
||||
<tests.security.manager>${tests.security.manager}</tests.security.manager>
|
||||
<tests.compatibility>${tests.compatibility}</tests.compatibility>
|
||||
<java.awt.headless>true</java.awt.headless>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
@ -8,9 +8,9 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.license.core.DateUtils;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -18,16 +18,22 @@ import java.util.UUID;
|
|||
|
||||
public abstract class AbstractLicensingTestBase extends ElasticsearchTestCase {
|
||||
|
||||
protected static String pubKeyPath = null;
|
||||
protected static String priKeyPath = null;
|
||||
protected String pubKeyPath = null;
|
||||
protected String priKeyPath = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
pubKeyPath = getResourcePath("/public.key");
|
||||
priKeyPath = getResourcePath("/private.key");
|
||||
}
|
||||
|
||||
public static Set<License> generateSignedLicenses(List<TestUtils.LicenseSpec> licenseSpecs) throws Exception {
|
||||
@After
|
||||
public void cleanUp() {
|
||||
pubKeyPath = null;
|
||||
priKeyPath = null;
|
||||
}
|
||||
|
||||
public static Set<License> generateSignedLicenses(List<TestUtils.LicenseSpec> licenseSpecs, String pubKeyPath, String priKeyPath) throws Exception {
|
||||
LicenseSigner signer = new LicenseSigner(priKeyPath, pubKeyPath);
|
||||
Set<License> unSignedLicenses = new HashSet<>();
|
||||
for (TestUtils.LicenseSpec spec : licenseSpecs) {
|
||||
|
@ -55,11 +61,11 @@ public abstract class AbstractLicensingTestBase extends ElasticsearchTestCase {
|
|||
return signer.sign(unSignedLicenses);
|
||||
}
|
||||
|
||||
public static License generateSignedLicense(String feature, TimeValue expiryDuration) throws Exception {
|
||||
return generateSignedLicense(feature, -1, expiryDuration);
|
||||
public static License generateSignedLicense(String feature, TimeValue expiryDuration, String pubKeyPath, String priKeyPath) throws Exception {
|
||||
return generateSignedLicense(feature, -1, expiryDuration, pubKeyPath, priKeyPath);
|
||||
}
|
||||
|
||||
public static License generateSignedLicense(String feature, long issueDate, TimeValue expiryDuration) throws Exception {
|
||||
public static License generateSignedLicense(String feature, long issueDate, TimeValue expiryDuration, String pubKeyPath, String priKeyPath) throws Exception {
|
||||
long issue = (issueDate != -1l) ? issueDate : System.currentTimeMillis();
|
||||
final License licenseSpec = License.builder()
|
||||
.uid(UUID.randomUUID().toString())
|
||||
|
@ -73,20 +79,19 @@ public abstract class AbstractLicensingTestBase extends ElasticsearchTestCase {
|
|||
.maxNodes(5)
|
||||
.build();
|
||||
|
||||
LicenseSigner signer = new LicenseSigner(getTestPriKeyPath(), getTestPubKeyPath());
|
||||
LicenseSigner signer = new LicenseSigner(priKeyPath, pubKeyPath);
|
||||
return signer.sign(licenseSpec);
|
||||
}
|
||||
|
||||
public static String getTestPriKeyPath() throws Exception {
|
||||
public String getTestPriKeyPath() throws Exception {
|
||||
return getResourcePath("/private.key");
|
||||
}
|
||||
|
||||
public static String getTestPubKeyPath() throws Exception {
|
||||
public String getTestPubKeyPath() throws Exception {
|
||||
return getResourcePath("/public.key");
|
||||
}
|
||||
|
||||
private static String getResourcePath(String resource) throws Exception {
|
||||
URL url = TestUtils.class.getResource(resource);
|
||||
return url.toURI().getPath();
|
||||
private String getResourcePath(String resource) throws Exception {
|
||||
return getDataPath(resource).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,21 +21,21 @@ public class LicenseVerificationTests extends AbstractLicensingTestBase {
|
|||
|
||||
@Test
|
||||
public void testGeneratedLicenses() throws Exception {
|
||||
License shieldLicense = generateSignedLicense("shield", TimeValue.timeValueHours(2 * 24));
|
||||
License shieldLicense = generateSignedLicense("shield", TimeValue.timeValueHours(2 * 24), pubKeyPath, priKeyPath);
|
||||
assertThat(LicenseVerifier.verifyLicense(shieldLicense), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleFeatureLicenses() throws Exception {
|
||||
License shieldLicense = generateSignedLicense("shield", TimeValue.timeValueHours(2 * 24));
|
||||
License marvelLicense = generateSignedLicense("marvel", TimeValue.timeValueHours(2 * 24));
|
||||
License shieldLicense = generateSignedLicense("shield", TimeValue.timeValueHours(2 * 24), pubKeyPath, priKeyPath);
|
||||
License marvelLicense = generateSignedLicense("marvel", TimeValue.timeValueHours(2 * 24), pubKeyPath, priKeyPath);
|
||||
|
||||
assertThat(LicenseVerifier.verifyLicenses(Arrays.asList(shieldLicense, marvelLicense)), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLicenseTampering() throws Exception {
|
||||
License license = generateSignedLicense("shield", TimeValue.timeValueHours(2));
|
||||
License license = generateSignedLicense("shield", TimeValue.timeValueHours(2), pubKeyPath, priKeyPath);
|
||||
|
||||
final License tamperedLicense = License.builder()
|
||||
.fromLicenseSpec(license, license.signature())
|
||||
|
@ -54,7 +54,7 @@ public class LicenseVerificationTests extends AbstractLicensingTestBase {
|
|||
licenseSpecs.add(TestUtils.generateRandomLicenseSpec());
|
||||
}
|
||||
|
||||
Set<License> generatedLicenses = generateSignedLicenses(licenseSpecs);
|
||||
Set<License> generatedLicenses = generateSignedLicenses(licenseSpecs, pubKeyPath, priKeyPath);
|
||||
assertThat(generatedLicenses.size(), equalTo(n));
|
||||
|
||||
for (License generatedLicense: generatedLicenses) {
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.hamcrest.MatcherAssert;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
|
||||
|
@ -31,6 +32,9 @@ import static org.junit.Assert.assertThat;
|
|||
|
||||
public class TestUtils {
|
||||
|
||||
public static final String PUBLIC_KEY_RESOURCE = "/public.key";
|
||||
public static final String PRIVATE_KEY_RESOURCE = "/private.key";
|
||||
|
||||
private final static FormatDateTimeFormatter formatDateTimeFormatter = Joda.forPattern("yyyy-MM-dd");
|
||||
private final static DateMathParser dateMathParser = new DateMathParser(formatDateTimeFormatter, TimeUnit.MILLISECONDS);
|
||||
private final static org.elasticsearch.common.joda.time.format.DateTimeFormatter dateTimeFormatter = formatDateTimeFormatter.printer();
|
||||
|
@ -71,12 +75,22 @@ public class TestUtils {
|
|||
return builder.string();
|
||||
}
|
||||
|
||||
public static String dateMathString(String time, long now) {
|
||||
return dateTimeFormatter.print(dateMathParser.parse(time, now));
|
||||
public static String dateMathString(String time, final long now) {
|
||||
return dateTimeFormatter.print(dateMathParser.parse(time, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return now;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static long dateMath(String time, long now) {
|
||||
return dateMathParser.parse(time, now);
|
||||
public static long dateMath(String time, final long now) {
|
||||
return dateMathParser.parse(time, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return now;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static LicenseSpec generateRandomLicenseSpec() {
|
||||
|
|
|
@ -8,13 +8,11 @@ package org.elasticsearch.license.licensor.tools;
|
|||
import org.elasticsearch.common.cli.CliToolTestCase;
|
||||
import org.elasticsearch.common.cli.commons.MissingOptionException;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.license.licensor.tools.KeyPairGeneratorTool.KeyGenerator;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -27,23 +25,20 @@ import static org.hamcrest.core.IsEqual.equalTo;
|
|||
|
||||
public class KeyPairGenerationToolTests extends CliToolTestCase {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void testParsingMissingPath() throws Exception {
|
||||
KeyPairGeneratorTool keyPairGeneratorTool = new KeyPairGeneratorTool();
|
||||
File tempFile = temporaryFolder.newFile();
|
||||
Path tempFile = createTempFile();
|
||||
try {
|
||||
keyPairGeneratorTool.parse(KeyPairGeneratorTool.NAME, args(
|
||||
"--privateKeyPath " + tempFile.getAbsolutePath()));
|
||||
"--privateKeyPath " + tempFile.toAbsolutePath()));
|
||||
fail("no public key path provided");
|
||||
} catch (MissingOptionException e) {
|
||||
assertThat(e.getMessage(), containsString("pub"));
|
||||
}
|
||||
try {
|
||||
keyPairGeneratorTool.parse(KeyPairGeneratorTool.NAME, args(
|
||||
"--publicKeyPath " + tempFile.getAbsolutePath()));
|
||||
"--publicKeyPath " + tempFile.toAbsolutePath()));
|
||||
fail("no private key path provided");
|
||||
} catch (MissingOptionException e) {
|
||||
assertThat(e.getMessage(), containsString("pri"));
|
||||
|
@ -53,20 +48,21 @@ public class KeyPairGenerationToolTests extends CliToolTestCase {
|
|||
@Test
|
||||
public void testParsingNeverOverrideKey() throws Exception {
|
||||
KeyPairGeneratorTool keyPairGeneratorTool = new KeyPairGeneratorTool();
|
||||
File tempFile = temporaryFolder.newFile();
|
||||
File tempFile2 = temporaryFolder.newFile();
|
||||
String nonExistentFilePath = tempFile2.getAbsolutePath();
|
||||
assertThat(tempFile2.delete(), equalTo(true));
|
||||
Path tempFile = createTempFile();
|
||||
Path tempFile2 = createTempFile();
|
||||
String nonExistentFilePath = tempFile2.toAbsolutePath().toString();
|
||||
Files.delete(tempFile2);
|
||||
assertThat(Files.exists(tempFile2), equalTo(false));
|
||||
|
||||
Command command = keyPairGeneratorTool.parse(KeyPairGeneratorTool.NAME, args("--privateKeyPath " + tempFile.getAbsolutePath()
|
||||
+ " --publicKeyPath " + nonExistentFilePath));
|
||||
Command command = keyPairGeneratorTool.parse(KeyPairGeneratorTool.NAME, new String[] {"--privateKeyPath", tempFile.toAbsolutePath().toString(),
|
||||
"--publicKeyPath", nonExistentFilePath });
|
||||
|
||||
assertThat(command, instanceOf(Command.Exit.class));
|
||||
Command.Exit exitCommand = (Command.Exit) command;
|
||||
assertThat(exitCommand.status(), equalTo(ExitStatus.USAGE));
|
||||
|
||||
command = keyPairGeneratorTool.parse(KeyPairGeneratorTool.NAME, args("--publicKeyPath " + tempFile.getAbsolutePath()
|
||||
+ " --privateKeyPath " + nonExistentFilePath));
|
||||
command = keyPairGeneratorTool.parse(KeyPairGeneratorTool.NAME, new String[] {"--publicKeyPath", tempFile.toAbsolutePath().toString(),
|
||||
"--privateKeyPath", nonExistentFilePath });
|
||||
|
||||
assertThat(command, instanceOf(Command.Exit.class));
|
||||
exitCommand = (Command.Exit) command;
|
||||
|
@ -76,18 +72,21 @@ public class KeyPairGenerationToolTests extends CliToolTestCase {
|
|||
@Test
|
||||
public void testToolSimple() throws Exception {
|
||||
KeyPairGeneratorTool keyPairGeneratorTool = new KeyPairGeneratorTool();
|
||||
File tempFile1 = temporaryFolder.newFile();
|
||||
File tempFile2 = temporaryFolder.newFile();
|
||||
String publicKeyPath = tempFile1.getAbsolutePath();
|
||||
String privateKeyPath = tempFile2.getAbsolutePath();
|
||||
Path tempFile1 = createTempFile();
|
||||
Path tempFile2 = createTempFile();
|
||||
String publicKeyPath = tempFile1.toAbsolutePath().toString();
|
||||
String privateKeyPath = tempFile2.toAbsolutePath().toString();
|
||||
Path publicKeyFilePath = Paths.get(publicKeyPath);
|
||||
Path privateKeyFilePath = Paths.get(privateKeyPath);
|
||||
Settings settings = ImmutableSettings.builder().put("path.home", createTempDir()).build();
|
||||
|
||||
assertThat(tempFile1.delete(), equalTo(true));
|
||||
assertThat(tempFile2.delete(), equalTo(true));
|
||||
Files.delete(tempFile1);
|
||||
Files.delete(tempFile2);
|
||||
assertThat(Files.exists(tempFile1), equalTo(false));
|
||||
assertThat(Files.exists(tempFile2), equalTo(false));
|
||||
|
||||
Command command = keyPairGeneratorTool.parse(KeyPairGeneratorTool.NAME, args("--privateKeyPath " + privateKeyPath
|
||||
+ " --publicKeyPath " + publicKeyPath));
|
||||
Command command = keyPairGeneratorTool.parse(KeyPairGeneratorTool.NAME, new String[] { "--privateKeyPath", privateKeyPath,
|
||||
"--publicKeyPath", publicKeyPath });
|
||||
|
||||
assertThat(command, instanceOf(KeyGenerator.class));
|
||||
KeyGenerator keyGenerator = (KeyGenerator) command;
|
||||
|
@ -97,7 +96,7 @@ public class KeyPairGenerationToolTests extends CliToolTestCase {
|
|||
assertThat(Files.exists(publicKeyFilePath), equalTo(false));
|
||||
assertThat(Files.exists(privateKeyFilePath), equalTo(false));
|
||||
|
||||
assertThat(keyGenerator.execute(ImmutableSettings.EMPTY, new Environment(ImmutableSettings.EMPTY)), equalTo(ExitStatus.OK));
|
||||
assertThat(keyGenerator.execute(settings, new Environment(settings)), equalTo(ExitStatus.OK));
|
||||
assertThat(Files.exists(publicKeyFilePath), equalTo(true));
|
||||
assertThat(Files.exists(privateKeyFilePath), equalTo(true));
|
||||
|
||||
|
|
|
@ -12,14 +12,10 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.core.Licenses;
|
||||
import org.elasticsearch.license.licensor.AbstractLicensingTestBase;
|
||||
import org.elasticsearch.license.licensor.TestUtils;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -36,17 +32,17 @@ import static org.hamcrest.core.IsEqual.equalTo;
|
|||
|
||||
public class LicenseGenerationToolTests extends CliToolTestCase {
|
||||
|
||||
protected static String pubKeyPath = null;
|
||||
protected static String priKeyPath = null;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
protected String pubKeyPath = null;
|
||||
protected String priKeyPath = null;
|
||||
protected Path homeDir = null;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception {
|
||||
pubKeyPath = AbstractLicensingTestBase.getTestPubKeyPath();
|
||||
priKeyPath = AbstractLicensingTestBase.getTestPriKeyPath();
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
logger.error("project.basedir [{}]", System.getProperty("project.basedir"));
|
||||
pubKeyPath = getDataPath(TestUtils.PUBLIC_KEY_RESOURCE).toString();
|
||||
priKeyPath = getDataPath(TestUtils.PRIVATE_KEY_RESOURCE).toString();
|
||||
homeDir = createTempDir();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -54,18 +50,18 @@ public class LicenseGenerationToolTests extends CliToolTestCase {
|
|||
TestUtils.LicenseSpec inputLicenseSpec = TestUtils.generateRandomLicenseSpec();
|
||||
LicenseGeneratorTool licenseGeneratorTool = new LicenseGeneratorTool();
|
||||
Command command = licenseGeneratorTool.parse(LicenseGeneratorTool.NAME,
|
||||
args("--license " + TestUtils.generateLicenseSpecString(Arrays.asList(inputLicenseSpec))
|
||||
+ " --publicKeyPath " + pubKeyPath.concat("invalid")
|
||||
+ " --privateKeyPath " + priKeyPath));
|
||||
new String[] {"--license", TestUtils.generateLicenseSpecString(Arrays.asList(inputLicenseSpec)),
|
||||
"--publicKeyPath", pubKeyPath.concat("invalid"),
|
||||
"--privateKeyPath", priKeyPath });
|
||||
|
||||
assertThat(command, instanceOf(Command.Exit.class));
|
||||
Command.Exit exitCommand = (Command.Exit) command;
|
||||
assertThat(exitCommand.status(), equalTo(ExitStatus.USAGE));
|
||||
|
||||
command = licenseGeneratorTool.parse(LicenseGeneratorTool.NAME,
|
||||
args("--license " + TestUtils.generateLicenseSpecString(Arrays.asList(inputLicenseSpec))
|
||||
+ " --privateKeyPath " + priKeyPath.concat("invalid")
|
||||
+ " --publicKeyPath " + pubKeyPath));
|
||||
new String[] {"--license", TestUtils.generateLicenseSpecString(Arrays.asList(inputLicenseSpec)),
|
||||
"--privateKeyPath", priKeyPath.concat("invalid"),
|
||||
"--publicKeyPath", pubKeyPath });
|
||||
|
||||
assertThat(command, instanceOf(Command.Exit.class));
|
||||
exitCommand = (Command.Exit) command;
|
||||
|
@ -76,8 +72,8 @@ public class LicenseGenerationToolTests extends CliToolTestCase {
|
|||
public void testParsingMissingLicenseSpec() throws Exception {
|
||||
LicenseGeneratorTool licenseGeneratorTool = new LicenseGeneratorTool();
|
||||
Command command = licenseGeneratorTool.parse(LicenseGeneratorTool.NAME,
|
||||
args(" --publicKeyPath " + pubKeyPath
|
||||
+ " --privateKeyPath " + priKeyPath));
|
||||
new String[] { "--publicKeyPath", pubKeyPath,
|
||||
"--privateKeyPath", priKeyPath });
|
||||
|
||||
assertThat(command, instanceOf(Command.Exit.class));
|
||||
Command.Exit exitCommand = (Command.Exit) command;
|
||||
|
@ -91,9 +87,9 @@ public class LicenseGenerationToolTests extends CliToolTestCase {
|
|||
boolean pubKeyMissing = randomBoolean();
|
||||
try {
|
||||
licenseGeneratorTool.parse(LicenseGeneratorTool.NAME,
|
||||
args("--license " + TestUtils.generateLicenseSpecString(Arrays.asList(inputLicenseSpec))
|
||||
+ ((!pubKeyMissing) ? " --publicKeyPath " + pubKeyPath : "")
|
||||
+ ((pubKeyMissing) ? " --privateKeyPath " + priKeyPath : "")));
|
||||
new String[] { "--license", TestUtils.generateLicenseSpecString(Arrays.asList(inputLicenseSpec)),
|
||||
((pubKeyMissing) ? "--privateKeyPath" : "--publicKeyPath"),
|
||||
((pubKeyMissing) ? priKeyPath : pubKeyPath) });
|
||||
fail("missing argument: " + ((pubKeyMissing) ? "publicKeyPath" : "privateKeyPath") + " should throw an exception");
|
||||
} catch (MissingOptionException e) {
|
||||
assertThat(e.getMessage(), containsString((pubKeyMissing) ? "pub" : "pri"));
|
||||
|
@ -105,9 +101,9 @@ public class LicenseGenerationToolTests extends CliToolTestCase {
|
|||
TestUtils.LicenseSpec inputLicenseSpec = TestUtils.generateRandomLicenseSpec();
|
||||
LicenseGeneratorTool licenseGeneratorTool = new LicenseGeneratorTool();
|
||||
Command command = licenseGeneratorTool.parse(LicenseGeneratorTool.NAME,
|
||||
args("--license " + TestUtils.generateLicenseSpecString(Arrays.asList(inputLicenseSpec))
|
||||
+ " --publicKeyPath " + pubKeyPath
|
||||
+ " --privateKeyPath " + priKeyPath));
|
||||
new String[]{"--license", TestUtils.generateLicenseSpecString(Arrays.asList(inputLicenseSpec)),
|
||||
"--publicKeyPath", pubKeyPath,
|
||||
"--privateKeyPath", priKeyPath });
|
||||
|
||||
assertThat(command, instanceOf(LicenseGenerator.class));
|
||||
LicenseGenerator licenseGenerator = (LicenseGenerator) command;
|
||||
|
@ -122,14 +118,14 @@ public class LicenseGenerationToolTests extends CliToolTestCase {
|
|||
@Test
|
||||
public void testParsingLicenseFile() throws Exception {
|
||||
TestUtils.LicenseSpec inputLicenseSpec = TestUtils.generateRandomLicenseSpec();
|
||||
File tempFile = temporaryFolder.newFile("license_spec.json");
|
||||
Files.write(Paths.get(tempFile.getAbsolutePath()), TestUtils.generateLicenseSpecString(Arrays.asList(inputLicenseSpec)).getBytes(StandardCharsets.UTF_8));
|
||||
Path tempFile = createTempFile();
|
||||
Files.write(tempFile, TestUtils.generateLicenseSpecString(Arrays.asList(inputLicenseSpec)).getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
LicenseGeneratorTool licenseGeneratorTool = new LicenseGeneratorTool();
|
||||
Command command = licenseGeneratorTool.parse(LicenseGeneratorTool.NAME,
|
||||
args("--licenseFile " + tempFile.getAbsolutePath()
|
||||
+ " --publicKeyPath " + pubKeyPath
|
||||
+ " --privateKeyPath " + priKeyPath));
|
||||
new String[] { "--licenseFile", tempFile.toAbsolutePath().toString(),
|
||||
"--publicKeyPath", pubKeyPath,
|
||||
"--privateKeyPath", priKeyPath });
|
||||
|
||||
assertThat(command, instanceOf(LicenseGenerator.class));
|
||||
LicenseGenerator licenseGenerator = (LicenseGenerator) command;
|
||||
|
@ -151,9 +147,9 @@ public class LicenseGenerationToolTests extends CliToolTestCase {
|
|||
}
|
||||
LicenseGeneratorTool licenseGeneratorTool = new LicenseGeneratorTool();
|
||||
Command command = licenseGeneratorTool.parse(LicenseGeneratorTool.NAME,
|
||||
args("--license " + TestUtils.generateLicenseSpecString(new ArrayList<>(inputLicenseSpecs.values()))
|
||||
+ " --publicKeyPath " + pubKeyPath
|
||||
+ " --privateKeyPath " + priKeyPath));
|
||||
new String[] { "--license", TestUtils.generateLicenseSpecString(new ArrayList<>(inputLicenseSpecs.values())),
|
||||
"--publicKeyPath", pubKeyPath,
|
||||
"--privateKeyPath", priKeyPath });
|
||||
|
||||
assertThat(command, instanceOf(LicenseGenerator.class));
|
||||
LicenseGenerator licenseGenerator = (LicenseGenerator) command;
|
||||
|
@ -191,8 +187,9 @@ public class LicenseGenerationToolTests extends CliToolTestCase {
|
|||
|
||||
private String runLicenseGenerationTool(Path pubKeyPath, Path priKeyPath, Set<License> licenseSpecs, ExitStatus expectedExitStatus) throws Exception {
|
||||
CaptureOutputTerminal outputTerminal = new CaptureOutputTerminal();
|
||||
Settings settings = ImmutableSettings.builder().put("path.home", homeDir).build();
|
||||
LicenseGenerator licenseGenerator = new LicenseGenerator(outputTerminal, pubKeyPath, priKeyPath, licenseSpecs);
|
||||
assertThat(execute(licenseGenerator, ImmutableSettings.EMPTY), equalTo(expectedExitStatus));
|
||||
assertThat(execute(licenseGenerator, settings), equalTo(expectedExitStatus));
|
||||
assertThat(outputTerminal.getTerminalOutput().size(), equalTo(1));
|
||||
return outputTerminal.getTerminalOutput().get(0);
|
||||
}
|
||||
|
|
|
@ -15,15 +15,13 @@ import org.elasticsearch.license.licensor.AbstractLicensingTestBase;
|
|||
import org.elasticsearch.license.licensor.TestUtils;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.core.Licenses;
|
||||
import org.junit.Rule;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
||||
import static org.elasticsearch.common.cli.CliTool.Command;
|
||||
|
@ -36,13 +34,23 @@ import static org.hamcrest.core.IsEqual.equalTo;
|
|||
|
||||
public class LicenseVerificationToolTests extends CliToolTestCase {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
protected static Path homeDir = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception {
|
||||
homeDir = createTempDir();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() throws Exception {
|
||||
homeDir = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingMissingLicense() throws Exception {
|
||||
LicenseVerificationTool licenseVerificationTool = new LicenseVerificationTool();
|
||||
Command command = licenseVerificationTool.parse(LicenseVerificationTool.NAME, args(" --publicKeyPath " + AbstractLicensingTestBase.getTestPubKeyPath()));
|
||||
Path path = getDataPath(TestUtils.PUBLIC_KEY_RESOURCE);
|
||||
Command command = licenseVerificationTool.parse(LicenseVerificationTool.NAME, args(" --publicKeyPath " + path));
|
||||
|
||||
assertThat(command, instanceOf(Command.Exit.class));
|
||||
Command.Exit exitCommand = (Command.Exit) command;
|
||||
|
@ -51,8 +59,10 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
|
|||
|
||||
@Test
|
||||
public void testParsingMissingPublicKeyPath() throws Exception {
|
||||
Path pubKeyPath = getDataPath(TestUtils.PUBLIC_KEY_RESOURCE);
|
||||
Path priKeyPath = getDataPath(TestUtils.PRIVATE_KEY_RESOURCE);
|
||||
License inputLicense = AbstractLicensingTestBase.generateSignedLicense("feature__1",
|
||||
TimeValue.timeValueHours(1));
|
||||
TimeValue.timeValueHours(1), pubKeyPath.toString(), priKeyPath.toString());
|
||||
LicenseVerificationTool licenseVerificationTool = new LicenseVerificationTool();
|
||||
try {
|
||||
licenseVerificationTool.parse(LicenseVerificationTool.NAME,
|
||||
|
@ -65,8 +75,9 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
|
|||
@Test
|
||||
public void testParsingNonExistentPublicKeyPath() throws Exception {
|
||||
LicenseVerificationTool licenseVerificationTool = new LicenseVerificationTool();
|
||||
Path path = getDataPath(TestUtils.PUBLIC_KEY_RESOURCE);
|
||||
Command command = licenseVerificationTool.parse(LicenseVerificationTool.NAME, args(" --publicKeyPath "
|
||||
+ AbstractLicensingTestBase.getTestPubKeyPath().concat(".invalid")));
|
||||
+ path.toString().concat(".invalid")));
|
||||
|
||||
assertThat(command, instanceOf(Command.Exit.class));
|
||||
Command.Exit exitCommand = (Command.Exit) command;
|
||||
|
@ -75,12 +86,14 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
|
|||
|
||||
@Test
|
||||
public void testParsingSimple() throws Exception {
|
||||
Path pubKeyPath = getDataPath(TestUtils.PUBLIC_KEY_RESOURCE);
|
||||
Path priKeyPath = getDataPath(TestUtils.PRIVATE_KEY_RESOURCE);
|
||||
License inputLicense = AbstractLicensingTestBase.generateSignedLicense("feature__1",
|
||||
TimeValue.timeValueHours(1));
|
||||
TimeValue.timeValueHours(1), pubKeyPath.toString(), priKeyPath.toString());
|
||||
LicenseVerificationTool licenseVerificationTool = new LicenseVerificationTool();
|
||||
Command command = licenseVerificationTool.parse(LicenseVerificationTool.NAME,
|
||||
args("--license " + TestUtils.dumpLicense(inputLicense)
|
||||
+ " --publicKeyPath " + AbstractLicensingTestBase.getTestPubKeyPath()));
|
||||
+ " --publicKeyPath " + getDataPath(TestUtils.PUBLIC_KEY_RESOURCE)));
|
||||
assertThat(command, instanceOf(LicenseVerifier.class));
|
||||
LicenseVerifier licenseVerifier = (LicenseVerifier) command;
|
||||
assertThat(licenseVerifier.licenses.size(), equalTo(1));
|
||||
|
@ -90,13 +103,15 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
|
|||
|
||||
@Test
|
||||
public void testParsingLicenseFile() throws Exception {
|
||||
Path pubKeyPath = getDataPath(TestUtils.PUBLIC_KEY_RESOURCE);
|
||||
Path priKeyPath = getDataPath(TestUtils.PRIVATE_KEY_RESOURCE);
|
||||
License inputLicense = AbstractLicensingTestBase.generateSignedLicense("feature__1",
|
||||
TimeValue.timeValueHours(1));
|
||||
TimeValue.timeValueHours(1), pubKeyPath.toString(), priKeyPath.toString());
|
||||
|
||||
LicenseVerificationTool licenseVerificationTool = new LicenseVerificationTool();
|
||||
Command command = licenseVerificationTool.parse(LicenseVerificationTool.NAME,
|
||||
args("--licenseFile " + dumpLicenseAsFile(inputLicense)
|
||||
+ " --publicKeyPath " + AbstractLicensingTestBase.getTestPubKeyPath()));
|
||||
new String[] { "--licenseFile", dumpLicenseAsFile(inputLicense),
|
||||
"--publicKeyPath", getDataPath(TestUtils.PUBLIC_KEY_RESOURCE).toString() });
|
||||
assertThat(command, instanceOf(LicenseVerifier.class));
|
||||
LicenseVerifier licenseVerifier = (LicenseVerifier) command;
|
||||
assertThat(licenseVerifier.licenses.size(), equalTo(1));
|
||||
|
@ -107,11 +122,14 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
|
|||
|
||||
@Test
|
||||
public void testParsingMultipleLicense() throws Exception {
|
||||
Path pubKeyPath = getDataPath(TestUtils.PUBLIC_KEY_RESOURCE);
|
||||
Path priKeyPath = getDataPath(TestUtils.PRIVATE_KEY_RESOURCE);
|
||||
|
||||
int n = randomIntBetween(2, 5);
|
||||
Map<String, License> inputLicenses = new HashMap<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
License license = AbstractLicensingTestBase.generateSignedLicense("feature__" + i,
|
||||
TimeValue.timeValueHours(1));
|
||||
TimeValue.timeValueHours(1), pubKeyPath.toString(), priKeyPath.toString());
|
||||
inputLicenses.put(license.feature(), license);
|
||||
}
|
||||
|
||||
|
@ -120,7 +138,7 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
|
|||
argsBuilder.append(" --license ")
|
||||
.append(TestUtils.dumpLicense(inputLicense));
|
||||
}
|
||||
argsBuilder.append(" --publicKeyPath ").append(AbstractLicensingTestBase.getTestPubKeyPath());
|
||||
argsBuilder.append(" --publicKeyPath ").append(getDataPath(TestUtils.PUBLIC_KEY_RESOURCE).toString());
|
||||
LicenseVerificationTool licenseVerificationTool = new LicenseVerificationTool();
|
||||
Command command = licenseVerificationTool.parse(LicenseVerificationTool.NAME, args(argsBuilder.toString()));
|
||||
|
||||
|
@ -137,15 +155,18 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
|
|||
|
||||
@Test
|
||||
public void testToolSimple() throws Exception {
|
||||
Path pubKeyPath = getDataPath(TestUtils.PUBLIC_KEY_RESOURCE);
|
||||
Path priKeyPath = getDataPath(TestUtils.PRIVATE_KEY_RESOURCE);
|
||||
|
||||
int n = randomIntBetween(2, 5);
|
||||
Map<String, License> inputLicenses = new HashMap<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
License license = AbstractLicensingTestBase.generateSignedLicense("feature__" + i,
|
||||
TimeValue.timeValueHours(1));
|
||||
TimeValue.timeValueHours(1), pubKeyPath.toString(), priKeyPath.toString());
|
||||
inputLicenses.put(license.feature(), license);
|
||||
}
|
||||
|
||||
String output = runLicenseVerificationTool(new HashSet<>(inputLicenses.values()), Paths.get(AbstractLicensingTestBase.getTestPubKeyPath()), ExitStatus.OK);
|
||||
String output = runLicenseVerificationTool(new HashSet<>(inputLicenses.values()), getDataPath(TestUtils.PUBLIC_KEY_RESOURCE), ExitStatus.OK);
|
||||
List<License> outputLicenses = Licenses.fromSource(output.getBytes(StandardCharsets.UTF_8), true);
|
||||
assertThat(outputLicenses.size(), equalTo(inputLicenses.size()));
|
||||
|
||||
|
@ -158,26 +179,29 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
|
|||
|
||||
@Test
|
||||
public void testToolInvalidLicense() throws Exception {
|
||||
Path pubKeyPath = getDataPath(TestUtils.PUBLIC_KEY_RESOURCE);
|
||||
Path priKeyPath = getDataPath(TestUtils.PRIVATE_KEY_RESOURCE);
|
||||
License signedLicense = AbstractLicensingTestBase.generateSignedLicense("feature__1"
|
||||
, TimeValue.timeValueHours(1));
|
||||
, TimeValue.timeValueHours(1), pubKeyPath.toString(), priKeyPath.toString());
|
||||
|
||||
License tamperedLicense = License.builder()
|
||||
.fromLicenseSpec(signedLicense, signedLicense.signature())
|
||||
.expiryDate(signedLicense.expiryDate() + randomIntBetween(1, 1000)).build();
|
||||
|
||||
runLicenseVerificationTool(Collections.singleton(tamperedLicense), Paths.get(AbstractLicensingTestBase.getTestPubKeyPath()), ExitStatus.DATA_ERROR);
|
||||
runLicenseVerificationTool(Collections.singleton(tamperedLicense), getDataPath(TestUtils.PUBLIC_KEY_RESOURCE), ExitStatus.DATA_ERROR);
|
||||
}
|
||||
|
||||
private String dumpLicenseAsFile(License license) throws Exception {
|
||||
File tempFile = temporaryFolder.newFile();
|
||||
Files.write(Paths.get(tempFile.getAbsolutePath()), TestUtils.dumpLicense(license).getBytes(StandardCharsets.UTF_8));
|
||||
return tempFile.getAbsolutePath();
|
||||
Path tempFile = createTempFile();
|
||||
Files.write(tempFile, TestUtils.dumpLicense(license).getBytes(StandardCharsets.UTF_8));
|
||||
return tempFile.toAbsolutePath().toString();
|
||||
}
|
||||
|
||||
private String runLicenseVerificationTool(Set<License> licenses, Path publicKeyPath, ExitStatus expectedExitStatus) throws Exception {
|
||||
CaptureOutputTerminal outputTerminal = new CaptureOutputTerminal();
|
||||
Settings settings = ImmutableSettings.builder().put("path.home", homeDir).build();
|
||||
LicenseVerifier licenseVerifier = new LicenseVerifier(outputTerminal, licenses, publicKeyPath);
|
||||
assertThat(execute(licenseVerifier, ImmutableSettings.EMPTY), equalTo(expectedExitStatus));
|
||||
assertThat(execute(licenseVerifier, settings), equalTo(expectedExitStatus));
|
||||
if (expectedExitStatus == ExitStatus.OK) {
|
||||
assertThat(outputTerminal.getTerminalOutput().size(), equalTo(1));
|
||||
|
||||
|
|
101
plugin/pom.xml
101
plugin/pom.xml
|
@ -51,7 +51,6 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
@ -94,7 +93,6 @@
|
|||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<attach>false</attach>
|
||||
<outputDirectory>${project.build.directory}/releases/</outputDirectory>
|
||||
|
@ -119,7 +117,6 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>1.3.1</version>
|
||||
<executions>
|
||||
<!-- TODO: do we want to always enforce non-default keys -->
|
||||
<execution>
|
||||
|
@ -149,7 +146,6 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>for-plugin</id>
|
||||
|
@ -164,7 +160,6 @@
|
|||
<plugin>
|
||||
<groupId>com.carrotsearch.randomizedtesting</groupId>
|
||||
<artifactId>junit4-maven-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>tests</id>
|
||||
|
@ -173,101 +168,7 @@
|
|||
<goal>junit4</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<dir>${project.basedir}/target</dir>
|
||||
<classesDirectory>${project.basedir}/target/classes</classesDirectory>
|
||||
<heartbeat>40</heartbeat>
|
||||
<jvmOutputAction>pipe,warn</jvmOutputAction>
|
||||
<leaveTemporary>true</leaveTemporary>
|
||||
<listeners>
|
||||
<report-ant-xml mavenExtensions="true"
|
||||
dir="${project.build.directory}/surefire-reports"/>
|
||||
<report-text
|
||||
showThrowable="true"
|
||||
showStackTraces="true"
|
||||
showOutput="${tests.output}"
|
||||
showStatusOk="false"
|
||||
showStatusError="true"
|
||||
showStatusFailure="true"
|
||||
showStatusIgnored="true"
|
||||
showSuiteSummary="true"
|
||||
timestamps="false"/>
|
||||
<report-execution-times historyLength="20" file="${basedir}/${execution.hint.file}"/>
|
||||
</listeners>
|
||||
<assertions>
|
||||
<enable/>
|
||||
<disable package="${tests.assertion.disabled}"/>
|
||||
<!-- pass org.elasticsearch to run without assertions -->
|
||||
</assertions>
|
||||
<parallelism>${tests.jvms}</parallelism>
|
||||
<balancers>
|
||||
<execution-times>
|
||||
<fileset dir="${basedir}" includes="${execution.hint.file}"/>
|
||||
</execution-times>
|
||||
</balancers>
|
||||
<includes>
|
||||
<include>**/*Tests.class</include>
|
||||
<include>**/*Test.class</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*.class</exclude>
|
||||
<exclude>**/*StressTest.class</exclude>
|
||||
</excludes>
|
||||
<jvmArgs>
|
||||
<param>-Xmx${tests.heap.size}</param>
|
||||
<param>-Xms${tests.heap.size}</param>
|
||||
<param>-Xss256k</param>
|
||||
<param>-XX:MaxPermSize=128m</param>
|
||||
<param>-XX:MaxDirectMemorySize=512m</param>
|
||||
<param>-Des.logger.prefix=</param>
|
||||
</jvmArgs>
|
||||
<shuffleOnSlave>${tests.shuffle}</shuffleOnSlave>
|
||||
<sysouts>${tests.verbose}</sysouts>
|
||||
<seed>${tests.seed}</seed>
|
||||
<haltOnFailure>${tests.failfast}</haltOnFailure>
|
||||
<uniqueSuiteNames>false</uniqueSuiteNames>
|
||||
<systemProperties>
|
||||
<java.io.tmpdir>.</java.io.tmpdir>
|
||||
<!-- we use '.' since this is different per JVM-->
|
||||
<!-- RandomizedTesting library system properties -->
|
||||
<tests.bwc>${tests.bwc}</tests.bwc>
|
||||
<tests.bwc.path>${tests.bwc.path}</tests.bwc.path>
|
||||
<tests.bwc.version>${tests.bwc.version}</tests.bwc.version>
|
||||
<tests.jvm.argline>${tests.jvm.argline}</tests.jvm.argline>
|
||||
<tests.processors>${tests.processors}</tests.processors>
|
||||
<tests.appendseed>${tests.appendseed}</tests.appendseed>
|
||||
<tests.iters>${tests.iters}</tests.iters>
|
||||
<tests.maxfailures>${tests.maxfailures}</tests.maxfailures>
|
||||
<tests.failfast>${tests.failfast}</tests.failfast>
|
||||
<tests.class>${tests.class}</tests.class>
|
||||
<tests.method>${tests.method}</tests.method>
|
||||
<tests.nightly>${tests.nightly}</tests.nightly>
|
||||
<tests.verbose>${tests.verbose}</tests.verbose>
|
||||
<tests.badapples>${tests.badapples}</tests.badapples>
|
||||
<tests.weekly>${tests.weekly}</tests.weekly>
|
||||
<tests.slow>${tests.slow}</tests.slow>
|
||||
<tests.awaitsfix>${tests.awaitsfix}</tests.awaitsfix>
|
||||
<tests.slow>${tests.slow}</tests.slow>
|
||||
<tests.timeoutSuite>${tests.timeoutSuite}</tests.timeoutSuite>
|
||||
<tests.showSuccess>${tests.showSuccess}</tests.showSuccess>
|
||||
<tests.integration>${tests.integration}</tests.integration>
|
||||
<tests.client.ratio>${tests.client.ratio}</tests.client.ratio>
|
||||
<tests.enable_mock_modules>${tests.enable_mock_modules}</tests.enable_mock_modules>
|
||||
<tests.assertion.disabled>${tests.assertion.disabled}</tests.assertion.disabled>
|
||||
<tests.rest>${tests.rest}</tests.rest>
|
||||
<tests.rest.suite>${tests.rest.suite}</tests.rest.suite>
|
||||
<tests.rest.blacklist>${tests.rest.blacklist}</tests.rest.blacklist>
|
||||
<tests.rest.spec>${tests.rest.spec}</tests.rest.spec>
|
||||
<tests.network>${tests.network}</tests.network>
|
||||
<tests.cluster>${tests.cluster}</tests.cluster>
|
||||
<tests.heap.size>${tests.heap.size}</tests.heap.size>
|
||||
<tests.filter>${tests.filter}</tests.filter>
|
||||
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
|
||||
<es.node.mode>${es.node.mode}</es.node.mode>
|
||||
<es.logger.level>${es.logger.level}</es.logger.level>
|
||||
<tests.security.manager>${tests.security.manager}</tests.security.manager>
|
||||
<tests.compatibility>${tests.compatibility}</tests.compatibility>
|
||||
<java.awt.headless>true</java.awt.headless>
|
||||
</systemProperties>
|
||||
<heartbeat combine.self="override">40</heartbeat>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
|
|
@ -37,7 +37,7 @@ public class LicensePlugin extends AbstractPlugin {
|
|||
private final boolean isEnabled;
|
||||
|
||||
static {
|
||||
MetaData.registerFactory(LicensesMetaData.TYPE, LicensesMetaData.FACTORY);
|
||||
MetaData.registerPrototype(LicensesMetaData.TYPE, LicensesMetaData.PROTO);
|
||||
}
|
||||
|
||||
@Inject
|
||||
|
|
|
@ -25,7 +25,7 @@ public class LicenseVersion implements Serializable {
|
|||
public static final int V_1_0_0_ID = /*00*/1000099;
|
||||
public static final int V_2_0_0_ID = /*00*/2000099;
|
||||
public static final LicenseVersion V_1_0_0 = new LicenseVersion(V_1_0_0_ID, false, License.VERSION_START, Version.V_1_4_0_Beta1);
|
||||
public static final LicenseVersion V_2_0_0 = new LicenseVersion(V_2_0_0_ID, true, License.VERSION_START, Version.V_1_4_0_Beta1);
|
||||
public static final LicenseVersion V_2_0_0 = new LicenseVersion(V_2_0_0_ID, true, License.VERSION_START, Version.V_2_0_0);
|
||||
|
||||
public static final LicenseVersion CURRENT = V_2_0_0;
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.action.delete;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.ClusterAction;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
public class DeleteLicenseAction extends ClusterAction<DeleteLicenseRequest, DeleteLicenseResponse, DeleteLicenseRequestBuilder> {
|
||||
public class DeleteLicenseAction extends Action<DeleteLicenseRequest, DeleteLicenseResponse, DeleteLicenseRequestBuilder> {
|
||||
|
||||
public static final DeleteLicenseAction INSTANCE = new DeleteLicenseAction();
|
||||
public static final String NAME = "cluster:admin/plugin/license/delete";
|
||||
|
@ -23,7 +23,7 @@ public class DeleteLicenseAction extends ClusterAction<DeleteLicenseRequest, Del
|
|||
}
|
||||
|
||||
@Override
|
||||
public DeleteLicenseRequestBuilder newRequestBuilder(ClusterAdminClient client) {
|
||||
return new DeleteLicenseRequestBuilder(client);
|
||||
public DeleteLicenseRequestBuilder newRequestBuilder(ElasticsearchClient client) {
|
||||
return new DeleteLicenseRequestBuilder(client, this);
|
||||
}
|
||||
}
|
|
@ -5,31 +5,25 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.action.delete;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class DeleteLicenseRequestBuilder extends AcknowledgedRequestBuilder<DeleteLicenseRequest, DeleteLicenseResponse, DeleteLicenseRequestBuilder, ClusterAdminClient> {
|
||||
public class DeleteLicenseRequestBuilder extends AcknowledgedRequestBuilder<DeleteLicenseRequest, DeleteLicenseResponse, DeleteLicenseRequestBuilder> {
|
||||
|
||||
/**
|
||||
* Creates new get licenses request builder
|
||||
*
|
||||
* @param clusterAdminClient cluster admin client
|
||||
* @param client elasticsearch client
|
||||
*/
|
||||
public DeleteLicenseRequestBuilder(ClusterAdminClient clusterAdminClient) {
|
||||
super(clusterAdminClient, new DeleteLicenseRequest());
|
||||
public DeleteLicenseRequestBuilder(ElasticsearchClient client, DeleteLicenseAction action) {
|
||||
super(client, action, new DeleteLicenseRequest());
|
||||
}
|
||||
|
||||
public DeleteLicenseRequestBuilder setFeatures(Set<String> features) {
|
||||
request.features(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<DeleteLicenseResponse> listener) {
|
||||
client.execute(DeleteLicenseAction.INSTANCE, request, listener);
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ public class TransportDeleteLicenseAction extends TransportMasterNodeOperationAc
|
|||
@Inject
|
||||
public TransportDeleteLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService, LicensesManagerService licensesManagerService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters) {
|
||||
super(settings, DeleteLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||
super(settings, DeleteLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters, DeleteLicenseRequest.class);
|
||||
this.licensesManagerService = licensesManagerService;
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,6 @@ public class TransportDeleteLicenseAction extends TransportMasterNodeOperationAc
|
|||
return ThreadPool.Names.MANAGEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeleteLicenseRequest newRequest() {
|
||||
return new DeleteLicenseRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeleteLicenseResponse newResponse() {
|
||||
return new DeleteLicenseResponse();
|
||||
|
@ -50,7 +45,7 @@ public class TransportDeleteLicenseAction extends TransportMasterNodeOperationAc
|
|||
|
||||
@Override
|
||||
protected ClusterBlockException checkBlock(DeleteLicenseRequest request, ClusterState state) {
|
||||
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
|
||||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.action.get;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.ClusterAction;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
public class GetLicenseAction extends ClusterAction<GetLicenseRequest, GetLicenseResponse, GetLicenseRequestBuilder> {
|
||||
public class GetLicenseAction extends Action<GetLicenseRequest, GetLicenseResponse, GetLicenseRequestBuilder> {
|
||||
|
||||
public static final GetLicenseAction INSTANCE = new GetLicenseAction();
|
||||
public static final String NAME = "cluster:admin/plugin/license/get";
|
||||
|
@ -23,7 +23,7 @@ public class GetLicenseAction extends ClusterAction<GetLicenseRequest, GetLicens
|
|||
}
|
||||
|
||||
@Override
|
||||
public GetLicenseRequestBuilder newRequestBuilder(ClusterAdminClient client) {
|
||||
return new GetLicenseRequestBuilder(client);
|
||||
public GetLicenseRequestBuilder newRequestBuilder(ElasticsearchClient client) {
|
||||
return new GetLicenseRequestBuilder(client, this);
|
||||
}
|
||||
}
|
|
@ -7,10 +7,6 @@ package org.elasticsearch.license.plugin.action.get;
|
|||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequest;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class GetLicenseRequest extends MasterNodeReadOperationRequest<GetLicenseRequest> {
|
||||
|
@ -22,16 +18,4 @@ public class GetLicenseRequest extends MasterNodeReadOperationRequest<GetLicense
|
|||
public ActionRequestValidationException validate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
readLocal(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
writeLocal(out);
|
||||
}
|
||||
}
|
|
@ -5,24 +5,17 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.action.get;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
public class GetLicenseRequestBuilder extends MasterNodeReadOperationRequestBuilder<GetLicenseRequest, GetLicenseResponse, GetLicenseRequestBuilder, ClusterAdminClient> {
|
||||
public class GetLicenseRequestBuilder extends MasterNodeReadOperationRequestBuilder<GetLicenseRequest, GetLicenseResponse, GetLicenseRequestBuilder> {
|
||||
|
||||
/**
|
||||
* Creates new get licenses request builder
|
||||
*
|
||||
* @param clusterAdminClient cluster admin client
|
||||
* @param client elasticsearch client
|
||||
*/
|
||||
public GetLicenseRequestBuilder(ClusterAdminClient clusterAdminClient) {
|
||||
super(clusterAdminClient, new GetLicenseRequest());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<GetLicenseResponse> listener) {
|
||||
client.execute(GetLicenseAction.INSTANCE, request, listener);
|
||||
public GetLicenseRequestBuilder(ElasticsearchClient client, GetLicenseAction action) {
|
||||
super(client, action, new GetLicenseRequest());
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ public class TransportGetLicenseAction extends TransportMasterNodeReadOperationA
|
|||
@Inject
|
||||
public TransportGetLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService, LicensesManagerService licensesManagerService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters) {
|
||||
super(settings, GetLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||
super(settings, GetLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters, GetLicenseRequest.class);
|
||||
this.licensesManagerService = licensesManagerService;
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,6 @@ public class TransportGetLicenseAction extends TransportMasterNodeReadOperationA
|
|||
return ThreadPool.Names.MANAGEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GetLicenseRequest newRequest() {
|
||||
return new GetLicenseRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GetLicenseResponse newResponse() {
|
||||
return new GetLicenseResponse();
|
||||
|
@ -47,7 +42,7 @@ public class TransportGetLicenseAction extends TransportMasterNodeReadOperationA
|
|||
|
||||
@Override
|
||||
protected ClusterBlockException checkBlock(GetLicenseRequest request, ClusterState state) {
|
||||
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
|
||||
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_READ, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.action.put;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.ClusterAction;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
public class PutLicenseAction extends ClusterAction<PutLicenseRequest, PutLicenseResponse, PutLicenseRequestBuilder> {
|
||||
public class PutLicenseAction extends Action<PutLicenseRequest, PutLicenseResponse, PutLicenseRequestBuilder> {
|
||||
|
||||
public static final PutLicenseAction INSTANCE = new PutLicenseAction();
|
||||
public static final String NAME = "cluster:admin/plugin/license/put";
|
||||
|
@ -23,7 +23,7 @@ public class PutLicenseAction extends ClusterAction<PutLicenseRequest, PutLicens
|
|||
}
|
||||
|
||||
@Override
|
||||
public PutLicenseRequestBuilder newRequestBuilder(ClusterAdminClient client) {
|
||||
return new PutLicenseRequestBuilder(client);
|
||||
public PutLicenseRequestBuilder newRequestBuilder(ElasticsearchClient client) {
|
||||
return new PutLicenseRequestBuilder(client, this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.action.put;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
|
@ -38,7 +37,7 @@ public class PutLicenseRequest extends AcknowledgedRequest<PutLicenseRequest> {
|
|||
try {
|
||||
return licenses(Licenses.fromSource(licenseDefinition));
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchIllegalArgumentException("failed to parse licenses source", e);
|
||||
throw new IllegalArgumentException("failed to parse licenses source", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.action.put;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.license.core.License;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -15,15 +14,15 @@ import java.util.List;
|
|||
/**
|
||||
* Register license request builder
|
||||
*/
|
||||
public class PutLicenseRequestBuilder extends AcknowledgedRequestBuilder<PutLicenseRequest, PutLicenseResponse, PutLicenseRequestBuilder, ClusterAdminClient> {
|
||||
public class PutLicenseRequestBuilder extends AcknowledgedRequestBuilder<PutLicenseRequest, PutLicenseResponse, PutLicenseRequestBuilder> {
|
||||
|
||||
/**
|
||||
* Constructs register license request
|
||||
*
|
||||
* @param clusterAdminClient cluster admin client
|
||||
* @param client elasticsearch client
|
||||
*/
|
||||
public PutLicenseRequestBuilder(ClusterAdminClient clusterAdminClient) {
|
||||
super(clusterAdminClient, new PutLicenseRequest());
|
||||
public PutLicenseRequestBuilder(ElasticsearchClient client, PutLicenseAction action) {
|
||||
super(client, action, new PutLicenseRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,9 +40,4 @@ public class PutLicenseRequestBuilder extends AcknowledgedRequestBuilder<PutLice
|
|||
request.licenses(licenseSource);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<PutLicenseResponse> listener) {
|
||||
client.execute(PutLicenseAction.INSTANCE, request, listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class TransportPutLicenseAction extends TransportMasterNodeOperationActio
|
|||
@Inject
|
||||
public TransportPutLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
LicensesManagerService licensesManagerService, ThreadPool threadPool, ActionFilters actionFilters) {
|
||||
super(settings, PutLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||
super(settings, PutLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters, PutLicenseRequest.class);
|
||||
this.licensesManagerService = licensesManagerService;
|
||||
}
|
||||
|
||||
|
@ -39,11 +39,6 @@ public class TransportPutLicenseAction extends TransportMasterNodeOperationActio
|
|||
return ThreadPool.Names.MANAGEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PutLicenseRequest newRequest() {
|
||||
return new PutLicenseRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PutLicenseResponse newResponse() {
|
||||
return new PutLicenseResponse();
|
||||
|
@ -51,7 +46,7 @@ public class TransportPutLicenseAction extends TransportMasterNodeOperationActio
|
|||
|
||||
@Override
|
||||
protected ClusterBlockException checkBlock(PutLicenseRequest request, ClusterState state) {
|
||||
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
|
||||
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA_WRITE, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.core;
|
||||
|
||||
import org.elasticsearch.cluster.AbstractDiffable;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.license.core.License;
|
||||
|
@ -17,17 +17,18 @@ import org.elasticsearch.license.core.Licenses;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains metadata about registered licenses
|
||||
*/
|
||||
public class LicensesMetaData implements MetaData.Custom {
|
||||
public class LicensesMetaData extends AbstractDiffable<MetaData.Custom> implements MetaData.Custom {
|
||||
|
||||
public static final String TYPE = "licenses";
|
||||
|
||||
public static final Factory FACTORY = new Factory();
|
||||
public static final LicensesMetaData PROTO = new LicensesMetaData(Collections.<License>emptyList(), Collections.<License>emptyList());
|
||||
|
||||
private final ImmutableList<License> signedLicenses;
|
||||
|
||||
|
@ -68,107 +69,87 @@ public class LicensesMetaData implements MetaData.Custom {
|
|||
return signedLicenses.hashCode() + 31 * trialLicenses.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Licenses metadata factory
|
||||
*/
|
||||
public static class Factory extends MetaData.Custom.Factory<LicensesMetaData> {
|
||||
@Override
|
||||
public String type() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String type() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public LicensesMetaData readFrom(StreamInput in) throws IOException {
|
||||
List<License> signedLicenses = Licenses.readFrom(in);
|
||||
int numTrialLicenses = in.readVInt();
|
||||
List<License> trialLicenses = new ArrayList<>(numTrialLicenses);
|
||||
for (int i = 0; i < numTrialLicenses; i++) {
|
||||
trialLicenses.add(TrialLicenseUtils.fromEncodedTrialLicense(in.readString()));
|
||||
}
|
||||
return new LicensesMetaData(signedLicenses, trialLicenses);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void writeTo(LicensesMetaData licensesMetaData, StreamOutput out) throws IOException {
|
||||
Licenses.writeTo(licensesMetaData.signedLicenses, out);
|
||||
out.writeVInt(licensesMetaData.trialLicenses.size());
|
||||
for (License trialLicense : licensesMetaData.trialLicenses) {
|
||||
out.writeString(TrialLicenseUtils.toEncodedTrialLicense(trialLicense));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public LicensesMetaData fromXContent(XContentParser parser) throws IOException {
|
||||
List<License> trialLicenses = new ArrayList<>();
|
||||
List<License> signedLicenses = new ArrayList<>();
|
||||
XContentParser.Token token;
|
||||
while (parser.currentToken() != XContentParser.Token.END_OBJECT) {
|
||||
token = parser.nextToken();
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
String fieldName = parser.text();
|
||||
if (fieldName != null) {
|
||||
if (fieldName.equals(Fields.TRIAL_LICENSES)) {
|
||||
if (parser.nextToken() == XContentParser.Token.START_ARRAY) {
|
||||
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
|
||||
if (parser.currentToken().isValue()) {
|
||||
trialLicenses.add(TrialLicenseUtils.fromEncodedTrialLicense(parser.text()));
|
||||
}
|
||||
@Override
|
||||
public LicensesMetaData fromXContent(XContentParser parser) throws IOException {
|
||||
List<License> trialLicenses = new ArrayList<>();
|
||||
List<License> signedLicenses = new ArrayList<>();
|
||||
XContentParser.Token token;
|
||||
while (parser.currentToken() != XContentParser.Token.END_OBJECT) {
|
||||
token = parser.nextToken();
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
String fieldName = parser.text();
|
||||
if (fieldName != null) {
|
||||
if (fieldName.equals(Fields.TRIAL_LICENSES)) {
|
||||
if (parser.nextToken() == XContentParser.Token.START_ARRAY) {
|
||||
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
|
||||
if (parser.currentToken().isValue()) {
|
||||
trialLicenses.add(TrialLicenseUtils.fromEncodedTrialLicense(parser.text()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fieldName.equals(Fields.SIGNED_LICENCES)) {
|
||||
if (parser.nextToken() == XContentParser.Token.START_ARRAY) {
|
||||
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
|
||||
License.Builder builder = License.builder().fromXContent(parser);
|
||||
signedLicenses.add(builder.build());
|
||||
}
|
||||
}
|
||||
if (fieldName.equals(Fields.SIGNED_LICENCES)) {
|
||||
if (parser.nextToken() == XContentParser.Token.START_ARRAY) {
|
||||
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
|
||||
License.Builder builder = License.builder().fromXContent(parser);
|
||||
signedLicenses.add(builder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new LicensesMetaData(signedLicenses, trialLicenses);
|
||||
}
|
||||
return new LicensesMetaData(signedLicenses, trialLicenses);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void toXContent(LicensesMetaData licensesMetaData, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startArray(Fields.TRIAL_LICENSES);
|
||||
for (License trailLicense : licensesMetaData.trialLicenses) {
|
||||
builder.value(TrialLicenseUtils.toEncodedTrialLicense(trailLicense));
|
||||
}
|
||||
builder.endArray();
|
||||
@Override
|
||||
public EnumSet<MetaData.XContentContext> context() {
|
||||
return EnumSet.of(MetaData.XContentContext.GATEWAY);
|
||||
}
|
||||
|
||||
builder.startArray(Fields.SIGNED_LICENCES);
|
||||
for (License license : licensesMetaData.signedLicenses) {
|
||||
license.toXContent(builder, params);
|
||||
}
|
||||
builder.endArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<MetaData.XContentContext> context() {
|
||||
return EnumSet.of(MetaData.XContentContext.GATEWAY);
|
||||
}
|
||||
|
||||
private final static class Fields {
|
||||
private static final String SIGNED_LICENCES = "signed_licenses";
|
||||
private static final String TRIAL_LICENSES = "trial_licenses";
|
||||
@Override
|
||||
public void writeTo(StreamOutput streamOutput) throws IOException {
|
||||
Licenses.writeTo(signedLicenses, streamOutput);
|
||||
streamOutput.writeVInt(trialLicenses.size());
|
||||
for (License trialLicense : trialLicenses) {
|
||||
streamOutput.writeString(TrialLicenseUtils.toEncodedTrialLicense(trialLicense));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaData.Custom readFrom(StreamInput streamInput) throws IOException {
|
||||
List<License> signedLicenses = Licenses.readFrom(streamInput);
|
||||
int numTrialLicenses = streamInput.readVInt();
|
||||
List<License> trialLicenses = new ArrayList<>(numTrialLicenses);
|
||||
for (int i = 0; i < numTrialLicenses; i++) {
|
||||
trialLicenses.add(TrialLicenseUtils.fromEncodedTrialLicense(streamInput.readString()));
|
||||
}
|
||||
return new LicensesMetaData(signedLicenses, trialLicenses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startArray(Fields.TRIAL_LICENSES);
|
||||
for (License trailLicense : trialLicenses) {
|
||||
builder.value(TrialLicenseUtils.toEncodedTrialLicense(trailLicense));
|
||||
}
|
||||
builder.endArray();
|
||||
|
||||
builder.startArray(Fields.SIGNED_LICENCES);
|
||||
for (License license : signedLicenses) {
|
||||
license.toXContent(builder, params);
|
||||
}
|
||||
builder.endArray();
|
||||
return builder;
|
||||
}
|
||||
|
||||
private final static class Fields {
|
||||
private static final String SIGNED_LICENCES = "signed_licenses";
|
||||
private static final String TRIAL_LICENSES = "trial_licenses";
|
||||
}
|
||||
}
|
|
@ -37,7 +37,6 @@ import org.elasticsearch.transport.*;
|
|||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
@ -128,7 +127,8 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
|||
this.transportService = transportService;
|
||||
this.lastObservedLicensesState = new AtomicReference<>(null);
|
||||
if (DiscoveryNode.masterNode(settings)) {
|
||||
transportService.registerHandler(REGISTER_TRIAL_LICENSE_ACTION_NAME, new RegisterTrialLicenseRequestHandler());
|
||||
transportService.registerRequestHandler(REGISTER_TRIAL_LICENSE_ACTION_NAME, RegisterTrialLicenseRequest.class,
|
||||
ThreadPool.Names.SAME, new RegisterTrialLicenseRequestHandler());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1087,21 +1087,12 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
|||
/**
|
||||
* Request handler for trial license generation to master
|
||||
*/
|
||||
private class RegisterTrialLicenseRequestHandler extends BaseTransportRequestHandler<RegisterTrialLicenseRequest> {
|
||||
@Override
|
||||
public RegisterTrialLicenseRequest newInstance() {
|
||||
return new RegisterTrialLicenseRequest();
|
||||
}
|
||||
private class RegisterTrialLicenseRequestHandler implements TransportRequestHandler<RegisterTrialLicenseRequest> {
|
||||
|
||||
@Override
|
||||
public void messageReceived(RegisterTrialLicenseRequest request, TransportChannel channel) throws Exception {
|
||||
registerTrialLicense(request);
|
||||
channel.sendResponse(TransportResponse.Empty.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String executor() {
|
||||
return ThreadPool.Names.SAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.core;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
||||
|
||||
public enum LicensesStatus {
|
||||
VALID((byte) 0),
|
||||
INVALID((byte) 1),
|
||||
|
@ -30,7 +28,7 @@ public enum LicensesStatus {
|
|||
} else if (id == 2) {
|
||||
return EXPIRED;
|
||||
} else {
|
||||
throw new ElasticsearchIllegalStateException("no valid LicensesStatus for id=" + id);
|
||||
throw new IllegalStateException("no valid LicensesStatus for id=" + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.rest;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -34,10 +33,9 @@ public class RestDeleteLicenseAction extends BaseRestHandler {
|
|||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] features = Strings.splitStringByCommaToArray(request.param("features"));
|
||||
if (features.length == 0) {
|
||||
throw new ElasticsearchIllegalArgumentException("no feature specified for license deletion");
|
||||
throw new IllegalArgumentException("no feature specified for license deletion");
|
||||
}
|
||||
DeleteLicenseRequest deleteLicenseRequest = new DeleteLicenseRequest(features);
|
||||
deleteLicenseRequest.listenerThreaded(false);
|
||||
client.admin().cluster().execute(DeleteLicenseAction.INSTANCE, deleteLicenseRequest, new AcknowledgedRestListener<DeleteLicenseResponse>(channel));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ public class RestPutLicenseAction extends BaseRestHandler {
|
|||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
|
||||
putLicenseRequest.listenerThreaded(false);
|
||||
putLicenseRequest.licenses(request.content().toUtf8());
|
||||
client.admin().cluster().execute(PutLicenseAction.INSTANCE, putLicenseRequest, new LicensesAcknowledgedListener(channel));
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.elasticsearch.common.settings.ImmutableSettings;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseRequestBuilder;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseResponse;
|
||||
import org.elasticsearch.license.plugin.consumer.EagerLicenseRegistrationPluginService;
|
||||
|
@ -32,6 +33,7 @@ import org.elasticsearch.test.InternalTestCluster;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -45,12 +47,22 @@ public abstract class AbstractLicensesIntegrationTests extends ElasticsearchInte
|
|||
private final static org.elasticsearch.common.joda.time.format.DateTimeFormatter dateTimeFormatter = formatDateTimeFormatter.printer();
|
||||
private final static DateMathParser dateMathParser = new DateMathParser(formatDateTimeFormatter, TimeUnit.MILLISECONDS);
|
||||
|
||||
public static String dateMathString(String time, long now) {
|
||||
return dateTimeFormatter.print(dateMathParser.parse(time, now));
|
||||
public static String dateMathString(String time, final long now) {
|
||||
return dateTimeFormatter.print(dateMathParser.parse(time, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return now;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static long dateMath(String time, long now) {
|
||||
return dateMathParser.parse(time, now);
|
||||
public static long dateMath(String time, final long now) {
|
||||
return dateMathParser.parse(time, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return now;
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
|
@ -92,7 +104,7 @@ public abstract class AbstractLicensesIntegrationTests extends ElasticsearchInte
|
|||
|
||||
protected void putLicense(String feature, TimeValue expiryDuration) throws Exception {
|
||||
License license1 = generateSignedLicense(feature, expiryDuration);
|
||||
final PutLicenseResponse putLicenseResponse = new PutLicenseRequestBuilder(client().admin().cluster()).setLicense(Lists.newArrayList(license1)).get();
|
||||
final PutLicenseResponse putLicenseResponse = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(Lists.newArrayList(license1)).get();
|
||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class LicensesMetaDataSerializationTests extends ElasticsearchTestCase {
|
|||
LicensesMetaData licensesMetaData = new LicensesMetaData(Arrays.asList(license), new ArrayList<License>());
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
builder.startObject("licensesMetaData");
|
||||
LicensesMetaData.FACTORY.toXContent(licensesMetaData, builder, ToXContent.EMPTY_PARAMS);
|
||||
licensesMetaData.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
byte[] serializedBytes = builder.bytes().toBytes();
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class LicensesMetaDataSerializationTests extends ElasticsearchTestCase {
|
|||
LicensesMetaData licensesMetaData = new LicensesMetaData(licenses, new ArrayList<License>());
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
builder.startObject("licensesMetaData");
|
||||
LicensesMetaData.FACTORY.toXContent(licensesMetaData, builder, ToXContent.EMPTY_PARAMS);
|
||||
licensesMetaData.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
byte[] serializedBytes = builder.bytes().toBytes();
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class LicensesMetaDataSerializationTests extends ElasticsearchTestCase {
|
|||
LicensesMetaData licensesMetaData = new LicensesMetaData(new ArrayList<License>(), Arrays.asList(trialLicense));
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
builder.startObject("licensesMetaData");
|
||||
LicensesMetaData.FACTORY.toXContent(licensesMetaData, builder, ToXContent.EMPTY_PARAMS);
|
||||
licensesMetaData.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
byte[] serializedBytes = builder.bytes().toBytes();
|
||||
|
||||
|
@ -101,7 +101,7 @@ public class LicensesMetaDataSerializationTests extends ElasticsearchTestCase {
|
|||
LicensesMetaData licensesMetaData = new LicensesMetaData(new ArrayList<License>(), trialLicenses);
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
builder.startObject("licensesMetaData");
|
||||
LicensesMetaData.FACTORY.toXContent(licensesMetaData, builder, ToXContent.EMPTY_PARAMS);
|
||||
licensesMetaData.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
byte[] serializedBytes = builder.bytes().toBytes();
|
||||
|
||||
|
@ -131,7 +131,7 @@ public class LicensesMetaDataSerializationTests extends ElasticsearchTestCase {
|
|||
LicensesMetaData licensesMetaData = new LicensesMetaData(licenses, trialLicenses);
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
builder.startObject("licensesMetaData");
|
||||
LicensesMetaData.FACTORY.toXContent(licensesMetaData, builder, ToXContent.EMPTY_PARAMS);
|
||||
licensesMetaData.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
byte[] serializedBytes = builder.bytes().toBytes();
|
||||
|
||||
|
@ -147,7 +147,7 @@ public class LicensesMetaDataSerializationTests extends ElasticsearchTestCase {
|
|||
final XContentParser parser = XContentFactory.xContent(bytes).createParser(bytes);
|
||||
parser.nextToken(); // consume null
|
||||
parser.nextToken(); // consume "licensesMetaData"
|
||||
LicensesMetaData licensesMetaDataFromXContent = LicensesMetaData.FACTORY.fromXContent(parser);
|
||||
LicensesMetaData licensesMetaDataFromXContent = LicensesMetaData.PROTO.fromXContent(parser);
|
||||
parser.nextToken(); // consume endObject
|
||||
assertThat(parser.nextToken(), nullValue());
|
||||
return licensesMetaDataFromXContent;
|
||||
|
|
|
@ -10,8 +10,10 @@ import org.elasticsearch.common.settings.ImmutableSettings;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.get.GetLicenseRequestBuilder;
|
||||
import org.elasticsearch.license.plugin.action.get.GetLicenseResponse;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseRequestBuilder;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseResponse;
|
||||
import org.elasticsearch.license.plugin.consumer.EagerLicenseRegistrationConsumerPlugin;
|
||||
|
@ -20,7 +22,7 @@ import org.elasticsearch.license.plugin.consumer.LazyLicenseRegistrationConsumer
|
|||
import org.elasticsearch.license.plugin.consumer.LazyLicenseRegistrationPluginService;
|
||||
import org.elasticsearch.license.plugin.core.LicensesMetaData;
|
||||
import org.elasticsearch.license.plugin.core.LicensesStatus;
|
||||
import org.elasticsearch.node.internal.InternalNode;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -57,7 +59,7 @@ public class LicensesServiceClusterTest extends AbstractLicensesIntegrationTests
|
|||
.put(EagerLicenseRegistrationConsumerPlugin.NAME + ".trial_license_duration_in_seconds", 2)
|
||||
.put(LazyLicenseRegistrationConsumerPlugin.NAME + ".trial_license_duration_in_seconds", 2)
|
||||
.putArray("plugin.types", LicensePlugin.class.getName(), EagerLicenseRegistrationConsumerPlugin.class.getName(), LazyLicenseRegistrationConsumerPlugin.class.getName())
|
||||
.put(InternalNode.HTTP_ENABLED, true);
|
||||
.put(Node.HTTP_ENABLED, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -124,7 +126,7 @@ public class LicensesServiceClusterTest extends AbstractLicensesIntegrationTests
|
|||
for (String feature : FEATURES) {
|
||||
putLicenses.add(generateSignedLicense(feature, TimeValue.timeValueMinutes(1)));
|
||||
}
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(cluster);
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(cluster, PutLicenseAction.INSTANCE);
|
||||
putLicenseRequestBuilder.setLicense(putLicenses);
|
||||
ensureGreen();
|
||||
|
||||
|
@ -138,7 +140,7 @@ public class LicensesServiceClusterTest extends AbstractLicensesIntegrationTests
|
|||
|
||||
private void getAndCheckLicense(List<License> licenses) {
|
||||
ClusterAdminClient cluster = internalCluster().client().admin().cluster();
|
||||
final GetLicenseResponse response = new GetLicenseRequestBuilder(cluster).get();
|
||||
final GetLicenseResponse response = new GetLicenseRequestBuilder(cluster, GetLicenseAction.INSTANCE).get();
|
||||
assertThat(response.licenses().size(), equalTo(licenses.size()));
|
||||
TestUtils.isSame(licenses, response.licenses());
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.elasticsearch.common.settings.ImmutableSettings;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.plugin.consumer.EagerLicenseRegistrationConsumerPlugin;
|
||||
import org.elasticsearch.license.plugin.consumer.EagerLicenseRegistrationPluginService;
|
||||
import org.elasticsearch.node.internal.InternalNode;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||
import org.junit.Test;
|
||||
|
@ -31,7 +31,7 @@ public class LicensesServiceNodeTests extends AbstractLicensesIntegrationTests {
|
|||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put(EagerLicenseRegistrationConsumerPlugin.NAME + ".trial_license_duration_in_seconds", 60 * 5)
|
||||
.putArray("plugin.types", LicensePlugin.class.getName(), EagerLicenseRegistrationConsumerPlugin.class.getName())
|
||||
.put(InternalNode.HTTP_ENABLED, true)
|
||||
.put(Node.HTTP_ENABLED, true)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,13 @@ import org.elasticsearch.action.ActionFuture;
|
|||
import org.elasticsearch.common.collect.Sets;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequestBuilder;
|
||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseResponse;
|
||||
import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.get.GetLicenseRequestBuilder;
|
||||
import org.elasticsearch.license.plugin.action.get.GetLicenseResponse;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseRequestBuilder;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseResponse;
|
||||
import org.elasticsearch.license.plugin.core.LicensesStatus;
|
||||
|
@ -39,7 +42,7 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
|
||||
@Test
|
||||
public void testEmptyGetLicense() throws Exception {
|
||||
final ActionFuture<GetLicenseResponse> getLicenseFuture = new GetLicenseRequestBuilder(client().admin().cluster()).execute();
|
||||
final ActionFuture<GetLicenseResponse> getLicenseFuture = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).execute();
|
||||
final GetLicenseResponse getLicenseResponse = getLicenseFuture.get();
|
||||
assertThat("expected 0 licenses; but got: " + getLicenseResponse.licenses().size(), getLicenseResponse.licenses().size(), equalTo(0));
|
||||
}
|
||||
|
@ -50,14 +53,14 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
List<License> actualLicenses = Collections.singletonList(signedLicense);
|
||||
|
||||
// put license
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster())
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE)
|
||||
.setLicense(actualLicenses);
|
||||
PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
|
||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
|
||||
// get license
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses(), notNullValue());
|
||||
assertThat(getLicenseResponse.licenses().size(), equalTo(1));
|
||||
|
||||
|
@ -71,14 +74,14 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
String licenseString = TestUtils.dumpLicense(signedLicense);
|
||||
|
||||
// put license source
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster())
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE)
|
||||
.setLicense(licenseString);
|
||||
PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
|
||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
|
||||
// get license
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses(), notNullValue());
|
||||
assertThat(getLicenseResponse.licenses().size(), equalTo(1));
|
||||
|
||||
|
@ -97,7 +100,7 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
.validate()
|
||||
.build();
|
||||
|
||||
PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(client().admin().cluster());
|
||||
PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE);
|
||||
builder.setLicense(Collections.singletonList(tamperedLicense));
|
||||
|
||||
// try to put license (should be invalid)
|
||||
|
@ -105,7 +108,7 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.INVALID));
|
||||
|
||||
// try to get invalid license
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses().size(), equalTo(0));
|
||||
}
|
||||
|
||||
|
@ -114,7 +117,7 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
License expiredLicense = generateSignedLicense("feature", dateMath("now-10d/d", System.currentTimeMillis()), TimeValue.timeValueMinutes(2));
|
||||
License signedLicense = generateSignedLicense("feature", TimeValue.timeValueMinutes(2));
|
||||
|
||||
PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(client().admin().cluster());
|
||||
PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE);
|
||||
builder.setLicense(Arrays.asList(signedLicense, expiredLicense));
|
||||
|
||||
// put license should return valid (as there is one valid license)
|
||||
|
@ -122,7 +125,7 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
|
||||
// get license should not return the expired license
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses().size(), equalTo(1));
|
||||
|
||||
TestUtils.isSame(getLicenseResponse.licenses().get(0), signedLicense);
|
||||
|
@ -135,14 +138,14 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
List<License> actualLicenses = Arrays.asList(longerSignedLicense, shortedSignedLicense);
|
||||
|
||||
// put license
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster())
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE)
|
||||
.setLicense(actualLicenses);
|
||||
PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
|
||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
|
||||
// get should return only one license (with longer expiry date)
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses(), notNullValue());
|
||||
assertThat(getLicenseResponse.licenses().size(), equalTo(1));
|
||||
|
||||
|
@ -157,14 +160,14 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
List<License> actualLicenses = Arrays.asList(marvelLicense, shieldLicense);
|
||||
|
||||
// put license
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster())
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE)
|
||||
.setLicense(actualLicenses);
|
||||
PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
|
||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
|
||||
// get should return both the licenses
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses(), notNullValue());
|
||||
|
||||
// check license
|
||||
|
@ -179,14 +182,14 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
List<License> actualLicenses = Arrays.asList(marvelLicense, shortedSignedLicense, longerSignedLicense);
|
||||
|
||||
// put license
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster())
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE)
|
||||
.setLicense(actualLicenses);
|
||||
PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
|
||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
|
||||
// get should return both the licenses
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses(), notNullValue());
|
||||
assertThat(getLicenseResponse.licenses().size(), equalTo(2));
|
||||
|
||||
|
@ -201,25 +204,25 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
List<License> actualLicenses = Arrays.asList(marvelLicense, shieldLicense);
|
||||
|
||||
// put two licenses
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster())
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE)
|
||||
.setLicense(actualLicenses);
|
||||
PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
|
||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
|
||||
// get and check licenses
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses(), notNullValue());
|
||||
assertThat(getLicenseResponse.licenses().size(), equalTo(2));
|
||||
|
||||
// delete all licenses
|
||||
DeleteLicenseRequestBuilder deleteLicenseRequestBuilder = new DeleteLicenseRequestBuilder(client().admin().cluster())
|
||||
DeleteLicenseRequestBuilder deleteLicenseRequestBuilder = new DeleteLicenseRequestBuilder(client().admin().cluster(), DeleteLicenseAction.INSTANCE)
|
||||
.setFeatures(Sets.newHashSet("shield", "marvel"));
|
||||
DeleteLicenseResponse deleteLicenseResponse = deleteLicenseRequestBuilder.get();
|
||||
assertThat(deleteLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
// get licenses (expected no licenses)
|
||||
getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses(), notNullValue());
|
||||
assertThat(getLicenseResponse.licenses().size(), equalTo(0));
|
||||
}
|
||||
|
@ -231,31 +234,31 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTests {
|
|||
List<License> actualLicenses = Arrays.asList(marvelLicense, shieldLicense);
|
||||
|
||||
// put two licenses
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster())
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE)
|
||||
.setLicense(actualLicenses);
|
||||
PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
|
||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
|
||||
// delete one license
|
||||
DeleteLicenseRequestBuilder deleteLicenseRequestBuilder = new DeleteLicenseRequestBuilder(client().admin().cluster())
|
||||
DeleteLicenseRequestBuilder deleteLicenseRequestBuilder = new DeleteLicenseRequestBuilder(client().admin().cluster(), DeleteLicenseAction.INSTANCE)
|
||||
.setFeatures(Sets.newHashSet("shield"));
|
||||
DeleteLicenseResponse deleteLicenseResponse = deleteLicenseRequestBuilder.get();
|
||||
assertThat(deleteLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
// check other license
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses(), notNullValue());
|
||||
assertThat(getLicenseResponse.licenses().size(), equalTo(1));
|
||||
|
||||
// delete another license
|
||||
deleteLicenseRequestBuilder = new DeleteLicenseRequestBuilder(client().admin().cluster())
|
||||
deleteLicenseRequestBuilder = new DeleteLicenseRequestBuilder(client().admin().cluster(), DeleteLicenseAction.INSTANCE)
|
||||
.setFeatures(Sets.newHashSet("marvel"));
|
||||
deleteLicenseResponse = deleteLicenseRequestBuilder.get();
|
||||
assertThat(deleteLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
// check no license
|
||||
getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).get();
|
||||
getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
|
||||
assertThat(getLicenseResponse.licenses(), notNullValue());
|
||||
assertThat(getLicenseResponse.licenses().size(), equalTo(0));
|
||||
}
|
||||
|
|
31
pom.xml
31
pom.xml
|
@ -4,6 +4,12 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch-parent</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch-license</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
@ -16,17 +22,6 @@
|
|||
</modules>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<elasticsearch.version>1.4.0</elasticsearch.version>
|
||||
<lucene.version>4.10.2</lucene.version>
|
||||
<tests.jvms>auto</tests.jvms>
|
||||
<tests.shuffle>true</tests.shuffle>
|
||||
<tests.output>onerror</tests.output>
|
||||
<tests.bwc.path>${project.basedir}/backwards</tests.bwc.path>
|
||||
<es.logger.level>INFO</es.logger.level>
|
||||
<tests.heap.size>512m</tests.heap.size>
|
||||
<tests.topn>5</tests.topn>
|
||||
<execution.hint.file>.local-${project.version}-execution-hints.log</execution.hint.file>
|
||||
<license.basedir combine.self="override">${project.basedir}</license.basedir>
|
||||
</properties>
|
||||
|
||||
|
@ -36,13 +31,11 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.lucene</groupId>
|
||||
<artifactId>lucene-test-framework</artifactId>
|
||||
<version>${lucene.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
<scope>test</scope>
|
||||
<type>test-jar</type>
|
||||
</dependency>
|
||||
|
@ -61,13 +54,11 @@
|
|||
<dependency>
|
||||
<groupId>com.carrotsearch.randomizedtesting</groupId>
|
||||
<artifactId>randomizedtesting-runner</artifactId>
|
||||
<version>2.1.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -75,7 +66,7 @@
|
|||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
@ -85,7 +76,6 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
|
@ -107,15 +97,10 @@
|
|||
<!-- we skip surefire to work with randomized testing above -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.16</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>de.thetaphi</groupId>
|
||||
<artifactId>forbiddenapis</artifactId>
|
||||
<version>1.6.1</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
|
@ -200,7 +185,6 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>1.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-versions</id>
|
||||
|
@ -278,7 +262,6 @@
|
|||
<plugin>
|
||||
<groupId>com.carrotsearch.randomizedtesting</groupId>
|
||||
<artifactId>junit4-maven-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<configuration>
|
||||
<argLine>${tests.jvm.argline}</argLine>
|
||||
</configuration>
|
||||
|
|
Loading…
Reference in New Issue