scottyaslan commented on code in PR #11946:
URL: https://github.com/apache/nifi/pull/11946#discussion_r4697127962


##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/drain-process-group-dialog/drain-process-group-dialog.html:
##########
@@ -0,0 +1,101 @@
+<!--
+  ~ 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.
+  -->
+
+<h2 mat-dialog-title>Drain Process Group</h2>
+@if (drainState$ | async; as drainState) {
+    @if (getFailureMessages(drainState.drainRequest?.failureReason); as 
failureMessages) {
+        @if (failureMessages.length > 0) {
+            <error-banner [messages]="failureMessages" [showErrorIcon]="true" 
[allowDismiss]="false"></error-banner>
+        }
+    }
+    <div class="drain-process-group">
+        <mat-dialog-content>
+            <div class="flex flex-col gap-y-4">
+                <div class="tertiary-color font-medium" 
data-qa="drain-status-message">
+                    {{ getStatusMessage(drainState) }}
+                </div>
+                @if (drainState.drainRequest; as drainRequest) {
+                    <div class="w-full flex flex-col items-center">
+                        <mat-progress-bar
+                            [mode]="isProgressIndeterminate(drainRequest) ? 
'indeterminate' : 'determinate'"
+                            
[value]="getPercentCompleted(drainRequest)"></mat-progress-bar>
+                        <div class="tertiary-color font-medium" 
data-qa="drain-remaining">
+                            {{ getRemainingText(drainRequest) }}
+                        </div>
+                    </div>
+                    @if (drainRequest.blockingComponents.length > 0) {
+                        <div class="flex flex-col gap-y-2">
+                            <status-banner variant="caution" 
[allowDismiss]="false" data-qa="drain-blocking-banner">
+                                <div statusBannerTitle>{{ 
getBlockingBannerTitle(drainState) }}</div>
+                                <div statusBannerDescription>
+                                    Queued data cannot leave until the 
components below are fixed.
+                                </div>
+                            </status-banner>
+                            @for (component of 
drainRequest.blockingComponents; track component.id) {
+                                <div class="flex items-center gap-x-2" 
data-qa="drain-blocking-component">
+                                    @if 
(getBlockingTooltipComponent(component); as tooltipComponent) {
+                                        <div
+                                            class="fa fa-warning caution-color"
+                                            
data-qa="drain-blocking-component-warning"
+                                            nifiTooltip
+                                            
[tooltipComponentType]="tooltipComponent"
+                                            
[tooltipInputData]="getBlockingTooltipData(component)"
+                                            [delayClose]="true"></div>
+                                    } @else {
+                                        <div
+                                            class="fa fa-warning caution-color"
+                                            
data-qa="drain-blocking-component-warning"></div>
+                                    }
+                                    <div class="flex-1">
+                                        @if (drainState.status === 'ended') {
+                                            <a
+                                                class="pointer primary-color"
+                                                data-qa="drain-go-to"
+                                                
(click)="goToComponent.next(component)"
+                                                >{{ 
getBlockingComponentLabel(component) }}</a
+                                            >
+                                        } @else {
+                                            <span 
data-qa="drain-blocking-component-label">{{
+                                                
getBlockingComponentLabel(component)
+                                            }}</span>
+                                        }
+                                        <span 
data-qa="drain-blocking-component-detail">{{
+                                            
getBlockingComponentDetail(component)
+                                        }}</span>
+                                    </div>
+                                </div>
+                            }
+                        </div>
+                    }
+                }
+            </div>
+        </mat-dialog-content>
+        <mat-dialog-actions align="end">
+            @if (drainState.status === 'ended') {
+                <button mat-flat-button mat-dialog-close 
data-qa="drain-close">Close</button>
+            } @else {
+                <button
+                    mat-button
+                    data-qa="drain-cancel"
+                    [disabled]="drainState.status !== 'draining'"
+                    (click)="cancelDrain.next()">
+                    Cancel Drain
+                </button>

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Should fix: View Drain is available to read-only users, but the dialog 
always offers Cancel Drain.
   
   Why: The View Drain context-menu condition in 
`canvas-context-menu.service.ts` only checks `canRead`, so a user without write 
permission can open this dialog. Cancelling a drain is a DELETE on the drain 
request, which requires write permission on the group. That user gets a 403, an 
error snackbar, and `drainApiError$` closes the dialog. The button shouldn't be 
offered to someone who can't use it.
   
   Where: this actions block (`drain-cancel` button), 
`canvas-context-menu.service.ts` (View Drain `action`), and `DrainDialogState` 
in `drain-process-group-dialog.types.ts`.
   
   Fix:
   - Add `canCancel: boolean` to the `viewDrain` request and carry it into 
`DrainDialogState`.
   - In the View Drain `action`, pass `canCancel: 
this.canvasUtils.canModify(selection)` (use `canModifyCurrentProcessGroup()` 
when the selection is empty). `beginDrainSuccess` can pass `true`, since Drain 
itself requires modify permission.
   - In this template, render the Cancel Drain button only when 
`drainState.canCancel`; otherwise show the Close button used for the ended 
state.
   - Tests: the dialog spec asserts Cancel Drain is absent when `canCancel` is 
false and present when true; the context-menu spec asserts the flag follows 
`canModify` for both a selected group and the current group.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/process-group-drain/process-group-drain.effects.ts:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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, inject } from '@angular/core';
+import { Actions, createEffect, ofType } from '@ngrx/effects';
+import { concatLatestFrom } from '@ngrx/operators';
+import { Action, Store } from '@ngrx/store';
+import { HttpErrorResponse } from '@angular/common/http';
+import { MatDialog, MatDialogRef } from '@angular/material/dialog';
+import { NavigationStart, Router } from '@angular/router';
+import {
+    asyncScheduler,
+    catchError,
+    exhaustMap,
+    filter,
+    from,
+    interval,
+    map,
+    of,
+    switchMap,
+    take,
+    takeUntil,
+    tap
+} from 'rxjs';
+import {
+    ComponentType,
+    DrainBlockingComponentType,
+    isDefinedAndNotNull,
+    MEDIUM_DIALOG,
+    SMALL_DIALOG,
+    YesNoDialog
+} from '@nifi/shared';
+import * as ProcessGroupDrainActions from './process-group-drain.actions';
+import * as FlowActions from '../flow/flow.actions';
+import * as ErrorActions from '../../../../state/error/error.actions';
+import {
+    selectDrainDialogState,
+    selectDrainProcessGroupId,
+    selectDrainRequestId
+} from './process-group-drain.selectors';
+import { selectCurrentProcessGroupId } from '../flow/flow.selectors';
+import { ProcessGroupDrainService } from 
'../../../../service/process-group-drain.service';
+import { ErrorHelper } from '../../../../service/error-helper.service';
+import { DrainProcessGroupDialog } from 
'../../../../ui/common/drain-process-group-dialog/drain-process-group-dialog';
+import { NiFiState } from '../../../../state';
+
+const COMPONENT_TYPES: Record<DrainBlockingComponentType, ComponentType> = {
+    PROCESSOR: ComponentType.Processor,
+    INPUT_PORT: ComponentType.InputPort,
+    OUTPUT_PORT: ComponentType.OutputPort,
+    REMOTE_INPUT_PORT: ComponentType.RemoteProcessGroup
+};
+
+const POLLING_STOP_ACTIONS = [
+    ProcessGroupDrainActions.drainEnded,
+    ProcessGroupDrainActions.cancelDrain,
+    ProcessGroupDrainActions.resetDrainState,
+    ProcessGroupDrainActions.drainApiError
+] as const;
+
+@Injectable()
+export class ProcessGroupDrainEffects {
+    private actions$ = inject(Actions);
+    private store = inject<Store<NiFiState>>(Store);
+    private processGroupDrainService = inject(ProcessGroupDrainService);
+    private errorHelper = inject(ErrorHelper);
+    private dialog = inject(MatDialog);
+    private router = inject(Router);
+
+    private drainDialogRef: MatDialogRef<DrainProcessGroupDialog> | undefined;
+    private lastPrepared = false;
+
+    promptDrain$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.promptDrain),
+                map((action) => action.request),
+                tap((request) => {
+                    const dialogReference = this.dialog.open(YesNoDialog, {
+                        ...SMALL_DIALOG,
+                        data: {
+                            title: 'Drain Process Group',
+                            message:
+                                'Drain stops the components that bring data 
into this Process Group, enables the Controller Services its components 
reference, and starts the other components so the queued data can flow out. The 
drain ends when the group is empty or when you cancel it. Components keep their 
run state afterwards, so sources remain stopped. Are you sure you want to drain 
this Process Group?'
+                        }
+                    });
+
+                    
dialogReference.componentInstance.yes.pipe(take(1)).subscribe(() => {
+                        
this.store.dispatch(ProcessGroupDrainActions.beginDrain({ request }));
+                    });
+                })
+            ),
+        { dispatch: false }
+    );
+
+    beginDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.beginDrain),
+            map((action) => action.request),
+            switchMap((request) =>
+                
this.processGroupDrainService.beginDrain(request.processGroupId).pipe(
+                    map((response) =>
+                        ProcessGroupDrainActions.beginDrainSuccess({
+                            response: { drainRequestEntity: response }
+                        })
+                    ),
+                    catchError((errorResponse: HttpErrorResponse) => 
this.handleDrainApiError(errorResponse))
+                )
+            )
+        )
+    );
+
+    beginDrainSuccess$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.beginDrainSuccess),
+            concatLatestFrom(() => [
+                this.store.select(selectDrainProcessGroupId),
+                this.store.select(selectCurrentProcessGroupId)
+            ]),
+            switchMap(([action, processGroupId, currentProcessGroupId]) => {
+                this.lastPrepared = 
action.response.drainRequestEntity.drainRequest?.prepared === true;
+                const drainRequest = 
action.response.drainRequestEntity.drainRequest;
+                // drainEnded$ performs the reload when the drain has already 
ended, so the group is reloaded once
+                if (!drainRequest || drainRequest.state !== 'DRAINING') {
+                    return of(ProcessGroupDrainActions.drainEnded());
+                }
+                return from([
+                    this.reloadProcessGroupAction(processGroupId, 
currentProcessGroupId),
+                    ProcessGroupDrainActions.startPollingDrain()
+                ]);
+            })
+        )
+    );
+
+    openDrainDialog$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.beginDrainSuccess, 
ProcessGroupDrainActions.viewDrain),
+                tap(() => {
+                    if (this.drainDialogRef) {
+                        return;
+                    }
+
+                    const dialogReference = 
this.dialog.open(DrainProcessGroupDialog, {
+                        ...MEDIUM_DIALOG,
+                        disableClose: true,
+                        autoFocus: false
+                    });
+                    this.drainDialogRef = dialogReference;
+
+                    dialogReference.componentInstance.drainState$ = 
this.store.select(selectDrainDialogState);
+
+                    dialogReference.componentInstance.cancelDrain
+                        .pipe(takeUntil(dialogReference.afterClosed()))
+                        .subscribe(() => {
+                            
this.store.dispatch(ProcessGroupDrainActions.cancelDrain());
+                        });
+
+                    dialogReference.componentInstance.goToComponent
+                        .pipe(takeUntil(dialogReference.afterClosed()))
+                        .subscribe((component) => {
+                            
this.store.dispatch(ProcessGroupDrainActions.goToBlockingComponent({ component 
}));
+                        });
+
+                    dialogReference.afterClosed().subscribe(() => {
+                        this.drainDialogRef = undefined;
+                        this.lastPrepared = false;
+                        
this.store.dispatch(ProcessGroupDrainActions.resetDrainState());
+                    });
+                })
+            ),
+        { dispatch: false }
+    );
+
+    viewDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.viewDrain),
+            map(() => ProcessGroupDrainActions.startPollingDrain())
+        )
+    );
+
+    // viewDrain reaches this effect through viewDrain$, which dispatches 
startPollingDrain. Listening
+    // for both would still be a single interval because switchMap replaces 
the previous one, but it
+    // would restart the timer on every View.
+    startPollingDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.startPollingDrain),
+            switchMap(() =>
+                interval(2000, 
asyncScheduler).pipe(takeUntil(this.actions$.pipe(ofType(...POLLING_STOP_ACTIONS))))
+            ),
+            map(() => ProcessGroupDrainActions.pollDrain())
+        )
+    );
+
+    pollDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.pollDrain, 
ProcessGroupDrainActions.viewDrain),
+            concatLatestFrom(() => [
+                
this.store.select(selectDrainProcessGroupId).pipe(isDefinedAndNotNull()),
+                
this.store.select(selectDrainRequestId).pipe(isDefinedAndNotNull())
+            ]),
+            exhaustMap(([, processGroupId, drainRequestId]) =>
+                this.processGroupDrainService.getDrain(processGroupId, 
drainRequestId).pipe(
+                    map((response) =>
+                        ProcessGroupDrainActions.pollDrainSuccess({
+                            response: { drainRequestEntity: response }
+                        })
+                    ),
+                    catchError((errorResponse: HttpErrorResponse) => 
this.handleDrainApiError(errorResponse)),
+                    
takeUntil(this.actions$.pipe(ofType(...POLLING_STOP_ACTIONS)))
+                )
+            )
+        )
+    );
+
+    pollDrainSuccess$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.pollDrainSuccess),
+            concatLatestFrom(() => [
+                this.store.select(selectDrainProcessGroupId),
+                this.store.select(selectCurrentProcessGroupId)
+            ]),
+            switchMap(([action, processGroupId, currentProcessGroupId]) => {
+                const drainRequest = 
action.response.drainRequestEntity.drainRequest;
+                const actions: Action[] = [];
+                const isDraining = drainRequest?.state === 'DRAINING';
+                const prepared = drainRequest?.prepared === true;
+                // An ended drain is reloaded by drainEnded$, so the prepared 
flip only reloads while draining
+                if (isDraining && prepared && !this.lastPrepared) {

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Should fix: Viewing a drain that is already prepared reloads the group once 
unnecessarily.
   
   Why: `lastPrepared` (line 85) starts as `false` and is reset to `false` 
whenever the dialog closes. On View Drain for a drain that is already prepared, 
the first poll sees `prepared` flip from `false` to `true` and dispatches 
`reloadProcessGroupAction`, even though the canvas already shows the prepared 
state.
   
   Where: this check, and the field at line 85 (`private lastPrepared = 
false;`). The reset in the `afterClosed` handler (line 181) and the one at line 
313 are affected too.
   
   Fix:
   - Make the field `boolean | null`, starting at `null`. Reload only when the 
previous value was explicitly `false`: `if (isDraining && prepared && 
this.lastPrepared === false)`.
   - Set it to the response value at the end of each poll, and reset it to 
`null` (not `false`) in the `afterClosed` and `drainApiError` handlers.
   - Tests: add a spec where the first poll after View returns `prepared: true` 
and assert no reload action; the existing `prepared` false-to-true case 
("reloads the flow once when prepared flips to true") should still pass.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/process-group-drain/process-group-drain.effects.ts:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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, inject } from '@angular/core';
+import { Actions, createEffect, ofType } from '@ngrx/effects';
+import { concatLatestFrom } from '@ngrx/operators';
+import { Action, Store } from '@ngrx/store';
+import { HttpErrorResponse } from '@angular/common/http';
+import { MatDialog, MatDialogRef } from '@angular/material/dialog';
+import { NavigationStart, Router } from '@angular/router';
+import {
+    asyncScheduler,
+    catchError,
+    exhaustMap,
+    filter,
+    from,
+    interval,
+    map,
+    of,
+    switchMap,
+    take,
+    takeUntil,
+    tap
+} from 'rxjs';
+import {
+    ComponentType,
+    DrainBlockingComponentType,
+    isDefinedAndNotNull,
+    MEDIUM_DIALOG,
+    SMALL_DIALOG,
+    YesNoDialog
+} from '@nifi/shared';
+import * as ProcessGroupDrainActions from './process-group-drain.actions';
+import * as FlowActions from '../flow/flow.actions';
+import * as ErrorActions from '../../../../state/error/error.actions';
+import {
+    selectDrainDialogState,
+    selectDrainProcessGroupId,
+    selectDrainRequestId
+} from './process-group-drain.selectors';
+import { selectCurrentProcessGroupId } from '../flow/flow.selectors';
+import { ProcessGroupDrainService } from 
'../../../../service/process-group-drain.service';
+import { ErrorHelper } from '../../../../service/error-helper.service';
+import { DrainProcessGroupDialog } from 
'../../../../ui/common/drain-process-group-dialog/drain-process-group-dialog';
+import { NiFiState } from '../../../../state';
+
+const COMPONENT_TYPES: Record<DrainBlockingComponentType, ComponentType> = {
+    PROCESSOR: ComponentType.Processor,
+    INPUT_PORT: ComponentType.InputPort,
+    OUTPUT_PORT: ComponentType.OutputPort,
+    REMOTE_INPUT_PORT: ComponentType.RemoteProcessGroup
+};
+
+const POLLING_STOP_ACTIONS = [
+    ProcessGroupDrainActions.drainEnded,
+    ProcessGroupDrainActions.cancelDrain,
+    ProcessGroupDrainActions.resetDrainState,
+    ProcessGroupDrainActions.drainApiError
+] as const;
+
+@Injectable()
+export class ProcessGroupDrainEffects {
+    private actions$ = inject(Actions);
+    private store = inject<Store<NiFiState>>(Store);
+    private processGroupDrainService = inject(ProcessGroupDrainService);
+    private errorHelper = inject(ErrorHelper);
+    private dialog = inject(MatDialog);
+    private router = inject(Router);
+
+    private drainDialogRef: MatDialogRef<DrainProcessGroupDialog> | undefined;
+    private lastPrepared = false;
+
+    promptDrain$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.promptDrain),
+                map((action) => action.request),
+                tap((request) => {
+                    const dialogReference = this.dialog.open(YesNoDialog, {
+                        ...SMALL_DIALOG,
+                        data: {
+                            title: 'Drain Process Group',
+                            message:
+                                'Drain stops the components that bring data 
into this Process Group, enables the Controller Services its components 
reference, and starts the other components so the queued data can flow out. The 
drain ends when the group is empty or when you cancel it. Components keep their 
run state afterwards, so sources remain stopped. Are you sure you want to drain 
this Process Group?'
+                        }
+                    });
+
+                    
dialogReference.componentInstance.yes.pipe(take(1)).subscribe(() => {
+                        
this.store.dispatch(ProcessGroupDrainActions.beginDrain({ request }));
+                    });
+                })
+            ),
+        { dispatch: false }
+    );
+
+    beginDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.beginDrain),
+            map((action) => action.request),
+            switchMap((request) =>
+                
this.processGroupDrainService.beginDrain(request.processGroupId).pipe(
+                    map((response) =>
+                        ProcessGroupDrainActions.beginDrainSuccess({
+                            response: { drainRequestEntity: response }
+                        })
+                    ),
+                    catchError((errorResponse: HttpErrorResponse) => 
this.handleDrainApiError(errorResponse))
+                )
+            )
+        )
+    );
+
+    beginDrainSuccess$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.beginDrainSuccess),
+            concatLatestFrom(() => [
+                this.store.select(selectDrainProcessGroupId),
+                this.store.select(selectCurrentProcessGroupId)
+            ]),
+            switchMap(([action, processGroupId, currentProcessGroupId]) => {
+                this.lastPrepared = 
action.response.drainRequestEntity.drainRequest?.prepared === true;
+                const drainRequest = 
action.response.drainRequestEntity.drainRequest;
+                // drainEnded$ performs the reload when the drain has already 
ended, so the group is reloaded once
+                if (!drainRequest || drainRequest.state !== 'DRAINING') {
+                    return of(ProcessGroupDrainActions.drainEnded());
+                }
+                return from([
+                    this.reloadProcessGroupAction(processGroupId, 
currentProcessGroupId),
+                    ProcessGroupDrainActions.startPollingDrain()
+                ]);
+            })
+        )
+    );
+
+    openDrainDialog$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.beginDrainSuccess, 
ProcessGroupDrainActions.viewDrain),
+                tap(() => {
+                    if (this.drainDialogRef) {
+                        return;
+                    }
+
+                    const dialogReference = 
this.dialog.open(DrainProcessGroupDialog, {
+                        ...MEDIUM_DIALOG,
+                        disableClose: true,

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Should fix: While a drain is running, the only way out of the dialog is 
Cancel Drain, and the links to the blocking components are plain text.
   
   Why: A drain can run for a long time and can be blocked by an invalid or 
disabled component. The user can't fix that component without leaving the 
dialog, but the only exit is to cancel the drain. The rest of the feature 
assumes the drain keeps running without the dialog: the group shows a Draining 
badge and the View Drain menu item reopens the dialog. The dialog should be 
dismissable without affecting the drain.
   
   Where: `disableClose: true` here, plus `drain-process-group-dialog.html` 
(the `@if (drainState.status === 'ended')` that gates the Go To link, and the 
dialog actions).
   
   Fix:
   - Remove `disableClose: true` so Escape and backdrop click close the dialog, 
or keep it and add a Close button next to Cancel Drain. Closing must not cancel 
the drain.
   - Render the Go To link whenever the status is not `'ending'`, not only 
`'ended'`. `goToBlockingComponent$` already closes the dialog before 
navigating, and the drain keeps running in the background.
   - Tests: the dialog spec asserts the Close button and the Go To link are 
present while the status is `'draining'` (the existing "does not offer Go To 
links while draining" case changes accordingly); the effects spec asserts 
closing the dialog does not dispatch `cancelDrain`.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/canvas/utils/draining-badge.utils.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 * as d3 from 'd3';
+import { CanvasConstants } from '../canvas.constants';
+
+/**
+ * Space between the Draining label and the edge of its background.
+ */
+export const DRAINING_BADGE_HORIZONTAL_PADDING = 5;
+
+/**
+ * Appends a hidden Draining badge inside a process group's Queued stats row. 
The badge is shorter
+ * than the row so it never changes the row height. Its horizontal layout is 
applied by
+ * `updateDrainingBadge`, once the label's font is rendered and can be 
measured accurately.
+ */
+export function appendDrainingBadge<PElement extends d3.BaseType, PDatum>(

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Should fix: The canvas Draining badge has a tooltip but no info icon, and 
its sizing doesn't match the status badge used in the Operate panel.
   
   Why: The status badge shows the info-circle icon whenever it opens a tooltip 
or popover, and the Operate panel badge already does. The canvas badge uses a 
different weight (`bold` here, `font-weight: bold` in `canvas.component.scss`, 
versus semibold) and different padding and radius than the status badge. The 
stats row is 19px tall, so the badge needs a compact variant of the same 
anatomy to fit.
   
   Where: `appendDrainingBadge` / `updateDrainingBadge`, 
`CanvasConstants.PROCESS_GROUP_DRAINING_BADGE_HEIGHT` in `canvas.constants.ts` 
(line 73), and the `text.process-group-draining-badge-label` rules in both 
`canvas.component.scss` files.
   
   Fix:
   - Add a `text.process-group-draining-badge-icon` element with the `\uf05a` 
glyph (`fa-info-circle`), `font-family: FontAwesome`, `font-size: 9px`, fill 
`var(--nf-success-contrast)`.
   - Lay out horizontally as padding 4, label, gap 4, icon, padding 4. Use 
`text-anchor="start"` on the label and icon, and place the icon at `labelX + 
labelWidth + gap`. Set the badge height to 16 (it is 13 today), rect radius 3, 
and label `font-size: 9px; font-weight: 600`.
   - Add `text-rendering: geometricPrecision` to the label and icon so measured 
text widths stay linear at every canvas zoom level.
   - The gap is 4 rather than the 2px of the HTML status badge because canvas 
units shrink with zoom. At 0.6x a 2-unit gap is about 1px, and the icon looks 
like it touches the label.
   - Tests: assert the icon exists, the badge is vertically centred in the 
stats row, and the padding/label/gap/icon layout ends at the requested right 
edge.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/process-group-drain/process-group-drain.effects.spec.ts:
##########
@@ -0,0 +1,523 @@
+/*
+ * 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 { provideMockActions } from '@ngrx/effects/testing';
+import { MockStore, provideMockStore } from '@ngrx/store/testing';
+import { Action } from '@ngrx/store';
+import { HttpErrorResponse } from '@angular/common/http';
+import { MatDialog } from '@angular/material/dialog';
+import { NavigationStart, Router } from '@angular/router';
+import { filter, firstValueFrom, Observable, of, Subject, throwError } from 
'rxjs';
+import { ProcessGroupDrainEffects } from './process-group-drain.effects';
+import * as ProcessGroupDrainActions from './process-group-drain.actions';
+import * as FlowActions from '../flow/flow.actions';
+import * as ErrorActions from '../../../../state/error/error.actions';
+import { selectCurrentProcessGroupId } from '../flow/flow.selectors';
+import { selectDrainProcessGroupId, selectDrainRequestId } from 
'./process-group-drain.selectors';
+import { ProcessGroupDrainService } from 
'../../../../service/process-group-drain.service';
+import { ErrorHelper } from '../../../../service/error-helper.service';
+import {
+    createDrainBlockingComponent,
+    createProcessGroupDrainRequestEntity
+} from '../../../../testing/process-group-drain-fixture';
+import { ComponentType } from '@nifi/shared';
+
+describe('ProcessGroupDrainEffects', () => {
+    async function setup(
+        options: {
+            processGroupId?: string | null;
+            drainRequestId?: string | null;
+            currentProcessGroupId?: string;
+            processGroupDrainService?: Partial<ProcessGroupDrainService>;
+        } = {}
+    ) {
+        let actions$: Observable<Action>;
+        const yes$ = new Subject<void>();
+        const cancelDrain$ = new Subject<void>();
+        const goToComponent$ = new Subject<unknown>();
+        const afterClosed$ = new Subject<void>();
+        const routerEvents$ = new Subject<unknown>();
+        const mockDialog = {
+            open: vi.fn().mockReturnValue({
+                componentInstance: {
+                    yes: yes$,
+                    cancelDrain: cancelDrain$,
+                    goToComponent: goToComponent$,
+                    drainState$: undefined
+                },
+                close: vi.fn(),
+                afterClosed: () => afterClosed$
+            })
+        };
+
+        await TestBed.configureTestingModule({
+            providers: [
+                ProcessGroupDrainEffects,
+                provideMockActions(() => actions$),
+                provideMockStore({
+                    selectors: [
+                        {
+                            selector: selectDrainProcessGroupId,
+                            value: options.processGroupId !== undefined ? 
options.processGroupId : 'pg-1'
+                        },
+                        {
+                            selector: selectDrainRequestId,
+                            value: options.drainRequestId !== undefined ? 
options.drainRequestId : 'drain-1'
+                        },
+                        {
+                            selector: selectCurrentProcessGroupId,
+                            value: options.currentProcessGroupId ?? 'pg-1'
+                        }
+                    ]
+                }),
+                { provide: MatDialog, useValue: mockDialog },
+                { provide: Router, useValue: { events: routerEvents$ } },
+                {
+                    provide: ProcessGroupDrainService,
+                    useValue: {
+                        beginDrain: vi.fn(),
+                        getDrain: vi.fn(),
+                        endDrain: vi.fn(),
+                        ...options.processGroupDrainService
+                    }
+                },
+                {
+                    provide: ErrorHelper,
+                    useValue: {
+                        getErrorString: (error: HttpErrorResponse) => 
error.message,
+                        showErrorInContext: (status: number) => [400, 403, 
404, 409, 413, 503].includes(status),
+                        fullScreenError: vi
+                            .fn()
+                            .mockReturnValue(
+                                ErrorActions.fullScreenError({ errorDetail: { 
title: 'Error', message: 'boom' } })
+                            )
+                    }
+                }
+            ]
+        }).compileComponents();
+
+        const effects = TestBed.inject(ProcessGroupDrainEffects);
+        const store = TestBed.inject(MockStore);
+        const processGroupDrainService = 
TestBed.inject(ProcessGroupDrainService);
+        const dispatchSpy = vi.spyOn(store, 'dispatch');
+
+        return {
+            effects,
+            setActions: (source: Observable<Action>) => {
+                actions$ = source;
+            },
+            mockDialog,
+            yes$,
+            cancelDrain$,
+            goToComponent$,
+            afterClosed$,
+            routerEvents$,
+            processGroupDrainService,
+            dispatchSpy
+        };
+    }
+
+    it('dispatches beginDrain only when the prompt is confirmed', async () => {
+        const { effects, setActions, mockDialog, yes$, dispatchSpy } = await 
setup();
+        const actions$ = new Subject<Action>();
+        setActions(actions$);
+
+        effects.promptDrain$.subscribe();
+        actions$.next(ProcessGroupDrainActions.promptDrain({ request: { 
processGroupId: 'pg-1' } }));
+
+        expect(mockDialog.open).toHaveBeenCalled();
+        expect(dispatchSpy).not.toHaveBeenCalled();
+
+        yes$.next();
+
+        expect(dispatchSpy).toHaveBeenCalledWith(
+            ProcessGroupDrainActions.beginDrain({ request: { processGroupId: 
'pg-1' } })
+        );
+    });
+
+    it('opens the dialog, starts polling, and reloads the current group after 
a successful POST', async () => {
+        const entity = createProcessGroupDrainRequestEntity();
+        const { effects, setActions, mockDialog } = await setup({
+            processGroupDrainService: {
+                beginDrain: vi.fn().mockReturnValue(of(entity))
+            }
+        });
+        const actions$ = new Subject<Action>();
+        setActions(actions$);
+
+        const beginResult = firstValueFrom(effects.beginDrain$);
+        actions$.next(ProcessGroupDrainActions.beginDrain({ request: { 
processGroupId: 'pg-1' } }));
+        expect(await beginResult).toEqual(
+            ProcessGroupDrainActions.beginDrainSuccess({ response: { 
drainRequestEntity: entity } })
+        );
+
+        const successResults = 
firstValueFrom(effects.beginDrainSuccess$.pipe());
+        const openPromise = firstValueFrom(effects.openDrainDialog$);
+        actions$.next(ProcessGroupDrainActions.beginDrainSuccess({ response: { 
drainRequestEntity: entity } }));
+        await openPromise;
+        const success = await successResults;
+
+        expect(mockDialog.open).toHaveBeenCalled();
+        expect(success).toEqual(FlowActions.reloadFlow());
+    });
+
+    it('reloads a child process group after a successful POST when it is not 
the current group', async () => {
+        const entity = createProcessGroupDrainRequestEntity();
+        const { effects, setActions } = await setup({
+            currentProcessGroupId: 'current-pg',
+            processGroupId: 'pg-1'
+        });
+        const actions$ = new Subject<Action>();
+        setActions(actions$);
+
+        const result = firstValueFrom(effects.beginDrainSuccess$);
+        actions$.next(ProcessGroupDrainActions.beginDrainSuccess({ response: { 
drainRequestEntity: entity } }));
+
+        expect(await result).toEqual(FlowActions.loadChildProcessGroup({ 
request: { id: 'pg-1' } }));
+    });
+
+    it('ends the drain without reloading in beginDrainSuccess$ when the POST 
returns an ended drain', async () => {
+        const ended = createProcessGroupDrainRequestEntity({ state: 'ENDED', 
currentCount: 0 });
+        const { effects, setActions } = await setup({ currentProcessGroupId: 
'pg-1', processGroupId: 'pg-1' });
+        const actions$ = new Subject<Action>();
+        setActions(actions$);
+
+        const emitted: Action[] = [];
+        const subscription = effects.beginDrainSuccess$.subscribe((action) => 
emitted.push(action));
+        actions$.next(ProcessGroupDrainActions.beginDrainSuccess({ response: { 
drainRequestEntity: ended } }));
+        subscription.unsubscribe();
+
+        expect(emitted).toEqual([ProcessGroupDrainActions.drainEnded()]);
+    });
+
+    it('shows a snackbar and does not open the dialog when the POST fails', 
async () => {
+        const errorResponse = new HttpErrorResponse({ status: 409, statusText: 
'Conflict', error: 'already draining' });
+        Object.defineProperty(errorResponse, 'message', { value: 'already 
draining' });
+        const { effects, setActions, mockDialog, processGroupDrainService } = 
await setup({
+            processGroupDrainService: {
+                beginDrain: vi.fn().mockReturnValue(throwError(() => 
errorResponse))
+            }
+        });
+        vi.spyOn(processGroupDrainService, 
'beginDrain').mockReturnValue(throwError(() => errorResponse));
+        const actions$ = new Subject<Action>();
+        setActions(actions$);
+
+        const result = firstValueFrom(effects.beginDrain$);
+        actions$.next(ProcessGroupDrainActions.beginDrain({ request: { 
processGroupId: 'pg-1' } }));
+
+        expect(await result).toEqual(ProcessGroupDrainActions.drainApiError({ 
error: 'already draining' }));
+        expect(mockDialog.open).not.toHaveBeenCalled();
+    });
+
+    it('stops polling and reloads when a poll returns an ended drain', async 
() => {

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Should fix: This test's name claims more than it asserts.
   
   Why: `'stops polling and reloads when a poll returns an ended drain'` only 
asserts that `pollDrainSuccess$` emits `drainEnded`. It doesn't assert that 
polling stops or that a reload is dispatched, so a regression in either would 
still pass.
   
   Where: this `it(...)`.
   
   Fix: Either rename it to describe what it asserts (for example `'dispatches 
drainEnded when a poll returns an ended drain'`), or extend it to assert the 
behavior in the name: feed `drainEnded` into `drainEnded$` and expect 
`FlowActions.reloadFlow()`, and assert that the polling interval stops after an 
ended poll.
   



##########
nifi-frontend/src/main/frontend/libs/shared/src/components/status-badge/status-badge.component.scss:
##########
@@ -19,6 +19,7 @@
 
 .status-badge {
     .fa {
+        font-size: var(--mat-sys-body-small-size);

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Optional: The status badge measures differently from its design spec, and 
the new Draining badge is meant to match it.
   
   Why: In the running app the badge is 20px tall with 16px line-height, 0.4px 
letter-spacing, a 2px radius and a roughly 10.7x12px icon. The spec is 22px 
tall, 18px line-height, no letter-spacing, a 4px radius and a 16px icon slot. 
Padding (2px/6px), gap (2px), 12px size and weight 600 already match. The extra 
letter-spacing and tighter line-height come from the `text-sm` utility's theme 
values.
   
   Where: `status-badge.component.html` (class list on the `.status-badge` 
span, line 20) and this `.fa` rule.
   
   Fix:
   - In the html, replace `rounded-xs` with `rounded-sm` and add 
`leading-[18px] tracking-normal` after `text-sm`.
   - In this `.fa` rule, add `width: 16px; height: 16px; line-height: 16px; 
text-align: center;` next to the existing `font-size`.
   - This changes every status badge in the app, so it may be better as a 
follow-up. If it stays in this PR, update `status-badge.component.spec.ts` if 
it asserts any of these.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/process-group-drain/process-group-drain.effects.ts:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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, inject } from '@angular/core';
+import { Actions, createEffect, ofType } from '@ngrx/effects';
+import { concatLatestFrom } from '@ngrx/operators';
+import { Action, Store } from '@ngrx/store';
+import { HttpErrorResponse } from '@angular/common/http';
+import { MatDialog, MatDialogRef } from '@angular/material/dialog';
+import { NavigationStart, Router } from '@angular/router';
+import {
+    asyncScheduler,
+    catchError,
+    exhaustMap,
+    filter,
+    from,
+    interval,
+    map,
+    of,
+    switchMap,
+    take,
+    takeUntil,
+    tap
+} from 'rxjs';
+import {
+    ComponentType,
+    DrainBlockingComponentType,
+    isDefinedAndNotNull,
+    MEDIUM_DIALOG,
+    SMALL_DIALOG,
+    YesNoDialog
+} from '@nifi/shared';
+import * as ProcessGroupDrainActions from './process-group-drain.actions';
+import * as FlowActions from '../flow/flow.actions';
+import * as ErrorActions from '../../../../state/error/error.actions';
+import {
+    selectDrainDialogState,
+    selectDrainProcessGroupId,
+    selectDrainRequestId
+} from './process-group-drain.selectors';
+import { selectCurrentProcessGroupId } from '../flow/flow.selectors';
+import { ProcessGroupDrainService } from 
'../../../../service/process-group-drain.service';
+import { ErrorHelper } from '../../../../service/error-helper.service';
+import { DrainProcessGroupDialog } from 
'../../../../ui/common/drain-process-group-dialog/drain-process-group-dialog';
+import { NiFiState } from '../../../../state';
+
+const COMPONENT_TYPES: Record<DrainBlockingComponentType, ComponentType> = {
+    PROCESSOR: ComponentType.Processor,
+    INPUT_PORT: ComponentType.InputPort,
+    OUTPUT_PORT: ComponentType.OutputPort,
+    REMOTE_INPUT_PORT: ComponentType.RemoteProcessGroup
+};
+
+const POLLING_STOP_ACTIONS = [
+    ProcessGroupDrainActions.drainEnded,
+    ProcessGroupDrainActions.cancelDrain,
+    ProcessGroupDrainActions.resetDrainState,
+    ProcessGroupDrainActions.drainApiError
+] as const;
+
+@Injectable()
+export class ProcessGroupDrainEffects {
+    private actions$ = inject(Actions);
+    private store = inject<Store<NiFiState>>(Store);
+    private processGroupDrainService = inject(ProcessGroupDrainService);
+    private errorHelper = inject(ErrorHelper);
+    private dialog = inject(MatDialog);
+    private router = inject(Router);
+
+    private drainDialogRef: MatDialogRef<DrainProcessGroupDialog> | undefined;
+    private lastPrepared = false;
+
+    promptDrain$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.promptDrain),
+                map((action) => action.request),
+                tap((request) => {
+                    const dialogReference = this.dialog.open(YesNoDialog, {
+                        ...SMALL_DIALOG,
+                        data: {
+                            title: 'Drain Process Group',
+                            message:
+                                'Drain stops the components that bring data 
into this Process Group, enables the Controller Services its components 
reference, and starts the other components so the queued data can flow out. The 
drain ends when the group is empty or when you cancel it. Components keep their 
run state afterwards, so sources remain stopped. Are you sure you want to drain 
this Process Group?'
+                        }
+                    });
+
+                    
dialogReference.componentInstance.yes.pipe(take(1)).subscribe(() => {
+                        
this.store.dispatch(ProcessGroupDrainActions.beginDrain({ request }));
+                    });
+                })
+            ),
+        { dispatch: false }
+    );
+
+    beginDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.beginDrain),
+            map((action) => action.request),
+            switchMap((request) =>
+                
this.processGroupDrainService.beginDrain(request.processGroupId).pipe(
+                    map((response) =>
+                        ProcessGroupDrainActions.beginDrainSuccess({
+                            response: { drainRequestEntity: response }
+                        })
+                    ),
+                    catchError((errorResponse: HttpErrorResponse) => 
this.handleDrainApiError(errorResponse))
+                )
+            )
+        )
+    );
+
+    beginDrainSuccess$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.beginDrainSuccess),
+            concatLatestFrom(() => [
+                this.store.select(selectDrainProcessGroupId),
+                this.store.select(selectCurrentProcessGroupId)
+            ]),
+            switchMap(([action, processGroupId, currentProcessGroupId]) => {
+                this.lastPrepared = 
action.response.drainRequestEntity.drainRequest?.prepared === true;
+                const drainRequest = 
action.response.drainRequestEntity.drainRequest;
+                // drainEnded$ performs the reload when the drain has already 
ended, so the group is reloaded once
+                if (!drainRequest || drainRequest.state !== 'DRAINING') {
+                    return of(ProcessGroupDrainActions.drainEnded());
+                }
+                return from([
+                    this.reloadProcessGroupAction(processGroupId, 
currentProcessGroupId),
+                    ProcessGroupDrainActions.startPollingDrain()
+                ]);
+            })
+        )
+    );
+
+    openDrainDialog$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.beginDrainSuccess, 
ProcessGroupDrainActions.viewDrain),
+                tap(() => {
+                    if (this.drainDialogRef) {
+                        return;
+                    }
+
+                    const dialogReference = 
this.dialog.open(DrainProcessGroupDialog, {
+                        ...MEDIUM_DIALOG,
+                        disableClose: true,
+                        autoFocus: false
+                    });
+                    this.drainDialogRef = dialogReference;
+
+                    dialogReference.componentInstance.drainState$ = 
this.store.select(selectDrainDialogState);
+
+                    dialogReference.componentInstance.cancelDrain
+                        .pipe(takeUntil(dialogReference.afterClosed()))
+                        .subscribe(() => {
+                            
this.store.dispatch(ProcessGroupDrainActions.cancelDrain());
+                        });
+
+                    dialogReference.componentInstance.goToComponent
+                        .pipe(takeUntil(dialogReference.afterClosed()))
+                        .subscribe((component) => {
+                            
this.store.dispatch(ProcessGroupDrainActions.goToBlockingComponent({ component 
}));
+                        });
+
+                    dialogReference.afterClosed().subscribe(() => {
+                        this.drainDialogRef = undefined;
+                        this.lastPrepared = false;
+                        
this.store.dispatch(ProcessGroupDrainActions.resetDrainState());
+                    });
+                })
+            ),
+        { dispatch: false }
+    );
+
+    viewDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.viewDrain),
+            map(() => ProcessGroupDrainActions.startPollingDrain())
+        )
+    );
+
+    // viewDrain reaches this effect through viewDrain$, which dispatches 
startPollingDrain. Listening
+    // for both would still be a single interval because switchMap replaces 
the previous one, but it
+    // would restart the timer on every View.
+    startPollingDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.startPollingDrain),
+            switchMap(() =>
+                interval(2000, 
asyncScheduler).pipe(takeUntil(this.actions$.pipe(ofType(...POLLING_STOP_ACTIONS))))
+            ),
+            map(() => ProcessGroupDrainActions.pollDrain())
+        )
+    );
+
+    pollDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.pollDrain, 
ProcessGroupDrainActions.viewDrain),
+            concatLatestFrom(() => [
+                
this.store.select(selectDrainProcessGroupId).pipe(isDefinedAndNotNull()),
+                
this.store.select(selectDrainRequestId).pipe(isDefinedAndNotNull())
+            ]),
+            exhaustMap(([, processGroupId, drainRequestId]) =>
+                this.processGroupDrainService.getDrain(processGroupId, 
drainRequestId).pipe(
+                    map((response) =>
+                        ProcessGroupDrainActions.pollDrainSuccess({
+                            response: { drainRequestEntity: response }
+                        })
+                    ),
+                    catchError((errorResponse: HttpErrorResponse) => 
this.handleDrainApiError(errorResponse)),
+                    
takeUntil(this.actions$.pipe(ofType(...POLLING_STOP_ACTIONS)))
+                )
+            )
+        )
+    );
+
+    pollDrainSuccess$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.pollDrainSuccess),
+            concatLatestFrom(() => [
+                this.store.select(selectDrainProcessGroupId),
+                this.store.select(selectCurrentProcessGroupId)
+            ]),
+            switchMap(([action, processGroupId, currentProcessGroupId]) => {
+                const drainRequest = 
action.response.drainRequestEntity.drainRequest;
+                const actions: Action[] = [];
+                const isDraining = drainRequest?.state === 'DRAINING';
+                const prepared = drainRequest?.prepared === true;
+                // An ended drain is reloaded by drainEnded$, so the prepared 
flip only reloads while draining
+                if (isDraining && prepared && !this.lastPrepared) {
+                    actions.push(this.reloadProcessGroupAction(processGroupId, 
currentProcessGroupId));
+                }
+                this.lastPrepared = prepared;
+                if (!isDraining) {
+                    actions.push(ProcessGroupDrainActions.drainEnded());
+                }
+                return from(actions);
+            })
+        )
+    );
+
+    drainEnded$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.drainEnded, 
ProcessGroupDrainActions.cancelDrainSuccess),
+            concatLatestFrom(() => [
+                this.store.select(selectDrainProcessGroupId),
+                this.store.select(selectCurrentProcessGroupId)
+            ]),
+            map(([, processGroupId, currentProcessGroupId]) =>
+                this.reloadProcessGroupAction(processGroupId, 
currentProcessGroupId)

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Optional: The end-of-drain reload can be dropped when another reload 
happened within the previous second.
   
   Why: For the current process group, `reloadProcessGroupAction` returns 
`FlowActions.reloadFlow()`, and `reloadFlow$` in `flow.effects.ts` applies 
`throttleTime(1000)`. If the reload from `drainEnded$` lands within a second of 
another `reloadFlow` (for example the prepared-flip reload), it is dropped, and 
the group may keep showing the Draining badge until the next scheduled refresh.
   
   Where: `drainEnded$` here, and `reloadFlow$` in `flow.effects.ts`.
   
   Fix:
   - Either give the throttle a trailing emission (`throttleTime(1000, 
asyncScheduler, { leading: true, trailing: true })`), or have the end-of-drain 
path dispatch `FlowActions.loadProcessGroup` for the current group directly.
   - Tests: add a spec where `drainEnded` is dispatched within a second of a 
prepared-flip reload and assert a reload still happens.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/testing/process-group-drain-fixture.ts:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 {
+    DrainBlockingComponent,
+    ProcessGroupDrainRequest,
+    ProcessGroupDrainRequestEntity,
+    ProcessGroupDrainSummary
+} from '@nifi/shared';
+
+export function createDrainBlockingComponent(overrides: 
Partial<DrainBlockingComponent> = {}): DrainBlockingComponent {
+    return {
+        id: 'processor-1',
+        groupId: 'pg-1',
+        type: 'PROCESSOR',
+        name: 'GenerateFlowFile',
+        reason: 'INVALID',
+        validationErrors: ["'Run Schedule' is invalid"],
+        queuedCount: 3,
+        ...overrides
+    };
+}
+
+export function createProcessGroupDrainSummary(
+    overrides: Partial<ProcessGroupDrainSummary> = {}
+): ProcessGroupDrainSummary {
+    return {
+        id: 'drain-1',
+        prepared: true,
+        originalCount: 10,
+        originalSize: 1024,
+        currentCount: 4,
+        currentSize: 400,
+        ...overrides
+    };
+}
+
+export function createProcessGroupDrainRequest(
+    overrides: Partial<ProcessGroupDrainRequest> = {}
+): ProcessGroupDrainRequest {
+    return {
+        id: 'drain-1',
+        processGroupId: 'pg-1',
+        uri: '../nifi-api/process-groups/pg-1/drain-requests/drain-1',
+        state: 'DRAINING',
+        prepared: true,
+        originalCount: 10,
+        originalSize: 1024,
+        currentCount: 4,
+        currentSize: 400,
+        blockingComponents: [],
+        ...overrides
+    };
+}
+
+export function createProcessGroupDrainRequestEntity(
+    drainRequestOverrides: Partial<ProcessGroupDrainRequest> | null = {}
+): ProcessGroupDrainRequestEntity {
+    if (drainRequestOverrides === null) {
+        return {};
+    }

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Optional: `createProcessGroupDrainRequestEntity(null)` uses `null` to mean 
"return an empty entity", and this adds a new `testing/` directory with a 
single file.
   
   Why: The `null` sentinel is easy to misread at call sites. Other specs in 
this app build test data inline, so a shared fixture directory is new.
   
   Where: `createProcessGroupDrainRequestEntity` (lines 70-80).
   
   Fix: Replace the sentinel with an explicit helper such as 
`createEmptyDrainRequestEntity()`, and either keep the factories next to the 
specs that use them or keep the directory if more specs are expected to share 
it.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/operation-control/operation-control.component.html:
##########
@@ -30,6 +30,15 @@
     </mat-expansion-panel-header>
     <div class="flex flex-col gap-y-2">
         <component-context [type]="contextType()" [name]="contextName()" 
[id]="contextId()"></component-context>
+        @if (isDraining()) {

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Optional: Start and Stop controls are not gated for components that a drain 
restricts.
   
   Why: While a drain has data queued, the server rejects starting a source 
component and stopping any other component in the group 
(`verifyDrainAllowsStart` and `verifyDrainAllowsStop` in the DAOs). The Operate 
panel buttons, the context-menu Start and Stop items, and the Start and Stop 
controls in the Processor, Port and Controller Service dialogs all still offer 
those actions. The user clicks, waits for the request and gets an error. A 
Controller Service disable that would stop a running referencing Processor is 
rejected the same way. When the queue is empty, the same click succeeds and 
silently ends the drain.
   
   Where: the Operate panel buttons below this badge, the Start and Stop items 
in `canvas-context-menu.service.ts`, and `isStoppable` / `isRunnable` in 
`edit-processor.component.ts` (and the equivalent port and Controller Service 
dialogs).
   
   Fix:
   - Follow-up, together with the inherited drain information above. Disable or 
annotate Start and Stop for components the drain keeps stopped (sources) or 
running (everything else), with a tooltip such as "Kept running by the drain of 
<group>".
   - Alternatively, surface the server's rejection message in a clearer way, 
naming the drain and offering a View Drain link.
   - Tests: the controls are disabled or annotated for restricted components, 
and enabled again once the drain ends or is cancelled.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/tooltips/drain-summary-tip/drain-summary-tip.component.scss:
##########
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+.tooltip {
+    min-width: 240px;

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Nit: The `.tooltip { min-width: 240px; }` rule isn't needed.
   
   Why: The shared `.tooltip` rule in 
`libs/shared/src/assets/themes/material.scss` already constrains tooltip size 
(`max-width: 500px`, `padding: 10px`, `word-wrap: break-word`, `white-space: 
normal`). None of the other tooltip components under `ui/common/tooltips/` set 
a `min-width`, so this one is inconsistent and makes a short summary tooltip 
wider than its content.
   
   Where: this rule in `drain-summary-tip.component.scss`.
   
   Fix: Delete the rule and leave only the license header, as the other tip 
components do.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/tooltips/drain-summary-tip/drain-summary-tip.component.html:
##########
@@ -0,0 +1,28 @@
+<!--
+  ~ 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.
+  -->
+
+<div class="tooltip">
+    @if (data) {
+        <div class="flex flex-col gap-y-2">
+            <div>{{ title }}</div>
+            <mat-progress-bar
+                [mode]="isProgressIndeterminate() ? 'indeterminate' : 
'determinate'"
+                [value]="getPercentCompleted()"></mat-progress-bar>
+            <div class="tertiary-color font-medium">{{ getStatusDetail() 
}}</div>

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Nit: The tooltip lays out the progress bar and caption differently from the 
dialog that shows the same drain progress.
   
   Why: In `drain-process-group-dialog.html` the bar and caption sit in a 
`w-full flex flex-col items-center` wrapper with no gap between them. Here they 
are separate children of a `gap-y-2` stack with left-aligned text, so the same 
drain progress looks different in the tooltip and the dialog.
   
   Where: the `mat-progress-bar` and the status-detail line.
   
   Fix: Keep the `gap-y-2` stack for the title and the progress block, and wrap 
the bar and caption the way the dialog does:
   
   ```html
   <div class="flex flex-col gap-y-2">
       <div>{{ title }}</div>
       <div class="w-full flex flex-col items-center">
           <mat-progress-bar
               [mode]="isProgressIndeterminate() ? 'indeterminate' : 
'determinate'"
               [value]="getPercentCompleted()"></mat-progress-bar>
           <div class="tertiary-color font-medium">{{ getStatusDetail() }}</div>
       </div>
   </div>
   ```
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/canvas/utils/canvas-tooltip-overlay.ts:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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 { ComponentRef, Type } from '@angular/core';
+import { Overlay, OverlayRef, PositionStrategy } from '@angular/cdk/overlay';
+import { ComponentPortal } from '@angular/cdk/portal';
+import * as d3 from 'd3';
+import { NiFiCommon } from '@nifi/shared';
+
+export interface CanvasTooltipSession {
+    type: Type<unknown>;
+    data: unknown;
+    overlayRef: OverlayRef | null;
+    positionStrategy: PositionStrategy | null;
+    tooltipReference: ComponentRef<unknown> | null;
+    closeTimer: number;
+    openTimer: number;
+}
+
+export type CanvasTooltipSessionMap = WeakMap<Element, CanvasTooltipSession>;
+
+const TOOLTIP_POSITIONS = [
+    {
+        originX: 'end' as const,
+        originY: 'bottom' as const,
+        overlayX: 'start' as const,
+        overlayY: 'top' as const,
+        offsetX: 8,
+        offsetY: 8
+    }
+];
+
+function clearOpenTimer(session: CanvasTooltipSession): void {
+    if (session.openTimer > 0) {
+        window.clearTimeout(session.openTimer);
+        session.openTimer = -1;
+    }
+}
+
+function clearCloseTimer(session: CanvasTooltipSession): void {
+    if (session.closeTimer > 0) {
+        window.clearTimeout(session.closeTimer);
+        session.closeTimer = -1;
+    }
+}
+
+function disposeSession(session: CanvasTooltipSession): void {
+    clearOpenTimer(session);
+    clearCloseTimer(session);
+    session.overlayRef?.detach();
+    session.overlayRef?.dispose();
+    session.overlayRef = null;
+    session.tooltipReference = null;
+    session.positionStrategy?.detach?.();
+    session.positionStrategy?.dispose();
+    session.positionStrategy = null;
+}
+
+function refreshOpenTooltip(session: CanvasTooltipSession): void {
+    if (session.overlayRef?.hasAttached() && session.tooltipReference) {
+        session.tooltipReference.setInput('data', session.data);
+        session.tooltipReference.changeDetectorRef.detectChanges();
+        session.overlayRef.updatePosition();
+    }
+}
+
+function openTooltip(overlay: Overlay, element: Element, session: 
CanvasTooltipSession): void {
+    session.positionStrategy = overlay
+        .position()
+        .flexibleConnectedTo(element)
+        .withPositions(TOOLTIP_POSITIONS)
+        .withPush(true);
+    session.overlayRef = overlay.create({ positionStrategy: 
session.positionStrategy });
+    session.tooltipReference = session.overlayRef.attach(new 
ComponentPortal(session.type));
+    session.tooltipReference.setInput('data', session.data);
+    session.tooltipReference.changeDetectorRef.detectChanges();
+
+    const tooltipElement: HTMLElement = 
session.tooltipReference.location.nativeElement;
+    tooltipElement.addEventListener('mouseenter', () => 
clearCloseTimer(session));
+    tooltipElement.addEventListener('mouseleave', () => 
disposeSession(session));
+}
+
+/**
+ * Binds hover listeners that open a canvas overlay tooltip. If the tooltip is 
already open,
+ * the next bind (for example from a poll) updates its `data` input in place. 
A tooltip that is
+ * waiting to open uses the data from the latest bind.
+ */
+export function bindCanvasTooltip<C>(
+    overlay: Overlay,
+    sessions: CanvasTooltipSessionMap,
+    type: Type<C>,
+    selection: d3.Selection<any, any, any, any>,

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Should fix: `d3.Selection<any, any, any, any>` violates 
`@typescript-eslint/no-explicit-any`, which is an error for 
`src/app/ui/common/canvas/**`.
   
   Why: `apps/nifi/eslint.config.mjs` turns `no-explicit-any` off for the app 
but enables it as an error for `src/app/ui/common/canvas/**/*.ts`. Running `npx 
eslint src/app/ui/common/canvas/utils/` from `apps/nifi` reports 12 errors 
across this file and its spec. `nx lint nifi` from the workspace root doesn't 
report them, so CI doesn't catch it.
   
   Where: this parameter, line 170 in the same file, and the matching `openTip` 
signature in `canvas-tooltip-overlay.spec.ts` (line 72).
   
   Fix:
   - Type the `selection` parameters as `d3.Selection<d3.BaseType, unknown, 
d3.BaseType, unknown>`, or use a generic `<E extends d3.BaseType, D>`.
   - Update the spec casts to match.
   - Run `npx eslint src/app/ui/common/canvas/utils/` from `apps/nifi` and 
confirm zero errors.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/service/flow.service.ts:
##########
@@ -403,18 +403,6 @@ export class FlowService implements 
PropertyDescriptorRetriever {
         return 
this.httpClient.put(`${FlowService.API}/flow/process-groups/${request.id}`, 
stopRequest);
     }
 
-    stopSources(request: StopSourcesRequest): Observable<StopSourcesResponse> {

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Optional: This PR removes the Stop Sources action (context-menu item, 
action, effects and this service method). Please confirm that's intentional and 
call it out in the PR description.
   
   Why: Drain is not a drop-in replacement. It stops the sources, but it also 
enables the Controller Services the group's components reference and starts the 
other components so queued data can flow out. Users who only want to stop a 
group's source components lose that action.
   
   Where: the removed `stopSources` here, `FlowActions.stopSources`, the 
`stopSources$` effects in `flow.effects.ts`, and the `Stop Sources` menu item 
in `canvas-context-menu.service.ts`.
   
   Fix: If the removal is intentional, add a line to the PR description stating 
that Drain replaces Stop Sources and why. If it isn't, restore the menu item 
and its action.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/drain-process-group-dialog/drain-process-group-dialog.html:
##########
@@ -0,0 +1,101 @@
+<!--
+  ~ 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.
+  -->
+
+<h2 mat-dialog-title>Drain Process Group</h2>
+@if (drainState$ | async; as drainState) {
+    @if (getFailureMessages(drainState.drainRequest?.failureReason); as 
failureMessages) {
+        @if (failureMessages.length > 0) {
+            <error-banner [messages]="failureMessages" [showErrorIcon]="true" 
[allowDismiss]="false"></error-banner>
+        }
+    }
+    <div class="drain-process-group">
+        <mat-dialog-content>
+            <div class="flex flex-col gap-y-4">
+                <div class="tertiary-color font-medium" 
data-qa="drain-status-message">
+                    {{ getStatusMessage(drainState) }}
+                </div>
+                @if (drainState.drainRequest; as drainRequest) {
+                    <div class="w-full flex flex-col items-center">
+                        <mat-progress-bar
+                            [mode]="isProgressIndeterminate(drainRequest) ? 
'indeterminate' : 'determinate'"
+                            
[value]="getPercentCompleted(drainRequest)"></mat-progress-bar>
+                        <div class="tertiary-color font-medium" 
data-qa="drain-remaining">
+                            {{ getRemainingText(drainRequest) }}
+                        </div>
+                    </div>
+                    @if (drainRequest.blockingComponents.length > 0) {
+                        <div class="flex flex-col gap-y-2">
+                            <status-banner variant="caution" 
[allowDismiss]="false" data-qa="drain-blocking-banner">
+                                <div statusBannerTitle>{{ 
getBlockingBannerTitle(drainState) }}</div>
+                                <div statusBannerDescription>
+                                    Queued data cannot leave until the 
components below are fixed.
+                                </div>
+                            </status-banner>
+                            @for (component of 
drainRequest.blockingComponents; track component.id) {
+                                <div class="flex items-center gap-x-2" 
data-qa="drain-blocking-component">
+                                    @if 
(getBlockingTooltipComponent(component); as tooltipComponent) {
+                                        <div
+                                            class="fa fa-warning caution-color"
+                                            
data-qa="drain-blocking-component-warning"
+                                            nifiTooltip
+                                            
[tooltipComponentType]="tooltipComponent"
+                                            
[tooltipInputData]="getBlockingTooltipData(component)"
+                                            [delayClose]="true"></div>
+                                    } @else {
+                                        <div
+                                            class="fa fa-warning caution-color"
+                                            
data-qa="drain-blocking-component-warning"></div>
+                                    }
+                                    <div class="flex-1">
+                                        @if (drainState.status === 'ended') {
+                                            <a
+                                                class="pointer primary-color"
+                                                data-qa="drain-go-to"
+                                                
(click)="goToComponent.next(component)"
+                                                >{{ 
getBlockingComponentLabel(component) }}</a
+                                            >

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Optional: The Go To link is an `<a (click)>` with no `href`, and the warning 
icon has no accessible name.
   
   Why: An anchor without an `href` isn't reachable with the keyboard, and the 
`fa-warning` icon doesn't announce what it means to a screen reader.
   
   Where: the `drain-go-to` anchor here and the `fa fa-warning` icons above it 
(lines 51-61).
   
   Fix:
   - Use `<button type="button" class="..." 
(click)="goToComponent.next(component)">` styled as a link, or keep the anchor 
and add `tabindex="0"` with `(keydown.enter)`.
   - Add `aria-label="Warning"` to the warning icons.
   - Tests: the dialog spec asserts the Go To control is focusable and 
activates on Enter.
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/process-group-drain/process-group-drain.effects.ts:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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, inject } from '@angular/core';
+import { Actions, createEffect, ofType } from '@ngrx/effects';
+import { concatLatestFrom } from '@ngrx/operators';
+import { Action, Store } from '@ngrx/store';
+import { HttpErrorResponse } from '@angular/common/http';
+import { MatDialog, MatDialogRef } from '@angular/material/dialog';
+import { NavigationStart, Router } from '@angular/router';
+import {
+    asyncScheduler,
+    catchError,
+    exhaustMap,
+    filter,
+    from,
+    interval,
+    map,
+    of,
+    switchMap,
+    take,
+    takeUntil,
+    tap
+} from 'rxjs';
+import {
+    ComponentType,
+    DrainBlockingComponentType,
+    isDefinedAndNotNull,
+    MEDIUM_DIALOG,
+    SMALL_DIALOG,
+    YesNoDialog
+} from '@nifi/shared';
+import * as ProcessGroupDrainActions from './process-group-drain.actions';
+import * as FlowActions from '../flow/flow.actions';
+import * as ErrorActions from '../../../../state/error/error.actions';
+import {
+    selectDrainDialogState,
+    selectDrainProcessGroupId,
+    selectDrainRequestId
+} from './process-group-drain.selectors';
+import { selectCurrentProcessGroupId } from '../flow/flow.selectors';
+import { ProcessGroupDrainService } from 
'../../../../service/process-group-drain.service';
+import { ErrorHelper } from '../../../../service/error-helper.service';
+import { DrainProcessGroupDialog } from 
'../../../../ui/common/drain-process-group-dialog/drain-process-group-dialog';
+import { NiFiState } from '../../../../state';
+
+const COMPONENT_TYPES: Record<DrainBlockingComponentType, ComponentType> = {
+    PROCESSOR: ComponentType.Processor,
+    INPUT_PORT: ComponentType.InputPort,
+    OUTPUT_PORT: ComponentType.OutputPort,
+    REMOTE_INPUT_PORT: ComponentType.RemoteProcessGroup
+};
+
+const POLLING_STOP_ACTIONS = [
+    ProcessGroupDrainActions.drainEnded,
+    ProcessGroupDrainActions.cancelDrain,
+    ProcessGroupDrainActions.resetDrainState,
+    ProcessGroupDrainActions.drainApiError
+] as const;
+
+@Injectable()
+export class ProcessGroupDrainEffects {
+    private actions$ = inject(Actions);
+    private store = inject<Store<NiFiState>>(Store);
+    private processGroupDrainService = inject(ProcessGroupDrainService);
+    private errorHelper = inject(ErrorHelper);
+    private dialog = inject(MatDialog);
+    private router = inject(Router);
+
+    private drainDialogRef: MatDialogRef<DrainProcessGroupDialog> | undefined;
+    private lastPrepared = false;
+
+    promptDrain$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.promptDrain),
+                map((action) => action.request),
+                tap((request) => {
+                    const dialogReference = this.dialog.open(YesNoDialog, {
+                        ...SMALL_DIALOG,
+                        data: {
+                            title: 'Drain Process Group',
+                            message:
+                                'Drain stops the components that bring data 
into this Process Group, enables the Controller Services its components 
reference, and starts the other components so the queued data can flow out. The 
drain ends when the group is empty or when you cancel it. Components keep their 
run state afterwards, so sources remain stopped. Are you sure you want to drain 
this Process Group?'

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Optional: The confirmation message is a single long paragraph.
   
   Why: The key point (data keeps flowing out, sources stay stopped) is easy to 
miss in one sentence of about 70 words.
   
   Where: the `message` for the Drain Process Group `YesNoDialog` (lines 97-98).
   
   Fix: Split it into shorter sentences, for example: "Drain stops the 
components that bring data into this Process Group and lets the queued data 
flow out. Components keep their run state afterwards, so sources remain 
stopped. Are you sure you want to drain this Process Group?"
   



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/drain/drain-summary.utils.ts:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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 { NiFiCommon, ProcessGroupDrainSummary } from '@nifi/shared';
+
+export const DRAINING_DESCRIPTION = 'This Process Group is being drained.';
+
+export const DRAIN_WAITING_FOR_SOURCES = 'Waiting for source components to 
stop.';
+
+export const DRAIN_NO_FLOWFILES_REMAIN = 'No FlowFiles remain.';
+
+/**
+ * Percent of the original queue that has already drained.
+ */
+export function getDrainPercentCompleted(originalCount: number, currentCount: 
number): number {
+    if (originalCount === 0) {
+        return 100;
+    }
+    return Math.min(Math.max(Math.round(((originalCount - currentCount) * 100) 
/ originalCount), 0), 100);
+}
+
+export function getDrainRemainingText(
+    summary: Pick<ProcessGroupDrainSummary, 'currentCount' | 'currentSize' | 
'originalCount'>,
+    nifiCommon: NiFiCommon
+): string {
+    const currentCount = nifiCommon.formatInteger(summary.currentCount);
+    const currentSize = nifiCommon.formatDataSize(summary.currentSize);
+    const originalCount = nifiCommon.formatInteger(summary.originalCount);
+    return `${currentCount} FlowFiles (${currentSize}) remaining of 
${originalCount}`;
+}
+
+/**
+ * One-sentence progress detail shared by the canvas drain tooltip and the 
operate panel tooltip.
+ */
+export function getDrainStatusDetail(summary: ProcessGroupDrainSummary, 
nifiCommon: NiFiCommon): string {
+    if (!summary.prepared) {
+        return DRAIN_WAITING_FOR_SOURCES;
+    }
+    if (summary.currentCount === 0) {
+        return DRAIN_NO_FLOWFILES_REMAIN;
+    }
+    return `${getDrainRemainingText(summary, nifiCommon)}.`;
+}
+
+/**
+ * Text tooltip for the operate panel Draining badge.
+ */
+export function getDrainingTooltip(summary: ProcessGroupDrainSummary | null, 
nifiCommon: NiFiCommon): string {
+    if (!summary) {
+        return DRAINING_DESCRIPTION;
+    }
+    return `${DRAINING_DESCRIPTION} ${getDrainStatusDetail(summary, 
nifiCommon)}`;
+}
+
+/**
+ * Drain summary the operate panel reflects: the current group when nothing is 
selected, the
+ * selected group when exactly one Process Group is selected, and none 
otherwise.
+ */
+export function getOperationDrainSummary(

Review Comment:
   <!-- snapps-agent-authored -->
   > Posted by an AI agent on behalf of the user
   
   Optional: Components inside a draining group have no drain indicator, so a 
user there gets no hint why Start or Stop fails.
   
   Why: The backend applies the drain to everything beneath the drained group: 
`ProcessGroup.findActiveDrain()` walks up the parent groups, so a Processor in 
a child group is kept running or stopped just like one in the drained group. 
The UI only knows about the group itself. `createProcessGroupDrainSummaryDto` 
in `DtoFactory` checks `group.getDrain()`, which is the exact group, and this 
function only reflects the current group or the one selected Process Group. 
Someone in a child group, or selecting a Processor inside the drained group, 
sees no Draining badge and gets a plain error when Start or Stop is rejected.
   
   Where: `getOperationDrainSummary` here, and `drainSummary` on 
`ProcessGroupFlowDTO` / `ProcessGroupEntity`, which the backend sets for the 
drained group only.
   
   Fix:
   - This needs a backend addition, so it is probably best as a follow-up 
issue. For example, expose the closest active drain on `ProcessGroupFlowDTO` 
(an inherited drain id, or the drained group's id plus its summary), computed 
with `findActiveDrain()`.
   - Once available, show the Draining badge and tooltip in the Operate panel 
for any selection inside a draining group, and name the drained group.
   - Tests: for a group nested in a drained group, the Operate panel shows the 
badge with the drained group's name.
   



-- 
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]

Reply via email to