Class MatcherDockerFile
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
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 Summary
Modifier and TypeFieldDescriptionprivate int
private int
private String
The containerID for the current running container.private static final int
private com.github.dockerjava.api.DockerClient
private boolean
private int
private String
private int
private static final boolean
private DockerLogCallback
The callback for log entries.private static final org.slf4j.Logger
private static final com.fasterxml.jackson.databind.ObjectMapper
private static final String
private boolean
If true, the container binds only on localhost instead of all interfaces.private int
-
Constructor Summary
ConstructorDescriptionMatcherDockerFile
(File dockerImageFile) Constructor.MatcherDockerFile
(String imageName) Constructor.MatcherDockerFile
(String imageName, File dockerImageFile) Loads the images in the docker file given by dockerImageFile.MatcherDockerFile
(String imageName, File dockerImageFile, com.github.dockerjava.core.DockerClientConfig config) 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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Deprecated.this function should not be useful anymore because the output is directly (and automatically) logged.The container id which used.private int
Return the exposed port of the docker image.static com.github.dockerjava.core.DefaultDockerClientConfig.Builder
private int
Returns a free port number on localhost.int
The port on which the matching service is avilable.Retunrs the image name which is used by this matcher.static String
getImageNameFromFileContent
(File dockerFile) Extracts the image name from the docker file content.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'int
private static org.apache.commons.compress.archivers.ArchiveInputStream
getUncompressedStream
(InputStream inputStream) boolean
Returns true, if for each call to the match function, a new docker container should be created.boolean
Return true if the docker container should only listen on localhost.void
loadDockerFile
(File dockerImageFile) private void
loadDockerFileInternal
(File dockerImageFile) void
Deprecated.this function should not be useful anymore because the output is directly (and automatically) logged.void
logLastLinesFromContainer
(int numberOfLastLines) Deprecated.this function should not be useful anymore because the output is directly (and automatically) logged.Match two ontologies / knowledge graphs together and returns an alignment.void
setInitialWaitingTimeInSeconds
(int initialWaitingTimeInSeconds) 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.private void
private void
toString()
Methods inherited from class de.uni_mannheim.informatik.dws.melt.matching_base.MatcherURL
align, align, canExecute, getType
Methods inherited from class eu.sealsproject.platform.res.tool.impl.AbstractPlugin
getId, getVersion, setId, setVersion
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface eu.sealsproject.platform.res.tool.api.IPlugin
getId, getVersion
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
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:
-
dockerClient
private com.github.dockerjava.api.DockerClient dockerClient -
logCallback
The callback for log entries. This is an attribute of the class because it should be closed. -
imageName
-
runOnlyLocalhost
private boolean runOnlyLocalhostIf true, the container binds only on localhost instead of all interfaces. True is the default. -
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
-
MatcherDockerFile
Loads the images in the docker file given by dockerImageFile. And then runs the image given by imageName.- Parameters:
imageName
- the image namedockerImageFile
- the file which contains the image given by imageName
-
MatcherDockerFile
Constructor.- Parameters:
imageName
- Name of the image. The image must already be in the local docker registry.
-
MatcherDockerFile
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
-
getDockerConfigBuilder
public static com.github.dockerjava.core.DefaultDockerClientConfig.Builder getDockerConfigBuilder() -
loadDockerFileInternal
-
startContainer
private void startContainer() -
stopContainer
private void stopContainer() -
match
Description copied from class:MatcherURL
Match two ontologies / knowledge graphs together and returns an alignment.- Specified by:
match
in classMatcherURL
- Parameters:
source
- The source ontology / knowledge graphtarget
- The target ontology / knowledge graphinputAlignment
- 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
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- 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
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
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
-
getImageNameFromFileName
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
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
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)
-