Code format hawkbit-artifact-repository-filesystem (#1933)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
# Eclipse.IoT hawkBit - Artifact Repository File System
|
||||
|
||||
This module contains the implementation of the `ArtifactRepository` based on the file-system.
|
||||
It's a very convenient and easy implementation of storing the artifact binaries into the file-system based on the SHA-1 hash naming.
|
||||
It's a very convenient and easy implementation of storing the artifact binaries into the file-system based on the SHA-1
|
||||
hash naming.
|
||||
|
||||
Due the limit of many file-systems of files within one directory, the files
|
||||
are stored in different sub-directories based on the last four digits of the
|
||||
SHA1-hash `/basepath/[two digit sha1]/[two digit sha1/sha1-hash-filename]`.
|
||||
SHA1-hash `/basepath/[two digit sha1]/[two digit sha1/sha1-hash-filename]`.
|
||||
|
||||
# Compile
|
||||
|
||||
|
||||
@@ -9,44 +9,45 @@
|
||||
SPDX-License-Identifier: EPL-2.0
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<artifactId>hawkbit-artifact-repository-filesystem</artifactId>
|
||||
<name>hawkBit :: Artifact Repository :: Filesystem</name>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<artifactId>hawkbit-artifact-repository-filesystem</artifactId>
|
||||
<name>hawkBit :: Artifact Repository :: Filesystem</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.qameta.allure</groupId>
|
||||
<artifactId>allure-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.qameta.allure</groupId>
|
||||
<artifactId>allure-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ArtifactFileNotFoundException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Creates the Exception from it's cause
|
||||
*
|
||||
* @param cause the original exception
|
||||
*/
|
||||
public ArtifactFileNotFoundException(final Exception cause) {
|
||||
|
||||
@@ -22,8 +22,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class ArtifactFilesystemConfiguration {
|
||||
|
||||
/**
|
||||
* @param artifactFilesystemProperties
|
||||
* the artifact file system properties
|
||||
* @param artifactFilesystemProperties the artifact file system properties
|
||||
* @return Default {@link ArtifactRepository} implementation.
|
||||
*/
|
||||
@Bean
|
||||
|
||||
@@ -24,10 +24,10 @@ import org.springframework.validation.annotation.Validated;
|
||||
* Implementation of the {@link ArtifactRepository} to store artifacts on the
|
||||
* file-system. The files are stored by their SHA1 hash of the artifact binary.
|
||||
* Duplicate files with the same SHA1 hash will only stored once.
|
||||
*
|
||||
*
|
||||
* All files are stored flat in one base directory configured in the
|
||||
* {@link ArtifactFilesystemProperties#getPath()}.
|
||||
*
|
||||
*
|
||||
* Due the limit of many file-systems of files within one directory, the files
|
||||
* are stored in different sub-directories based on the last four digits of the
|
||||
* SHA1-hash {@code (/basepath/[two digit sha1]/[two digit sha1])}.
|
||||
@@ -39,10 +39,9 @@ public class ArtifactFilesystemRepository extends AbstractArtifactRepository {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param artifactResourceProperties
|
||||
* the properties which holds the necessary configuration for the
|
||||
* file-system repository
|
||||
*
|
||||
* @param artifactResourceProperties the properties which holds the necessary configuration for the
|
||||
* file-system repository
|
||||
*/
|
||||
public ArtifactFilesystemRepository(final ArtifactFilesystemProperties artifactResourceProperties) {
|
||||
this.artifactResourceProperties = artifactResourceProperties;
|
||||
@@ -64,10 +63,22 @@ public class ArtifactFilesystemRepository extends AbstractArtifactRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes, final String contentType, final String tempFile) throws IOException {
|
||||
public void deleteByTenant(final String tenant) {
|
||||
FileUtils.deleteQuietly(Paths.get(artifactResourceProperties.getPath(), sanitizeTenant(tenant)).toFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByTenantAndSha1(final String tenant, final String sha1) {
|
||||
return getFile(tenant, sha1).exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes, final String contentType, final String tempFile)
|
||||
throws IOException {
|
||||
|
||||
final File file = new File(tempFile);
|
||||
return renameFileToSHA1Naming(tenant, file, new ArtifactFilesystem(file, base16Hashes.getSha1(), base16Hashes, file.length(), contentType));
|
||||
return renameFileToSHA1Naming(tenant, file,
|
||||
new ArtifactFilesystem(file, base16Hashes.getSha1(), base16Hashes, file.length(), contentType));
|
||||
}
|
||||
|
||||
private ArtifactFilesystem renameFileToSHA1Naming(final String tenant, final File file,
|
||||
@@ -95,14 +106,4 @@ public class ArtifactFilesystemRepository extends AbstractArtifactRepository {
|
||||
final String folder2 = sha1.substring(length - 2, length);
|
||||
return Paths.get(artifactResourceProperties.getPath(), sanitizeTenant(tenant), folder1, folder2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByTenant(final String tenant) {
|
||||
FileUtils.deleteQuietly(Paths.get(artifactResourceProperties.getPath(), sanitizeTenant(tenant)).toFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByTenantAndSha1(final String tenant, final String sha1) {
|
||||
return getFile(tenant, sha1).exists();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Random;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -26,10 +29,6 @@ import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
|
||||
@Slf4j
|
||||
@Feature("Unit Tests - Artifact File System Repository")
|
||||
@Story("Test storing artifact binaries in the file-system")
|
||||
@@ -121,12 +120,6 @@ public class ArtifactFilesystemRepositoryTest {
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractDbArtifact storeRandomArtifact(final byte[] fileContent) {
|
||||
final String fileName = "filename.tmp";
|
||||
final ByteArrayInputStream inputStream = new ByteArrayInputStream(fileContent);
|
||||
return artifactFilesystemRepository.store(TENANT, inputStream, fileName, "application/txt", null);
|
||||
}
|
||||
|
||||
private static byte[] randomBytes() {
|
||||
final byte[] randomBytes = new byte[20];
|
||||
final Random ran = new Random();
|
||||
@@ -134,4 +127,10 @@ public class ArtifactFilesystemRepositoryTest {
|
||||
return randomBytes;
|
||||
}
|
||||
|
||||
private AbstractDbArtifact storeRandomArtifact(final byte[] fileContent) {
|
||||
final String fileName = "filename.tmp";
|
||||
final ByteArrayInputStream inputStream = new ByteArrayInputStream(fileContent);
|
||||
return artifactFilesystemRepository.store(TENANT, inputStream, fileName, "application/txt", null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,15 +16,14 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
|
||||
@Feature("Unit Tests - Artifact File System Repository")
|
||||
@Story("Test storing artifact binaries in the file-system")
|
||||
public class ArtifactFilesystemTest {
|
||||
|
||||
Reference in New Issue
Block a user