Search in sources :

Example 1 with CONFIGURATION_CONFIG_KEY

use of com.aws.greengrass.componentmanager.KernelConfigResolver.CONFIGURATION_CONFIG_KEY in project aws-greengrass-nucleus by aws-greengrass.

the class DeviceConfiguration method persistInitialLaunchParams.

/**
 * Persist initial launch parameters of JVM options.
 *
 * @param kernelAlts KernelAlternatives instance
 */
void persistInitialLaunchParams(KernelAlternatives kernelAlts) {
    if (Files.exists(kernelAlts.getLaunchParamsPath())) {
        logger.atDebug().log("Nucleus launch parameters has already been set up");
        return;
    }
    // Persist initial Nucleus launch parameters
    try {
        String jvmOptions = ManagementFactory.getRuntimeMXBean().getInputArguments().stream().sorted().filter(s -> !s.startsWith(JVM_OPTION_ROOT_PATH)).collect(Collectors.joining(" "));
        kernel.getConfig().lookup(SERVICES_NAMESPACE_TOPIC, getNucleusComponentName(), CONFIGURATION_CONFIG_KEY, DEVICE_PARAM_JVM_OPTIONS).withNewerValue(DEFAULT_VALUE_TIMESTAMP + 1, jvmOptions);
        kernelAlts.writeLaunchParamsToFile(jvmOptions);
        logger.atInfo().log("Successfully setup Nucleus launch parameters");
    } catch (IOException e) {
        logger.atError().log("Unable to setup Nucleus launch parameters", e);
    }
}
Also used : PackageLoadingException(com.aws.greengrass.componentmanager.exceptions.PackageLoadingException) SerializerFactory.getRecipeSerializer(com.amazon.aws.iot.greengrass.component.common.SerializerFactory.getRecipeSerializer) Arrays(java.util.Arrays) URISyntaxException(java.net.URISyntaxException) LogStore(com.aws.greengrass.logging.impl.config.LogStore) Validator(com.aws.greengrass.config.Validator) ComponentConfigurationValidationException(com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException) SERVICE_LIFECYCLE_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICE_LIFECYCLE_NAMESPACE_TOPIC) LogFormat(com.aws.greengrass.logging.impl.config.LogFormat) Level(org.slf4j.event.Level) Map(java.util.Map) SETENV_CONFIG_NAMESPACE(com.aws.greengrass.lifecyclemanager.GreengrassService.SETENV_CONFIG_NAMESPACE) LogManager(com.aws.greengrass.logging.impl.LogManager) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) Node(com.aws.greengrass.config.Node) SERVICE_TYPE_TOPIC_KEY(com.aws.greengrass.lifecyclemanager.Kernel.SERVICE_TYPE_TOPIC_KEY) TLSAuthException(com.aws.greengrass.util.exceptions.TLSAuthException) Collectors(java.util.stream.Collectors) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) StandardCharsets(java.nio.charset.StandardCharsets) SERVICES_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICES_NAMESPACE_TOPIC) ChildChanged(com.aws.greengrass.config.ChildChanged) Objects(java.util.Objects) Topics(com.aws.greengrass.config.Topics) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) NucleusPaths(com.aws.greengrass.util.NucleusPaths) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) CaseInsensitiveString(com.aws.greengrass.config.CaseInsensitiveString) Optional(java.util.Optional) SecurityService(com.aws.greengrass.security.SecurityService) DefaultAwsRegionProviderChain(software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain) ComponentStore(com.aws.greengrass.componentmanager.ComponentStore) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) VERSION_CONFIG_KEY(com.aws.greengrass.componentmanager.KernelConfigResolver.VERSION_CONFIG_KEY) COPY_ATTRIBUTES(java.nio.file.StandardCopyOption.COPY_ATTRIBUTES) CONFIGURATION_CONFIG_KEY(com.aws.greengrass.componentmanager.KernelConfigResolver.CONFIGURATION_CONFIG_KEY) Coerce(com.aws.greengrass.util.Coerce) AtomicReference(java.util.concurrent.atomic.AtomicReference) LogConfigUpdate(com.aws.greengrass.logging.impl.config.model.LogConfigUpdate) ArrayList(java.util.ArrayList) Platform(com.aws.greengrass.util.platforms.Platform) Inject(javax.inject.Inject) MAIN_SERVICE_NAME(com.aws.greengrass.lifecyclemanager.KernelCommandLine.MAIN_SERVICE_NAME) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) NOFOLLOW_LINKS(java.nio.file.LinkOption.NOFOLLOW_LINKS) Semver(com.vdurmont.semver4j.Semver) ManagementFactory(java.lang.management.ManagementFactory) Region(software.amazon.awssdk.regions.Region) DependencyProperties(com.amazon.aws.iot.greengrass.component.common.DependencyProperties) SERVICE_DEPENDENCIES_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICE_DEPENDENCIES_NAMESPACE_TOPIC) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) FileSystemPermission(com.aws.greengrass.util.FileSystemPermission) Files(java.nio.file.Files) Permissions(com.aws.greengrass.util.Permissions) IOException(java.io.IOException) ComponentRecipe(com.aws.greengrass.componentmanager.models.ComponentRecipe) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) KeyManager(javax.net.ssl.KeyManager) Topic(com.aws.greengrass.config.Topic) ComponentType(com.amazon.aws.iot.greengrass.component.common.ComponentType) Utils(com.aws.greengrass.util.Utils) RecipeLoader(com.aws.greengrass.componentmanager.converter.RecipeLoader) WhatHappened(com.aws.greengrass.config.WhatHappened) Paths(java.nio.file.Paths) KernelAlternatives(com.aws.greengrass.lifecyclemanager.KernelAlternatives) KernelAlternatives.locateCurrentKernelUnpackDir(com.aws.greengrass.lifecyclemanager.KernelAlternatives.locateCurrentKernelUnpackDir) DeviceConfigurationException(com.aws.greengrass.deployment.exceptions.DeviceConfigurationException) KernelConfigResolver(com.aws.greengrass.componentmanager.KernelConfigResolver) Collections(java.util.Collections) Logger(com.aws.greengrass.logging.api.Logger) DEFAULT_VALUE_TIMESTAMP(com.aws.greengrass.config.Topic.DEFAULT_VALUE_TIMESTAMP) CaseInsensitiveString(com.aws.greengrass.config.CaseInsensitiveString) IOException(java.io.IOException)

Example 2 with CONFIGURATION_CONFIG_KEY

use of com.aws.greengrass.componentmanager.KernelConfigResolver.CONFIGURATION_CONFIG_KEY in project aws-greengrass-nucleus by aws-greengrass.

the class AuthorizationPolicyParser method parseAllAuthorizationPolicies.

/**
 * Given a kernel object, construct and return a map of AuthorizationPolicy objects that may exist,
 * grouped into lists of the same destination component.
 * This is used only upon kernel startup, to initialize all policies.
 * Never returns null.
 *
 * @param kernel Kernel
 * @return {@Map} of {@String} keys and {@List} of {@AuthorizationPolicy}'s as values"
 */
public Map<String, List<AuthorizationPolicy>> parseAllAuthorizationPolicies(Kernel kernel) {
    Map<String, List<AuthorizationPolicy>> primaryAuthorizationPolicyMap = new HashMap<>();
    Topics allServices = kernel.getConfig().findTopics(SERVICES_NAMESPACE_TOPIC);
    if (allServices == null) {
        logger.atWarn("load-authorization-all-services-component-config-retrieval-error").log("Unable to retrieve services config");
        return primaryAuthorizationPolicyMap;
    }
    // For each component
    for (Node service : allServices) {
        if (service == null) {
            continue;
        }
        if (!(service instanceof Topics)) {
            continue;
        }
        Topics serviceConfig = (Topics) service;
        String componentName = Kernel.findServiceForNode(serviceConfig);
        Node accessControlMapTopic = serviceConfig.findNode(CONFIGURATION_CONFIG_KEY, ACCESS_CONTROL_NAMESPACE_TOPIC);
        if (accessControlMapTopic == null) {
            continue;
        }
        // Retrieve all policies, mapped to each policy type
        Map<String, List<AuthorizationPolicy>> componentAuthorizationPolicyMap = parseAllPoliciesForComponent(accessControlMapTopic, componentName);
        // For each policy type (e.g. aws.greengrass.ipc.pubsub)
        for (Map.Entry<String, List<AuthorizationPolicy>> policyTypeList : componentAuthorizationPolicyMap.entrySet()) {
            String policyType = policyTypeList.getKey();
            List<AuthorizationPolicy> policyList = policyTypeList.getValue();
            // If multiple components have policies for the same policy type
            primaryAuthorizationPolicyMap.computeIfAbsent(policyType, k -> new ArrayList<>()).addAll(policyList);
        }
    }
    return primaryAuthorizationPolicyMap;
}
Also used : Node(com.aws.greengrass.config.Node) CONFIGURATION_CONFIG_KEY(com.aws.greengrass.componentmanager.KernelConfigResolver.CONFIGURATION_CONFIG_KEY) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) HashMap(java.util.HashMap) Coerce(com.aws.greengrass.util.Coerce) JsonMapper(com.fasterxml.jackson.databind.json.JsonMapper) SERVICES_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICES_NAMESPACE_TOPIC) ArrayList(java.util.ArrayList) Topic(com.aws.greengrass.config.Topic) Topics(com.aws.greengrass.config.Topics) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) List(java.util.List) Utils(com.aws.greengrass.util.Utils) ACCESS_CONTROL_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.ACCESS_CONTROL_NAMESPACE_TOPIC) Map(java.util.Map) LogManager(com.aws.greengrass.logging.impl.LogManager) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Logger(com.aws.greengrass.logging.api.Logger) Topics(com.aws.greengrass.config.Topics) HashMap(java.util.HashMap) Node(com.aws.greengrass.config.Node) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with CONFIGURATION_CONFIG_KEY

use of com.aws.greengrass.componentmanager.KernelConfigResolver.CONFIGURATION_CONFIG_KEY in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentActivator method createDeploymentMergeBehavior.

protected UpdateBehaviorTree createDeploymentMergeBehavior(long deploymentTimestamp, Map<String, Object> newConfig) {
    // root: MERGE
    // services: MERGE
    // *: REPLACE
    // runtime: MERGE
    // _private: MERGE
    // configuration: REPLACE with deployment timestamp
    // AUTH_TOKEN: MERGE
    long now = System.currentTimeMillis();
    UpdateBehaviorTree rootMergeBehavior = new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.MERGE, now);
    UpdateBehaviorTree servicesMergeBehavior = new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.MERGE, now);
    UpdateBehaviorTree insideServiceMergeBehavior = new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.REPLACE, now);
    UpdateBehaviorTree serviceRuntimeMergeBehavior = new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.MERGE, now);
    UpdateBehaviorTree servicePrivateMergeBehavior = new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.MERGE, now);
    rootMergeBehavior.getChildOverride().put(SERVICES_NAMESPACE_TOPIC, servicesMergeBehavior);
    servicesMergeBehavior.getChildOverride().put(UpdateBehaviorTree.WILDCARD, insideServiceMergeBehavior);
    servicesMergeBehavior.getChildOverride().put(AUTHENTICATION_TOKEN_LOOKUP_KEY, new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.MERGE, now));
    // Set merge mode for all builtin services
    kernel.orderedDependencies().stream().filter(GreengrassService::isBuiltin).filter(s -> !((Map) newConfig.get(SERVICES_NAMESPACE_TOPIC)).containsKey(s.getServiceName())).forEach(s -> servicesMergeBehavior.getChildOverride().put(s.getServiceName(), new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.MERGE, now)));
    insideServiceMergeBehavior.getChildOverride().put(GreengrassService.RUNTIME_STORE_NAMESPACE_TOPIC, serviceRuntimeMergeBehavior);
    insideServiceMergeBehavior.getChildOverride().put(GreengrassService.PRIVATE_STORE_NAMESPACE_TOPIC, servicePrivateMergeBehavior);
    UpdateBehaviorTree serviceConfigurationMergeBehavior = new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.REPLACE, deploymentTimestamp);
    insideServiceMergeBehavior.getChildOverride().put(CONFIGURATION_CONFIG_KEY, serviceConfigurationMergeBehavior);
    return rootMergeBehavior;
}
Also used : DeploymentDirectoryManager(com.aws.greengrass.deployment.DeploymentDirectoryManager) CONFIGURATION_CONFIG_KEY(com.aws.greengrass.componentmanager.KernelConfigResolver.CONFIGURATION_CONFIG_KEY) ConfigurationReader(com.aws.greengrass.config.ConfigurationReader) Deployment(com.aws.greengrass.deployment.model.Deployment) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) SERVICES_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICES_NAMESPACE_TOPIC) AUTHENTICATION_TOKEN_LOOKUP_KEY(com.aws.greengrass.ipc.AuthenticationHandler.AUTHENTICATION_TOKEN_LOOKUP_KEY) UpdateBehaviorTree(com.aws.greengrass.config.UpdateBehaviorTree) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) KernelLifecycle(com.aws.greengrass.lifecyclemanager.KernelLifecycle) Map(java.util.Map) LogManager(com.aws.greengrass.logging.impl.LogManager) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) FailureHandlingPolicy(com.aws.greengrass.deployment.model.FailureHandlingPolicy) MERGE_ERROR_LOG_EVENT_KEY(com.aws.greengrass.deployment.DeploymentConfigMerger.MERGE_ERROR_LOG_EVENT_KEY) Logger(com.aws.greengrass.logging.api.Logger) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) UpdateBehaviorTree(com.aws.greengrass.config.UpdateBehaviorTree)

Aggregations

CONFIGURATION_CONFIG_KEY (com.aws.greengrass.componentmanager.KernelConfigResolver.CONFIGURATION_CONFIG_KEY)3 SERVICES_NAMESPACE_TOPIC (com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICES_NAMESPACE_TOPIC)3 Kernel (com.aws.greengrass.lifecyclemanager.Kernel)3 Logger (com.aws.greengrass.logging.api.Logger)3 LogManager (com.aws.greengrass.logging.impl.LogManager)3 IOException (java.io.IOException)3 Map (java.util.Map)3 Node (com.aws.greengrass.config.Node)2 Topic (com.aws.greengrass.config.Topic)2 Topics (com.aws.greengrass.config.Topics)2 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)2 Coerce (com.aws.greengrass.util.Coerce)2 Utils (com.aws.greengrass.util.Utils)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ComponentType (com.amazon.aws.iot.greengrass.component.common.ComponentType)1 DependencyProperties (com.amazon.aws.iot.greengrass.component.common.DependencyProperties)1 SerializerFactory.getRecipeSerializer (com.amazon.aws.iot.greengrass.component.common.SerializerFactory.getRecipeSerializer)1 ComponentStore (com.aws.greengrass.componentmanager.ComponentStore)1 KernelConfigResolver (com.aws.greengrass.componentmanager.KernelConfigResolver)1