Expand my Community achievements bar.

TranslationException: Error getting Cloud Config credentials

Avatar

Level 2

My custom bootstrap connector (forked from this) produces this error running on AEM Cloud:

 

com.adobe.granite.translation.connector.bootstrap.core.impl.BootstrapTranslationServiceFactoryImpl Error while resolving config resource
com.adobe.granite.translation.api.TranslationException: Error getting Cloud Config credentials

 

The configuration is there in conf/global and interestingly it works in one environment but not in an other.

 

The error message refers to this function:

 

    public BootstrapTranslationCloudConfigImpl(Resource translationConfigResource) throws TranslationException {
        log.trace("BootstrapTranslationCloudConfigImpl.");

        Resource configContent;
        if (JcrConstants.JCR_CONTENT.equals(translationConfigResource.getName())) {
            configContent = translationConfigResource;
        } else {
            configContent = translationConfigResource.getChild(JcrConstants.JCR_CONTENT);
        }

        if (configContent != null) {
            ValueMap properties = configContent.adaptTo(ValueMap.class);

            this.dummyServerUrl = properties.get(PROPERTY_DUMMY_SERVER_URL, "");
            this.dummyConfigId = properties.get(PROPERTY_DUMMY_CONFIG_ID, "");
            this.previewPath = properties.get(PROPERTY_PREVIEW_PATH, ""); 

            if (log.isTraceEnabled()) {
                log.trace("Created Bootstrap Cloud Config with the following:");
                log.trace("dummyServerUrl: {}", dummyServerUrl);
                log.trace("dummyConfigId: {}", dummyConfigId);
                log.trace("previewPath: {}", previewPath);
                
            }
        } else {
            throw new TranslationException("Error getting Cloud Config credentials",
                TranslationException.ErrorCode.MISSING_CREDENTIALS);
        }
    }

 

called by this:

 

	@Override
	public TranslationService createTranslationService(TranslationMethod translationMethod, String cloudConfigPath)
			throws TranslationException {
		log.trace("BootstrapTranslationServiceFactoryImpl.createTranslationService");

		BootstrapTranslationCloudConfig bootstrapCloudConfg = null;

		String dummyConfigId = "";
		String dummyServerUrl = "";
		String previewPath = "";

		try {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put(ResourceResolverFactory.SUBSERVICE, "bootstrap-service");
			ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(param);
			Resource res = resourceResolver.getResource(cloudConfigPath);
			bootstrapCloudConfg = (BootstrapTranslationCloudConfig) cloudConfigUtil
					.getCloudConfigObjectFromPath(res, BootstrapTranslationCloudConfig.class, cloudConfigPath);
			if (res != null) {
				bootstrapCloudConfg = new BootstrapTranslationCloudConfigImpl(res);
			}
		} catch (Exception ex) {
			log.error("Error while resolving config resource", ex);
		}

		if (bootstrapCloudConfg != null) {
			dummyConfigId = bootstrapCloudConfg.getDummyConfigId();
			dummyServerUrl = bootstrapCloudConfg.getDummyServerUrl();
			previewPath = bootstrapCloudConfg.getPreviewPath();
		}

		Map<String, String> availableLanguageMap = new HashMap<String, String>();
		Map<String, String> availableCategoryMap = new HashMap<String, String>();
		return new BootstrapTranslationServiceImpl(availableLanguageMap, availableCategoryMap, factoryName,
				isPreviewEnabled, isPseudoLocalizationDisabled, exportFormat, dummyConfigId, dummyServerUrl, previewPath
				translationConfig, bootstrapTmsService);
	}

 

Why it fails to load the configuration? 

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

3 Replies

Avatar

Community Advisor

Hi @thebestusernameifound ,

The error message "Error getting Cloud Config credentials" suggests that there's an issue retrieving the configuration properties required for initializing the BootstrapTranslationCloudConfigImpl object. Let's break down the code and look for potential reasons for this failure:

  1. Resource Resolution: Check if the cloudConfigPath provided to createTranslationService method is correct and points to the desired configuration resource.

  2. Resource Retrieval: Ensure that the resourceResolver.getResource(cloudConfigPath) call returns a valid Resource object.

  3. Config Content Retrieval: Make sure that the configContent object obtained from translationConfigResource contains the expected content.

  4. Properties Retrieval: Verify if the properties required (dummyServerUrl, dummyConfigId, previewPath) are present and accessible in the configContent.

Here are some potential issues in your code:

  1. Redundant Initialization: You are initializing bootstrapCloudConfg twice. First, you assign it by calling cloudConfigUtil.getCloudConfigObjectFromPath(...), and then you initialize it again immediately afterward using new BootstrapTranslationCloudConfigImpl(res). You should remove one of these initializations depending on your requirement.

  2. Error Handling: The catch block in createTranslationService method logs the error but continues execution without throwing an exception. This might lead to unexpected behavior, especially if the configuration is critical for the functionality. Consider rethrowing the exception or handling it appropriately based on the use case.

  3. Logging: Ensure that you log enough information to diagnose the issue properly. For example, log the value of cloudConfigPath and res to ensure they are correct.

Here's a revised version of your code with potential improvements:

 

@Override
public TranslationService createTranslationService(TranslationMethod translationMethod, String cloudConfigPath)
        throws TranslationException {
    log.trace("BootstrapTranslationServiceFactoryImpl.createTranslationService");

    BootstrapTranslationCloudConfig bootstrapCloudConfg = null;

    String dummyConfigId = "";
    String dummyServerUrl = "";
    String previewPath = "";

    try {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put(ResourceResolverFactory.SUBSERVICE, "bootstrap-service");
        ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(param);
        Resource res = resourceResolver.getResource(cloudConfigPath);
        
        if (res != null) {
            // Initialize bootstrapCloudConfg only once
            bootstrapCloudConfg = new BootstrapTranslationCloudConfigImpl(res);
        }
    } catch (Exception ex) {
        log.error("Error while resolving config resource", ex);
        // Rethrow TranslationException to indicate the failure to get config
        throw new TranslationException("Error getting Cloud Config credentials", ex,
            TranslationException.ErrorCode.MISSING_CREDENTIALS);
    }

    if (bootstrapCloudConfg != null) {
        dummyConfigId = bootstrapCloudConfg.getDummyConfigId();
        dummyServerUrl = bootstrapCloudConfg.getDummyServerUrl();
        previewPath = bootstrapCloudConfg.getPreviewPath();
    }

    Map<String, String> availableLanguageMap = new HashMap<String, String>();
    Map<String, String> availableCategoryMap = new HashMap<String, String>();
    return new BootstrapTranslationServiceImpl(availableLanguageMap, availableCategoryMap, factoryName,
            isPreviewEnabled, isPseudoLocalizationDisabled, exportFormat, dummyConfigId, dummyServerUrl, previewPath
            translationConfig, bootstrapTmsService);
}

 

Ensure you thoroughly debug and log relevant information to understand why the configuration retrieval fails. This will help in diagnosing the issue more effectively.

Hi,

 

Thanks for your insights, I will definitely revise the code. However, it is still not clear why the current code runs well on one instance and fails on an other. Do you know any reason why the configuration is not loaded?

Avatar

Administrator

@thebestusernameifound Did you find the suggestions helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni