kunwp1 commented on code in PR #7820: URL: https://github.com/apache/texera/pull/7820#discussion_r3844869199
########## 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 { 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-mybucket", Review Comment: Shouldn't the lakekeeperWarehouseName now be `user-3-7`? ########## frontend/src/app/common/service/warehouse/warehouse-actions.service.spec.ts: ########## @@ -0,0 +1,129 @@ +/** + * 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, 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: { 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-sales", Review Comment: ditto ########## frontend/src/app/common/type/warehouse.ts: ########## @@ -0,0 +1,49 @@ +/** + * 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. + */ + +/** + * A per-user warehouse registration (#6870), as served by `GET /warehouse/status`. + * 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: string; Review Comment: Since this string can only be `aws` or `local`, can you make it a closed set? ########## frontend/src/app/common/service/warehouse/warehouse-actions.service.ts: ########## @@ -0,0 +1,83 @@ +/** + * 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: + * create and delete sit behind one service so the confirm dialog and its + * wording live 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, so create and delete both sit behind this service. */ + 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), which can take tens of seconds, + * 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, + // Resolves on failure too: the error is reported as a toast, and leaving the + // confirm dialog open on top of it would just have to be dismissed twice. + // Two callbacks rather than .then().catch(): chaining would route a throw + // from onDeleted into the delete-failed branch, reporting a failure over a + // delete that succeeded. + nzOnOk: () => + firstValueFrom(this.warehouseService.deleteWarehouse(warehouse.whid)).then( + () => { + this.notificationService.success("Warehouse deleted."); + onDeleted(); Review Comment: Better to add a try-catch for onDeleted(). ########## 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 { 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-mybucket", + flavor: "local", + createdAtMillis: 1723300000000, + ownerName: "Alice", + ownerAvatar: "", + }; + + 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`); + 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`); Review Comment: ditto ########## 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 { 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-mybucket", + flavor: "local", + createdAtMillis: 1723300000000, + ownerName: "Alice", + ownerAvatar: "", + }; + + 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`); Review Comment: Don't hardcode the path `/warehouse/status`. ########## 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 { 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-mybucket", + flavor: "local", + createdAtMillis: 1723300000000, + ownerName: "Alice", + ownerAvatar: "", + }; + + 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`); + 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`); + 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/7`); Review Comment: ditto ########## frontend/src/app/common/service/warehouse/warehouse-actions.service.spec.ts: ########## @@ -0,0 +1,129 @@ +/** + * 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, 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: { 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-sales", + flavor: "local", + createdAtMillis: 0, + ownerName: "Alice", + ownerAvatar: "", Review Comment: change it to null. ########## 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 { 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-mybucket", + flavor: "local", + createdAtMillis: 1723300000000, + ownerName: "Alice", + ownerAvatar: "", Review Comment: ditto ########## frontend/src/app/common/service/warehouse/warehouse-actions.service.ts: ########## @@ -0,0 +1,83 @@ +/** + * 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: + * create and delete sit behind one service so the confirm dialog and its + * wording live 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, so create and delete both sit behind this service. */ + 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), which can take tens of seconds, Review Comment: Tens of seconds seems too overstated. Change it to 16seconds? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
