rename Server to Node to better reflect its usage (it can be a client node), also add on the NodeBuilder helper methods to set common settings

This commit is contained in:
kimchy 2010-04-09 00:54:54 +03:00
parent d4bc187be9
commit a9cd00e287
44 changed files with 472 additions and 437 deletions

View File

@ -21,7 +21,7 @@ package org.elasticsearch.benchmark.monitor.memory;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.Client;
import org.elasticsearch.server.Server;
import org.elasticsearch.node.Node;
import org.elasticsearch.util.StopWatch;
import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings;
@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.cluster.metadata.IndexMetaData.*;
import static org.elasticsearch.server.ServerBuilder.*;
import static org.elasticsearch.node.NodeBuilder.*;
import static org.elasticsearch.util.json.JsonBuilder.*;
import static org.elasticsearch.util.settings.ImmutableSettings.*;
@ -51,10 +51,10 @@ public class SimpleMemoryMonitorBenchmark {
.put(SETTING_NUMBER_OF_REPLICAS, 1)
.build();
Server server1 = serverBuilder().settings(settingsBuilder().put(settings).put("name", "server1")).server();
Server server2 = serverBuilder().settings(settingsBuilder().put(settings).put("name", "server2")).server();
Node node1 = nodeBuilder().settings(settingsBuilder().put(settings).put("name", "server1")).node();
Node node2 = nodeBuilder().settings(settingsBuilder().put(settings).put("name", "server2")).node();
Client client1 = server1.client();
Client client1 = node1.client();
Thread.sleep(1000);
client1.admin().indices().create(createIndexRequest("test")).actionGet();
@ -78,8 +78,8 @@ public class SimpleMemoryMonitorBenchmark {
}
System.out.println("Indexing took " + stopWatch.stop().totalTime());
server1.close();
server2.close();
node1.close();
node2.close();
}
private static JsonBuilder source(String id, String nameValue) throws IOException {

View File

@ -27,7 +27,7 @@ import org.elasticsearch.action.support.nodes.NodeOperationRequest;
import org.elasticsearch.action.support.nodes.TransportNodesOperationAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.server.Server;
import org.elasticsearch.node.Node;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.util.TimeValue;
@ -48,15 +48,15 @@ import static org.elasticsearch.util.TimeValue.*;
*/
public class TransportNodesShutdown extends TransportNodesOperationAction<NodesShutdownRequest, NodesShutdownResponse, TransportNodesShutdown.NodeShutdownRequest, NodesShutdownResponse.NodeShutdownResponse> {
private final Server server;
private final Node node;
private final boolean disabled;
@Inject public TransportNodesShutdown(Settings settings, ClusterName clusterName, ThreadPool threadPool,
ClusterService clusterService, TransportService transportService,
Server server) {
Node node) {
super(settings, clusterName, threadPool, clusterService, transportService);
this.server = server;
this.node = node;
disabled = componentSettings.getAsBoolean("disabled", false);
}
@ -102,7 +102,7 @@ public class TransportNodesShutdown extends TransportNodesOperationAction<NodesS
logger.info("Shutting down in [{}]", request.delay);
threadPool.schedule(new Runnable() {
@Override public void run() {
server.close();
node.close();
}
}, request.delay.millis(), TimeUnit.MILLISECONDS);
return new NodesShutdownResponse.NodeShutdownResponse(clusterService.state().nodes().localNode());

View File

@ -25,9 +25,9 @@ import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.env.Environment;
import org.elasticsearch.jmx.JmxService;
import org.elasticsearch.server.Server;
import org.elasticsearch.server.ServerBuilder;
import org.elasticsearch.server.internal.InternalSettingsPerparer;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
import org.elasticsearch.node.internal.InternalSettingsPerparer;
import org.elasticsearch.util.Classes;
import org.elasticsearch.util.Tuple;
import org.elasticsearch.util.jline.ANSI;
@ -51,17 +51,17 @@ import static org.elasticsearch.util.settings.ImmutableSettings.*;
*/
public class Bootstrap {
private Server server;
private Node node;
private void setup(boolean addShutdownHook, Tuple<Settings, Environment> tuple) throws Exception {
tuple = setupJmx(tuple);
ServerBuilder serverBuilder = ServerBuilder.serverBuilder().settings(tuple.v1()).loadConfigSettings(false);
server = serverBuilder.build();
NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(tuple.v1()).loadConfigSettings(false);
node = nodeBuilder.build();
if (addShutdownHook) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override public void run() {
server.close();
node.close();
}
});
}
@ -107,14 +107,14 @@ public class Bootstrap {
* hook for JSVC
*/
public void start() {
server.start();
node.start();
}
/**
* hook for JSVC
*/
public void stop() {
server.stop();
node.stop();
}
@ -122,7 +122,7 @@ public class Bootstrap {
* hook for JSVC
*/
public void destroy() {
server.close();
node.close();
}
@ -163,8 +163,8 @@ public class Bootstrap {
}
} catch (Throwable e) {
Logger logger = Loggers.getLogger(Bootstrap.class);
if (bootstrap.server != null) {
logger = Loggers.getLogger(Bootstrap.class, bootstrap.server.settings().get("name"));
if (bootstrap.node != null) {
logger = Loggers.getLogger(Bootstrap.class, bootstrap.node.settings().get("name"));
}
String errorMessage = buildErrorMessage(stage, e);
if (foreground) {

View File

@ -45,11 +45,11 @@ import org.elasticsearch.action.terms.TermsResponse;
* simply returns an {@link org.elasticsearch.action.ActionFuture}, while the second accepts an
* {@link org.elasticsearch.action.ActionListener}.
*
* <p>A client can either be retrieved from a {@link org.elasticsearch.server.Server} started, or connected remotely
* <p>A client can either be retrieved from a {@link org.elasticsearch.node.Node} started, or connected remotely
* to one or more nodes using {@link org.elasticsearch.client.transport.TransportClient}.
*
* @author kimchy (shay.banon)
* @see org.elasticsearch.server.Server#client()
* @see org.elasticsearch.node.Node#client()
* @see org.elasticsearch.client.transport.TransportClient
*/
public interface Client {

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.client.server;
package org.elasticsearch.client.node;
import com.google.inject.Inject;
import org.elasticsearch.client.AdminClient;
@ -27,15 +27,15 @@ import org.elasticsearch.util.component.AbstractComponent;
import org.elasticsearch.util.settings.Settings;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class ServerAdminClient extends AbstractComponent implements AdminClient {
public class NodeAdminClient extends AbstractComponent implements AdminClient {
private final ServerIndicesAdminClient indicesAdminClient;
private final NodeIndicesAdminClient indicesAdminClient;
private final ServerClusterAdminClient clusterAdminClient;
private final NodeClusterAdminClient clusterAdminClient;
@Inject public ServerAdminClient(Settings settings, ServerClusterAdminClient clusterAdminClient, ServerIndicesAdminClient indicesAdminClient) {
@Inject public NodeAdminClient(Settings settings, NodeClusterAdminClient clusterAdminClient, NodeIndicesAdminClient indicesAdminClient) {
super(settings);
this.indicesAdminClient = indicesAdminClient;
this.clusterAdminClient = clusterAdminClient;

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.client.server;
package org.elasticsearch.client.node;
import com.google.inject.Inject;
import org.elasticsearch.action.ActionFuture;
@ -51,9 +51,9 @@ import org.elasticsearch.util.settings.Settings;
/**
* @author kimchy (shay.banon)
*/
public class ServerClient extends AbstractComponent implements Client {
public class NodeClient extends AbstractComponent implements Client {
private final ServerAdminClient admin;
private final NodeAdminClient admin;
private final TransportIndexAction indexAction;
@ -73,11 +73,11 @@ public class ServerClient extends AbstractComponent implements Client {
private final TransportMoreLikeThisAction moreLikeThisAction;
@Inject public ServerClient(Settings settings, ServerAdminClient admin,
TransportIndexAction indexAction, TransportDeleteAction deleteAction,
TransportDeleteByQueryAction deleteByQueryAction, TransportGetAction getAction, TransportCountAction countAction,
TransportSearchAction searchAction, TransportSearchScrollAction searchScrollAction,
TransportTermsAction termsAction, TransportMoreLikeThisAction moreLikeThisAction) {
@Inject public NodeClient(Settings settings, NodeAdminClient admin,
TransportIndexAction indexAction, TransportDeleteAction deleteAction,
TransportDeleteByQueryAction deleteByQueryAction, TransportGetAction getAction, TransportCountAction countAction,
TransportSearchAction searchAction, TransportSearchScrollAction searchScrollAction,
TransportTermsAction termsAction, TransportMoreLikeThisAction moreLikeThisAction) {
super(settings);
this.admin = admin;
this.indexAction = indexAction;

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.client.server;
package org.elasticsearch.client.node;
import com.google.inject.AbstractModule;
import org.elasticsearch.client.AdminClient;
@ -28,12 +28,12 @@ import org.elasticsearch.client.IndicesAdminClient;
/**
* @author kimchy (shay.banon)
*/
public class ServerClientModule extends AbstractModule {
public class NodeClientModule extends AbstractModule {
@Override protected void configure() {
bind(ClusterAdminClient.class).to(ServerClusterAdminClient.class).asEagerSingleton();
bind(IndicesAdminClient.class).to(ServerIndicesAdminClient.class).asEagerSingleton();
bind(AdminClient.class).to(ServerAdminClient.class).asEagerSingleton();
bind(Client.class).to(ServerClient.class).asEagerSingleton();
bind(ClusterAdminClient.class).to(NodeClusterAdminClient.class).asEagerSingleton();
bind(IndicesAdminClient.class).to(NodeIndicesAdminClient.class).asEagerSingleton();
bind(AdminClient.class).to(NodeAdminClient.class).asEagerSingleton();
bind(Client.class).to(NodeClient.class).asEagerSingleton();
}
}

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.client.server;
package org.elasticsearch.client.node;
import com.google.inject.Inject;
import org.elasticsearch.action.ActionFuture;
@ -48,9 +48,9 @@ import org.elasticsearch.util.component.AbstractComponent;
import org.elasticsearch.util.settings.Settings;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class ServerClusterAdminClient extends AbstractComponent implements ClusterAdminClient {
public class NodeClusterAdminClient extends AbstractComponent implements ClusterAdminClient {
private final TransportClusterHealthAction clusterHealthAction;
@ -66,10 +66,10 @@ public class ServerClusterAdminClient extends AbstractComponent implements Clust
private final TransportNodesShutdown nodesShutdown;
@Inject public ServerClusterAdminClient(Settings settings,
TransportClusterHealthAction clusterHealthAction, TransportClusterStateAction clusterStateAction,
TransportSinglePingAction singlePingAction, TransportBroadcastPingAction broadcastPingAction, TransportReplicationPingAction replicationPingAction,
TransportNodesInfo nodesInfo, TransportNodesShutdown nodesShutdown) {
@Inject public NodeClusterAdminClient(Settings settings,
TransportClusterHealthAction clusterHealthAction, TransportClusterStateAction clusterStateAction,
TransportSinglePingAction singlePingAction, TransportBroadcastPingAction broadcastPingAction, TransportReplicationPingAction replicationPingAction,
TransportNodesInfo nodesInfo, TransportNodesShutdown nodesShutdown) {
super(settings);
this.clusterHealthAction = clusterHealthAction;
this.clusterStateAction = clusterStateAction;

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.client.server;
package org.elasticsearch.client.node;
import com.google.inject.Inject;
import org.elasticsearch.action.ActionFuture;
@ -57,9 +57,9 @@ import org.elasticsearch.util.component.AbstractComponent;
import org.elasticsearch.util.settings.Settings;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class ServerIndicesAdminClient extends AbstractComponent implements IndicesAdminClient {
public class NodeIndicesAdminClient extends AbstractComponent implements IndicesAdminClient {
private final TransportIndicesStatusAction indicesStatusAction;
@ -81,11 +81,11 @@ public class ServerIndicesAdminClient extends AbstractComponent implements Indic
private final TransportClearIndicesCacheAction clearIndicesCacheAction;
@Inject public ServerIndicesAdminClient(Settings settings, TransportIndicesStatusAction indicesStatusAction,
TransportCreateIndexAction createIndexAction, TransportDeleteIndexAction deleteIndexAction,
TransportRefreshAction refreshAction, TransportFlushAction flushAction, TransportOptimizeAction optimizeAction,
TransportPutMappingAction putMappingAction, TransportGatewaySnapshotAction gatewaySnapshotAction,
TransportIndicesAliasesAction indicesAliasesAction, TransportClearIndicesCacheAction clearIndicesCacheAction) {
@Inject public NodeIndicesAdminClient(Settings settings, TransportIndicesStatusAction indicesStatusAction,
TransportCreateIndexAction createIndexAction, TransportDeleteIndexAction deleteIndexAction,
TransportRefreshAction refreshAction, TransportFlushAction flushAction, TransportOptimizeAction optimizeAction,
TransportPutMappingAction putMappingAction, TransportGatewaySnapshotAction gatewaySnapshotAction,
TransportIndicesAliasesAction indicesAliasesAction, TransportClearIndicesCacheAction clearIndicesCacheAction) {
super(settings);
this.indicesStatusAction = indicesStatusAction;
this.createIndexAction = createIndexAction;

View File

@ -50,7 +50,7 @@ import org.elasticsearch.cluster.ClusterNameModule;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule;
import org.elasticsearch.server.internal.InternalSettingsPerparer;
import org.elasticsearch.node.internal.InternalSettingsPerparer;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.threadpool.ThreadPoolModule;
import org.elasticsearch.timer.TimerModule;
@ -120,7 +120,7 @@ public class TransportClient implements Client {
Tuple<Settings, Environment> tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings);
this.settings = settingsBuilder().put(tuple.v1())
.put("network.server", false)
.put("discovery.client", true)
.put("node.client", true)
.build();
this.environment = tuple.v2();

View File

@ -79,7 +79,7 @@ public class GatewayService extends AbstractLifecycleComponent<GatewayService> i
gateway.start();
this.executor = newSingleThreadExecutor(daemonThreadFactory(settings, "gateway"));
// if we received initial state, see if we can recover within the start phase, so we hold the
// server from starting until we recovered properly
// node from starting until we recovered properly
if (discoveryService.initialStateReceived()) {
if (discoveryService.firstMaster()) {
if (firstMasterRead.compareAndSet(false, true)) {

View File

@ -17,24 +17,24 @@
* under the License.
*/
package org.elasticsearch.server;
package org.elasticsearch.node;
import org.elasticsearch.client.Client;
import org.elasticsearch.util.settings.Settings;
/**
* A server represent a node within a cluster (<tt>cluster.name</tt>). The {@link #client()} can be used
* A node represent a node within a cluster (<tt>cluster.name</tt>). The {@link #client()} can be used
* in order to use a {@link Client} to perform actions/operations against the cluster.
*
* <p>In order to create a server, the {@link ServerBuilder} can be used. When done with it, make sure to
* <p>In order to create a node, the {@link NodeBuilder} can be used. When done with it, make sure to
* call {@link #close()} on it.
*
* @author kimchy (shay.banon)
*/
public interface Server {
public interface Node {
/**
* The settings that were used to create the server.
* The settings that were used to create the node.
*/
Settings settings();
@ -44,17 +44,17 @@ public interface Server {
Client client();
/**
* Start the server. If the server is already started, this method is noop.
* Start the node. If the node is already started, this method is no-op.
*/
Server start();
Node start();
/**
* Stops the server. If the server is already started, this method is noop.
* Stops the node. If the node is already started, this method is no-op.
*/
Server stop();
Node stop();
/**
* Closes the server (and {@link #stop}s if its running).
* Closes the node (and {@link #stop}s if its running).
*/
void close();
}

View File

@ -0,0 +1,143 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.node;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.util.settings.ImmutableSettings;
import org.elasticsearch.util.settings.Settings;
/**
* A node builder is used to construct a {@link Node} instance.
*
* <p>Settings will be loaded relative to the ES home (with or without <tt>config/</tt> prefix) and if not found,
* within the classpath (with or without <tt>config/<tt> prefix). The settings file loaded can either be named
* <tt>elasticsearch.yml</tt> or <tt>elasticsearch.json</tt>). Loading settings can be disabled by calling
* {@link #loadConfigSettings(boolean)} with <tt>false<tt>.
*
* <p>Explicit settings can be passed by using the {@link #settings(Settings)} method.
*
* <p>In any case, settings will be resolved from system properties as well that are either prefixed with <tt>es.</tt>
* or <tt>elasticsearch.</tt>.
*
* <p>An example for creating a simple node with optional settings loaded from the classpath:
*
* <pre>
* Node node = NodeBuilder.nodeBuilder().node();
* </pre>
*
* <p>An example for creating a node with explicit settings (in this case, a node in the cluster that does not hold
* data):
*
* <pre>
* Node node = NodeBuilder.nodeBuilder()
* .settings(ImmutableSettings.settingsBuilder().put("node.data", false)
* .node();
* </pre>
*
* <p>When done with the node, make sure you call {@link Node#close()} on it.
*
* @author kimchy (shay.banon)
*/
public class NodeBuilder {
private final ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
private boolean loadConfigSettings = true;
/**
* A convenient factory method to create a {@link NodeBuilder}.
*/
public static NodeBuilder nodeBuilder() {
return new NodeBuilder();
}
/**
* Explicit node settings to set.
*/
public NodeBuilder settings(Settings.Builder settings) {
return settings(settings.build());
}
/**
* Explicit node settings to set.
*/
public NodeBuilder settings(Settings settings) {
this.settings.put(settings);
return this;
}
/**
* Should the node builder automatically try and load config settings from the file system / classpath. Defaults
* to <tt>true</tt>.
*/
public NodeBuilder loadConfigSettings(boolean loadConfigSettings) {
this.loadConfigSettings = loadConfigSettings;
return this;
}
/**
* Is the node going to be a client node which means it will hold no data (<tt>node.data</tt> is
* set to <tt>false</tt>) and other optimizations by different modules.
*
* @param client Should the node be just a client node or not.
*/
public NodeBuilder client(boolean client) {
settings.put("node.client", client);
data(!client);
return this;
}
/**
* Is the node going to be allowed to allocate data (shards) to it or not. This setting map to
* the <tt>node.data</tt> setting. Note, when setting {@link #client(boolean)}, the node will
* not hold any data by default.
*
* @param data Should the node be allocated data to or not.
*/
public NodeBuilder data(boolean data) {
settings.put("node.data", data);
return this;
}
/**
* The cluster name this node is part of (maps to the <tt>cluster.name</tt> setting). Defaults
* to <tt>elasticsearch</tt>.
*
* @param clusterName The cluster name this node is part of.
*/
public NodeBuilder clusterName(String clusterName) {
settings.put("cluster.name", clusterName);
return this;
}
/**
* Builds the node without starting it.
*/
public Node build() {
return new InternalNode(settings.build(), loadConfigSettings);
}
/**
* {@link #build()}s and starts the node.
*/
public Node node() {
return build().start();
}
}

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.server.internal;
package org.elasticsearch.node.internal;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -26,7 +26,7 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.TransportActionModule;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.server.ServerClientModule;
import org.elasticsearch.client.node.NodeClientModule;
import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.cluster.ClusterNameModule;
import org.elasticsearch.cluster.ClusterService;
@ -46,13 +46,13 @@ import org.elasticsearch.jmx.JmxModule;
import org.elasticsearch.jmx.JmxService;
import org.elasticsearch.monitor.MonitorModule;
import org.elasticsearch.monitor.MonitorService;
import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.PluginsModule;
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestModule;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.SearchService;
import org.elasticsearch.server.Server;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.threadpool.ThreadPoolModule;
import org.elasticsearch.timer.TimerModule;
@ -79,7 +79,7 @@ import static org.elasticsearch.util.settings.ImmutableSettings.*;
/**
* @author kimchy (shay.banon)
*/
public final class InternalServer implements Server {
public final class InternalNode implements Node {
private final Lifecycle lifecycle = new Lifecycle();
@ -93,14 +93,14 @@ public final class InternalServer implements Server {
private final Client client;
public InternalServer() throws ElasticSearchException {
public InternalNode() throws ElasticSearchException {
this(Builder.EMPTY_SETTINGS, true);
}
public InternalServer(Settings pSettings, boolean loadConfigSettings) throws ElasticSearchException {
public InternalNode(Settings pSettings, boolean loadConfigSettings) throws ElasticSearchException {
Tuple<Settings, Environment> tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings);
Logger logger = Loggers.getLogger(Server.class, tuple.v1().get("name"));
Logger logger = Loggers.getLogger(Node.class, tuple.v1().get("name"));
logger.info("{{}}: Initializing ...", Version.full());
this.pluginsService = new PluginsService(tuple.v1(), tuple.v2());
@ -109,7 +109,7 @@ public final class InternalServer implements Server {
ArrayList<Module> modules = new ArrayList<Module>();
modules.add(new PluginsModule(settings, pluginsService));
modules.add(new ServerModule(this));
modules.add(new NodeModule(this));
modules.add(new JmxModule(settings));
modules.add(new EnvironmentModule(environment));
modules.add(new ClusterNameModule(settings));
@ -128,7 +128,7 @@ public final class InternalServer implements Server {
modules.add(new TransportActionModule());
modules.add(new MonitorModule(settings));
modules.add(new GatewayModule(settings));
modules.add(new ServerClientModule());
modules.add(new NodeClientModule());
injector = Guice.createInjector(modules);
@ -146,12 +146,12 @@ public final class InternalServer implements Server {
return client;
}
public Server start() {
public Node start() {
if (!lifecycle.moveToStarted()) {
return this;
}
Logger logger = Loggers.getLogger(Server.class, settings.get("name"));
Logger logger = Loggers.getLogger(Node.class, settings.get("name"));
logger.info("{{}}: Starting ...", Version.full());
for (Class<? extends LifecycleComponent> plugin : pluginsService.services()) {
@ -180,11 +180,11 @@ public final class InternalServer implements Server {
return this;
}
@Override public Server stop() {
@Override public Node stop() {
if (!lifecycle.moveToStopped()) {
return this;
}
Logger logger = Loggers.getLogger(Server.class, settings.get("name"));
Logger logger = Loggers.getLogger(Node.class, settings.get("name"));
logger.info("{{}}: Stopping ...", Version.full());
if (settings.getAsBoolean("http.enabled", true)) {
@ -228,7 +228,7 @@ public final class InternalServer implements Server {
return;
}
Logger logger = Loggers.getLogger(Server.class, settings.get("name"));
Logger logger = Loggers.getLogger(Node.class, settings.get("name"));
logger.info("{{}}: Closing ...", Version.full());
if (settings.getAsBoolean("http.enabled", true)) {
@ -272,11 +272,11 @@ public final class InternalServer implements Server {
}
public static void main(String[] args) throws Exception {
final InternalServer server = new InternalServer();
server.start();
final InternalNode node = new InternalNode();
node.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override public void run() {
server.close();
node.close();
}
});
}

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.server.internal;
package org.elasticsearch.node.internal;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.env.Environment;

View File

@ -17,23 +17,23 @@
* under the License.
*/
package org.elasticsearch.server.internal;
package org.elasticsearch.node.internal;
import com.google.inject.AbstractModule;
import org.elasticsearch.server.Server;
import org.elasticsearch.node.Node;
/**
* @author kimchy (shay.banon)
*/
public class ServerModule extends AbstractModule {
public class NodeModule extends AbstractModule {
private final Server server;
private final Node node;
public ServerModule(Server server) {
this.server = server;
public NodeModule(Node node) {
this.node = node;
}
@Override protected void configure() {
bind(Server.class).toInstance(server);
bind(Node.class).toInstance(node);
}
}

View File

@ -18,6 +18,6 @@
*/
/**
* Allow to build a {@link Server} using {@link ServerBuilder} which is a node within the cluster.
* Allow to build a {@link Node} using {@link NodeBuilder} which is a node within the cluster.
*/
package org.elasticsearch.server;
package org.elasticsearch.node;

View File

@ -43,12 +43,12 @@ public interface Plugin {
String description();
/**
* Server level modules.
* Node level modules.
*/
Collection<Class<? extends Module>> modules();
/**
* Server level services that will be automatically started/stopped/closed.
* Node level services that will be automatically started/stopped/closed.
*/
Collection<Class<? extends LifecycleComponent>> services();

View File

@ -1,108 +0,0 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.server;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.util.settings.ImmutableSettings;
import org.elasticsearch.util.settings.Settings;
/**
* A server builder is used to construct a {@link Server} instance.
*
* <p>Settings will be loaded relative to the ES home (with or without <tt>config/</tt> prefix) and if not found,
* within the classpath (with or without <tt>config/<tt> prefix). The settings file loaded can either be named
* <tt>elasticsearch.yml</tt> or <tt>elasticsearch.json</tt>). Loading settings can be disabled by calling
* {@link #loadConfigSettings(boolean)} with <tt>false<tt>.
*
* <p>Explicit settings can be passed by using the {@link #settings(Settings)} method.
*
* <p>In any case, settings will be resolved from system properties as well that are either prefixed with <tt>es.</tt>
* or <tt>elasticsearch.</tt>.
*
* <p>An example for creating a simple server with optional settings loaded from the classpath:
*
* <pre>
* Server server = ServerBuilder.serverBuilder().server();
* </pre>
*
* <p>An example for creating a server with explicit settings (in this case, a node in the cluster that does not hold
* data):
*
* <pre>
* Server server = ServerBuilder.serverBuilder()
* .settings(ImmutableSettings.settingsBuilder().putBoolean("node.data", false)
* .server();
* </pre>
*
* <p>When done with the server, make sure you call {@link Server#close()} on it.
*
* @author kimchy (shay.banon)
*/
public class ServerBuilder {
private Settings settings = ImmutableSettings.Builder.EMPTY_SETTINGS;
private boolean loadConfigSettings = true;
/**
* A convenient factory method to create a {@link ServerBuilder}.
*/
public static ServerBuilder serverBuilder() {
return new ServerBuilder();
}
/**
* Explicit server settings to set.
*/
public ServerBuilder settings(Settings.Builder settings) {
return settings(settings.build());
}
/**
* Explicit server settings to set.
*/
public ServerBuilder settings(Settings settings) {
this.settings = settings;
return this;
}
/**
* Should the server builder automatically try and load config settings from the file system / classpath. Defaults
* to <tt>true</tt>.
*/
public ServerBuilder loadConfigSettings(boolean loadConfigSettings) {
this.loadConfigSettings = loadConfigSettings;
return this;
}
/**
* Builds the server without starting it.
*/
public Server build() {
return new InternalServer(settings, loadConfigSettings);
}
/**
* {@link #build()}s and starts the server.
*/
public Server server() {
return build().start();
}
}

View File

@ -20,7 +20,7 @@
package org.elasticsearch.test.integration;
import org.elasticsearch.client.Client;
import org.elasticsearch.server.Server;
import org.elasticsearch.node.Node;
import org.elasticsearch.util.logging.Loggers;
import org.elasticsearch.util.settings.Settings;
import org.slf4j.Logger;
@ -28,72 +28,72 @@ import org.slf4j.Logger;
import java.util.Map;
import static com.google.common.collect.Maps.*;
import static org.elasticsearch.server.ServerBuilder.*;
import static org.elasticsearch.node.NodeBuilder.*;
import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*;
import static org.elasticsearch.util.settings.ImmutableSettings.*;
public abstract class AbstractServersTests {
public abstract class AbstractNodesTests {
protected final Logger logger = Loggers.getLogger(getClass());
private Map<String, Server> servers = newHashMap();
private Map<String, Node> nodes = newHashMap();
private Map<String, Client> clients = newHashMap();
public Server startServer(String id) {
return buildServer(id).start();
public Node startNode(String id) {
return buildNode(id).start();
}
public Server startServer(String id, Settings settings) {
return buildServer(id, settings).start();
public Node startNode(String id, Settings settings) {
return buildNode(id, settings).start();
}
public Server buildServer(String id) {
return buildServer(id, EMPTY_SETTINGS);
public Node buildNode(String id) {
return buildNode(id, EMPTY_SETTINGS);
}
public Server buildServer(String id, Settings settings) {
public Node buildNode(String id, Settings settings) {
String settingsSource = getClass().getName().replace('.', '/') + ".yml";
Settings finalSettings = settingsBuilder()
.loadFromClasspath(settingsSource)
.put(settings)
.put("name", id)
.build();
Server server = serverBuilder()
Node node = nodeBuilder()
.settings(finalSettings)
.build();
servers.put(id, server);
clients.put(id, server.client());
return server;
nodes.put(id, node);
clients.put(id, node.client());
return node;
}
public void closeServer(String id) {
public void closeNode(String id) {
Client client = clients.remove(id);
if (client != null) {
client.close();
}
Server server = servers.remove(id);
if (server != null) {
server.close();
Node node = nodes.remove(id);
if (node != null) {
node.close();
}
}
public Server server(String id) {
return servers.get(id);
public Node node(String id) {
return nodes.get(id);
}
public Client client(String id) {
return clients.get(id);
}
public void closeAllServers() {
public void closeAllNodes() {
for (Client client : clients.values()) {
client.close();
}
clients.clear();
for (Server server : servers.values()) {
server.close();
for (Node node : nodes.values()) {
node.close();
}
servers.clear();
nodes.clear();
}
}

View File

@ -24,7 +24,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -37,22 +37,22 @@ import static org.hamcrest.Matchers.*;
* @author kimchy (shay.banon)
*/
@Test
public class IndexAliasesTests extends AbstractServersTests {
public class IndexAliasesTests extends AbstractNodesTests {
protected Client client1;
protected Client client2;
@BeforeMethod public void startServers() {
startServer("server1");
startServer("server2");
@BeforeMethod public void startNodes() {
startNode("server1");
startNode("server2");
client1 = getClient1();
client2 = getClient2();
}
@AfterMethod public void closeServers() {
@AfterMethod public void closeNodes() {
client1.close();
client2.close();
closeAllServers();
closeAllNodes();
}
protected Client getClient1() {

View File

@ -26,7 +26,7 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.Unicode;
import org.elasticsearch.util.json.JsonBuilder;
import org.testng.annotations.AfterMethod;
@ -43,14 +43,14 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (shay.banon)
*/
public class BroadcastActionsTests extends AbstractServersTests {
public class BroadcastActionsTests extends AbstractNodesTests {
@AfterMethod public void closeServers() {
closeAllServers();
closeAllNodes();
}
@Test public void testBroadcastOperations() throws IOException {
startServer("server1");
startNode("server1");
client("server1").admin().indices().create(createIndexRequest("test")).actionGet(5000);

View File

@ -21,7 +21,7 @@ package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.search.TransportTwoServersSearchTests;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.util.transport.TransportAddress;
@ -32,7 +32,7 @@ import org.elasticsearch.util.transport.TransportAddress;
public class ClientTransportTwoServersSearchTests extends TransportTwoServersSearchTests {
@Override protected Client getClient() {
TransportAddress server1Address = ((InternalServer) server("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient();
client.addTransportAddress(server1Address);
return client;

View File

@ -20,7 +20,7 @@
package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.settings.ImmutableSettings;
import org.testng.annotations.AfterMethod;
@ -29,7 +29,7 @@ import static org.elasticsearch.client.Requests.*;
/**
* @author kimchy (Shay Banon)
*/
public class DiscoveryTransportClientTests extends AbstractServersTests {
public class DiscoveryTransportClientTests extends AbstractNodesTests {
private TransportClient client;
@ -37,13 +37,13 @@ public class DiscoveryTransportClientTests extends AbstractServersTests {
if (client != null) {
client.close();
}
closeAllServers();
closeAllNodes();
}
/*@Test*/
public void testWithDiscovery() throws Exception {
startServer("server1");
startNode("server1");
client = new TransportClient(ImmutableSettings.settingsBuilder().put("discovery.enabled", true).build());
// wait a bit so nodes will be discovered
Thread.sleep(1000);
@ -51,13 +51,13 @@ public class DiscoveryTransportClientTests extends AbstractServersTests {
Thread.sleep(500);
client.admin().cluster().ping(pingSingleRequest("test").type("person").id("1")).actionGet();
startServer("server2");
startNode("server2");
Thread.sleep(1000);
client.admin().cluster().ping(pingSingleRequest("test").type("person").id("1")).actionGet();
closeServer("server1");
closeNode("server1");
Thread.sleep(10000);
client.admin().cluster().ping(pingSingleRequest("test").type("person").id("1")).actionGet();
closeServer("server2");
closeNode("server2");
client.admin().cluster().ping(pingSingleRequest("test").type("person").id("1")).actionGet();
}

View File

@ -21,7 +21,7 @@ package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.document.DocumentActionsTests;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.util.transport.TransportAddress;
@ -34,14 +34,14 @@ import static org.elasticsearch.util.settings.ImmutableSettings.*;
public class TransportClientDocumentActionsTests extends DocumentActionsTests {
@Override protected Client getClient1() {
TransportAddress server1Address = ((InternalServer) server("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("discovery.enabled", false).build());
client.addTransportAddress(server1Address);
return client;
}
@Override protected Client getClient2() {
TransportAddress server1Address = ((InternalServer) server("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportAddress server1Address = ((InternalNode) node("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("discovery.enabled", false).build());
client.addTransportAddress(server1Address);
return client;

View File

@ -21,7 +21,7 @@ package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.document.MoreLikeThisActionTests;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.util.transport.TransportAddress;
@ -34,14 +34,14 @@ import static org.elasticsearch.util.settings.ImmutableSettings.*;
public class TransportClientMoreLikeThisActionTests extends MoreLikeThisActionTests {
@Override protected Client getClient1() {
TransportAddress server1Address = ((InternalServer) server("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("discovery.enabled", false).build());
client.addTransportAddress(server1Address);
return client;
}
@Override protected Client getClient2() {
TransportAddress server1Address = ((InternalServer) server("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportAddress server1Address = ((InternalNode) node("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("discovery.enabled", false).build());
client.addTransportAddress(server1Address);
return client;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.test.integration.datanode;
import org.elasticsearch.action.PrimaryNotStartedActionException;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Requests;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@ -35,14 +35,14 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (Shay Banon)
*/
public class SimpleDataNodesTests extends AbstractServersTests {
public class SimpleDataNodesTests extends AbstractNodesTests {
@AfterMethod public void closeServers() {
closeAllServers();
@AfterMethod public void closeNodes() {
closeAllNodes();
}
@Test public void testDataNodes() throws Exception {
startServer("nonData1", settingsBuilder().put("node.data", false).build());
startNode("nonData1", settingsBuilder().put("node.data", false).build());
client("nonData1").admin().indices().create(createIndexRequest("test")).actionGet();
try {
client("nonData1").index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test")).timeout(timeValueSeconds(1))).actionGet();
@ -51,7 +51,7 @@ public class SimpleDataNodesTests extends AbstractServersTests {
// all is well
}
startServer("nonData2", settingsBuilder().put("node.data", false).build());
startNode("nonData2", settingsBuilder().put("node.data", false).build());
Thread.sleep(500);
// still no shard should be allocated
@ -63,7 +63,7 @@ public class SimpleDataNodesTests extends AbstractServersTests {
}
// now, start a node data, and see that it gets with shards
startServer("data1", settingsBuilder().put("node.data", true).build());
startNode("data1", settingsBuilder().put("node.data", true).build());
Thread.sleep(500);
IndexResponse indexResponse = client("nonData2").index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test"))).actionGet();

View File

@ -32,7 +32,7 @@ import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.Client;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.Unicode;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@ -48,14 +48,14 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (shay.banon)
*/
public class DocumentActionsTests extends AbstractServersTests {
public class DocumentActionsTests extends AbstractNodesTests {
protected Client client1;
protected Client client2;
@BeforeMethod public void startServers() {
startServer("server1");
startServer("server2");
@BeforeMethod public void startNodes() {
startNode("server1");
startNode("server2");
client1 = getClient1();
client2 = getClient2();
createIndex();
@ -70,10 +70,10 @@ public class DocumentActionsTests extends AbstractServersTests {
return "test";
}
@AfterMethod public void closeServers() {
@AfterMethod public void closeNodes() {
client1.close();
client2.close();
closeAllServers();
closeAllNodes();
}
protected Client getClient1() {

View File

@ -23,7 +23,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -36,14 +36,14 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (shay.banon)
*/
public class MoreLikeThisActionTests extends AbstractServersTests {
public class MoreLikeThisActionTests extends AbstractNodesTests {
private Client client1;
private Client client2;
@BeforeMethod public void startServers() {
startServer("server1");
startServer("server2");
startNode("server1");
startNode("server2");
client1 = getClient1();
client2 = getClient2();
}
@ -51,7 +51,7 @@ public class MoreLikeThisActionTests extends AbstractServersTests {
@AfterMethod public void closeServers() {
client1.close();
client2.close();
closeAllServers();
closeAllNodes();
}
protected Client getClient1() {

View File

@ -26,8 +26,8 @@ import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Requests;
import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -39,23 +39,23 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (Shay Banon)
*/
public abstract class AbstractSimpleIndexGatewayTests extends AbstractServersTests {
public abstract class AbstractSimpleIndexGatewayTests extends AbstractNodesTests {
@AfterMethod public void closeServers() {
server("server1").stop();
@AfterMethod public void closeNodes() {
node("server1").stop();
// since we store (by default) the index snapshot under the gateway, resetting it will reset the index data as well
((InternalServer) server("server1")).injector().getInstance(Gateway.class).reset();
closeAllServers();
((InternalNode) node("server1")).injector().getInstance(Gateway.class).reset();
closeAllNodes();
}
@BeforeMethod public void buildServer1() {
buildServer("server1");
@BeforeMethod public void buildNode1() {
buildNode("server1");
// since we store (by default) the index snapshot under the gateway, resetting it will reset the index data as well
((InternalServer) server("server1")).injector().getInstance(Gateway.class).reset();
((InternalNode) node("server1")).injector().getInstance(Gateway.class).reset();
}
@Test public void testSnapshotOperations() throws Exception {
server("server1").start();
node("server1").start();
// Translog tests
@ -87,9 +87,9 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractServersTes
client("server1").admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet();
logger.info("Closing the server");
closeServer("server1");
closeNode("server1");
logger.info("Starting the server, should recover from the gateway (only translog should be populated)");
startServer("server1");
startNode("server1");
logger.info("Running Cluster Health (wait for the shards to startup)");
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForYellowStatus()).actionGet();
@ -120,9 +120,9 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractServersTes
client("server1").admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet();
logger.info("Closing the server");
closeServer("server1");
closeNode("server1");
logger.info("Starting the server, should recover from the gateway (both index and translog)");
startServer("server1");
startNode("server1");
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForYellowStatus()).actionGet();
@ -149,9 +149,9 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractServersTes
client("server1").admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet();
logger.info("Closing the server");
closeServer("server1");
closeNode("server1");
logger.info("Starting the server, should recover from the gateway (just from the index, nothing in the translog)");
startServer("server1");
startNode("server1");
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForYellowStatus()).actionGet();

View File

@ -21,8 +21,8 @@ package org.elasticsearch.test.integration.gateway.fs;
import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -32,31 +32,31 @@ import static org.elasticsearch.client.Requests.*;
/**
* @author kimchy (Shay Banon)
*/
public class FsMetaDataGatewayTests extends AbstractServersTests {
public class FsMetaDataGatewayTests extends AbstractNodesTests {
@AfterMethod void closeServers() {
server("server1").stop();
@AfterMethod void closeNodes() {
node("server1").stop();
// since we store (by default) the index snapshot under the gateway, resetting it will reset the index data as well
((InternalServer) server("server1")).injector().getInstance(Gateway.class).reset();
closeAllServers();
((InternalNode) node("server1")).injector().getInstance(Gateway.class).reset();
closeAllNodes();
}
@BeforeMethod void buildServer1() {
buildServer("server1");
@BeforeMethod void buildNode1() {
buildNode("server1");
// since we store (by default) the index snapshot under the gateway, resetting it will reset the index data as well
((InternalServer) server("server1")).injector().getInstance(Gateway.class).reset();
((InternalNode) node("server1")).injector().getInstance(Gateway.class).reset();
}
@Test public void testIndexActions() throws Exception {
buildServer("server1");
((InternalServer) server("server1")).injector().getInstance(Gateway.class).reset();
server("server1").start();
buildNode("server1");
((InternalNode) node("server1")).injector().getInstance(Gateway.class).reset();
node("server1").start();
client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
closeServer("server1");
closeNode("server1");
startServer("server1");
startNode("server1");
try {
client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
assert false : "index should exists";

View File

@ -26,8 +26,8 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.routing.RoutingNode;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.logging.Loggers;
import org.elasticsearch.util.settings.Settings;
import org.slf4j.Logger;
@ -44,12 +44,12 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (Shay Banon)
*/
public class IndexLifecycleActionTests extends AbstractServersTests {
public class IndexLifecycleActionTests extends AbstractNodesTests {
private final Logger logger = Loggers.getLogger(IndexLifecycleActionTests.class);
@AfterMethod public void closeServers() {
closeAllServers();
@AfterMethod public void closeNodes() {
closeAllNodes();
}
@Test public void testIndexLifecycleActionsWith11Shards1Backup() throws Exception {
@ -60,9 +60,9 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
// start one server
logger.info("Starting sever1");
startServer("server1", settings);
startNode("server1", settings);
ClusterService clusterService1 = ((InternalServer) server("server1")).injector().getInstance(ClusterService.class);
ClusterService clusterService1 = ((InternalNode) node("server1")).injector().getInstance(ClusterService.class);
logger.info("Creating index [test]");
CreateIndexResponse createIndexResponse = client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
@ -88,10 +88,10 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
logger.info("Starting server2");
// start another server
startServer("server2", settings);
startNode("server2", settings);
Thread.sleep(200);
ClusterService clusterService2 = ((InternalServer) server("server2")).injector().getInstance(ClusterService.class);
ClusterService clusterService2 = ((InternalNode) node("server2")).injector().getInstance(ClusterService.class);
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
@ -112,10 +112,10 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
logger.info("Starting server3");
// start another server
startServer("server3", settings);
startNode("server3", settings);
Thread.sleep(200);
ClusterService clusterService3 = ((InternalServer) server("server3")).injector().getInstance(ClusterService.class);
ClusterService clusterService3 = ((InternalNode) node("server3")).injector().getInstance(ClusterService.class);
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForRelocatingShards(0)).actionGet();
@ -145,7 +145,7 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
logger.info("Closing server1");
// kill the first server
closeServer("server1");
closeNode("server1");
// wait a bit so it will be discovered as removed
Thread.sleep(200);
// verify health
@ -195,9 +195,9 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
// start one server
logger.info("Starting server1");
startServer("server1", settings);
startNode("server1", settings);
ClusterService clusterService1 = ((InternalServer) server("server1")).injector().getInstance(ClusterService.class);
ClusterService clusterService1 = ((InternalNode) node("server1")).injector().getInstance(ClusterService.class);
logger.info("Creating index [test]");
CreateIndexResponse createIndexResponse = client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
@ -218,7 +218,7 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
// start another server
logger.info("Starting server2");
startServer("server2", settings);
startNode("server2", settings);
// wait a bit
Thread.sleep(200);
@ -234,7 +234,7 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
// sleep till the cluster state gets published, since we check the master
Thread.sleep(200);
ClusterService clusterService2 = ((InternalServer) server("server2")).injector().getInstance(ClusterService.class);
ClusterService clusterService2 = ((InternalNode) node("server2")).injector().getInstance(ClusterService.class);
clusterState1 = clusterService1.state();
routingNodeEntry1 = clusterState1.readOnlyRoutingNodes().nodesToShards().get(clusterState1.nodes().localNodeId());
@ -246,11 +246,11 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
// start another server
logger.info("Starting server3");
startServer("server3");
startNode("server3");
// wait a bit so assignment will start
Thread.sleep(200);
ClusterService clusterService3 = ((InternalServer) server("server3")).injector().getInstance(ClusterService.class);
ClusterService clusterService3 = ((InternalNode) node("server3")).injector().getInstance(ClusterService.class);
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForRelocatingShards(0)).actionGet();
@ -280,7 +280,7 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
logger.info("Closing server1");
// kill the first server
closeServer("server1");
closeNode("server1");
// wait a bit so it will be discovered as removed
Thread.sleep(200);
@ -328,7 +328,7 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
.build();
// start one server
startServer("server1", settings);
startNode("server1", settings);
client("server1").admin().indices().create(createIndexRequest("test1")).actionGet();
client("server1").admin().indices().create(createIndexRequest("test2")).actionGet();
}

View File

@ -21,8 +21,8 @@ package org.elasticsearch.test.integration.nodesinfo;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@ -33,17 +33,17 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (Shay Banon)
*/
public class SimpleNodesInfoTests extends AbstractServersTests {
public class SimpleNodesInfoTests extends AbstractNodesTests {
@AfterMethod public void closeServers() {
closeAllServers();
@AfterMethod public void closeNodes() {
closeAllNodes();
}
@Test public void testNodesInfos() {
startServer("server1");
startServer("server2");
String server1NodeId = ((InternalServer) server("server1")).injector().getInstance(ClusterService.class).state().nodes().localNodeId();
String server2NodeId = ((InternalServer) server("server2")).injector().getInstance(ClusterService.class).state().nodes().localNodeId();
startNode("server1");
startNode("server2");
String server1NodeId = ((InternalNode) node("server1")).injector().getInstance(ClusterService.class).state().nodes().localNodeId();
String server2NodeId = ((InternalNode) node("server2")).injector().getInstance(ClusterService.class).state().nodes().localNodeId();
NodesInfoResponse response = client("server1").admin().cluster().nodesInfo(nodesInfo()).actionGet();
assertThat(response.nodes().length, equalTo(2));

View File

@ -22,7 +22,7 @@ package org.elasticsearch.test.integration.ping;
import org.elasticsearch.action.admin.cluster.ping.broadcast.BroadcastPingResponse;
import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingResponse;
import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.logging.Loggers;
import org.slf4j.Logger;
import org.testng.annotations.AfterMethod;
@ -36,17 +36,17 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (Shay Banon)
*/
public class PingActionTests extends AbstractServersTests {
public class PingActionTests extends AbstractNodesTests {
private final Logger logger = Loggers.getLogger(PingActionTests.class);
@BeforeMethod public void startServers() {
startServer("server1");
startServer("server2");
@BeforeMethod public void startNodes() {
startNode("server1");
startNode("server2");
}
@AfterMethod public void closeServers() {
closeAllServers();
@AfterMethod public void closeNodes() {
closeAllNodes();
}
@Test public void testIndexActions() throws Exception {

View File

@ -24,7 +24,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@ -35,14 +35,14 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (shay.banon)
*/
public class SimpleRecoveryTests extends AbstractServersTests {
public class SimpleRecoveryTests extends AbstractNodesTests {
@AfterMethod public void closeServers() {
closeAllServers();
@AfterMethod public void closeNodes() {
closeAllNodes();
}
@Test public void testSimpleRecovery() throws Exception {
startServer("server1");
startNode("server1");
client("server1").admin().indices().create(createIndexRequest("test")).actionGet(5000);
@ -63,7 +63,7 @@ public class SimpleRecoveryTests extends AbstractServersTests {
assertThat(refreshResponse.successfulShards(), equalTo(5));
assertThat(refreshResponse.failedShards(), equalTo(0));
startServer("server2");
startNode("server2");
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
@ -85,7 +85,7 @@ public class SimpleRecoveryTests extends AbstractServersTests {
}
// now start another one so we move some primaries
startServer("server3");
startNode("server3");
Thread.sleep(1000);
logger.info("Running Cluster Health");
clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();

View File

@ -20,6 +20,7 @@
package org.elasticsearch.test.integration.search;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.search.Scroll;
import org.elasticsearch.search.SearchContextMissingException;
import org.elasticsearch.search.SearchService;
@ -35,8 +36,7 @@ import org.elasticsearch.search.fetch.QueryFetchSearchResult;
import org.elasticsearch.search.internal.InternalSearchRequest;
import org.elasticsearch.search.query.QuerySearchRequest;
import org.elasticsearch.search.query.QuerySearchResult;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.TimeValue;
import org.elasticsearch.util.trove.ExtTIntArrayList;
import org.testng.annotations.AfterClass;
@ -55,14 +55,14 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (Shay Banon)
*/
public class SingleInstanceEmbeddedSearchTests extends AbstractServersTests {
public class SingleInstanceEmbeddedSearchTests extends AbstractNodesTests {
private SearchService searchService;
private SearchPhaseController searchPhaseController;
@BeforeClass public void createServerAndInitWithData() throws Exception {
startServer("server1");
@BeforeClass public void createNodeAndInitWithData() throws Exception {
startNode("server1");
client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
index(client("server1"), "1", "test1", 1);
@ -72,12 +72,12 @@ public class SingleInstanceEmbeddedSearchTests extends AbstractServersTests {
index(client("server1"), "5", "test5", 2);
client("server1").admin().indices().refresh(refreshRequest("test")).actionGet();
searchService = ((InternalServer) server("server1")).injector().getInstance(SearchService.class);
searchPhaseController = ((InternalServer) server("server1")).injector().getInstance(SearchPhaseController.class);
searchService = ((InternalNode) node("server1")).injector().getInstance(SearchService.class);
searchPhaseController = ((InternalNode) node("server1")).injector().getInstance(SearchPhaseController.class);
}
@AfterClass public void closeServer() {
closeAllServers();
@AfterClass public void closeNode() {
closeAllNodes();
}
@Test public void testDirectDfs() throws Exception {

View File

@ -27,7 +27,7 @@ import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.Unicode;
import org.elasticsearch.util.json.JsonBuilder;
import org.testng.annotations.AfterMethod;
@ -43,15 +43,15 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (shay.banon)
*/
public class TransportSearchFailuresTests extends AbstractServersTests {
public class TransportSearchFailuresTests extends AbstractNodesTests {
@AfterMethod public void closeServers() {
closeAllServers();
@AfterMethod public void closeNodes() {
closeAllNodes();
}
@Test public void testFailedSearchWithWrongQuery() throws Exception {
logger.info("Start Testing failed search with wrong query");
startServer("server1");
startNode("server1");
client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
for (int i = 0; i < 100; i++) {
@ -74,8 +74,8 @@ public class TransportSearchFailuresTests extends AbstractServersTests {
}
}
startServer("server2");
Thread.sleep(300);
startNode("server2");
Thread.sleep(500);
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealth("test").waitForYellowStatus().waitForRelocatingShards(0)).actionGet();

View File

@ -28,7 +28,7 @@ import org.elasticsearch.client.Requests;
import org.elasticsearch.search.Scroll;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.Unicode;
import org.elasticsearch.util.json.JsonBuilder;
import org.testng.annotations.AfterClass;
@ -51,13 +51,13 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (shay.banon)
*/
public class TransportTwoServersSearchTests extends AbstractServersTests {
public class TransportTwoServersSearchTests extends AbstractNodesTests {
private Client client;
@BeforeClass public void createServers() throws Exception {
startServer("server1");
startServer("server2");
@BeforeClass public void createNodes() throws Exception {
startNode("server1");
startNode("server2");
client = getClient();
client.admin().indices().create(createIndexRequest("test")).actionGet();
@ -70,7 +70,7 @@ public class TransportTwoServersSearchTests extends AbstractServersTests {
@AfterClass public void closeServers() {
client.close();
closeAllServers();
closeAllNodes();
}
protected Client getClient() {

View File

@ -27,6 +27,7 @@ import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardsIterator;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.search.*;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.controller.SearchPhaseController;
@ -42,8 +43,7 @@ import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.search.query.QuerySearchRequest;
import org.elasticsearch.search.query.QuerySearchResult;
import org.elasticsearch.search.query.QuerySearchResultProvider;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.TimeValue;
import org.elasticsearch.util.trove.ExtTIntArrayList;
import org.testng.annotations.AfterClass;
@ -67,7 +67,7 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (Shay Banon)
*/
public class TwoInstanceEmbeddedSearchTests extends AbstractServersTests {
public class TwoInstanceEmbeddedSearchTests extends AbstractNodesTests {
private IndicesService indicesService;
@ -77,12 +77,12 @@ public class TwoInstanceEmbeddedSearchTests extends AbstractServersTests {
private SearchPhaseController searchPhaseController;
@BeforeClass public void createServerAndInitWithData() throws Exception {
startServer("server1");
startServer("server2");
@BeforeClass public void createNodeAndInitWithData() throws Exception {
startNode("server1");
startNode("server2");
clusterService = ((InternalServer) server("server1")).injector().getInstance(ClusterService.class);
indicesService = ((InternalServer) server("server1")).injector().getInstance(IndicesService.class);
clusterService = ((InternalNode) node("server1")).injector().getInstance(ClusterService.class);
indicesService = ((InternalNode) node("server1")).injector().getInstance(IndicesService.class);
client("server1").admin().indices().create(Requests.createIndexRequest("test")).actionGet();
for (int i = 0; i < 100; i++) {
@ -90,19 +90,19 @@ public class TwoInstanceEmbeddedSearchTests extends AbstractServersTests {
}
client("server1").admin().indices().refresh(refreshRequest("test")).actionGet();
SearchService searchService1 = ((InternalServer) server("server1")).injector().getInstance(SearchService.class);
SearchService searchService2 = ((InternalServer) server("server2")).injector().getInstance(SearchService.class);
SearchService searchService1 = ((InternalNode) node("server1")).injector().getInstance(SearchService.class);
SearchService searchService2 = ((InternalNode) node("server2")).injector().getInstance(SearchService.class);
nodeToSearchService = ImmutableMap.<String, SearchService>builder()
.put(((InternalServer) server("server1")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService1)
.put(((InternalServer) server("server2")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService2)
.put(((InternalNode) node("server1")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService1)
.put(((InternalNode) node("server2")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService2)
.build();
searchPhaseController = ((InternalServer) server("server1")).injector().getInstance(SearchPhaseController.class);
searchPhaseController = ((InternalNode) node("server1")).injector().getInstance(SearchPhaseController.class);
}
@AfterClass public void closeServers() {
closeAllServers();
closeAllNodes();
}
@Test public void testDfsQueryThenFetch() throws Exception {

View File

@ -32,6 +32,7 @@ import org.elasticsearch.index.routing.OperationRouting;
import org.elasticsearch.index.routing.plain.PlainOperationRouting;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.search.*;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.controller.SearchPhaseController;
@ -47,8 +48,7 @@ import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.search.query.QuerySearchRequest;
import org.elasticsearch.search.query.QuerySearchResult;
import org.elasticsearch.search.query.QuerySearchResultProvider;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.TimeValue;
import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.trove.ExtTIntArrayList;
@ -72,7 +72,7 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (Shay Banon)
*/
public class TwoInstanceUnbalancedShardsEmbeddedSearchTests extends AbstractServersTests {
public class TwoInstanceUnbalancedShardsEmbeddedSearchTests extends AbstractNodesTests {
private IndicesService indicesService;
@ -82,12 +82,12 @@ public class TwoInstanceUnbalancedShardsEmbeddedSearchTests extends AbstractServ
private SearchPhaseController searchPhaseController;
@BeforeClass public void createServerAndInitWithData() throws Exception {
startServer("server1");
startServer("server2");
@BeforeClass public void createNodeAndInitWithData() throws Exception {
startNode("server1");
startNode("server2");
clusterService = ((InternalServer) server("server1")).injector().getInstance(ClusterService.class);
indicesService = ((InternalServer) server("server1")).injector().getInstance(IndicesService.class);
clusterService = ((InternalNode) node("server1")).injector().getInstance(ClusterService.class);
indicesService = ((InternalNode) node("server1")).injector().getInstance(IndicesService.class);
client("server1").admin().indices().create(Requests.createIndexRequest("test")).actionGet();
@ -96,19 +96,19 @@ public class TwoInstanceUnbalancedShardsEmbeddedSearchTests extends AbstractServ
}
client("server1").admin().indices().refresh(refreshRequest("test")).actionGet();
SearchService searchService1 = ((InternalServer) server("server1")).injector().getInstance(SearchService.class);
SearchService searchService2 = ((InternalServer) server("server2")).injector().getInstance(SearchService.class);
SearchService searchService1 = ((InternalNode) node("server1")).injector().getInstance(SearchService.class);
SearchService searchService2 = ((InternalNode) node("server2")).injector().getInstance(SearchService.class);
nodeToSearchService = ImmutableMap.<String, SearchService>builder()
.put(((InternalServer) server("server1")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService1)
.put(((InternalServer) server("server2")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService2)
.put(((InternalNode) node("server1")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService1)
.put(((InternalNode) node("server2")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService2)
.build();
searchPhaseController = ((InternalServer) server("server1")).injector().getInstance(SearchPhaseController.class);
searchPhaseController = ((InternalNode) node("server1")).injector().getInstance(SearchPhaseController.class);
}
@AfterClass public void closeServers() {
closeAllServers();
@AfterClass public void closeNodes() {
closeAllNodes();
}
@Test public void testDfsQueryFetch() throws Exception {

View File

@ -24,7 +24,7 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.util.json.JsonBuilder;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@ -45,13 +45,13 @@ import static org.hamcrest.Matchers.*;
/**
* @author kimchy (shay.banon)
*/
public class HighlightSearchTests extends AbstractServersTests {
public class HighlightSearchTests extends AbstractNodesTests {
private Client client;
@BeforeClass public void createServers() throws Exception {
startServer("server1");
startServer("server2");
@BeforeClass public void createNodes() throws Exception {
startNode("server1");
startNode("server2");
client = getClient();
client.admin().indices().create(createIndexRequest("test")).actionGet();
@ -65,9 +65,9 @@ public class HighlightSearchTests extends AbstractServersTests {
client.admin().indices().refresh(refreshRequest("test")).actionGet();
}
@AfterClass public void closeServers() {
@AfterClass public void closeNodes() {
client.close();
closeAllServers();
closeAllNodes();
}
protected Client getClient() {

View File

@ -21,19 +21,19 @@ package org.elasticsearch.test.integration.terms;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.server.internal.InternalServer;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.util.transport.TransportAddress;
import org.testng.annotations.Test;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
@Test
public class ClientTransportTermsActionTests extends TermsActionTests {
@Override protected Client getClient() {
TransportAddress server1Address = ((InternalServer) server("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient();
client.addTransportAddress(server1Address);
return client;

View File

@ -26,7 +26,7 @@ import org.elasticsearch.action.admin.indices.status.IndexStatus;
import org.elasticsearch.action.terms.TermsRequest;
import org.elasticsearch.action.terms.TermsResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.test.integration.AbstractServersTests;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -42,13 +42,13 @@ import static org.hamcrest.Matchers.*;
* @author kimchy (shay.banon)
*/
@Test
public class TermsActionTests extends AbstractServersTests {
public class TermsActionTests extends AbstractNodesTests {
private Client client;
@BeforeMethod public void createServersAndClient() throws Exception {
startServer("server1");
startServer("server2");
@BeforeMethod public void createNodesAndClient() throws Exception {
startNode("server1");
startNode("server2");
client = getClient();
logger.info("Creating index test");
@ -60,9 +60,9 @@ public class TermsActionTests extends AbstractServersTests {
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
}
@AfterMethod public void closeServers() {
@AfterMethod public void closeNodes() {
client.close();
closeAllServers();
closeAllNodes();
}
protected Client getClient() {

View File

@ -22,14 +22,14 @@ package org.elasticsearch.plugin.attachments.test;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.server.Server;
import org.elasticsearch.node.Node;
import org.elasticsearch.util.logging.Loggers;
import org.slf4j.Logger;
import org.testng.annotations.*;
import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.index.query.json.JsonQueryBuilders.*;
import static org.elasticsearch.server.ServerBuilder.*;
import static org.elasticsearch.node.NodeBuilder.*;
import static org.elasticsearch.util.io.Streams.*;
import static org.elasticsearch.util.json.JsonBuilder.*;
import static org.elasticsearch.util.settings.ImmutableSettings.*;
@ -44,21 +44,21 @@ public class SimpleAttachmentIntegrationTests {
private final Logger logger = Loggers.getLogger(getClass());
private Server server;
private Node node;
@BeforeClass public void setupServer() {
server = serverBuilder().settings(settingsBuilder().put("node.local", true)).server();
node = nodeBuilder().settings(settingsBuilder().put("node.local", true)).node();
}
@AfterClass public void closeServer() {
server.close();
node.close();
}
@BeforeMethod public void createIndex() {
logger.info("creating index [test]");
server.client().admin().indices().create(createIndexRequest("test").settings(settingsBuilder().put("index.numberOfReplicas", 0))).actionGet();
node.client().admin().indices().create(createIndexRequest("test").settings(settingsBuilder().put("index.numberOfReplicas", 0))).actionGet();
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = server.client().admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealth().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
@ -66,22 +66,22 @@ public class SimpleAttachmentIntegrationTests {
@AfterMethod public void deleteIndex() {
logger.info("deleting index [test]");
server.client().admin().indices().delete(deleteIndexRequest("test")).actionGet();
node.client().admin().indices().delete(deleteIndexRequest("test")).actionGet();
}
@Test public void testSimpleAttachment() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/plugin/attachments/index/mapper/test-mapping.json");
server.client().admin().indices().putMapping(putMappingRequest("test").mappingSource(mapping)).actionGet();
node.client().admin().indices().putMapping(putMappingRequest("test").mappingSource(mapping)).actionGet();
server.client().index(indexRequest("test").type("person")
node.client().index(indexRequest("test").type("person")
.source(jsonBuilder().startObject().field("file", copyToBytesFromClasspath("/org/elasticsearch/plugin/attachments/index/mapper/testXHTML.html")).endObject())).actionGet();
server.client().admin().indices().refresh(refreshRequest()).actionGet();
node.client().admin().indices().refresh(refreshRequest()).actionGet();
CountResponse countResponse = server.client().count(countRequest("test").querySource(fieldQuery("file.title", "test document"))).actionGet();
CountResponse countResponse = node.client().count(countRequest("test").querySource(fieldQuery("file.title", "test document"))).actionGet();
assertThat(countResponse.count(), equalTo(1l));
countResponse = server.client().count(countRequest("test").querySource(fieldQuery("file", "tests the ability"))).actionGet();
countResponse = node.client().count(countRequest("test").querySource(fieldQuery("file", "tests the ability"))).actionGet();
assertThat(countResponse.count(), equalTo(1l));
}
}