Skip to content

Commit

Permalink
chore(orchestrator): add Category to the procesInstance result (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
mareklibra authored and caponetto committed Jan 16, 2024
1 parent 3accbc9 commit 0bfc646
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
14 changes: 14 additions & 0 deletions plugins/orchestrator-backend/src/helpers/workflows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {
ASSESSMENT_WORKFLOW_TYPE,
WorkflowCategory,
WorkflowDefinition,
} from '@janus-idp/backstage-plugin-orchestrator-common';

export const getWorkflowCategory = (
workflowDefinition?: WorkflowDefinition,
): WorkflowCategory =>
workflowDefinition?.annotations?.find(
annotation => annotation === ASSESSMENT_WORKFLOW_TYPE,
)
? WorkflowCategory.ASSESSMENT
: WorkflowCategory.INFRASTRUCTURE;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
import { Logger } from 'winston';

import {
ASSESSMENT_WORKFLOW_TYPE,
default_catalog_environment,
default_catalog_owner,
orchestrator_service_ready_topic,
Expand All @@ -27,6 +26,8 @@ import {
WorkflowItem,
} from '@janus-idp/backstage-plugin-orchestrator-common';

import { getWorkflowCategory } from '../helpers/workflows';

export class OrchestratorEntityProvider
implements EntityProvider, EventSubscriber
{
Expand Down Expand Up @@ -156,11 +157,8 @@ export class OrchestratorEntityProvider
): TemplateEntityV1beta3[] {
return items.map(i => {
const sanitizedId = i.definition.id.replace(/ /g, '_');
const category: WorkflowCategory = i.definition.annotations?.find(
annotation => annotation === ASSESSMENT_WORKFLOW_TYPE,
)
? WorkflowCategory.ASSESSMENT
: WorkflowCategory.INFRASTRUCTURE;
const category: WorkflowCategory = getWorkflowCategory(i.definition);

return {
apiVersion: 'scaffolder.backstage.io/v1beta3',
kind: 'Template',
Expand Down
16 changes: 15 additions & 1 deletion plugins/orchestrator-backend/src/service/SonataFlowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { spawn } from 'child_process';
import { join, resolve } from 'path';

import { getWorkflowCategory } from '../helpers/workflows';
import { executeWithRetry } from './Helper';

const SONATA_FLOW_RESOURCES_PATH =
Expand Down Expand Up @@ -242,6 +243,7 @@ export class SonataFlowService {
return this.fetchWorkflowOverview(workflowId);
}),
);

return items.filter((item): item is WorkflowOverview => !!item);
}
const responseStr = JSON.stringify(response);
Expand Down Expand Up @@ -295,7 +297,19 @@ export class SonataFlowService {

if (response.ok) {
const json = await response.json();
return (json.data.ProcessInstances as ProcessInstance[])?.pop();
const processInstance = (
json.data.ProcessInstances as ProcessInstance[]
)?.pop();

if (processInstance?.processId) {
const workflowDefinition = await this.fetchWorkflowDefinition(
processInstance.processId,
);

processInstance.category = getWorkflowCategory(workflowDefinition);
}

return processInstance;
}
} catch (error) {
this.logger.error(`Error when fetching instance: ${error}`);
Expand Down
3 changes: 3 additions & 0 deletions plugins/orchestrator-common/src/models.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { WorkflowCategory } from './types';

export enum ProcessInstanceState {
Active = 'ACTIVE',
Completed = 'COMPLETED',
Expand Down Expand Up @@ -75,6 +77,7 @@ export interface ProcessInstance {
diagram?: string;
nodeDefinitions?: TriggerableNode[];
source?: string;
category?: WorkflowCategory;
}

export enum JobStatus {
Expand Down

0 comments on commit 0bfc646

Please sign in to comment.