Skip to content

Commit 9540e10

Browse files
committed
Specify Adapter when sending Sequence
1 parent 1dcb09a commit 9540e10

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

packages/api-client/src/host-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class HostClient implements ClientProvider {
8080
*/
8181
async sendSequence(
8282
sequencePackage: Parameters<HttpClient["sendStream"]>[1],
83-
requestInit?: RequestInit,
83+
requestInit: RequestInit = {},
8484
update?: boolean
8585
): Promise<SequenceClient> {
8686
const response = await this.client.sendStream<any>("sequence", sequencePackage, requestInit, {

packages/cli/src/lib/commands/sequence.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ export const sequence: CommandDefinition = (program) => {
7878
.command("send")
7979
.argument("<package>", "The file or directory to upload or '-' to use the last packed. If directory, it will be packed and sent.")
8080
.option("--name <name>", "Allows to name sequence")
81+
.option("--runtime-adapter <adapter>", "STH will try to use Adapter with this name or it's default when Adapter name is not provided.")
8182
.description("Send the Sequence package to the Hub")
8283
.action(
83-
async (sequencePackage: string, { name }) => {
84-
const sequenceClient = await sequenceSendPackage(sequencePackage, { name }, false, { progress: sequenceCmd.parent?.getOptionValue("progress") });
84+
async (sequencePackage: string, { name, runtimeAdapter })=> {
85+
const sequenceClient = await sequenceSendPackage(sequencePackage, { name, runtimeAdapter }, false, { progress: sequenceCmd.parent?.getOptionValue("progress") });
8586

8687
displayObject(sequenceClient, profileManager.getProfileConfig().format);
8788
}
@@ -233,3 +234,4 @@ export const sequence: CommandDefinition = (program) => {
233234
displayMessage("Sequences removed successfully.");
234235
});
235236
};
237+

packages/cli/src/lib/helpers/sequence.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const { F_OK, R_OK } = constants;
2020

2121
type SequenceUploadOptions = {
2222
name?: string;
23+
runtimeAdapter?: string;
2324
}
2425

2526
/**
@@ -134,6 +135,10 @@ export const sequenceSendPackage = async (
134135
headers["x-name"] = options.name;
135136
}
136137

138+
if (options.runtimeAdapter) {
139+
headers["x-runtime-adapter"] = options.runtimeAdapter;
140+
}
141+
137142
seq = await getHostClient().sendSequence(
138143
sequenceStream,
139144
{ headers }

packages/host/src/lib/adapter-manager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type InitializedRuntimeAdapter = IRuntimeAdapter & {
66
status: "ready" | { error?: string };
77
};
88

9-
export type AdaptersStore = { [key: string]: InitializedRuntimeAdapter };
9+
export type AdaptersStore = Record<string, InitializedRuntimeAdapter>;
1010

1111
export class AdapterManager {
1212
adapters: AdaptersStore = {};
@@ -112,6 +112,12 @@ export class AdapterManager {
112112
return Object.values(this.adapters).find(a => a.moduleName === moduleName);
113113
}
114114

115+
/**
116+
* Returns first Adapter with "ready" status if prefferedAdapter is "detect".
117+
* Returns Adapter with name provided by prefferedAdapter.
118+
* @param prefferedAdapter
119+
* @returns
120+
*/
115121
getDefaultAdapter(prefferedAdapter: string) {
116122
if (prefferedAdapter === "detect") {
117123
return Object.values(this.adapters).filter(adapter => adapter.status === "ready")[0];

packages/host/src/lib/host.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,12 @@ export class Host implements IComponent {
767767
stream.params ||= {};
768768

769769
const sequenceName = stream.params.id_name || stream.headers["x-name"];
770+
const requestedAdapter = stream.headers["x-runtime-adapter"] as string;
770771

771-
this.logger.info("New Sequence incoming", { name: sequenceName });
772+
this.logger.info("New Sequence incoming", { name: sequenceName, requestedAdapter });
772773

773774
try {
774-
const adapter = this.adapterManager.getDefaultAdapter(this.adapterName);
775+
const adapter = this.adapterManager.getDefaultAdapter(requestedAdapter || this.adapterName);
775776

776777
if (!adapter) {
777778
return {
@@ -1004,7 +1005,7 @@ export class Host implements IComponent {
10041005
* @param {STHRestAPI.StartSequencePayload} payload App start configuration.
10051006
*/
10061007
async startCSIController(sequence: SequenceInfo, payload: STHRestAPI.StartSequencePayload): Promise<CSIController> {
1007-
const adapter = this.adapterManager.getDefaultAdapter(this.adapterName);
1008+
const adapter = this.adapterManager.getDefaultAdapter(sequence.config.type || this.adapterName);
10081009

10091010
if (!adapter) {
10101011
throw new Error("Failed to use adapter");

packages/types/src/runner-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ export type KubernetesSequenceConfig = CommonSequenceConfig & {
4545
type: "kubernetes"
4646
}
4747

48-
export type SequenceConfig = DockerSequenceConfig | ProcessSequenceConfig | KubernetesSequenceConfig
48+
export type SequenceConfig = DockerSequenceConfig | ProcessSequenceConfig | KubernetesSequenceConfig;
4949

5050
export type InstanceConfig = SequenceConfig & { instanceAdapterExitDelay: number, limits: InstanceLimits }

0 commit comments

Comments
 (0)