use of com.aws.greengrass.config.Topics in project aws-greengrass-nucleus by aws-greengrass.
the class MultiGroupDeploymentTest method GIVEN_device_belongs_to_two_groups_WHEN_device_is_removed_from_one_group_THEN_next_deployment_removes_corresponding_component.
@Test
void GIVEN_device_belongs_to_two_groups_WHEN_device_is_removed_from_one_group_THEN_next_deployment_removes_corresponding_component() throws Exception {
CountDownLatch firstGroupCDL = new CountDownLatch(1);
CountDownLatch secondGroupCDL = new CountDownLatch(1);
DeploymentStatusKeeper deploymentStatusKeeper = kernel.getContext().get(DeploymentStatusKeeper.class);
deploymentStatusKeeper.registerDeploymentStatusConsumer(Deployment.DeploymentType.IOT_JOBS, (status) -> {
if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("firstGroup") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
firstGroupCDL.countDown();
}
if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("secondGroup") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
secondGroupCDL.countDown();
}
return true;
}, "dummyValue");
when(thingGroupHelper.listThingGroupsForDevice(anyInt())).thenReturn(Optional.of(new HashSet<>(Arrays.asList("firstGroup", "secondGroup"))));
submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithRedSignalService.json").toURI(), "firstGroup", Deployment.DeploymentType.IOT_JOBS);
assertTrue(firstGroupCDL.await(10, TimeUnit.SECONDS));
when(thingGroupHelper.listThingGroupsForDevice(anyInt())).thenReturn(Optional.of(new HashSet<>(Arrays.asList("secondGroup"))));
submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithSomeService.json").toURI(), "secondGroup", Deployment.DeploymentType.IOT_JOBS);
assertTrue(secondGroupCDL.await(10, TimeUnit.SECONDS));
Topics groupToRootTopic = kernel.getConfig().lookupTopics(SERVICES_NAMESPACE_TOPIC, DEPLOYMENT_SERVICE_TOPICS, GROUP_TO_ROOT_COMPONENTS_TOPICS);
List<String> groupNames = new ArrayList<>();
groupToRootTopic.forEach(node -> groupNames.add(node.getName()));
assertTrue(groupNames.containsAll(Arrays.asList("secondGroup")), "Device should belong to firstGroup and secondGroup");
Map<GreengrassService, DependencyType> dependenciesAfter = kernel.getMain().getDependencies();
List<String> serviceNames = dependenciesAfter.keySet().stream().map(service -> service.getName()).collect(Collectors.toList());
assertTrue(serviceNames.containsAll(Arrays.asList("SomeService")));
Topics componentsToGroupTopic = kernel.getConfig().lookupTopics(SERVICES_NAMESPACE_TOPIC, DEPLOYMENT_SERVICE_TOPICS, COMPONENTS_TO_GROUPS_TOPICS);
assertNotNull(componentsToGroupTopic.find("SomeService", "secondGroup"));
}
use of com.aws.greengrass.config.Topics in project aws-greengrass-nucleus by aws-greengrass.
the class MultiGroupDeploymentTest method GIVEN_device_receives_deployment_from_multiple_groups_THEN_components_deployed_by_shadow_deployment_are_not_removed.
@Test
void GIVEN_device_receives_deployment_from_multiple_groups_THEN_components_deployed_by_shadow_deployment_are_not_removed() throws Exception {
CountDownLatch firstGroupCDL = new CountDownLatch(1);
CountDownLatch secondGroupCDL = new CountDownLatch(1);
CountDownLatch shadowDeploymentCDL = new CountDownLatch(1);
DeploymentStatusKeeper deploymentStatusKeeper = kernel.getContext().get(DeploymentStatusKeeper.class);
deploymentStatusKeeper.registerDeploymentStatusConsumer(Deployment.DeploymentType.IOT_JOBS, (status) -> {
if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("thinggroup/firstGroup") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
firstGroupCDL.countDown();
}
if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("thinggroup/secondGroup") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
secondGroupCDL.countDown();
}
return true;
}, "dummyValueIotJobs");
deploymentStatusKeeper.registerDeploymentStatusConsumer(Deployment.DeploymentType.SHADOW, (status) -> {
if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("thing/thingname") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
shadowDeploymentCDL.countDown();
}
return true;
}, "dummyValueShadow");
when(thingGroupHelper.listThingGroupsForDevice(anyInt())).thenReturn(Optional.of(new HashSet<>(Arrays.asList("thinggroup/firstGroup", "thinggroup/secondGroup"))));
submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithRedSignalService.json").toURI(), "thinggroup/firstGroup", Deployment.DeploymentType.IOT_JOBS);
assertTrue(firstGroupCDL.await(30, TimeUnit.SECONDS));
submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithSomeService.json").toURI(), "thing/thingname", Deployment.DeploymentType.SHADOW);
assertTrue(shadowDeploymentCDL.await(30, TimeUnit.SECONDS));
when(thingGroupHelper.listThingGroupsForDevice(anyInt())).thenReturn(Optional.of(new HashSet<>(Arrays.asList("thinggroup/secondGroup"))));
submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithYellowSignal.json").toURI(), "thinggroup/secondGroup", Deployment.DeploymentType.IOT_JOBS);
assertTrue(secondGroupCDL.await(30, TimeUnit.SECONDS));
Topics groupToRootTopic = kernel.getConfig().lookupTopics(SERVICES_NAMESPACE_TOPIC, DEPLOYMENT_SERVICE_TOPICS, GROUP_TO_ROOT_COMPONENTS_TOPICS);
List<String> groupNames = new ArrayList<>();
groupToRootTopic.forEach(node -> groupNames.add(node.getName()));
assertTrue(groupNames.containsAll(Arrays.asList("thinggroup/secondGroup", "thing/thingname")));
assertFalse(groupNames.contains("thinggroup/firstGroup"));
Topics componentsToGroupTopic = kernel.getConfig().lookupTopics(SERVICES_NAMESPACE_TOPIC, DEPLOYMENT_SERVICE_TOPICS, COMPONENTS_TO_GROUPS_TOPICS);
assertNotNull(componentsToGroupTopic.find("YellowSignal", "thinggroup/secondGroup"));
assertNotNull(componentsToGroupTopic.find("SomeService", "thing/thingname"));
}
use of com.aws.greengrass.config.Topics in project aws-greengrass-nucleus by aws-greengrass.
the class IPCMqttProxyTest method beforeEach.
@BeforeEach
void beforeEach() throws Exception {
mqttClient = mock(MqttClient.class);
when(mqttClient.publish(any())).thenReturn(CompletableFuture.completedFuture(0));
System.setProperty("root", tempRootDir.toAbsolutePath().toString());
kernel = new Kernel();
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, IPCMqttProxyTest.class.getResource("mqttproxy.yaml"));
CountDownLatch awaitIpcServiceLatch = new CountDownLatch(1);
kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals(TEST_SERVICE_NAME) && newState.equals(State.FINISHED)) {
awaitIpcServiceLatch.countDown();
}
});
kernel.getContext().put(MqttClient.class, mqttClient);
kernel.launch();
assertTrue(awaitIpcServiceLatch.await(10, TimeUnit.SECONDS));
Topics servicePrivateConfig = kernel.getConfig().findTopics(SERVICES_NAMESPACE_TOPIC, TEST_SERVICE_NAME, PRIVATE_STORE_NAMESPACE_TOPIC);
String authToken = Coerce.toString(servicePrivateConfig.find(SERVICE_UNIQUE_ID_KEY));
socketOptions = TestUtils.getSocketOptionsForIPC();
clientConnection = IPCTestUtils.connectToGGCOverEventStreamIPC(socketOptions, authToken, kernel);
}
use of com.aws.greengrass.config.Topics in project aws-greengrass-nucleus by aws-greengrass.
the class IPCPubSubRemovalTest method GIVEN_pubsubclient_WHEN_authorized_THEN_ACL_child_removed_THEN_updates.
@Test
void GIVEN_pubsubclient_WHEN_authorized_THEN_ACL_child_removed_THEN_updates() throws Exception {
try (EventStreamRPCConnection connection = IPCTestUtils.getEventStreamRpcConnection(kernel, "DoAll1")) {
GreengrassCoreIPCClient ipcClient = new GreengrassCoreIPCClient(connection);
assertTrue(kernel.getContext().get(AuthorizationModule.class).isPresent(TOKEN_EXCHANGE_SERVICE_TOPICS, TES_DEFAULT_POLICY));
Pair<CompletableFuture<Void>, Consumer<byte[]>> cb = asyncAssertOnConsumer((m) -> {
assertEquals("some message", new String(m, StandardCharsets.UTF_8));
});
subscribeToTopicOveripcForBinaryMessages(ipcClient, "a", cb.getRight());
publishToTopicOverIpcAsBinaryMessage(ipcClient, "a", "some message");
cb.getLeft().get(TIMEOUT_FOR_PUBSUB_SECONDS, TimeUnit.SECONDS);
Topics serviceTopic = kernel.findServiceTopic("DoAll1");
Topics parameters = serviceTopic.findTopics(CONFIGURATION_CONFIG_KEY);
Topic acl = parameters.find(ACCESS_CONTROL_NAMESPACE_TOPIC, "aws.greengrass.ipc.pubsub", "policyId5", "operations");
if (acl != null) {
acl.withValue(Collections.emptyList());
}
// Block until events are completed
kernel.getContext().waitForPublishQueueToClear();
assertTrue(kernel.getContext().get(AuthorizationModule.class).isPresent(TOKEN_EXCHANGE_SERVICE_TOPICS, TES_DEFAULT_POLICY));
// Now the authorization policies should have been removed and these should fail
ExecutionException executionException = assertThrows(ExecutionException.class, () -> subscribeToTopicOveripcForBinaryMessages(ipcClient, "a", cb.getRight()));
assertTrue(executionException.getCause() instanceof UnauthorizedError);
ExecutionException executionException1 = assertThrows(ExecutionException.class, () -> publishToTopicOverIpcAsBinaryMessage(ipcClient, "a", "some message"));
assertTrue(executionException1.getCause() instanceof UnauthorizedError);
serviceTopic = kernel.findServiceTopic("DoAll1");
parameters = serviceTopic.findTopics(CONFIGURATION_CONFIG_KEY);
Topics aclTopics = parameters.findTopics(ACCESS_CONTROL_NAMESPACE_TOPIC);
if (aclTopics != null) {
aclTopics.remove();
}
// Block until events are completed
kernel.getContext().waitForPublishQueueToClear();
assertTrue(kernel.getContext().get(AuthorizationModule.class).isPresent(TOKEN_EXCHANGE_SERVICE_TOPICS, TES_DEFAULT_POLICY));
// Now the authorization policies should have been removed and these should fail
executionException = assertThrows(ExecutionException.class, () -> subscribeToTopicOveripcForBinaryMessages(ipcClient, "a", cb.getRight()));
assertTrue(executionException.getCause() instanceof UnauthorizedError);
executionException1 = assertThrows(ExecutionException.class, () -> publishToTopicOverIpcAsBinaryMessage(ipcClient, "a", "some message"));
assertTrue(executionException1.getCause() instanceof UnauthorizedError);
}
}
use of com.aws.greengrass.config.Topics in project aws-greengrass-nucleus by aws-greengrass.
the class IPCPubSubRemovalTest method GIVEN_pubsubclient_WHEN_authorized_THEN_parameters_child_removed_THEN_updates.
@Test
void GIVEN_pubsubclient_WHEN_authorized_THEN_parameters_child_removed_THEN_updates() throws Exception {
try (EventStreamRPCConnection connection = IPCTestUtils.getEventStreamRpcConnection(kernel, "DoAll2")) {
GreengrassCoreIPCClient ipcClient = new GreengrassCoreIPCClient(connection);
assertTrue(kernel.getContext().get(AuthorizationModule.class).isPresent(TOKEN_EXCHANGE_SERVICE_TOPICS, TES_DEFAULT_POLICY));
Pair<CompletableFuture<Void>, Consumer<byte[]>> cb = asyncAssertOnConsumer((m) -> {
assertEquals("some message", new String(m, StandardCharsets.UTF_8));
});
// this should succeed
subscribeToTopicOveripcForBinaryMessages(ipcClient, "a", cb.getRight());
publishToTopicOverIpcAsBinaryMessage(ipcClient, "a", "some message");
cb.getLeft().get(TIMEOUT_FOR_PUBSUB_SECONDS, TimeUnit.SECONDS);
Topics serviceTopic = kernel.findServiceTopic("DoAll2");
Topics parameters = serviceTopic.findTopics(CONFIGURATION_CONFIG_KEY);
if (parameters != null) {
parameters.remove();
}
// Block until events are completed
kernel.getContext().waitForPublishQueueToClear();
assertTrue(kernel.getContext().get(AuthorizationModule.class).isPresent(TOKEN_EXCHANGE_SERVICE_TOPICS, TES_DEFAULT_POLICY));
// Now the authorization policies should have been removed and these should fail
ExecutionException e = assertThrows(ExecutionException.class, () -> subscribeToTopicOveripcForBinaryMessages(ipcClient, "a", cb.getRight()));
assertTrue(e.getCause() instanceof UnauthorizedError);
e = assertThrows(ExecutionException.class, () -> publishToTopicOverIpcAsBinaryMessage(ipcClient, "a", "some message"));
assertTrue(e.getCause() instanceof UnauthorizedError);
}
}
Aggregations