/** * Verify that the given file path is a valid reference to an existing file on the disk. * @param filePath */ protected void validateFile(String filePath) { if (new File(filePath).isFile() == false) { throw new ElasticsearchSetupException( "The provided init script path is not a valid file path: " + filePath); } }
@Override public void execute(ClusterConfiguration config) { int instanceCount = config.getInstanceConfigurationList().size(); if (instanceCount < 1) { throw new ElasticsearchSetupException(String.format( "The number of instances should not be smaller than 1; you configured: %d", instanceCount)); } }
@Override public void execute(ClusterConfiguration config) { String pathConf = config.getPathConf(); if (StringUtils.isNotBlank(pathConf) && new File(pathConf).isDirectory() == false) { throw new ElasticsearchSetupException(String.format( "The value of the 'pathConf' parameter ('%1$s') must be the absolute path" + " (or relative to the maven project) of an existing directory.", pathConf)); } }
@Override public void execute(ClusterConfiguration config) { String clusterName = config.getClusterName(); if (clusterName == null) { throw new ElasticsearchSetupException(String.format( "Please provide a cluster name.")); } if (clusterName.matches("[a-zA-Z0-9.-]+") == false) { throw new ElasticsearchSetupException(String.format( "elasticsearch-maven-plugin supports only alphanumeric with dots and dashes cluster names. You configured: %s.", clusterName)); } }
@Override public void execute(ClusterConfiguration config) { String version = config.getVersion(); if (StringUtils.isBlank(version)) { throw new ElasticsearchSetupException(String.format( "Please provide a valid Elasticsearch version.")); } if (VersionUtil.isUnder_5_0_0(version)) { throw new ElasticsearchSetupException(String.format( "elasticsearch-maven-plugin supports only versions 5+ of Elasticsearch. You configured: %s.", version)); } }
protected void parseJson(ElasticsearchClient client, Log log, Path path) { try { String json = new String(Files.readAllBytes(path)); List<Map<String, Object>> commands = new ObjectMapper().readValue( json, new TypeReference<List<Map<String, Object>>>(){}); commands.forEach(command -> { log.debug(String.format("Parsing command: %s", command)); ElasticsearchCommand esCommand = parseMapCommand(command); executeInitCommand(client, log, esCommand); }); } catch (IOException e) { throw new ElasticsearchSetupException("Cannot read the init json file", e); } }
@Override public void execute(ClusterConfiguration config) { String baseDir = config.getInstanceConfigurationList().get(0).getBaseDir(); try { Validate.notBlank(baseDir); new File(baseDir).getCanonicalPath(); // this should catch erroneous paths } catch (Exception e) { throw new ElasticsearchSetupException(String.format( "The value of the 'baseDir' parameter ('%1$s') is not a valid file path.", baseDir)); } }
@Override public void execute(ClusterConfiguration config) { List<Integer> httpPorts = new ArrayList<>(); List<Integer> transportPorts = new ArrayList<>(); config.getInstanceConfigurationList().forEach(instanceConfig -> { httpPorts.add(instanceConfig.getHttpPort()); transportPorts.add(instanceConfig.getTransportPort()); }); // create additional sets to verify that there are no duplicates within the source lists Set<Integer> httpPortsSet = new HashSet<>(httpPorts); Set<Integer> transportPortsSet = new HashSet<>(transportPorts); Set<Integer> intersection = new HashSet<>(httpPortsSet); intersection.retainAll(transportPortsSet); if (httpPortsSet.size() != httpPorts.size() || transportPortsSet.size() != transportPorts.size() || intersection.size() > 0) { throw new ElasticsearchSetupException( "We have conflicting ports in the list of HTTP ports [" + StringUtils.join(httpPorts, ',') + "] and the list of transport ports [" + StringUtils.join(transportPorts, ',') + "]"); } }
throw new ElasticsearchSetupException( "Cannot get the current process environment", ex);
@Override public void execute(ClusterConfiguration config) { List<Integer> ports = new ArrayList<>(); // Iterate twice, because I want to maintain the order: // HTTP ports first, then transport ports config.getInstanceConfigurationList().forEach(instanceConfig -> { ports.add(instanceConfig.getHttpPort()); }); config.getInstanceConfigurationList().forEach(instanceConfig -> { ports.add(instanceConfig.getTransportPort()); }); List<Integer> protectedPorts = ports.stream() .filter(port -> port < 1024) .collect(Collectors.toList()); if (protectedPorts.size() > 0) { throw new ElasticsearchSetupException(String.format( "The following provided or inferred ports are protected (below 1024): %s", StringUtils.join(protectedPorts, ','))); } }
protected void parseScript(ElasticsearchClient client, Log log, Path path) { try (Stream<String> stream = Files.lines(path)) { stream.forEach(command -> { log.debug(String.format("Parsing command: %s", command)); ElasticsearchCommand esCommand = parseStringCommand(command); if (esCommand.isSkip() == false) { executeInitCommand(client, log, esCommand); } }); } catch (IOException e) { throw new ElasticsearchSetupException("Cannot read the init script file", 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).")); } }
throw new ElasticsearchSetupException( "Command '" + command + "' in the script file is not properly formatted." + " The format is: REQUEST_METHOD:path:json_script."
throw new ElasticsearchSetupException( "Cannot serialize the JSON payload for command '" + command + "'", e);
throw new ElasticsearchSetupException(String.format( "Elasticsearch [%d]: Command '%s' in directory '%s' finished with exit code %d; see above for details", instanceId, command, baseDir, exitCode)); message.append(StringUtils.join(error, lineSeparator)); throw new ElasticsearchSetupException(message.toString(), e);
throw new ElasticsearchSetupException( "Cannot check if the plugins directory exists", e);
throw new ElasticsearchSetupException( String.format("Cannot execute command %s", command), e);