mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05:18:58 +00:00
(control-service) Add timestamp to file storages.
This commit is contained in:
parent
676e7c7947
commit
9e185e80ce
@ -13,6 +13,7 @@ import java.io.IOException;
|
|||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.nio.file.attribute.PosixFilePermissions;
|
import java.nio.file.attribute.PosixFilePermissions;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/** Manages file storage for processes and services
|
/** Manages file storage for processes and services
|
||||||
@ -292,6 +293,7 @@ public class FileStorageService {
|
|||||||
new FileStorageId(rs.getLong("ID")),
|
new FileStorageId(rs.getLong("ID")),
|
||||||
base,
|
base,
|
||||||
type,
|
type,
|
||||||
|
LocalDateTime.now(),
|
||||||
newDir.toString(),
|
newDir.toString(),
|
||||||
description
|
description
|
||||||
);
|
);
|
||||||
@ -305,7 +307,7 @@ public class FileStorageService {
|
|||||||
public FileStorage getStorageByType(FileStorageType type) throws SQLException {
|
public FileStorage getStorageByType(FileStorageType type) throws SQLException {
|
||||||
try (var conn = dataSource.getConnection();
|
try (var conn = dataSource.getConnection();
|
||||||
var stmt = conn.prepareStatement("""
|
var stmt = conn.prepareStatement("""
|
||||||
SELECT PATH, DESCRIPTION, ID, BASE_ID
|
SELECT PATH, DESCRIPTION, ID, BASE_ID, CREATE_DATE
|
||||||
FROM FILE_STORAGE_VIEW WHERE TYPE = ?
|
FROM FILE_STORAGE_VIEW WHERE TYPE = ?
|
||||||
""")) {
|
""")) {
|
||||||
stmt.setString(1, type.name());
|
stmt.setString(1, type.name());
|
||||||
@ -314,11 +316,13 @@ public class FileStorageService {
|
|||||||
long baseId;
|
long baseId;
|
||||||
String path;
|
String path;
|
||||||
String description;
|
String description;
|
||||||
|
LocalDateTime createDateTime;
|
||||||
|
|
||||||
try (var rs = stmt.executeQuery()) {
|
try (var rs = stmt.executeQuery()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
baseId = rs.getLong("BASE_ID");
|
baseId = rs.getLong("BASE_ID");
|
||||||
storageId = rs.getLong("ID");
|
storageId = rs.getLong("ID");
|
||||||
|
createDateTime = rs.getTimestamp("CREATE_DATE").toLocalDateTime();
|
||||||
path = rs.getString("PATH");
|
path = rs.getString("PATH");
|
||||||
description = rs.getString("DESCRIPTION");
|
description = rs.getString("DESCRIPTION");
|
||||||
}
|
}
|
||||||
@ -332,6 +336,7 @@ public class FileStorageService {
|
|||||||
new FileStorageId(storageId),
|
new FileStorageId(storageId),
|
||||||
base,
|
base,
|
||||||
type,
|
type,
|
||||||
|
createDateTime,
|
||||||
path,
|
path,
|
||||||
description
|
description
|
||||||
);
|
);
|
||||||
@ -344,7 +349,7 @@ public class FileStorageService {
|
|||||||
|
|
||||||
try (var conn = dataSource.getConnection();
|
try (var conn = dataSource.getConnection();
|
||||||
var stmt = conn.prepareStatement("""
|
var stmt = conn.prepareStatement("""
|
||||||
SELECT PATH, TYPE, DESCRIPTION, ID, BASE_ID
|
SELECT PATH, TYPE, DESCRIPTION, CREATE_DATE, ID, BASE_ID
|
||||||
FROM FILE_STORAGE_VIEW WHERE ID = ?
|
FROM FILE_STORAGE_VIEW WHERE ID = ?
|
||||||
""")) {
|
""")) {
|
||||||
stmt.setLong(1, id.id());
|
stmt.setLong(1, id.id());
|
||||||
@ -354,6 +359,7 @@ public class FileStorageService {
|
|||||||
String path;
|
String path;
|
||||||
String description;
|
String description;
|
||||||
FileStorageType type;
|
FileStorageType type;
|
||||||
|
LocalDateTime createDateTime;
|
||||||
|
|
||||||
try (var rs = stmt.executeQuery()) {
|
try (var rs = stmt.executeQuery()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
@ -362,6 +368,7 @@ public class FileStorageService {
|
|||||||
type = FileStorageType.valueOf(rs.getString("TYPE"));
|
type = FileStorageType.valueOf(rs.getString("TYPE"));
|
||||||
path = rs.getString("PATH");
|
path = rs.getString("PATH");
|
||||||
description = rs.getString("DESCRIPTION");
|
description = rs.getString("DESCRIPTION");
|
||||||
|
createDateTime = rs.getTimestamp("CREATE_DATE").toLocalDateTime();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
@ -373,6 +380,7 @@ public class FileStorageService {
|
|||||||
new FileStorageId(storageId),
|
new FileStorageId(storageId),
|
||||||
base,
|
base,
|
||||||
type,
|
type,
|
||||||
|
createDateTime,
|
||||||
path,
|
path,
|
||||||
description
|
description
|
||||||
);
|
);
|
||||||
@ -394,7 +402,7 @@ public class FileStorageService {
|
|||||||
List<FileStorage> ret = new ArrayList<>();
|
List<FileStorage> ret = new ArrayList<>();
|
||||||
try (var conn = dataSource.getConnection();
|
try (var conn = dataSource.getConnection();
|
||||||
var stmt = conn.prepareStatement("""
|
var stmt = conn.prepareStatement("""
|
||||||
SELECT PATH, TYPE, DESCRIPTION, ID, BASE_ID
|
SELECT PATH, TYPE, DESCRIPTION, CREATE_DATE, ID, BASE_ID
|
||||||
FROM FILE_STORAGE_VIEW
|
FROM FILE_STORAGE_VIEW
|
||||||
""")) {
|
""")) {
|
||||||
|
|
||||||
@ -402,6 +410,7 @@ public class FileStorageService {
|
|||||||
long baseId;
|
long baseId;
|
||||||
String path;
|
String path;
|
||||||
String description;
|
String description;
|
||||||
|
LocalDateTime createDateTime;
|
||||||
FileStorageType type;
|
FileStorageType type;
|
||||||
|
|
||||||
try (var rs = stmt.executeQuery()) {
|
try (var rs = stmt.executeQuery()) {
|
||||||
@ -411,13 +420,14 @@ public class FileStorageService {
|
|||||||
path = rs.getString("PATH");
|
path = rs.getString("PATH");
|
||||||
type = FileStorageType.valueOf(rs.getString("TYPE"));
|
type = FileStorageType.valueOf(rs.getString("TYPE"));
|
||||||
description = rs.getString("DESCRIPTION");
|
description = rs.getString("DESCRIPTION");
|
||||||
|
createDateTime = rs.getTimestamp("CREATE_DATE").toLocalDateTime();
|
||||||
var base = getStorageBase(new FileStorageBaseId(baseId));
|
var base = getStorageBase(new FileStorageBaseId(baseId));
|
||||||
|
|
||||||
ret.add(new FileStorage(
|
ret.add(new FileStorage(
|
||||||
new FileStorageId(storageId),
|
new FileStorageId(storageId),
|
||||||
base,
|
base,
|
||||||
type,
|
type,
|
||||||
|
createDateTime,
|
||||||
path,
|
path,
|
||||||
description
|
description
|
||||||
));
|
));
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package nu.marginalia.db.storage.model;
|
package nu.marginalia.db.storage.model;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a file storage area
|
* Represents a file storage area
|
||||||
@ -15,10 +17,38 @@ public record FileStorage(
|
|||||||
FileStorageId id,
|
FileStorageId id,
|
||||||
FileStorageBase base,
|
FileStorageBase base,
|
||||||
FileStorageType type,
|
FileStorageType type,
|
||||||
|
LocalDateTime createDateTime,
|
||||||
String path,
|
String path,
|
||||||
String description)
|
String description)
|
||||||
{
|
{
|
||||||
public Path asPath() {
|
public Path asPath() {
|
||||||
return Path.of(path);
|
return Path.of(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
FileStorage that = (FileStorage) o;
|
||||||
|
|
||||||
|
// Exclude timestamp as it may different due to how the objects
|
||||||
|
// are constructed
|
||||||
|
|
||||||
|
if (!Objects.equals(id, that.id)) return false;
|
||||||
|
if (!Objects.equals(base, that.base)) return false;
|
||||||
|
if (type != that.type) return false;
|
||||||
|
if (!Objects.equals(path, that.path)) return false;
|
||||||
|
return Objects.equals(description, that.description);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = id != null ? id.hashCode() : 0;
|
||||||
|
result = 31 * result + (base != null ? base.hashCode() : 0);
|
||||||
|
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||||
|
result = 31 * result + (path != null ? path.hashCode() : 0);
|
||||||
|
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class LoaderIndexJournalWriterTest {
|
|||||||
tempDir = Files.createTempDirectory(getClass().getSimpleName());
|
tempDir = Files.createTempDirectory(getClass().getSimpleName());
|
||||||
FileStorageService storageService = Mockito.mock(FileStorageService.class);
|
FileStorageService storageService = Mockito.mock(FileStorageService.class);
|
||||||
Mockito.when(storageService.getStorageByType(FileStorageType.INDEX_STAGING)).
|
Mockito.when(storageService.getStorageByType(FileStorageType.INDEX_STAGING)).
|
||||||
thenReturn(new FileStorage(null, null, null, tempDir.toString(),
|
thenReturn(new FileStorage(null, null, null, null, tempDir.toString(),
|
||||||
"test"));
|
"test"));
|
||||||
writer = new LoaderIndexJournalWriter(storageService);
|
writer = new LoaderIndexJournalWriter(storageService);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,10 @@ import nu.marginalia.db.storage.model.FileStorage;
|
|||||||
import nu.marginalia.db.storage.model.FileStorageBaseType;
|
import nu.marginalia.db.storage.model.FileStorageBaseType;
|
||||||
import nu.marginalia.db.storage.model.FileStorageType;
|
import nu.marginalia.db.storage.model.FileStorageType;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public record FileStorageWithActions(FileStorage storage) {
|
public record FileStorageWithActions(FileStorage storage) {
|
||||||
public boolean isCrawlable() {
|
public boolean isCrawlable() {
|
||||||
return storage.type() == FileStorageType.CRAWL_SPEC;
|
return storage.type() == FileStorageType.CRAWL_SPEC;
|
||||||
@ -27,4 +31,27 @@ public record FileStorageWithActions(FileStorage storage) {
|
|||||||
return baseType == FileStorageBaseType.SLOW
|
return baseType == FileStorageBaseType.SLOW
|
||||||
|| baseType == FileStorageBaseType.BACKUP;
|
|| baseType == FileStorageBaseType.BACKUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRelPath() {
|
||||||
|
Path basePath = storage.base().asPath();
|
||||||
|
Path storagePath = storage.asPath();
|
||||||
|
|
||||||
|
return basePath.relativize(storagePath)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimestampFull() {
|
||||||
|
return storage.createDateTime().format(DateTimeFormatter.ISO_DATE_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimestamp() {
|
||||||
|
var ctime = storage.createDateTime();
|
||||||
|
if (ctime.isAfter(LocalDate.now().atStartOfDay())) {
|
||||||
|
return storage.createDateTime().format(DateTimeFormatter.ISO_TIME);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return storage.createDateTime().format(DateTimeFormatter.ISO_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
<table>
|
<table class="table-rh-2">
|
||||||
{{#each storage}}
|
{{#each storage}}
|
||||||
<tr>
|
<tr>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Path</th>
|
<th>Path</th>
|
||||||
<th>Permit Temp</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{base.type}}</td>
|
<td>{{base.type}}</td>
|
||||||
<td>{{base.name}}</td>
|
<td>{{base.name}}</td>
|
||||||
<td>{{base.path}}</td>
|
<td>{{base.path}}</td>
|
||||||
<td>{{base.permitTemp}}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th>Path</th>
|
<th>Path</th>
|
||||||
<th>Description</th>
|
<tr>
|
||||||
|
<th>Created</th>
|
||||||
|
<th colspan="2">Description</th>
|
||||||
</tr>
|
</tr>
|
||||||
{{#each storage}}
|
{{#each storage}}
|
||||||
<tr>
|
<tr>
|
||||||
@ -24,8 +24,11 @@
|
|||||||
<a href="/storage/{{storage.id}}">Info</a>
|
<a href="/storage/{{storage.id}}">Info</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{storage.type}}</td>
|
<td>{{storage.type}}</td>
|
||||||
<td>{{storage.path}}</td>
|
<td>{{relPath}}</td>
|
||||||
<td>{{storage.description}}</td>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td title="{{timestampFull}}">{{timestamp}}</td>
|
||||||
|
<td colspan="2">{{storage.description}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -52,9 +53,9 @@ public class IndexQueryServiceIntegrationTestModule extends AbstractModule {
|
|||||||
try {
|
try {
|
||||||
var fileStorageServiceMock = Mockito.mock(FileStorageService.class);
|
var fileStorageServiceMock = Mockito.mock(FileStorageService.class);
|
||||||
|
|
||||||
when(fileStorageServiceMock.getStorageByType(FileStorageType.SEARCH_SETS)).thenReturn(new FileStorage(null, null, null, fastDir.toString(), null));
|
when(fileStorageServiceMock.getStorageByType(FileStorageType.SEARCH_SETS)).thenReturn(new FileStorage(null, null, null, LocalDateTime.now(), fastDir.toString(), null));
|
||||||
when(fileStorageServiceMock.getStorageByType(FileStorageType.INDEX_LIVE)).thenReturn(new FileStorage(null, null, null, fastDir.toString(), null));
|
when(fileStorageServiceMock.getStorageByType(FileStorageType.INDEX_LIVE)).thenReturn(new FileStorage(null, null, null, LocalDateTime.now(), fastDir.toString(), null));
|
||||||
when(fileStorageServiceMock.getStorageByType(FileStorageType.INDEX_STAGING)).thenReturn(new FileStorage(null, null, null, slowDir.toString(), null));
|
when(fileStorageServiceMock.getStorageByType(FileStorageType.INDEX_STAGING)).thenReturn(new FileStorage(null, null, null, LocalDateTime.now(), slowDir.toString(), null));
|
||||||
|
|
||||||
bind(FileStorageService.class).toInstance(fileStorageServiceMock);
|
bind(FileStorageService.class).toInstance(fileStorageServiceMock);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user