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:
IMatcher<URL,,URL, URL> 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.3.3</version><!--maybe update version-->
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-httpclient5</artifactId>
<version>3.3.3</version><!--maybe update version-->
</dependency>
With this in place everything should work.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate intprivate StringThe containerID for the current running container.private static final intprivate com.github.dockerjava.api.DockerClientprivate booleanprivate intprivate Stringprivate intprivate static final booleanprivate DockerLogCallbackThe callback for log entries.private static final org.slf4j.Loggerprivate static final com.fasterxml.jackson.databind.ObjectMapperprivate static final Stringprivate booleanIf true, the container binds only on localhost instead of all interfaces.private intprivate List<com.github.dockerjava.api.model.Bind> -
Constructor Summary
ConstructorsConstructorDescriptionMatcherDockerFile(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 TypeMethodDescriptionvoidaddEnvironmentVariable(String environmentVariable) This method will add one environment variable in form of e.g.voidaddEnvironmentVariableCudaVisibleDevices(String visibleDevicesValue) This method will add one environment variable where the key is "CUDA_VISIBLE_DEVICES".voidaddVolumeMounted(com.github.dockerjava.api.model.Bind volume) Adds a volume mount specification represented by the corresponding object.voidaddVolumeMounted(String volume) Adds a volume mount specification represented as string e.g.voidclose()Deprecated.this function should not be useful anymore because the output is directly (and automatically) logged.The container id which used.private intReturn the exposed port of the docker image.static com.github.dockerjava.core.DefaultDockerClientConfig.BuilderReturn the environment variables which are set for the container.private intReturns a free port number on localhost.intThe port on which the matching service is avilable.Retunrs the image name which is used by this matcher.static StringgetImageNameFromFileContent(File dockerFile) Extracts the image name from the docker file content.static StringgetImageNameFromFileName(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'intprivate static org.apache.commons.compress.archivers.ArchiveInputStreamgetUncompressedStream(InputStream inputStream) List<com.github.dockerjava.api.model.Bind>Return all mounted volumes as a list of Bind objects.booleanReturns true, if for each call to the match function, a new docker container should be created.booleanReturn true if the docker container should only listen on localhost.voidloadDockerFile(File dockerImageFile) private voidloadDockerFileInternal(File dockerImageFile) voidDeprecated.this function should not be useful anymore because the output is directly (and automatically) logged.voidlogLastLinesFromContainer(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.Aligns two ontologies/knowledge graphs given as the first and second parameter.voidsetEnvironmentVariables(List<String> environmentVariables) Set the environment variables which are used for the container.voidsetInitialWaitingTimeInSeconds(int initialWaitingTimeInSeconds) voidsetTimeouts(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.voidsetVolumeMounted(List<com.github.dockerjava.api.model.Bind> volumeMounted) Set the list of bindings.private voidprivate voidtoString()Methods inherited from class de.uni_mannheim.informatik.dws.melt.matching_base.MatcherURL
align, align, canExecute, getTypeMethods inherited from class eu.sealsproject.platform.res.tool.impl.AbstractPlugin
getId, getVersion, setId, setVersionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 -
volumeMounted
-
environmentVariables
-
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:MatcherURLMatch two ontologies / knowledge graphs together and returns an alignment.- Specified by:
matchin 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.
-
match
Description copied from interface:IMatcherAligns two ontologies/knowledge graphs given as the first and second parameter. An additional input alignment can be given as well as parameters which further define how and what to match. In case inputAlignment or parameters is not used, making them to the Object class, will required no additional transformations of these objects (no overhead).- Specified by:
matchin interfaceIMatcher<URL,URL, URL> - Parameters:
source- this object represents the source ontology/knowledge graphtarget- this object represents the target ontology/knowledge graphinputAlignment- this object represents the input alignment.parameters- object representing additional parameters. Only add to this object and do not create a new Object likeparameters= new ...()because otherwise the parameters are lost (java ist call by value). Sensible classes areProperties(preferred),Map<String, Object>or any similar data structure. Some already specified keys (strings) can be found atParameterConfigKeys.- Returns:
- the resulting alignment of the matching process.
- Throws:
Exception- any exception which occurs during matching
-
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:
closein interfaceAutoCloseable- Specified by:
closein 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.
-
getVolumeMounted
Return all mounted volumes as a list of Bind objects.- Returns:
- a list of Bind objects.
-
setVolumeMounted
Set the list of bindings. This will override all previous bindings.- Parameters:
volumeMounted- the list of bindings which should not be null.
-
addVolumeMounted
public void addVolumeMounted(com.github.dockerjava.api.model.Bind volume) Adds a volume mount specification represented by the corresponding object.- Parameters:
volume- the corresponding bin object
-
addVolumeMounted
Adds a volume mount specification represented as string e.g./host:/container:ro.- Parameters:
volume- the specification, e.g./host:/container:ro
-
getEnvironmentVariables
Return the environment variables which are set for the container.- Returns:
- the environment variables which are set for the container.
-
setEnvironmentVariables
Set the environment variables which are used for the container. This is a list of environemtn variables in form of e.g. "CUDA_VISIBLE_DEVICES=1"- Parameters:
environmentVariables- a list of environemtn variables in form of e.g. "CUDA_VISIBLE_DEVICES=1"
-
addEnvironmentVariable
This method will add one environment variable in form of e.g. "CUDA_VISIBLE_DEVICES=1".- Parameters:
environmentVariable- one environment variable in form of e.g. "CUDA_VISIBLE_DEVICES=1".
-
addEnvironmentVariableCudaVisibleDevices
This method will add one environment variable where the key is "CUDA_VISIBLE_DEVICES". The key does not need to be repreat. Just provide the value which can either be one number e.g. 2 (0-based) or a list of numbers (gpus) like "1,2,3".- Parameters:
visibleDevicesValue- provide the value which can either be one number e.g. 2 (0-based) or a list of numbers (gpus) like "1,2,3".
-
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)
-