use of com.aws.greengrass.componentmanager.models.ComponentRecipe in project aws-greengrass-nucleus by aws-greengrass.
the class DeviceConfiguration method initializeNucleusFromRecipe.
/**
* Load Nucleus component information from build recipe.
*
* @param kernelAlts KernelAlternatives instance
*/
public void initializeNucleusFromRecipe(KernelAlternatives kernelAlts) {
String nucleusComponentName = getNucleusComponentName();
persistInitialLaunchParams(kernelAlts);
Semver componentVersion = null;
try {
Path unpackDir = locateCurrentKernelUnpackDir();
Path recipePath = unpackDir.resolve(NUCLEUS_BUILD_METADATA_DIRECTORY).resolve(NUCLEUS_RECIPE_FILENAME);
if (!Files.exists(recipePath)) {
throw new PackageLoadingException("Failed to find Nucleus recipe at " + recipePath);
}
// Update Nucleus in config store
Optional<ComponentRecipe> resolvedRecipe = kernel.getContext().get(RecipeLoader.class).loadFromFile(new String(Files.readAllBytes(recipePath.toAbsolutePath()), StandardCharsets.UTF_8));
if (!resolvedRecipe.isPresent()) {
throw new PackageLoadingException("Failed to load Nucleus recipe");
}
ComponentRecipe componentRecipe = resolvedRecipe.get();
componentVersion = componentRecipe.getVersion();
initializeNucleusLifecycleConfig(nucleusComponentName, componentRecipe);
initializeComponentStore(kernelAlts, nucleusComponentName, componentVersion, recipePath, unpackDir);
} catch (IOException | URISyntaxException | PackageLoadingException e) {
logger.atError().log("Unable to set up Nucleus from build recipe file", e);
}
initializeNucleusVersion(nucleusComponentName, componentVersion == null ? FALLBACK_VERSION : componentVersion.toString());
}
use of com.aws.greengrass.componentmanager.models.ComponentRecipe in project aws-greengrass-nucleus by aws-greengrass.
the class DeviceConfigurationTest method GIVEN_recipe_WHEN_initializeNucleusLifecycleConfig_THEN_init_lifecycle_and_dependencies.
@Test
void GIVEN_recipe_WHEN_initializeNucleusLifecycleConfig_THEN_init_lifecycle_and_dependencies(@Mock KernelConfigResolver kernelConfigResolver, @Mock Context context) throws Exception {
deviceConfiguration = new DeviceConfiguration(mockKernel);
List mockDependencies = Arrays.asList("A", "B", "C");
doReturn(mockDependencies).when(kernelConfigResolver).generateServiceDependencies(anyMap());
Object interpolatedLifecycle = new HashMap<String, String>() {
{
put("lifecycle", "step");
}
};
doReturn(interpolatedLifecycle).when(kernelConfigResolver).interpolate(anyMap(), any(), anySet(), anyMap());
doReturn(kernelConfigResolver).when(context).get(KernelConfigResolver.class);
doReturn(context).when(mockKernel).getContext();
String nucleusComponentName = "test.component.name";
ComponentRecipe componentRecipe = ComponentRecipe.builder().lifecycle((Map<String, Object>) interpolatedLifecycle).build();
Topics lifecycleTopics = spy(Topics.of(context, SERVICE_LIFECYCLE_NAMESPACE_TOPIC, null));
when(configuration.lookupTopics(eq(DEFAULT_VALUE_TIMESTAMP), eq(SERVICES_NAMESPACE_TOPIC), eq(nucleusComponentName), eq(SERVICE_LIFECYCLE_NAMESPACE_TOPIC))).thenReturn(lifecycleTopics);
Topic dependencyTopic = Topic.of(context, SERVICE_DEPENDENCIES_NAMESPACE_TOPIC, null);
when(configuration.lookup(eq(DEFAULT_VALUE_TIMESTAMP), eq(SERVICES_NAMESPACE_TOPIC), eq(nucleusComponentName), eq(SERVICE_DEPENDENCIES_NAMESPACE_TOPIC))).thenReturn(dependencyTopic);
deviceConfiguration.initializeNucleusLifecycleConfig(nucleusComponentName, componentRecipe);
assertEquals(mockDependencies, dependencyTopic.toPOJO());
verify(lifecycleTopics).replaceAndWait((Map<String, Object>) interpolatedLifecycle);
}
use of com.aws.greengrass.componentmanager.models.ComponentRecipe in project aws-greengrass-nucleus by aws-greengrass.
the class ComponentManager method preparePackage.
private void preparePackage(ComponentIdentifier componentIdentifier) throws PackageLoadingException, PackageDownloadException, InvalidArtifactUriException, InterruptedException {
logger.atInfo().setEventType("prepare-package-start").kv(PACKAGE_IDENTIFIER, componentIdentifier).log();
try {
ComponentRecipe pkg = componentStore.getPackageRecipe(componentIdentifier);
prepareArtifacts(componentIdentifier, pkg.getArtifacts());
logger.atDebug("prepare-package-finished").kv(PACKAGE_IDENTIFIER, componentIdentifier).log();
} catch (SizeLimitException e) {
logger.atError().log("Size limit reached", e);
throw e;
} catch (PackageLoadingException | PackageDownloadException e) {
logger.atError().log("Failed to prepare package {}", componentIdentifier, e);
throw e;
}
}
use of com.aws.greengrass.componentmanager.models.ComponentRecipe 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.aws.greengrass.componentmanager.models.ComponentRecipe in project aws-greengrass-nucleus by aws-greengrass.
the class ComponentStoreTest method GIVEN_a_recipe_exists_WHEN_findPackageRecipe_THEN_return_it.
@Test
void GIVEN_a_recipe_exists_WHEN_findPackageRecipe_THEN_return_it() throws Exception {
// GIVEN
preloadRecipeFileFromTestResource(MONITORING_SERVICE_PKG_RECIPE_FILE_NAME);
Path sourceRecipe = RECIPE_RESOURCE_PATH.resolve(MONITORING_SERVICE_PKG_RECIPE_FILE_NAME);
// WHEN
Optional<ComponentRecipe> optionalPackageRecipe = componentStore.findPackageRecipe(MONITORING_SERVICE_PKG_ID);
// THEN
assertTrue(optionalPackageRecipe.isPresent());
ComponentRecipe expectedRecipe = recipeLoader.loadFromFile(new String(Files.readAllBytes(sourceRecipe))).get();
assertThat(optionalPackageRecipe.get(), equalTo(expectedRecipe));
}
Aggregations