use of com.aws.greengrass.componentmanager.models.ComponentMetadata in project aws-greengrass-nucleus by aws-greengrass.
the class ComponentStoreTest method GIVEN_a_recipe_exists_WHEN_getPackageMetadata_then_return_it.
@Test
void GIVEN_a_recipe_exists_WHEN_getPackageMetadata_then_return_it() throws Exception {
// GIVEN
preloadRecipeFileFromTestResource(MONITORING_SERVICE_PKG_RECIPE_FILE_NAME);
// WHEN
ComponentMetadata componentMetadata = componentStore.getPackageMetadata(MONITORING_SERVICE_PKG_ID);
// THEN
assertThat(componentMetadata.getComponentIdentifier(), is(MONITORING_SERVICE_PKG_ID));
assertThat(componentMetadata.getDependencies(), is(getExpectedDependencies(Requirement.build(MONITORING_SERVICE_PKG_VERSION))));
}
use of com.aws.greengrass.componentmanager.models.ComponentMetadata in project aws-greengrass-nucleus by aws-greengrass.
the class DependencyResolverTest method GIVEN_circular_dependency_for_root_component_WHEN_resolve_dependency_called_THEN_resolution_fails.
@Test
void GIVEN_circular_dependency_for_root_component_WHEN_resolve_dependency_called_THEN_resolution_fails() throws Exception {
/*
* group1
* \(1.0.0)
* |--> A
* 1.0.0 / \
* |__/ \(>1.0)
* B2
*/
// prepare A
Map<String, String> dependenciesA_1_x = new HashMap<>();
dependenciesA_1_x.put(componentA, "1.0.0");
dependenciesA_1_x.put(componentB2, ">1.0");
ComponentMetadata componentA_1_0_0 = new ComponentMetadata(new ComponentIdentifier(componentA, v1_0_0), dependenciesA_1_x);
when(componentManager.resolveComponentVersion(eq(componentA), any())).thenReturn(componentA_1_0_0);
ComponentMetadata componentB2_1_1_0 = new ComponentMetadata(new ComponentIdentifier(componentB2, v1_1_0), Collections.emptyMap());
when(componentManager.resolveComponentVersion(eq(componentB2), any())).thenReturn(componentB2_1_1_0);
DeploymentDocument doc = new DeploymentDocument("mockId", "mockJob1", Collections.singletonList(new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue())), Collections.emptyList(), "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
context.runOnPublishQueueAndWait(() -> System.out.println("Waiting for queue to finish updating the config"));
Exception e = assertThrows(PackagingException.class, () -> dependencyResolver.resolveDependencies(doc, new HashMap<>()));
assertTrue(e.getMessage().contains("Circular dependency detected for component A-v1.0.0"));
}
use of com.aws.greengrass.componentmanager.models.ComponentMetadata in project aws-greengrass-nucleus by aws-greengrass.
the class DependencyResolverTest method GIVEN_component_B_WHEN_version_is_bumped_up_from_1_to_2_THEN_dependencies_of_1_are_removed.
@Test
void GIVEN_component_B_WHEN_version_is_bumped_up_from_1_to_2_THEN_dependencies_of_1_are_removed() throws Exception {
/*
* group1
* \(1.0.0)
* A
(>=1.0.0)/ \(1.0)
* B D
/ (>=2.0.0)
* /
* B
*
* B will be first resolved to version 1.0.0 which depends on X=2.0.0
* X=2.0.0 depends on Y=1.0.0
*
* B will then be resolved to version 2.0.0 which depends on Y=2.0.0
* For the test to succeed X should be removed from the dependency tree and the constraint X puts on Y should be removed.
*/
// prepare A
Map<String, String> dependenciesA_1_x = new HashMap<>();
dependenciesA_1_x.put(componentB, ">=1.0.0");
dependenciesA_1_x.put(componentD, "1.0.0");
ComponentMetadata componentA_1_0_0 = new ComponentMetadata(new ComponentIdentifier(componentA, v1_0_0), dependenciesA_1_x);
when(componentManager.resolveComponentVersion(eq(componentA), any())).thenReturn(componentA_1_0_0);
// prepare D
Map<String, String> dependenciesD_1_0_0 = new HashMap<>();
dependenciesD_1_0_0.put(componentB, ">=2.0.0");
ComponentMetadata componentD_1_0_0 = new ComponentMetadata(new ComponentIdentifier(componentD, v1_0_0), dependenciesD_1_0_0);
when(componentManager.resolveComponentVersion(eq(componentD), any())).thenReturn(componentD_1_0_0);
// prepare B version 1
Map<String, String> dependenciesB_1_0_0 = new HashMap<>();
dependenciesB_1_0_0.put("X", "2.0.0");
ComponentMetadata componentB_1_0_0 = new ComponentMetadata(new ComponentIdentifier(componentB, v1_0_0), dependenciesB_1_0_0);
Map<String, Requirement> versionRequirementsForB_1_0_0 = new HashMap<>();
versionRequirementsForB_1_0_0.put(componentA, Requirement.buildNPM(">=1.0.0"));
when(componentManager.resolveComponentVersion(eq(componentB), eq(versionRequirementsForB_1_0_0))).thenReturn(componentB_1_0_0);
// prepare B version 1
Map<String, String> dependenciesB_2_0_0 = new HashMap<>();
dependenciesB_2_0_0.put("Y", "2.0.0");
ComponentMetadata componentB_2_0_0 = new ComponentMetadata(new ComponentIdentifier(componentB, v2_0_0), dependenciesB_2_0_0);
Map<String, Requirement> versionRequirementsForB_2_0_0 = new HashMap<>();
versionRequirementsForB_2_0_0.put(componentA, Requirement.buildNPM(">=1.0.0"));
versionRequirementsForB_2_0_0.put(componentD, Requirement.buildNPM(">=2.0.0"));
when(componentManager.resolveComponentVersion(eq(componentB), eq(versionRequirementsForB_2_0_0))).thenReturn(componentB_2_0_0);
// prepare X
Map<String, String> dependenciesX_2_0_0 = new HashMap<>();
dependenciesX_2_0_0.put("Y", "1.0.0");
ComponentMetadata componentX_2_0_0 = new ComponentMetadata(new ComponentIdentifier(componentX, v2_0_0), dependenciesX_2_0_0);
when(componentManager.resolveComponentVersion(eq(componentX), any())).thenReturn(componentX_2_0_0);
// prepare Y version 1
ComponentMetadata componentY_1_0_0 = new ComponentMetadata(new ComponentIdentifier(componentY, v1_0_0), Collections.emptyMap());
Map<String, Requirement> versionRequirementsForY_1_0_0 = new HashMap<>();
versionRequirementsForY_1_0_0.put(componentX, Requirement.buildNPM("=1.0.0"));
lenient().when(componentManager.resolveComponentVersion(eq(componentY), eq(versionRequirementsForY_1_0_0))).thenReturn(componentY_1_0_0);
// prepare Y version 2
ComponentMetadata componentY_2_0_0 = new ComponentMetadata(new ComponentIdentifier(componentY, v2_0_0), Collections.emptyMap());
Map<String, Requirement> versionRequirementsForY_2_0_0 = new HashMap<>();
versionRequirementsForY_2_0_0.put(componentB, Requirement.buildNPM("=2.0.0"));
lenient().when(componentManager.resolveComponentVersion(eq(componentY), eq(versionRequirementsForY_2_0_0))).thenReturn(componentY_2_0_0);
DeploymentDocument doc = new DeploymentDocument("mockId", "mockJob1", Collections.singletonList(new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue())), Collections.emptyList(), "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
context.runOnPublishQueueAndWait(() -> System.out.println("Waiting for queue to finish updating the config"));
List<ComponentIdentifier> result = dependencyResolver.resolveDependencies(doc, new HashMap<>());
assertThat(result.size(), is(4));
assertThat(result, containsInAnyOrder(new ComponentIdentifier(componentA, v1_0_0), new ComponentIdentifier(componentB, v2_0_0), new ComponentIdentifier(componentD, v1_0_0), new ComponentIdentifier(componentY, v2_0_0)));
}
use of com.aws.greengrass.componentmanager.models.ComponentMetadata in project aws-greengrass-nucleus by aws-greengrass.
the class DependencyResolverTest method GIVEN_component_A_B2_WHEN_dependencies_overlap_THEN_satisfy_both.
@Test
void GIVEN_component_A_B2_WHEN_dependencies_overlap_THEN_satisfy_both() throws Exception {
/*
* group1
* (1.0.0)/ \(1.1.0)
* A B2
* (1.0.0)/ /
* B1 /
* (>1.0.0)\ /(<=1.1.0)
* C1
*/
// prepare A
Map<String, String> dependenciesA_1_x = new HashMap<>();
dependenciesA_1_x.put(componentB1, "1.0.0");
ComponentMetadata componentA_1_0_0 = new ComponentMetadata(new ComponentIdentifier(componentA, v1_0_0), dependenciesA_1_x);
when(componentManager.resolveComponentVersion(eq(componentA), any())).thenReturn(componentA_1_0_0);
// prepare B1
Map<String, String> dependenciesB1_1_x = new HashMap<>();
dependenciesB1_1_x.put(componentC1, ">1.0.0");
ComponentMetadata componentB1_1_0_0 = new ComponentMetadata(new ComponentIdentifier(componentB1, v1_0_0), dependenciesB1_1_x);
when(componentManager.resolveComponentVersion(eq(componentB1), any())).thenReturn(componentB1_1_0_0);
// prepare B2
Map<String, String> dependenciesB2_1_x = new HashMap<>();
dependenciesB2_1_x.put(componentC1, "<=1.1.0");
ComponentMetadata componentB2_1_1_0 = new ComponentMetadata(new ComponentIdentifier(componentB2, v1_1_0), dependenciesB2_1_x);
when(componentManager.resolveComponentVersion(eq(componentB2), any())).thenReturn(componentB2_1_1_0);
// prepare C1
ComponentMetadata componentC_1_5_0 = new ComponentMetadata(new ComponentIdentifier(componentC1, v1_5_0), Collections.emptyMap());
when(componentManager.resolveComponentVersion(eq(componentC1), eq(Collections.singletonMap(componentB1, Requirement.buildNPM(">1.0.0"))))).thenReturn(componentC_1_5_0);
ComponentMetadata componentC_1_1_0 = new ComponentMetadata(new ComponentIdentifier(componentC1, v1_1_0), Collections.emptyMap());
Map<String, Requirement> versionRequirementMap = new HashMap<>();
versionRequirementMap.put(componentB1, Requirement.buildNPM(">1.0.0"));
versionRequirementMap.put(componentB2, Requirement.buildNPM("<=1.1.0"));
when(componentManager.resolveComponentVersion(eq(componentC1), eq(versionRequirementMap))).thenReturn(componentC_1_1_0);
// top-level package order: A, B2
DeploymentDocument doc = new DeploymentDocument("mockId", "mockJob1", Arrays.asList(new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue()), new DeploymentPackageConfiguration(componentB2, true, v1_1_0.getValue())), Collections.emptyList(), "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
context.runOnPublishQueueAndWait(() -> System.out.println("Waiting for queue to finish updating the config"));
List<ComponentIdentifier> result = dependencyResolver.resolveDependencies(doc, new HashMap<>());
assertThat(result.size(), is(4));
assertThat(result, containsInAnyOrder(new ComponentIdentifier(componentA, v1_0_0), new ComponentIdentifier(componentB1, v1_0_0), new ComponentIdentifier(componentB2, v1_1_0), new ComponentIdentifier(componentC1, v1_1_0)));
ArgumentCaptor<String> componentNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Map<String, Requirement>> versionRequirementsCaptor = ArgumentCaptor.forClass(Map.class);
verify(componentManager, times(5)).resolveComponentVersion(componentNameCaptor.capture(), versionRequirementsCaptor.capture());
List<String> componentNameList = componentNameCaptor.getAllValues();
assertThat(componentNameList, contains("A", "B1", "C1", "B2", "C1"));
List<Map<String, Requirement>> versionRequirementsList = versionRequirementsCaptor.getAllValues();
assertThat(versionRequirementsList.size(), is(5));
Map<String, Requirement> versionRequirements = versionRequirementsList.get(2);
assertThat(versionRequirements.size(), is(1));
assertThat(versionRequirements, IsMapContaining.hasEntry("B1", Requirement.buildNPM(">1.0.0")));
versionRequirements = versionRequirementsList.get(4);
assertThat(versionRequirements.size(), is(2));
assertThat(versionRequirements, IsMapContaining.hasEntry("B1", Requirement.buildNPM(">1.0.0")));
assertThat(versionRequirements, IsMapContaining.hasEntry("B2", Requirement.buildNPM("<=1.1.0")));
}
use of com.aws.greengrass.componentmanager.models.ComponentMetadata in project aws-greengrass-nucleus by aws-greengrass.
the class ComponentManagerTest method GIVEN_requirement_is_from_local_group_and_has_local_version_WHEN_resolve_version_THEN_use_local_version.
@Test
void GIVEN_requirement_is_from_local_group_and_has_local_version_WHEN_resolve_version_THEN_use_local_version() throws Exception {
ComponentIdentifier componentA_1_2_0 = new ComponentIdentifier(componentA, v1_2_0);
ComponentMetadata componentA_1_2_0_md = new ComponentMetadata(componentA_1_2_0, Collections.emptyMap());
when(componentStore.findBestMatchAvailableComponent(eq(componentA), any())).thenReturn(Optional.of(componentA_1_2_0));
when(componentStore.getPackageMetadata(any())).thenReturn(componentA_1_2_0_md);
ComponentMetadata componentMetadata = componentManager.resolveComponentVersion(componentA, Collections.singletonMap(DeploymentDocumentConverter.LOCAL_DEPLOYMENT_GROUP_NAME, Requirement.buildNPM("^1.0")));
assertThat(componentMetadata, is(componentA_1_2_0_md));
verify(componentStore).findBestMatchAvailableComponent(componentA, Requirement.buildNPM("^1.0"));
verify(componentStore).getPackageMetadata(componentA_1_2_0);
verify(componentManagementServiceHelper, never()).resolveComponentVersion(anyString(), any(), any());
}
Aggregations