com.github.alexcojocaru.mojo.elasticsearch.v2.step.ValidatePortsStep Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-maven-plugin Show documentation
Show all versions of elasticsearch-maven-plugin Show documentation
A Maven plugin to run a single node Elasticsearch cluster during the integration test phase of a build
package com.github.alexcojocaru.mojo.elasticsearch.v2.step;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import com.github.alexcojocaru.mojo.elasticsearch.v2.ClusterConfiguration;
import com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException;
/**
* Validate that the provided and inferred HTTP and transport ports are not protected
* (ie. less than 1024).
*
* @author Alex Cojocaru
*/
public class ValidatePortsStep
implements ClusterStep
{
@Override
public void execute(ClusterConfiguration config)
{
List 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 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, ',')));
}
}
}