java.lang.Object
eu.sealsproject.platform.res.tool.impl.AbstractPlugin
de.uni_mannheim.informatik.dws.melt.matching_base.MatcherURL
de.uni_mannheim.informatik.dws.melt.matching_base.external.docker.MatcherDockerFile
All Implemented Interfaces:
eu.sealsproject.platform.res.domain.omt.IOntologyMatchingToolBridge, eu.sealsproject.platform.res.tool.api.IPlugin, eu.sealsproject.platform.res.tool.api.IToolBridge, Closeable, AutoCloseable

public class MatcherDockerFile
extends MatcherURL
implements Closeable
This matcher creates a docker container based on a given docker image name. Within this container a matcher server should be started. Therefore it will use the MatcherHTTPCall internally to run the matcher. For this Matcher to work you have to add the following dependency to YOUR pom:

<dependency>
    <groupId>com.github.docker-java</groupId>
    <artifactId>docker-java-core</artifactId>
    <version>3.2.7</version><!--maybe update version-->
</dependency>
<dependency>
    <groupId>com.github.docker-java</groupId>
    <artifactId>docker-java-transport-httpclient5</artifactId>
    <version>3.2.7</version><!--maybe update version-->
</dependency>
 
With this in place everything should work.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • OS_NAME

      private static final String OS_NAME
    • IS_WINDOWS

      private static final boolean IS_WINDOWS
    • mapper

      private static final com.fasterxml.jackson.databind.ObjectMapper mapper
    • DEFAULT_EXPOSED_PORT

      private static final int DEFAULT_EXPOSED_PORT
      See Also:
      Constant Field Values
    • dockerClient

      private com.github.dockerjava.api.DockerClient dockerClient
    • logCallback

      private DockerLogCallback logCallback
      The callback for log entries. This is an attribute of the class because it should be closed.
    • imageName

      private String imageName
    • runOnlyLocalhost

      private boolean runOnlyLocalhost
      If true, the container binds only on localhost instead of all interfaces. True is the default.
    • containerId

      private String containerId
      The containerID for the current running container. This is set to null if no container is running.
    • hostPort

      private int hostPort
    • freshInstance

      private boolean freshInstance
    • socketTimeout

      private int socketTimeout
    • connectTimeout

      private int connectTimeout
    • connectionRequestTimeout

      private int connectionRequestTimeout
    • initialWaitingTimeInSeconds

      private int initialWaitingTimeInSeconds
  • Constructor Details

    • MatcherDockerFile

      public MatcherDockerFile​(String imageName, File dockerImageFile, com.github.dockerjava.core.DockerClientConfig config, boolean runOnlyLocalhost, boolean freshInstance)
      Initializes a matcher which starts a docker image to create a docker container in which a HTTP server runs.
      Parameters:
      imageName - the image name to use (docker image name).
      dockerImageFile - a file which contains the image.
      config - the config to connect to a docker machine.
      runOnlyLocalhost - true if all ports should be bound to localhost. If false, all ports are bound to all interfaces (0.0.0.0) and makes the server also available from outside.
      freshInstance - if true, with every call of the match method, a new container is started (default is false because it should not be necessary).
    • MatcherDockerFile

      public MatcherDockerFile​(String imageName, File dockerImageFile, com.github.dockerjava.core.DockerClientConfig config)
    • MatcherDockerFile

      public MatcherDockerFile​(String imageName, File dockerImageFile)
      Loads the images in the docker file given by dockerImageFile. And then runs the image given by imageName.
      Parameters:
      imageName - the image name
      dockerImageFile - the file which contains the image given by imageName
    • MatcherDockerFile

      public MatcherDockerFile​(String imageName)
      Constructor.
      Parameters:
      imageName - Name of the image. The image must already be in the local docker registry.
    • MatcherDockerFile

      public MatcherDockerFile​(File dockerImageFile)
      Constructor. Obtains the image name form the file name.
      Parameters:
      dockerImageFile - The file which contains the image. The file must carry the name of the image optionally succeeded by a '-latest' postfix.
  • Method Details

    • loadDockerFile

      public void loadDockerFile​(File dockerImageFile)
    • getDockerConfigBuilder

      public static com.github.dockerjava.core.DefaultDockerClientConfig.Builder getDockerConfigBuilder()
    • loadDockerFileInternal

      private void loadDockerFileInternal​(File dockerImageFile)
    • startContainer

      private void startContainer()
    • stopContainer

      private void stopContainer()
    • match

      public URL match​(URL source, URL target, URL inputAlignment) throws Exception
      Description copied from class: MatcherURL
      Match two ontologies / knowledge graphs together and returns an alignment.
      Specified by:
      match in class MatcherURL
      Parameters:
      source - The source ontology / knowledge graph
      target - The target ontology / knowledge graph
      inputAlignment - The input alignment as URL (alignment API format)
      Returns:
      An alignment as URL (most often as file URL) the format is again the alignment API format.
      Throws:
      Exception - in case something went wrong.
    • getContainerPort

      private int getContainerPort()
      Return the exposed port of the docker image. This port should be mapped to a host port to communicate with the started container.
      Returns:
      the port which is exposed by the image.
    • getFreePortOnHost

      private int getFreePortOnHost()
      Returns a free port number on localhost.
      Returns:
      a free port number on localhost
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • setTimeouts

      public void setTimeouts​(int socketTimeout, int connectTimeout, int connectionRequestTimeout)
      Sets the timeouts for the HTTP call which happens when the docker container is started and the call to the service is executed.
      Parameters:
      socketTimeout - the time in milliseconds waiting for data – after the connection is established; maximum time between two data packets. Zero means infinite timeout. Negative usually means systems default.
      connectTimeout - the timeout in milliseconds until a connection is established. Zero means infinite timeout. Negative usually means systems default.
      connectionRequestTimeout - timeout in milliseconds when requesting a connection from the connection manager. Zero means infinite timeout. Negative usually means systems default.
    • getImageName

      public String getImageName()
      Retunrs the image name which is used by this matcher.
      Returns:
      the docker image name
    • isRunOnlyLocalhost

      public boolean isRunOnlyLocalhost()
      Return true if the docker container should only listen on localhost. This means the matcher service can only be called from the same maschine. If access to the service is required also from outside, then change the parameter in the constructor.
      Returns:
      true if the docker container should only listen on localhost
    • getContainerId

      public String getContainerId()
      The container id which used. It returns null if the container is not running (eg. not started or already stopped).
      Returns:
      containter id or null if container is not running.
    • getHostPort

      public int getHostPort()
      The port on which the matching service is avilable. Usually http://localhost:{hostPort}/match
      Returns:
      the port to which the matcher service whithin the container is mapped to the host.
    • isFreshInstance

      public boolean isFreshInstance()
      Returns true, if for each call to the match function, a new docker container should be created. If false, the docker container is created when instantiating the MatcherDockerFile (e.g. in the constuctor). Then the close method should be also called to stop the container.
      Returns:
      true, if for each call to the match function, a new docker container should be created. False otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getImageNameFromFileName

      public static String getImageNameFromFileName​(File dockerFile)
      The naming convention of the MELT Web Docker files is such that the files carry the name of the image with an optional postfix of '-latest' such as 'my_image-latest.tar.gz'
      Parameters:
      dockerFile - The docker file of which the image name shall be retrieved.
      Returns:
      The image name as String.
    • getImageNameFromFileContent

      public static String getImageNameFromFileContent​(File dockerFile)
      Extracts the image name from the docker file content. In more detail, it analyzes the 'repositories' file and returns the key of the corresponding json. If something goes wrong, null is returned. If multiple images are contained in the file, only the first one is returned.
      Parameters:
      dockerFile - the docker file to extract the image name from. This file is usally created from a docker save command.
      Returns:
      the image name contained in the docker file.
    • getUncompressedStream

      private static org.apache.commons.compress.archivers.ArchiveInputStream getUncompressedStream​(InputStream inputStream) throws org.apache.commons.compress.archivers.ArchiveException
      Throws:
      org.apache.commons.compress.archivers.ArchiveException
    • getAllLogLinesFromContainer

      public String getAllLogLinesFromContainer()
      Deprecated.
      this function should not be useful anymore because the output is directly (and automatically) logged.
      Returns the all lines of the log from the container.
      Returns:
      all lines of the log from the container
    • logAllLinesFromContainer

      public void logAllLinesFromContainer()
      Deprecated.
      this function should not be useful anymore because the output is directly (and automatically) logged.
      Calling this function will log all lines from the container using SLF4J.
    • logLastLinesFromContainer

      public void logLastLinesFromContainer​(int numberOfLastLines)
      Deprecated.
      this function should not be useful anymore because the output is directly (and automatically) logged.
      Calling this function will log the last x lines from the container.
      Parameters:
      numberOfLastLines - the number of last lines to log.
    • getInitialWaitingTimeInSeconds

      public int getInitialWaitingTimeInSeconds()
    • setInitialWaitingTimeInSeconds

      public void setInitialWaitingTimeInSeconds​(int initialWaitingTimeInSeconds)