Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace businessKey #306

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions workspaces/orchestrator/.changeset/good-wasps-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@red-hat-developer-hub/backstage-plugin-orchestrator-common': patch
'@red-hat-developer-hub/backstage-plugin-orchestrator': patch
---

removing business key
5 changes: 5 additions & 0 deletions workspaces/orchestrator/.changeset/silly-horses-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@red-hat-developer-hub/backstage-plugin-orchestrator-backend': patch
---

replace business key with variable
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ describe('fetchInstances', () => {
definitionIds,
)}`;
const queryBody =
'id, processName, processId, businessKey, state, start, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}';
'id, processName, processId, state, start, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}';

const mockProcessInstances: ProcessInstance[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Backstage Authors
* Copyright Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { LoggerService } from '@backstage/backend-plugin-api';

import { Client, fetchExchange, gql } from '@urql/core';
Expand Down Expand Up @@ -299,7 +300,7 @@ export class DataIndexService {
const graphQlQuery = buildGraphQlQuery({
type: 'ProcessInstances',
queryBody:
'id, processName, processId, businessKey, state, start, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}',
'id, processName, processId, state, start, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}',
whereClause,
pagination,
});
Expand Down Expand Up @@ -456,7 +457,6 @@ export class DataIndexService {
processName
processId
serviceUrl
businessKey
state
start
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ export class OrchestratorService {
definitionId: string;
serviceUrl: string;
inputData?: ProcessInstanceVariables;
businessKey?: string;
cacheHandler?: CacheHandler;
}): Promise<WorkflowExecutionResponse | undefined> {
const { definitionId, cacheHandler } = args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,26 +192,6 @@ describe('SonataFlowService', () => {
expect(loggerMock.child).not.toHaveBeenCalled();
});

it('should include businessKey in the URL if provided', async () => {
// Given
const businessKey = 'key-123';
setupTest({ ok: true, json: { id: definitionId, status: 'completed' } });

// When
const result = await sonataFlowService.executeWorkflow({
definitionId,
serviceUrl,
inputData,
businessKey,
});

// Then
expect(fetch).toHaveBeenCalledWith(
`${serviceUrl}/${definitionId}?businessKey=${businessKey}`,
expectedFetchRequestInit(),
);
expect(result).toEqual({ id: definitionId, status: 'completed' });
});
it('should propagate thrown error when the fetch response is not ok without extra info', async () => {
// When
setupTest({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,8 @@ export class SonataFlowService {
definitionId: string;
serviceUrl: string;
inputData?: ProcessInstanceVariables;
businessKey?: string;
}): Promise<WorkflowExecutionResponse | undefined> {
const urlToFetch = args.businessKey
? `${args.serviceUrl}/${args.definitionId}?businessKey=${args.businessKey}`
: `${args.serviceUrl}/${args.definitionId}`;
const urlToFetch = `${args.serviceUrl}/${args.definitionId}`;

const response = await fetch(urlToFetch, {
method: 'POST',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Backstage Authors
* Copyright Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import moment from 'moment';

import {
Expand Down Expand Up @@ -133,7 +134,6 @@ export function mapToProcessInstanceDTO(
processName: processInstance.processName,
description: processInstance.description,
serviceUrl: processInstance.serviceUrl,
businessKey: processInstance.businessKey,
endpoint: processInstance.endpoint,
error: processInstance.error,
category: mapWorkflowCategoryDTO(processInstance.category),
Expand All @@ -142,6 +142,7 @@ export function mapToProcessInstanceDTO(
duration: duration,
// @ts-ignore
workflowdata: variables?.workflowdata,
assessmentInstanceId: variables?.orchestratorAssessmentInstanceId as string,
state: processInstance.state
? getProcessInstancesStatusDTOFromString(processInstance.state)
: undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Backstage Authors
* Copyright Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Request } from 'express';

import {
Expand Down Expand Up @@ -376,7 +377,6 @@ describe('executeWorkflow', () => {
const actualResultV2: ExecuteWorkflowResponseDTO = await v2.executeWorkflow(
workflowData,
workflowInfo.id,
'businessKey',
);

// Assert
Expand Down Expand Up @@ -484,9 +484,14 @@ describe('getInstanceById', () => {

it('Instance exists, assessment non empty string', async () => {
const processInstance = generateProcessInstance(1);
processInstance.businessKey = 'testBusinessKey';
const assessedBy = generateProcessInstance(1);
assessedBy.id = processInstance.businessKey;
if (
processInstance.variables &&
typeof processInstance.variables !== 'string'
) {
processInstance.variables.orchestratorAssessmentInstanceId =
assessedBy.id;
}

(mockOrchestratorService.fetchInstance as jest.Mock)
.mockResolvedValueOnce(processInstance)
Expand All @@ -501,9 +506,6 @@ describe('getInstanceById', () => {
expect(processInstanceV2).toBeDefined();
expect(processInstanceV2.instance).toBeDefined();
expect(processInstanceV2.assessedBy).toBeDefined();
expect(processInstanceV2.assessedBy?.id).toEqual(
processInstance.businessKey,
);
expect(processInstanceV2.instance.id).toEqual(processInstance.id);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
ProcessInstance,
ProcessInstanceListResultDTO,
ProcessInstanceState,
ProcessInstanceVariables,
WorkflowDTO,
WorkflowInfo,
WorkflowOverviewDTO,
Expand Down Expand Up @@ -141,9 +140,16 @@ export class V2 {

let assessedByInstance: ProcessInstance | undefined;

if (includeAssessment && instance.businessKey) {
let variables: Record<string, unknown> | undefined;
if (typeof instance.variables === 'string') {
variables = JSON.parse(instance?.variables);
} else {
variables = instance.variables;
}

if (includeAssessment && variables?.orchestratorAssessmentInstanceId) {
assessedByInstance = await this.orchestratorService.fetchInstance({
instanceId: instance.businessKey,
instanceId: variables.orchestratorAssessmentInstanceId as string,
cacheHandler: 'throw',
});
}
Expand All @@ -159,7 +165,6 @@ export class V2 {
public async executeWorkflow(
executeWorkflowRequestDTO: ExecuteWorkflowRequestDTO,
workflowId: string,
businessKey: string | undefined,
): Promise<ExecuteWorkflowResponseDTO> {
const definition = await this.orchestratorService.fetchWorkflowInfo({
definitionId: workflowId,
Expand All @@ -173,10 +178,12 @@ export class V2 {
}
const executionResponse = await this.orchestratorService.executeWorkflow({
definitionId: workflowId,
inputData:
executeWorkflowRequestDTO.inputData as ProcessInstanceVariables,
inputData: {
workflowdata: executeWorkflowRequestDTO.inputData,
orchestratorAssessmentInstanceId:
executeWorkflowRequestDTO.orchestratorAssessmentInstanceId,
},
serviceUrl: definition.serviceUrl,
businessKey,
cacheHandler: 'throw',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
orchestratorWorkflowSpecificPermission,
orchestratorWorkflowUsePermission,
orchestratorWorkflowUseSpecificPermission,
QUERY_PARAM_BUSINESS_KEY,
QUERY_PARAM_INCLUDE_ASSESSMENT,
WorkflowOverviewListResultDTO,
} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';
Expand Down Expand Up @@ -483,15 +482,10 @@ function setupInternalRoutes(
manageDenyAuthorization(endpointName, endpoint, req);
}

const businessKey = routerApi.v2.extractQueryParam(
c.request,
QUERY_PARAM_BUSINESS_KEY,
);

const executeWorkflowRequestDTO = req.body;

return routerApi.v2
.executeWorkflow(executeWorkflowRequestDTO, workflowId, businessKey)
.executeWorkflow(executeWorkflowRequestDTO, workflowId)
.then(result => res.status(200).json(result))
.catch(error => {
auditLogRequestError(error, endpointName, endpoint, req);
Expand Down
Loading
Loading