@Override public void execute(ClusterConfiguration config) { if (StringUtils.isBlank(config.getPathInitScript())) { // nothing to do; return return; } String filePath = config.getPathInitScript(); validateFile(filePath); // we'll run all commands against the first node in the cluster ElasticsearchClient client = new ElasticsearchClient.Builder() .withInstanceConfiguration(config.getInstanceConfigurationList().get(0)) .withHostname("localhost") .build(); Path path = Paths.get(filePath); if ("json".equalsIgnoreCase(FilenameUtils.getExtension(filePath))) { parseJson(client, config.getLog(), path); } else { parseScript(client, config.getLog(), path); } }
@Override public void execute(ClusterConfiguration config) { // the instances have already started; // waiting just 10 seconds for them to form the cluster int timeout = 10; ElasticsearchClient client = new ElasticsearchClient.Builder() .withInstanceConfiguration(config.getInstanceConfigurationList().get(0)) .withHostname("localhost") .build(); Monitor monitor = new Monitor(client, config.getLog()); monitor.waitToStartCluster( config.getClusterName(), config.getInstanceConfigurationList().size(), timeout); } }
/** * Check whether the cluster with the given name exists in the ES running on the given port. * @param clusterName the ES cluster name * @param httpPort the HTTP port to connect to ES * @return true if the instance is running, false otherwise */ public static boolean isInstanceRunning(String clusterName, int httpPort) { Log log = Mockito.mock(Log.class); ElasticsearchClient client = new ElasticsearchClient.Builder() .withLog(log) .withHostname("localhost") .withPort(httpPort) .withSocketTimeout(5000) .build(); return isInstanceRunning(clusterName, client); }
/** * Verify that the cluster name and the number of nodes in the cluster, * as reported by the ES node, is as expected. * @param clusterName the ES cluster name * @param instanceCount the number of ES nodes in the cluster * @param httpPort the HTTP port to connect to ES * @return true if the cluster is running, false otherwise */ public static boolean isClusterRunning(String clusterName, int instanceCount, int httpPort) { Log log = Mockito.mock(Log.class); ElasticsearchClient client = new ElasticsearchClient.Builder() .withLog(log) .withHostname("localhost") .withPort(httpPort) .withSocketTimeout(5000) .build(); return isClusterRunning(clusterName, instanceCount, client); } }
@Override public void execute(InstanceConfiguration config) { int timeout = config.getClusterConfiguration().getTimeout(); ElasticsearchClient client = new ElasticsearchClient.Builder() .withInstanceConfiguration(config) .withHostname("localhost") .build(); Monitor monitor = new Monitor(client, config.getClusterConfiguration().getLog()); monitor.waitToStartInstance( config.getBaseDir(), config.getClusterConfiguration().getClusterName(), timeout); } }
@Before public void before() { client = new ElasticsearchClient.Builder() .withLog(log) .withHostname("localhost") .withPort(httpPort) .withSocketTimeout(5000) .build(); }