use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class GreengrassServiceTest method beforeEach.
@BeforeEach
void beforeEach() throws IOException, URISyntaxException, ServiceLoadException {
Path configPath = Paths.get(this.getClass().getResource("services.yaml").toURI());
context = spy(new Context());
context.put(Kernel.class, kernel);
configuration = new Configuration(context);
configuration.read(configPath);
Topics root = configuration.getRoot();
bService = new GreengrassService(root.findTopics(SERVICES_NAMESPACE_TOPIC, "B"));
cService = new GreengrassService(root.findTopics(SERVICES_NAMESPACE_TOPIC, "C"));
dService = new GreengrassService(root.findTopics(SERVICES_NAMESPACE_TOPIC, "D"));
eService = new GreengrassService(root.findTopics(SERVICES_NAMESPACE_TOPIC, "E"));
when(kernel.locateIgnoreError("B")).thenReturn(bService);
when(kernel.locateIgnoreError("C")).thenReturn(cService);
when(kernel.locateIgnoreError("D")).thenReturn(dService);
lenient().when(kernel.locateIgnoreError("E")).thenReturn(eService);
aService = spy(new GreengrassService(root.findTopics(SERVICES_NAMESPACE_TOPIC, "A")));
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class ConfigStoreIPCEventStreamAgentTest method setup.
@BeforeEach
public void setup() {
configuration = new Configuration(new Context());
Topics root = configuration.getRoot();
root.lookup(SERVICES_NAMESPACE_TOPIC, TEST_COMPONENT_A, CONFIGURATION_CONFIG_KEY, TEST_CONFIG_KEY_1).withNewerValue(100, TEST_CONFIG_KEY_1_INITIAL_VALUE);
root.lookup(SERVICES_NAMESPACE_TOPIC, TEST_COMPONENT_A, CONFIGURATION_CONFIG_KEY, TEST_CONFIG_KEY_2).withNewerValue(100, TEST_CONFIG_KEY_2_INITIAL_VALUE);
root.lookupTopics(SERVICES_NAMESPACE_TOPIC, TEST_COMPONENT_B);
root.lookup(SERVICES_NAMESPACE_TOPIC, TEST_COMPONENT_B, CONFIGURATION_CONFIG_KEY, TEST_CONFIG_KEY_3).withNewerValue(100, TEST_CONFIG_KEY_3_INITIAL_VALUE);
configuration.context.waitForPublishQueueToClear();
lenient().when(kernel.getConfig()).thenReturn(configuration);
when(mockContext.getContinuation()).thenReturn(mockServerConnectionContinuation);
when(mockContext.getAuthenticationData()).thenReturn(mockAuthenticationData);
lenient().when(mockContext2.getContinuation()).thenReturn(mock(ServerConnectionContinuation.class));
lenient().when(mockContext2.getAuthenticationData()).thenReturn(mockAuthenticationData2);
agent = new ConfigStoreIPCEventStreamAgent();
agent.setKernel(kernel);
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class Lifecycle method startStateTransition.
private void startStateTransition() throws InterruptedException {
AtomicReference<Predicate<Object>> asyncFinishAction = new AtomicReference<>((stateEvent) -> true);
State prevState = getState();
while (!(isClosed.get() && getState().isClosable())) {
Optional<State> desiredState;
State current = getState();
logger.atDebug("service-state-transition-start").log();
Configuration kernelConfig = greengrassService.getContext().get(Configuration.class);
// postpone start/install when configuration is under update.
if (current == State.NEW || current == State.INSTALLED) {
kernelConfig.waitConfigUpdateComplete();
}
// if already in desired state, remove the head of desired state list.
desiredState = peekOrRemoveFirstDesiredState(current);
while (desiredState.isPresent() && desiredState.get().equals(current)) {
desiredState = peekOrRemoveFirstDesiredState(current);
}
switch(current) {
case BROKEN:
handleCurrentStateBroken(desiredState, prevState);
break;
case NEW:
handleCurrentStateNew(desiredState);
break;
case INSTALLED:
handleCurrentStateInstalledAsync(desiredState, asyncFinishAction);
break;
case STARTING:
handleCurrentStateStartingAsync(desiredState, asyncFinishAction);
break;
case RUNNING:
handleCurrentStateRunning(desiredState);
break;
case STOPPING:
handleCurrentStateStopping();
break;
case FINISHED:
handleCurrentStateFinished(desiredState);
break;
case ERRORED:
handleCurrentStateErrored(desiredState, prevState);
break;
default:
logger.atError(INVALID_STATE_ERROR_EVENT).log("Unrecognized current state");
break;
}
boolean canFinish = false;
while (!canFinish) {
// A state event can either be a report state transition event or a desired state updated event.
Object stateEvent = stateEventQueue.poll();
// drain them until a "State" event is encountered.
while (!(stateEvent instanceof State) && !stateEventQueue.isEmpty()) {
stateEvent = stateEventQueue.poll();
}
// if there are no events in the queue, block until one is available.
if (stateEvent == null) {
stateEvent = stateEventQueue.take();
}
if (stateEvent instanceof State) {
State newState = (State) stateEvent;
if (newState == current) {
continue;
}
canFinish = true;
setState(current, newState);
prevState = current;
}
if (asyncFinishAction.get().test(stateEvent)) {
canFinish = true;
}
}
asyncFinishAction.set((stateEvent) -> true);
}
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class KernelTest method GIVEN_kernel_WHEN_locate_finds_class_definition_in_config_THEN_create_service.
@SuppressWarnings("PMD.AvoidCatchingGenericException")
@Test
void GIVEN_kernel_WHEN_locate_finds_class_definition_in_config_THEN_create_service(ExtensionContext context) throws Exception {
// We need to launch the kernel here as this triggers EZPlugins to search the classpath for @ImplementsService
// it complains that there's no main, but we don't care for this test
ignoreExceptionUltimateCauseWithMessage(context, "No matching definition in system model for: main");
try {
kernel.parseArgs().launch();
} catch (RuntimeException ignored) {
}
Configuration config = kernel.getConfig();
config.lookup(GreengrassService.SERVICES_NAMESPACE_TOPIC, "1", "class").withValue(TestClass.class.getName());
GreengrassService main = kernel.locate("1");
assertEquals("tester", main.getName());
GreengrassService service2 = kernel.locate("testImpl");
assertEquals("testImpl", service2.getName());
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleTest method setupContext.
@BeforeEach
void setupContext() throws IOException {
context = new Context();
ScheduledThreadPoolExecutor ses = new ScheduledThreadPoolExecutor(4);
ExecutorService executorService = Executors.newCachedThreadPool();
context.put(ScheduledThreadPoolExecutor.class, ses);
context.put(ScheduledExecutorService.class, ses);
context.put(Executor.class, executorService);
context.put(ExecutorService.class, executorService);
context.put(ThreadPoolExecutor.class, ses);
context.put(Clock.class, Clock.systemUTC());
context.put(Kernel.class, mock(Kernel.class));
Topics rootConfig = new Configuration(context).getRoot();
config = rootConfig.createInteriorChild(GreengrassService.SERVICES_NAMESPACE_TOPIC).createInteriorChild("MockService");
try (InputStream inputStream = new ByteArrayInputStream(BLANK_CONFIG_YAML_WITH_TIMEOUT.getBytes())) {
config.updateFromMap(new YAMLMapper().readValue(inputStream, Map.class), new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.MERGE, 0));
}
lenient().when(greengrassService.getConfig()).thenReturn(config);
lenient().when(greengrassService.getRuntimeConfig()).thenReturn(config.lookupTopics(RUNTIME_STORE_NAMESPACE_TOPIC));
lenient().when(greengrassService.getPrivateConfig()).thenReturn(config.lookupTopics(PRIVATE_STORE_NAMESPACE_TOPIC));
lenient().when(greengrassService.getContext()).thenReturn(context);
lenient().when(greengrassService.dependencyReady()).thenReturn(true);
lenient().when(greengrassService.getState()).thenAnswer((a) -> State.values()[Coerce.toInt(greengrassService.getPrivateConfig().findLeafChild(STATE_TOPIC_NAME))]);
}
Aggregations