com.github.alexcojocaru.mojo.elasticsearch.v2.step.ValidateUniquePortsStep 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.HashSet;
import java.util.List;
import java.util.Set;
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 all provided and inferred HTTP and transport ports are unique.
*
* @author Alex Cojocaru
*/
public class ValidateUniquePortsStep
implements ClusterStep
{
@Override
public void execute(ClusterConfiguration config)
{
List httpPorts = new ArrayList<>();
List 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 httpPortsSet = new HashSet<>(httpPorts);
Set transportPortsSet = new HashSet<>(transportPorts);
Set 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, ',') + "]");
}
}
}