From 512540e32e309ead8fe64b0ed00d8a82fd6ce53a Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Mon, 22 Nov 2021 12:53:22 +0000 Subject: [PATCH] ACS-2270 Read T-Engine config in alphabetical order (#806) * T-Engines config need to be combined in the same predefined order in the all-in-one transformer, T-Router and the Content Repository with individual T-Engines. --- .../LocalTransformServiceRegistry.java | 43 +++++------- .../LocalTransformServiceRegistryTest.java | 68 +++++++++++++++++++ .../transform/TransformerConfigTestSuite.java | 5 +- 3 files changed, 88 insertions(+), 28 deletions(-) create mode 100644 repository/src/test/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistryTest.java diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistry.java b/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistry.java index c71375601f..cde68e2f63 100644 --- a/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistry.java +++ b/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistry.java @@ -26,7 +26,6 @@ package org.alfresco.repo.content.transform; import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -34,6 +33,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.function.Consumer; +import java.util.stream.Collectors; import org.alfresco.service.cmr.repository.MimetypeService; import org.alfresco.transform.client.model.config.TransformOptionGroup; @@ -134,7 +134,7 @@ public class LocalTransformServiceRegistry extends TransformServiceRegistryImpl public boolean readConfig() throws IOException { CombinedConfig combinedConfig = new CombinedConfig(getLog(), this); - List urls = getTEngineUrls(); + List urls = getTEngineUrlsSortedByName(); boolean successReadingConfig = combinedConfig.addRemoteConfig(urls, "T-Engine"); successReadingConfig &= combinedConfig.addLocalConfig("alfresco/transforms"); if (pipelineConfigDir != null && !pipelineConfigDir.isBlank()) @@ -321,30 +321,23 @@ public class LocalTransformServiceRegistry extends TransformServiceRegistryImpl return log; } - private List getTEngineUrls() + /** + * @return urls from System or Alfresco global properties that match of localTransform..url= sorted + * in order. + */ + List getTEngineUrlsSortedByName() { - List urls = new ArrayList<>(); - for (Object o : getKeySet()) - { - if (o instanceof String) - { - String key = (String)o; - if (key.startsWith(LOCAL_TRANSFORMER) && key.endsWith(URL)) - { - Object url = getProperty(key, null); - if (url instanceof String) - { - String urlStr = ((String)url).trim(); - if (!urlStr.isEmpty()) - { - urls.add((String) url); - } - } - } - } - } - - return urls; + // T-Engines are sorted by name so they are in the same order as in the all-in-one transformer and the + // T-Router. See AIOCustomConfig#getTEnginesSortedByName and TransformersConfigRegistry#retrieveRemoteConfig. + return getKeySet().stream() + .filter(key -> key instanceof String) + .filter(key -> key.startsWith(LOCAL_TRANSFORMER) && key.endsWith(URL)) + .sorted() + .map(key -> getProperty(key, null)) + .filter(url -> url instanceof String) + .map(url -> url.trim()) + .filter(url -> !url.isEmpty()) + .collect(Collectors.toList()); } private int getStartupRetryPeriodSeconds(String name) diff --git a/repository/src/test/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistryTest.java b/repository/src/test/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistryTest.java new file mode 100644 index 0000000000..43947bce6a --- /dev/null +++ b/repository/src/test/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistryTest.java @@ -0,0 +1,68 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2021 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.repo.content.transform; + +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.io.IOException; +import java.util.Properties; +import java.util.StringJoiner; + +import static org.alfresco.repo.content.transform.LocalTransformServiceRegistry.LOCAL_TRANSFORMER; +import static org.alfresco.repo.content.transform.LocalTransformServiceRegistry.URL; +import static org.junit.Assert.assertEquals; + +public class LocalTransformServiceRegistryTest +{ + @Spy + private Properties properties = new Properties(); + + @InjectMocks + LocalTransformServiceRegistry registry = new LocalTransformServiceRegistry(); + + @Rule + public MockitoRule initRule = MockitoJUnit.rule(); + + @Test + public void testGetTEngineUrlsSortedByName() throws IOException + { + properties.put(LOCAL_TRANSFORMER+"aa"+URL, "aa"); + properties.put(LOCAL_TRANSFORMER+"engine1"+URL, "http_xxxx1"); + properties.put(LOCAL_TRANSFORMER+"engine3"+URL, "http3"); + properties.put(LOCAL_TRANSFORMER+"engine2"+URL, "http_xx2"); + properties.put(LOCAL_TRANSFORMER+"bb"+URL, "bb"); + properties.put(LOCAL_TRANSFORMER+"b"+URL, "b"); + + StringJoiner orderEngineConfigRead = new StringJoiner(","); + registry.getTEngineUrlsSortedByName().forEach(name -> orderEngineConfigRead.add(name)); + assertEquals("aa,b,bb,http_xxxx1,http_xx2,http3", orderEngineConfigRead.toString()); + } +} diff --git a/repository/src/test/java/org/alfresco/repo/content/transform/TransformerConfigTestSuite.java b/repository/src/test/java/org/alfresco/repo/content/transform/TransformerConfigTestSuite.java index 1ad493937e..9c711c2154 100644 --- a/repository/src/test/java/org/alfresco/repo/content/transform/TransformerConfigTestSuite.java +++ b/repository/src/test/java/org/alfresco/repo/content/transform/TransformerConfigTestSuite.java @@ -44,16 +44,15 @@ import org.junit.runners.Suite.SuiteClasses; TransformerLogTest.class, TransformerDebugLogTest.class, + LocalTransformServiceRegistryTest.class, + TransformerConfigMBeanImplTest.class}) /** * Test classes in the Transformers subsystem * * @author Alan Davis - * - * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries. */ -@Deprecated public class TransformerConfigTestSuite { }