mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-07-31 17:38:33 +00:00
MNT-21869 libreoffice timeout set too high (#295)
* MNT-21869 libreoffice timeout set too high Reduce default value of timeout for libreoffice from 2000min to 20min Add option to configure libreoffice timeout externally. Enable to configure externally the port on which the app starts. Add external-engine-configuration.md
This commit is contained in:
committed by
GitHub
parent
608fdc1ab4
commit
32e48b413b
@@ -66,12 +66,27 @@ public class LibreOfficeController extends AbstractTransformerController
|
||||
@Value("${transform.core.libreoffice.path}")
|
||||
private String execPath;
|
||||
|
||||
@Value("${transform.core.libreoffice.maxTasksPerProcess}")
|
||||
private String maxTasksPerProcess;
|
||||
|
||||
@Value("${transform.core.libreoffice.timeout}")
|
||||
private String timeout;
|
||||
|
||||
@Value("${transform.core.libreoffice.portNumbers}")
|
||||
private String portNumbers;
|
||||
|
||||
@Value("${transform.core.libreoffice.templateProfileDir}")
|
||||
private String templateProfileDir;
|
||||
|
||||
@Value("${transform.core.libreoffice.isEnabled}")
|
||||
private String isEnabled;
|
||||
|
||||
LibreOfficeJavaExecutor javaExecutor;
|
||||
|
||||
@PostConstruct
|
||||
private void init()
|
||||
{
|
||||
javaExecutor = new LibreOfficeJavaExecutor(execPath);
|
||||
javaExecutor = new LibreOfficeJavaExecutor(execPath, maxTasksPerProcess, timeout, portNumbers, templateProfileDir, isEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -5,4 +5,9 @@ transform:
|
||||
config:
|
||||
location: classpath:libreoffice_engine_config.json
|
||||
libreoffice:
|
||||
path: ${LIBREOFFICE_HOME:/opt/libreoffice6.3}
|
||||
path: ${LIBREOFFICE_HOME:/opt/libreoffice6.3}
|
||||
maxTasksPerProcess: ${LIBREOFFICE_MAX_TASKS_PER_PROCESS:200}
|
||||
timeout: ${LIBREOFFICE_TIMEOUT:1200000}
|
||||
portNumbers: ${LIBREOFFICE_PORT_NUMBERS:8100}
|
||||
templateProfileDir: ${LIBREOFFICE_TEMPLATE_PROFILE_DIR:}
|
||||
isEnabled: ${LIBREOFFICE_IS_ENABLED:true}
|
@@ -45,7 +45,6 @@ import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
import static org.springframework.http.MediaType.IMAGE_PNG_VALUE;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.util.StringUtils.getFilenameExtension;
|
||||
|
||||
@@ -97,14 +96,29 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
protected ExecutionResult mockExecutionResult;
|
||||
|
||||
@Value("${transform.core.libreoffice.path}")
|
||||
protected String execPath;
|
||||
private String execPath;
|
||||
|
||||
@Value("${transform.core.libreoffice.maxTasksPerProcess}")
|
||||
private String maxTasksPerProcess;
|
||||
|
||||
@Value("${transform.core.libreoffice.timeout}")
|
||||
private String timeout;
|
||||
|
||||
@Value("${transform.core.libreoffice.portNumbers}")
|
||||
private String portNumbers;
|
||||
|
||||
@Value("${transform.core.libreoffice.templateProfileDir}")
|
||||
private String templateProfileDir;
|
||||
|
||||
@Value("${transform.core.libreoffice.isEnabled}")
|
||||
private String isEnabled;
|
||||
|
||||
protected LibreOfficeJavaExecutor javaExecutor;
|
||||
|
||||
@PostConstruct
|
||||
private void init()
|
||||
{
|
||||
javaExecutor = Mockito.spy(new LibreOfficeJavaExecutor(execPath));
|
||||
javaExecutor = Mockito.spy(new LibreOfficeJavaExecutor(execPath, maxTasksPerProcess, timeout, portNumbers, templateProfileDir, isEnabled));
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -267,4 +281,103 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
//System test property value can me modified in the pom.xml
|
||||
assertEquals(execPath, System.getProperty("LIBREOFFICE_HOME"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverridingExecutorMaxTasksPerProcess()
|
||||
{
|
||||
//System test property value can me modified in the pom.xml
|
||||
assertEquals(maxTasksPerProcess, System.getProperty("LIBREOFFICE_MAX_TASKS_PER_PROCESS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverridingExecutorTimeout()
|
||||
{
|
||||
//System test property value can me modified in the pom.xml
|
||||
assertEquals(timeout, System.getProperty("LIBREOFFICE_TIMEOUT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverridingExecutorPortNumbers()
|
||||
{
|
||||
//System test property value can me modified in the pom.xml
|
||||
assertEquals(portNumbers, System.getProperty("LIBREOFFICE_PORT_NUMBERS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverridingExecutorTemplateProfileDir()
|
||||
{
|
||||
//System test property value can me modified in the pom.xml
|
||||
assertEquals(templateProfileDir, System.getProperty("LIBREOFFICE_TEMPLATE_PROFILE_DIR"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverridingExecutorIsEnabled()
|
||||
{
|
||||
//System test property value can me modified in the pom.xml
|
||||
assertEquals(isEnabled, System.getProperty("LIBREOFFICE_IS_ENABLED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidExecutorMaxTasksPerProcess()
|
||||
{
|
||||
String errorMessage = "";
|
||||
try
|
||||
{
|
||||
new LibreOfficeJavaExecutor(execPath, "INVALID", timeout, portNumbers, templateProfileDir, isEnabled);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
errorMessage = e.getMessage();
|
||||
}
|
||||
|
||||
assertEquals("LibreOfficeJavaExecutor MAX_TASKS_PER_PROCESS must have a numeric value", errorMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidExecutorTimeout()
|
||||
{
|
||||
String errorMessage = "";
|
||||
try
|
||||
{
|
||||
new LibreOfficeJavaExecutor(execPath, maxTasksPerProcess, "INVALID", portNumbers, templateProfileDir, isEnabled);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
errorMessage = e.getMessage();
|
||||
}
|
||||
|
||||
assertEquals("LibreOfficeJavaExecutor TIMEOUT must have a numeric value", errorMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidExecutorPortNumbers()
|
||||
{
|
||||
String errorMessage = "";
|
||||
try
|
||||
{
|
||||
new LibreOfficeJavaExecutor(execPath, maxTasksPerProcess, timeout, null, templateProfileDir, isEnabled);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
errorMessage = e.getMessage();
|
||||
}
|
||||
|
||||
assertEquals("LibreOfficeJavaExecutor PORT variable cannot be null or empty", errorMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidExecutorIsEnabled()
|
||||
{
|
||||
String errorMessage = "";
|
||||
try
|
||||
{
|
||||
new LibreOfficeJavaExecutor(execPath, maxTasksPerProcess, timeout, portNumbers, templateProfileDir, "INVALID");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
errorMessage = e.getMessage();
|
||||
}
|
||||
|
||||
assertEquals("LibreOfficeJavaExecutor IS_ENABLED variable must be set to true/false", errorMessage);
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ package org.alfresco.transformer.executors;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.star.task.ErrorCodeIOException;
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||
@@ -60,36 +61,76 @@ public class LibreOfficeJavaExecutor implements JavaExecutor
|
||||
|
||||
private static String LIBREOFFICE_HOME;
|
||||
|
||||
private static String LIBREOFFICE_MAX_TASKS_PER_PROCESS;
|
||||
|
||||
private static String LIBREOFFICE_TIMEOUT;
|
||||
|
||||
private static String LIBREOFFICE_PORT_NUMBERS;
|
||||
|
||||
private static String LIBREOFFICE_TEMPLATE_PROFILE_DIR;
|
||||
|
||||
private static String LIBREOFFICE_IS_ENABLED;
|
||||
|
||||
public static final String LICENCE = "This transformer uses LibreOffice from The Document Foundation. See the license at https://www.libreoffice.org/download/license/ or in /libreoffice.txt";
|
||||
|
||||
private final JodConverter jodconverter;
|
||||
|
||||
private final ObjectMapper jsonObjectMapper = new ObjectMapper();
|
||||
|
||||
public LibreOfficeJavaExecutor(String path)
|
||||
public LibreOfficeJavaExecutor(String path, String maxTasksPerProcess, String timeout, String portNumbers, String templateProfileDir, String isEnabled)
|
||||
{
|
||||
if (path == null || path.isEmpty())
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor OFFICE_HOME variable cannot be null or empty");
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor OFFICE_HOME cannot be null or empty");
|
||||
}
|
||||
LIBREOFFICE_HOME = path;
|
||||
|
||||
if(timeout == null || timeout.isEmpty() || !StringUtils.isNumeric(timeout))
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor TIMEOUT must have a numeric value");
|
||||
}
|
||||
LIBREOFFICE_TIMEOUT = timeout;
|
||||
|
||||
if(maxTasksPerProcess == null || maxTasksPerProcess.isEmpty() || !StringUtils.isNumeric(maxTasksPerProcess))
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor MAX_TASKS_PER_PROCESS must have a numeric value");
|
||||
}
|
||||
LIBREOFFICE_MAX_TASKS_PER_PROCESS = maxTasksPerProcess;
|
||||
|
||||
if(portNumbers == null || portNumbers.isEmpty())
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor PORT variable cannot be null or empty");
|
||||
}
|
||||
// value parsed and validated in JodConverterSharedInstance#parsePortNumbers(String s, String sys)
|
||||
LIBREOFFICE_PORT_NUMBERS = portNumbers;
|
||||
|
||||
if (templateProfileDir == null)
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor TEMPLATE_PROFILE_DIR variable cannot be null");
|
||||
}
|
||||
LIBREOFFICE_TEMPLATE_PROFILE_DIR = templateProfileDir;
|
||||
|
||||
if(isEnabled == null || isEnabled.isEmpty() || !(isEnabled.equalsIgnoreCase("true")|| isEnabled.equalsIgnoreCase("false")))
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor IS_ENABLED variable must be set to true/false");
|
||||
}
|
||||
LIBREOFFICE_IS_ENABLED = isEnabled;
|
||||
|
||||
jodconverter = createJodConverter();
|
||||
}
|
||||
|
||||
private static JodConverter createJodConverter()
|
||||
{
|
||||
final String timeout = "120000000";
|
||||
|
||||
final JodConverterSharedInstance jodconverter = new JodConverterSharedInstance();
|
||||
|
||||
jodconverter.setOfficeHome(LIBREOFFICE_HOME); // jodconverter.officeHome
|
||||
jodconverter.setMaxTasksPerProcess("200"); // jodconverter.maxTasksPerProcess
|
||||
jodconverter.setTaskExecutionTimeout(timeout); // jodconverter.maxTaskExecutionTimeout
|
||||
jodconverter.setTaskQueueTimeout(timeout); // jodconverter.taskQueueTimeout
|
||||
jodconverter.setConnectTimeout(timeout); // jodconverter.connectTimeout
|
||||
jodconverter.setPortNumbers("8100"); // jodconverter.portNumbers
|
||||
jodconverter.setTemplateProfileDir(""); // jodconverter.templateProfileDir
|
||||
jodconverter.setEnabled("true"); // jodconverter.enabled
|
||||
jodconverter.setOfficeHome(LIBREOFFICE_HOME); // jodconverter.officeHome
|
||||
jodconverter.setMaxTasksPerProcess(LIBREOFFICE_MAX_TASKS_PER_PROCESS); // jodconverter.maxTasksPerProcess
|
||||
jodconverter.setTaskExecutionTimeout(LIBREOFFICE_TIMEOUT); // jodconverter.maxTaskExecutionTimeout
|
||||
jodconverter.setTaskQueueTimeout(LIBREOFFICE_TIMEOUT); // jodconverter.taskQueueTimeout
|
||||
jodconverter.setConnectTimeout(LIBREOFFICE_TIMEOUT); // jodconverter.connectTimeout
|
||||
jodconverter.setPortNumbers(LIBREOFFICE_PORT_NUMBERS); // jodconverter.portNumbers
|
||||
jodconverter.setTemplateProfileDir(LIBREOFFICE_TEMPLATE_PROFILE_DIR); // jodconverter.templateProfileDir
|
||||
jodconverter.setEnabled(LIBREOFFICE_IS_ENABLED); // jodconverter.enabled
|
||||
jodconverter.afterPropertiesSet();
|
||||
|
||||
return jodconverter;
|
||||
|
Reference in New Issue
Block a user