Search in sources :

Example 1 with ComponentMetadata

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))));
}
Also used : ComponentMetadata(com.aws.greengrass.componentmanager.models.ComponentMetadata) Test(org.junit.jupiter.api.Test)

Example 2 with ComponentMetadata

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"));
}
Also used : DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) HashMap(java.util.HashMap) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) ComponentMetadata(com.aws.greengrass.componentmanager.models.ComponentMetadata) NoAvailableComponentVersionException(com.aws.greengrass.componentmanager.exceptions.NoAvailableComponentVersionException) PackagingException(com.aws.greengrass.componentmanager.exceptions.PackagingException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 3 with ComponentMetadata

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)));
}
Also used : DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) Requirement(com.vdurmont.semver4j.Requirement) HashMap(java.util.HashMap) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) ComponentMetadata(com.aws.greengrass.componentmanager.models.ComponentMetadata) Test(org.junit.jupiter.api.Test)

Example 4 with ComponentMetadata

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")));
}
Also used : HashMap(java.util.HashMap) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) ComponentMetadata(com.aws.greengrass.componentmanager.models.ComponentMetadata) DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) Requirement(com.vdurmont.semver4j.Requirement) Map(java.util.Map) HashMap(java.util.HashMap) ImmutableMap(software.amazon.awssdk.utils.ImmutableMap) Test(org.junit.jupiter.api.Test)

Example 5 with ComponentMetadata

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());
}
Also used : ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) ComponentMetadata(com.aws.greengrass.componentmanager.models.ComponentMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

ComponentMetadata (com.aws.greengrass.componentmanager.models.ComponentMetadata)17 ComponentIdentifier (com.aws.greengrass.componentmanager.models.ComponentIdentifier)14 Test (org.junit.jupiter.api.Test)14 HashMap (java.util.HashMap)11 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)8 DeploymentPackageConfiguration (com.aws.greengrass.deployment.model.DeploymentPackageConfiguration)8 Requirement (com.vdurmont.semver4j.Requirement)6 Map (java.util.Map)4 ResolvedComponentVersion (software.amazon.awssdk.services.greengrassv2data.model.ResolvedComponentVersion)3 NoAvailableComponentVersionException (com.aws.greengrass.componentmanager.exceptions.NoAvailableComponentVersionException)2 PackagingException (com.aws.greengrass.componentmanager.exceptions.PackagingException)2 RecipeMetadata (com.aws.greengrass.componentmanager.models.RecipeMetadata)2 Topic (com.aws.greengrass.config.Topic)2 Topics (com.aws.greengrass.config.Topics)2 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 ImmutableMap (software.amazon.awssdk.utils.ImmutableMap)2 ComponentRequirementIdentifier (com.aws.greengrass.componentmanager.models.ComponentRequirementIdentifier)1 ServiceLoadException (com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException)1