Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@
nzTitle="Hub"
nzIcon="usergroup-add"
nzOpen="true">
<texera-hub
[isLogin]="isLogin"
[sidebarTabs]="sidebarTabs">
</texera-hub>
<texera-hub [sidebarTabs]="sidebarTabs"> </texera-hub>
</li>

<li
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { firstValueFrom } from "rxjs";
import { NgxFileDropEntry, NgxFileDropModule } from "ngx-file-drop";
import { NzModalRef, NzModalService } from "ng-zorro-antd/modal";
import { FileUploadItem } from "../../../type/dashboard-file.interface";
import { DatasetFileNode } from "../../../../common/type/datasetVersionFileTree";
import { NotificationService } from "../../../../common/service/notification/notification.service";
import { AdminSettingsService } from "../../../service/admin/settings/admin-settings.service";
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
Expand Down Expand Up @@ -74,8 +73,6 @@ export class FilesUploaderComponent implements OnInit {

@Output() uploadedFiles = new EventEmitter<FileUploadItem[]>();

newUploadFileTreeNodes: DatasetFileNode[] = [];

fileUploadingFinished: boolean = false;
fileUploadBannerType: "error" | "success" | "info" | "warning" = "success";
fileUploadBannerMessage: string = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { NzModalService } from "ng-zorro-antd/modal";
import { NzTooltipDirective } from "ng-zorro-antd/tooltip";
import { MarkdownService } from "ngx-markdown";
import { DatasetDetailComponent } from "./dataset-detail.component";
import { DatasetService, MultipartUploadProgress } from "../../../../service/user/dataset/dataset.service";
import { DatasetService } from "../../../../service/user/dataset/dataset.service";
import { VersionUploaderComponent } from "../../version-uploader/version-uploader.component";
import { NotificationService } from "../../../../../common/service/notification/notification.service";
import { DownloadService } from "../../../../service/user/download/download.service";
Expand Down Expand Up @@ -78,7 +78,6 @@ describe("DatasetDetailComponent rendered explorer", () => {
})
),
retrieveDatasetVersionFileTree: vi.fn(() => of({ fileNodes: [], size: 1024 })),
getDatasetDiff: vi.fn(() => of([])),
createDatasetVersion: vi.fn(() => of({})),
deleteDatasetFile: vi.fn(() => of({})),
},
Expand Down Expand Up @@ -438,9 +437,6 @@ describe("DatasetDetailComponent behavior", () => {
updateDatasetName: vi.fn(() => of({})),
deleteDatasets: vi.fn(() => of({})),
deleteDatasetFile: vi.fn(() => of({})),
getDatasetDiff: vi.fn(() => of([])),
multipartUpload: vi.fn(() => of()),
finalizeMultipartUpload: vi.fn(() => of({})),
};
notificationServiceStub = { success: vi.fn(), error: vi.fn(), info: vi.fn() };
modalServiceStub = { create: vi.fn() };
Expand Down Expand Up @@ -2083,7 +2079,6 @@ describe("DatasetDetailComponent rendered template", () => {
// The real file renderer is rendered here, and it fetches whatever file is on screen.
retrieveDatasetVersionSingleFile: vi.fn(() => of(new Blob(["a,b"], { type: "text/csv" }))),
getDatasetCoverUrl: vi.fn(() => of({ url: "http://cover" })),
getDatasetDiff: vi.fn(() => of([])),
createDatasetVersion: vi.fn(() => of(aVersion())),
updateDatasetPublicity: vi.fn(() => of({})),
updateDatasetDownloadable: vi.fn(() => of({})),
Expand All @@ -2093,10 +2088,6 @@ describe("DatasetDetailComponent rendered template", () => {
updateDatasetName: vi.fn(() => of({})),
deleteDatasets: vi.fn(() => of({})),
deleteDatasetFile: vi.fn(() => of({})),
// Never completes, so an upload started from the template stays in flight
// and its row keeps rendering the "uploading" arm.
multipartUpload: vi.fn(() => new Subject<MultipartUploadProgress>().asObservable()),
finalizeMultipartUpload: vi.fn(() => of({})),
};
downloadService = {
downloadDatasetVersion: vi.fn(() => of(new Blob())),
Expand Down
392 changes: 25 additions & 367 deletions frontend/src/app/dashboard/service/user/dataset/dataset.service.spec.ts

Large diffs are not rendered by default.

121 changes: 16 additions & 105 deletions frontend/src/app/dashboard/service/user/dataset/dataset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,22 @@
*/

import { Injectable } from "@angular/core";
import { HttpClient, HttpErrorResponse, HttpParams } from "@angular/common/http";
import { HttpClient, HttpParams } from "@angular/common/http";
import { map, switchMap } from "rxjs/operators";
import { Contributor, Dataset, DatasetVersion } from "../../../../common/type/dataset";
import { AppSettings } from "../../../../common/app-setting";
import { EMPTY, Observable } from "rxjs";
import { Observable } from "rxjs";
import { DashboardDataset } from "../../../type/dashboard-dataset.interface";
import { DatasetFileNode } from "../../../../common/type/datasetVersionFileTree";
import { DatasetStagedObject } from "../../../../common/type/dataset-staged-object";
import { GuiConfigService } from "../../../../common/service/gui-config.service";
import { MultipartUploadProgress, MultipartUploadService } from "../file-resource/multipart-upload.service";
import { StagedFileService } from "../file-resource/staged-file.service";
import { DATASET_FILE_RESOURCE_ENDPOINT } from "../file-resource/file-resource-endpoint";

export const DATASET_BASE_URL = "dataset";
export const DATASET_CREATE_URL = DATASET_BASE_URL + "/create";
export const DATASET_UPDATE_BASE_URL = DATASET_BASE_URL + "/update";
export const DATASET_UPDATE_NAME_URL = DATASET_UPDATE_BASE_URL + "/name";
export const DATASET_UPDATE_DESCRIPTION_URL = DATASET_UPDATE_BASE_URL + "/description";
export const DATASET_UPDATE_PUBLICITY_URL = "update/publicity";
export const DATASET_UPDATE_DOWNLOADABLE_URL = "update/downloadable";
export const DATASET_LIST_URL = DATASET_BASE_URL + "/list";
export const DATASET_SEARCH_URL = DATASET_BASE_URL + "/search";
export const DATASET_DELETE_URL = DATASET_BASE_URL + "/delete";
const DATASET_BASE_URL = "dataset";

export const DATASET_VERSION_BASE_URL = "version";
export const DATASET_VERSION_RETRIEVE_LIST_URL = DATASET_VERSION_BASE_URL + "/list";
export const DATASET_VERSION_LATEST_URL = DATASET_VERSION_BASE_URL + "/latest";
const DATASET_VERSION_BASE_URL = "version";
export const DEFAULT_DATASET_NAME = "Untitled-dataset";

export const DATASET_NAME_MAX_LENGTH = 128;
const DATASET_NAME_MAX_LENGTH = 128;
const DATASET_NAME_PATTERN = /^[A-Za-z0-9_-]+$/;

export function validateDatasetName(name: string): string | null {
Expand All @@ -68,26 +54,19 @@ function normalizeContributor(contributor: Contributor): Contributor {
};
}

export const DATASET_PUBLIC_VERSION_BASE_URL = "publicVersion";
export const DATASET_PUBLIC_VERSION_RETRIEVE_LIST_URL = DATASET_PUBLIC_VERSION_BASE_URL + "/list";
export const DATASET_GET_OWNERS_URL = DATASET_BASE_URL + "/user-dataset-owners";

// Re-exported so existing importers keep resolving it from here.
export type { MultipartUploadProgress };
const DATASET_PUBLIC_VERSION_BASE_URL = "publicVersion";

@Injectable({
providedIn: "root",
})
export class DatasetService {
constructor(
private http: HttpClient,
private config: GuiConfigService,
private multipartUploadService: MultipartUploadService,
private stagedFileService: StagedFileService
) {}

public createDataset(dataset: Dataset, contributors: Contributor[] = []): Observable<DashboardDataset> {
return this.http.post<DashboardDataset>(`${AppSettings.getApiEndpoint()}/${DATASET_CREATE_URL}`, {
return this.http.post<DashboardDataset>(`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/create`, {
datasetName: dataset.name,
datasetDescription: dataset.description,
isDatasetPublic: dataset.isPublic,
Expand Down Expand Up @@ -140,7 +119,7 @@ export class DatasetService {
}

public retrieveAccessibleDatasets(): Observable<DashboardDataset[]> {
return this.http.get<DashboardDataset[]>(`${AppSettings.getApiEndpoint()}/${DATASET_LIST_URL}`);
return this.http.get<DashboardDataset[]>(`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/list`);
}

public createDatasetVersion(did: number, newVersion: string): Observable<DatasetVersion> {
Expand All @@ -159,63 +138,6 @@ export class DatasetService {
);
}

/**
* Multipart upload for large files. The engine lives in MultipartUploadService; this keeps the
* dataset-facing signature so existing callers are untouched.
*/
public multipartUpload(
ownerEmail: string,
datasetName: string,
filePath: string,
file: File,
partSize: number,
concurrencyLimit: number,
restart: boolean
): Observable<MultipartUploadProgress> {
return this.multipartUploadService.multipartUpload(
DATASET_FILE_RESOURCE_ENDPOINT,
ownerEmail,
datasetName,
filePath,
file,
partSize,
concurrencyLimit,
restart
);
}

public listMultipartUploads(ownerEmail: string, datasetName: string): Observable<string[]> {
return this.multipartUploadService.listMultipartUploads(DATASET_FILE_RESOURCE_ENDPOINT, ownerEmail, datasetName);
}

public findExistingUploadFiles(did: number, files: { path: string; sizeBytes: number }[]): Observable<string[]> {
return this.multipartUploadService.findExistingUploadFiles(DATASET_FILE_RESOURCE_ENDPOINT, did, files);
}

public finalizeMultipartUpload(
ownerEmail: string,
datasetName: string,
filePath: string,
isAbort: boolean
): Observable<Response> {
return this.multipartUploadService.finalizeMultipartUpload(
DATASET_FILE_RESOURCE_ENDPOINT,
ownerEmail,
datasetName,
filePath,
isAbort
);
}

/**
* Resets a dataset file difference in LakeFS.
* @param did Dataset ID
* @param filePath File path to reset
*/
public resetDatasetFileDiff(did: number, filePath: string): Observable<Response> {
return this.stagedFileService.resetFileDiff(DATASET_FILE_RESOURCE_ENDPOINT, did, filePath);
}

/**
* Deletes a dataset file from LakeFS.
* @param did Dataset ID
Expand All @@ -225,23 +147,15 @@ export class DatasetService {
return this.stagedFileService.deleteFile(DATASET_FILE_RESOURCE_ENDPOINT, did, filePath);
}

/**
* Retrieves the list of uncommitted dataset changes (diffs).
* @param did Dataset ID
*/
public getDatasetDiff(did: number): Observable<DatasetStagedObject[]> {
return this.stagedFileService.getDiff(DATASET_FILE_RESOURCE_ENDPOINT, did);
}

/**
* retrieve a list of versions of a dataset. The list is sorted so that the latest versions are at front.
* @param did
* @param isLogin
*/
public retrieveDatasetVersionList(did: number, isLogin: boolean = true): Observable<DatasetVersion[]> {
const apiEndPont = isLogin
? `${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/${did}/${DATASET_VERSION_RETRIEVE_LIST_URL}`
: `${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/${did}/${DATASET_PUBLIC_VERSION_RETRIEVE_LIST_URL}`;
? `${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/${did}/${DATASET_VERSION_BASE_URL}/list`
: `${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/${did}/${DATASET_PUBLIC_VERSION_BASE_URL}/list`;
return this.http.get<DatasetVersion[]>(apiEndPont);
}

Expand All @@ -254,7 +168,7 @@ export class DatasetService {
.get<{
datasetVersion: DatasetVersion;
fileNodes: DatasetFileNode[];
}>(`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/${did}/${DATASET_VERSION_LATEST_URL}`)
}>(`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/${did}/${DATASET_VERSION_BASE_URL}/latest`)
.pipe(
map(response => {
response.datasetVersion.fileNodes = response.fileNodes;
Expand Down Expand Up @@ -285,35 +199,32 @@ export class DatasetService {
}

public updateDatasetName(did: number, name: string): Observable<Response> {
return this.http.post<Response>(`${AppSettings.getApiEndpoint()}/${DATASET_UPDATE_NAME_URL}`, {
return this.http.post<Response>(`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/update/name`, {
did: did,
name: name,
});
}

public updateDatasetDescription(did: number, description: string): Observable<Response> {
return this.http.post<Response>(`${AppSettings.getApiEndpoint()}/${DATASET_UPDATE_DESCRIPTION_URL}`, {
return this.http.post<Response>(`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/update/description`, {
did: did,
description: description,
});
}

public updateDatasetPublicity(did: number): Observable<Response> {
return this.http.post<Response>(
`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/${did}/${DATASET_UPDATE_PUBLICITY_URL}`,
{}
);
return this.http.post<Response>(`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/${did}/update/publicity`, {});
}

public updateDatasetDownloadable(did: number): Observable<Response> {
return this.http.post<Response>(
`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/${did}/${DATASET_UPDATE_DOWNLOADABLE_URL}`,
`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/${did}/update/downloadable`,
{}
);
}

public retrieveOwners(): Observable<string[]> {
return this.http.get<string[]>(`${AppSettings.getApiEndpoint()}/${DATASET_GET_OWNERS_URL}`);
return this.http.get<string[]>(`${AppSettings.getApiEndpoint()}/${DATASET_BASE_URL}/user-dataset-owners`);
}

public updateDatasetCoverImage(did: number, coverImage: string): Observable<Response> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,77 @@ describe("MultipartUploadService", () => {
await done;
});

// ─── progress statistics ──────────────────────────────────────────────────

it("smooths, throttles and shifts the progress statistics across events", async () => {
let now = 1_000_000;
vi.spyOn(Date, "now").mockImplementation(() => now);
const { done, emissions } = startUpload("big.bin", { bytes: new Uint8Array(100), chunkSize: 100 });
flushInit();
const xhr = FakeXMLHttpRequest.instances[0];

xhr.emitProgress(5, false); // non-lengthComputable -> ignored
xhr.emitProgress(10); // first update: startTime set, elapsed 0
xhr.emitProgress(20); // same timestamp -> throttled (returns cached stats)
now = 1_002_000;
xhr.emitProgress(30); // elapsed>0 so speed/avg become positive
now = 1_003_000;
xhr.emitProgress(90); // large ETA drop -> smoothing clamps the change
now = 1_004_000;
xhr.emitProgress(99); // >95% complete -> ETA capped to 10s
now = 1_005_000;
xhr.emitProgress(99);
now = 1_006_000;
xhr.emitProgress(99); // 6th sample -> speedSamples window shifts
xhr.respond(200);
http.expectOne(isType(DATASET_FILE_RESOURCE_ENDPOINT, "finish")).flush({});
await done;

const uploading = emissions.filter(e => e.status === "uploading");
expect(uploading.length).toBeGreaterThan(0);
expect(uploading.every(e => e.percentage <= 99)).toBe(true);
// Once real elapsed time exists the smoothed speed becomes positive.
expect(uploading.some(e => (e.uploadSpeed ?? 0) > 0)).toBe(true);
// ETA is always reported as a non-negative integer number of seconds.
expect(
uploading.every(e => Number.isInteger(e.estimatedTimeRemaining) && (e.estimatedTimeRemaining ?? -1) >= 0)
).toBe(true);
expect(emissions.at(-1)).toMatchObject({
status: "finished",
percentage: 100,
uploadSpeed: 0,
estimatedTimeRemaining: 0,
});
});

it("clamps a sharply rising ETA to the +30% smoothing bound", async () => {
let now = 1_000_000;
vi.spyOn(Date, "now").mockImplementation(() => now);
const { done, emissions } = startUpload("rise.bin", { bytes: new Uint8Array(100), chunkSize: 100 });
flushInit();
const xhr = FakeXMLHttpRequest.instances[0];

// Stalling at 10 of 100 bytes keeps the ETAs far enough apart that rounding cannot hide the clamp.
xhr.emitProgress(10); // first update: elapsed 0 -> ETA 0
now = 1_001_000;
xhr.emitProgress(10); // 10 B/s sample -> ETA 18s, sets lastETA
now = 1_100_000;
xhr.emitProgress(10); // huge elapsed collapses avg speed -> raw ETA ~27s, clamped to +30%
xhr.respond(200);
http.expectOne(isType(DATASET_FILE_RESOURCE_ENDPOINT, "finish")).flush({});
await done;

const uploading = emissions.filter(e => e.status === "uploading");
expect(uploading.length).toBeGreaterThanOrEqual(3);

const etaBefore = uploading[1].estimatedTimeRemaining ?? 0;
const etaAfter = uploading[2].estimatedTimeRemaining ?? 0;

expect(etaBefore).toBe(18);
expect(etaAfter).toBe(Math.round(etaBefore * 1.3));
expect(emissions.at(-1)).toMatchObject({ status: "finished", percentage: 100 });
});

// ─── failure and teardown ─────────────────────────────────────────────────

it("fails the upload when a part returns a non-2xx status", async () => {
Expand All @@ -231,6 +302,19 @@ describe("MultipartUploadService", () => {
expect(await outcome).toBeInstanceOf(Error);
});

it("reports a 0% failure when the finish call errors for an empty file", async () => {
// An empty file has no parts, so init leads straight to finish.
const { done: outcome, emissions } = startUpload("empty.bin", { bytes: "", captureError: true });

flushInit({ missingParts: [], completedPartsCount: 0 });
expect(FakeXMLHttpRequest.instances.length).toBe(0);
http.expectOne(isType(DATASET_FILE_RESOURCE_ENDPOINT, "finish")).error(new ProgressEvent("error"));

expect(await outcome).not.toBeNull();
expect(emissions[0]).toMatchObject({ status: "initializing", percentage: 0 });
expect(emissions.at(-1)).toMatchObject({ status: "failed", percentage: 0 });
});

it("aborts the in-flight part request when the caller unsubscribes", () => {
const { subscription } = startUpload("t.bin");

Expand Down
Loading
Loading