use of com.aws.greengrass.util.NucleusPaths 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());
}
}
use of com.aws.greengrass.util.NucleusPaths 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()));
}
use of com.aws.greengrass.util.NucleusPaths 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));
}
use of com.aws.greengrass.util.NucleusPaths 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);
}
use of com.aws.greengrass.util.NucleusPaths in project aws-greengrass-nucleus by aws-greengrass.
the class DeviceConfigurationTest method beforeEach.
@BeforeEach
void beforeEach() {
NucleusPaths nucleusPaths = mock(NucleusPaths.class);
Topics rootConfigTopics = mock(Topics.class);
when(rootConfigTopics.findOrDefault(any(), anyString(), anyString(), anyString())).thenReturn(new ArrayList<>());
lenient().when(configuration.lookup(anyString(), anyString(), anyString())).thenReturn(mock(Topic.class));
when(configuration.lookup(anyString(), anyString(), anyString(), anyString())).thenReturn(mockTopic);
lenient().when(configuration.getRoot()).thenReturn(rootConfigTopics);
when(mockKernel.getConfig()).thenReturn(configuration);
lenient().when(mockKernel.getNucleusPaths()).thenReturn(nucleusPaths);
Topics topics = Topics.of(mock(Context.class), SERVICES_NAMESPACE_TOPIC, mock(Topics.class));
when(mockTopics.subscribe(any())).thenReturn(mockTopics);
when(configuration.lookupTopics(anyString(), anyString(), anyString())).thenReturn(mockTopics);
when(configuration.lookupTopics(anyString(), anyString(), anyString(), anyString())).thenReturn(mockTopics);
when(configuration.lookupTopics(anyString())).thenReturn(topics);
lenient().when(configuration.lookupTopics(anyString())).thenReturn(topics);
}
Aggregations