Search in sources :

Example 66 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project crate by crate.

the class MockTransportService method createNewService.

public static MockTransportService createNewService(Settings settings, Version version, ThreadPool threadPool, @Nullable ClusterSettings clusterSettings) {
    var allSettings = Settings.builder().put(TransportSettings.PORT.getKey(), ESTestCase.getPortRange()).put(settings).build();
    var namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables());
    var transport = new Netty4Transport(allSettings, version, threadPool, new NetworkService(List.of()), new PageCacheRecycler(allSettings), namedWriteableRegistry, new NoneCircuitBreakerService(), new NettyBootstrap(), new AlwaysOKAuthentication(name -> User.CRATE_USER), new SslContextProvider(allSettings));
    return new MockTransportService(allSettings, transport, threadPool, boundAddress -> new DiscoveryNode(Node.NODE_NAME_SETTING.get(settings), UUIDs.randomBase64UUID(), boundAddress.publishAddress(), Node.NODE_ATTRIBUTES.getAsMap(settings), DiscoveryNode.getRolesFromSettings(settings), version), clusterSettings);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Arrays(java.util.Arrays) TransportRequest(org.elasticsearch.transport.TransportRequest) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Transport(org.elasticsearch.transport.Transport) User(io.crate.user.User) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUIDs(org.elasticsearch.common.UUIDs) Set(java.util.Set) PageCacheRecycler(org.elasticsearch.common.util.PageCacheRecycler) ConnectionManager(org.elasticsearch.transport.ConnectionManager) ClusterModule(org.elasticsearch.cluster.ClusterModule) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) Version(org.elasticsearch.Version) TransportAddress(org.elasticsearch.common.transport.TransportAddress) TransportSettings(org.elasticsearch.transport.TransportSettings) TimeValue(io.crate.common.unit.TimeValue) Queue(java.util.Queue) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) RequestHandlerRegistry(org.elasticsearch.transport.RequestHandlerRegistry) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) Function(java.util.function.Function) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NetworkService(org.elasticsearch.common.network.NetworkService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) TcpTransport(org.elasticsearch.transport.TcpTransport) NettyBootstrap(io.crate.netty.NettyBootstrap) Node(org.elasticsearch.node.Node) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) Nullable(javax.annotation.Nullable) ConnectionProfile(org.elasticsearch.transport.ConnectionProfile) Netty4Transport(org.elasticsearch.transport.netty4.Netty4Transport) IOUtils(io.crate.common.io.IOUtils) Plugin(org.elasticsearch.plugins.Plugin) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) ActionListener(org.elasticsearch.action.ActionListener) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) PageCacheRecycler(org.elasticsearch.common.util.PageCacheRecycler) Netty4Transport(org.elasticsearch.transport.netty4.Netty4Transport) NetworkService(org.elasticsearch.common.network.NetworkService) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) NettyBootstrap(io.crate.netty.NettyBootstrap)

Example 67 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project crate by crate.

the class AllocationCommandsTests method testSerialization.

@Test
public void testSerialization() throws Exception {
    AllocationCommands commands = new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 1, "node1", true), new AllocateStalePrimaryAllocationCommand("test", 2, "node1", true), new AllocateReplicaAllocationCommand("test", 2, "node1"), new MoveAllocationCommand("test", 3, "node2", "node3"), new CancelAllocationCommand("test", 4, "node5", true));
    BytesStreamOutput bytes = new BytesStreamOutput();
    AllocationCommands.writeTo(commands, bytes);
    StreamInput in = bytes.bytes().streamInput();
    // Since the commands are named writeable we need to register them and wrap the input stream
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(NetworkModule.getNamedWriteables());
    in = new NamedWriteableAwareStreamInput(in, namedWriteableRegistry);
    // Now we can read them!
    AllocationCommands sCommands = AllocationCommands.readFrom(in);
    assertThat(sCommands.commands().size(), equalTo(5));
    assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).shardId(), equalTo(1));
    assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).index(), equalTo("test"));
    assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).node(), equalTo("node1"));
    assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).acceptDataLoss(), equalTo(true));
    assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).shardId(), equalTo(2));
    assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).index(), equalTo("test"));
    assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).node(), equalTo("node1"));
    assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).acceptDataLoss(), equalTo(true));
    assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).shardId(), equalTo(2));
    assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).index(), equalTo("test"));
    assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).node(), equalTo("node1"));
    assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).shardId(), equalTo(3));
    assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).index(), equalTo("test"));
    assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).fromNode(), equalTo("node2"));
    assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).toNode(), equalTo("node3"));
    assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).shardId(), equalTo(4));
    assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).index(), equalTo("test"));
    assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).node(), equalTo("node5"));
    assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).allowPrimary(), equalTo(true));
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) AllocateStalePrimaryAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand) CancelAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.CancelAllocationCommand) AllocateEmptyPrimaryAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) AllocateReplicaAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) AllocationCommands(org.elasticsearch.cluster.routing.allocation.command.AllocationCommands) Test(org.junit.Test)

Example 68 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project crate by crate.

the class CoordinationMetadataTests method testVotingTombstoneSerializationEqualsHashCode.

public void testVotingTombstoneSerializationEqualsHashCode() {
    VotingConfigExclusion tombstone = new VotingConfigExclusion(randomAlphaOfLength(10), randomAlphaOfLength(10));
    // Note: the explicit cast of the CopyFunction is needed for some IDE (specifically Eclipse 4.8.0) to infer the right type
    EqualsHashCodeTestUtils.checkEqualsAndHashCode(tombstone, (CopyFunction<VotingConfigExclusion>) orig -> ESTestCase.copyWriteable(orig, new NamedWriteableRegistry(Collections.emptyList()), VotingConfigExclusion::new), orig -> randomlyChangeVotingTombstone(orig));
}
Also used : VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) EqualsHashCodeTestUtils(org.elasticsearch.test.EqualsHashCodeTestUtils) ToXContent(org.elasticsearch.common.xcontent.ToXContent) Set(java.util.Set) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) BytesReference(org.elasticsearch.common.bytes.BytesReference) JsonXContent(org.elasticsearch.common.xcontent.json.JsonXContent) XContentParser(org.elasticsearch.common.xcontent.XContentParser) CopyFunction(org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction) HashSet(java.util.HashSet) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Matchers.equalTo(org.hamcrest.Matchers.equalTo) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) ESTestCase(org.elasticsearch.test.ESTestCase) Collections(java.util.Collections) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry)

Example 69 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project crate by crate.

the class CoordinationMetadataTests method testVotingConfigurationSerializationEqualsHashCode.

public void testVotingConfigurationSerializationEqualsHashCode() {
    VotingConfiguration initialConfig = randomVotingConfig();
    // Note: the explicit cast of the CopyFunction is needed for some IDE (specifically Eclipse 4.8.0) to infer the right type
    EqualsHashCodeTestUtils.checkEqualsAndHashCode(initialConfig, (CopyFunction<VotingConfiguration>) orig -> ESTestCase.copyWriteable(orig, new NamedWriteableRegistry(Collections.emptyList()), VotingConfiguration::new), cfg -> randomlyChangeVotingConfiguration(cfg));
}
Also used : EqualsHashCodeTestUtils(org.elasticsearch.test.EqualsHashCodeTestUtils) ToXContent(org.elasticsearch.common.xcontent.ToXContent) Set(java.util.Set) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) BytesReference(org.elasticsearch.common.bytes.BytesReference) JsonXContent(org.elasticsearch.common.xcontent.json.JsonXContent) XContentParser(org.elasticsearch.common.xcontent.XContentParser) CopyFunction(org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction) HashSet(java.util.HashSet) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Matchers.equalTo(org.hamcrest.Matchers.equalTo) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) ESTestCase(org.elasticsearch.test.ESTestCase) Collections(java.util.Collections) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 70 with NamedWriteableRegistry

use of org.elasticsearch.common.io.stream.NamedWriteableRegistry in project crate by crate.

the class TransportServiceHandshakeTests method startServices.

private NetworkHandle startServices(String nodeNameAndId, Settings settings, Version version) {
    var allSettings = Settings.builder().put(TransportSettings.PORT.getKey(), ESTestCase.getPortRange()).put(settings).build();
    var transport = new Netty4Transport(allSettings, // handle the real world scenario instead of a faked one.
    Version.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, new NamedWriteableRegistry(Collections.emptyList()), new NoneCircuitBreakerService(), new NettyBootstrap(), new AlwaysOKAuthentication(userName -> User.CRATE_USER), new SslContextProvider(settings));
    TransportService transportService = new MockTransportService(allSettings, transport, threadPool, (boundAddress) -> new DiscoveryNode(nodeNameAndId, nodeNameAndId, boundAddress.publishAddress(), emptyMap(), emptySet(), version), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    transportServices.add(transportService);
    return new NetworkHandle(transportService, transportService.getLocalNode());
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) BeforeClass(org.junit.BeforeClass) ArrayList(java.util.ArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NetworkService(org.elasticsearch.common.network.NetworkService) Settings(org.elasticsearch.common.settings.Settings) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) After(org.junit.After) NettyBootstrap(io.crate.netty.NettyBootstrap) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ESTestCase(org.elasticsearch.test.ESTestCase) MockTransportService(org.elasticsearch.test.transport.MockTransportService) Collections.emptyMap(java.util.Collections.emptyMap) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) AfterClass(org.junit.AfterClass) Collections.emptySet(java.util.Collections.emptySet) Netty4Transport(org.elasticsearch.transport.netty4.Netty4Transport) User(io.crate.user.User) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) IOException(java.io.IOException) PageCacheRecycler(org.elasticsearch.common.util.PageCacheRecycler) Test(org.junit.Test) VersionUtils(org.elasticsearch.test.VersionUtils) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Version(org.elasticsearch.Version) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) Matchers.containsString(org.hamcrest.Matchers.containsString) Collections(java.util.Collections) ActionListener(org.elasticsearch.action.ActionListener) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportService(org.elasticsearch.test.transport.MockTransportService) Netty4Transport(org.elasticsearch.transport.netty4.Netty4Transport) MockTransportService(org.elasticsearch.test.transport.MockTransportService) NetworkService(org.elasticsearch.common.network.NetworkService) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) NettyBootstrap(io.crate.netty.NettyBootstrap)

Aggregations

NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)71 NetworkService (org.elasticsearch.common.network.NetworkService)27 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)25 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)23 Settings (org.elasticsearch.common.settings.Settings)21 ThreadPool (org.elasticsearch.threadpool.ThreadPool)19 ArrayList (java.util.ArrayList)18 MockTransportService (org.elasticsearch.test.transport.MockTransportService)18 Transport (org.elasticsearch.transport.Transport)18 IOException (java.io.IOException)15 Collections (java.util.Collections)15 TransportAddress (org.elasticsearch.common.transport.TransportAddress)15 BigArrays (org.elasticsearch.common.util.BigArrays)15 SearchModule (org.elasticsearch.search.SearchModule)15 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)15 MockTcpTransport (org.elasticsearch.transport.MockTcpTransport)15 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)14 TransportService (org.elasticsearch.transport.TransportService)14 List (java.util.List)13 ESTestCase (org.elasticsearch.test.ESTestCase)13