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:
parent
eeb964c886
commit
5e300fc1e4
|
@ -415,7 +415,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
|||
long issueDate = System.currentTimeMillis();
|
||||
License.Builder specBuilder = License.builder()
|
||||
.uid(UUID.randomUUID().toString())
|
||||
.issuedTo(clusterService.state().getClusterName().value())
|
||||
.issuedTo(clusterService.getClusterName().value())
|
||||
.maxNodes(trialLicenseMaxNodes)
|
||||
.issueDate(issueDate)
|
||||
.expiryDate(issueDate + trialLicenseDuration.getMillis());
|
||||
|
|
|
@ -41,17 +41,15 @@ public class ClusterStatsCollector extends AbstractCollector<ClusterStatsCollect
|
|||
|
||||
public static final String NAME = "cluster-stats-collector";
|
||||
|
||||
private final ClusterName clusterName;
|
||||
private final LicensesManagerService licensesManagerService;
|
||||
private final Client client;
|
||||
|
||||
@Inject
|
||||
public ClusterStatsCollector(Settings settings, ClusterService clusterService,
|
||||
MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client,
|
||||
LicensesManagerService licensesManagerService, ClusterName clusterName) {
|
||||
LicensesManagerService licensesManagerService) {
|
||||
super(settings, NAME, clusterService, monitoringSettings, licensee);
|
||||
this.client = client;
|
||||
this.clusterName = clusterName;
|
||||
this.licensesManagerService = licensesManagerService;
|
||||
}
|
||||
|
||||
|
@ -86,7 +84,7 @@ public class ClusterStatsCollector extends AbstractCollector<ClusterStatsCollect
|
|||
clusterInfoDoc.setClusterUUID(clusterUUID);
|
||||
clusterInfoDoc.setTimestamp(timestamp);
|
||||
clusterInfoDoc.setSourceNode(sourceNode);
|
||||
clusterInfoDoc.setClusterName(clusterName.value());
|
||||
clusterInfoDoc.setClusterName(clusterService.getClusterName().value());
|
||||
clusterInfoDoc.setVersion(Version.CURRENT.toString());
|
||||
clusterInfoDoc.setLicense(licensesManagerService.getLicense());
|
||||
clusterInfoDoc.setClusterStats(clusterStats);
|
||||
|
|
|
@ -88,9 +88,9 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
|
|||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
CapturingTransport transport = new CapturingTransport();
|
||||
clusterService = new ClusterService(Settings.EMPTY, null, new ClusterSettings(Settings.EMPTY,
|
||||
ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadPool,
|
||||
new ClusterName(TransportMonitoringBulkActionTests.class.getName()));
|
||||
clusterService = new ClusterService(Settings.builder().put("cluster.name",
|
||||
TransportMonitoringBulkActionTests.class.getName()).build(),
|
||||
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadPool);
|
||||
clusterService.setLocalNode(new DiscoveryNode("node", DummyTransportAddress.INSTANCE, emptyMap(), emptySet(), Version.CURRENT));
|
||||
clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) {
|
||||
@Override
|
||||
|
@ -106,7 +106,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
|
|||
clusterService.setClusterStatePublisher((event, ackListener) -> {});
|
||||
clusterService.start();
|
||||
|
||||
transportService = new TransportService(Settings.EMPTY, transport, threadPool, clusterService.state().getClusterName());
|
||||
transportService = new TransportService(clusterService.getSettings(), transport, threadPool);
|
||||
transportService.start();
|
||||
transportService.acceptIncomingRequests();
|
||||
exportService = new CapturingExporters();
|
||||
|
|
|
@ -134,8 +134,7 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
|
|||
internalCluster().getInstance(MonitoringSettings.class, nodeId),
|
||||
internalCluster().getInstance(MonitoringLicensee.class, nodeId),
|
||||
securedClient(nodeId),
|
||||
internalCluster().getInstance(LicensesManagerService.class, nodeId),
|
||||
internalCluster().getInstance(ClusterName.class, nodeId));
|
||||
internalCluster().getInstance(LicensesManagerService.class, nodeId));
|
||||
}
|
||||
|
||||
private void assertCanCollect(AbstractCollector collector, Class<?>... classes) {
|
||||
|
|
|
@ -223,7 +223,8 @@ public class ExportersTests extends ESTestCase {
|
|||
|
||||
DiscoveryNodes nodes = mock(DiscoveryNodes.class);
|
||||
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();
|
||||
assertThat(bulk, notNullValue());
|
||||
|
@ -247,7 +248,8 @@ public class ExportersTests extends ESTestCase {
|
|||
|
||||
DiscoveryNodes nodes = mock(DiscoveryNodes.class);
|
||||
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();
|
||||
assertThat(bulk, notNullValue());
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.DummyTransportAddress;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
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.setLicense(licenseBuilder.build());
|
||||
doc.setClusterName(randomAsciiOfLength(5));
|
||||
doc.setClusterStats(new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.DEFAULT,
|
||||
randomAsciiOfLength(5), Collections.emptyList(), Collections.emptyList()));
|
||||
doc.setClusterStats(new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.CLUSTER_NAME_SETTING
|
||||
.getDefault(Settings.EMPTY), randomAsciiOfLength(5), Collections.emptyList(), Collections.emptyList()));
|
||||
return doc;
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to generated random ClusterInfoMarvelDoc", e);
|
||||
|
|
|
@ -97,8 +97,8 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa
|
|||
emptyMap(), emptySet(), Version.CURRENT),
|
||||
ClusterHealthStatus.GREEN, randomNodeInfo(), randomNodeStats(), randomShardStats())
|
||||
);
|
||||
return new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.DEFAULT, UUID.randomUUID().toString(),
|
||||
responses, Collections.emptyList());
|
||||
return new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY),
|
||||
UUID.randomUUID().toString(), responses, Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.action.FailedNodeException;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.action.support.nodes.TransportNodesAction;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -31,11 +30,11 @@ public class TransportClearRealmCacheAction extends TransportNodesAction<ClearRe
|
|||
private final Realms realms;
|
||||
|
||||
@Inject
|
||||
public TransportClearRealmCacheAction(Settings settings, ClusterName clusterName, ThreadPool threadPool,
|
||||
public TransportClearRealmCacheAction(Settings settings, ThreadPool threadPool,
|
||||
ClusterService clusterService, TransportService transportService,
|
||||
ActionFilters actionFilters, Realms realms,
|
||||
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,
|
||||
ClearRealmCacheResponse.Node.class);
|
||||
this.realms = realms;
|
||||
|
@ -44,7 +43,7 @@ public class TransportClearRealmCacheAction extends TransportNodesAction<ClearRe
|
|||
@Override
|
||||
protected ClearRealmCacheResponse newResponse(ClearRealmCacheRequest request,
|
||||
List<ClearRealmCacheResponse.Node> responses, List<FailedNodeException> failures) {
|
||||
return new ClearRealmCacheResponse(clusterName, responses, failures);
|
||||
return new ClearRealmCacheResponse(clusterService.getClusterName(), responses, failures);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.elasticsearch.shield.action.role;
|
|||
import org.elasticsearch.action.FailedNodeException;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.action.support.nodes.TransportNodesAction;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -28,10 +27,10 @@ public class TransportClearRolesCacheAction extends TransportNodesAction<ClearRo
|
|||
private final NativeRolesStore rolesStore;
|
||||
|
||||
@Inject
|
||||
public TransportClearRolesCacheAction(Settings settings, ClusterName clusterName, ThreadPool threadPool,
|
||||
public TransportClearRolesCacheAction(Settings settings, ThreadPool threadPool,
|
||||
ClusterService clusterService, TransportService transportService, ActionFilters actionFilters,
|
||||
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,
|
||||
ThreadPool.Names.MANAGEMENT, ClearRolesCacheResponse.Node.class);
|
||||
this.rolesStore = rolesStore;
|
||||
|
@ -40,7 +39,7 @@ public class TransportClearRolesCacheAction extends TransportNodesAction<ClearRo
|
|||
@Override
|
||||
protected ClearRolesCacheResponse newResponse(ClearRolesCacheRequest request,
|
||||
List<ClearRolesCacheResponse.Node> responses, List<FailedNodeException> failures) {
|
||||
return new ClearRolesCacheResponse(clusterName, responses, failures);
|
||||
return new ClearRolesCacheResponse(clusterService.getClusterName(), responses, failures);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.shield.transport;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -24,8 +23,8 @@ public class ShieldClientTransportService extends TransportService {
|
|||
|
||||
@Inject
|
||||
public ShieldClientTransportService(Settings settings, Transport transport, ThreadPool threadPool,
|
||||
ClusterName clusterName, ClientTransportFilter clientFilter) {
|
||||
super(settings, transport, threadPool, clusterName);
|
||||
ClientTransportFilter clientFilter) {
|
||||
super(settings, transport, threadPool);
|
||||
this.clientFilter = clientFilter;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.shield.transport;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -56,13 +55,12 @@ public class ShieldServerTransportService extends TransportService {
|
|||
|
||||
@Inject
|
||||
public ShieldServerTransportService(Settings settings, Transport transport, ThreadPool threadPool,
|
||||
ClusterName clusterName,
|
||||
AuthenticationService authcService,
|
||||
AuthorizationService authzService,
|
||||
ShieldActionMapper actionMapper,
|
||||
ClientTransportFilter clientTransportFilter,
|
||||
SecurityLicenseState licenseState) {
|
||||
super(settings, transport, threadPool, clusterName);
|
||||
super(settings, transport, threadPool);
|
||||
this.authcService = authcService;
|
||||
this.authzService = authzService;
|
||||
this.actionMapper = actionMapper;
|
||||
|
|
|
@ -290,9 +290,9 @@ public class TransportFilterTests extends ESIntegTestCase {
|
|||
|
||||
@Inject
|
||||
public InternalPluginServerTransportService(Settings settings, Transport transport, ThreadPool threadPool,
|
||||
ClusterName clusterName, AuthenticationService authcService, AuthorizationService authzService,
|
||||
AuthenticationService authcService, AuthorizationService authzService,
|
||||
ShieldActionMapper actionMapper, ClientTransportFilter clientTransportFilter) {
|
||||
super(settings, transport, threadPool, clusterName, authcService, authzService, actionMapper, clientTransportFilter,
|
||||
super(settings, transport, threadPool, authcService, authzService, actionMapper, clientTransportFilter,
|
||||
mock(SecurityLicenseState.class));
|
||||
when(licenseState.authenticationAndAuthorizationEnabled()).thenReturn(true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue