public ForkedElasticsearchProcessDestroyer(final InstanceConfiguration config) { this.log = config.getClusterConfiguration().getLog(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { ForkedElasticsearchProcessDestroyer.this.terminateProcess(config); } }); }
private void cleanUp(File unpackDirectory, ClusterConfiguration config) { if (unpackDirectory != null) { try { FileUtils.deleteDirectory(unpackDirectory); } catch (IOException e) { config.getLog().error( String.format( "Could not delete Elasticsearch upack directory : ", unpackDirectory.getAbsolutePath()), e); } } }
@Override public void execute(ClusterConfiguration config) { String flavour = config.getFlavour(); String version = config.getVersion(); config.getLog().debug( "Checking flavour '" + flavour + "' against version '" + version + "'"); if (StringUtils.isNotBlank(flavour) && VersionUtil.isBetween_5_0_0_and_6_2_x(version)) { throw new ElasticsearchSetupException(String.format( "The flavour property is not supported for Elasticsearch [5.0.0 - 6.3.0).")); } }
/** * Download the artifact from the download repository. * @param artifactReference * @param config * @return the downloaded file * @throws IOException */ private File downloadArtifact( ElasticsearchArtifact artifactReference, ClusterConfiguration config) throws IOException { String filename = String.format( ELASTICSEARCH_FILENAME, artifactReference.getArtifactId(), artifactReference.getVersion()); File tempFile = new File(FilesystemUtil.getTempDirectory(), filename); tempFile.deleteOnExit(); FileUtils.deleteQuietly(tempFile); URL downloadUrl = new URL( StringUtils.isBlank(config.getDownloadUrl()) ? String.format(ELASTICSEARCH_DOWNLOAD_URL, filename) : config.getDownloadUrl()); config.getLog().debug("Downloading " + downloadUrl + " to " + tempFile); FileUtils.copyURLToFile(downloadUrl, tempFile); return tempFile; }
@Override public void execute(ClusterConfiguration config) { if (config.isSetAwait()) { new ExecutionLock(config.getLog()).lock(); } }
@Before public void setup() { when(config.getLog()).thenReturn(log); when(instanceConfig.getClusterConfiguration()).thenReturn(config); when(config.getInstanceConfigurationList()).thenReturn(Arrays.asList(instanceConfig)); }
public Builder withInstanceConfiguration(InstanceConfiguration config) { this.log = config.getClusterConfiguration().getLog(); this.socketTimeout = config.getClusterConfiguration().getClientSocketTimeout(); this.port = config.getHttpPort(); return this; }
@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); } }
config.getLog().debug("Artifact ref: " + artifactReference); config.getLog().debug("Resolving artifact against the local maven repo (stage 1)"); return artifactResolver .resolveArtifact(artifactReference.getArtifactCoordinates()); config.getLog().debug("Artifact not found; downloading and installing it"); config.getLog().debug("Installing " + tempFile + " in the local maven repo"); config.getArtifactInstaller().installArtifact( artifactReference.getGroupId(), tempFile); config.getLog().debug("Resolving artifact against the local maven repo (stage 2)"); return artifactResolver .resolveArtifact(artifactReference.getArtifactCoordinates());
boolean disableLogging) Log log = config.getClusterConfiguration().getLog(); int instanceId = config.getId(); File baseDir = new File(config.getBaseDir());
@Override public void execute(InstanceConfiguration config) Log log = config.getClusterConfiguration().getLog();
@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); } }
Log log = config.getClusterConfiguration().getLog();
@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); } }