Code format hawkbit-artifact-repository-filesystem (#1933)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-05 11:13:48 +02:00
committed by GitHub
parent eb1cb699ca
commit 2c2ed8f8ab
7 changed files with 75 additions and 74 deletions

View File

@@ -1,7 +1,8 @@
# 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

View File

@@ -9,7 +9,8 @@
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">
<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>

View File

@@ -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) {

View File

@@ -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

View File

@@ -40,8 +40,7 @@ public class ArtifactFilesystemRepository extends AbstractArtifactRepository {
/**
* Constructor.
*
* @param artifactResourceProperties
* the properties which holds the necessary configuration for the
* @param artifactResourceProperties the properties which holds the necessary configuration for the
* file-system repository
*/
public ArtifactFilesystemRepository(final ArtifactFilesystemProperties 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();
}
}

View File

@@ -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);
}
}

View File

@@ -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 {