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

Orchestrator: replace businessKey #157

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
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
Expand Up @@ -497,7 +497,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 @@ -187,7 +187,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 @@ -91,11 +91,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
Expand Up @@ -163,7 +163,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 @@ -172,6 +171,7 @@ export function mapToProcessInstanceDTO(
duration: duration,
// @ts-ignore
workflowdata: variables?.workflowdata,
assessmentInstanceId: variables?.orchestratorAssessmentInstanceId,
status: getProcessInstancesStatusDTOFromString(processInstance.state),
nodes: processInstance.nodes.map(mapToNodeInstanceDTO),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ describe('executeWorkflow', () => {
const actualResultV2: ExecuteWorkflowResponseDTO = await v2.executeWorkflow(
workflowData,
workflowInfo.id,
'businessKey',
);

// Assert
Expand Down Expand Up @@ -489,9 +488,7 @@ 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;

(mockOrchestratorService.fetchInstance as jest.Mock)
.mockResolvedValueOnce(processInstance)
Expand All @@ -506,9 +503,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 @@ -147,9 +146,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 @@ -165,7 +171,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 @@ -179,10 +184,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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const QUERY_PARAM_BUSINESS_KEY = 'businessKey' as const;
export const QUERY_PARAM_INSTANCE_ID = 'instanceId' as const;
export const QUERY_PARAM_INCLUDE_ASSESSMENT = 'includeAssessment' as const;
export const QUERY_PARAM_ASSESSMENT_INSTANCE_ID =
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
91326c20d83a0f45099f3ba29eab13709d60a938
b437ddcc0b31dea1764b1e272ab429b1cedbfe7e
Loading
Loading