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

com.github.alexcojocaru.mojo.elasticsearch.v2.step.ValidatePortsStep 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.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, ',')));
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy