All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.alexcojocaru.mojo.elasticsearch.v2.step.ValidateUniquePortsStep Maven / Gradle / Ivy

Go to download

A Maven plugin to run a single node Elasticsearch cluster during the integration test phase of a build

There is a newer version: 6.28
Show newest version
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, ',') + "]");
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy