Giter VIP home page Giter VIP logo

Comments (9)

alexcojocaru avatar alexcojocaru commented on June 28, 2024 1

You have a couple of options to address this issue:

  • do not run such jobs in parallel on the same build machine
  • use a random ES port for each build (see below for details)

You can use this plugin config:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.9.1</version>
    <executions>
        <execution>
            <id>es-ports</id>
            <phase>generate-test-resources</phase>
            <goals>
                <!-- called during generate-test-resources and records unused port numbers in ${es.http.port} and ${es.tcp.port} -->
                <goal>reserve-network-port</goal>
            </goals>
            <configuration>
                <portNames>
                    <portName>es.http.port</portName>
                    <portName>es.tcp.port</portName>
                </portNames>
            </configuration>
        </execution>
    </executions>
</plugin>

to reserve two random port on the local machine to be used by the ES server.
You can than pass the ports (properties) to the ES plugin (to start the server) and to your application (to connect to the ES server using those 2 ports).
That's how I have configured one of my projects to start a local MySQL server on a random port in the pre-integration-test phase, and to start an application (in the same phase) which connects to the MySQL server on that port.

I hope that helps.

from elasticsearch-maven-plugin.

angelcervera avatar angelcervera commented on June 28, 2024

I think that the problem is that Jenkins is executing the integration test in few jobs at the same time (because we have few jobs per different environment and pipelines)

I am not going to remove the issue because maybe is useful for other people.

Regards.

from elasticsearch-maven-plugin.

angelcervera avatar angelcervera commented on June 28, 2024

Cool! Thanks @alexcojocaru

from elasticsearch-maven-plugin.

g3kr avatar g3kr commented on June 28, 2024

I am kind of experiencing a similar problem where I need ES to run in a different port if one of the ports is in use

 <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.9.1</version>
            <executions>
                <execution>
                    <id>es-ports</id>
                    <phase>generate-test-resources</phase>
                    <goals>
                        <!-- called during generate-test-resources and records unused port numbers in ${es.http.port} and ${es.tcp.port} -->
                        <goal>reserve-network-port</goal>
                    </goals>
                    <configuration>
                        <portNames>
                            <portName>es.http.port</portName>
                            <portName>es.tcp.port</portName>
                        </portNames>
                    </configuration>
                </execution>
            </executions>
        </plugin>
      <plugin>
        <groupId>com.github.alexcojocaru</groupId>
        <artifactId>elasticsearch-maven-plugin</artifactId>
        <version>5.7</version>
        <configuration>
          <clusterName>testCluster</clusterName>
          <transportPort>${es.tcp.port}</transportPort>
          <httpPort>${es.http.port}</httpPort>
          <version>6.0.0</version>
          <autoCreateIndex>true</autoCreateIndex>
          <pathInitScript> src/test/resources/initialize/Init.script</pathInitScript>
        </configuration>
        <executions>
          <execution>
            <id>start-elasticsearch</id>
            <phase>process-test-classes</phase>
            <goals>
              <goal>runforked</goal>
            </goals>
          </execution>
          <execution>
            <id>stop-elasticsearch</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

I am using 2 plugins here - one for reserving network port and the other is for spinning up ES. I wasn't sure how the port numbers will be passed through properties. Can it be a comma separated list of ports? any examples?

from elasticsearch-maven-plugin.

alexcojocaru avatar alexcojocaru commented on June 28, 2024

No, it cannot be a list of ports. Your configuration above looks correct. Are you having issues with it?

from elasticsearch-maven-plugin.

g3kr avatar g3kr commented on June 28, 2024

Still finding it difficult to comprehend.

The properties tag in pom.xml

> <properties>
>    <es.http.port>9400</es.http.port>
>     <es.tcp.port>9500</es.tcp.port>
> </properties> 

In this case I supply only 2 ports one for TCP and the other for HTTP.
If these are already in use, how does it know to choose a different one?

from elasticsearch-maven-plugin.

alexcojocaru avatar alexcojocaru commented on June 28, 2024

It does not choose a different one, if the provided ones are in use.
The snippet in your previous comment does use random port numbers, which are reserved, meaning the ES instance should not run into the "address already in use" problem.

from elasticsearch-maven-plugin.

g3kr avatar g3kr commented on June 28, 2024

Does that mean I need not set the port numbers in the properties tag? The below snippet should work all by itself?

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.9.1</version>
            <executions>
                <execution>
                    <id>es-ports</id>
                    <phase>generate-test-resources</phase>
                    <goals>
                        <!-- called during generate-test-resources and records unused port numbers in ${es.http.port} and ${es.tcp.port} -->
                        <goal>reserve-network-port</goal>
                    </goals>
                    <configuration>
                        <portNames>
                            <portName>es.http.port</portName>
                            <portName>es.tcp.port</portName>
                        </portNames>
                    </configuration>
                </execution>
            </executions>
        </plugin>
      <plugin>
        <groupId>com.github.alexcojocaru</groupId>
        <artifactId>elasticsearch-maven-plugin</artifactId>
        <version>5.7</version>
        <configuration>
          <clusterName>testCluster</clusterName>
          <transportPort>${es.tcp.port}</transportPort>
          <httpPort>${es.http.port}</httpPort>
          <version>6.0.0</version>
          <autoCreateIndex>true</autoCreateIndex>
          <pathInitScript> src/test/resources/initialize/Init.script</pathInitScript>
        </configuration>
        <executions>
          <execution>
            <id>start-elasticsearch</id>
            <phase>process-test-classes</phase>
            <goals>
              <goal>runforked</goal>
            </goals>
          </execution>
          <execution>
            <id>stop-elasticsearch</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

This snippet above - picks up random free ports and when another instance of ES is spun it shouldn't complain.

from elasticsearch-maven-plugin.

alexcojocaru avatar alexcojocaru commented on June 28, 2024

Yes, I believe the config above would work.

from elasticsearch-maven-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.