use of com.aws.greengrass.config.CaseInsensitiveString in project aws-greengrass-nucleus by aws-greengrass.
the class DeviceConfiguration method initNucleusComponentName.
/**
* Get the Nucleus component name to lookup the configuration in the right place. If no component of type Nucleus
* exists, create service config for the default Nucleus component.
*/
private String initNucleusComponentName() {
Optional<CaseInsensitiveString> nucleusComponent = kernel.getConfig().lookupTopics(SERVICES_NAMESPACE_TOPIC).children.keySet().stream().filter(s -> ComponentType.NUCLEUS.name().equals(getComponentType(s.toString()))).findAny();
String nucleusComponentName = nucleusComponent.isPresent() ? nucleusComponent.get().toString() : DEFAULT_NUCLEUS_COMPONENT_NAME;
// Initialize default/inferred required config if it doesn't exist
initializeNucleusComponentConfig(nucleusComponentName);
return nucleusComponentName;
}
use of com.aws.greengrass.config.CaseInsensitiveString in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentServiceTest method GIVEN_deployment_job_WHEN_deployment_process_succeeds_THEN_correctly_map_components_to_groups.
@ParameterizedTest
@EnumSource(Deployment.DeploymentType.class)
void GIVEN_deployment_job_WHEN_deployment_process_succeeds_THEN_correctly_map_components_to_groups(Deployment.DeploymentType type) throws Exception {
String expectedGroupName = EXPECTED_GROUP_NAME;
if (type.equals(Deployment.DeploymentType.LOCAL)) {
expectedGroupName = LOCAL_DEPLOYMENT_GROUP_NAME;
}
String deploymentDocument = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("TestDeploymentDocument.json"), StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
deploymentQueue.offer(new Deployment(deploymentDocument, type, TEST_JOB_ID_1));
Topics allGroupTopics = Topics.of(context, GROUP_TO_ROOT_COMPONENTS_TOPICS, null);
Topics groupMembershipTopics = Topics.of(context, GROUP_MEMBERSHIP_TOPICS, null);
groupMembershipTopics.lookup(expectedGroupName);
Topics deploymentGroupTopics = Topics.of(context, expectedGroupName, allGroupTopics);
Topic pkgTopic1 = Topic.of(context, DeploymentService.GROUP_TO_ROOT_COMPONENTS_VERSION_KEY, "1.0.0");
Topic groupTopic1 = Topic.of(context, DeploymentService.GROUP_TO_ROOT_COMPONENTS_GROUP_CONFIG_ARN, "arn:aws:greengrass:testRegion:12345:configuration:testGroup:12");
Topic groupNameTopic1 = Topic.of(context, DeploymentService.GROUP_TO_ROOT_COMPONENTS_GROUP_NAME, expectedGroupName);
Map<CaseInsensitiveString, Node> pkgDetails = new HashMap<>();
pkgDetails.put(new CaseInsensitiveString(DeploymentService.GROUP_TO_ROOT_COMPONENTS_VERSION_KEY), pkgTopic1);
pkgDetails.put(new CaseInsensitiveString(DeploymentService.GROUP_TO_ROOT_COMPONENTS_GROUP_CONFIG_ARN), groupTopic1);
pkgDetails.put(new CaseInsensitiveString(DeploymentService.GROUP_TO_ROOT_COMPONENTS_GROUP_NAME), groupNameTopic1);
Topics pkgTopics = Topics.of(context, EXPECTED_ROOT_PACKAGE_NAME, deploymentGroupTopics);
pkgTopics.children.putAll(pkgDetails);
deploymentGroupTopics.children.put(new CaseInsensitiveString(EXPECTED_ROOT_PACKAGE_NAME), pkgTopics);
allGroupTopics.children.put(new CaseInsensitiveString(expectedGroupName), deploymentGroupTopics);
when(config.lookupTopics(GROUP_MEMBERSHIP_TOPICS)).thenReturn(groupMembershipTopics);
when(config.lookupTopics(GROUP_TO_ROOT_COMPONENTS_TOPICS)).thenReturn(allGroupTopics);
lenient().when(config.lookupTopics(GROUP_TO_ROOT_COMPONENTS_TOPICS, expectedGroupName)).thenReturn(deploymentGroupTopics);
when(config.lookupTopics(COMPONENTS_TO_GROUPS_TOPICS)).thenReturn(mockComponentsToGroupPackages);
when(mockKernel.locate(any())).thenReturn(mockGreengrassService);
when(mockGreengrassService.getName()).thenReturn(EXPECTED_ROOT_PACKAGE_NAME);
mockFuture.complete(new DeploymentResult(DeploymentStatus.SUCCESSFUL, null));
when(mockExecutorService.submit(any(DefaultDeploymentTask.class))).thenReturn(mockFuture);
doNothing().when(deploymentStatusKeeper).persistAndPublishDeploymentStatus(eq(TEST_JOB_ID_1), eq(type), eq(JobStatus.IN_PROGRESS.toString()), any());
startDeploymentServiceInAnotherThread();
verify(deploymentStatusKeeper, timeout(1000)).persistAndPublishDeploymentStatus(eq(TEST_JOB_ID_1), eq(type), eq(JobStatus.IN_PROGRESS.toString()), any());
verify(deploymentStatusKeeper, timeout(10000)).persistAndPublishDeploymentStatus(eq(TEST_JOB_ID_1), eq(type), eq(JobStatus.SUCCEEDED.toString()), any());
verify(mockExecutorService, timeout(1000)).submit(any(DefaultDeploymentTask.class));
verify(deploymentStatusKeeper, timeout(2000)).persistAndPublishDeploymentStatus(eq(TEST_JOB_ID_1), eq(type), eq(JobStatus.SUCCEEDED.toString()), any());
ArgumentCaptor<Map<String, Object>> mapCaptor = ArgumentCaptor.forClass(Map.class);
verify(mockComponentsToGroupPackages).replaceAndWait(mapCaptor.capture());
Map<String, Object> groupToRootPackages = mapCaptor.getValue();
assertThat(groupToRootPackages, is(IsNull.notNullValue()));
assertThat(groupToRootPackages.entrySet(), IsNot.not(IsEmptyCollection.empty()));
assertThat(groupToRootPackages, hasKey(EXPECTED_ROOT_PACKAGE_NAME));
assertThat((Map<String, Boolean>) groupToRootPackages.get(EXPECTED_ROOT_PACKAGE_NAME), hasKey("arn:aws:greengrass:testRegion:12345:configuration:testGroup:12"));
}
use of com.aws.greengrass.config.CaseInsensitiveString in project aws-greengrass-nucleus by aws-greengrass.
the class SecurityService method deregisterCryptoKeyProvider.
/**
* Deregister crypto key provider for the key type.
*
* @param keyProvider Crypto key provider
*/
public void deregisterCryptoKeyProvider(CryptoKeySpi keyProvider) {
CaseInsensitiveString keyType = new CaseInsensitiveString(keyProvider.supportedKeyType());
boolean removed = cryptoKeyProviderMap.remove(keyType, keyProvider);
if (!removed) {
logger.atInfo().kv(KEY_TYPE, keyType).log("Crypto key service provider is either already removed or " + "unregistered");
}
}
use of com.aws.greengrass.config.CaseInsensitiveString in project aws-greengrass-nucleus by aws-greengrass.
the class SecurityService method selectCryptoKeyProvider.
private CryptoKeySpi selectCryptoKeyProvider(URI uri) throws ServiceUnavailableException {
CaseInsensitiveString keyType = new CaseInsensitiveString(uri.getScheme());
CryptoKeySpi provider = cryptoKeyProviderMap.get(keyType);
if (provider == null) {
throw new ServiceUnavailableException(String.format("Crypto key service for %s is unavailable", keyType));
}
return provider;
}
use of com.aws.greengrass.config.CaseInsensitiveString in project aws-greengrass-nucleus by aws-greengrass.
the class SecurityService method registerCryptoKeyProvider.
/**
* Register crypto key provider for the key type.
*
* @param keyProvider Crypto key provider
* @throws ServiceProviderConflictException if key type is already registered
*/
public void registerCryptoKeyProvider(CryptoKeySpi keyProvider) throws ServiceProviderConflictException {
CaseInsensitiveString keyType = new CaseInsensitiveString(keyProvider.supportedKeyType());
logger.atInfo().kv(KEY_TYPE, keyType).log("Register crypto key service provider");
CryptoKeySpi provider = cryptoKeyProviderMap.computeIfAbsent(keyType, k -> keyProvider);
if (!provider.equals(keyProvider)) {
throw new ServiceProviderConflictException(String.format("Key type %s crypto key provider is registered", keyType));
}
}
Aggregations