diff --git a/engines/base/pom.xml b/engines/base/pom.xml index 73e985ea..f6ad0a90 100644 --- a/engines/base/pom.xml +++ b/engines/base/pom.xml @@ -28,6 +28,10 @@ org.springframework.boot spring-boot-starter-actuator + + org.springframework.retry + spring-retry + io.micrometer micrometer-registry-prometheus diff --git a/engines/base/src/main/java/org/alfresco/transform/base/Application.java b/engines/base/src/main/java/org/alfresco/transform/base/Application.java index 3c2161f1..5c74fcec 100644 --- a/engines/base/src/main/java/org/alfresco/transform/base/Application.java +++ b/engines/base/src/main/java/org/alfresco/transform/base/Application.java @@ -36,16 +36,28 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.context.annotation.Bean; +import org.springframework.core.task.SimpleAsyncTaskExecutor; +import org.springframework.core.task.TaskExecutor; +import org.springframework.retry.annotation.EnableRetry; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class}) +@EnableAsync +//@EnableScheduling +//@EnableRetry public class Application { - private static final Logger logger = LoggerFactory.getLogger(Application.class); - @Value("${container.name}") private String containerName; + @Bean + public TaskExecutor taskExecutor() + { + return new SimpleAsyncTaskExecutor(); + } + @Bean MeterRegistryCustomizer metricsCommonTags() { diff --git a/engines/base/src/main/java/org/alfresco/transform/base/TransformController.java b/engines/base/src/main/java/org/alfresco/transform/base/TransformController.java index b408efdd..ea9841bc 100644 --- a/engines/base/src/main/java/org/alfresco/transform/base/TransformController.java +++ b/engines/base/src/main/java/org/alfresco/transform/base/TransformController.java @@ -28,6 +28,7 @@ package org.alfresco.transform.base; import org.alfresco.transform.base.html.OptionLister; import org.alfresco.transform.base.logging.LogEntry; +import org.alfresco.transform.base.registry.TransformRegistry; import org.alfresco.transform.base.transform.TransformHandler; import org.alfresco.transform.client.model.TransformReply; import org.alfresco.transform.client.model.TransformRequest; @@ -62,7 +63,6 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Arrays; import java.util.Collection; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/engines/base/src/main/java/org/alfresco/transform/base/config/SpringAsyncConfig.java b/engines/base/src/main/java/org/alfresco/transform/base/config/SpringAsyncConfig.java deleted file mode 100644 index 3a8b9c12..00000000 --- a/engines/base/src/main/java/org/alfresco/transform/base/config/SpringAsyncConfig.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * #%L - * Alfresco Transform Core - * %% - * Copyright (C) 2022 - 2022 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.transform.base.config; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.annotation.AsyncConfigurer; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; - -import java.util.concurrent.Executor; - -@Configuration -@EnableAsync -public class SpringAsyncConfig implements AsyncConfigurer -{ - private static final Logger logger = LoggerFactory.getLogger(SpringAsyncConfig.class); - - @Value("${async-task-executor.core-pool-size:1}") - int corePoolSize; - - @Value("${async-task-executor.max-pool-size:"+Integer.MAX_VALUE+"}") - int maxPoolSize; - - @Value("${async-task-executor.keep-alive-seconds:60}") - int keepAliveSeconds; - - @Value("${async-task-executor.queue-capacity:"+Integer.MAX_VALUE+"}") - int queueCapacity; - - @Value("${async-task-executor.allow-core-thread-time-out:false}") - boolean allowCoreThreadTimeOut; - - @Value("${async-task-executor.prestart-all-core-threads:false}") - boolean prestartAllCoreThreads; - - @Override - @Bean(name = "taskExecutor") - public Executor getAsyncExecutor() - { - logger.debug("async-task-executor:"); - logger.debug(" corePoolSize="+corePoolSize); - logger.debug(" max-pool-size: "+maxPoolSize); - logger.debug(" keep-alive-seconds: "+keepAliveSeconds); - logger.debug(" queue-capacity: "+queueCapacity); - logger.debug(" allow-core-thread-time-out: "+allowCoreThreadTimeOut); - logger.debug(" prestart-all-core-threads: "+prestartAllCoreThreads); - - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); - executor.setCorePoolSize(corePoolSize); - executor.setMaxPoolSize(maxPoolSize); - executor.setKeepAliveSeconds(keepAliveSeconds); - executor.setQueueCapacity(queueCapacity); - executor.setAllowCoreThreadTimeOut(allowCoreThreadTimeOut); - executor.setPrestartAllCoreThreads(prestartAllCoreThreads); - return executor; - } -} diff --git a/engines/base/src/main/java/org/alfresco/transform/base/config/WebApplicationConfig.java b/engines/base/src/main/java/org/alfresco/transform/base/config/WebApplicationConfig.java index 7aeab997..03b6f0e4 100644 --- a/engines/base/src/main/java/org/alfresco/transform/base/config/WebApplicationConfig.java +++ b/engines/base/src/main/java/org/alfresco/transform/base/config/WebApplicationConfig.java @@ -26,9 +26,10 @@ */ package org.alfresco.transform.base.config; -import org.alfresco.transform.base.html.TransformInterceptor; -import org.alfresco.transform.base.TransformRegistry; import org.alfresco.transform.base.clients.AlfrescoSharedFileStoreClient; +import org.alfresco.transform.base.html.TransformInterceptor; +import org.alfresco.transform.base.registry.TransformConfigSource; +import org.alfresco.transform.base.registry.TransformRegistry; import org.alfresco.transform.common.TransformerDebug; import org.alfresco.transform.messages.TransformRequestValidator; import org.alfresco.transform.registry.TransformServiceRegistry; @@ -41,6 +42,9 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.util.ArrayList; +import java.util.List; + import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM; import static org.alfresco.transform.config.CoreFunction.standardizeCoreVersion; @@ -102,4 +106,10 @@ public class WebApplicationConfig implements WebMvcConfigurer { return standardizeCoreVersion(coreVersionString); } + + @Bean + public List transformConfigSources() + { + return new ArrayList<>(); + } } diff --git a/engines/base/src/main/java/org/alfresco/transform/base/registry/AbstractTransformConfigSource.java b/engines/base/src/main/java/org/alfresco/transform/base/registry/AbstractTransformConfigSource.java new file mode 100644 index 00000000..d609002b --- /dev/null +++ b/engines/base/src/main/java/org/alfresco/transform/base/registry/AbstractTransformConfigSource.java @@ -0,0 +1,53 @@ +/* + * #%L + * Alfresco Transform Core + * %% + * Copyright (C) 2022 - 2022 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.transform.base.registry; + +import org.springframework.stereotype.Component; + +public abstract class AbstractTransformConfigSource implements TransformConfigSource +{ + private final String readFrom; + private final String baseUrl; + + public AbstractTransformConfigSource(String readFrom, String baseUrl) + { + this.readFrom = readFrom; + this.baseUrl = baseUrl == null ? "---" : baseUrl; + } + + @Override + public String getReadFrom() + { + return readFrom; + } + + @Override + public String getBaseUrl() + { + return baseUrl; + } +} \ No newline at end of file diff --git a/engines/base/src/main/java/org/alfresco/transform/base/registry/TransformConfigFromTransformEngines.java b/engines/base/src/main/java/org/alfresco/transform/base/registry/TransformConfigFromTransformEngines.java new file mode 100644 index 00000000..1e6c3586 --- /dev/null +++ b/engines/base/src/main/java/org/alfresco/transform/base/registry/TransformConfigFromTransformEngines.java @@ -0,0 +1,67 @@ +/* + * #%L + * Alfresco Transform Core + * %% + * Copyright (C) 2022 - 2022 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.transform.base.registry; + +import org.alfresco.transform.base.TransformEngine; +import org.alfresco.transform.config.TransformConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.List; + +@Component +public class TransformConfigFromTransformEngines +{ + @Autowired(required = false) + private List transformEngines; + @Autowired + private List transformConfigSources; + + @PostConstruct + private void fromTransformEngineConfig() + { + if (transformEngines != null) + { + transformEngines.stream() + .forEach(transformEngine -> { + TransformConfig transformConfig = transformEngine.getTransformConfig(); + if (transformConfig != null) // if not a wrapping TransformEngine like all-in-one + { + transformConfigSources.add( + new AbstractTransformConfigSource(transformEngine.getTransformEngineName(),null) + { + @Override public TransformConfig getTransformConfig() + { + return transformEngine.getTransformConfig(); + } + }); + } + }); + } + } +} diff --git a/engines/base/src/main/java/org/alfresco/transform/base/registry/TransformConfigSource.java b/engines/base/src/main/java/org/alfresco/transform/base/registry/TransformConfigSource.java new file mode 100644 index 00000000..5e79d470 --- /dev/null +++ b/engines/base/src/main/java/org/alfresco/transform/base/registry/TransformConfigSource.java @@ -0,0 +1,12 @@ +package org.alfresco.transform.base.registry; + +import org.alfresco.transform.config.TransformConfig; + +public interface TransformConfigSource +{ + String getReadFrom(); + + String getBaseUrl(); + + TransformConfig getTransformConfig(); +} diff --git a/engines/base/src/main/java/org/alfresco/transform/base/TransformRegistry.java b/engines/base/src/main/java/org/alfresco/transform/base/registry/TransformRegistry.java similarity index 69% rename from engines/base/src/main/java/org/alfresco/transform/base/TransformRegistry.java rename to engines/base/src/main/java/org/alfresco/transform/base/registry/TransformRegistry.java index 60f5598f..e336d8e8 100644 --- a/engines/base/src/main/java/org/alfresco/transform/base/TransformRegistry.java +++ b/engines/base/src/main/java/org/alfresco/transform/base/registry/TransformRegistry.java @@ -23,7 +23,7 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.transform.base; +package org.alfresco.transform.base.registry; import org.alfresco.transform.config.TransformConfig; import org.alfresco.transform.registry.AbstractTransformRegistry; @@ -32,8 +32,9 @@ import org.alfresco.transform.registry.TransformCache; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.context.event.EventListener; -import javax.annotation.PostConstruct; import java.util.Comparator; import java.util.List; @@ -43,38 +44,36 @@ public class TransformRegistry extends AbstractTransformRegistry { private static final Logger log = LoggerFactory.getLogger(TransformRegistry.class); - @Autowired(required = false) - private List transformEngines; - @Autowired private String coreVersion; + @Autowired + private List transformConfigSources; private TransformConfig transformConfigBeforeIncompleteTransformsAreRemoved; - @PostConstruct - public void init() + /** + * Load the registry on application startup. This allows Components in projects that extend the t-engine base + * to use @PostConstruct to add to {@code transformConfigSources}, before the registry is loaded. + */ + @EventListener + void init(final ContextRefreshedEvent event) { CombinedTransformConfig combinedTransformConfig = new CombinedTransformConfig(); - if (transformEngines != null) - { - transformEngines.stream() - .sorted(Comparator.comparing(TransformEngine::getTransformEngineName)) - .forEach(transformEngine -> { - TransformConfig transformConfig = transformEngine.getTransformConfig(); - if (transformConfig != null) // if not a wrapping TransformEngine like all-in-one - { - setCoreVersionOnSingleStepTransformers(transformConfig, coreVersion); - combinedTransformConfig.addTransformConfig(transformConfig, - transformEngine.getTransformEngineName(), "---", this); - } - }); - } + + transformConfigSources.stream() + .sorted(Comparator.comparing(TransformConfigSource::getReadFrom)) + .forEach(source -> { + TransformConfig transformConfig = source.getTransformConfig(); + setCoreVersionOnSingleStepTransformers(transformConfig, coreVersion); + combinedTransformConfig.addTransformConfig(transformConfig, source.getReadFrom(), source.getBaseUrl(), + this); + }); + transformConfigBeforeIncompleteTransformsAreRemoved = combinedTransformConfig.buildTransformConfig(); combinedTransformConfig.combineTransformerConfig(this); combinedTransformConfig.registerCombinedTransformers(this); } - // Unlike other subclasses this class does not extend Data or replace it at run time. private TransformCache data = new TransformCache(); public TransformConfig getTransformConfig() diff --git a/engines/pom.xml b/engines/pom.xml deleted file mode 100644 index e69de29b..00000000