Search in sources :

Example 1 with ComponentStore

use of com.aws.greengrass.componentmanager.ComponentStore in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentTaskIntegrationTest method setupKernel.

@BeforeAll
static void setupKernel() throws IOException {
    kernel = new Kernel();
    rootDir = Paths.get(System.getProperty("root"));
    NoOpPathOwnershipHandler.register(kernel);
    ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, DeploymentTaskIntegrationTest.class.getResource("onlyMain.yaml"));
    kernel.launch();
    // get required instances from context
    componentManager = kernel.getContext().get(ComponentManager.class);
    componentStore = kernel.getContext().get(ComponentStore.class);
    dependencyResolver = kernel.getContext().get(DependencyResolver.class);
    kernelConfigResolver = kernel.getContext().get(KernelConfigResolver.class);
    deploymentConfigMerger = kernel.getContext().get(DeploymentConfigMerger.class);
    deploymentDocumentDownloader = kernel.getContext().get(DeploymentDocumentDownloader.class);
    thingGroupHelper = kernel.getContext().get(ThingGroupHelper.class);
}
Also used : ThingGroupHelper(com.aws.greengrass.deployment.ThingGroupHelper) DeploymentDocumentDownloader(com.aws.greengrass.deployment.DeploymentDocumentDownloader) DeploymentConfigMerger(com.aws.greengrass.deployment.DeploymentConfigMerger) ComponentManager(com.aws.greengrass.componentmanager.ComponentManager) KernelConfigResolver(com.aws.greengrass.componentmanager.KernelConfigResolver) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) ComponentStore(com.aws.greengrass.componentmanager.ComponentStore) DependencyResolver(com.aws.greengrass.componentmanager.DependencyResolver) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with ComponentStore

use of com.aws.greengrass.componentmanager.ComponentStore in project aws-greengrass-nucleus by aws-greengrass.

the class PluginComponentTest method setupPackageStore.

static void setupPackageStore(Kernel kernel, ComponentIdentifier componentId, ComponentIdentifier... pluginIds) throws IOException, PackagingException, URISyntaxException {
    Path localStoreContentPath = Paths.get(PluginComponentTest.class.getResource("local_store_content").toURI());
    NucleusPaths nucleusPaths = kernel.getNucleusPaths();
    PreloadComponentStoreHelper.preloadRecipesFromTestResourceDir(localStoreContentPath.resolve("recipes"), nucleusPaths.recipePath());
    FileUtils.copyDirectory(localStoreContentPath.resolve("artifacts").toFile(), nucleusPaths.artifactPath().toFile());
    ComponentStore e2ETestComponentStore = kernel.getContext().get(ComponentStore.class);
    Path jarFilePath = e2ETestComponentStore.resolveArtifactDirectoryPath(componentId).resolve("plugin-tests.jar");
    // Copy over the same jar file as the plugin-1.1.0 artifact
    Path artifact1_1_0 = e2ETestComponentStore.resolveArtifactDirectoryPath(new ComponentIdentifier(componentName, new Semver("1.1.0"))).resolve(componentName + JAR_FILE_EXTENSION);
    Path artifactPath1_0_0 = e2ETestComponentStore.resolveArtifactDirectoryPath(componentId).resolve(componentName + JAR_FILE_EXTENSION);
    // set the artifact dir as writable so we can copy
    Platform.getInstance().setPermissions(FileSystemPermission.builder().ownerRead(true).ownerWrite(true).ownerExecute(true).otherRead(true).otherExecute(true).build(), artifactPath1_0_0.getParent().getParent(), FileSystemPermission.Option.Recurse);
    FileUtils.copyFile(jarFilePath.toFile(), artifact1_1_0.toFile());
    FileUtils.copyFile(jarFilePath.toFile(), artifactPath1_0_0.toFile());
    for (ComponentIdentifier pluginId : pluginIds) {
        Path artifactPath = e2ETestComponentStore.resolveArtifactDirectoryPath(pluginId).resolve(pluginId.getName() + JAR_FILE_EXTENSION);
        FileUtils.copyFile(jarFilePath.toFile(), artifactPath.toFile());
    }
}
Also used : Path(java.nio.file.Path) NucleusPaths(com.aws.greengrass.util.NucleusPaths) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) Semver(com.vdurmont.semver4j.Semver) ComponentStore(com.aws.greengrass.componentmanager.ComponentStore)

Example 3 with ComponentStore

use of com.aws.greengrass.componentmanager.ComponentStore in project aws-greengrass-nucleus by aws-greengrass.

the class ComponentManagerIntegTest method GIVEN_component_with_artifact_WHEN_prepareArtifacts_THEN_set_permissions_on_artifacts.

@Test
void GIVEN_component_with_artifact_WHEN_prepareArtifacts_THEN_set_permissions_on_artifacts() throws Exception {
    ComponentIdentifier ident = new ComponentIdentifier("aws.iot.gg.test.integ.perm", new Semver("1.0.0"));
    NucleusPaths nucleusPaths = kernel.getNucleusPaths();
    nucleusPaths.setComponentStorePath(tempRootDir);
    ComponentStore store = new ComponentStore(nucleusPaths, platformResolver, recipeLoader);
    kernel.getContext().put(ComponentStore.class, store);
    File scriptFile = store.resolveArtifactDirectoryPath(ident).resolve("script.sh").toFile();
    File emptyFile = store.resolveArtifactDirectoryPath(ident).resolve("empty.txt").toFile();
    ArtifactDownloader mockDownloader = mock(ArtifactDownloader.class);
    when(mockDownloader.downloadRequired()).thenReturn(true);
    when(mockDownloader.checkDownloadable()).thenReturn(Optional.empty());
    when(mockDownloader.getArtifactFile()).thenReturn(scriptFile).thenReturn(emptyFile);
    when(mockDownloader.canUnarchiveArtifact()).thenReturn(true);
    when(mockDownloader.canSetFilePermissions()).thenReturn(true);
    when(mockDownloader.checkComponentStoreSize()).thenReturn(true);
    when(mockDownloader.download()).thenAnswer(downloadToPath("script.sh", scriptFile)).thenAnswer(downloadToPath("empty.txt", emptyFile));
    ArtifactDownloaderFactory mockDownloaderFactory = mock(ArtifactDownloaderFactory.class);
    when(mockDownloaderFactory.getArtifactDownloader(any(), any(), any())).thenReturn(mockDownloader);
    kernel.getContext().put(ArtifactDownloaderFactory.class, mockDownloaderFactory);
    Files.copy(Paths.get(this.getClass().getResource("aws.iot.gg.test.integ.perm-1.0.0.yaml").toURI()), nucleusPaths.recipePath().resolve(PreloadComponentStoreHelper.getRecipeStorageFilenameFromTestSource("aws.iot.gg.test.integ.perm-1.0.0.yaml")));
    // THEN
    kernel.getContext().get(ComponentManager.class).preparePackages(Collections.singletonList(ident)).get(10, TimeUnit.SECONDS);
    assertThat(nucleusPaths.artifactPath(ident).resolve("script.sh"), hasPermission(FileSystemPermission.builder().ownerRead(true).groupRead(true).otherRead(true).ownerWrite(!PlatformResolver.isWindows && !SystemUtils.USER_NAME.equals(ROOT)).ownerExecute(true).groupExecute(true).build()));
    assertThat(nucleusPaths.artifactPath(ident).resolve("empty.txt"), hasPermission(FileSystemPermission.builder().ownerRead(true).groupRead(true).ownerWrite(!PlatformResolver.isWindows && !SystemUtils.USER_NAME.equals(ROOT)).build()));
}
Also used : ArtifactDownloaderFactory(com.aws.greengrass.componentmanager.builtins.ArtifactDownloaderFactory) NucleusPaths(com.aws.greengrass.util.NucleusPaths) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) Semver(com.vdurmont.semver4j.Semver) FileMatchers.anExistingFile(org.hamcrest.io.FileMatchers.anExistingFile) File(java.io.File) ArtifactDownloader(com.aws.greengrass.componentmanager.builtins.ArtifactDownloader) ComponentStore(com.aws.greengrass.componentmanager.ComponentStore) Test(org.junit.jupiter.api.Test)

Example 4 with ComponentStore

use of com.aws.greengrass.componentmanager.ComponentStore in project aws-greengrass-nucleus by aws-greengrass.

the class ComponentManagerIntegTest method GIVEN_component_with_archived_artifact_WHEN_prepareArtifacts_THEN_unarchives_artifacts.

@Test
void GIVEN_component_with_archived_artifact_WHEN_prepareArtifacts_THEN_unarchives_artifacts() throws Exception {
    // GIVEN
    ComponentIdentifier ident = new ComponentIdentifier("aws.iot.gg.test.integ.zip", new Semver("1.0.0"));
    NucleusPaths nucleusPaths = kernel.getNucleusPaths();
    nucleusPaths.setComponentStorePath(tempRootDir);
    ComponentStore store = new ComponentStore(nucleusPaths, platformResolver, recipeLoader);
    kernel.getContext().put(ComponentStore.class, store);
    ArtifactDownloader mockDownloader = mock(ArtifactDownloader.class);
    File artifactFile = store.resolveArtifactDirectoryPath(ident).resolve("zip.zip").toFile();
    when(mockDownloader.downloadRequired()).thenReturn(true);
    when(mockDownloader.checkDownloadable()).thenReturn(Optional.empty());
    when(mockDownloader.getArtifactFile()).thenReturn(artifactFile);
    when(mockDownloader.canUnarchiveArtifact()).thenReturn(true);
    when(mockDownloader.canSetFilePermissions()).thenReturn(true);
    when(mockDownloader.checkComponentStoreSize()).thenReturn(true);
    when(mockDownloader.download()).thenAnswer(downloadToPath("zip.zip", artifactFile));
    ArtifactDownloaderFactory mockDownloaderFactory = mock(ArtifactDownloaderFactory.class);
    when(mockDownloaderFactory.getArtifactDownloader(any(), any(), any())).thenReturn(mockDownloader);
    kernel.getContext().put(ArtifactDownloaderFactory.class, mockDownloaderFactory);
    Files.copy(Paths.get(this.getClass().getResource("aws.iot.gg.test.integ.zip-1.0.0.yaml").toURI()), nucleusPaths.recipePath().resolve(PreloadComponentStoreHelper.getRecipeStorageFilenameFromTestSource("aws.iot.gg.test.integ.zip-1.0.0.yaml")));
    // THEN
    kernel.getContext().get(ComponentManager.class).preparePackages(Collections.singletonList(ident)).get(10, TimeUnit.SECONDS);
    Path zipPath = nucleusPaths.unarchiveArtifactPath(ident, "zip");
    assertThat(zipPath.toFile(), anExistingDirectory());
    assertThat(zipPath.resolve("zip").toFile(), anExistingDirectory());
    assertThat(zipPath.resolve("zip").resolve("1").toFile(), anExistingFile());
    assertThat(zipPath.resolve("zip").resolve("2").toFile(), anExistingFile());
    // check everyone can enter dir
    assertThat(zipPath.resolve("zip"), hasPermission(FileSystemPermission.builder().ownerRead(true).ownerWrite(true).ownerExecute(true).groupRead(true).groupExecute(true).otherRead(true).otherExecute(true).build()));
    // check perms match what we gave
    FileSystemPermission allRead = FileSystemPermission.builder().ownerRead(true).groupRead(true).otherRead(true).ownerWrite(!PlatformResolver.isWindows && !SystemUtils.USER_NAME.equals(ROOT)).build();
    assertThat(zipPath.resolve("zip").resolve("1"), hasPermission(allRead));
    assertThat(zipPath.resolve("zip").resolve("2"), hasPermission(allRead));
}
Also used : Path(java.nio.file.Path) ArtifactDownloaderFactory(com.aws.greengrass.componentmanager.builtins.ArtifactDownloaderFactory) NucleusPaths(com.aws.greengrass.util.NucleusPaths) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) FileSystemPermission(com.aws.greengrass.util.FileSystemPermission) Semver(com.vdurmont.semver4j.Semver) ArtifactDownloader(com.aws.greengrass.componentmanager.builtins.ArtifactDownloader) FileMatchers.anExistingFile(org.hamcrest.io.FileMatchers.anExistingFile) File(java.io.File) ComponentStore(com.aws.greengrass.componentmanager.ComponentStore) Test(org.junit.jupiter.api.Test)

Example 5 with ComponentStore

use of com.aws.greengrass.componentmanager.ComponentStore in project aws-greengrass-nucleus by aws-greengrass.

the class DockerImageArtifactDownloadTest method before.

@BeforeEach
void before() throws Exception {
    Instant credentialsExpiry = Instant.now().plusSeconds(10);
    AuthorizationData authorizationData = AuthorizationData.builder().authorizationToken(Base64.getEncoder().encodeToString("username:password".getBytes(StandardCharsets.UTF_8))).expiresAt(credentialsExpiry).build();
    GetAuthorizationTokenResponse response = GetAuthorizationTokenResponse.builder().authorizationData(authorizationData).build();
    lenient().when(ecrClient.getAuthorizationToken(any(GetAuthorizationTokenRequest.class))).thenReturn(response);
    lenient().when(dockerClient.dockerInstalled()).thenReturn(true);
    AtomicBoolean mqttOnline = new AtomicBoolean(true);
    lenient().when(mqttClient.getMqttOnline()).thenReturn(mqttOnline);
    kernel = new Kernel();
    NucleusPaths nucleusPaths = kernel.getNucleusPaths();
    nucleusPaths.setComponentStorePath(tempRootDir);
    ComponentStore store = new ComponentStore(nucleusPaths, platformResolver, recipeLoader);
    EcrAccessor ecrAccessor = new EcrAccessor(ecrClient);
    kernel.getContext().put(ComponentStore.class, store);
    kernel.getContext().put(EcrAccessor.class, ecrAccessor);
    kernel.getContext().put(DefaultDockerClient.class, dockerClient);
    kernel.getContext().put(MqttClient.class, mqttClient);
    preloadLocalStoreContent();
    componentManager = kernel.getContext().get(ComponentManager.class);
}
Also used : GetAuthorizationTokenResponse(software.amazon.awssdk.services.ecr.model.GetAuthorizationTokenResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GetAuthorizationTokenRequest(software.amazon.awssdk.services.ecr.model.GetAuthorizationTokenRequest) AuthorizationData(software.amazon.awssdk.services.ecr.model.AuthorizationData) EcrAccessor(com.aws.greengrass.componentmanager.plugins.docker.EcrAccessor) NucleusPaths(com.aws.greengrass.util.NucleusPaths) Instant(java.time.Instant) ComponentManager(com.aws.greengrass.componentmanager.ComponentManager) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) ComponentStore(com.aws.greengrass.componentmanager.ComponentStore) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ComponentStore (com.aws.greengrass.componentmanager.ComponentStore)7 NucleusPaths (com.aws.greengrass.util.NucleusPaths)6 ComponentIdentifier (com.aws.greengrass.componentmanager.models.ComponentIdentifier)5 Path (java.nio.file.Path)4 Semver (com.vdurmont.semver4j.Semver)3 ComponentManager (com.aws.greengrass.componentmanager.ComponentManager)2 ArtifactDownloader (com.aws.greengrass.componentmanager.builtins.ArtifactDownloader)2 ArtifactDownloaderFactory (com.aws.greengrass.componentmanager.builtins.ArtifactDownloaderFactory)2 Kernel (com.aws.greengrass.lifecyclemanager.Kernel)2 File (java.io.File)2 FileMatchers.anExistingFile (org.hamcrest.io.FileMatchers.anExistingFile)2 Test (org.junit.jupiter.api.Test)2 DependencyType (com.amazon.aws.iot.greengrass.component.common.DependencyType)1 DeploymentCapability (com.amazon.aws.iot.greengrass.configuration.common.DeploymentCapability)1 DependencyResolver (com.aws.greengrass.componentmanager.DependencyResolver)1 KernelConfigResolver (com.aws.greengrass.componentmanager.KernelConfigResolver)1 VERSION_CONFIG_KEY (com.aws.greengrass.componentmanager.KernelConfigResolver.VERSION_CONFIG_KEY)1 EcrAccessor (com.aws.greengrass.componentmanager.plugins.docker.EcrAccessor)1 Configuration (com.aws.greengrass.config.Configuration)1 ConfigurationWriter (com.aws.greengrass.config.ConfigurationWriter)1