Skip to content
Draft
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
5 changes: 4 additions & 1 deletion agent-service/src/agent/texera-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class TexeraAgent {
workflowId: number;
workflowName?: string;
computingUnitId?: number;
warehouseId?: number;
};

private stepCallback: ReActStepCallback | null = null;
Expand Down Expand Up @@ -185,6 +186,7 @@ export class TexeraAgent {
userToken: this.delegateConfig.userToken,
workflowId: this.delegateConfig.workflowId,
computingUnitId: this.delegateConfig.computingUnitId,
warehouseId: this.delegateConfig.warehouseId,
maxOperatorResultCharLimit: this.settings.maxOperatorResultCharLimit,
maxOperatorResultCellCharLimit: this.settings.maxOperatorResultCellCharLimit,
executionTimeoutMs: this.settings.executionTimeoutMs,
Expand Down Expand Up @@ -425,6 +427,7 @@ export class TexeraAgent {
workflowId: number;
workflowName?: string;
computingUnitId?: number;
warehouseId?: number;
}): void {
this.delegateConfig = config;

Expand All @@ -434,7 +437,7 @@ export class TexeraAgent {
}

getDelegateConfig():
| { userToken: string; userInfo?: UserInfo; workflowId: number; workflowName?: string; computingUnitId?: number }
| { userToken: string; userInfo?: UserInfo; workflowId: number; workflowName?: string; computingUnitId?: number; warehouseId?: number }
| undefined {
return this.delegateConfig;
}
Expand Down
4 changes: 4 additions & 0 deletions agent-service/src/agent/tools/workflow-execution-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export interface ExecutionConfig {
userToken: string;
workflowId: number;
computingUnitId?: number;
// The warehouse the user picked in the UI; forwarded alongside computingUnitId so
// the run writes into their own warehouse rather than shared storage (#7751).
warehouseId?: number;
maxOperatorResultCharLimit?: number;
maxOperatorResultCellCharLimit?: number;
executionTimeoutMs?: number;
Expand Down Expand Up @@ -285,6 +288,7 @@ async function executeWorkflowHttp(
maxOperatorResultCharLimit: config.maxOperatorResultCharLimit ?? DEFAULT_AGENT_SETTINGS.maxOperatorResultCharLimit,
maxOperatorResultCellCharLimit:
config.maxOperatorResultCellCharLimit ?? DEFAULT_AGENT_SETTINGS.maxOperatorResultCellCharLimit,
...(config.warehouseId !== undefined ? { warehouseId: config.warehouseId } : {}),
};

log.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ case class SyncExecutionRequest(
targetOperatorIds: List[String],
timeoutSeconds: Int,
maxOperatorResultCharLimit: Int,
maxOperatorResultCellCharLimit: Int
maxOperatorResultCellCharLimit: Int,
// The user_warehouse this run writes into. Carried from the caller the same way
// computingUnitId is: the agent forwards what the user picked in the UI. Required
// while per-user warehouses are enabled; absent keeps the shared default when the
// feature is off (#7751).
warehouseId: Option[Int] = None
)

case class ConsoleMessageInfo(
Expand Down Expand Up @@ -169,7 +174,7 @@ class SyncExecutionResource extends LazyLogging {
),
emailNotificationEnabled = false,
computingUnitId = computingUnitId,
warehouseId = None
warehouseId = request.warehouseId
)

workflowService.initExecutionService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ object WorkflowService {

/**
* Maps an execution's chosen warehouse (`whid`) to its Lakekeeper warehouse name,
* checking that the requesting user owns it. `None` (no explicit pick) keeps the
* shared default warehouse. With warehouses disabled, an explicit pick is refused
* loudly rather than silently routed into the shared warehouse (#6930).
* checking that the requesting user owns it.
*
* With warehouses enabled a pick is **required**, the same way a computing unit is:
* falling back to the shared default would make "a run writes into the user's own
* warehouse" a UI convention rather than a system property, and would silently route
* any caller that forgot to pick into shared storage (#7751).
*
* With warehouses disabled, an explicit pick is refused loudly rather than silently
* routed into the shared warehouse, and no pick keeps the shared default (#6930).
*/
def resolveWarehouseName(
warehouseId: Option[Int],
Expand All @@ -89,6 +95,11 @@ object WorkflowService {
)
return None
}
if (warehouseId.isEmpty) {
throw new IllegalArgumentException(
"a warehouse must be selected for this execution"
)
}
warehouseId.map(whid => {
val row = SqlServer
.getInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,17 @@ class WorkflowServiceWarehouseSpec

override protected def afterAll(): Unit = closeConnectionPool()

"resolveWarehouseName" should "keep the shared default warehouse when nothing is picked" in {
WorkflowService.resolveWarehouseName(None, ownerUid, enabled = true) shouldBe None
"resolveWarehouseName" should "require a pick while warehouses are enabled" in {
// A run must name the warehouse it writes into, the same way it names a computing
// unit; falling back to the shared default would route a caller that forgot to pick
// into shared storage (#7751).
val error = intercept[IllegalArgumentException] {
WorkflowService.resolveWarehouseName(None, ownerUid, enabled = true)
}
error.getMessage should include("warehouse")
}

it should "keep the shared default warehouse when nothing is picked and the feature is off" in {
WorkflowService.resolveWarehouseName(None, ownerUid, enabled = false) shouldBe None
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/app-routing.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const USER_WORKFLOW = `${USER}/workflow`;
export const USER_DATASET = `${USER}/dataset`;
export const USER_DATASET_CREATE = `${USER_DATASET}/create`;
export const USER_COMPUTING_UNIT = `${USER}/compute`;
export const USER_WAREHOUSE = `${USER}/warehouse`;
export const USER_PYTHON_VENV = `${USER}/python-venv`;
export const USER_QUOTA = `${USER}/quota`;
export const USER_DISCUSSION = `${USER}/discussion`;
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { UserQuotaComponent } from "./dashboard/component/user/user-quota/user-q
import { UserProjectSectionComponent } from "./dashboard/component/user/user-project/user-project-section/user-project-section.component";
import { UserProjectComponent } from "./dashboard/component/user/user-project/user-project.component";
import { UserComputingUnitComponent } from "./dashboard/component/user/user-computing-unit/user-computing-unit.component";
import { UserWarehouseComponent } from "./dashboard/component/user/user-warehouse/user-warehouse.component";
import { UserVenvComponent } from "./dashboard/component/user/user-venv/user-venv.component";
import { WorkspaceComponent } from "./workspace/component/workspace.component";
import { AboutComponent } from "./hub/component/about/about.component";
Expand Down Expand Up @@ -139,6 +140,10 @@ routes.push({
path: "compute",
component: UserComputingUnitComponent,
},
{
path: "warehouse",
component: UserWarehouseComponent,
},
{
path: "python-venv",
component: UserVenvComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!--
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.
-->

<nz-modal
[nzVisible]="visible"
nzTitle="Create Warehouse"
[nzContent]="createWarehouseModalContent"
[nzFooter]="createWarehouseModalFooter"
(nzOnCancel)="handleCreateWarehouseModalCancel()">
<ng-template #createWarehouseModalContent>
<input
nz-input
placeholder="Warehouse name"
maxlength="64"
[(ngModel)]="newWarehouseName"
(keyup.enter)="createWarehouse()" />
<p class="warehouse-name-hint">Letters, digits, '-' and '_' only; must start with a letter or digit.</p>
</ng-template>
<ng-template #createWarehouseModalFooter>
<button
nz-button
nzType="default"
(click)="handleCreateWarehouseModalCancel()">
Cancel
</button>
<button
nz-button
nzType="primary"
id="confirm-create-warehouse-btn"
[disabled]="!newWarehouseName.trim()"
[nzLoading]="creating"
(click)="createWarehouse()">
Create
</button>
</ng-template>
</nz-modal>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.
*/

.warehouse-name-hint {
margin: 8px 0 0;
color: rgba(0, 0, 0, 0.45);
font-size: 12px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/**
* 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 { SimpleChange } from "@angular/core";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { NzModalService } from "ng-zorro-antd/modal";
import { of, throwError } from "rxjs";
import { WarehouseCreateModalComponent } from "./warehouse-create-modal.component";
import { NotificationService } from "../../service/notification/notification.service";
import { WarehouseService } from "../../service/warehouse/warehouse.service";
import { DashboardWarehouse } from "../../type/warehouse";
import { commonTestProviders } from "../../testing/test-utils";

describe("WarehouseCreateModalComponent", () => {
let fixture: ComponentFixture<WarehouseCreateModalComponent>;
let component: WarehouseCreateModalComponent;
let warehouseService: { createWarehouse: ReturnType<typeof vi.fn> };
let notificationService: { error: ReturnType<typeof vi.fn>; success: ReturnType<typeof vi.fn> };

const created: DashboardWarehouse = {
whid: 7,
name: "mybucket",
warehouseName: "user-1-mybucket",
flavor: "local",
createdAtMillis: 0,
};

beforeEach(async () => {
warehouseService = { createWarehouse: vi.fn().mockReturnValue(of(created)) };
notificationService = { error: vi.fn(), success: vi.fn() };

await TestBed.configureTestingModule({
imports: [WarehouseCreateModalComponent, NoopAnimationsModule, HttpClientTestingModule],
providers: [
// The rendered <nz-modal> injects NzModalService itself.
NzModalService,
{ provide: WarehouseService, useValue: warehouseService },
{ provide: NotificationService, useValue: notificationService },
...commonTestProviders,
],
}).compileComponents();

fixture = TestBed.createComponent(WarehouseCreateModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

afterEach(() => {
fixture?.destroy();
});

it("renders the name input and a disabled Create button once opened", () => {
component.visible = true;
fixture.detectChanges();

// nz-modal renders into the CDK overlay on document, not into the fixture.
expect(document.querySelector("input[nz-input]")).toBeTruthy();
const createButton = document.querySelector<HTMLButtonElement>("#confirm-create-warehouse-btn");
expect(createButton?.disabled).toBe(true);

component.newWarehouseName = "mybucket";
fixture.detectChanges();
expect(createButton?.disabled).toBe(false);
});

it("creates the trimmed name, then emits the warehouse and closes", () => {
const createdSpy = vi.fn();
const visibleSpy = vi.fn();
component.warehouseCreated.subscribe(createdSpy);
component.visibleChange.subscribe(visibleSpy);
component.visible = true;
component.newWarehouseName = " mybucket ";

component.createWarehouse();

expect(warehouseService.createWarehouse).toHaveBeenCalledWith("mybucket");
expect(notificationService.success).toHaveBeenCalledWith('Warehouse "mybucket" created.');
expect(createdSpy).toHaveBeenCalledWith(created);
expect(component.visible).toBe(false);
expect(visibleSpy).toHaveBeenCalledWith(false);
expect(component.creating).toBe(false);
});

it("does nothing for a blank name", () => {
component.newWarehouseName = " ";

component.createWarehouse();

expect(warehouseService.createWarehouse).not.toHaveBeenCalled();
});

it("does not double-submit while a create is in flight", () => {
component.newWarehouseName = "mybucket";
component.creating = true;

component.createWarehouse();

expect(warehouseService.createWarehouse).not.toHaveBeenCalled();
});

it("keeps the modal open and surfaces the backend message when the create fails", () => {
warehouseService.createWarehouse.mockReturnValue(
throwError(() => ({ error: "a warehouse named 'mybucket' already exists" }))
);
const visibleSpy = vi.fn();
component.visibleChange.subscribe(visibleSpy);
component.visible = true;
component.newWarehouseName = "mybucket";

component.createWarehouse();

expect(component.visible).toBe(true);
expect(visibleSpy).not.toHaveBeenCalled();
expect(component.creating).toBe(false);
expect(notificationService.error).toHaveBeenCalledWith("a warehouse named 'mybucket' already exists");
});

it("clears the previous name when the modal opens", () => {
component.newWarehouseName = "leftover";
component.visible = true;

component.ngOnChanges({ visible: new SimpleChange(false, true, false) });

expect(component.newWarehouseName).toBe("");
});

it("cancel closes without creating", () => {
const visibleSpy = vi.fn();
component.visibleChange.subscribe(visibleSpy);
component.visible = true;

component.handleCreateWarehouseModalCancel();

expect(component.visible).toBe(false);
expect(visibleSpy).toHaveBeenCalledWith(false);
expect(warehouseService.createWarehouse).not.toHaveBeenCalled();
});
});
Loading
Loading