Skip to content

Commit

Permalink
feat(orchestrator): add endpoint for retrieving single workflow insta…
Browse files Browse the repository at this point in the history
…nces (#2268)

FLPATH-1694
https://issues.redhat.com/browse/FLPATH-1694
we added /v2/workflows/{workflowId}/instances

Signed-off-by: Yaron Dayagi <ydayagi@redhat.com>
  • Loading branch information
ydayagi authored Oct 6, 2024
1 parent 1e520dd commit c9393d3
Show file tree
Hide file tree
Showing 11 changed files with 681 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# comma delimited path of files to exclude from copy/paste duplicate checking
sonar.cpd.exclusions=packages/cli/src/lib/bundler/scalprumConfig.ts
sonar.cpd.exclusions=plugins/orchestrator-common/src/generated/**,packages/cli/src/lib/bundler/scalprumConfig.ts
15 changes: 10 additions & 5 deletions plugins/orchestrator-backend/src/service/OrchestratorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,23 @@ export class OrchestratorService {
public async fetchInstances(args: {
pagination?: Pagination;
filter?: FilterInfo;
workflowId?: string;
}): Promise<ProcessInstance[]> {
const definitionIds = args.workflowId
? [args.workflowId]
: this.workflowCacheService.definitionIds;
return await this.dataIndexService.fetchInstances({
definitionIds: this.workflowCacheService.definitionIds,
definitionIds: definitionIds,
pagination: args.pagination,
filter: args.filter,
});
}

public async fetchInstancesTotalCount(): Promise<number> {
return await this.dataIndexService.fetchInstancesTotalCount(
this.workflowCacheService.definitionIds,
);
public async fetchInstancesTotalCount(workflowId?: string): Promise<number> {
const definitionIds = workflowId
? [workflowId]
: this.workflowCacheService.definitionIds;
return await this.dataIndexService.fetchInstancesTotalCount(definitionIds);
}

public async fetchWorkflowSource(args: {
Expand Down
4 changes: 3 additions & 1 deletion plugins/orchestrator-backend/src/service/api/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ export class V2 {
public async getInstances(
pagination?: Pagination,
filter?: FilterInfo,
workflowId?: string,
): Promise<ProcessInstanceListResultDTO> {
const instances = await this.orchestratorService.fetchInstances({
pagination,
filter,
workflowId,
});
const totalCount =
await this.orchestratorService.fetchInstancesTotalCount();
await this.orchestratorService.fetchInstancesTotalCount(workflowId);

const result: ProcessInstanceListResultDTO = {
items: instances?.map(mapToProcessInstanceDTO),
Expand Down
33 changes: 33 additions & 0 deletions plugins/orchestrator-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,39 @@ function setupInternalRoutes(
},
);

// v2
routerApi.openApiBackend.register(
'getWorkflowInstances',
async (c, req: express.Request, res: express.Response, next) => {
const endpointName = 'getWorkflowInstances';
const workflowId = c.request.params.workflowId as string;
const endpoint = `/v2/workflows/${workflowId}/instances`;

auditLogger.auditLog({
eventName: endpointName,
stage: 'start',
status: 'succeeded',
level: 'debug',
request: req,
message: `Received request to '${endpoint}' endpoint`,
});

const decision = await authorize(
req,
orchestratorWorkflowInstancesReadPermission,
permissions,
httpAuth,
);
if (decision.result === AuthorizeResult.DENY) {
manageDenyAuthorization(endpointName, endpoint, req);
}
await routerApi.v2
.getInstances(buildPagination(req), buildFilter(req), workflowId)
.then(result => res.json(result))
.catch(next);
},
);

// v2
routerApi.openApiBackend.register(
'getInstances',
Expand Down
2 changes: 1 addition & 1 deletion plugins/orchestrator-common/src/generated/.METADATA.sha1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dafd6a712ec5abf3cf6be47f4f216c3e9c36b699
93059f9ed87bfe29bf2ea6dfebf85e3342dcb573

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions plugins/orchestrator-common/src/generated/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,44 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
options: localVarRequestOptions,
};
},
/**
* Retrieve an array of workflow executions (instances) for the given workflow
* @summary Get instances for a specific workflow
* @param {string} workflowId ID of the workflow
* @param {GetInstancesRequestParams} [getInstancesRequestParams] Parameters for retrieving workflow instances
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getWorkflowInstances: async (workflowId: string, getInstancesRequestParams?: GetInstancesRequestParams, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'workflowId' is not null or undefined
assertParamExists('getWorkflowInstances', 'workflowId', workflowId)
const localVarPath = `/v2/workflows/{workflowId}/instances`
.replace(`{${"workflowId"}}`, encodeURIComponent(String(workflowId)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;



localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = serializeDataIfNeeded(getInstancesRequestParams, localVarRequestOptions, configuration)

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* Returns the key fields of the workflow including data on the last run instance
* @param {string} workflowId Unique identifier of the workflow
Expand Down Expand Up @@ -1251,6 +1289,20 @@ export const DefaultApiFp = function(configuration?: Configuration) {
const localVarOperationServerBasePath = operationServerMap['DefaultApi.getWorkflowInputSchemaById']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
* Retrieve an array of workflow executions (instances) for the given workflow
* @summary Get instances for a specific workflow
* @param {string} workflowId ID of the workflow
* @param {GetInstancesRequestParams} [getInstancesRequestParams] Parameters for retrieving workflow instances
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getWorkflowInstances(workflowId: string, getInstancesRequestParams?: GetInstancesRequestParams, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ProcessInstanceListResultDTO>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getWorkflowInstances(workflowId, getInstancesRequestParams, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['DefaultApi.getWorkflowInstances']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
* Returns the key fields of the workflow including data on the last run instance
* @param {string} workflowId Unique identifier of the workflow
Expand Down Expand Up @@ -1370,6 +1422,17 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa
getWorkflowInputSchemaById(workflowId: string, instanceId?: string, options?: any): AxiosPromise<object> {
return localVarFp.getWorkflowInputSchemaById(workflowId, instanceId, options).then((request) => request(axios, basePath));
},
/**
* Retrieve an array of workflow executions (instances) for the given workflow
* @summary Get instances for a specific workflow
* @param {string} workflowId ID of the workflow
* @param {GetInstancesRequestParams} [getInstancesRequestParams] Parameters for retrieving workflow instances
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getWorkflowInstances(workflowId: string, getInstancesRequestParams?: GetInstancesRequestParams, options?: any): AxiosPromise<ProcessInstanceListResultDTO> {
return localVarFp.getWorkflowInstances(workflowId, getInstancesRequestParams, options).then((request) => request(axios, basePath));
},
/**
* Returns the key fields of the workflow including data on the last run instance
* @param {string} workflowId Unique identifier of the workflow
Expand Down Expand Up @@ -1489,6 +1552,19 @@ export class DefaultApi extends BaseAPI {
return DefaultApiFp(this.configuration).getWorkflowInputSchemaById(workflowId, instanceId, options).then((request) => request(this.axios, this.basePath));
}

/**
* Retrieve an array of workflow executions (instances) for the given workflow
* @summary Get instances for a specific workflow
* @param {string} workflowId ID of the workflow
* @param {GetInstancesRequestParams} [getInstancesRequestParams] Parameters for retrieving workflow instances
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof DefaultApi
*/
public getWorkflowInstances(workflowId: string, getInstancesRequestParams?: GetInstancesRequestParams, options?: RawAxiosRequestConfig) {
return DefaultApiFp(this.configuration).getWorkflowInstances(workflowId, getInstancesRequestParams, options).then((request) => request(this.axios, this.basePath));
}

/**
* Returns the key fields of the workflow including data on the last run instance
* @param {string} workflowId Unique identifier of the workflow
Expand Down
Loading

0 comments on commit c9393d3

Please sign in to comment.