forked from janus-idp/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orchestrator): add backend endpoint for getting workflows from d…
…ata index service (janus-idp#39) * feat: add backend for getting work flows from data index service * feat: cherrypick - add backend for getting work flows from data index service * feat: cherrypick - add backend for getting work flows from data index service * feat: cherrypick - add backend for getting work flows from data index service
- Loading branch information
Showing
12 changed files
with
246 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export const NO_DATA_INDEX_URL = 'NO_DATA_INDEX_URL'; | ||
export const NO_BACKEND_EXEC_CTX = 'NO_BACKEND_EXEC_CTX'; | ||
export const NO_CLIENT_PROVIDED = 'NO_CLIENT_PROVIDED'; | ||
export const NO_LOGGER = 'NO_LOGGER'; | ||
export const SWF_BACKEND_NOT_INITED = 'SWF_BACKEND_NOT_INITED'; | ||
|
||
export class ErrorBuilder { | ||
public static NewBackendError(name: string, message: string): Error { | ||
const e = new Error(message); | ||
e.name = name; | ||
return e; | ||
} | ||
|
||
public static GET_NO_DATA_INDEX_URL_ERR(): Error { | ||
return this.NewBackendError( | ||
NO_DATA_INDEX_URL, | ||
'No data index url specified or found', | ||
); | ||
} | ||
|
||
public static GET_NO_BACKEND_EXEC_CTX_ERR(): Error { | ||
return this.NewBackendError( | ||
NO_BACKEND_EXEC_CTX, | ||
'No or null backend execution context provided', | ||
); | ||
} | ||
|
||
public static GET_NO_CLIENT_PROVIDED_ERR(): Error { | ||
return this.NewBackendError( | ||
NO_CLIENT_PROVIDED, | ||
'No or null graphql client', | ||
); | ||
} | ||
|
||
public static GET_SWF_BACKEND_NOT_INITED(): Error { | ||
return this.NewBackendError( | ||
SWF_BACKEND_NOT_INITED, | ||
'The SonataFlow backend is not initialized, call initialize() method before trying to get the workflows.', | ||
); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
plugins/orchestrator-backend/src/service/DataIndexService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { cacheExchange, Client, fetchExchange } from '@urql/core'; | ||
|
||
import { WorkflowDefinition } from '@janus-idp/backstage-plugin-orchestrator-common'; | ||
|
||
import { ErrorBuilder } from '../helpers/errorBuilder'; | ||
import { BackendExecCtx } from '../types/backendExecCtx'; | ||
import { DEFAULT_DATA_INDEX_URL } from '../types/constants'; | ||
|
||
export class DataIndexService { | ||
public static backendExecCtx: BackendExecCtx; | ||
private static inited = false; | ||
|
||
public static initialize(backendExecCtx: BackendExecCtx) { | ||
if (!backendExecCtx) { | ||
throw ErrorBuilder.GET_NO_BACKEND_EXEC_CTX_ERR(); | ||
} | ||
|
||
if ( | ||
!backendExecCtx.dataIndexUrl || | ||
backendExecCtx.dataIndexUrl.length === 0 | ||
) { | ||
throw ErrorBuilder.GET_NO_DATA_INDEX_URL_ERR(); | ||
} | ||
|
||
if (!backendExecCtx.client) { | ||
throw ErrorBuilder.GET_NO_CLIENT_PROVIDED_ERR(); | ||
} | ||
|
||
if (!this.inited) { | ||
this.backendExecCtx = backendExecCtx; | ||
this.inited = true; | ||
this.backendExecCtx.logger.info('Initialized the swf backend'); | ||
} | ||
} | ||
|
||
public static getNewGraphQLClient( | ||
dataIndexUrl = DEFAULT_DATA_INDEX_URL, | ||
): Client { | ||
const diURL = | ||
this.backendExecCtx && this.backendExecCtx.dataIndexUrl | ||
? this.backendExecCtx.dataIndexUrl | ||
: dataIndexUrl; | ||
return new Client({ | ||
url: diURL, | ||
exchanges: [cacheExchange, fetchExchange], | ||
}); | ||
} | ||
|
||
private static getDeployedSwfsQuery() { | ||
return ` | ||
query ProcessDefinitions { | ||
ProcessDefinitions { | ||
id | ||
name | ||
version | ||
type | ||
endpoint | ||
serviceUrl | ||
} | ||
} | ||
`; | ||
} | ||
|
||
public static async getWorkflowDefinitions(): Promise<WorkflowDefinition[]> { | ||
if (!this.inited) { | ||
throw ErrorBuilder.GET_SWF_BACKEND_NOT_INITED(); | ||
} | ||
const QUERY = this.getDeployedSwfsQuery(); | ||
this.backendExecCtx.logger.info( | ||
`getWorkflowDefinitions() called: ${this.backendExecCtx.dataIndexUrl}`, | ||
); | ||
const result = await this.backendExecCtx.client.query(QUERY, {}); | ||
|
||
if (result.error) { | ||
this.backendExecCtx.logger.error( | ||
`Error fetching data index swf results ${result.error}`, | ||
); | ||
throw result.error; | ||
} | ||
return result.data.ProcessDefinitions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export interface ApiResponse { | ||
message?: String; | ||
result?: any; | ||
backEndErrCd?: String; | ||
} | ||
|
||
export class ApiResponseBuilder { | ||
static SUCCESS_RESPONSE(result: any, message = 'success'): ApiResponse { | ||
return { | ||
result: result, | ||
message: message, | ||
}; | ||
} | ||
|
||
static VALIDATION_ERR_RESPONSE( | ||
backEndErrCd = 'backend validation error code', | ||
message = 'backend validation error', | ||
): ApiResponse { | ||
return { | ||
message: message, | ||
backEndErrCd: backEndErrCd, | ||
}; | ||
} | ||
|
||
static HTTP_ERR_RESPONSE(message = 'Internal Server Error'): ApiResponse { | ||
return { | ||
result: null, | ||
message: message, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Client } from '@urql/core'; | ||
import { Logger } from 'winston'; | ||
|
||
import { DEFAULT_DATA_INDEX_URL } from './constants'; | ||
|
||
export class BackendExecCtx { | ||
constructor( | ||
public logger: Logger, | ||
public client: Client, | ||
public dataIndexUrl = DEFAULT_DATA_INDEX_URL, | ||
) { | ||
this.dataIndexUrl = dataIndexUrl; | ||
this.logger = logger; | ||
this.client = client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const DEFAULT_DATA_INDEX_URL = 'http://localhost:8080/graphql'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
# yarn lockfile v1 | ||
|
||
|
||
"@0no-co/graphql.web@^1.0.1": | ||
version "1.0.4" | ||
resolved "https://registry.yarnpkg.com/@0no-co/graphql.web/-/graphql.web-1.0.4.tgz#9606eb651955499525d068ce0ad8bea596286ce2" | ||
integrity sha512-W3ezhHGfO0MS1PtGloaTpg0PbaT8aZSmmaerL7idtU5F7oCI+uu25k+MsMS31BVFlp4aMkHSrNRxiD72IlK8TA== | ||
|
||
"@aashutoshrathi/word-wrap@^1.2.3": | ||
version "1.2.6" | ||
resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf" | ||
|
@@ -13409,6 +13414,14 @@ | |
"@uiw/codemirror-extensions-basic-setup" "4.21.20" | ||
codemirror "^6.0.0" | ||
|
||
"@urql/core@^4.1.4": | ||
version "4.2.0" | ||
resolved "https://registry.yarnpkg.com/@urql/core/-/core-4.2.0.tgz#7715491bc07e4af8b5d5039a19ea562cd109ae2f" | ||
integrity sha512-GRkZ4kECR9UohWAjiSk2UYUetco6/PqSrvyC4AH6g16tyqEShA63M232cfbE1J9XJPaGNjia14Gi+oOqzp144w== | ||
dependencies: | ||
"@0no-co/graphql.web" "^1.0.1" | ||
wonka "^6.3.2" | ||
|
||
"@webassemblyjs/[email protected]", "@webassemblyjs/ast@^1.11.5": | ||
version "1.11.6" | ||
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.6.tgz#db046555d3c413f8966ca50a95176a0e2c642e24" | ||
|
@@ -30898,6 +30911,11 @@ winston@^3.11.0, winston@^3.2.1: | |
triple-beam "^1.3.0" | ||
winston-transport "^4.5.0" | ||
|
||
wonka@^6.3.2: | ||
version "6.3.4" | ||
resolved "https://registry.yarnpkg.com/wonka/-/wonka-6.3.4.tgz#76eb9316e3d67d7febf4945202b5bdb2db534594" | ||
integrity sha512-CjpbqNtBGNAeyNS/9W6q3kSkKE52+FjIj7AkFlLr11s/VWGUu6a2CdYSdGxocIhIVjaW/zchesBQUKPVU69Cqg== | ||
|
||
word-wrap@^1.2.3, word-wrap@~1.2.3: | ||
version "1.2.5" | ||
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" | ||
|