Skip to content

Commit 5140849

Browse files
sudhirvermadgolovin
authored andcommitted
Unlink a component with multiple port (#1265)
1 parent 761ad37 commit 5140849

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/odo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ export class Command {
225225
static getComponentJson(project: string, app: string, component: string) {
226226
return `oc get service ${component}-${app} --namespace ${project} -o json`;
227227
}
228-
static unlinkComponents(project: string, app: string, comp1: string, comp2: string) {
229-
return `odo unlink --project ${project} --app ${app} ${comp2} --component ${comp1}`;
228+
static unlinkComponents(project: string, app: string, comp1: string, comp2: string, port: string) {
229+
return `odo unlink --project ${project} --app ${app} ${comp2} --port ${port} --component ${comp1}`;
230230
}
231231
static unlinkService(project: string, app: string, service: string, comp: string) {
232232
return `odo unlink --project ${project} --app ${app} ${service} --component ${comp}`;

src/openshift/component.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,24 @@ export class Component extends OpenShiftItem {
9797
}
9898
}
9999

100+
static async getLinkPort(component: OpenShiftObject, compName: string) {
101+
const compData = await Component.odo.execute(Command.describeComponentJson(component.getParent().getParent().getName(), component.getParent().getName(), compName), component.contextPath ? component.contextPath.fsPath : Platform.getUserHomePath());
102+
return JSON.parse(compData.stdout);
103+
}
104+
100105
static async unlinkAllComponents(component: OpenShiftObject) {
101106
const linkComponent = await Component.getLinkData(component);
102107
const getLinkComponent = linkComponent['status'].linkedComponents;
103108
if (getLinkComponent) {
104-
Object.keys(getLinkComponent).forEach(async key => {
105-
await Component.odo.execute(Command.unlinkComponents(component.getParent().getParent().getName(), component.getParent().getName(), key, component.getName()), component.contextPath.fsPath);
106-
});
109+
for (const key of Object.keys(getLinkComponent)) {
110+
const getLinkPort = await Component.getLinkPort(component, key);
111+
const getPort = getLinkPort['status'].linkedComponents[component.getName()];
112+
if (getPort) {
113+
for (const port of getPort) {
114+
await Component.odo.execute(Command.unlinkComponents(component.getParent().getParent().getName(), component.getParent().getName(), key, component.getName(), port), component.contextPath.fsPath);
115+
}
116+
}
117+
}
107118
}
108119
}
109120

@@ -177,8 +188,11 @@ export class Component extends OpenShiftItem {
177188
});
178189
const compName = await window.showQuickPick(linkCompName, {placeHolder: "Select a Component to unlink", ignoreFocusOut: true});
179190
if (!compName) return null;
191+
const getLinkPort = linkComponent['status'].linkedComponents[compName];
192+
const port = await window.showQuickPick(getLinkPort, {placeHolder: "Select a Port"});
193+
if (!port) return null;
180194
return Progress.execFunctionWithProgress(`Unlinking Component`,
181-
() => Component.odo.execute(Command.unlinkComponents(component.getParent().getParent().getName(), component.getParent().getName(), component.getName(), compName), component.contextPath.fsPath)
195+
() => Component.odo.execute(Command.unlinkComponents(component.getParent().getParent().getName(), component.getParent().getName(), component.getName(), compName, port), component.contextPath.fsPath)
182196
.then(() => `Component '${compName}' has been successfully unlinked from the Component '${component.getName()}'`)
183197
.catch((err) => Promise.reject(`Failed to unlink Component with error '${err}'`))
184198
);

test/unit/openshift/component.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ suite('OpenShift/Component', () => {
528528

529529
test('errors when a command fails', async () => {
530530
quickPickStub.onFirstCall().resolves('comp2');
531+
quickPickStub.onSecondCall().resolves('8080');
531532
execStub.onFirstCall().rejects(errorMessage);
532533
let savedErr: any;
533534

0 commit comments

Comments
 (0)