Removes version 2.x constants from Version (elastic/x-pack-elasticsearch#1022)

Original commit: elastic/x-pack-elasticsearch@39ef909aec
This commit is contained in:
Colin Goodheart-Smithe 2017-04-11 08:30:59 +01:00 committed by GitHub
parent 8840042751
commit 29c64d83e1
9 changed files with 53 additions and 79 deletions

View File

@ -5,17 +5,6 @@
*/
package org.elasticsearch.xpack.security.support;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier;
@ -46,6 +35,16 @@ import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.xpack.security.InternalClient;
import org.elasticsearch.xpack.template.TemplateUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import static org.elasticsearch.common.xcontent.XContentHelper.convertToMap;
/**
@ -269,8 +268,7 @@ public class IndexLifecycleManager extends AbstractComponent {
Map<String, Object> meta =
(Map<String, Object>) mappingMetaData.sourceAsMap().get("_meta");
if (meta == null) {
// something pre-5.0, but we don't know what. Use 2.3.0 as a placeholder for "old"
return Version.V_2_3_0;
throw new IllegalStateException("Cannot read security-version string");
}
return Version.fromString((String) meta.get(SECURITY_VERSION_STRING));
} catch (IOException e) {

View File

@ -70,11 +70,6 @@ import static org.hamcrest.Matchers.hasSize;
**/
public class OldSecurityIndexBackwardsCompatibilityTests extends AbstractOldXPackIndicesBackwardsCompatibilityTestCase {
@Override
protected boolean shouldTestVersion(Version version) {
return version.onOrAfter(Version.V_2_3_0); // native realm only supported from 2.3.0 on
}
protected void checkVersion(Version version) throws Exception {
// wait for service to start
SecurityClient securityClient = new SecurityClient(client());

View File

@ -138,11 +138,11 @@ public class XPackExtensionInfoTests extends ESTestCase {
"description", "fake desc",
"name", "my_extension",
"version", "1.0",
"xpack.version", Version.V_2_0_0.toString());
"xpack.version", Version.V_5_0_0.toString());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
XPackExtensionInfo.readFromProperties(extensionDir);
});
assertTrue(e.getMessage().contains("Was designed for version [2.0.0]"));
assertTrue(e.getMessage().contains("Was designed for version [5.0.0]"));
}
public void testReadFromPropertiesJvmMissingClassname() throws Exception {

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.monitoring;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.AbstractOldXPackIndicesBackwardsCompatibilityTestCase;
import org.elasticsearch.Version;
@ -42,7 +43,6 @@ import java.util.concurrent.TimeUnit;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
@ -127,22 +127,6 @@ public class OldMonitoringIndicesBackwardsCompatibilityTests extends AbstractOld
assertThat(clusterHealth.getIndices().get(expectedIndex).getActivePrimaryShards(), equalTo(numShards.numPrimaries));
});
if (version.before(Version.V_2_3_0)) {
/* We can't do anything with indexes created before 2.3 so we just assert that we didn't delete them or do
anything otherwise crazy. */
SearchResponse response = client().prepareSearch(".marvel-es-data").get();
// 2.0.x didn't index the nodes info
long expectedEsData = version.before(Version.V_2_1_0) ? 1 : 2;
assertHitCount(response, expectedEsData);
response = client().prepareSearch(".marvel-es-*").get();
assertThat(response.getHits().getTotalHits(), greaterThanOrEqualTo(20L));
return;
}
/* Indexes created from 2.3 onwards get aliased to the place they'd be if they were created in 5.0 so queries should just work.
* Monitoring doesn't really have a Java API so we can't test that, but we can test that we write the data we expected to
* write. */
SearchResponse firstIndexStats =
search(indexPattern, IndexStatsMonitoringDoc.TYPE, greaterThanOrEqualTo(10L));
@ -295,9 +279,6 @@ public class OldMonitoringIndicesBackwardsCompatibilityTests extends AbstractOld
}
private void checkSourceNode(final Version version, Map<String, Object> element) {
if (version.onOrAfter(Version.V_2_3_0)) {
// The source_node field has been added in v2.3.0
assertThat(element, hasKey("source_node"));
}
}
}

View File

@ -25,7 +25,7 @@ public class MonitoringDocTests extends ESTestCase {
String nodeId = randomAlphaOfLength(5);
TransportAddress address = buildNewFakeTransportAddress();
Version version = randomFrom(Version.V_2_4_1, Version.V_5_0_1, Version.CURRENT);
Version version = randomFrom(Version.V_5_0_1, Version.V_5_3_0_UNRELEASED, Version.CURRENT);
String name = randomBoolean() ? randomAlphaOfLength(5) : "";
Map<String, String> attributes = new HashMap<>();

View File

@ -47,7 +47,7 @@ public class ClusterInfoResolverTests extends MonitoringIndexNameResolverTestCas
Math.abs(randomLong()),
new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
randomAlphaOfLength(5),
randomFrom(Version.V_2_0_0, Version.CURRENT).toString(),
randomFrom(Version.V_5_0_0, Version.CURRENT).toString(),
licenseBuilder.build(),
Collections.singletonList(new MonitoringFeatureSet.Usage(randomBoolean(), randomBoolean(), emptyMap())),
new ClusterStatsResponse(

View File

@ -5,11 +5,6 @@
*/
package org.elasticsearch.xpack.security;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.Action;
@ -49,6 +44,11 @@ import org.junit.After;
import org.junit.Before;
import org.mockito.Mockito;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
import static org.elasticsearch.xpack.security.SecurityLifecycleService.SECURITY_INDEX_NAME;
import static org.elasticsearch.xpack.security.SecurityLifecycleService.SECURITY_TEMPLATE_NAME;
import static org.elasticsearch.xpack.security.SecurityLifecycleService.securityIndexMappingAndTemplateSufficientToRead;
@ -312,13 +312,13 @@ public class SecurityLifecycleServiceTests extends ESTestCase {
assertFalse(securityIndex.checkMappingVersion(Version.V_5_0_0::after));
}
public void testMissingVersionMappingIsIdentifiedAsNotUpToDate() throws IOException {
public void testMissingVersionMappingThrowsError() throws IOException {
String templateString = "/missing-version-" + SECURITY_TEMPLATE_NAME + ".json";
ClusterState.Builder clusterStateBuilder = createClusterStateWithMapping(templateString);
final ClusterState clusterState = clusterStateBuilder.build();
assertFalse(securityIndexMappingAndTemplateUpToDate(clusterState, logger));
assertFalse(securityIndexMappingAndTemplateSufficientToRead(clusterState, logger));
checkMappingUpdateWorkCorrectly(clusterStateBuilder, Version.V_2_3_0);
IllegalStateException exception = expectThrows(IllegalStateException.class,
() -> securityIndexMappingAndTemplateUpToDate(clusterState, logger));
assertEquals(exception.getMessage(), "Cannot read security-version string");
}
public void testMissingIndexIsIdentifiedAsUpToDate() throws IOException {

View File

@ -12,6 +12,7 @@ import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.SecurityLifecycleService;
import org.elasticsearch.xpack.security.authc.esnative.NativeUsersStore.ReservedUserInfo;
@ -24,7 +25,6 @@ import org.elasticsearch.xpack.security.user.ElasticUser;
import org.elasticsearch.xpack.security.user.KibanaUser;
import org.elasticsearch.xpack.security.user.LogstashSystemUser;
import org.elasticsearch.xpack.security.user.User;
import org.elasticsearch.test.ESTestCase;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
@ -356,7 +356,6 @@ public class ReservedRealmTests extends ESTestCase {
}
private void verifyVersionPredicate(String principal, Predicate<Version> versionPredicate) {
assertThat(versionPredicate.test(Version.V_2_4_3), is(false));
assertThat(versionPredicate.test(Version.V_5_0_0_rc1), is(false));
switch (principal) {
case LogstashSystemUser.NAME:

View File

@ -94,9 +94,11 @@ public class OldWatcherIndicesBackwardsCompatibilityTests extends AbstractOldXPa
indexPayload = (Map<?, ?>) actions.get("index_payload");
assertEquals(timeout, indexPayload.get("throttle_period_in_millis"));
if (version.onOrAfter(Version.V_2_3_0)) {
/* Fetch a watch with a funny timeout to verify loading fractional time values. This watch is only built in >= 2.3 because
* email attachments aren't supported before that. */
/*
* Fetch a watch with a funny timeout to verify loading fractional time
* values. This watch is only built in >= 2.3 because email attachments
* aren't supported before that.
*/
bwcWatch = watcherClient.prepareGetWatch("bwc_funny_timeout").get();
assertTrue(bwcWatch.isFound());
assertNotNull(bwcWatch.getSource());
@ -118,7 +120,6 @@ public class OldWatcherIndicesBackwardsCompatibilityTests extends AbstractOldXPa
assertThat(basic, hasEntry("username", "Aladdin"));
// password doesn't come back because it is hidden
assertThat(basic, not(hasKey("password")));
}
String watchHistoryPattern = version.onOrAfter(Version.V_5_0_0_alpha1) ? ".watcher-history*" : ".watch_history*";
SearchResponse history = client().prepareSearch(watchHistoryPattern).get();