Skip to content

Commit e22a1b5

Browse files
committed
Add seperate pods to nodered page
1 parent f3c7b01 commit e22a1b5

10 files changed

Lines changed: 143 additions & 24 deletions

OpenFlow/src/Messages/DeleteNoderedInstanceMessage.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Base } from "../base";
33
export class DeleteNoderedInstanceMessage implements IReplyMessage {
44
public error: string;
55
public jwt: any;
6-
public name: string;
6+
// public name: string;
77
public _id: string;
88

99
static assign(o: any): DeleteNoderedInstanceMessage {
@@ -13,3 +13,15 @@ export class DeleteNoderedInstanceMessage implements IReplyMessage {
1313
return Object.assign(new DeleteNoderedInstanceMessage(), o);
1414
}
1515
}
16+
export class DeleteNoderedPodMessage implements IReplyMessage {
17+
public error: string;
18+
public jwt: any;
19+
public name: string;
20+
21+
static assign(o: any): DeleteNoderedPodMessage {
22+
if (typeof o === "string" || o instanceof String) {
23+
return Object.assign(new DeleteNoderedPodMessage(), JSON.parse(o.toString()));
24+
}
25+
return Object.assign(new DeleteNoderedPodMessage(), o);
26+
}
27+
}

OpenFlow/src/Messages/EnsureNoderedInstanceMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Base } from "../base";
33
export class EnsureNoderedInstanceMessage implements IReplyMessage {
44
public error: string;
55
public jwt: any;
6-
public name: string;
6+
// public name: string;
77
public _id: string;
88

99
static assign(o: any): EnsureNoderedInstanceMessage {

OpenFlow/src/Messages/GetNoderedInstanceMessage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ export class GetNoderedInstanceMessage implements IReplyMessage {
44
public error: string;
55
public jwt: any;
66
public name: string;
7+
// public instancename: string;
78
public _id: string;
89
public result: any;
10+
public results: any;
911

1012
static assign(o: any): GetNoderedInstanceMessage {
1113
if (typeof o === "string" || o instanceof String) {

OpenFlow/src/Messages/Message.ts

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { EnsureNoderedInstanceMessage } from "./EnsureNoderedInstanceMessage";
2727
import { KubeUtil } from "../KubeUtil";
2828
import { Role } from "../Role";
2929
import { RestartNoderedInstanceMessage } from "./RestartNoderedInstanceMessage";
30-
import { DeleteNoderedInstanceMessage } from "./DeleteNoderedInstanceMessage";
30+
import { DeleteNoderedInstanceMessage, DeleteNoderedPodMessage } from "./DeleteNoderedInstanceMessage";
3131
import { GetNoderedInstanceMessage } from "./GetNoderedInstanceMessage";
3232
import { GetNoderedInstanceLogMessage } from "./GetNoderedInstanceLogMessage";
3333
import { Util } from "../Util";
@@ -172,6 +172,9 @@ export class Message {
172172
case "stopnoderedinstance":
173173
this.StopNoderedInstance(cli);
174174
break;
175+
case "deletenoderedpod":
176+
this.DeleteNoderedPod(cli);
177+
break;
175178
case "savefile":
176179
this.SaveFile(cli);
177180
break;
@@ -743,7 +746,8 @@ export class Message {
743746
this.Send(cli);
744747
}
745748

746-
private async GetInstanceName(cli: WebSocketClient, _id: string, name: string): Promise<string> {
749+
private async GetInstanceName(cli: WebSocketClient, _id: string): Promise<string> {
750+
var name: string = "";
747751
if (_id !== null && _id !== undefined && _id !== "" && _id != cli.user._id) {
748752
var res = await Config.db.query<User>({ _id: _id }, null, 1, 0, null, "users", cli.jwt);
749753
if (res.length == 0) {
@@ -773,7 +777,7 @@ export class Message {
773777
try {
774778
cli._logger.debug("[" + cli.user.username + "] EnsureNoderedInstance");
775779
msg = EnsureNoderedInstanceMessage.assign(this.data);
776-
var name = await this.GetInstanceName(cli, msg._id, msg.name);
780+
var name = await this.GetInstanceName(cli, msg._id);
777781
var _id = msg._id;
778782
if (_id === null || _id === undefined || _id === "") _id = cli.user._id;
779783

@@ -934,7 +938,7 @@ export class Message {
934938
try {
935939
cli._logger.debug("[" + cli.user.username + "] DeleteNoderedInstance");
936940
msg = DeleteNoderedInstanceMessage.assign(this.data);
937-
var name = await this.GetInstanceName(cli, msg._id, msg.name);
941+
var name = await this.GetInstanceName(cli, msg._id);
938942
var namespace = Config.namespace;
939943
var hostname = Config.nodered_domain_schema.replace("$nodered_id$", name);
940944

@@ -995,13 +999,46 @@ export class Message {
995999
}
9961000
this.Send(cli);
9971001
}
1002+
private async DeleteNoderedPod(cli: WebSocketClient): Promise<void> {
1003+
this.Reply();
1004+
var msg: DeleteNoderedPodMessage;
1005+
var user: User;
1006+
try {
1007+
cli._logger.debug("[" + cli.user.username + "] DeleteNoderedInstance");
1008+
msg = DeleteNoderedPodMessage.assign(this.data);
1009+
var namespace = Config.namespace;
1010+
var list = await KubeUtil.instance().CoreV1Api.listNamespacedPod(namespace);
1011+
if (list.body.items.length > 0) {
1012+
for (var i = 0; i < list.body.items.length; i++) {
1013+
var item = list.body.items[i];
1014+
if (item.metadata.name == msg.name) {
1015+
await KubeUtil.instance().CoreV1Api.deleteNamespacedPod(item.metadata.name, namespace);
1016+
}
1017+
}
1018+
} else {
1019+
cli._logger.warn("[" + cli.user.username + "] GetNoderedInstance: found NO Namespaced Pods ???");
1020+
}
1021+
} catch (error) {
1022+
this.data = "";
1023+
cli._logger.error(error);
1024+
//msg.error = JSON.stringify(error, null, 2);
1025+
if (msg !== null && msg !== undefined) msg.error = "Request failed!"
1026+
}
1027+
try {
1028+
this.data = JSON.stringify(msg);
1029+
} catch (error) {
1030+
this.data = "";
1031+
cli._logger.error(error);
1032+
}
1033+
this.Send(cli);
1034+
}
9981035
private async RestartNoderedInstance(cli: WebSocketClient): Promise<void> {
9991036
this.Reply();
10001037
var msg: RestartNoderedInstanceMessage;
10011038
try {
10021039
cli._logger.debug("[" + cli.user.username + "] RestartNoderedInstance");
10031040
msg = RestartNoderedInstanceMessage.assign(this.data);
1004-
var name = await this.GetInstanceName(cli, msg._id, msg.name);
1041+
var name = await this.GetInstanceName(cli, msg._id);
10051042
var namespace = Config.namespace;
10061043
// var hostname = Config.nodered_domain_schema.replace("$nodered_id$", name);
10071044

@@ -1033,23 +1070,28 @@ export class Message {
10331070
try {
10341071
cli._logger.debug("[" + cli.user.username + "] GetNoderedInstance");
10351072
msg = GetNoderedInstanceMessage.assign(this.data);
1036-
var name = await this.GetInstanceName(cli, msg._id, msg.name);
1073+
var name = await this.GetInstanceName(cli, msg._id);
10371074
var namespace = Config.namespace;
10381075
// var hostname = Config.nodered_domain_schema.replace("$nodered_id$", name);
10391076

10401077
var list = await KubeUtil.instance().CoreV1Api.listNamespacedPod(namespace);
10411078

10421079
var found: any = null;
10431080
msg.result = null;
1081+
msg.results = [];
10441082
if (list.body.items.length > 0) {
10451083
for (var i = 0; i < list.body.items.length; i++) {
10461084
var item = list.body.items[i];
1047-
if (item.metadata.labels.app === name) {
1085+
if (!Util.IsNullEmpty(msg.name) && item.metadata.name == msg.name && cli.user.HasRoleName("admins")) {
1086+
found = item;
1087+
msg.results.push(item);
1088+
} else if (item.metadata.labels.app === name) {
10481089
found = item;
10491090
if (item.status.phase != "Failed") {
10501091
msg.result = item;
10511092
cli._logger.debug("[" + cli.user.username + "] GetNoderedInstance:" + name + " found one");
10521093
}
1094+
msg.results.push(item);
10531095
}
10541096
}
10551097
if (msg.result == null) msg.result = found;
@@ -1076,29 +1118,34 @@ export class Message {
10761118
try {
10771119
cli._logger.debug("[" + cli.user.username + "] GetNoderedInstance");
10781120
msg = GetNoderedInstanceLogMessage.assign(this.data);
1079-
var name = await this.GetInstanceName(cli, msg._id, msg.name);
1121+
var name = await this.GetInstanceName(cli, msg._id);
10801122
var namespace = Config.namespace;
10811123

10821124
var list = await KubeUtil.instance().CoreV1Api.listNamespacedPod(namespace);
10831125

10841126
if (list.body.items.length > 0) {
10851127
for (var i = 0; i < list.body.items.length; i++) {
10861128
var item = list.body.items[i];
1087-
if (item.metadata.labels.app === name) {
1129+
if (!Util.IsNullEmpty(msg.name) && item.metadata.name == msg.name && cli.user.HasRoleName("admins")) {
1130+
cli._logger.debug("[" + cli.user.username + "] GetNoderedInstance:" + name + " found one as " + item.metadata.name);
1131+
var obj = await await KubeUtil.instance().CoreV1Api.readNamespacedPodLog(item.metadata.name, namespace, "", false);
1132+
msg.result = obj.body;
1133+
} else if (item.metadata.labels.app === name) {
10881134
cli._logger.debug("[" + cli.user.username + "] GetNoderedInstance:" + name + " found one as " + item.metadata.name);
10891135
var obj = await await KubeUtil.instance().CoreV1Api.readNamespacedPodLog(item.metadata.name, namespace, "", false);
10901136
msg.result = obj.body;
10911137
}
10921138
}
10931139
}
10941140

1095-
1096-
10971141
} catch (error) {
10981142
this.data = "";
10991143
cli._logger.error(error);
11001144
//msg.error = JSON.stringify(error, null, 2);
11011145
if (msg !== null && msg !== undefined) msg.error = "Request failed!"
1146+
if (error.response && error.response.body && !Util.IsNullEmpty(error.response.body.message)) {
1147+
msg.error = error.response.body.message;
1148+
}
11021149
}
11031150
try {
11041151
this.data = JSON.stringify(msg);

OpenFlow/src/Messages/RestartNoderedInstanceMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Base } from "../base";
33
export class RestartNoderedInstanceMessage implements IReplyMessage {
44
public error: string;
55
public jwt: any;
6-
public name: string;
6+
//public name: string;
77
public _id: string;
88

99
static assign(o: any): RestartNoderedInstanceMessage {

OpenFlow/src/public/CommonControllers.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ module openflow {
251251
}
252252
return msg;
253253
}
254-
async GetNoderedInstance(_id: string, name: string): Promise<any> {
254+
async GetNoderedInstance(_id: string, name: string): Promise<any[]> {
255255
var q: GetNoderedInstanceMessage = new GetNoderedInstanceMessage(); q.name = name; q._id = _id;
256256
var msg: Message = new Message(); msg.command = "getnoderedinstance"; msg.data = JSON.stringify(q);
257257
q = await this.WebSocketClient.Send<GetNoderedInstanceMessage>(msg);
258-
return q.result;
258+
return q.results;
259259
}
260260
async GetNoderedInstanceLog(_id: string, name: string): Promise<string> {
261261
var q: GetNoderedInstanceLogMessage = new GetNoderedInstanceLogMessage(); q.name = name; q._id = _id;
@@ -273,6 +273,11 @@ module openflow {
273273
var msg: Message = new Message(); msg.command = "deletenoderedinstance"; msg.data = JSON.stringify(q);
274274
q = await this.WebSocketClient.Send<DeleteNoderedInstanceMessage>(msg);
275275
}
276+
async DeleteNoderedPod(_id: string, name: string): Promise<void> {
277+
var q: DeleteNoderedPodMessage = new DeleteNoderedPodMessage(); q.name = name; q._id = _id;
278+
var msg: Message = new Message(); msg.command = "deletenoderedpod"; msg.data = JSON.stringify(q);
279+
q = await this.WebSocketClient.Send<DeleteNoderedPodMessage>(msg);
280+
}
276281
async RestartNoderedInstance(_id: string, name: string): Promise<void> {
277282
var q: RestartNoderedInstanceMessage = new RestartNoderedInstanceMessage(); q.name = name; q._id = _id;
278283
var msg: Message = new Message(); msg.command = "restartnoderedinstance"; msg.data = JSON.stringify(q);

OpenFlow/src/public/Controllers.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,9 +2619,11 @@ module openflow {
26192619
public queuename: string = "webtest";
26202620
public noderedurl: string = "";
26212621
public instance: any = null;
2622+
public instances: any[] = null;
26222623
public instancestatus: string = "";
26232624
public instancelog: string = "";
26242625
public name: string = "";
2626+
public instancename: string = "";
26252627
public userid: string = "";
26262628
public user: NoderedUser = null;
26272629
public limitsmemory: string = "";
@@ -2697,7 +2699,11 @@ module openflow {
26972699
this.errormessage = "";
26982700
this.instancestatus = "fetching status";
26992701

2700-
this.instance = await this.api.GetNoderedInstance(this.userid, this.name);
2702+
this.instances = await this.api.GetNoderedInstance(this.userid, null);
2703+
if (this.instances != null && this.instances.length > 0) {
2704+
this.instance = this.instances[0];
2705+
}
2706+
27012707
console.debug("GetNoderedInstance:");
27022708
if (this.instance !== null && this.instance !== undefined) {
27032709
if (this.instance.metadata.deletionTimestamp !== undefined) {
@@ -2709,6 +2715,7 @@ module openflow {
27092715
this.instancestatus = "non existent";
27102716
// this.messages += "GetNoderedInstance completed, status unknown/non existent" + "\n";
27112717
}
2718+
27122719
this.messages += "GetNoderedInstance completed, status " + this.instancestatus + "\n";
27132720
} catch (error) {
27142721
this.errormessage = error;
@@ -2719,12 +2726,12 @@ module openflow {
27192726
this.loading = false;
27202727
if (!this.$scope.$$phase) { this.$scope.$apply(); }
27212728
}
2722-
async GetNoderedInstanceLog() {
2729+
async GetNoderedInstanceLog(instancename: string) {
27232730
try {
27242731
this.errormessage = "";
27252732
this.instancestatus = "fetching log";
27262733
console.debug("GetNoderedInstanceLog:");
2727-
this.instancelog = await this.api.GetNoderedInstanceLog(this.userid, this.name);
2734+
this.instancelog = await this.api.GetNoderedInstanceLog(this.userid, instancename);
27282735
this.instancelog = this.instancelog.split("\n").reverse().join("\n");
27292736
this.messages += "GetNoderedInstanceLog completed\n";
27302737
this.instancestatus = "";
@@ -2762,6 +2769,20 @@ module openflow {
27622769
if (!this.$scope.$$phase) { this.$scope.$apply(); }
27632770
this.GetNoderedInstance();
27642771
}
2772+
async DeleteNoderedPod(instancename: string) {
2773+
try {
2774+
this.errormessage = "";
2775+
await this.api.DeleteNoderedPod(this.userid, instancename);
2776+
this.messages += "DeleteNoderedPod completed" + "\n";
2777+
} catch (error) {
2778+
this.errormessage = error;
2779+
this.messages += error + "\n";
2780+
console.error(error);
2781+
}
2782+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
2783+
this.GetNoderedInstance();
2784+
2785+
}
27652786
async RestartNoderedInstance() {
27662787
try {
27672788
this.errormessage = "";

OpenFlow/src/public/Message.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ module openflow {
196196
public error: string;
197197
public jwt: any;
198198
public name: string;
199+
public instancename: string;
199200
public _id: string;
200201
public result: any;
202+
public results: any[];
201203
static assign(o: any): GetNoderedInstanceMessage {
202204
if (typeof o === "string" || o instanceof String) {
203205
return Object.assign(new GetNoderedInstanceMessage(), JSON.parse(o.toString()));
@@ -209,6 +211,7 @@ module openflow {
209211
public error: string;
210212
public jwt: any;
211213
public name: string;
214+
public instancename: string;
212215
public _id: string;
213216
public result: string;
214217
static assign(o: any): GetNoderedInstanceMessage {
@@ -242,6 +245,18 @@ module openflow {
242245
return Object.assign(new DeleteNoderedInstanceMessage(), o);
243246
}
244247
}
248+
export class DeleteNoderedPodMessage {
249+
public error: string;
250+
public jwt: any;
251+
public name: string;
252+
public _id: string;
253+
static assign(o: any): DeleteNoderedPodMessage {
254+
if (typeof o === "string" || o instanceof String) {
255+
return Object.assign(new DeleteNoderedPodMessage(), JSON.parse(o.toString()));
256+
}
257+
return Object.assign(new DeleteNoderedPodMessage(), o);
258+
}
259+
}
245260
export class RestartNoderedInstanceMessage {
246261
public error: string;
247262
public jwt: any;

OpenFlow/src/public/Nodered.html

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,29 @@ <h1 translate lib="web">sockets</h1>
2626
</form>
2727
<div ng-show="ctrl.errormessage != ''"" class=" alert alert-danger" role="alert">{{ctrl.errormessage}}</div>
2828
<section>
29-
<div class="form-group">
30-
<label class="col-sm-3 control-label"><span translate lib="web">status</span>: </label>
31-
<div class="col-sm-9">
32-
<span ng-show="ctrl.instance!=null">{{ ctrl.instancestatus }}</span>
29+
<div ng-repeat="instance in ctrl.instances"
30+
ng-class="{alert: true, 'alert-primary': instance.status.phase != 'Failed', 'alert-danger': instance.status.phase == 'Failed'}">
31+
<div class="row">
32+
<label class="col-sm-1 control-label"><span translate lib="web">name</span>: </label>
33+
<div class="col">
34+
<span ng-show="ctrl.instance!=null">{{ instance.metadata.name }}</span>
35+
</div>
36+
<label class="col-sm-1 control-label"><span translate lib="web">status</span>: </label>
37+
<div class="col">
38+
<span ng-show="ctrl.instance!=null">{{ instance.status.phase }}</span>
39+
</div>
40+
<div class="col" ng-show="instance.status.phase == 'Failed'">
41+
<!-- <button type="button" class="btn btn-secondary"
42+
ng-click="ctrl.GetNoderedInstanceLog(instance.metadata.name)">Logs</button> -->
43+
<button type="button" class="btn btn-secondary"
44+
ng-click="ctrl.DeleteNoderedPod(instance.metadata.name)">Delete</button>
45+
</div>
46+
</div>
47+
<div class="row" ng-show="instance.status.phase == 'Failed'">
48+
<span>{{ instance.status.message }}</span>
3349
</div>
3450
</div>
51+
3552
</section>
3653
<section>
3754
<div class="form-group">

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.555
1+
0.0.556

0 commit comments

Comments
 (0)