Removed generics from LifecycleComponent

This is the xplugins side of elastic/elasticsearch#19225

Original commit: elastic/x-pack-elasticsearch@845a945552
This commit is contained in:
Ryan Ernst 2016-07-01 16:23:13 -07:00
parent 09c8418a50
commit 9f52066bdb
38 changed files with 174 additions and 113 deletions

View File

@ -14,7 +14,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
/**
* A supporting base class for injectable Licensee components.
*/
public abstract class AbstractLicenseeComponent<T extends AbstractLicenseeComponent<T>> extends AbstractLifecycleComponent<T>
public abstract class AbstractLicenseeComponent<T extends AbstractLicenseeComponent<T>> extends AbstractLifecycleComponent
implements Licensee {
private final String id;

View File

@ -79,7 +79,7 @@ import java.util.concurrent.atomic.AtomicReference;
* Registered listeners are notified using {@link #notifyAndSchedule(LicensesMetaData)}
*/
@Singleton
public class LicensesService extends AbstractLifecycleComponent<LicensesService> implements ClusterStateListener, LicensesManagerService,
public class LicensesService extends AbstractLifecycleComponent implements ClusterStateListener, LicensesManagerService,
LicenseeRegistry {
public static final String REGISTER_TRIAL_LICENSE_ACTION_NAME = "internal:plugin/license/cluster/register_trial_license";

View File

@ -21,7 +21,7 @@ import org.elasticsearch.license.plugin.core.LicensesService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
public abstract class TestPluginServiceBase extends AbstractLifecycleComponent<TestPluginServiceBase>
public abstract class TestPluginServiceBase extends AbstractLifecycleComponent
implements ClusterStateListener, Licensee {
private LicensesService licensesClientService;

View File

@ -41,7 +41,7 @@ import java.util.concurrent.locks.ReentrantLock;
* @see #stopCollection()
* @see #startCollection()
*/
public class AgentService extends AbstractLifecycleComponent<AgentService> {
public class AgentService extends AbstractLifecycleComponent {
private volatile ExportingWorker exportingWorker;

View File

@ -19,7 +19,7 @@ import org.elasticsearch.xpack.monitoring.agent.exporter.MonitoringDoc;
import java.util.Collection;
public abstract class AbstractCollector<T> extends AbstractLifecycleComponent<T> implements Collector<T> {
public abstract class AbstractCollector extends AbstractLifecycleComponent implements Collector {
private final String name;
@ -48,9 +48,9 @@ public abstract class AbstractCollector<T> extends AbstractLifecycleComponent<T>
}
@Override
public T start() {
public void start() {
logger.debug("starting collector [{}]", name());
return super.start();
super.start();
}
@Override
@ -90,9 +90,9 @@ public abstract class AbstractCollector<T> extends AbstractLifecycleComponent<T>
protected abstract Collection<MonitoringDoc> doCollect() throws Exception;
@Override
public T stop() {
public void stop() {
logger.debug("stopping collector [{}]", name());
return super.stop();
super.stop();
}
@Override

View File

@ -10,7 +10,7 @@ import org.elasticsearch.xpack.monitoring.agent.exporter.MonitoringDoc;
import java.util.Collection;
public interface Collector<T> extends LifecycleComponent<T> {
public interface Collector extends LifecycleComponent {
String name();

View File

@ -30,7 +30,7 @@ import java.util.List;
* This collector runs on the master node only and collects {@link ClusterStateMonitoringDoc} document
* at a given frequency.
*/
public class ClusterStateCollector extends AbstractCollector<ClusterStateCollector> {
public class ClusterStateCollector extends AbstractCollector {
public static final String NAME = "cluster-state-collector";

View File

@ -36,7 +36,7 @@ import java.util.List;
* document; the cluster stats are also indexed in the timestamped index in a
* "cluster_stats" document.
*/
public class ClusterStatsCollector extends AbstractCollector<ClusterStatsCollector> {
public class ClusterStatsCollector extends AbstractCollector {
public static final String NAME = "cluster-stats-collector";

View File

@ -32,7 +32,7 @@ import java.util.List;
* This collector runs on the master node only and collects a {@link IndexRecoveryMonitoringDoc} document
* for every index that has on-going shard recoveries.
*/
public class IndexRecoveryCollector extends AbstractCollector<IndexRecoveryCollector> {
public class IndexRecoveryCollector extends AbstractCollector {
public static final String NAME = "index-recovery-collector";

View File

@ -34,7 +34,7 @@ import java.util.List;
* This collector runs on the master node only and collect a {@link IndexStatsMonitoringDoc} document
* for each existing index in the cluster.
*/
public class IndexStatsCollector extends AbstractCollector<IndexStatsCollector> {
public class IndexStatsCollector extends AbstractCollector {
public static final String NAME = "index-stats-collector";

View File

@ -29,7 +29,7 @@ import java.util.Collections;
* <p>
* This collector runs on the master node only and collect one {@link IndicesStatsMonitoringDoc} document.
*/
public class IndicesStatsCollector extends AbstractCollector<IndicesStatsCollector> {
public class IndicesStatsCollector extends AbstractCollector {
public static final String NAME = "indices-stats-collector";

View File

@ -32,7 +32,7 @@ import java.util.Collections;
* This collector runs on every non-client node and collect
* a {@link NodeStatsMonitoringDoc} document for each node of the cluster.
*/
public class NodeStatsCollector extends AbstractCollector<NodeStatsCollector> {
public class NodeStatsCollector extends AbstractCollector {
public static final String NAME = "node-stats-collector";

View File

@ -30,7 +30,7 @@ import java.util.List;
* This collector runs on the master node only and collects the {@link ShardMonitoringDoc} documents
* for every index shard.
*/
public class ShardsCollector extends AbstractCollector<ShardsCollector> {
public class ShardsCollector extends AbstractCollector {
public static final String NAME = "shards-collector";

View File

@ -32,7 +32,7 @@ import static java.util.Collections.emptyMap;
/**
*
*/
public class Exporters extends AbstractLifecycleComponent<Exporters> implements Iterable<Exporter> {
public class Exporters extends AbstractLifecycleComponent implements Iterable<Exporter> {
private final Map<String, Exporter.Factory> factories;
private final ClusterService clusterService;

View File

@ -26,7 +26,7 @@ import java.util.concurrent.ScheduledFuture;
/**
* {@code CleanerService} takes care of deleting old monitoring indices.
*/
public class CleanerService extends AbstractLifecycleComponent<CleanerService> {
public class CleanerService extends AbstractLifecycleComponent {
private final MonitoringLicensee licensee;
private final ThreadPool threadPool;

View File

@ -44,7 +44,7 @@ import static org.elasticsearch.xpack.security.Security.setting;
/**
*
*/
public class LoggingAuditTrail extends AbstractLifecycleComponent<LoggingAuditTrail> implements AuditTrail {
public class LoggingAuditTrail extends AbstractLifecycleComponent implements AuditTrail {
public static final String NAME = "logfile";
public static final Setting<Boolean> HOST_ADDRESS_SETTING =

View File

@ -32,7 +32,7 @@ import static org.elasticsearch.xpack.security.Security.setting;
/**
* Serves as a realms registry (also responsible for ordering the realms appropriately)
*/
public class Realms extends AbstractLifecycleComponent<Realms> implements Iterable<Realm> {
public class Realms extends AbstractLifecycleComponent implements Iterable<Realm> {
public static final Setting<Settings> REALMS_GROUPS_SETTINGS = Setting.groupSetting(setting("authc.realms."), Property.NodeScope);

View File

@ -49,7 +49,7 @@ import static org.elasticsearch.xpack.security.Security.setting;
/**
*
*/
public class FileRolesStore extends AbstractLifecycleComponent<RolesStore> implements RolesStore {
public class FileRolesStore extends AbstractLifecycleComponent implements RolesStore {
public static final Setting<String> ROLES_FILE_SETTING =
Setting.simpleString(setting("authz.store.files.roles"), Property.NodeScope);

View File

@ -51,7 +51,7 @@ import static org.elasticsearch.xpack.security.Security.setting;
/**
*
*/
public class InternalCryptoService extends AbstractLifecycleComponent<InternalCryptoService> implements CryptoService {
public class InternalCryptoService extends AbstractLifecycleComponent implements CryptoService {
public static final String KEY_ALGO = "HmacSHA512";
public static final int KEY_SIZE = 1024;

View File

@ -124,7 +124,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
TransportMessage message = randomBoolean() ? new MockMessage(threadContext) : new MockIndicesRequest(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);
auditTrail.anonymousAccessDenied("_action", message);
@ -164,7 +165,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
auditTrail.anonymousAccessDenied(request);
switch (level) {
case ERROR:
@ -187,7 +189,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
TransportMessage message = randomBoolean() ? new MockMessage(threadContext) : new MockIndicesRequest(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);;
auditTrail.authenticationFailed(new MockToken(), "_action", message);
@ -220,7 +223,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
TransportMessage message = randomBoolean() ? new MockMessage(threadContext) : new MockIndicesRequest(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);;
auditTrail.authenticationFailed("_action", message);
@ -258,7 +262,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
when(request.uri()).thenReturn("_uri");
String expectedMessage = prepareRestContent(request);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
auditTrail.authenticationFailed(new MockToken(), request);
switch (level) {
case ERROR:
@ -285,7 +290,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
when(request.uri()).thenReturn("_uri");
String expectedMessage = prepareRestContent(request);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
auditTrail.authenticationFailed(request);
switch (level) {
case ERROR:
@ -306,7 +312,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
TransportMessage message = randomBoolean() ? new MockMessage(threadContext) : new MockIndicesRequest(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);;
auditTrail.authenticationFailed("_realm", new MockToken(), "_action", message);
@ -338,7 +345,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
when(request.uri()).thenReturn("_uri");
String expectedMessage = prepareRestContent(request);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
auditTrail.authenticationFailed("_realm", new MockToken(), request);
switch (level) {
case ERROR:
@ -359,7 +367,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
TransportMessage message = randomBoolean() ? new MockMessage(threadContext) : new MockIndicesRequest(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);
boolean runAs = randomBoolean();
@ -403,7 +412,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
TransportMessage message = randomBoolean() ? new MockMessage(threadContext) : new MockIndicesRequest(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);
auditTrail.accessGranted(SystemUser.INSTANCE, "internal:_action", message);
@ -431,7 +441,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
TransportMessage message = randomBoolean() ? new MockMessage(threadContext) : new MockIndicesRequest(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);
boolean runAs = randomBoolean();
@ -475,7 +486,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
TransportMessage message = randomBoolean() ? new MockMessage(threadContext) : new MockIndicesRequest(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);
boolean runAs = randomBoolean();
@ -523,7 +535,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
auditTrail.tamperedRequest(request);
switch (level) {
case ERROR:
@ -547,7 +560,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
TransportMessage message = randomBoolean() ? new MockMessage(threadContext) : new MockIndicesRequest(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
auditTrail.tamperedRequest(action, message);
switch (level) {
case ERROR:
@ -588,7 +602,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
TransportMessage message = randomBoolean() ? new MockMessage(threadContext) : new MockIndicesRequest(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
auditTrail.tamperedRequest(user, action, message);
switch (level) {
case ERROR:
@ -619,7 +634,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
InetAddress inetAddress = InetAddress.getLoopbackAddress();
SecurityIpFilterRule rule = new SecurityIpFilterRule(false, "_all");
auditTrail.connectionDenied(inetAddress, "default", rule);
@ -641,7 +657,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
InetAddress inetAddress = InetAddress.getLoopbackAddress();
SecurityIpFilterRule rule = IPFilter.DEFAULT_PROFILE_ACCEPT_ALL;
auditTrail.connectionGranted(inetAddress, "default", rule);
@ -664,7 +681,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
TransportMessage message = new MockMessage(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);
User user = new User("_username", new String[]{"r1"}, new User("running as", new String[] {"r2"}));
@ -690,7 +708,8 @@ public class LoggingAuditTrailTests extends ESTestCase {
for (Level level : Level.values()) {
threadContext = new ThreadContext(Settings.EMPTY);
CapturingLogger logger = new CapturingLogger(level);
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext).start();
LoggingAuditTrail auditTrail = new LoggingAuditTrail(settings, transport, logger, threadContext);
auditTrail.start();
TransportMessage message = new MockMessage(threadContext);
String origins = LoggingAuditTrail.originAttributes(message, transport, threadContext);
User user = new User("_username", new String[]{"r1"}, new User("running as", new String[] {"r2"}));

View File

@ -346,7 +346,8 @@ public class RealmsTests extends ESTestCase {
.put("xpack.security.authc.realms.realm_1.order", 0)
.build();
Environment env = new Environment(settings);
Realms realms = new Realms(settings, env, factories, securityLicenseState, reservedRealm).start();
Realms realms = new Realms(settings, env, factories, securityLicenseState, reservedRealm);
realms.start();
assertThat(realms.iterator().hasNext(), is(true));

View File

@ -68,14 +68,16 @@ public class InternalCryptoServiceTests extends ESTestCase {
public void testSigned() throws Exception {
// randomize whether to use a system key or not
Settings settings = randomBoolean() ? this.settings : Settings.EMPTY;
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
String text = randomAsciiOfLength(10);
String signed = service.sign(text);
assertThat(service.signed(signed), is(true));
}
public void testSignAndUnsign() throws Exception {
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
String text = randomAsciiOfLength(10);
String signed = service.sign(text);
assertThat(text.equals(signed), is(false));
@ -84,7 +86,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testSignAndUnsignNoKeyFile() throws Exception {
InternalCryptoService service = new InternalCryptoService(Settings.EMPTY, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(Settings.EMPTY, env, watcherService);
service.start();
final String text = randomAsciiOfLength(10);
String signed = service.sign(text);
// we always have some sort of key to sign with
@ -94,7 +97,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testTamperedSignature() throws Exception {
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
String text = randomAsciiOfLength(10);
String signed = service.sign(text);
int i = signed.indexOf("$$", 2);
@ -111,7 +115,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testTamperedSignatureOneChar() throws Exception {
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
String text = randomAsciiOfLength(10);
String signed = service.sign(text);
int i = signed.indexOf("$$", 2);
@ -130,7 +135,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testTamperedSignatureLength() throws Exception {
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
String text = randomAsciiOfLength(10);
String signed = service.sign(text);
int i = signed.indexOf("$$", 2);
@ -157,7 +163,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testEncryptionAndDecryptionChars() {
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(true));
final char[] chars = randomAsciiOfLengthBetween(0, 1000).toCharArray();
final char[] encrypted = service.encrypt(chars);
@ -169,7 +176,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testEncryptionAndDecryptionBytes() {
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(true));
final byte[] bytes = randomByteArray();
final byte[] encrypted = service.encrypt(bytes);
@ -181,7 +189,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testEncryptionAndDecryptionCharsWithoutKey() {
InternalCryptoService service = new InternalCryptoService(Settings.EMPTY, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(Settings.EMPTY, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(false));
final char[] chars = randomAsciiOfLengthBetween(0, 1000).toCharArray();
final char[] encryptedChars = service.encrypt(chars);
@ -191,7 +200,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testEncryptionAndDecryptionBytesWithoutKey() {
InternalCryptoService service = new InternalCryptoService(Settings.EMPTY, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(Settings.EMPTY, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(false));
final byte[] bytes = randomByteArray();
final byte[] encryptedBytes = service.encrypt(bytes);
@ -201,17 +211,20 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testEncryptionEnabledWithKey() {
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(true));
}
public void testEncryptionEnabledWithoutKey() {
InternalCryptoService service = new InternalCryptoService(Settings.EMPTY, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(Settings.EMPTY, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(false));
}
public void testChangingAByte() {
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(true));
// We need at least one byte to test changing a byte, otherwise output is always the same
final byte[] bytes = randomByteArray(1);
@ -231,7 +244,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testEncryptedChar() {
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(true));
assertThat(service.encrypted((char[]) null), is(false));
@ -243,7 +257,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testEncryptedByte() {
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(true));
assertThat(service.encrypted((byte[]) null), is(false));
@ -266,9 +281,11 @@ public class InternalCryptoServiceTests extends ESTestCase {
// randomize how we set the listener
InternalCryptoService service;
if (randomBoolean()) {
service = new InternalCryptoService(settings, env, watcherService, Collections.singletonList(listener)).start();
service = new InternalCryptoService(settings, env, watcherService, Collections.singletonList(listener));
service.start();
} else {
service = new InternalCryptoService(settings, env, watcherService).start();
service = new InternalCryptoService(settings, env, watcherService);
service.start();
service.register(listener);
}
@ -299,7 +316,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testReencryptValuesOnKeyChange() throws Exception {
final InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
final InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(true));
final char[] text = randomAsciiOfLength(10).toCharArray();
final char[] encrypted = service.encrypt(text);
@ -329,7 +347,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testResignValuesOnKeyChange() throws Exception {
final InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
final InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
final String text = randomAsciiOfLength(10);
final String signed = service.sign(text);
assertThat(text, not(equalTo(signed)));
@ -363,7 +382,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testReencryptValuesOnKeyDeleted() throws Exception {
final InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
final InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(true));
final char[] text = randomAsciiOfLength(10).toCharArray();
final char[] encrypted = service.encrypt(text);
@ -393,7 +413,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testAllListenersCalledWhenExceptionThrown() throws Exception {
final InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
final InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
assertThat(service.encryptionEnabled(), is(true));
final CountDownLatch latch = new CountDownLatch(3);
@ -428,7 +449,8 @@ public class InternalCryptoServiceTests extends ESTestCase {
}
public void testSigningOnKeyDeleted() throws Exception {
final InternalCryptoService service = new InternalCryptoService(settings, env, watcherService).start();
final InternalCryptoService service = new InternalCryptoService(settings, env, watcherService);
service.start();
final String text = randomAsciiOfLength(10);
final String signed = service.sign(text);
assertThat(text, not(equalTo(signed)));

View File

@ -327,7 +327,8 @@ public class SSLConfigurationTests extends ESTestCase {
ThreadPool threadPool = new TestThreadPool("reload");
try {
ResourceWatcherService resourceWatcherService =
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool).start();
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool);
resourceWatcherService.start();
KeyManager[] keyManagers = keyConfig.keyManagers(env, resourceWatcherService, listener);
assertThat(keyManagers.length, is(1));
assertThat(keyManagers[0], instanceOf(X509ExtendedKeyManager.class));
@ -390,7 +391,8 @@ public class SSLConfigurationTests extends ESTestCase {
ThreadPool threadPool = new TestThreadPool("reload pem");
try {
ResourceWatcherService resourceWatcherService =
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool).start();
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool);
resourceWatcherService.start();
KeyManager[] keyManagers = keyConfig.keyManagers(env, resourceWatcherService, listener);
assertThat(keyManagers.length, is(1));
assertThat(keyManagers[0], instanceOf(X509ExtendedKeyManager.class));
@ -466,7 +468,8 @@ public class SSLConfigurationTests extends ESTestCase {
ThreadPool threadPool = new TestThreadPool("reload");
try {
ResourceWatcherService resourceWatcherService =
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool).start();
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool);
resourceWatcherService.start();
TrustManager[] trustManagers = trustConfig.trustManagers(env, resourceWatcherService, listener);
assertThat(trustManagers.length, is(1));
assertThat(trustManagers[0], instanceOf(X509ExtendedTrustManager.class));
@ -512,7 +515,8 @@ public class SSLConfigurationTests extends ESTestCase {
ThreadPool threadPool = new TestThreadPool("reload");
try {
ResourceWatcherService resourceWatcherService =
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool).start();
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool);
resourceWatcherService.start();
TrustManager[] trustManagers = trustConfig.trustManagers(env, resourceWatcherService, listener);
assertThat(trustManagers.length, is(1));
assertThat(trustManagers[0], instanceOf(X509ExtendedTrustManager.class));
@ -560,7 +564,8 @@ public class SSLConfigurationTests extends ESTestCase {
ThreadPool threadPool = new TestThreadPool("reload");
try {
ResourceWatcherService resourceWatcherService =
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool).start();
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool);
resourceWatcherService.start();
KeyManager[] keyManagers = keyConfig.keyManagers(env, resourceWatcherService, listener);
X509ExtendedKeyManager keyManager = (X509ExtendedKeyManager) keyManagers[0];
String[] aliases = keyManager.getServerAliases("RSA", null);
@ -609,7 +614,8 @@ public class SSLConfigurationTests extends ESTestCase {
ThreadPool threadPool = new TestThreadPool("reload pem");
try {
ResourceWatcherService resourceWatcherService =
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool).start();
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool);
resourceWatcherService.start();
KeyManager[] keyManagers = keyConfig.keyManagers(env, resourceWatcherService, listener);
assertThat(keyManagers.length, is(1));
assertThat(keyManagers[0], instanceOf(X509ExtendedKeyManager.class));
@ -660,7 +666,8 @@ public class SSLConfigurationTests extends ESTestCase {
ThreadPool threadPool = new TestThreadPool("reload");
try {
ResourceWatcherService resourceWatcherService =
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool).start();
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool);
resourceWatcherService.start();
TrustManager[] trustManagers = trustConfig.trustManagers(env, resourceWatcherService, listener);
assertThat(trustManagers.length, is(1));
assertThat(trustManagers[0], instanceOf(X509ExtendedTrustManager.class));
@ -699,7 +706,8 @@ public class SSLConfigurationTests extends ESTestCase {
ThreadPool threadPool = new TestThreadPool("reload");
try {
ResourceWatcherService resourceWatcherService =
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool).start();
new ResourceWatcherService(Settings.builder().put("resource.reload.interval.high", "1s").build(), threadPool);
resourceWatcherService.start();
TrustManager[] trustManagers = trustConfig.trustManagers(env, resourceWatcherService, listener);
assertThat(trustManagers.length, is(1));
assertThat(trustManagers[0], instanceOf(X509ExtendedTrustManager.class));

View File

@ -46,7 +46,7 @@ import java.util.Map;
/**
* Client class to wrap http connections
*/
public class HttpClient extends AbstractLifecycleComponent<HttpClient> {
public class HttpClient extends AbstractLifecycleComponent {
static final String SETTINGS_SSL_PREFIX = "xpack.http.ssl.";
static final String SETTINGS_PROXY_PREFIX = "xpack.http.proxy.";

View File

@ -12,7 +12,7 @@ import javax.mail.MessagingException;
/**
*
*/
public interface EmailService extends LifecycleComponent<EmailService>{
public interface EmailService extends LifecycleComponent{
EmailSent send(Email email, Authentication auth, Profile profile) throws MessagingException;

View File

@ -19,7 +19,7 @@ import javax.mail.MessagingException;
/**
*
*/
public class InternalEmailService extends AbstractLifecycleComponent<EmailService> implements EmailService {
public class InternalEmailService extends AbstractLifecycleComponent implements EmailService {
private final SecretService secretService;
public static final Setting<Settings> EMAIL_ACCOUNT_SETTING =

View File

@ -10,7 +10,7 @@ import org.elasticsearch.common.component.LifecycleComponent;
/**
*
*/
public interface HipChatService extends LifecycleComponent<HipChatService> {
public interface HipChatService extends LifecycleComponent {
/**
* @return The default hipchat account.

View File

@ -15,7 +15,7 @@ import org.elasticsearch.xpack.common.http.HttpClient;
/**
*
*/
public class InternalHipChatService extends AbstractLifecycleComponent<HipChatService> implements HipChatService {
public class InternalHipChatService extends AbstractLifecycleComponent implements HipChatService {
private final HttpClient httpClient;
private volatile HipChatAccounts accounts;

View File

@ -15,7 +15,7 @@ import org.elasticsearch.xpack.common.http.HttpClient;
/**
*
*/
public class InternalPagerDutyService extends AbstractLifecycleComponent<PagerDutyService> implements PagerDutyService {
public class InternalPagerDutyService extends AbstractLifecycleComponent implements PagerDutyService {
public static final Setting<Settings> PAGERDUTY_ACCOUNT_SETTING =
Setting.groupSetting("xpack.notification.pagerduty.", Setting.Property.Dynamic, Setting.Property.NodeScope);

View File

@ -10,7 +10,7 @@ import org.elasticsearch.common.component.LifecycleComponent;
/**
*
*/
public interface PagerDutyService extends LifecycleComponent<PagerDutyService> {
public interface PagerDutyService extends LifecycleComponent {
PagerDutyAccount getDefaultAccount();

View File

@ -15,7 +15,7 @@ import org.elasticsearch.xpack.common.http.HttpClient;
/**
*
*/
public class InternalSlackService extends AbstractLifecycleComponent<SlackService> implements SlackService {
public class InternalSlackService extends AbstractLifecycleComponent implements SlackService {
private final HttpClient httpClient;
public static final Setting<Settings> SLACK_ACCOUNT_SETTING =

View File

@ -10,7 +10,7 @@ import org.elasticsearch.common.component.LifecycleComponent;
/**
*
*/
public interface SlackService extends LifecycleComponent<SlackService> {
public interface SlackService extends LifecycleComponent {
/**

View File

@ -60,7 +60,8 @@ public class HttpClientTests extends ESTestCase {
authRegistry = new HttpAuthRegistry(singletonMap(BasicAuth.TYPE, new BasicAuthFactory(secretService)));
webServer = startWebServer();
webPort = webServer.getPort();
httpClient = new HttpClient(Settings.EMPTY, authRegistry, environment).start();
httpClient = new HttpClient(Settings.EMPTY, authRegistry, environment);
httpClient.start();
}
@After
@ -173,15 +174,16 @@ public class HttpClientTests extends ESTestCase {
.put(HttpClient.SETTINGS_SSL_SECURITY_TRUSTSTORE_PASSWORD, "truststore-testnode-only")
.build();
}
HttpClient httpClient = new HttpClient(settings, authRegistry, environment).start();
HttpClient httpClient = new HttpClient(settings, authRegistry, environment);
httpClient.start();
// We can't use the client created above for the server since it is only a truststore
webServer.useHttps(new HttpClient(Settings.builder()
HttpClient httpClient2 = new HttpClient(Settings.builder()
.put(HttpClient.SETTINGS_SSL_KEYSTORE, getDataPath("/org/elasticsearch/xpack/security/keystore/testnode.jks"))
.put(HttpClient.SETTINGS_SSL_KEYSTORE_PASSWORD, "testnode")
.build(), authRegistry, environment)
.start()
.getSslSocketFactory(), false);
.build(), authRegistry, environment);
httpClient2.start();
webServer.useHttps(httpClient2.getSslSocketFactory(), false);
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
HttpRequest.Builder request = HttpRequest.builder("localhost", webPort)
@ -211,7 +213,8 @@ public class HttpClientTests extends ESTestCase {
.build();
}
HttpClient httpClient = new HttpClient(settings, authRegistry, environment).start();
HttpClient httpClient = new HttpClient(settings, authRegistry, environment);
httpClient.start();
webServer.useHttps(new ClientAuthRequiringSSLSocketFactory(httpClient.getSslSocketFactory()), false);
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
@ -247,7 +250,8 @@ public class HttpClientTests extends ESTestCase {
.build();
}
HttpClient httpClient = new HttpClient(settings, authRegistry, environment).start();
HttpClient httpClient = new HttpClient(settings, authRegistry, environment);
httpClient.start();
assertThat(httpClient.getSslSocketFactory(), notNullValue());
Settings.Builder badSettings = Settings.builder().put(settings);
@ -293,7 +297,8 @@ public class HttpClientTests extends ESTestCase {
@Network
public void testHttpsWithoutTruststore() throws Exception {
HttpClient httpClient = new HttpClient(Settings.EMPTY, authRegistry, environment).start();
HttpClient httpClient = new HttpClient(Settings.EMPTY, authRegistry, environment);
httpClient.start();
assertThat(httpClient.getSslSocketFactory(), nullValue());
// Known server with a valid cert from a commercial CA
@ -312,7 +317,8 @@ public class HttpClientTests extends ESTestCase {
Settings settings = Settings.builder()
.put(setting, randomBoolean())
.build();
HttpClient httpClient = new HttpClient(settings, authRegistry, environment).start();
HttpClient httpClient = new HttpClient(settings, authRegistry, environment);
httpClient.start();
assertThat(httpClient.getSslSocketFactory(), notNullValue());
// Known server with a valid cert from a commercial CA
@ -333,7 +339,8 @@ public class HttpClientTests extends ESTestCase {
.put(HttpClient.SETTINGS_PROXY_HOST, "localhost")
.put(HttpClient.SETTINGS_PROXY_PORT, proxyServer.getPort())
.build();
HttpClient httpClient = new HttpClient(settings, authRegistry, environment).start();
HttpClient httpClient = new HttpClient(settings, authRegistry, environment);
httpClient.start();
HttpRequest.Builder requestBuilder = HttpRequest.builder("localhost", webPort)
.method(HttpMethod.GET)
@ -361,7 +368,8 @@ public class HttpClientTests extends ESTestCase {
.put(HttpClient.SETTINGS_PROXY_HOST, "localhost")
.put(HttpClient.SETTINGS_PROXY_PORT, proxyServer.getPort() + 1)
.build();
HttpClient httpClient = new HttpClient(settings, authRegistry, environment).start();
HttpClient httpClient = new HttpClient(settings, authRegistry, environment);
httpClient.start();
HttpRequest.Builder requestBuilder = HttpRequest.builder("localhost", webPort)
.method(HttpMethod.GET)

View File

@ -29,7 +29,8 @@ public class HttpConnectionTimeoutTests extends ESTestCase {
@Network
public void testDefaultTimeout() throws Exception {
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
HttpClient httpClient = new HttpClient(Settings.EMPTY, mock(HttpAuthRegistry.class), environment).start();
HttpClient httpClient = new HttpClient(Settings.EMPTY, mock(HttpAuthRegistry.class), environment);
httpClient.start();
HttpRequest request = HttpRequest.builder(UNROUTABLE_IP, 12345)
.method(HttpMethod.POST)
@ -54,9 +55,9 @@ public class HttpConnectionTimeoutTests extends ESTestCase {
public void testDefaultTimeoutCustom() throws Exception {
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
HttpClient httpClient = new HttpClient(Settings.builder()
.put("xpack.http.default_connection_timeout", "5s")
.build()
, mock(HttpAuthRegistry.class), environment).start();
.put("xpack.http.default_connection_timeout", "5s").build()
, mock(HttpAuthRegistry.class), environment);
httpClient.start();
HttpRequest request = HttpRequest.builder(UNROUTABLE_IP, 12345)
.method(HttpMethod.POST)
@ -81,9 +82,9 @@ public class HttpConnectionTimeoutTests extends ESTestCase {
public void testTimeoutCustomPerRequest() throws Exception {
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
HttpClient httpClient = new HttpClient(Settings.builder()
.put("xpack.http.default_connection_timeout", "10s")
.build()
, mock(HttpAuthRegistry.class), environment).start();
.put("xpack.http.default_connection_timeout", "10s").build()
, mock(HttpAuthRegistry.class), environment);
httpClient.start();
HttpRequest request = HttpRequest.builder(UNROUTABLE_IP, 12345)
.connectionTimeout(TimeValue.timeValueSeconds(5))

View File

@ -48,7 +48,8 @@ public class HttpReadTimeoutTests extends ESTestCase {
public void testDefaultTimeout() throws Exception {
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
HttpClient httpClient = new HttpClient(Settings.EMPTY, mock(HttpAuthRegistry.class), environment).start();
HttpClient httpClient = new HttpClient(Settings.EMPTY, mock(HttpAuthRegistry.class), environment);
httpClient.start();
// we're not going to enqueue an response... so the server will just hang
@ -74,9 +75,9 @@ public class HttpReadTimeoutTests extends ESTestCase {
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
HttpClient httpClient = new HttpClient(Settings.builder()
.put("xpack.http.default_read_timeout", "3s")
.build()
, mock(HttpAuthRegistry.class), environment).start();
.put("xpack.http.default_read_timeout", "3s").build()
, mock(HttpAuthRegistry.class), environment);
httpClient.start();
final String path = '/' + randomAsciiOfLength(5);
final CountDownLatch latch = new CountDownLatch(1);
@ -107,9 +108,9 @@ public class HttpReadTimeoutTests extends ESTestCase {
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
HttpClient httpClient = new HttpClient(Settings.builder()
.put("xpack.http.default_read_timeout", "10s")
.build()
, mock(HttpAuthRegistry.class), environment).start();
.put("xpack.http.default_read_timeout", "10s").build()
, mock(HttpAuthRegistry.class), environment);
httpClient.start();
final String path = '/' + randomAsciiOfLength(5);
final CountDownLatch latch = new CountDownLatch(1);

View File

@ -18,7 +18,7 @@ import java.util.List;
/**
*
*/
public class WatcherSettingsValidation extends AbstractLifecycleComponent<WatcherSettingsValidation> {
public class WatcherSettingsValidation extends AbstractLifecycleComponent {
private List<String> errors = new ArrayList<>();

View File

@ -226,7 +226,8 @@ public class WebhookActionTests extends ESTestCase {
public void testThatSelectingProxyWorks() throws Exception {
Environment environment = new Environment(Settings.builder().put("path.home", createTempDir()).build());
HttpClient httpClient = new HttpClient(Settings.EMPTY, authRegistry, environment).start();
HttpClient httpClient = new HttpClient(Settings.EMPTY, authRegistry, environment);
httpClient.start();
MockWebServer proxyServer = new MockWebServer();
try {

View File

@ -594,7 +594,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
assertThat("watcher should only run on the elected master node, but it is running on [" + running + "] nodes", running, equalTo(1));
}
public static class NoopEmailService extends AbstractLifecycleComponent<EmailService> implements EmailService {
public static class NoopEmailService extends AbstractLifecycleComponent implements EmailService {
public NoopEmailService() {
super(Settings.EMPTY);