Skip to content

Commit e3b21b6

Browse files
msivasubramaniaandatho7561
authored andcommitted
resolved cyclic dependency
Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
1 parent 6fe9ee6 commit e3b21b6

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

src/serverlessFunction/functions.ts

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ import { CliChannel } from '../cli';
99
import { Oc } from '../oc/ocWrapper';
1010
import { Odo } from '../odo/odoWrapper';
1111
import { isTektonAware } from '../tekton/tekton';
12-
import { Platform } from '../util/platform';
1312
import { Progress } from '../util/progress';
1413
import { OpenShiftTerminalApi, OpenShiftTerminalManager } from '../webview/openshift-terminal/openShiftTerminal';
1514
import { ServerlessCommand, Utils } from './commands';
1615
import { GitModel, getGitBranchInteractively, getGitRepoInteractively, getGitStateByPath } from './git/git';
1716
import { isKnativeServingAware } from './knative';
1817
import { multiStep } from './multiStepInput';
19-
import { FunctionContent, FunctionObject, FunctionSession, InvokeFunction } from './types';
20-
import { ServerlessFunctionView } from './view';
18+
import { FunctionContent, FunctionObject, FunctionSession } from './types';
2119

2220
export class Functions {
2321

@@ -129,7 +127,7 @@ export class Functions {
129127
teminal: terminal
130128
};
131129
this.addSession(context, session);
132-
ServerlessFunctionView.getInstance().refresh(context);
130+
void commands.executeCommand('openshift.Serverless.refresh', context);
133131
}
134132

135133
private addSession(context: FunctionObject, session: FunctionSession) {
@@ -192,7 +190,7 @@ export class Functions {
192190
teminal: terminal
193191
}
194192
this.addSession(context, session);
195-
ServerlessFunctionView.getInstance().refresh(context);
193+
void commands.executeCommand('openshift.Serverless.refresh', context);
196194
this.buildTerminalMap.set(terminalKey, terminal);
197195
}
198196

@@ -218,7 +216,7 @@ export class Functions {
218216
teminal: terminal
219217
}
220218
this.addSession(context, session);
221-
ServerlessFunctionView.getInstance().refresh(context);
219+
void commands.executeCommand('openshift.Serverless.refresh', context);
222220
this.runTerminalMap.set(`run-${context.folderURI.fsPath}`, terminal);
223221
}
224222

@@ -240,14 +238,6 @@ export class Functions {
240238
});
241239
}
242240

243-
public async getTemplates(): Promise<any[]> {
244-
const result = await Odo.Instance.execute(ServerlessCommand.getTemplates(), undefined, false);
245-
if (result.error) {
246-
void window.showErrorMessage(result.error.message);
247-
}
248-
return JSON.parse(result.stdout) as any[];
249-
}
250-
251241
public async deploy(context: FunctionObject) {
252242
const currentNamespace: string = await Oc.Instance.getActiveProject();
253243
const yamlContent = await Utils.getFuncYamlContent(context.folderURI.fsPath);
@@ -309,17 +299,7 @@ export class Functions {
309299
teminal: terminal
310300
};
311301
this.addSession(context, session);
312-
ServerlessFunctionView.getInstance().refresh(context);
313-
}
314-
315-
public async invoke(functionName: string, invokeFunData: InvokeFunction): Promise<void> {
316-
await OpenShiftTerminalManager.getInstance().createTerminal(
317-
ServerlessCommand.invokeFunction(invokeFunData),
318-
`Invoke: ${functionName}`,
319-
undefined, undefined, {
320-
onExit: undefined
321-
}, true
322-
);
302+
void commands.executeCommand('openshift.Serverless.refresh', context);
323303
}
324304

325305
public async config(title: string, context: FunctionObject, mode: string, isAdd = true) {
@@ -377,16 +357,6 @@ export class Functions {
377357
});
378358
}
379359

380-
public getDefaultImages(name: string): string[] {
381-
const imageList: string[] = [];
382-
const defaultUsername = Platform.getEnv();
383-
const defaultQuayImage = `quay.io/${Platform.getOS() === 'win32' ? defaultUsername.USERNAME : defaultUsername.USER}/${name}:latest`;
384-
const defaultDockerImage = `docker.io/${Platform.getOS() === 'win32' ? defaultUsername.USERNAME : defaultUsername.USER}/${name}:latest`;
385-
imageList.push(defaultQuayImage);
386-
imageList.push(defaultDockerImage);
387-
return imageList;
388-
}
389-
390360
public async getImage(folderURI: Uri): Promise<string> {
391361
const yamlContent = await Utils.getFuncYamlContent(folderURI.fsPath);
392362
if (yamlContent?.image && Functions.imageRegex.test(yamlContent.image)) {

src/webview/serverless-function/serverlessFunctionLoader.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,50 @@ import * as path from 'path';
1010
import * as vscode from 'vscode';
1111
import { Odo } from '../../odo/odoWrapper';
1212
import { ServerlessCommand, Utils } from '../../serverlessFunction/commands';
13-
import { Functions } from '../../serverlessFunction/functions';
13+
1414
import { InvokeFunction } from '../../serverlessFunction/types';
1515
import { CliExitData } from '../../util/childProcessUtil';
1616
import { ExtensionID } from '../../util/constants';
1717
import { Progress } from '../../util/progress';
1818
import { selectWorkspaceFolder, selectWorkspaceFolders } from '../../util/workspace';
1919
import { VsCommandError } from '../../vscommand';
2020
import { loadWebviewHtml, validateName } from '../common-ext/utils';
21+
import { Platform } from '../../util/platform';
22+
import { OpenShiftTerminalManager } from '../openshift-terminal/openShiftTerminal';
2123

2224
export interface ServiceBindingFormResponse {
2325
selectedService: string;
2426
bindingName: string;
2527
}
2628

29+
function getDefaultImages(name: string): string[] {
30+
const imageList: string[] = [];
31+
const defaultUsername = Platform.getEnv();
32+
const defaultQuayImage = `quay.io/${Platform.getOS() === 'win32' ? defaultUsername.USERNAME : defaultUsername.USER}/${name}:latest`;
33+
const defaultDockerImage = `docker.io/${Platform.getOS() === 'win32' ? defaultUsername.USERNAME : defaultUsername.USER}/${name}:latest`;
34+
imageList.push(defaultQuayImage);
35+
imageList.push(defaultDockerImage);
36+
return imageList;
37+
}
38+
39+
async function getTemplates(): Promise<any[]> {
40+
const result = await Odo.Instance.execute(ServerlessCommand.getTemplates(), undefined, false);
41+
if (result.error) {
42+
void vscode.window.showErrorMessage(result.error.message);
43+
}
44+
return JSON.parse(result.stdout) as any[];
45+
}
46+
47+
async function invoke(functionName: string, invokeFunData: InvokeFunction): Promise<void> {
48+
await OpenShiftTerminalManager.getInstance().createTerminal(
49+
ServerlessCommand.invokeFunction(invokeFunData),
50+
`Invoke: ${functionName}`,
51+
undefined, undefined, {
52+
onExit: undefined
53+
}, true
54+
);
55+
}
56+
2757
async function messageListener(panel: vscode.WebviewPanel, event: any): Promise<any> {
2858
let response: CliExitData;
2959
const eventName = event.action;
@@ -33,7 +63,7 @@ async function messageListener(panel: vscode.WebviewPanel, event: any): Promise<
3363
case 'validateName': {
3464
const flag = validateName(functionName);
3565
const defaultImages = !flag
36-
? Functions.getInstance().getDefaultImages(functionName)
66+
? getDefaultImages(functionName)
3767
: [];
3868
void panel?.webview.postMessage({
3969
action: eventName,
@@ -117,7 +147,7 @@ async function messageListener(panel: vscode.WebviewPanel, event: any): Promise<
117147
enableURL: event.enableURL,
118148
invokeURL: event.invokeURL,
119149
};
120-
await Functions.getInstance().invoke(functionName, invokeFunData);
150+
await invoke(functionName, invokeFunData);
121151
panel.dispose();
122152
break;
123153
}
@@ -155,7 +185,7 @@ export default class ServerlessFunctionViewLoader {
155185
panel.reveal(vscode.ViewColumn.One);
156186
return null;
157187
}
158-
const templates = await Functions.getInstance().getTemplates();
188+
const templates = await getTemplates();
159189
if (invoke) {
160190
const panel = await this.createView(title);
161191
const getEnvFuncId = crypto.randomUUID();

0 commit comments

Comments
 (0)