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);
}
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<>();
}
Aggregations