Fix compile after removal of apache commons and refactoring of plugin api

Original commit: elastic/x-pack-elasticsearch@5171192d16
This commit is contained in:
Ryan Ernst 2015-08-18 14:43:04 -07:00
parent 9dc9a1cce7
commit 2b5cb6b9f2
18 changed files with 100 additions and 68 deletions

View File

@ -19,12 +19,13 @@ import org.elasticsearch.marvel.agent.exporter.HttpESExporter;
import org.elasticsearch.marvel.agent.settings.MarvelSetting;
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
import org.elasticsearch.marvel.license.LicenseService;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.tribe.TribeService;
import java.util.Collection;
import java.util.Collections;
public class MarvelPlugin extends AbstractPlugin {
public class MarvelPlugin extends Plugin {
private static final ESLogger logger = Loggers.getLogger(MarvelPlugin.class);
@ -52,15 +53,15 @@ public class MarvelPlugin extends AbstractPlugin {
}
@Override
public Collection<Class<? extends Module>> modules() {
public Collection<Module> nodeModules() {
if (!enabled) {
return ImmutableList.of();
return Collections.emptyList();
}
return ImmutableList.<Class<? extends Module>>of(MarvelModule.class);
return Collections.<Module>singletonList(new MarvelModule());
}
@Override
public Collection<Class<? extends LifecycleComponent>> services() {
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
if (!enabled) {
return ImmutableList.of();
}

View File

@ -26,7 +26,7 @@ public class MarvelPluginClientTests extends ESTestCase {
MarvelPlugin plugin = new MarvelPlugin(settings);
assertThat(plugin.isEnabled(), is(false));
Collection<Class<? extends Module>> modules = plugin.modules();
Collection<Module> modules = plugin.nodeModules();
assertThat(modules.size(), is(0));
}
@ -38,7 +38,7 @@ public class MarvelPluginClientTests extends ESTestCase {
.build();
MarvelPlugin plugin = new MarvelPlugin(settings);
assertThat(plugin.isEnabled(), is(true));
Collection<Class<? extends Module>> modules = plugin.modules();
Collection<Module> modules = plugin.nodeModules();
assertThat(modules.size(), is(1));
}

View File

@ -18,13 +18,14 @@ import org.elasticsearch.license.plugin.core.LicensesClientService;
import org.elasticsearch.license.plugin.core.LicensesService;
import org.elasticsearch.marvel.MarvelPlugin;
import org.elasticsearch.marvel.mode.Mode;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
@ -71,7 +72,7 @@ public class LicenseIntegrationTests extends ESIntegTestCase {
}
}
public static class MockLicensePlugin extends AbstractPlugin {
public static class MockLicensePlugin extends Plugin {
public static final String NAME = "internal-test-licensing";
@ -86,8 +87,8 @@ public class LicenseIntegrationTests extends ESIntegTestCase {
}
@Override
public Collection<Class<? extends Module>> modules() {
return ImmutableSet.<Class<? extends Module>>of(InternalLicenseModule.class);
public Collection<Module> nodeModules() {
return Collections.<Module>singletonList(new InternalLicenseModule());
}
}

View File

@ -173,11 +173,6 @@
<artifactId>t-digest</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>

View File

@ -14,7 +14,7 @@ import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.shield.authc.Realms;
import org.elasticsearch.shield.authc.support.SecuredString;
import org.elasticsearch.shield.authc.support.UsernamePasswordToken;
@ -25,12 +25,13 @@ import org.elasticsearch.shield.transport.filter.IPFilter;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
/**
*
*/
public class ShieldPlugin extends AbstractPlugin {
public class ShieldPlugin extends Plugin {
public static final String NAME = "shield";
@ -57,14 +58,14 @@ public class ShieldPlugin extends AbstractPlugin {
}
@Override
public Collection<Class<? extends Module>> modules() {
public Collection<Module> nodeModules() {
return enabled ?
ImmutableList.<Class<? extends Module>>of(ShieldModule.class) :
ImmutableList.<Class<? extends Module>>of(ShieldDisabledModule.class);
Collections.<Module>singletonList(new ShieldModule(settings)) :
Collections.<Module>singletonList(new ShieldDisabledModule(settings));
}
@Override
public Collection<Class<? extends LifecycleComponent>> services() {
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
ImmutableList.Builder<Class<? extends LifecycleComponent>> builder = ImmutableList.builder();
if (enabled && !clientMode) {
builder.add(LicenseService.class).add(InternalCryptoService.class).add(FileRolesStore.class).add(Realms.class).add(IPFilter.class);

View File

@ -98,7 +98,7 @@ public class SystemKeyTool extends CliTool {
return ExitStatus.IO_ERROR;
}
boolean supportsPosixPermissions = Files.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class);
boolean supportsPosixPermissions = Environment.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class);
if (supportsPosixPermissions) {
try {
Files.setPosixFilePermissions(path, PERMISSION_OWNER_READ_WRITE);

View File

@ -6,6 +6,7 @@
package org.elasticsearch.shield.support;
import com.google.common.base.Charsets;
import org.elasticsearch.env.Environment;
import java.io.IOException;
import java.io.Writer;
@ -48,7 +49,7 @@ public class ShieldFiles {
writer.close();
// get original permissions
if (Files.exists(path)) {
boolean supportsPosixAttributes = Files.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class);
boolean supportsPosixAttributes = Environment.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class);
if (supportsPosixAttributes) {
setPosixAttributesOnTempFile(path, tempFile);
}

View File

@ -21,7 +21,6 @@ import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.core.License;
import org.elasticsearch.license.plugin.core.LicensesClientService;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.shield.license.LicenseService;
@ -31,6 +30,7 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@ -181,7 +181,7 @@ public class LicensingTests extends ShieldIntegTestCase {
}
}
public static class InternalLicensePlugin extends AbstractPlugin {
public static class InternalLicensePlugin extends Plugin {
public static final String NAME = "internal-licensing";
@ -196,8 +196,8 @@ public class LicensingTests extends ShieldIntegTestCase {
}
@Override
public Collection<Class<? extends Module>> modules() {
return ImmutableSet.<Class<? extends Module>>of(InternalLicenseModule.class);
public Collection<Module> nodeModules() {
return Collections.<Module>singletonList(new InternalLicenseModule());
}
}

View File

@ -22,7 +22,12 @@ import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;
import static org.elasticsearch.shield.crypto.tool.SystemKeyTool.Generate;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -106,7 +111,7 @@ public class SystemKeyToolTests extends CliToolTestCase {
Path path = shieldConfig.resolve("system_key");
// no posix file permissions, nothing to test, done here
boolean supportsPosixPermissions = Files.getFileStore(shieldConfig).supportsFileAttributeView(PosixFileAttributeView.class);
boolean supportsPosixPermissions = Environment.getFileStore(shieldConfig).supportsFileAttributeView(PosixFileAttributeView.class);
assumeTrue("Ignoring because posix file attributes are not supported", supportsPosixPermissions);
when(env.configFile()).thenReturn(config);

View File

@ -9,6 +9,7 @@ import com.google.common.base.Charsets;
import com.google.common.collect.Sets;
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ESTestCase;
import org.junit.Test;
@ -21,9 +22,15 @@ import java.nio.file.attribute.PosixFilePermission;
import java.util.Locale;
import java.util.Set;
import static java.nio.file.attribute.PosixFilePermission.*;
import static java.nio.file.attribute.PosixFilePermission.GROUP_EXECUTE;
import static java.nio.file.attribute.PosixFilePermission.OTHERS_EXECUTE;
import static java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE;
import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
import static org.elasticsearch.shield.support.ShieldFiles.openAtomicMoveWriter;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
public class ShieldFilesTests extends ESTestCase {
@ -32,7 +39,7 @@ public class ShieldFilesTests extends ESTestCase {
Path path = createTempFile();
// no posix file permissions, nothing to test, done here
boolean supportsPosixPermissions = Files.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class);
boolean supportsPosixPermissions = Environment.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class);
assumeTrue("Ignoring because posix file attributes are not supported", supportsPosixPermissions);
Files.write(path, "foo".getBytes(Charsets.UTF_8));

View File

@ -10,8 +10,6 @@ import org.junit.Test;
import java.util.Arrays;
import static org.apache.commons.lang3.ArrayUtils.add;
import static org.apache.commons.lang3.ArrayUtils.addAll;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
@ -28,15 +26,29 @@ public class ValidationTests extends ESTestCase {
private static final char[] numbers = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
private static final char[] allowedFirstChars = add(alphabet, '_');
private static final char[] allowedFirstChars = concat(alphabet, new char[]{'_'});
private static final char[] allowedSubsequent = addAll(addAll(alphabet, numbers), new char[] { '_', '@', '-', '$', '.' });
private static final char[] allowedSubsequent = concat(alphabet, numbers, new char[]{'_', '@', '-', '$', '.'});
static {
Arrays.sort(allowedFirstChars);
Arrays.sort(allowedSubsequent);
}
static char[] concat(char[]... arrays) {
int length = 0;
for (char[] array : arrays) {
length += array.length;
}
char[] newArray = new char[length];
int i = 0;
for (char[] array : arrays) {
System.arraycopy(array, 0, newArray, i, array.length);
i += array.length;
}
return newArray;
}
@Test
public void testESUsers_validateUsername() throws Exception {
int length = randomIntBetween(1, 30);
@ -102,7 +114,7 @@ public class ValidationTests extends ESTestCase {
for (int i = 0; i < subsequent.length; i++) {
subsequent[i] = allowedSubsequent[randomIntBetween(0, allowedSubsequent.length - 1)];
}
return addAll(new char[] { first }, subsequent);
return concat(new char[]{first}, subsequent);
}
private static char[] generateInvalidName(int length) {
@ -122,7 +134,7 @@ public class ValidationTests extends ESTestCase {
for (int i = 0; i < subsequent.length; i++) {
subsequent[i] = allowedSubsequent[randomIntBetween(0, allowedSubsequent.length - 1)];
}
return addAll(new char[] { first }, subsequent);
return concat(new char[]{first}, subsequent);
}
// invalid name due to charaters not allowed within the name itself
@ -139,7 +151,7 @@ public class ValidationTests extends ESTestCase {
}
subsequent[i] = c;
}
return addAll(new char[] { first }, subsequent);
return concat(new char[]{first}, subsequent);
}

View File

@ -14,7 +14,7 @@ import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.shield.action.ShieldActionMapper;
import org.elasticsearch.shield.authc.AuthenticationService;
import org.elasticsearch.shield.authz.AuthorizationService;
@ -49,7 +49,7 @@ public class TransportFilterTests extends ESIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.settingsBuilder()
.put("plugins.load_classpath_plugins", false)
.putArray("plugin.types", InternalPlugin.class.getName(), InternalPluginServerTransportService.Plugin.class.getName())
.putArray("plugin.types", InternalPlugin.class.getName(), InternalPluginServerTransportService.TestPlugin.class.getName())
.put("node.mode", "network")
.build();
}
@ -87,7 +87,7 @@ public class TransportFilterTests extends ESIntegTestCase {
inOrder.verify(sourceServerFilter).inbound(eq("_action"), eq(new Request("trgt_to_src")), isA(NettyTransportChannel.class));
}
public static class InternalPlugin extends AbstractPlugin {
public static class InternalPlugin extends Plugin {
@Override
public String name() {
@ -100,8 +100,8 @@ public class TransportFilterTests extends ESIntegTestCase {
}
@Override
public Collection<Class<? extends Module>> modules() {
return ImmutableSet.<Class<? extends Module>>of(TestTransportFilterModule.class);
public Collection<Module> nodeModules() {
return Collections.<Module>singletonList(new TestTransportFilterModule());
}
}
@ -264,7 +264,7 @@ public class TransportFilterTests extends ESIntegTestCase {
// Sub class the Shield transport to always inject a mock for testing
static class InternalPluginServerTransportService extends ShieldServerTransportService {
public static class Plugin extends AbstractPlugin {
public static class TestPlugin extends Plugin {
@Override
public String name() {
return "mock-transport-service";

View File

@ -13,7 +13,7 @@ import org.elasticsearch.cluster.settings.Validator;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.watcher.actions.email.service.InternalEmailService;
import org.elasticsearch.watcher.history.HistoryModule;
@ -25,10 +25,11 @@ import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation;
import java.util.Collection;
import java.util.Collections;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
public class WatcherPlugin extends AbstractPlugin {
public class WatcherPlugin extends Plugin {
public static final String NAME = "watcher";
public static final String ENABLED_SETTING = NAME + ".enabled";
@ -37,8 +38,8 @@ public class WatcherPlugin extends AbstractPlugin {
MetaData.registerPrototype(WatcherMetaData.TYPE, WatcherMetaData.PROTO);
}
private final Settings settings;
private final boolean transportClient;
protected final Settings settings;
protected final boolean transportClient;
protected final boolean enabled;
public WatcherPlugin(Settings settings) {
@ -56,18 +57,18 @@ public class WatcherPlugin extends AbstractPlugin {
}
@Override
public Collection<Class<? extends Module>> modules() {
public Collection<Module> nodeModules() {
if (!enabled) {
return ImmutableList.of();
}
return transportClient ?
ImmutableList.<Class<? extends Module>>of(TransportClientWatcherModule.class) :
ImmutableList.<Class<? extends Module>>of(WatcherModule.class);
Collections.<Module>singletonList(new TransportClientWatcherModule()) :
Collections.<Module>singletonList(new WatcherModule(settings));
}
@Override
public Collection<Class<? extends LifecycleComponent>> services() {
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
if (!enabled || transportClient) {
return ImmutableList.of();
}

View File

@ -6,7 +6,6 @@
package org.elasticsearch.watcher.watch;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.ArrayUtils;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
@ -162,7 +161,14 @@ public class WatchStatus implements ToXContent, Streamable {
*/
boolean onAck(DateTime timestamp, String... actionIds) {
boolean changed = false;
if (ArrayUtils.contains(actionIds, Watch.ALL_ACTIONS_ID)) {
boolean containsAll = false;
for (String actionId : actionIds) {
if (actionId.equals(Watch.ALL_ACTIONS_ID)) {
containsAll = true;
break;
}
}
if (containsAll) {
for (ActionStatus status : actions.values()) {
changed |= status.onAck(timestamp);
}

View File

@ -14,7 +14,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.support.xcontent.XContentSource;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
@ -113,7 +113,7 @@ public class ActionErrorIntegrationTests extends AbstractWatcherIntegrationTests
public static class ErrorActionPlugin extends AbstractPlugin {
public static class ErrorActionPlugin extends Plugin {
public ErrorActionPlugin() {
}

View File

@ -17,7 +17,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.core.License;
import org.elasticsearch.license.plugin.core.LicensesClientService;
import org.elasticsearch.license.plugin.core.LicensesService;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.watcher.actions.ActionStatus;
@ -30,6 +29,7 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.elasticsearch.index.query.QueryBuilders.*;
@ -278,7 +278,7 @@ public class LicenseIntegrationTests extends AbstractWatcherIntegrationTests {
}
}
public static class MockLicensePlugin extends AbstractPlugin {
public static class MockLicensePlugin extends Plugin {
public static final String NAME = "internal-test-licensing";
@ -293,8 +293,8 @@ public class LicenseIntegrationTests extends AbstractWatcherIntegrationTests {
}
@Override
public Collection<Class<? extends Module>> modules() {
return ImmutableSet.<Class<? extends Module>>of(InternalLicenseModule.class);
public Collection<Module> nodeModules() {
return Collections.<Module>singletonList(new InternalLicenseModule());
}
}

View File

@ -24,6 +24,7 @@ import org.elasticsearch.watcher.trigger.manual.ManualTriggerEngine;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
@ -40,11 +41,11 @@ public class TimeWarpedWatcherPlugin extends WatcherPlugin {
}
@Override
public Collection<Class<? extends Module>> modules() {
public Collection<Module> nodeModules() {
if (!enabled) {
return super.modules();
return super.nodeModules();
}
return ImmutableList.<Class<? extends Module>>of(WatcherModule.class);
return Collections.<Module>singletonList(new WatcherModule(settings));
}
/**

View File

@ -25,6 +25,7 @@ import org.elasticsearch.watcher.trigger.TriggerModule;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.elasticsearch.watcher.actions.ActionBuilders.indexAction;
@ -211,8 +212,8 @@ public class WatcherExecutorServiceBenchmark {
}
@Override
public Collection<Class<? extends Module>> modules() {
return ImmutableList.<Class<? extends Module>>of(WatcherModule.class);
public Collection<Module> nodeModules() {
return Collections.<Module>singletonList(new WatcherModule(settings));
}
public static class WatcherModule extends org.elasticsearch.watcher.WatcherModule {