logger corrections update

This commit is contained in:
jaikant79
2025-02-20 16:03:22 +05:30
parent b01fc2263d
commit 1565b5bb79

View File

@@ -53,15 +53,14 @@ import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_C
/** /**
* This class reads multiple T-Engine config and local files and registers as if they were all * This class reads multiple T-Engine config and local files and registers as if they were all
* in one file. Transform options are shared between all sources.<p> * in one file. Transform options are shared between all sources.<p>
* * <p>
* The caller should make calls to {@link #addRemoteConfig(List, String)}, {@link #addLocalConfig(String)} or * The caller should make calls to {@link #addRemoteConfig(List, String)}, {@link #addLocalConfig(String)} or
* {@link CombinedTransformConfig#addTransformConfig(TransformConfig, String, String, AbstractTransformRegistry)} * {@link CombinedTransformConfig#addTransformConfig(TransformConfig, String, String, AbstractTransformRegistry)}
* followed by a call to {@link #register(TransformServiceRegistryImpl)}. * followed by a call to {@link #register(TransformServiceRegistryImpl)}.
* *
* @author adavis * @author adavis
*/ */
public class CombinedConfig extends CombinedTransformConfig public class CombinedConfig extends CombinedTransformConfig {
{
public static final String X_ALFRESCO_RETRY_NEEDED_HEADER = "X-Alfresco-Retry-Needed"; public static final String X_ALFRESCO_RETRY_NEEDED_HEADER = "X-Alfresco-Retry-Needed";
private final Log log; private final Log log;
@@ -71,39 +70,30 @@ public class CombinedConfig extends CombinedTransformConfig
private final HttpClientConfig httpClientConfig; private final HttpClientConfig httpClientConfig;
public CombinedConfig(Log log, AbstractTransformRegistry registry, HttpClientConfig httpClientConfig) public CombinedConfig(Log log, AbstractTransformRegistry registry, HttpClientConfig httpClientConfig) {
{
this.httpClientConfig = httpClientConfig; this.httpClientConfig = httpClientConfig;
this.log = log; this.log = log;
configFileFinder = new ConfigFileFinder(jsonObjectMapper) configFileFinder = new ConfigFileFinder(jsonObjectMapper) {
{
@Override @Override
protected void readJson(JsonNode jsonNode, String readFrom, String baseUrl) protected void readJson(JsonNode jsonNode, String readFrom, String baseUrl) {
{
TransformConfig transformConfig = jsonObjectMapper.convertValue(jsonNode, TransformConfig.class); TransformConfig transformConfig = jsonObjectMapper.convertValue(jsonNode, TransformConfig.class);
addTransformConfig(transformConfig, readFrom, baseUrl, registry); addTransformConfig(transformConfig, readFrom, baseUrl, registry);
} }
}; };
} }
public boolean addLocalConfig(String path) public boolean addLocalConfig(String path) {
{
return configFileFinder.readFiles(path, log); return configFileFinder.readFiles(path, log);
} }
public boolean addRemoteConfig(List<String> urls, String remoteType) throws IOException public boolean addRemoteConfig(List<String> urls, String remoteType) throws IOException {
{ try (CloseableHttpClient httpclient = HttpClient4Factory.createHttpClient(httpClientConfig)) {
try(CloseableHttpClient httpclient = HttpClient4Factory.createHttpClient(httpClientConfig))
{
boolean successReadingConfig = true; boolean successReadingConfig = true;
for (String url : urls) for (String url : urls) {
{ if (addRemoteConfig(httpclient, url, remoteType)) {
if (addRemoteConfig(httpclient, url, remoteType))
{
tEngineCount++; tEngineCount++;
} else } else {
{
successReadingConfig = false; successReadingConfig = false;
} }
} }
@@ -111,68 +101,49 @@ public class CombinedConfig extends CombinedTransformConfig
} }
} }
private boolean addRemoteConfig(CloseableHttpClient httpclient, String baseUrl, String remoteType) private boolean addRemoteConfig(CloseableHttpClient httpclient, String baseUrl, String remoteType) {
{
String url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + ENDPOINT_TRANSFORM_CONFIG_LATEST; String url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + ENDPOINT_TRANSFORM_CONFIG_LATEST;
HttpGet httpGet = new HttpGet(url); HttpGet httpGet = new HttpGet(url);
boolean successReadingConfig = true; boolean successReadingConfig = true;
try try {
{ try (CloseableHttpResponse response = execute(httpclient, httpGet)) {
try (CloseableHttpResponse response = execute(httpclient, httpGet))
{
StatusLine statusLine = response.getStatusLine(); StatusLine statusLine = response.getStatusLine();
if (statusLine == null) if (statusLine == null) {
{
throw new AlfrescoRuntimeException(remoteType + " on " + url + " returned no status "); throw new AlfrescoRuntimeException(remoteType + " on " + url + " returned no status ");
} }
HttpEntity resEntity = response.getEntity(); HttpEntity resEntity = response.getEntity();
if (resEntity != null) if (resEntity != null) {
{
int statusCode = statusLine.getStatusCode(); int statusCode = statusLine.getStatusCode();
if (statusCode == 200) if (statusCode == 200) {
{ try {
try
{
String content = getContent(resEntity); String content = getContent(resEntity);
try (StringReader reader = new StringReader(content)) try (StringReader reader = new StringReader(content)) {
{
int transformCount = transformerCount(); int transformCount = transformerCount();
configFileFinder.readFile(reader, remoteType + " on " + baseUrl, "json", baseUrl, log); configFileFinder.readFile(reader, remoteType + " on " + baseUrl, "json", baseUrl, log);
if (transformCount == transformerCount() || response.containsHeader(X_ALFRESCO_RETRY_NEEDED_HEADER)) if (transformCount == transformerCount() || response.containsHeader(X_ALFRESCO_RETRY_NEEDED_HEADER)) {
{
successReadingConfig = false; successReadingConfig = false;
} }
} }
EntityUtils.consume(resEntity); EntityUtils.consume(resEntity);
} } catch (IOException e) {
catch (IOException e)
{
throw new AlfrescoRuntimeException("Failed to read the returned content from " + throw new AlfrescoRuntimeException("Failed to read the returned content from " +
remoteType + " on " + url, e); remoteType + " on " + url, e);
} }
} } else {
else
{
String message = getErrorMessage(resEntity); String message = getErrorMessage(resEntity);
throw new AlfrescoRuntimeException(remoteType + " on " + url + " returned a " + statusCode + throw new AlfrescoRuntimeException(remoteType + " on " + url + " returned a " + statusCode +
" status " + message); " status " + message);
} }
} } else {
else
{
throw new AlfrescoRuntimeException(remoteType + " on " + url + " did not return an entity " + url); throw new AlfrescoRuntimeException(remoteType + " on " + url + " did not return an entity " + url);
} }
} } catch (IOException e) {
catch (IOException e)
{
throw new AlfrescoRuntimeException("This error was generated because the engine requires Transform AIO but it is not being used " + remoteType + throw new AlfrescoRuntimeException("This error was generated because the engine requires Transform AIO but it is not being used " + remoteType +
" on " + url, e); " on " + url, e);
} }
} } catch (AlfrescoRuntimeException e) {
catch (AlfrescoRuntimeException e)
{
log.error(e.getMsgId()); log.error(e.getMsgId());
successReadingConfig = false; successReadingConfig = false;
} }
@@ -180,28 +151,23 @@ public class CombinedConfig extends CombinedTransformConfig
} }
// Tests mock the return values // Tests mock the return values
CloseableHttpResponse execute(CloseableHttpClient httpclient, HttpGet httpGet) throws IOException CloseableHttpResponse execute(CloseableHttpClient httpclient, HttpGet httpGet) throws IOException {
{
return httpclient.execute(httpGet); return httpclient.execute(httpGet);
} }
// Tests mock the return values // Tests mock the return values
String getContent(HttpEntity resEntity) throws IOException String getContent(HttpEntity resEntity) throws IOException {
{
return EntityUtils.toString(resEntity); return EntityUtils.toString(resEntity);
} }
// Strip out just the error message in the response // Strip out just the error message in the response
private String getErrorMessage(HttpEntity resEntity) throws IOException private String getErrorMessage(HttpEntity resEntity) throws IOException {
{
String message = ""; String message = "";
String content = getContent(resEntity); String content = getContent(resEntity);
int i = content.indexOf("\"message\":\""); int i = content.indexOf("\"message\":\"");
if (i != -1) if (i != -1) {
{
int j = content.indexOf("\",\"path\":", i); int j = content.indexOf("\",\"path\":", i);
if (j != -1) if (j != -1) {
{
message = content.substring(i + 11, j); message = content.substring(i + 11, j);
} }
} }
@@ -209,18 +175,17 @@ public class CombinedConfig extends CombinedTransformConfig
} }
@Override @Override
protected boolean isPassThroughTransformName(String name) protected boolean isPassThroughTransformName(String name) {
{
return name.equals(LocalPassThroughTransform.NAME); return name.equals(LocalPassThroughTransform.NAME);
} }
/** /**
* Adds a PassThrough transform where the source and target mimetypes are identical, or transforms to "text/plain" * Adds a PassThrough transform where the source and target mimetypes are identical, or transforms to "text/plain"
* from selected text based types. * from selected text based types.
*
* @param mimetypeService to find all the mimetypes * @param mimetypeService to find all the mimetypes
*/ */
public void addPassThroughTransformer(MimetypeService mimetypeService, AbstractTransformRegistry registry) public void addPassThroughTransformer(MimetypeService mimetypeService, AbstractTransformRegistry registry) {
{
List<String> mimetypes = mimetypeService.getMimetypes(); List<String> mimetypes = mimetypeService.getMimetypes();
Transformer transformer = LocalPassThroughTransform.getConfig(mimetypes); Transformer transformer = LocalPassThroughTransform.getConfig(mimetypes);
TransformConfig transformConfig = TransformConfig.builder() TransformConfig transformConfig = TransformConfig.builder()
@@ -229,8 +194,7 @@ public class CombinedConfig extends CombinedTransformConfig
addTransformConfig(transformConfig, "based on mimetype list", null, registry); addTransformConfig(transformConfig, "based on mimetype list", null, registry);
} }
public void register(TransformServiceRegistryImpl registry) public void register(TransformServiceRegistryImpl registry) {
{
TransformServiceRegistryImpl.Data data = registry.getData(); TransformServiceRegistryImpl.Data data = registry.getData();
data.setTEngineCount(tEngineCount); data.setTEngineCount(tEngineCount);
data.setFileCount(configFileFinder.getFileCount()); data.setFileCount(configFileFinder.getFileCount());