Skip to content

Commit d976fe1

Browse files
shaileshpadaveShailesh Jagannath PadaveShailesh Jagannath PadaveShailesh Jagannath Padave
authored
SDK Changes for API Orch (#73)
* WF Execution Endpoint changes * Few code changes * Added Service Registry client and test * Updated test * Updated response to SignalResponse * Updated Test * Updated Test * Add more timeout * Code cleanup --------- Co-authored-by: Shailesh Jagannath Padave <shaileshpadave@192.168.1.3> Co-authored-by: Shailesh Jagannath Padave <shaileshpadave@192.168.1.4> Co-authored-by: Shailesh Jagannath Padave <shaileshpadave@192.168.1.2>
1 parent 6042c12 commit d976fe1

20 files changed

Lines changed: 3349 additions & 1319 deletions

src/common/open-api/ConductorClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { request as baseRequest } from "./core/request";
1616
import { ConductorHttpRequest } from "../RequestCustomizer";
1717
import { HumanTaskService } from "./services/HumanTaskService";
1818
import { HumanTaskResourceService } from "./services/HumanTaskResourceService";
19+
import {ServiceRegistryResourceService} from "./services/ServiceRegistryResourceService";
1920

2021
export const defaultRequestHandler: ConductorHttpRequest = (
2122
request,
@@ -51,6 +52,7 @@ export class ConductorClient {
5152
public readonly tokenResource: TokenResourceService;
5253
public readonly workflowBulkResource: WorkflowBulkResourceService;
5354
public readonly workflowResource: WorkflowResourceService;
55+
public readonly serviceRegistryResource: ServiceRegistryResourceService;
5456

5557
public readonly humanTask: HumanTaskService;
5658
public readonly humanTaskResource: HumanTaskResourceService;
@@ -100,6 +102,7 @@ export class ConductorClient {
100102
this.tokenResource = new TokenResourceService(this.request);
101103
this.workflowBulkResource = new WorkflowBulkResourceService(this.request);
102104
this.workflowResource = new WorkflowResourceService(this.request);
105+
this.serviceRegistryResource = new ServiceRegistryResourceService(this.request);
103106
this.humanTask = new HumanTaskService(this.request);
104107
this.humanTaskResource = new HumanTaskResourceService(this.request);
105108
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
5+
// Service Registry Type enum
6+
export enum ServiceType {
7+
HTTP = 'HTTP',
8+
gRPC = 'gRPC'
9+
}
10+
11+
// Request Parameter Schema interface
12+
export interface RequestParamSchema {
13+
type: string;
14+
format?: string;
15+
defaultValue?: any;
16+
}
17+
18+
// Request Parameter interface
19+
export interface RequestParam {
20+
name: string;
21+
type: string; // Query, Header, Path, etc.
22+
required: boolean;
23+
schema?: RequestParamSchema;
24+
}
25+
26+
// Service Method interface
27+
export interface ServiceMethod {
28+
id?: number;
29+
operationName: string;
30+
methodName: string;
31+
methodType: string; // GET, PUT, POST, UNARY, SERVER_STREAMING etc.
32+
inputType: string;
33+
outputType: string;
34+
requestParams?: RequestParam[];
35+
exampleInput?: Record<string, any>; // Sample input request
36+
}
37+
38+
// Circuit Breaker Configuration interface
39+
export interface OrkesCircuitBreakerConfig {
40+
failureRateThreshold?: number; // Percentage (e.g., 50.0 for 50%)
41+
slidingWindowSize?: number;
42+
minimumNumberOfCalls?: number;
43+
waitDurationInOpenState?: number; // In millisec
44+
permittedNumberOfCallsInHalfOpenState?: number;
45+
slowCallRateThreshold?: number; // Percentage of slow calls
46+
slowCallDurationThreshold?: number; // Defines "slow" call duration in milliSec
47+
automaticTransitionFromOpenToHalfOpenEnabled?: boolean; // Auto transition
48+
maxWaitDurationInHalfOpenState?: number; // Max time in HALF-OPEN state
49+
}
50+
51+
// Service Registry Configuration interface
52+
export interface ServiceRegistryConfig {
53+
circuitBreakerConfig?: OrkesCircuitBreakerConfig;
54+
}
55+
56+
// Service Registry interface
57+
export interface ServiceRegistry {
58+
name: string;
59+
type: ServiceType;
60+
serviceURI: string;
61+
methods?: ServiceMethod[];
62+
requestParams?: RequestParam[];
63+
config?: ServiceRegistryConfig;
64+
}
65+
66+
// Circuit Breaker Transition Response interface
67+
export interface CircuitBreakerTransitionResponse {
68+
service: string;
69+
previousState: string;
70+
currentState: string;
71+
transitionTimestamp: number;
72+
message: string;
73+
}
74+
75+
// Proto Registry Entry interface
76+
export interface ProtoRegistryEntry {
77+
filename: string;
78+
lastUpdated: number;
79+
}
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
5+
import type { Task } from './Task';
6+
import type { Workflow } from './Workflow';
7+
8+
/**
9+
* SignalResponse represents a unified response from the signal API
10+
*/
11+
export class SignalResponse {
12+
// ========== COMMON FIELDS IN ALL RESPONSES ==========
13+
14+
/** Type of response based on return strategy */
15+
responseType?: string;
16+
17+
/** ID of the target workflow */
18+
targetWorkflowId?: string;
19+
20+
/** Status of the target workflow */
21+
targetWorkflowStatus?: string;
22+
23+
/** ID of the workflow */
24+
workflowId?: string;
25+
26+
/** Input data for the workflow/task */
27+
input?: Record<string, any>;
28+
29+
/** Output data from the workflow/task */
30+
output?: Record<string, any>;
31+
32+
/** Priority of the workflow */
33+
priority?: number;
34+
35+
/** Workflow variables */
36+
variables?: Record<string, any>;
37+
38+
// ========== FIELDS SPECIFIC TO TARGET_WORKFLOW & BLOCKING_WORKFLOW ==========
39+
40+
/** Array of tasks in the workflow */
41+
tasks?: Array<Task>;
42+
43+
/** User who created the workflow */
44+
createdBy?: string;
45+
46+
/** Timestamp when workflow was created */
47+
createTime?: number;
48+
49+
/** Current status of the workflow */
50+
status?: string;
51+
52+
/** Timestamp when workflow was last updated */
53+
updateTime?: number;
54+
55+
// ========== FIELDS SPECIFIC TO BLOCKING_TASK & BLOCKING_TASK_INPUT ==========
56+
57+
/** Type of the blocking task */
58+
taskType?: string;
59+
60+
/** ID of the blocking task */
61+
taskId?: string;
62+
63+
/** Reference name of the blocking task */
64+
referenceTaskName?: string;
65+
66+
/** Number of retries for the task */
67+
retryCount?: number;
68+
69+
/** Definition name of the task */
70+
taskDefName?: string;
71+
72+
/** Type of the workflow containing the task */
73+
workflowType?: string;
74+
75+
// ========== CHECK METHODS ==========
76+
77+
/**
78+
* Returns true if the response contains target workflow details
79+
*/
80+
isTargetWorkflow(): boolean {
81+
return this.responseType === 'TARGET_WORKFLOW';
82+
}
83+
84+
/**
85+
* Returns true if the response contains blocking workflow details
86+
*/
87+
isBlockingWorkflow(): boolean {
88+
return this.responseType === 'BLOCKING_WORKFLOW';
89+
}
90+
91+
/**
92+
* Returns true if the response contains blocking task details
93+
*/
94+
isBlockingTask(): boolean {
95+
return this.responseType === 'BLOCKING_TASK';
96+
}
97+
98+
/**
99+
* Returns true if the response contains blocking task input
100+
*/
101+
isBlockingTaskInput(): boolean {
102+
return this.responseType === 'BLOCKING_TASK_INPUT';
103+
}
104+
105+
// ========== EXTRACTION METHODS ==========
106+
107+
/**
108+
* Extracts workflow details from a SignalResponse
109+
* @throws Error if the response type doesn't contain workflow details
110+
*/
111+
getWorkflow(): Workflow {
112+
if (!this.isTargetWorkflow() && !this.isBlockingWorkflow()) {
113+
throw new Error(
114+
`Response type ${this.responseType} does not contain workflow details`
115+
);
116+
}
117+
118+
return {
119+
workflowId: this.workflowId!,
120+
status: this.status!,
121+
tasks: this.tasks || [],
122+
createdBy: this.createdBy,
123+
createTime: this.createTime,
124+
updateTime: this.updateTime,
125+
input: this.input || {},
126+
output: this.output || {},
127+
variables: this.variables || {},
128+
priority: this.priority
129+
} as Workflow;
130+
}
131+
132+
/**
133+
* Extracts task details from a SignalResponse
134+
* @throws Error if the response type doesn't contain task details
135+
*/
136+
getBlockingTask(): Task {
137+
if (!this.isBlockingTask() && !this.isBlockingTaskInput()) {
138+
throw new Error(
139+
`Response type ${this.responseType} does not contain task details`
140+
);
141+
}
142+
143+
return {
144+
taskId: this.taskId!,
145+
taskType: this.taskType!,
146+
taskDefName: this.taskDefName!,
147+
referenceTaskName: this.referenceTaskName!,
148+
retryCount: this.retryCount || 0,
149+
status: this.status,
150+
inputData: this.input || {},
151+
outputData: this.output || {},
152+
workflowInstanceId: this.workflowId!,
153+
workflowType: this.workflowType!
154+
} as Task;
155+
}
156+
157+
/**
158+
* Extracts task input from a SignalResponse
159+
* Only valid for BLOCKING_TASK_INPUT responses
160+
* @throws Error if the response type doesn't contain task input details
161+
*/
162+
getTaskInput(): Record<string, any> {
163+
if (!this.isBlockingTaskInput()) {
164+
throw new Error(
165+
`Response type ${this.responseType} does not contain task input details`
166+
);
167+
}
168+
169+
return this.input || {};
170+
}
171+
172+
// ========== UTILITY METHODS ==========
173+
174+
/**
175+
* Get the workflow ID from the response
176+
*/
177+
getWorkflowId(): string {
178+
return this.workflowId || this.targetWorkflowId || '';
179+
}
180+
181+
/**
182+
* Get the target workflow ID from the response
183+
*/
184+
getTargetWorkflowId(): string {
185+
return this.targetWorkflowId || this.workflowId || '';
186+
}
187+
188+
/**
189+
* Check if the response has workflow data
190+
*/
191+
hasWorkflowData(): boolean {
192+
return this.isTargetWorkflow() || this.isBlockingWorkflow();
193+
}
194+
195+
/**
196+
* Check if the response has task data
197+
*/
198+
hasTaskData(): boolean {
199+
return this.isBlockingTask() || this.isBlockingTaskInput();
200+
}
201+
202+
/**
203+
* Get response type as string
204+
*/
205+
getResponseType(): string {
206+
return this.responseType || '';
207+
}
208+
209+
/**
210+
* Check if the workflow/task is in a terminal state
211+
*/
212+
isTerminal(): boolean {
213+
const terminalStates = ['COMPLETED', 'FAILED', 'TERMINATED', 'TIMED_OUT'];
214+
return terminalStates.includes(this.status || '');
215+
}
216+
217+
/**
218+
* Check if the workflow/task is currently running
219+
*/
220+
isRunning(): boolean {
221+
return this.status === 'RUNNING';
222+
}
223+
224+
/**
225+
* Check if the workflow/task is paused
226+
*/
227+
isPaused(): boolean {
228+
return this.status === 'PAUSED';
229+
}
230+
231+
/**
232+
* Get a summary of the response for logging
233+
*/
234+
getSummary(): string {
235+
const parts = [
236+
`type=${this.responseType}`,
237+
`workflowId=${this.workflowId}`,
238+
`status=${this.status}`
239+
];
240+
241+
if (this.hasTaskData()) {
242+
parts.push(`taskId=${this.taskId}`);
243+
parts.push(`taskType=${this.taskType}`);
244+
}
245+
246+
if (this.hasWorkflowData() && this.tasks) {
247+
parts.push(`tasksCount=${this.tasks.length}`);
248+
}
249+
250+
return `SignalResponse{${parts.join(', ')}}`;
251+
}
252+
253+
/**
254+
* Convert to JSON for debugging (excludes large objects)
255+
*/
256+
toDebugJSON(): Record<string, any> {
257+
return {
258+
responseType: this.responseType,
259+
workflowId: this.workflowId,
260+
targetWorkflowId: this.targetWorkflowId,
261+
targetWorkflowStatus: this.targetWorkflowStatus,
262+
status: this.status,
263+
taskId: this.taskId,
264+
taskType: this.taskType,
265+
referenceTaskName: this.referenceTaskName,
266+
createTime: this.createTime,
267+
updateTime: this.updateTime,
268+
priority: this.priority,
269+
retryCount: this.retryCount,
270+
tasksCount: this.tasks?.length,
271+
hasInput: Boolean(this.input && Object.keys(this.input).length > 0),
272+
hasOutput: Boolean(this.output && Object.keys(this.output).length > 0),
273+
hasVariables: Boolean(this.variables && Object.keys(this.variables).length > 0)
274+
};
275+
}
276+
277+
/**
278+
* String representation for debugging
279+
*/
280+
toString(): string {
281+
return this.getSummary();
282+
}
283+
}

0 commit comments

Comments
 (0)