Skip to content

Commit

Permalink
fix(orchestrator): minor fixes (janus-idp#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
caponetto committed Jan 16, 2024
1 parent 71ded6b commit 07ecda8
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
import { Logger } from 'winston';

import {
default_catalog_environment,
default_catalog_owner,
DEFAULT_CATALOG_ENVIRONMENT,
DEFAULT_CATALOG_OWNER,
getWorkflowCategory,
orchestrator_service_ready_topic,
workflow_type,
ORCHESTRATOR_SERVICE_READY_TOPIC,
WORKFLOW_TYPE,
WorkflowCategory,
WorkflowItem,
} from '@janus-idp/backstage-plugin-orchestrator-common';
Expand Down Expand Up @@ -55,10 +55,10 @@ export class OrchestratorEntityProvider
);
const owner =
args.config.getOptionalString('orchestrator.catalog.owner') ??
default_catalog_owner;
DEFAULT_CATALOG_OWNER;
const environment =
args.config.getOptionalString('orchestrator.catalog.environment') ??
default_catalog_environment;
DEFAULT_CATALOG_ENVIRONMENT;

const orchestratorPluginUrl =
await args.discovery.getBaseUrl('orchestrator');
Expand Down Expand Up @@ -98,7 +98,7 @@ export class OrchestratorEntityProvider
}

supportsEventTopics(): string[] {
return [orchestrator_service_ready_topic];
return [ORCHESTRATOR_SERVICE_READY_TOPIC];
}

async connect(connection: EntityProviderConnection): Promise<void> {
Expand All @@ -115,7 +115,7 @@ export class OrchestratorEntityProvider
}

async onEvent(params: EventParams): Promise<void> {
if (params.topic !== orchestrator_service_ready_topic) {
if (params.topic !== ORCHESTRATOR_SERVICE_READY_TOPIC) {
return;
}
await this.run();
Expand Down Expand Up @@ -175,7 +175,7 @@ export class OrchestratorEntityProvider
},
spec: {
owner: this.owner,
type: workflow_type,
type: WORKFLOW_TYPE,
steps: [],
},
};
Expand Down
12 changes: 6 additions & 6 deletions plugins/orchestrator-backend/src/service/SonataFlowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { OpenAPIV3 } from 'openapi-types';
import { Logger } from 'winston';

import {
default_sonataflow_container_image,
default_sonataflow_persistance_path,
default_workflows_path,
DEFAULT_SONATAFLOW_CONTAINER_IMAGE,
DEFAULT_SONATAFLOW_PERSISTANCE_PATH,
DEFAULT_WORKFLOWS_PATH,
fromWorkflowSource,
getWorkflowCategory,
Job,
Expand Down Expand Up @@ -424,7 +424,7 @@ export class SonataFlowService {

private createLauncherCommand(): LauncherCommand {
const resourcesAbsPath = resolve(
join(this.connection.resourcesPath, default_workflows_path),
join(this.connection.resourcesPath, DEFAULT_WORKFLOWS_PATH),
);

const launcherArgs = [
Expand Down Expand Up @@ -482,12 +482,12 @@ export class SonataFlowService {

const containerImage =
config.getOptionalString('orchestrator.sonataFlowService.container') ??
default_sonataflow_container_image;
DEFAULT_SONATAFLOW_CONTAINER_IMAGE;

const persistencePath =
config.getOptionalString(
'orchestrator.sonataFlowService.persistence.path',
) ?? default_sonataflow_persistance_path;
) ?? DEFAULT_SONATAFLOW_PERSISTANCE_PATH;

const jiraHost = config.getOptionalString('orchestrator.jira.host');
const jiraBearerToken = config.getOptionalString(
Expand Down
20 changes: 10 additions & 10 deletions plugins/orchestrator-backend/src/service/WorkflowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import fs from 'fs-extra';
import { Logger } from 'winston';

import {
actions_open_api_file_path,
default_workflows_path,
ACTIONS_OPEN_API_FILE_PATH,
DEFAULT_WORKFLOWS_PATH,
extractWorkflowFormatFromUri,
fromWorkflowSource,
schemas_folder,
spec_files,
SCHEMAS_FOLDER,
SPEC_FILES,
toWorkflowString,
WorkflowItem,
WorkflowSpecFile,
Expand Down Expand Up @@ -111,7 +111,7 @@ export class WorkflowService {
}

async saveOpenApi(): Promise<void> {
const path = this.resolveResourcePath(actions_open_api_file_path);
const path = this.resolveResourcePath(ACTIONS_OPEN_API_FILE_PATH);
const openApi = await this.openApiService.generateOpenApi();
if (!openApi) {
return;
Expand Down Expand Up @@ -140,7 +140,7 @@ export class WorkflowService {
}

const workflowDataInputSchemaPath = join(
schemas_folder,
SCHEMAS_FOLDER,
dataInputSchema.compositionSchema.fileName,
);

Expand All @@ -151,7 +151,7 @@ export class WorkflowService {

dataInputSchema.actionSchemas.forEach(actionSchema => {
actionSchema.jsonSchema = {
$id: `classpath:/${schemas_folder}/${actionSchema.fileName}`,
$id: `classpath:/${SCHEMAS_FOLDER}/${actionSchema.fileName}`,
...actionSchema.jsonSchema,
};
});
Expand All @@ -163,7 +163,7 @@ export class WorkflowService {

const saveSchemaPromises = schemaFiles.map(schemaFile => {
const path = this.resolveResourcePath(
join(schemas_folder, schemaFile.fileName),
join(SCHEMAS_FOLDER, schemaFile.fileName),
);
return this.saveFile(path, schemaFile.jsonSchema);
});
Expand All @@ -181,7 +181,7 @@ export class WorkflowService {
async listStoredSpecs(): Promise<WorkflowSpecFile[]> {
const specs: WorkflowSpecFile[] = [];
// We can list all spec files from FS but let's keep it simple for now
for (const relativePath of spec_files) {
for (const relativePath of SPEC_FILES) {
const path = this.resolveResourcePath(relativePath);
const buffer = await fs.readFile(path);
const content = JSON.parse(buffer.toString('utf8'));
Expand All @@ -194,7 +194,7 @@ export class WorkflowService {
return resolve(
join(
this.sonataFlowService.resourcesPath,
default_workflows_path,
DEFAULT_WORKFLOWS_PATH,
relativePath,
),
);
Expand Down
6 changes: 3 additions & 3 deletions plugins/orchestrator-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Logger } from 'winston';

import {
fromWorkflowSource,
orchestrator_service_ready_topic,
ORCHESTRATOR_SERVICE_READY_TOPIC,
WorkflowDataInputSchemaResponse,
WorkflowItem,
WorkflowListResult,
Expand Down Expand Up @@ -98,7 +98,7 @@ export async function createBackendRouter(
await workflowService.reloadWorkflows();

await eventBroker.publish({
topic: orchestrator_service_ready_topic,
topic: ORCHESTRATOR_SERVICE_READY_TOPIC,
eventPayload: {},
});

Expand Down Expand Up @@ -320,7 +320,7 @@ function setupInternalRoutes(
}

await workflowService.deleteWorkflowDefinitionById(uri);
res.status(201).send();
res.status(200).send();
});

router.post('/workflows', async (req, res) => {
Expand Down
40 changes: 20 additions & 20 deletions plugins/orchestrator-common/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { WorkflowDefinition, WorkflowSample } from './types';

export const orchestrator_service_ready_topic = 'orchestrator-service-ready';
export const ORCHESTRATOR_SERVICE_READY_TOPIC = 'orchestrator-service-ready';

export const empty_definition: WorkflowDefinition = {
export const EMPTY_DEFINITION: WorkflowDefinition = {
id: 'workflow_unique_identifier',
version: '0.1',
specVersion: '0.8',
Expand Down Expand Up @@ -35,40 +35,40 @@ export const empty_definition: WorkflowDefinition = {
],
};

export const schemas_folder = 'schemas';
export const specs_folder = 'specs';
export const SCHEMAS_FOLDER = 'schemas';
export const SPECS_FOLDER = 'specs';

export const jira_open_api_file = 'jira-openapi.json';
export const jira_open_api_file_path = `${specs_folder}/${jira_open_api_file}`;
export const JIRA_OPEN_API_FILE = 'jira-openapi.json';
export const JIRA_OPEN_API_FILE_PATH = `${SPECS_FOLDER}/${JIRA_OPEN_API_FILE}`;

export const actions_open_api_file = 'actions-openapi.json';
export const actions_open_api_file_path = `${specs_folder}/${actions_open_api_file}`;
export const ACTIONS_OPEN_API_FILE = 'actions-openapi.json';
export const ACTIONS_OPEN_API_FILE_PATH = `${SPECS_FOLDER}/${ACTIONS_OPEN_API_FILE}`;

export const spec_files = [actions_open_api_file_path, jira_open_api_file_path];
export const SPEC_FILES = [ACTIONS_OPEN_API_FILE_PATH, JIRA_OPEN_API_FILE_PATH];

export const workflow_title = 'Workflow';
export const workflow_title_plural = 'Workflows';
export const workflow_type = 'workflow';
export const WORKFLOW_TITLE = 'Workflow';
export const WORKFLOW_TITLE_PLURAL = 'Workflows';
export const WORKFLOW_TYPE = 'workflow';

export const workflow_json_sample: WorkflowSample = {
export const WORKFLOW_JSON_SAMPLE: WorkflowSample = {
id: 'jsongreet',
url: 'https://raw.githubusercontent.com/kiegroup/kogito-examples/stable/serverless-workflow-examples/serverless-workflow-greeting-quarkus/src/main/resources/jsongreet.sw.json',
};

export const workflow_yaml_sample: WorkflowSample = {
export const WORKFLOW_YAML_SAMPLE: WorkflowSample = {
id: 'yamlgreet',
url: 'https://raw.githubusercontent.com/kiegroup/kogito-examples/stable/serverless-workflow-examples/serverless-workflow-greeting-quarkus/src/main/resources/yamlgreet.sw.yml',
};

// Default values for the orchestrator plugin configuration
export const default_sonataflow_container_image =
export const DEFAULT_SONATAFLOW_CONTAINER_IMAGE =
'quay.io/kiegroup/kogito-swf-devmode-nightly:main-2023-08-30';
export const default_sonataflow_persistance_path = '/home/kogito/persistence';
export const default_catalog_owner = 'orchestrator';
export const default_catalog_environment = 'development';
export const default_editor_path = 'https://start.kubesmarts.org';
export const DEFAULT_SONATAFLOW_PERSISTANCE_PATH = '/home/kogito/persistence';
export const DEFAULT_CATALOG_OWNER = 'orchestrator';
export const DEFAULT_CATALOG_ENVIRONMENT = 'development';
export const DEFAULT_EDITOR_PATH = 'https://start.kubesmarts.org';

export const default_workflows_path = 'workflows';
export const DEFAULT_WORKFLOWS_PATH = 'workflows';

export const ASSESSMENT_WORKFLOW_TYPE = 'workflow-type/assessment';
export const INFRASTRUCTURE_WORKFLOW_TYPE = 'workflow-type/infrastructure';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React, { PropsWithChildren } from 'react';

import { Content, Header, HeaderLabel, Page } from '@backstage/core-components';

import { workflow_title } from '@janus-idp/backstage-plugin-orchestrator-common';
import { WORKFLOW_TITLE } from '@janus-idp/backstage-plugin-orchestrator-common';

export const BaseOrchestratorPage = (props: PropsWithChildren<{}>) => {
return (
<Page themeId="tool">
<Header
title="Orchestrator"
subtitle={`Where all your ${workflow_title} needs come to life!`}
subtitle={`Where all your ${WORKFLOW_TITLE} needs come to life!`}
>
<HeaderLabel label="Owner" value="Team X" />
<HeaderLabel label="Lifecycle" value="Alpha" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useController } from '@kie-tools-core/react-hooks/dist/useController';
import { Grid } from '@material-ui/core';
import Button from '@material-ui/core/Button';

import { workflow_title } from '@janus-idp/backstage-plugin-orchestrator-common';
import { WORKFLOW_TITLE } from '@janus-idp/backstage-plugin-orchestrator-common';

import { orchestratorApiRef } from '../../api';
import {
Expand Down Expand Up @@ -132,7 +132,7 @@ export const CreateWorkflowPage = () => {
</Button>
)
}
title={workflowId ?? `New ${workflow_title}`}
title={workflowId ?? `New ${WORKFLOW_TITLE}`}
>
<div style={{ height: '600px', padding: '10px' }}>
<WorkflowEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { JSONSchema7 } from 'json-schema';

import {
getWorkflowCategory,
workflow_title,
WORKFLOW_TITLE,
WorkflowCategory,
WorkflowDataInputSchemaResponse,
} from '@janus-idp/backstage-plugin-orchestrator-common';
Expand Down Expand Up @@ -135,7 +135,7 @@ export const ExecuteWorkflowPage = (props: ExecuteWorkflowPageProps) => {
style={{ marginTop: 8, marginRight: 8 }}
onClick={_ => setWorkflowDialogOpen(true)}
>
View {workflow_title}
View {WORKFLOW_TITLE}
</Button>
<WorkflowDialog
kind={EditorViewKind.EXTENDED_DIAGRAM_VIEWER}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
} from '@material-ui/core';

import {
workflow_json_sample,
workflow_yaml_sample,
WORKFLOW_JSON_SAMPLE,
WORKFLOW_YAML_SAMPLE,
WorkflowFormat,
} from '@janus-idp/backstage-plugin-orchestrator-common';

Expand All @@ -42,7 +42,7 @@ export const NewWorkflowViewerPage = () => {
const createWorkflowLink = useRouteRef(createWorkflowRouteRef);

const defaultValues: FormData = {
url: workflow_json_sample.url,
url: WORKFLOW_JSON_SAMPLE.url,
};
const { handleSubmit, register, formState } = useForm<FormData>({
defaultValues,
Expand Down Expand Up @@ -167,17 +167,17 @@ export const NewWorkflowViewerPage = () => {
color="default"
variant="outlined"
style={{ marginTop: 8, marginRight: 8 }}
onClick={() => handleResult({ url: workflow_yaml_sample.url })}
onClick={() => handleResult({ url: WORKFLOW_YAML_SAMPLE.url })}
>
{workflow_yaml_sample.id}
{WORKFLOW_YAML_SAMPLE.id}
</Button>
<Button
color="default"
variant="outlined"
style={{ marginTop: 8, marginRight: 8 }}
onClick={() => handleResult({ url: workflow_json_sample.url })}
onClick={() => handleResult({ url: WORKFLOW_JSON_SAMPLE.url })}
>
{workflow_json_sample.id}
{WORKFLOW_JSON_SAMPLE.id}
</Button>
</Box>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useApi, useRouteRef } from '@backstage/core-plugin-api';
import { Button, Grid } from '@material-ui/core';

import {
workflow_title,
WORKFLOW_TITLE,
WorkflowItem,
} from '@janus-idp/backstage-plugin-orchestrator-common';

Expand Down Expand Up @@ -48,7 +48,7 @@ export const OrchestratorPage = () => {
color="primary"
onClick={() => navigate(newWorkflowLink())}
>
{`New ${workflow_title}`}
{`New ${WORKFLOW_TITLE}`}
</Button>
</Grid>
<Grid item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TemplateCardProps,
} from '@backstage/plugin-scaffolder-react/alpha';

import { workflow_type } from '@janus-idp/backstage-plugin-orchestrator-common';
import { WORKFLOW_TYPE } from '@janus-idp/backstage-plugin-orchestrator-common';

import { executeWorkflowRouteRef } from '../../routes';

Expand All @@ -21,7 +21,7 @@ export const OrchestratorScaffolderTemplateCard = (

const onSelectedExtended = useCallback(
(template: TemplateEntityV1beta3) => {
const isWorkflow = template.spec.type === workflow_type;
const isWorkflow = template.spec.type === WORKFLOW_TYPE;

if (!isWorkflow) {
onSelected?.(template);
Expand Down
Loading

0 comments on commit 07ecda8

Please sign in to comment.