You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@texera.apache.org by gi...@apache.org on 2026/08/26 20:23:05 UTC

(texera) branch main updated: feat(frontend): add the per-user warehouse API client (#7820)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git


The following commit(s) were added to refs/heads/main by this push:
     new b6c434e56c feat(frontend): add the per-user warehouse API client (#7820)
b6c434e56c is described below

commit b6c434e56cfd97446f176f42cadff4343f53eaa4
Author: Meng Wang <me...@uci.edu>
AuthorDate: Wed Aug 26 20:17:27 2026 +0000

    feat(frontend): add the per-user warehouse API client (#7820)
    
    ### What changes were proposed in this PR?
    
    The client half of the warehouse dashboard tab: the HTTP client for the
    warehouse endpoints and the actions service that owns create and delete
    on top of it. No UI renders any of this yet — it is the first of three
    parts of #6933, split so each lands as one reviewable change.
    
    - **`DashboardWarehouse` / `WarehouseStatus`** — the wire types,
    mirroring what `WarehouseResource` returns: the display name, the
    id-derived Lakekeeper catalog name (#7753), flavor, creation time, and
    the owner fields (#7743), which are nullable because a user need not
    have set a name or an avatar.
    - **`WarehouseService`** — `GET /warehouse/status`, `POST /warehouse`,
    `DELETE /warehouse/{whid}`. The status call answers both questions the
    UI has in one round trip: whether the deployment enables the feature,
    and which warehouses the caller owns.
    - **`WarehouseActionsService`** — mirrors `ComputingUnitActionsService`:
    create and delete sit behind one service so the confirm dialog and its
    wording live in one place, shared by the dashboard tab and, later, the
    workspace picker (#7817). Its delete keeps the dialog busy until the
    request settles, because deleting a warehouse that holds data waits out
    Lakekeeper's asynchronous purge (#7742) — seconds, not milliseconds —
    and closing the dialog eagerly would read as a frozen row.
    
    With the per-user warehouse flag off, which is every deployment today,
    nothing calls any of this.
    
    ### Any related issues, documentation, discussions?
    
    Part of #6933 (first of three: API client, then the dialogs and row
    card, then the page that assembles them). Part of #6870, and consumes
    the merged backend: the endpoints (#6932), the owner fields (#7743), the
    id-derived catalog name (#7753) and the purge-aware delete (#7742).
    
    ### How was this PR tested?
    
    - Vitest specs for both services: the three endpoints and their URLs,
    the confirm dialog's shape, that nothing is deleted before confirmation,
    that the dialog stays busy until the request settles, and that a failure
    is reported without running the caller's refresh callback. 7 tests
    across 2 files.
      - Whole suite as CI runs it: `yarn test:ci`
    - Just this change: `ng test --watch=false --include
    "src/app/common/service/warehouse/*.spec.ts"`
    - Failure paths verified rather than assumed: each behaviour was broken
    on purpose and the suite confirmed to fail for the expected reason
    before being restored.
    - Exercised end to end against a local deployment with the flag on,
    backed by live Lakekeeper and MinIO: create, list, and delete, including
    a warehouse holding execution data.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (claude-opus-5, claude-fable-5)
---
 .../warehouse/warehouse-actions.service.spec.ts    | 149 +++++++++++++++++++++
 .../service/warehouse/warehouse-actions.service.ts |  86 ++++++++++++
 .../service/warehouse/warehouse.service.spec.ts    |  86 ++++++++++++
 .../common/service/warehouse/warehouse.service.ts  |  50 +++++++
 frontend/src/app/common/type/warehouse.ts          |  53 ++++++++
 5 files changed, 424 insertions(+)

diff --git a/frontend/src/app/common/service/warehouse/warehouse-actions.service.spec.ts b/frontend/src/app/common/service/warehouse/warehouse-actions.service.spec.ts
new file mode 100644
index 0000000000..d56a9751ea
--- /dev/null
+++ b/frontend/src/app/common/service/warehouse/warehouse-actions.service.spec.ts
@@ -0,0 +1,149 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { TestBed } from "@angular/core/testing";
+import { Subject, firstValueFrom, of, throwError } from "rxjs";
+import { NzModalService } from "ng-zorro-antd/modal";
+import { WarehouseActionsService } from "./warehouse-actions.service";
+import { WarehouseService } from "./warehouse.service";
+import { NotificationService } from "../notification/notification.service";
+import { DashboardWarehouse } from "../../type/warehouse";
+
+describe("WarehouseActionsService", () => {
+  let service: WarehouseActionsService;
+  let modalService: { confirm: ReturnType<typeof vi.fn> };
+  let warehouseService: { createWarehouse: ReturnType<typeof vi.fn>; deleteWarehouse: ReturnType<typeof vi.fn> };
+  let notificationService: { error: ReturnType<typeof vi.fn>; success: ReturnType<typeof vi.fn> };
+
+  const warehouse: DashboardWarehouse = {
+    whid: 3,
+    name: "sales",
+    lakekeeperWarehouseName: "user-1-3",
+    flavor: "local",
+    createdAtMillis: 0,
+    ownerName: "Alice",
+    ownerAvatar: null,
+  };
+
+  // The dialog is the only way in: every case goes through the confirm config
+  // nz-modal was handed, so name that once instead of reaching into the mock.
+  const confirmConfig = () => modalService.confirm.mock.calls[0][0];
+  const clickDelete = () => confirmConfig().nzOnOk();
+
+  beforeEach(() => {
+    modalService = { confirm: vi.fn() };
+    warehouseService = {
+      createWarehouse: vi.fn().mockReturnValue(of(warehouse)),
+      deleteWarehouse: vi.fn().mockReturnValue(of(void 0)),
+    };
+    notificationService = { error: vi.fn(), success: vi.fn() };
+
+    TestBed.configureTestingModule({
+      providers: [
+        WarehouseActionsService,
+        { provide: NzModalService, useValue: modalService },
+        { provide: WarehouseService, useValue: warehouseService },
+        { provide: NotificationService, useValue: notificationService },
+      ],
+    });
+    service = TestBed.inject(WarehouseActionsService);
+  });
+
+  it("creates through the warehouse service, so create and delete share one entry point", async () => {
+    const created = await firstValueFrom(service.create("mybucket"));
+
+    expect(warehouseService.createWarehouse).toHaveBeenCalledWith("mybucket");
+    expect(created).toEqual(warehouse);
+  });
+
+  it("asks for confirmation with the danger wording, without deleting yet", () => {
+    const onDeleted = vi.fn();
+
+    service.confirmAndDelete(warehouse, onDeleted);
+
+    expect(modalService.confirm).toHaveBeenCalledTimes(1);
+    const config = confirmConfig();
+    expect(config.nzTitle).toBe('Delete warehouse "sales"?');
+    expect(config.nzOkText).toBe("Delete");
+    expect(config.nzOkDanger).toBe(true);
+    expect(warehouseService.deleteWarehouse).not.toHaveBeenCalled();
+    expect(onDeleted).not.toHaveBeenCalled();
+  });
+
+  it("deletes on confirm, then notifies and runs onDeleted", async () => {
+    const onDeleted = vi.fn();
+    service.confirmAndDelete(warehouse, onDeleted);
+
+    await clickDelete();
+
+    expect(warehouseService.deleteWarehouse).toHaveBeenCalledWith(3);
+    expect(notificationService.success).toHaveBeenCalledWith("Warehouse deleted.");
+    expect(onDeleted).toHaveBeenCalledTimes(1);
+  });
+
+  it("keeps the dialog busy until the delete settles", async () => {
+    // The backend waits out Lakekeeper's asynchronous purge (#7742), so nzOnOk must
+    // hand nz-modal a promise — that is what keeps the OK button spinning instead of
+    // closing the dialog onto a row that is still there.
+    const deleted = new Subject<void>();
+    warehouseService.deleteWarehouse.mockReturnValue(deleted.asObservable());
+    const onDeleted = vi.fn();
+    service.confirmAndDelete(warehouse, onDeleted);
+
+    const pending = clickDelete();
+    expect(pending).toBeInstanceOf(Promise);
+    expect(onDeleted).not.toHaveBeenCalled();
+
+    deleted.next();
+    deleted.complete();
+    await pending;
+
+    expect(onDeleted).toHaveBeenCalledTimes(1);
+  });
+
+  it("does not report a failure when the refresh callback throws after a successful delete", async () => {
+    // The delete succeeded; a refresh that blows up is logged, not turned into a
+    // failure toast, and it must not reject the dialog either.
+    const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined);
+    const onDeleted = vi.fn(() => {
+      throw new Error("refresh blew up");
+    });
+    service.confirmAndDelete(warehouse, onDeleted);
+
+    await clickDelete();
+
+    expect(notificationService.success).toHaveBeenCalledWith("Warehouse deleted.");
+    expect(notificationService.error).not.toHaveBeenCalled();
+    expect(consoleErrorSpy).toHaveBeenCalled();
+    consoleErrorSpy.mockRestore();
+  });
+
+  it("surfaces the backend message and skips onDeleted when the delete fails", async () => {
+    warehouseService.deleteWarehouse.mockReturnValue(throwError(() => ({ error: "Lakekeeper unreachable" })));
+    const onDeleted = vi.fn();
+    service.confirmAndDelete(warehouse, onDeleted);
+
+    // Resolves rather than rejects: the dialog closes and the error rides a toast.
+    await clickDelete();
+
+    expect(notificationService.error).toHaveBeenCalledWith("Failed to delete warehouse: Lakekeeper unreachable");
+    expect(notificationService.success).not.toHaveBeenCalled();
+    expect(onDeleted).not.toHaveBeenCalled();
+  });
+});
diff --git a/frontend/src/app/common/service/warehouse/warehouse-actions.service.ts b/frontend/src/app/common/service/warehouse/warehouse-actions.service.ts
new file mode 100644
index 0000000000..4077719d6c
--- /dev/null
+++ b/frontend/src/app/common/service/warehouse/warehouse-actions.service.ts
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { Injectable } from "@angular/core";
+import { NzModalService } from "ng-zorro-antd/modal";
+import { Observable, firstValueFrom } from "rxjs";
+import { NotificationService } from "../notification/notification.service";
+import { DashboardWarehouse } from "../../type/warehouse";
+import { extractErrorMessage } from "../../util/error";
+import { WarehouseService } from "./warehouse.service";
+
+/**
+ * Shared warehouse actions (#6933), mirroring ComputingUnitActionsService: one
+ * entry point for creating and deleting a warehouse, so callers reach the API
+ * the same way and the delete confirmation's wording lives in one place. Shared
+ * with the workspace picker once it lands (#7817).
+ */
+@Injectable({
+  providedIn: "root",
+})
+export class WarehouseActionsService {
+  constructor(
+    private modalService: NzModalService,
+    private warehouseService: WarehouseService,
+    private notificationService: NotificationService
+  ) {}
+
+  /** Creates a warehouse. Needs no confirmation, unlike the delete below. */
+  create(name: string): Observable<DashboardWarehouse> {
+    return this.warehouseService.createWarehouse(name);
+  }
+
+  /**
+   * Asks for confirmation, then deletes the warehouse and all data stored in it.
+   * Runs `onDeleted` after a successful delete so the caller can refresh its
+   * list (warehouses have no push stream to do that for them, unlike computing
+   * units).
+   *
+   * `nzOnOk` returns a promise so the dialog keeps its OK button spinning until
+   * the request settles: deleting a warehouse that still holds data waits out
+   * Lakekeeper's asynchronous purge (#7742) — bounded at roughly 16 seconds by
+   * the backend's backoff — and closing the dialog immediately would read as a
+   * frozen row.
+   */
+  confirmAndDelete(warehouse: DashboardWarehouse, onDeleted: () => void): void {
+    this.modalService.confirm({
+      nzTitle: `Delete warehouse "${warehouse.name}"?`,
+      nzContent: "This permanently deletes the warehouse and all data stored in it.",
+      nzOkText: "Delete",
+      nzOkDanger: true,
+      // Returning a promise is what keeps the dialog busy until the request
+      // settles; each failure is reported where it belongs, so a refresh that
+      // throws is never mistaken for a delete that failed.
+      nzOnOk: async () => {
+        try {
+          await firstValueFrom(this.warehouseService.deleteWarehouse(warehouse.whid));
+        } catch (err: unknown) {
+          this.notificationService.error(`Failed to delete warehouse: ${extractErrorMessage(err)}`);
+          return;
+        }
+        this.notificationService.success("Warehouse deleted.");
+        try {
+          onDeleted();
+        } catch (err: unknown) {
+          console.error("Failed to refresh after deleting a warehouse", err);
+        }
+      },
+    });
+  }
+}
diff --git a/frontend/src/app/common/service/warehouse/warehouse.service.spec.ts b/frontend/src/app/common/service/warehouse/warehouse.service.spec.ts
new file mode 100644
index 0000000000..093aadcaaa
--- /dev/null
+++ b/frontend/src/app/common/service/warehouse/warehouse.service.spec.ts
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { TestBed } from "@angular/core/testing";
+import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing";
+import { AppSettings } from "../../app-setting";
+import { WAREHOUSE_BASE_URL, WAREHOUSE_STATUS_URL, WarehouseService } from "./warehouse.service";
+import { DashboardWarehouse, WarehouseStatus } from "../../type/warehouse";
+
+describe("WarehouseService", () => {
+  let service: WarehouseService;
+  let httpMock: HttpTestingController;
+
+  const warehouse: DashboardWarehouse = {
+    whid: 7,
+    name: "mybucket",
+    lakekeeperWarehouseName: "user-3-7",
+    flavor: "local",
+    createdAtMillis: 1723300000000,
+    ownerName: "Alice",
+    ownerAvatar: null,
+  };
+
+  beforeEach(() => {
+    TestBed.configureTestingModule({
+      imports: [HttpClientTestingModule],
+      providers: [WarehouseService],
+    });
+    service = TestBed.inject(WarehouseService);
+    httpMock = TestBed.inject(HttpTestingController);
+  });
+
+  afterEach(() => {
+    httpMock.verify();
+  });
+
+  it("fetches the warehouse status", () => {
+    let received: WarehouseStatus | undefined;
+    service.getStatus().subscribe(status => (received = status));
+
+    const req = httpMock.expectOne(`${AppSettings.getApiEndpoint()}/${WAREHOUSE_STATUS_URL}`);
+    expect(req.request.method).toBe("GET");
+    req.flush({ enabled: true, warehouses: [warehouse] });
+
+    expect(received).toEqual({ enabled: true, warehouses: [warehouse] });
+  });
+
+  it("creates a warehouse with the given name", () => {
+    let received: DashboardWarehouse | undefined;
+    service.createWarehouse("mybucket").subscribe(created => (received = created));
+
+    const req = httpMock.expectOne(`${AppSettings.getApiEndpoint()}/${WAREHOUSE_BASE_URL}`);
+    expect(req.request.method).toBe("POST");
+    expect(req.request.body).toEqual({ name: "mybucket" });
+    req.flush(warehouse);
+
+    expect(received).toEqual(warehouse);
+  });
+
+  it("deletes a warehouse by id", () => {
+    let completed = false;
+    service.deleteWarehouse(7).subscribe({ complete: () => (completed = true) });
+
+    const req = httpMock.expectOne(`${AppSettings.getApiEndpoint()}/${WAREHOUSE_BASE_URL}/7`);
+    expect(req.request.method).toBe("DELETE");
+    req.flush(null);
+
+    expect(completed).toBe(true);
+  });
+});
diff --git a/frontend/src/app/common/service/warehouse/warehouse.service.ts b/frontend/src/app/common/service/warehouse/warehouse.service.ts
new file mode 100644
index 0000000000..facc7879b3
--- /dev/null
+++ b/frontend/src/app/common/service/warehouse/warehouse.service.ts
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { Injectable } from "@angular/core";
+import { HttpClient } from "@angular/common/http";
+import { Observable } from "rxjs";
+import { AppSettings } from "../../app-setting";
+import { DashboardWarehouse, WarehouseStatus } from "../../type/warehouse";
+
+export const WAREHOUSE_BASE_URL = "warehouse";
+export const WAREHOUSE_STATUS_URL = `${WAREHOUSE_BASE_URL}/status`;
+
+/**
+ * Client of the per-user warehouse API (#6870): feature status + the caller's
+ * warehouses, create, and delete.
+ */
+@Injectable({
+  providedIn: "root",
+})
+export class WarehouseService {
+  constructor(private http: HttpClient) {}
+
+  public getStatus(): Observable<WarehouseStatus> {
+    return this.http.get<WarehouseStatus>(`${AppSettings.getApiEndpoint()}/${WAREHOUSE_STATUS_URL}`);
+  }
+
+  public createWarehouse(name: string): Observable<DashboardWarehouse> {
+    return this.http.post<DashboardWarehouse>(`${AppSettings.getApiEndpoint()}/${WAREHOUSE_BASE_URL}`, { name });
+  }
+
+  public deleteWarehouse(whid: number): Observable<void> {
+    return this.http.delete<void>(`${AppSettings.getApiEndpoint()}/${WAREHOUSE_BASE_URL}/${whid}`);
+  }
+}
diff --git a/frontend/src/app/common/type/warehouse.ts b/frontend/src/app/common/type/warehouse.ts
new file mode 100644
index 0000000000..e3e870055a
--- /dev/null
+++ b/frontend/src/app/common/type/warehouse.ts
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/** The storage backing a warehouse; the backend's `user_warehouse_flavor_enum`. */
+export type WarehouseFlavor = "local" | "aws";
+
+/**
+ * A per-user warehouse registration (#6870), as served by `GET /warehouse/status`
+ * and returned by `POST /warehouse`. Mirrors the backend's
+ * `WarehouseResource.DashboardWarehouse`.
+ */
+export interface DashboardWarehouse {
+  whid: number;
+  /** The user-facing name, unique per user and free to change. */
+  name: string;
+  /** The Lakekeeper catalog name (`user-<uid>-<whid>`), stable for life (#7753). */
+  lakekeeperWarehouseName: string;
+  flavor: WarehouseFlavor;
+  createdAtMillis: number;
+  /**
+   * Owner display info, mirroring DashboardWorkflowComputingUnit: every
+   * warehouse belongs to the caller today, but binding to the entry keeps
+   * shared warehouses rendering the right person (#7743). Null when the owner
+   * has not set a name or avatar.
+   */
+  ownerName: string | null;
+  ownerAvatar: string | null;
+}
+
+/**
+ * Response of `GET /warehouse/status`. `enabled` reflects the deployment-wide
+ * feature flag; with it off the warehouse UI stays hidden entirely.
+ */
+export interface WarehouseStatus {
+  enabled: boolean;
+  warehouses: ReadonlyArray<DashboardWarehouse>;
+}