mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
Get TransformConfig from a TransformConfigSource List so we can add extra sources like files and remote t-engine config in t-router
This commit is contained in:
@@ -28,6 +28,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.retry</groupId>
|
||||||
|
<artifactId>spring-retry</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.micrometer</groupId>
|
<groupId>io.micrometer</groupId>
|
||||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||||
|
@@ -36,16 +36,28 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
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
|
@SpringBootApplication
|
||||||
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class})
|
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class})
|
||||||
|
@EnableAsync
|
||||||
|
//@EnableScheduling
|
||||||
|
//@EnableRetry
|
||||||
public class Application
|
public class Application
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Application.class);
|
|
||||||
|
|
||||||
@Value("${container.name}")
|
@Value("${container.name}")
|
||||||
private String containerName;
|
private String containerName;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TaskExecutor taskExecutor()
|
||||||
|
{
|
||||||
|
return new SimpleAsyncTaskExecutor();
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags()
|
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags()
|
||||||
{
|
{
|
||||||
|
@@ -28,6 +28,7 @@ package org.alfresco.transform.base;
|
|||||||
|
|
||||||
import org.alfresco.transform.base.html.OptionLister;
|
import org.alfresco.transform.base.html.OptionLister;
|
||||||
import org.alfresco.transform.base.logging.LogEntry;
|
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.base.transform.TransformHandler;
|
||||||
import org.alfresco.transform.client.model.TransformReply;
|
import org.alfresco.transform.client.model.TransformReply;
|
||||||
import org.alfresco.transform.client.model.TransformRequest;
|
import org.alfresco.transform.client.model.TransformRequest;
|
||||||
@@ -62,7 +63,6 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
* #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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -26,9 +26,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.transform.base.config;
|
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.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.common.TransformerDebug;
|
||||||
import org.alfresco.transform.messages.TransformRequestValidator;
|
import org.alfresco.transform.messages.TransformRequestValidator;
|
||||||
import org.alfresco.transform.registry.TransformServiceRegistry;
|
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.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
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.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||||
import static org.alfresco.transform.config.CoreFunction.standardizeCoreVersion;
|
import static org.alfresco.transform.config.CoreFunction.standardizeCoreVersion;
|
||||||
|
|
||||||
@@ -102,4 +106,10 @@ public class WebApplicationConfig implements WebMvcConfigurer
|
|||||||
{
|
{
|
||||||
return standardizeCoreVersion(coreVersionString);
|
return standardizeCoreVersion(coreVersionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public List<TransformConfigSource> transformConfigSources()
|
||||||
|
{
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
* #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;
|
||||||
|
}
|
||||||
|
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
* #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<TransformEngine> transformEngines;
|
||||||
|
@Autowired
|
||||||
|
private List<TransformConfigSource> 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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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();
|
||||||
|
}
|
@@ -23,7 +23,7 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transform.base;
|
package org.alfresco.transform.base.registry;
|
||||||
|
|
||||||
import org.alfresco.transform.config.TransformConfig;
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
import org.alfresco.transform.registry.AbstractTransformRegistry;
|
import org.alfresco.transform.registry.AbstractTransformRegistry;
|
||||||
@@ -32,8 +32,9 @@ import org.alfresco.transform.registry.TransformCache;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -43,38 +44,36 @@ public class TransformRegistry extends AbstractTransformRegistry
|
|||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(TransformRegistry.class);
|
private static final Logger log = LoggerFactory.getLogger(TransformRegistry.class);
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private List<TransformEngine> transformEngines;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private String coreVersion;
|
private String coreVersion;
|
||||||
|
@Autowired
|
||||||
|
private List<TransformConfigSource> transformConfigSources;
|
||||||
|
|
||||||
private TransformConfig transformConfigBeforeIncompleteTransformsAreRemoved;
|
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();
|
CombinedTransformConfig combinedTransformConfig = new CombinedTransformConfig();
|
||||||
if (transformEngines != null)
|
|
||||||
{
|
transformConfigSources.stream()
|
||||||
transformEngines.stream()
|
.sorted(Comparator.comparing(TransformConfigSource::getReadFrom))
|
||||||
.sorted(Comparator.comparing(TransformEngine::getTransformEngineName))
|
.forEach(source -> {
|
||||||
.forEach(transformEngine -> {
|
TransformConfig transformConfig = source.getTransformConfig();
|
||||||
TransformConfig transformConfig = transformEngine.getTransformConfig();
|
|
||||||
if (transformConfig != null) // if not a wrapping TransformEngine like all-in-one
|
|
||||||
{
|
|
||||||
setCoreVersionOnSingleStepTransformers(transformConfig, coreVersion);
|
setCoreVersionOnSingleStepTransformers(transformConfig, coreVersion);
|
||||||
combinedTransformConfig.addTransformConfig(transformConfig,
|
combinedTransformConfig.addTransformConfig(transformConfig, source.getReadFrom(), source.getBaseUrl(),
|
||||||
transformEngine.getTransformEngineName(), "---", this);
|
this);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
transformConfigBeforeIncompleteTransformsAreRemoved = combinedTransformConfig.buildTransformConfig();
|
transformConfigBeforeIncompleteTransformsAreRemoved = combinedTransformConfig.buildTransformConfig();
|
||||||
combinedTransformConfig.combineTransformerConfig(this);
|
combinedTransformConfig.combineTransformerConfig(this);
|
||||||
combinedTransformConfig.registerCombinedTransformers(this);
|
combinedTransformConfig.registerCombinedTransformers(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlike other subclasses this class does not extend Data or replace it at run time.
|
|
||||||
private TransformCache data = new TransformCache();
|
private TransformCache data = new TransformCache();
|
||||||
|
|
||||||
public TransformConfig getTransformConfig()
|
public TransformConfig getTransformConfig()
|
Reference in New Issue
Block a user