Cleanup ClusterService dependencies and detached from Guice (elastic/elasticsearch#2542)

followup for elastic/elasticsearchelastic/elasticsearch#18941

Original commit: elastic/x-pack-elasticsearch@6b8680b5e9
This commit is contained in:
Simon Willnauer 2016-06-17 17:07:22 +02:00 committed by GitHub
parent eeb964c886
commit 5e300fc1e4
12 changed files with 28 additions and 33 deletions

View File

@ -415,7 +415,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
long issueDate = System.currentTimeMillis(); long issueDate = System.currentTimeMillis();
License.Builder specBuilder = License.builder() License.Builder specBuilder = License.builder()
.uid(UUID.randomUUID().toString()) .uid(UUID.randomUUID().toString())
.issuedTo(clusterService.state().getClusterName().value()) .issuedTo(clusterService.getClusterName().value())
.maxNodes(trialLicenseMaxNodes) .maxNodes(trialLicenseMaxNodes)
.issueDate(issueDate) .issueDate(issueDate)
.expiryDate(issueDate + trialLicenseDuration.getMillis()); .expiryDate(issueDate + trialLicenseDuration.getMillis());

View File

@ -41,17 +41,15 @@ public class ClusterStatsCollector extends AbstractCollector<ClusterStatsCollect
public static final String NAME = "cluster-stats-collector"; public static final String NAME = "cluster-stats-collector";
private final ClusterName clusterName;
private final LicensesManagerService licensesManagerService; private final LicensesManagerService licensesManagerService;
private final Client client; private final Client client;
@Inject @Inject
public ClusterStatsCollector(Settings settings, ClusterService clusterService, public ClusterStatsCollector(Settings settings, ClusterService clusterService,
MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client, MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client,
LicensesManagerService licensesManagerService, ClusterName clusterName) { LicensesManagerService licensesManagerService) {
super(settings, NAME, clusterService, monitoringSettings, licensee); super(settings, NAME, clusterService, monitoringSettings, licensee);
this.client = client; this.client = client;
this.clusterName = clusterName;
this.licensesManagerService = licensesManagerService; this.licensesManagerService = licensesManagerService;
} }
@ -86,7 +84,7 @@ public class ClusterStatsCollector extends AbstractCollector<ClusterStatsCollect
clusterInfoDoc.setClusterUUID(clusterUUID); clusterInfoDoc.setClusterUUID(clusterUUID);
clusterInfoDoc.setTimestamp(timestamp); clusterInfoDoc.setTimestamp(timestamp);
clusterInfoDoc.setSourceNode(sourceNode); clusterInfoDoc.setSourceNode(sourceNode);
clusterInfoDoc.setClusterName(clusterName.value()); clusterInfoDoc.setClusterName(clusterService.getClusterName().value());
clusterInfoDoc.setVersion(Version.CURRENT.toString()); clusterInfoDoc.setVersion(Version.CURRENT.toString());
clusterInfoDoc.setLicense(licensesManagerService.getLicense()); clusterInfoDoc.setLicense(licensesManagerService.getLicense());
clusterInfoDoc.setClusterStats(clusterStats); clusterInfoDoc.setClusterStats(clusterStats);

View File

@ -88,9 +88,9 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
CapturingTransport transport = new CapturingTransport(); CapturingTransport transport = new CapturingTransport();
clusterService = new ClusterService(Settings.EMPTY, null, new ClusterSettings(Settings.EMPTY, clusterService = new ClusterService(Settings.builder().put("cluster.name",
ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadPool, TransportMonitoringBulkActionTests.class.getName()).build(),
new ClusterName(TransportMonitoringBulkActionTests.class.getName())); new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadPool);
clusterService.setLocalNode(new DiscoveryNode("node", DummyTransportAddress.INSTANCE, emptyMap(), emptySet(), Version.CURRENT)); clusterService.setLocalNode(new DiscoveryNode("node", DummyTransportAddress.INSTANCE, emptyMap(), emptySet(), Version.CURRENT));
clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) { clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) {
@Override @Override
@ -106,7 +106,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
clusterService.setClusterStatePublisher((event, ackListener) -> {}); clusterService.setClusterStatePublisher((event, ackListener) -> {});
clusterService.start(); clusterService.start();
transportService = new TransportService(Settings.EMPTY, transport, threadPool, clusterService.state().getClusterName()); transportService = new TransportService(clusterService.getSettings(), transport, threadPool);
transportService.start(); transportService.start();
transportService.acceptIncomingRequests(); transportService.acceptIncomingRequests();
exportService = new CapturingExporters(); exportService = new CapturingExporters();

View File

@ -134,8 +134,7 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
internalCluster().getInstance(MonitoringSettings.class, nodeId), internalCluster().getInstance(MonitoringSettings.class, nodeId),
internalCluster().getInstance(MonitoringLicensee.class, nodeId), internalCluster().getInstance(MonitoringLicensee.class, nodeId),
securedClient(nodeId), securedClient(nodeId),
internalCluster().getInstance(LicensesManagerService.class, nodeId), internalCluster().getInstance(LicensesManagerService.class, nodeId));
internalCluster().getInstance(ClusterName.class, nodeId));
} }
private void assertCanCollect(AbstractCollector collector, Class<?>... classes) { private void assertCanCollect(AbstractCollector collector, Class<?>... classes) {

View File

@ -223,7 +223,8 @@ public class ExportersTests extends ESTestCase {
DiscoveryNodes nodes = mock(DiscoveryNodes.class); DiscoveryNodes nodes = mock(DiscoveryNodes.class);
when(nodes.isLocalNodeElectedMaster()).thenReturn(true); when(nodes.isLocalNodeElectedMaster()).thenReturn(true);
when(clusterService.state()).thenReturn(ClusterState.builder(ClusterName.DEFAULT).nodes(nodes).build()); when(clusterService.state()).thenReturn(ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
.nodes(nodes).build());
ExportBulk bulk = exporters.openBulk(); ExportBulk bulk = exporters.openBulk();
assertThat(bulk, notNullValue()); assertThat(bulk, notNullValue());
@ -247,7 +248,8 @@ public class ExportersTests extends ESTestCase {
DiscoveryNodes nodes = mock(DiscoveryNodes.class); DiscoveryNodes nodes = mock(DiscoveryNodes.class);
when(nodes.isLocalNodeElectedMaster()).thenReturn(false); when(nodes.isLocalNodeElectedMaster()).thenReturn(false);
when(clusterService.state()).thenReturn(ClusterState.builder(ClusterName.DEFAULT).nodes(nodes).build()); when(clusterService.state()).thenReturn(ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
.nodes(nodes).build());
ExportBulk bulk = exporters.openBulk(); ExportBulk bulk = exporters.openBulk();
assertThat(bulk, notNullValue()); assertThat(bulk, notNullValue());

View File

@ -9,6 +9,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.common.transport.DummyTransportAddress;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
@ -45,8 +46,8 @@ public class ClusterInfoResolverTests extends MonitoringIndexNameResolverTestCas
doc.setVersion(randomFrom(Version.V_2_0_0, Version.CURRENT).toString()); doc.setVersion(randomFrom(Version.V_2_0_0, Version.CURRENT).toString());
doc.setLicense(licenseBuilder.build()); doc.setLicense(licenseBuilder.build());
doc.setClusterName(randomAsciiOfLength(5)); doc.setClusterName(randomAsciiOfLength(5));
doc.setClusterStats(new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.DEFAULT, doc.setClusterStats(new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.CLUSTER_NAME_SETTING
randomAsciiOfLength(5), Collections.emptyList(), Collections.emptyList())); .getDefault(Settings.EMPTY), randomAsciiOfLength(5), Collections.emptyList(), Collections.emptyList()));
return doc; return doc;
} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("Failed to generated random ClusterInfoMarvelDoc", e); throw new IllegalStateException("Failed to generated random ClusterInfoMarvelDoc", e);

View File

@ -97,8 +97,8 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa
emptyMap(), emptySet(), Version.CURRENT), emptyMap(), emptySet(), Version.CURRENT),
ClusterHealthStatus.GREEN, randomNodeInfo(), randomNodeStats(), randomShardStats()) ClusterHealthStatus.GREEN, randomNodeInfo(), randomNodeStats(), randomShardStats())
); );
return new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.DEFAULT, UUID.randomUUID().toString(), return new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY),
responses, Collections.emptyList()); UUID.randomUUID().toString(), responses, Collections.emptyList());
} }
/** /**

View File

@ -9,7 +9,6 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.nodes.TransportNodesAction; import org.elasticsearch.action.support.nodes.TransportNodesAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
@ -31,11 +30,11 @@ public class TransportClearRealmCacheAction extends TransportNodesAction<ClearRe
private final Realms realms; private final Realms realms;
@Inject @Inject
public TransportClearRealmCacheAction(Settings settings, ClusterName clusterName, ThreadPool threadPool, public TransportClearRealmCacheAction(Settings settings, ThreadPool threadPool,
ClusterService clusterService, TransportService transportService, ClusterService clusterService, TransportService transportService,
ActionFilters actionFilters, Realms realms, ActionFilters actionFilters, Realms realms,
IndexNameExpressionResolver indexNameExpressionResolver) { IndexNameExpressionResolver indexNameExpressionResolver) {
super(settings, ClearRealmCacheAction.NAME, clusterName, threadPool, clusterService, transportService, actionFilters, super(settings, ClearRealmCacheAction.NAME, threadPool, clusterService, transportService, actionFilters,
indexNameExpressionResolver, ClearRealmCacheRequest::new, ClearRealmCacheRequest.Node::new, ThreadPool.Names.MANAGEMENT, indexNameExpressionResolver, ClearRealmCacheRequest::new, ClearRealmCacheRequest.Node::new, ThreadPool.Names.MANAGEMENT,
ClearRealmCacheResponse.Node.class); ClearRealmCacheResponse.Node.class);
this.realms = realms; this.realms = realms;
@ -44,7 +43,7 @@ public class TransportClearRealmCacheAction extends TransportNodesAction<ClearRe
@Override @Override
protected ClearRealmCacheResponse newResponse(ClearRealmCacheRequest request, protected ClearRealmCacheResponse newResponse(ClearRealmCacheRequest request,
List<ClearRealmCacheResponse.Node> responses, List<FailedNodeException> failures) { List<ClearRealmCacheResponse.Node> responses, List<FailedNodeException> failures) {
return new ClearRealmCacheResponse(clusterName, responses, failures); return new ClearRealmCacheResponse(clusterService.getClusterName(), responses, failures);
} }
@Override @Override

View File

@ -8,7 +8,6 @@ package org.elasticsearch.shield.action.role;
import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.nodes.TransportNodesAction; import org.elasticsearch.action.support.nodes.TransportNodesAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
@ -28,10 +27,10 @@ public class TransportClearRolesCacheAction extends TransportNodesAction<ClearRo
private final NativeRolesStore rolesStore; private final NativeRolesStore rolesStore;
@Inject @Inject
public TransportClearRolesCacheAction(Settings settings, ClusterName clusterName, ThreadPool threadPool, public TransportClearRolesCacheAction(Settings settings, ThreadPool threadPool,
ClusterService clusterService, TransportService transportService, ActionFilters actionFilters, ClusterService clusterService, TransportService transportService, ActionFilters actionFilters,
NativeRolesStore rolesStore, IndexNameExpressionResolver indexNameExpressionResolver) { NativeRolesStore rolesStore, IndexNameExpressionResolver indexNameExpressionResolver) {
super(settings, ClearRolesCacheAction.NAME, clusterName, threadPool, clusterService, transportService, super(settings, ClearRolesCacheAction.NAME, threadPool, clusterService, transportService,
actionFilters, indexNameExpressionResolver, ClearRolesCacheRequest::new, ClearRolesCacheRequest.Node::new, actionFilters, indexNameExpressionResolver, ClearRolesCacheRequest::new, ClearRolesCacheRequest.Node::new,
ThreadPool.Names.MANAGEMENT, ClearRolesCacheResponse.Node.class); ThreadPool.Names.MANAGEMENT, ClearRolesCacheResponse.Node.class);
this.rolesStore = rolesStore; this.rolesStore = rolesStore;
@ -40,7 +39,7 @@ public class TransportClearRolesCacheAction extends TransportNodesAction<ClearRo
@Override @Override
protected ClearRolesCacheResponse newResponse(ClearRolesCacheRequest request, protected ClearRolesCacheResponse newResponse(ClearRolesCacheRequest request,
List<ClearRolesCacheResponse.Node> responses, List<FailedNodeException> failures) { List<ClearRolesCacheResponse.Node> responses, List<FailedNodeException> failures) {
return new ClearRolesCacheResponse(clusterName, responses, failures); return new ClearRolesCacheResponse(clusterService.getClusterName(), responses, failures);
} }
@Override @Override

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.transport; package org.elasticsearch.shield.transport;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -24,8 +23,8 @@ public class ShieldClientTransportService extends TransportService {
@Inject @Inject
public ShieldClientTransportService(Settings settings, Transport transport, ThreadPool threadPool, public ShieldClientTransportService(Settings settings, Transport transport, ThreadPool threadPool,
ClusterName clusterName, ClientTransportFilter clientFilter) { ClientTransportFilter clientFilter) {
super(settings, transport, threadPool, clusterName); super(settings, transport, threadPool);
this.clientFilter = clientFilter; this.clientFilter = clientFilter;
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.transport; package org.elasticsearch.shield.transport;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -56,13 +55,12 @@ public class ShieldServerTransportService extends TransportService {
@Inject @Inject
public ShieldServerTransportService(Settings settings, Transport transport, ThreadPool threadPool, public ShieldServerTransportService(Settings settings, Transport transport, ThreadPool threadPool,
ClusterName clusterName,
AuthenticationService authcService, AuthenticationService authcService,
AuthorizationService authzService, AuthorizationService authzService,
ShieldActionMapper actionMapper, ShieldActionMapper actionMapper,
ClientTransportFilter clientTransportFilter, ClientTransportFilter clientTransportFilter,
SecurityLicenseState licenseState) { SecurityLicenseState licenseState) {
super(settings, transport, threadPool, clusterName); super(settings, transport, threadPool);
this.authcService = authcService; this.authcService = authcService;
this.authzService = authzService; this.authzService = authzService;
this.actionMapper = actionMapper; this.actionMapper = actionMapper;

View File

@ -290,9 +290,9 @@ public class TransportFilterTests extends ESIntegTestCase {
@Inject @Inject
public InternalPluginServerTransportService(Settings settings, Transport transport, ThreadPool threadPool, public InternalPluginServerTransportService(Settings settings, Transport transport, ThreadPool threadPool,
ClusterName clusterName, AuthenticationService authcService, AuthorizationService authzService, AuthenticationService authcService, AuthorizationService authzService,
ShieldActionMapper actionMapper, ClientTransportFilter clientTransportFilter) { ShieldActionMapper actionMapper, ClientTransportFilter clientTransportFilter) {
super(settings, transport, threadPool, clusterName, authcService, authzService, actionMapper, clientTransportFilter, super(settings, transport, threadPool, authcService, authzService, actionMapper, clientTransportFilter,
mock(SecurityLicenseState.class)); mock(SecurityLicenseState.class));
when(licenseState.authenticationAndAuthorizationEnabled()).thenReturn(true); when(licenseState.authenticationAndAuthorizationEnabled()).thenReturn(true);
} }