Search in sources :

Example 1 with ComponentConfiguration

use of com.amazon.aws.iot.greengrass.component.common.ComponentConfiguration in project aws-greengrass-nucleus by aws-greengrass.

the class KernelConfigResolverTest method getComponent.

private ComponentRecipe getComponent(String componentName, String componentVersion, Map<String, DependencyProperties> dependencies, JsonNode defaultConfiguration, String jsonPointerStr, String crossComponentName, String crossComponentJsonPointerStr) {
    ComponentConfiguration componentConfiguration = defaultConfiguration == null ? null : ComponentConfiguration.builder().defaultConfiguration(defaultConfiguration).build();
    Semver version = new Semver(componentVersion);
    return new ComponentRecipe(RecipeFormatVersion.JAN_25_2020, componentName, version, "component in test", "publisher", componentConfiguration, getSimpleComponentLifecycle(componentName, jsonPointerStr, crossComponentName, crossComponentJsonPointerStr), Collections.emptyList(), dependencies, null);
}
Also used : ComponentConfiguration(com.amazon.aws.iot.greengrass.component.common.ComponentConfiguration) ComponentRecipe(com.aws.greengrass.componentmanager.models.ComponentRecipe) Semver(com.vdurmont.semver4j.Semver)

Example 2 with ComponentConfiguration

use of com.amazon.aws.iot.greengrass.component.common.ComponentConfiguration in project aws-greengrass-nucleus by aws-greengrass.

the class KernelConfigResolver method resolveConfigurationToApply.

/**
 * Resolve configurations to apply for a component. It resolves based on current running config, default config, and
 * config update operation.
 *
 * @param configurationUpdateOperation nullable component configuration update operation.
 * @param componentRecipe              component recipe containing default configuration.
 * @param document                     deployment document
 * @return resolved configuration for this component. non null.
 */
@SuppressWarnings("PMD.ConfusingTernary")
private Map<String, Object> resolveConfigurationToApply(@Nullable ConfigurationUpdateOperation configurationUpdateOperation, ComponentRecipe componentRecipe, DeploymentDocument document) {
    // try read the running service config
    try (Context context = new Context()) {
        Configuration currentRunningConfig = new Configuration(context);
        // Copy from running config (if any)
        Topics serviceTopics = kernel.findServiceTopic(componentRecipe.getComponentName());
        if (serviceTopics != null) {
            Topics configuration = serviceTopics.findTopics(CONFIGURATION_CONFIG_KEY);
            if (configuration != null) {
                currentRunningConfig.copyFrom(configuration);
            }
        } else if (ComponentType.NUCLEUS.equals(componentRecipe.getComponentType())) {
            // Copy from existing Nucleus config (if any)
            Topics nucleusTopics = kernel.findServiceTopic(deviceConfiguration.getNucleusComponentName());
            if (nucleusTopics != null) {
                Topics nucleusConfig = nucleusTopics.findTopics(CONFIGURATION_CONFIG_KEY);
                if (nucleusConfig != null) {
                    currentRunningConfig.copyFrom(nucleusConfig);
                }
            }
        }
        // Remove keys which want to be reset to their default value
        if (configurationUpdateOperation != null) {
            removeKeysFromConfigWhichAreReset(currentRunningConfig, configurationUpdateOperation.getPathsToReset());
        }
        // Merge in the defaults with timestamp 1 so that they don't overwrite any pre-existing values
        JsonNode defaultConfig = Optional.ofNullable(componentRecipe.getComponentConfiguration()).map(ComponentConfiguration::getDefaultConfiguration).orElse(// init null to be empty default config
        MAPPER.createObjectNode());
        // Merge in the defaults from the recipe using timestamp 1 to denote a default
        currentRunningConfig.mergeMap(1, MAPPER.convertValue(defaultConfig, Map.class));
        currentRunningConfig.context.waitForPublishQueueToClear();
        // Merge in the requested config updates
        if (configurationUpdateOperation != null && configurationUpdateOperation.getValueToMerge() != null) {
            currentRunningConfig.mergeMap(document.getTimestamp(), configurationUpdateOperation.getValueToMerge());
        }
        return currentRunningConfig.toPOJO();
    } catch (IOException ignored) {
    }
    return new HashMap<>();
}
Also used : Context(com.aws.greengrass.dependency.Context) Topics(com.aws.greengrass.config.Topics) DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) Configuration(com.aws.greengrass.config.Configuration) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) ComponentConfiguration(com.amazon.aws.iot.greengrass.component.common.ComponentConfiguration) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ComponentConfiguration (com.amazon.aws.iot.greengrass.component.common.ComponentConfiguration)2 ComponentRecipe (com.aws.greengrass.componentmanager.models.ComponentRecipe)1 Configuration (com.aws.greengrass.config.Configuration)1 Topics (com.aws.greengrass.config.Topics)1 Context (com.aws.greengrass.dependency.Context)1 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)1 DeploymentPackageConfiguration (com.aws.greengrass.deployment.model.DeploymentPackageConfiguration)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Semver (com.vdurmont.semver4j.Semver)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1