use of com.amazon.aws.iot.greengrass.component.common.DependencyProperties in project aws-greengrass-nucleus by aws-greengrass.
the class RecipeLoader method loadFromFile.
/**
* Converts from the recipe file with platform resolving.
*
* @param recipeFileContent recipe file content
* @return Optional package recipe
* @throws PackageLoadingException when failed to convert recipe file.
*/
public Optional<ComponentRecipe> loadFromFile(String recipeFileContent) throws PackageLoadingException {
com.amazon.aws.iot.greengrass.component.common.ComponentRecipe componentRecipe = parseRecipe(recipeFileContent, RecipeFormat.YAML);
if (componentRecipe.getManifests() == null || componentRecipe.getManifests().isEmpty()) {
throw new PackageLoadingException(String.format("Recipe file %s-%s.yaml is missing manifests", componentRecipe.getComponentName(), componentRecipe.getComponentVersion().toString()));
}
Optional<PlatformSpecificManifest> optionalPlatformSpecificManifest = platformResolver.findBestMatch(componentRecipe.getManifests());
if (!optionalPlatformSpecificManifest.isPresent()) {
return Optional.empty();
}
PlatformSpecificManifest platformSpecificManifest = optionalPlatformSpecificManifest.get();
Set<String> selectors = collectAllSelectors(componentRecipe.getManifests());
Map<String, DependencyProperties> dependencyPropertiesMap = new HashMap<>();
if (componentRecipe.getComponentDependencies() != null) {
dependencyPropertiesMap.putAll(componentRecipe.getComponentDependencies());
}
ComponentRecipe packageRecipe = ComponentRecipe.builder().componentName(componentRecipe.getComponentName()).version(componentRecipe.getComponentVersion()).publisher(componentRecipe.getComponentPublisher()).recipeTemplateVersion(componentRecipe.getRecipeFormatVersion()).componentType(componentRecipe.getComponentType()).dependencies(dependencyPropertiesMap).lifecycle(convertLifecycleFromFile(componentRecipe.getLifecycle(), platformSpecificManifest, selectors)).artifacts(convertArtifactsFromFile(platformSpecificManifest.getArtifacts())).componentConfiguration(componentRecipe.getComponentConfiguration()).build();
return Optional.of(packageRecipe);
}
use of com.amazon.aws.iot.greengrass.component.common.DependencyProperties in project aws-greengrass-nucleus by aws-greengrass.
the class RecipeLoaderTest method GIVEN_a_recipe_with_all_fields_and_mocked_resolved_platform_WHEN_converts_THEN_fields_are_populated_correctly.
@Test
void GIVEN_a_recipe_with_all_fields_and_mocked_resolved_platform_WHEN_converts_THEN_fields_are_populated_correctly() throws Exception {
// GIVEN
// read file
String filename = "sample_recipe_with_all_fields.yaml";
String recipeFileContent = new String(Files.readAllBytes(Paths.get(getClass().getResource(filename).toURI())));
// WHEN
Optional<ComponentRecipe> optionalRecipe = recipeLoader.loadFromFile(recipeFileContent);
// THEN
assertThat(optionalRecipe.isPresent(), is(true));
ComponentRecipe recipe = optionalRecipe.get();
assertThat(recipe.getComponentName(), is("FooService"));
assertThat(recipe.getVersion().getValue(), is("1.0.0"));
assertThat(recipe.getComponentType().name().toLowerCase(), is("plugin"));
// GG_NEEDS_REVIEW: TODO enrich testing fields after making lifecycle section strongly typed
assertThat(recipe.getLifecycle(), aMapWithSize(2));
assertThat(recipe.getLifecycle(), hasEntry("install", "echo install"));
assertThat(recipe.getLifecycle(), hasEntry("run", "echo run"));
assertThat(recipe.getArtifacts().size(), is(2));
ComponentArtifact artifact = recipe.getArtifacts().get(0);
assertThat(artifact.getArtifactUri().toString(), is("s3://some-bucket/hello_world.py"));
assertThat(artifact.getChecksum(), is("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f"));
assertThat(artifact.getAlgorithm(), is("SHA-256"));
assertThat(recipe.getDependencies().size(), is(2));
assertThat(recipe.getDependencies(), hasEntry("BarService", new DependencyProperties("^1.1", DependencyType.SOFT)));
assertThat(recipe.getDependencies(), hasEntry("BazService", new DependencyProperties("^2.0", DependencyType.HARD)));
}
use of com.amazon.aws.iot.greengrass.component.common.DependencyProperties in project aws-greengrass-nucleus by aws-greengrass.
the class KernelConfigResolverTest method GIVEN_deployment_with_dependencies_WHEN_config_resolution_requested_THEN_in_nested_namespace_cross_component_configuration_interpolated_for_inner_level.
@Test
void GIVEN_deployment_with_dependencies_WHEN_config_resolution_requested_THEN_in_nested_namespace_cross_component_configuration_interpolated_for_inner_level() throws Exception {
// A depends on both B and C
// GIVEN
ComponentIdentifier componentIdentifierA = new ComponentIdentifier(TEST_INPUT_PACKAGE_A, new Semver("1.2.0"));
ComponentIdentifier componentIdentifierB = new ComponentIdentifier(TEST_INPUT_PACKAGE_B, new Semver("2.3.0"));
ComponentIdentifier componentIdentifierC = new ComponentIdentifier(TEST_INPUT_PACKAGE_C, new Semver("3.4.0"));
Map<String, DependencyProperties> componentADependencies = new HashMap<>();
componentADependencies.put(TEST_INPUT_PACKAGE_B, DependencyProperties.builder().versionRequirement("2.3").build());
componentADependencies.put(TEST_INPUT_PACKAGE_C, DependencyProperties.builder().versionRequirement("3.4").build());
ComponentRecipe componentRecipeA = new ComponentRecipe(RecipeFormatVersion.JAN_25_2020, TEST_INPUT_PACKAGE_A, componentIdentifierA.getVersion(), "", "", null, new HashMap<String, Object>() {
{
put(LIFECYCLE_RUN_KEY, "java -jar {configuration:/jarPath}/test.jar");
}
}, Collections.emptyList(), componentADependencies, null);
ComponentRecipe componentRecipeB = new ComponentRecipe(RecipeFormatVersion.JAN_25_2020, TEST_INPUT_PACKAGE_B, componentIdentifierB.getVersion(), "", "", null, null, Collections.emptyList(), Collections.emptyMap(), null);
ComponentRecipe componentRecipeC = new ComponentRecipe(RecipeFormatVersion.JAN_25_2020, TEST_INPUT_PACKAGE_C, componentIdentifierC.getVersion(), "", "", null, null, Collections.emptyList(), Collections.emptyMap(), null);
DeploymentPackageConfiguration componentDeploymentConfigA = DeploymentPackageConfiguration.builder().packageName(TEST_INPUT_PACKAGE_A).rootComponent(true).resolvedVersion("=1.2").configurationUpdateOperation(new ConfigurationUpdateOperation(new HashMap<String, Object>() {
{
// using work path because only root component supports update config
put("jarPath", String.format("{randomName:{{{%s:work:path}:{%s:work:path}}:randomVal}}", TEST_INPUT_PACKAGE_B, TEST_INPUT_PACKAGE_C));
}
}, new ArrayList<>())).build();
DeploymentPackageConfiguration componentDeploymentConfigB = DeploymentPackageConfiguration.builder().packageName(TEST_INPUT_PACKAGE_B).rootComponent(false).resolvedVersion("=2.3").build();
DeploymentPackageConfiguration componentDeploymentConfigC = DeploymentPackageConfiguration.builder().packageName(TEST_INPUT_PACKAGE_C).rootComponent(false).resolvedVersion("=3.4").build();
DeploymentDocument document = DeploymentDocument.builder().deploymentPackageConfigurationList(Arrays.asList(componentDeploymentConfigA, componentDeploymentConfigB, componentDeploymentConfigC)).timestamp(10_000L).build();
// WHEN
Map<ComponentIdentifier, ComponentRecipe> componentsToResolve = new HashMap<>();
componentsToResolve.put(componentIdentifierA, componentRecipeA);
componentsToResolve.put(componentIdentifierB, componentRecipeB);
componentsToResolve.put(componentIdentifierC, componentRecipeC);
Path expectedCompBWorkPath = Paths.get("/work/" + TEST_INPUT_PACKAGE_B).toAbsolutePath();
Path expectedCompCWorkPath = Paths.get("/work/" + TEST_INPUT_PACKAGE_C).toAbsolutePath();
when(nucleusPaths.workPath(TEST_INPUT_PACKAGE_B)).thenReturn(expectedCompBWorkPath);
when(nucleusPaths.workPath(TEST_INPUT_PACKAGE_C)).thenReturn(expectedCompCWorkPath);
Map<String, Object> servicesConfig = serviceConfigurationProperlyResolved(document, componentsToResolve);
// THEN
String expectedRunCommand = String.format("java -jar {randomName:{{%s:%s}:randomVal}}/test.jar", expectedCompBWorkPath, expectedCompCWorkPath);
assertThat("jarPath should be replace by the {randomName:{{/work/PackageB:/work/PackageC}:randomVal}}", getServiceRunCommand(TEST_INPUT_PACKAGE_A, servicesConfig), equalTo(expectedRunCommand));
}
use of com.amazon.aws.iot.greengrass.component.common.DependencyProperties in project aws-greengrass-nucleus by aws-greengrass.
the class KernelConfigResolverTest method GIVEN_deployment_with_dependencies_WHEN_config_resolution_requested_THEN_cross_component_work_path_interpolated.
@Test
void GIVEN_deployment_with_dependencies_WHEN_config_resolution_requested_THEN_cross_component_work_path_interpolated() throws Exception {
// A depends on both B and C
// GIVEN
ComponentIdentifier componentIdentifierA = new ComponentIdentifier(TEST_INPUT_PACKAGE_A, new Semver("1.2.0"));
ComponentIdentifier componentIdentifierB = new ComponentIdentifier(TEST_INPUT_PACKAGE_B, new Semver("2.3.0"));
ComponentIdentifier componentIdentifierC = new ComponentIdentifier(TEST_INPUT_PACKAGE_C, new Semver("3.4.0"));
Map<String, DependencyProperties> componentADependencies = new HashMap<>();
componentADependencies.put(TEST_INPUT_PACKAGE_B, DependencyProperties.builder().versionRequirement("2.3").build());
componentADependencies.put(TEST_INPUT_PACKAGE_C, DependencyProperties.builder().versionRequirement("3.4").build());
ComponentRecipe componentRecipeA = new ComponentRecipe(RecipeFormatVersion.JAN_25_2020, TEST_INPUT_PACKAGE_A, componentIdentifierA.getVersion(), "", "", null, new HashMap<String, Object>() {
{
put(LIFECYCLE_RUN_KEY, String.format("java -jar {%s:work:path}/test.jar -Dtestval={%s:work:path}", TEST_INPUT_PACKAGE_B, TEST_INPUT_PACKAGE_C));
}
}, Collections.emptyList(), componentADependencies, null);
ComponentRecipe componentRecipeB = new ComponentRecipe(RecipeFormatVersion.JAN_25_2020, TEST_INPUT_PACKAGE_B, componentIdentifierB.getVersion(), "", "", null, null, Collections.emptyList(), Collections.emptyMap(), null);
ComponentRecipe componentRecipeC = new ComponentRecipe(RecipeFormatVersion.JAN_25_2020, TEST_INPUT_PACKAGE_C, componentIdentifierC.getVersion(), "", "", null, null, Collections.emptyList(), Collections.emptyMap(), null);
DeploymentPackageConfiguration componentDeploymentConfigA = DeploymentPackageConfiguration.builder().packageName(TEST_INPUT_PACKAGE_A).rootComponent(true).resolvedVersion("=1.2").build();
DeploymentPackageConfiguration componentDeploymentConfigB = DeploymentPackageConfiguration.builder().packageName(TEST_INPUT_PACKAGE_B).rootComponent(false).resolvedVersion("=2.3").build();
DeploymentPackageConfiguration componentDeploymentConfigC = DeploymentPackageConfiguration.builder().packageName(TEST_INPUT_PACKAGE_C).rootComponent(false).resolvedVersion("=3.4").build();
DeploymentDocument document = DeploymentDocument.builder().deploymentPackageConfigurationList(Arrays.asList(componentDeploymentConfigA, componentDeploymentConfigB, componentDeploymentConfigC)).timestamp(10_000L).build();
// WHEN
Map<ComponentIdentifier, ComponentRecipe> componentsToResolve = new HashMap<>();
componentsToResolve.put(componentIdentifierA, componentRecipeA);
componentsToResolve.put(componentIdentifierB, componentRecipeB);
componentsToResolve.put(componentIdentifierC, componentRecipeC);
Path expectedCompBWorkPath = Paths.get("/work/" + TEST_INPUT_PACKAGE_B).toAbsolutePath();
Path expectedCompCWorkPath = Paths.get("/work/" + TEST_INPUT_PACKAGE_C).toAbsolutePath();
when(nucleusPaths.workPath(TEST_INPUT_PACKAGE_B)).thenReturn(expectedCompBWorkPath);
when(nucleusPaths.workPath(TEST_INPUT_PACKAGE_C)).thenReturn(expectedCompCWorkPath);
Map<String, Object> servicesConfig = serviceConfigurationProperlyResolved(document, componentsToResolve);
// THEN
String expectedRunCommand = String.format("java -jar %s/test.jar -Dtestval=%s", expectedCompBWorkPath, expectedCompCWorkPath);
assertThat("{artifacts:path} should be replace by the package's artifact path", getServiceRunCommand(TEST_INPUT_PACKAGE_A, servicesConfig), equalTo(expectedRunCommand));
}
use of com.amazon.aws.iot.greengrass.component.common.DependencyProperties in project aws-greengrass-nucleus by aws-greengrass.
the class RecipeLoaderTest method GIVEN_a_recipe_file_with_global_dependencies_WHEN_converts_THEN_fields_are_populated_correctly.
@Test
void GIVEN_a_recipe_file_with_global_dependencies_WHEN_converts_THEN_fields_are_populated_correctly() throws Exception {
// GIVEN
// read file
String filename = "sample_recipe_with_all_fields.yaml";
String recipeFileContent = new String(Files.readAllBytes(Paths.get(getClass().getResource(filename).toURI())));
// WHEN
Optional<ComponentRecipe> optionalRecipe = recipeLoader.loadFromFile(recipeFileContent);
// THEN
assertThat(optionalRecipe.isPresent(), is(true));
ComponentRecipe recipe = optionalRecipe.get();
assertThat(recipe.getComponentName(), is("FooService"));
assertThat(recipe.getVersion().getValue(), is("1.0.0"));
assertThat(recipe.getComponentType().name().toLowerCase(), is("plugin"));
// GG_NEEDS_REVIEW: TODO enrich testing fields after making lifecycle section strongly typed
assertThat(recipe.getLifecycle(), aMapWithSize(2));
assertThat(recipe.getLifecycle(), hasEntry("install", "echo install"));
assertThat(recipe.getLifecycle(), hasEntry("run", "echo run"));
assertThat(recipe.getArtifacts().size(), is(2));
ComponentArtifact artifact = recipe.getArtifacts().get(0);
assertThat(artifact.getArtifactUri().toString(), is("s3://some-bucket/hello_world.py"));
assertThat(artifact.getChecksum(), is("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f"));
assertThat(artifact.getAlgorithm(), is("SHA-256"));
assertThat(recipe.getDependencies().size(), is(2));
assertThat(recipe.getDependencies(), hasEntry("BarService", new DependencyProperties("^1.1", DependencyType.SOFT)));
assertThat(recipe.getDependencies(), hasEntry("BazService", new DependencyProperties("^2.0", DependencyType.HARD)));
}
Aggregations