Skip to content

Commit

Permalink
NIFI-13119: When evaluating dependent Properties, the UI should ident…
Browse files Browse the repository at this point in the history
…ify when the Property value is a parameter reference and resolve the value accordingly (apache#8724)

* NIFI-13119:
- When evaluating dependent Properties, the UI should identify when the Property value is a parameter reference and resolve the value accordingly.

* NIFI-13119:
- Requiring a value to be present when showing dependent property that doesn't require any specific value.

* NIFI-13119:
- Using error helper to get error string.

* NIFI-13119:
- Handle convert to parameter error scenario.

This closes apache#8724
  • Loading branch information
mcgilman authored and shubhluck committed Jun 1, 2024
1 parent 1839890 commit 9aff130
Show file tree
Hide file tree
Showing 29 changed files with 305 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,48 @@

import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { catchError, EMPTY, filter, map, Observable, switchMap, take, takeUntil, tap } from 'rxjs';
import { catchError, EMPTY, filter, map, Observable, switchMap, takeUntil, tap } from 'rxjs';
import { Store } from '@ngrx/store';
import { HttpErrorResponse } from '@angular/common/http';
import { NiFiState } from '../../../state';
import { ParameterService } from './parameter.service';
import { Client } from '../../../service/client.service';
import { EditParameterRequest, EditParameterResponse, Parameter, ParameterEntity } from '../../../state/shared';
import { EditParameterRequest, EditParameterResponse, ParameterContext, ParameterEntity } from '../../../state/shared';
import { EditParameterDialog } from '../../../ui/common/edit-parameter-dialog/edit-parameter-dialog.component';
import { selectParameterSaving, selectParameterState } from '../state/parameter/parameter.selectors';
import { ParameterState } from '../state/parameter';
import * as ErrorActions from '../../../state/error/error.actions';
import * as ParameterActions from '../state/parameter/parameter.actions';
import { FlowService } from './flow.service';
import { MEDIUM_DIALOG } from '../../../index';
import { ClusterConnectionService } from '../../../service/cluster-connection.service';
import { ErrorHelper } from '../../../service/error-helper.service';

export interface ConvertToParameterResponse {
propertyValue: string;
parameterContext?: ParameterContext;
}

@Injectable({
providedIn: 'root'
})
export class ParameterHelperService {
constructor(
private dialog: MatDialog,
private store: Store<NiFiState>,
private flowService: FlowService,
private parameterService: ParameterService,
private clusterConnectionService: ClusterConnectionService,
private client: Client,
private errorHelper: ErrorHelper
) {}

/**
* Returns a function that can be used to pass into a PropertyTable to retrieve available Parameters.
*
* @param parameterContextId the current Parameter Context id
*/
getParameters(parameterContextId: string): (sensitive: boolean) => Observable<Parameter[]> {
return (sensitive: boolean) => {
return this.flowService.getParameterContext(parameterContextId).pipe(
take(1),
catchError((errorResponse: HttpErrorResponse) => {
this.store.dispatch(
ErrorActions.snackBarError({ error: this.errorHelper.getErrorString(errorResponse) })
);

// consider the error handled and allow the user to reattempt the action
return EMPTY;
}),
map((response) => response.component.parameters),
map((parameterEntities) => {
return parameterEntities
.map((parameterEntity: ParameterEntity) => parameterEntity.parameter)
.filter((parameter: Parameter) => parameter.sensitive == sensitive);
})
);
};
}

/**
* Returns a function that can be used to pass into a PropertyTable to convert a Property into a Parameter, inline.
*
* @param parameterContextId the current Parameter Context id
*/
convertToParameter(
parameterContextId: string
): (name: string, sensitive: boolean, value: string | null) => Observable<string> {
): (name: string, sensitive: boolean, value: string | null) => Observable<ConvertToParameterResponse> {
return (name: string, sensitive: boolean, value: string | null) => {
return this.parameterService.getParameterContext(parameterContextId, false).pipe(
catchError((errorResponse: HttpErrorResponse) => {
Expand Down Expand Up @@ -127,6 +103,7 @@ export class ParameterHelperService {
request: {
id: parameterContextId,
payload: {
id: parameterContextEntity.id,
revision: this.client.getRevision(parameterContextEntity),
disconnectedNodeAcknowledged:
this.clusterConnectionService.isDisconnectionAcknowledged(),
Expand All @@ -139,19 +116,33 @@ export class ParameterHelperService {
})
);

let parameterContext: ParameterContext;

return this.store.select(selectParameterState).pipe(
takeUntil(convertToParameterDialogReference.afterClosed()),
tap((parameterState: ParameterState) => {
if (parameterState.error) {
// if the convert to parameter sequence stores an error,
// throw it to avoid the completion mapping logic below
throw new Error(parameterState.error);
} else if (parameterState.updateRequestEntity?.request.failureReason) {
// if the convert to parameter sequence completes successfully
// with an error, throw the message
throw new Error(parameterState.updateRequestEntity?.request.failureReason);
}

if (parameterState.saving) {
parameterContext = parameterState.updateRequestEntity?.request.parameterContext;
}
}),
filter((parameterState: ParameterState) => !parameterState.saving),
filter((parameterState) => !parameterState.saving),
map(() => {
convertToParameterDialogReference.close();
return `#{${dialogResponse.parameter.name}}`;

return {
propertyValue: `#{${dialogResponse.parameter.name}}`,
parameterContext
} as ConvertToParameterResponse;
}),
catchError((error) => {
convertToParameterDialogReference.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { ParameterHelperService } from '../../service/parameter-helper.service';
import { LARGE_DIALOG, SMALL_DIALOG, XL_DIALOG } from '../../../../index';
import { ExtensionTypesService } from '../../../../service/extension-types.service';
import { ChangeComponentVersionDialog } from '../../../../ui/common/change-component-version-dialog/change-component-version-dialog';
import { FlowService } from '../../service/flow.service';

@Injectable()
export class ControllerServicesEffects {
Expand All @@ -61,6 +62,7 @@ export class ControllerServicesEffects {
private store: Store<NiFiState>,
private client: Client,
private controllerServiceService: ControllerServiceService,
private flowService: FlowService,
private errorHelper: ErrorHelper,
private dialog: MatDialog,
private router: Router,
Expand Down Expand Up @@ -236,6 +238,34 @@ export class ControllerServicesEffects {
this.store.select(selectParameterContext),
this.store.select(selectCurrentProcessGroupId)
]),
switchMap(([request, parameterContextReference, processGroupId]) => {
if (parameterContextReference && parameterContextReference.permissions.canRead) {
return from(this.flowService.getParameterContext(parameterContextReference.id)).pipe(
map((parameterContext) => {
return [request, parameterContext, processGroupId];
}),
tap({
error: (errorResponse: HttpErrorResponse) => {
this.store.dispatch(
ControllerServicesActions.selectControllerService({
request: {
processGroupId,
id: request.id
}
})
);
this.store.dispatch(
ErrorActions.snackBarError({
error: this.errorHelper.getErrorString(errorResponse)
})
);
}
})
);
}

return of([request, null, processGroupId]);
}),
tap(([request, parameterContext, processGroupId]) => {
const serviceId: string = request.id;

Expand Down Expand Up @@ -282,10 +312,6 @@ export class ControllerServicesEffects {
};

if (parameterContext != null) {
editDialogReference.componentInstance.getParameters = this.parameterHelperService.getParameters(
parameterContext.id
);

editDialogReference.componentInstance.parameterContext = parameterContext;
editDialogReference.componentInstance.goToParameter = () => {
const commands: string[] = ['/parameter-contexts', parameterContext.id];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,34 @@ export class FlowEffects {
this.store.select(selectCurrentParameterContext),
this.store.select(selectCurrentProcessGroupId)
]),
switchMap(([request, parameterContextReference, processGroupId]) => {
if (parameterContextReference && parameterContextReference.permissions.canRead) {
return from(this.flowService.getParameterContext(parameterContextReference.id)).pipe(
map((parameterContext) => {
return [request, parameterContext, processGroupId];
}),
tap({
error: (errorResponse: HttpErrorResponse) => {
this.store.dispatch(
FlowActions.selectComponents({
request: {
components: [
{
id: request.entity.id,
componentType: request.type
}
]
}
})
);
this.store.dispatch(this.snackBarOrFullScreenError(errorResponse));
}
})
);
}

return of([request, null, processGroupId]);
}),
tap(([request, parameterContext, processGroupId]) => {
const processorId: string = request.entity.id;

Expand Down Expand Up @@ -1239,10 +1267,6 @@ export class FlowEffects {
};

if (parameterContext != null) {
editDialogReference.componentInstance.getParameters = this.parameterHelperService.getParameters(
parameterContext.id
);

editDialogReference.componentInstance.parameterContext = parameterContext;
editDialogReference.componentInstance.goToParameter = () => {
const commands: string[] = ['/parameter-contexts', parameterContext.id];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ComponentHistory,
ComponentType,
DocumentedType,
ParameterContextEntity,
ParameterContextReferenceEntity,
Permissions,
RegistryClientEntity,
Expand All @@ -30,7 +31,6 @@ import {
SparseVersionedFlow,
VersionedFlowSnapshotMetadataEntity
} from '../../../../state/shared';
import { ParameterContextEntity } from '../../../parameter-contexts/state/parameter-context-listing';
import { HttpErrorResponse } from '@angular/common/http';

export const flowFeatureKey = 'flowState';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ import { MatTabsModule } from '@angular/material/tabs';
import { MatOptionModule } from '@angular/material/core';
import { MatSelectModule } from '@angular/material/select';
import { Observable } from 'rxjs';
import { SelectOption } from '../../../../../../../state/shared';
import { ParameterContextEntity, SelectOption } from '../../../../../../../state/shared';
import { Client } from '../../../../../../../service/client.service';
import { PropertyTable } from '../../../../../../../ui/common/property-table/property-table.component';
import { NifiSpinnerDirective } from '../../../../../../../ui/common/spinner/nifi-spinner.directive';
import { NifiTooltipDirective } from '../../../../../../../ui/common/tooltips/nifi-tooltip.directive';
import { TextTip } from '../../../../../../../ui/common/tooltips/text-tip/text-tip.component';
import { ParameterContextEntity } from '../../../../../../parameter-contexts/state/parameter-context-listing';
import { ControllerServiceTable } from '../../../../../../../ui/common/controller-service/controller-service-table/controller-service-table.component';
import { EditComponentDialogRequest } from '../../../../../state/flow';
import { ClusterConnectionService } from '../../../../../../../service/cluster-connection.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ <h2 mat-dialog-title>
formControlName="properties"
[createNewProperty]="createNewProperty"
[createNewService]="createNewService"
[getParameters]="getParameters"
[goToParameter]="goToParameter"
[parameterContext]="parameterContext"
[convertToParameter]="convertToParameter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import { Observable } from 'rxjs';
import {
InlineServiceCreationRequest,
InlineServiceCreationResponse,
Parameter,
ParameterContextReferenceEntity,
ParameterContextEntity,
Property,
SelectOption
} from '../../../../../../../state/shared';
Expand All @@ -49,6 +48,7 @@ import {
import { ErrorBanner } from '../../../../../../../ui/common/error-banner/error-banner.component';
import { ClusterConnectionService } from '../../../../../../../service/cluster-connection.service';
import { CanvasUtils } from '../../../../../service/canvas-utils.service';
import { ConvertToParameterResponse } from '../../../../../service/parameter-helper.service';

@Component({
selector: 'edit-processor',
Expand Down Expand Up @@ -76,10 +76,13 @@ import { CanvasUtils } from '../../../../../service/canvas-utils.service';
export class EditProcessor {
@Input() createNewProperty!: (existingProperties: string[], allowsSensitive: boolean) => Observable<Property>;
@Input() createNewService!: (request: InlineServiceCreationRequest) => Observable<InlineServiceCreationResponse>;
@Input() getParameters!: (sensitive: boolean) => Observable<Parameter[]>;
@Input() parameterContext: ParameterContextReferenceEntity | undefined;
@Input() parameterContext: ParameterContextEntity | undefined;
@Input() goToParameter!: (parameter: string) => void;
@Input() convertToParameter!: (name: string, sensitive: boolean, value: string | null) => Observable<string>;
@Input() convertToParameter!: (
name: string,
sensitive: boolean,
value: string | null
) => Observable<ConvertToParameterResponse>;
@Input() goToService!: (serviceId: string) => void;
@Input() saving$!: Observable<boolean>;
@Output() editProcessor: EventEmitter<UpdateProcessorRequest> = new EventEmitter<UpdateProcessorRequest>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import { Observable } from 'rxjs';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Client } from '../../../service/client.service';
import { NiFiCommon } from '../../../service/nifi-common.service';
import { CreateParameterContextRequest, DeleteParameterContextRequest } from '../state/parameter-context-listing';
import {
CreateParameterContextRequest,
DeleteParameterContextRequest,
ParameterContextEntity
} from '../state/parameter-context-listing';
import { ParameterContextUpdateRequest, SubmitParameterContextUpdate } from '../../../state/shared';
ParameterContextEntity,
ParameterContextUpdateRequest,
SubmitParameterContextUpdate
} from '../../../state/shared';
import { ClusterConnectionService } from '../../../service/cluster-connection.service';

@Injectable({ providedIn: 'root' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
* limitations under the License.
*/

import {
ParameterContextReferenceEntity,
ParameterContextUpdateRequestEntity,
ParameterEntity,
ParameterProviderConfigurationEntity,
Permissions,
Revision
} from '../../../../state/shared';
import { ParameterContextEntity, ParameterContextUpdateRequestEntity } from '../../../../state/shared';

export const parameterContextListingFeatureKey = 'parameterContextListing';

Expand Down Expand Up @@ -59,31 +52,6 @@ export interface SelectParameterContextRequest {
id: string;
}

export interface ParameterContextEntity {
revision: Revision;
permissions: Permissions;
id: string;
uri: string;
component: ParameterContext;
}

export interface ParameterContext {
id: string;
name: string;
description: string;
parameters: ParameterEntity[];
boundProcessGroups: BoundProcessGroup[];
inheritedParameterContexts: ParameterContextReferenceEntity[];
parameterProviderConfiguration?: ParameterProviderConfigurationEntity;
}

// TODO - Replace this with ProcessGroupEntity was available
export interface BoundProcessGroup {
permissions: Permissions;
id: string;
component: any;
}

export interface ParameterContextListingState {
parameterContexts: ParameterContextEntity[];
updateRequestEntity: ParameterContextUpdateRequestEntity | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

import { createSelector } from '@ngrx/store';
import { ParameterContextsState, selectParameterContextState } from '../index';
import { ParameterContextEntity, parameterContextListingFeatureKey, ParameterContextListingState } from './index';
import { parameterContextListingFeatureKey, ParameterContextListingState } from './index';
import { selectCurrentRoute } from '../../../../state/router/router.selectors';
import { ParameterContextEntity } from '../../../../state/shared';

export const selectParameterContextListingState = createSelector(
selectParameterContextState,
Expand Down
Loading

0 comments on commit 9aff130

Please sign in to comment.