Skip to content

Commit

Permalink
Merge pull request #152 from amosproj/106-replace-uuid-with-save-set-…
Browse files Browse the repository at this point in the history
…name

106 replace UUID with save set name
  • Loading branch information
engelharddirk authored Dec 10, 2024
2 parents 56dd3ba + 4f042e1 commit 083159f
Show file tree
Hide file tree
Showing 29 changed files with 427 additions and 229 deletions.
4 changes: 2 additions & 2 deletions apps/analyzer/metadata_analyzer/analyzer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime


class Analyzer:

def init(database, backend, simple_analyzer, simple_rule_based_analyzer):
Analyzer.database = database
Analyzer.backend = backend
Expand Down Expand Up @@ -30,6 +29,7 @@ def _convert_result(result):
}[result.fdi_type]
return {
"id": result.uuid,
"saveset": result.saveset,
"sizeMB": result.data_size / 1_000_000,
"creationDate": result.start_time.isoformat(),
"type": backup_type,
Expand Down
8 changes: 4 additions & 4 deletions apps/analyzer/metadata_analyzer/creation_date_alert.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class CreationDateAlert:
def __init__(self, result, reference_date):
self.uuid = result.uuid
self.backup_uuid = result.uuid
self.date = result.start_time
self.reference_date = reference_date

def as_json(self):
return {
"backupId": self.uuid,
"date": self.date.isoformat(),
"referenceDate": self.reference_date.isoformat(),
"backupId": self.backup_uuid,
"date": self.date.isoformat(),
"referenceDate": self.reference_date.isoformat()
}
1 change: 0 additions & 1 deletion apps/analyzer/metadata_analyzer/database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pg8000.dbapi
from sqlalchemy import create_engine, select
from sqlalchemy.orm import Session
from metadata_analyzer.models import BackupData, Result, Tasks, DataStore
Expand Down
1 change: 1 addition & 0 deletions apps/analyzer/metadata_analyzer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class BackupData(Base):
__tablename__ = "BackupData"

id: Mapped[str] = mapped_column(primary_key=True)
saveset: Mapped[str]
sizeMB: Mapped[int]
creationDate: Mapped[datetime]
bio: Mapped[str]
Expand Down
434 changes: 271 additions & 163 deletions apps/analyzer/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/analyzer/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ readme = 'README.md'
python = ">=3.9,<3.12"
flask = "^3.0.3"
python-dotenv = "^1.0.1"
sqlalchemy = "^2.0.36"
sqlalchemy = {extras = ["mypy"], version = "^2.0.36"}
pg8000 = "^1.31.2"
requests = "^2.32.3"
flasgger = "^0.9.7.1"
Expand Down
23 changes: 14 additions & 9 deletions apps/analyzer/tests/test_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from tests.mock_database import MockDatabase


def _create_mock_result(task, uuid, fdi_type, data_size, start_time, task_uuid=None, is_backup=1):
def _create_mock_result(task, uuid, saveset, fdi_type, data_size, start_time, task_uuid=None, is_backup=1):
mock_result = Result()
mock_result.task = task
mock_result.saveset = saveset
mock_result.uuid = uuid
mock_result.fdi_type = fdi_type
mock_result.data_size = data_size
Expand All @@ -26,10 +27,10 @@ def _create_mock_task(uuid, task):


def test_update_data_all_types():
mock_result1 = _create_mock_result("foo", "1", "F", 100_000_000, datetime.fromisoformat("2000-01-01"))
mock_result2 = _create_mock_result("foo", "2", "D", 150_000_000, datetime.fromisoformat("2000-01-02"))
mock_result3 = _create_mock_result("foo", "3", "I", 200_000_000, datetime.fromisoformat("2000-01-03"))
mock_result4 = _create_mock_result("foo", "4", "C", 250_000_000, datetime.fromisoformat("2000-01-04"), '123')
mock_result1 = _create_mock_result("foo", "1", "saveset1", "F", 100_000_000, datetime.fromisoformat("2000-01-01"))
mock_result2 = _create_mock_result("foo", "2", "saveset2", "D", 150_000_000, datetime.fromisoformat("2000-01-02"))
mock_result3 = _create_mock_result("foo", "3", "saveset3", "I", 200_000_000, datetime.fromisoformat("2000-01-03"))
mock_result4 = _create_mock_result("foo", "4", "saveset4", "C", 250_000_000, datetime.fromisoformat("2000-01-04"), '123')
mock_results = [mock_result1, mock_result2, mock_result3, mock_result4]

mock_task1 = _create_mock_task("1", "task1")
Expand All @@ -46,25 +47,29 @@ def test_update_data_all_types():
"sizeMB": mock_result1.data_size / 1_000_000,
"creationDate": mock_result1.start_time.isoformat(),
"type": "FULL",
"taskId": None
"taskId": None,
"saveset": mock_result1.saveset
}, {
"id": mock_result2.uuid,
"sizeMB": mock_result2.data_size / 1_000_000,
"creationDate": mock_result2.start_time.isoformat(),
"type": "DIFFERENTIAL",
"taskId": None
"taskId": None,
"saveset": mock_result2.saveset
}, {
"id": mock_result3.uuid,
"sizeMB": mock_result3.data_size / 1_000_000,
"creationDate": mock_result3.start_time.isoformat(),
"type": "INCREMENTAL",
"taskId": None
"taskId": None,
"saveset": mock_result3.saveset
}, {
"id": mock_result4.uuid,
"sizeMB": mock_result4.data_size / 1_000_000,
"creationDate": mock_result4.start_time.isoformat(),
"type": "COPY",
"taskId": '123'
"taskId": '123',
"saveset": mock_result4.saveset
}]

assert backend.tasks == [
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/app/alerting/alerting.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const mockedBackupDataEntity: BackupDataEntity = {
sizeMB: 100,
type: BackupType.FULL,
creationDate: new Date(),
saveset: 'saveset1',
};

const mockedSizeAlertTypeEntity: AlertTypeEntity = {
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/app/alerting/alerting.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const mockedBackupDataEntity: BackupDataEntity = {
sizeMB: 100,
type: BackupType.FULL,
creationDate: new Date(),
saveset: 'saveset1',
};

const mockedSizeAlertTypeEntity: AlertTypeEntity = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';

export class CreateCreationDateAlertDto {

@ApiProperty({
description: 'Id of the belonging Backup',
description: 'Uuid of the Backup',
required: true,
})
backupId!: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';

export class CreateSizeAlertDto {

@ApiProperty({
description: 'Id of the belonging Backup',
description: 'Uuid of the Backup',
required: true,
})
backupId!: string;
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/app/backupData/backupData.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TaskEntity } from '../tasks/entity/task.entity';
const mockBackupDataEntity: BackupDataEntity = {
id: '123e4567-e89b-12d3-a456-426614174062',
sizeMB: 100,
saveset: 'backup-123',
type: BackupType.FULL,
creationDate: new Date('2023-12-30 00:00:00.000000'),
};
Expand Down Expand Up @@ -60,6 +61,7 @@ describe('BackupDataController (e2e)', () => {
it('/backupData (POST) should create new backup data entry', async () => {
const createBackupDataDto: CreateBackupDataDto = {
id: '1',
saveset: 'backup-1',
sizeMB: 100,
creationDate: new Date(),
};
Expand All @@ -71,6 +73,7 @@ describe('BackupDataController (e2e)', () => {

expect(response.body).toEqual({
id: createBackupDataDto.id,
saveset: createBackupDataDto.saveset,
sizeMB: createBackupDataDto.sizeMB,
creationDate: createBackupDataDto.creationDate.toISOString(),
});
Expand Down
9 changes: 5 additions & 4 deletions apps/backend/src/app/backupData/backupData.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { TasksService } from '../tasks/tasks.service';
const mockBackupDataEntity: BackupDataEntity = {
id: '123e4567-e89b-12d3-a456-426614174062',
sizeMB: 100,
saveset: 'backup',
type: BackupType.FULL,
creationDate: new Date('2023-12-30 00:00:00.000000'),
};
Expand Down Expand Up @@ -201,8 +202,8 @@ describe('BackupDataService', () => {
describe('createBatched', () => {
it('should create new backup data entities batched', async () => {
const createBackupDataDtos: CreateBackupDataDto[] = [
{ id: '1', sizeMB: 100, creationDate: new Date() },
{ id: '2', sizeMB: 200, creationDate: new Date() },
{ id: '1', sizeMB: 100, creationDate: new Date(), saveset: 'backup' },
{ id: '2', sizeMB: 200, creationDate: new Date(), saveset: 'backup' },
];

await service.createBatched(createBackupDataDtos);
Expand All @@ -224,8 +225,8 @@ describe('BackupDataService', () => {
describe('createBatched', () => {
it('should create new backup data entities batched', async () => {
const createBackupDataDtos: CreateBackupDataDto[] = [
{ id: '1', sizeMB: 100, creationDate: new Date() },
{ id: '2', sizeMB: 200, creationDate: new Date() },
{ id: '1', sizeMB: 100, creationDate: new Date(), saveset: 'backup' },
{ id: '2', sizeMB: 200, creationDate: new Date(), saveset: 'backup' },
];

await service.createBatched(createBackupDataDtos);
Expand Down
5 changes: 5 additions & 0 deletions apps/backend/src/app/backupData/backupData.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ export class BackupDataService extends PaginationService {
};
}

//Saveset search
if (backupDataFilterDto.saveset) {
where.saveset = ILike(`%${backupDataFilterDto.saveset}%`);
}

where.type = BackupType.FULL;

return where;
Expand Down
7 changes: 7 additions & 0 deletions apps/backend/src/app/backupData/dto/backupDataFilter.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ export class BackupDataFilterDto {
})
@IsOptional()
taskName?: string;

@ApiProperty({
description: 'saveset',
required: false,
})
@IsOptional()
saveset?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export enum BackupDataOrderByOptions {
ID = 'id',
SIZE = 'sizeMB',
BACKUP_DATE = 'creationDate',
TASK_NAME = 'taskName'
TASK_NAME = 'taskName',
SAVESET = 'saveset',
}

export class BackupDataOrderOptionsDto {
Expand Down
6 changes: 6 additions & 0 deletions apps/backend/src/app/backupData/dto/createBackupData.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export class CreateBackupDataDto {
@IsUUID()
id!: string;

@ApiProperty({
description: 'saveset name of the backup',
required: true,
})
saveset!: string;

@ApiProperty({
description: 'Size of Backup in MB',
nullable: false,
Expand Down
7 changes: 7 additions & 0 deletions apps/backend/src/app/backupData/entity/backupData.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export class BackupDataEntity {
@PrimaryColumn()
id!: string;

@ApiProperty({
description: 'saveset name of the backup',
required: true,
})
@Column()
saveset!: string;

@ApiProperty({
description: 'Size of Backup in MB',
nullable: false,
Expand Down
2 changes: 2 additions & 0 deletions apps/backend/src/app/db-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { TaskEntity } from './tasks/entity/task.entity';
import { Tasks1733397652480 } from './migrations/1733397652480-Tasks';
import { MailReceiverEntity } from './utils/mail/entity/MailReceiver.entity';
import { MailReceiver1733580333590 } from './migrations/1733580333590-MailReceiver';
import { AddSaveset1733760846109 } from './migrations/1733760846109-AddSaveset';
import { StorageFillAlert1733739256545 } from './migrations/1733739256545-StorageFillAlert';
import { StorageFillAlertChangedColumns1733765217660 } from './migrations/1733765217660-StorageFillAlertChangedColumns';
import { StorageFillAlertChangedColumnsDecimal1733768959317 } from './migrations/1733768959317-StorageFillAlertChangedColumnsDecimal';
Expand Down Expand Up @@ -70,6 +71,7 @@ export class DbConfigService implements TypeOrmOptionsFactory {
CreationDateAlert1733070019992,
Tasks1733397652480,
MailReceiver1733580333590,
AddSaveset1733760846109,
StorageFillAlert1733739256545,
StorageFillAlertChangedColumns1733765217660,
StorageFillAlertChangedColumnsDecimal1733768959317,
Expand Down
14 changes: 14 additions & 0 deletions apps/backend/src/app/migrations/1733760846109-AddSaveset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AddSaveset1733760846109 implements MigrationInterface {
name = 'AddSaveset1733760846109'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "BackupData" ADD "saveset" character varying NOT NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "BackupData" DROP COLUMN "saveset"`);
}

}
1 change: 1 addition & 0 deletions apps/backend/src/app/utils/mail/mail.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe('MailService', () => {
sizeMB: 100,
type: BackupType.FULL,
creationDate: new Date(),
saveset: 'saveset1',
},
};

Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/app/alert/component/alert.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
</div>
<clr-tooltip-content [clrPosition]="'top-right'" [clrSize]="'lg'">
<div *ngIf="alert.backup">
<b>Backup ID:</b>
{{ alert.backup.id }}
<b>Backup Saveset:</b>
{{ alert.backup.saveset }}
<br />
<b>Creation Date:</b>
{{ formatDate(alert.backup.creationDate) }}
Expand Down
Loading

0 comments on commit 083159f

Please sign in to comment.