-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix_5804_back_to_the_future' into 'master'
5804 - Rollback griffin libreoffice daemon See merge request vitam/vitam-griffins!67
- Loading branch information
Showing
10 changed files
with
177 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
java -Dfile.encoding=UTF-8 -jar /vitam/bin/worker/griffins/libreoffice-griffin/libreoffice-jar-with-dependencies.jar $1 | ||
LIBREOFFICE_HOME=$(dirname $(dirname $(readlink -f $(which $(compgen -c | grep libreoffice | head -1))))) | ||
|
||
java -Doffice.home="$LIBREOFFICE_HOME" -Dfile.encoding=UTF-8 -jar /vitam/bin/worker/griffins/libreoffice-griffin/libreoffice-jar-with-dependencies.jar $1 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
libreoffice/src/main/java/fr/gouv/vitam/griffins/libreoffice/AutoClosableOfficeManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2015-2019) | ||
* | ||
* [email protected] | ||
* | ||
* This software is a computer program whose purpose is to implement a digital archiving back-office system managing | ||
* high volumetry securely and efficiently. | ||
* | ||
* This software is governed by the CeCILL 2.1 license under French law and abiding by the rules of distribution of free | ||
* software. You can use, modify and/ or redistribute the software under the terms of the CeCILL 2.1 license as | ||
* circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". | ||
* | ||
* As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, | ||
* users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the | ||
* successive licensors have only limited liability. | ||
* | ||
* In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or | ||
* developing or reproducing the software by the user in light of its specific status of free software, that may mean | ||
* that it is complicated to manipulate, and that also therefore means that it is reserved for developers and | ||
* experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the | ||
* software's suitability as regards their requirements in conditions enabling the security of their systems and/or data | ||
* to be ensured and, more generally, to use and operate it in the same conditions as regards security. | ||
* | ||
* The fact that you are presently reading this means that you have had knowledge of the CeCILL 2.1 license and that you | ||
* accept its terms. | ||
*/ | ||
package fr.gouv.vitam.griffins.libreoffice; | ||
|
||
import org.jodconverter.office.LocalOfficeManager; | ||
import org.jodconverter.office.OfficeException; | ||
import org.jodconverter.office.OfficeManager; | ||
import org.jodconverter.task.OfficeTask; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.net.ServerSocket; | ||
import java.nio.file.FileAlreadyExistsException; | ||
import java.nio.file.Files; | ||
import java.nio.file.OpenOption; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class AutoClosableOfficeManager implements AutoCloseable, OfficeManager { | ||
|
||
private final OfficeManager manager; | ||
|
||
public AutoClosableOfficeManager(int libreOffice) throws IOException { | ||
this.manager = LocalOfficeManager.builder() | ||
.portNumbers(libreOffice) | ||
.workingDir(Files.createTempDirectory("griffin-libreoffice-").toFile()) | ||
.install() | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
this.stop(); | ||
} | ||
|
||
@Override | ||
public void execute(OfficeTask task) throws OfficeException { | ||
manager.execute(task); | ||
} | ||
|
||
@Override | ||
public boolean isRunning() { | ||
return manager.isRunning(); | ||
} | ||
|
||
@Override | ||
public void start() throws OfficeException { | ||
manager.start(); | ||
} | ||
|
||
@Override | ||
public void stop() throws OfficeException { | ||
manager.stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
libreoffice/src/main/java/fr/gouv/vitam/griffins/libreoffice/PortReserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2015-2019) | ||
* | ||
* [email protected] | ||
* | ||
* This software is a computer program whose purpose is to implement a digital archiving back-office system managing | ||
* high volumetry securely and efficiently. | ||
* | ||
* This software is governed by the CeCILL 2.1 license under French law and abiding by the rules of distribution of free | ||
* software. You can use, modify and/ or redistribute the software under the terms of the CeCILL 2.1 license as | ||
* circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". | ||
* | ||
* As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, | ||
* users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the | ||
* successive licensors have only limited liability. | ||
* | ||
* In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or | ||
* developing or reproducing the software by the user in light of its specific status of free software, that may mean | ||
* that it is complicated to manipulate, and that also therefore means that it is reserved for developers and | ||
* experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the | ||
* software's suitability as regards their requirements in conditions enabling the security of their systems and/or data | ||
* to be ensured and, more generally, to use and operate it in the same conditions as regards security. | ||
* | ||
* The fact that you are presently reading this means that you have had knowledge of the CeCILL 2.1 license and that you | ||
* accept its terms. | ||
*/ | ||
package fr.gouv.vitam.griffins.libreoffice; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.net.ServerSocket; | ||
import java.nio.file.FileAlreadyExistsException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class PortReserver implements AutoCloseable { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(PortReserver.class); | ||
private static final Path LOCK_DIRECTORY = Paths.get(System.getProperty("java.io.tmpdir"), "griffin-libre-office-locks"); | ||
private static final int MAX_ATTEMPT_NUMBER = 4; | ||
|
||
private final int libreOfficePort; | ||
|
||
public PortReserver() throws IOException { | ||
createLockDirectory(); | ||
this.libreOfficePort = findAvailablePort(MAX_ATTEMPT_NUMBER); | ||
} | ||
|
||
private void createLockDirectory() throws IOException { | ||
if (Files.notExists(LOCK_DIRECTORY)) { | ||
try { | ||
Files.createDirectory(LOCK_DIRECTORY); | ||
} catch (FileAlreadyExistsException e) { | ||
LOGGER.info("ignore error {}", e); | ||
} | ||
} | ||
} | ||
|
||
private int findAvailablePort(int numberOfAttempt) throws IOException { | ||
try (ServerSocket socket = new ServerSocket(0, 1, InetAddress.getLocalHost())) { | ||
int localPort = socket.getLocalPort(); | ||
Files.createFile(LOCK_DIRECTORY.resolve(String.format("%d.lock", localPort))); | ||
return localPort; | ||
} catch (FileAlreadyExistsException e) { | ||
LOGGER.warn("{}", e); | ||
|
||
if (numberOfAttempt > MAX_ATTEMPT_NUMBER) { | ||
throw new RuntimeException("Reach max retries for find available port and yet there is still:", e); | ||
} | ||
|
||
return findAvailablePort(numberOfAttempt + 1); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
Files.delete(LOCK_DIRECTORY.resolve(String.format("%d.lock", this.libreOfficePort))); | ||
} | ||
|
||
public int getLibreOfficePort() { | ||
return libreOfficePort; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters