Skip to content

Commit ffd4879

Browse files
committed
add showing nodered console output
1 parent f461ed5 commit ffd4879

7 files changed

Lines changed: 108 additions & 2 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Base } from "../base";
2+
3+
export class GetNoderedInstanceLogMessage implements IReplyMessage {
4+
public error: string;
5+
public jwt: any;
6+
public name: string;
7+
public result: string;
8+
9+
static assign(o: any): GetNoderedInstanceLogMessage {
10+
if (typeof o === "string" || o instanceof String) {
11+
return Object.assign(new GetNoderedInstanceLogMessage(), JSON.parse(o.toString()));
12+
}
13+
return Object.assign(new GetNoderedInstanceLogMessage(), o);
14+
}
15+
}

OpenFlow/src/Messages/Message.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { Role } from "../Role";
2828
import { RestartNoderedInstanceMessage } from "./RestartNoderedInstanceMessage";
2929
import { DeleteNoderedInstanceMessage } from "./DeleteNoderedInstanceMessage";
3030
import { GetNoderedInstanceMessage } from "./GetNoderedInstanceMessage";
31+
import { GetNoderedInstanceLogMessage } from "./GetNoderedInstanceLogMessage";
3132

3233
export class Message {
3334
public id: string;
@@ -139,6 +140,9 @@ export class Message {
139140
case "getnoderedinstance":
140141
this.GetNoderedInstance(cli);
141142
break;
143+
case "getnoderedinstancelog":
144+
this.GetNoderedInstanceLog(cli);
145+
break;
142146
case "startnoderedinstance":
143147
this.StartNoderedInstance(cli);
144148
break;
@@ -560,7 +564,7 @@ export class Message {
560564
containers: [
561565
{
562566
name: 'nodered',
563-
image: 'cloudhack/openflownodered:0.0.233',
567+
image: 'cloudhack/openflownodered:0.0.235',
564568
imagePullPolicy: "Always",
565569
env: [
566570
{ name: "saml_federation_metadata", value: Config.saml_federation_metadata },
@@ -797,6 +801,52 @@ export class Message {
797801
}
798802
this.Send(cli);
799803
}
804+
private async GetNoderedInstanceLog(cli: WebSocketClient): Promise<void> {
805+
this.Reply();
806+
var msg: GetNoderedInstanceLogMessage;
807+
try {
808+
cli._logger.debug("[" + cli.user.username + "] GetNoderedInstance");
809+
msg = GetNoderedInstanceLogMessage.assign(this.data);
810+
var name = cli.user.username;
811+
if (msg.name !== null && msg.name !== undefined && msg.name !== "" && msg.name != cli.user.username) {
812+
var exists = User.FindByUsername(msg.name, cli.jwt);
813+
if (exists == null) { throw new Error("Unknown name " + msg.name) }
814+
name = msg.name;
815+
}
816+
name = name.split("@").join("").split(".").join("");
817+
name = name.toLowerCase();
818+
var namespace = Config.namespace;
819+
820+
821+
var list = await KubeUtil.instance().CoreV1Api.listNamespacedPod(namespace);
822+
823+
if (list.body.items.length > 0) {
824+
for (var i = 0; i < list.body.items.length; i++) {
825+
var item = list.body.items[i];
826+
if (item.metadata.labels.app === (name + "nodered")) {
827+
cli._logger.debug("[" + cli.user.username + "] GetNoderedInstance:" + name + " found one as " + item.metadata.name);
828+
var obj = await await KubeUtil.instance().CoreV1Api.readNamespacedPodLog(item.metadata.name, namespace, "", false);
829+
msg.result = obj.body;
830+
}
831+
}
832+
}
833+
834+
835+
836+
} catch (error) {
837+
this.data = "";
838+
console.error(error);
839+
//msg.error = JSON.stringify(error, null, 2);
840+
msg.error = "Request failed!"
841+
}
842+
try {
843+
this.data = JSON.stringify(msg);
844+
} catch (error) {
845+
this.data = "";
846+
msg.error = error.toString();
847+
}
848+
this.Send(cli);
849+
}
800850
private async StartNoderedInstance(cli: WebSocketClient): Promise<void> {
801851
this.Reply();
802852
this.Send(cli);

OpenFlow/src/public/CommonControllers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ module openflow {
191191
q = await this.WebSocketClient.Send<GetNoderedInstanceMessage>(msg);
192192
return q.result;
193193
}
194+
async GetNoderedInstanceLog(): Promise<string> {
195+
var q: GetNoderedInstanceLogMessage = new GetNoderedInstanceLogMessage();
196+
var msg: Message = new Message(); msg.command = "getnoderedinstancelog"; msg.data = JSON.stringify(q);
197+
q = await this.WebSocketClient.Send<GetNoderedInstanceLogMessage>(msg);
198+
return q.result;
199+
}
194200
async EnsureNoderedInstance(): Promise<void> {
195201
var q: EnsureNoderedInstanceMessage = new EnsureNoderedInstanceMessage();
196202
var msg: Message = new Message(); msg.command = "ensurenoderedinstance"; msg.data = JSON.stringify(q);

OpenFlow/src/public/Controllers.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,7 @@ module openflow {
15371537
public noderedurl: string = "";
15381538
public instance: any = null;
15391539
public instancestatus: string = "";
1540+
public instancelog: string = "";
15401541
constructor(
15411542
public $scope: ng.IScope,
15421543
public $location: ng.ILocationService,
@@ -1579,6 +1580,18 @@ module openflow {
15791580
}
15801581
if (!this.$scope.$$phase) { this.$scope.$apply(); }
15811582
}
1583+
async GetNoderedInstanceLog() {
1584+
try {
1585+
this.instancestatus = "fetching log";
1586+
console.log("GetNoderedInstanceLog:");
1587+
this.instancelog = await this.api.GetNoderedInstanceLog();
1588+
this.messages += "GetNoderedInstanceLog completed\n";
1589+
} catch (error) {
1590+
this.messages += error + "\n";
1591+
console.error(error);
1592+
}
1593+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
1594+
}
15821595
async EnsureNoderedInstance() {
15831596
try {
15841597
await this.api.EnsureNoderedInstance();

OpenFlow/src/public/Message.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ module openflow {
190190
return Object.assign(new GetNoderedInstanceMessage(), o);
191191
}
192192
}
193+
export class GetNoderedInstanceLogMessage {
194+
public error: string;
195+
public jwt: any;
196+
public name: string;
197+
public result: string;
198+
static assign(o: any): GetNoderedInstanceMessage {
199+
if (typeof o === "string" || o instanceof String) {
200+
return Object.assign(new GetNoderedInstanceMessage(), JSON.parse(o.toString()));
201+
}
202+
return Object.assign(new GetNoderedInstanceMessage(), o);
203+
}
204+
}
193205
export class EnsureNoderedInstanceMessage {
194206
public error: string;
195207
public jwt: any;

OpenFlow/src/public/Nodered.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@ <h1 translate lib="web">sockets</h1>
1515
<button type="button" class="btn btn-secondary" ng-click="ctrl.DeleteNoderedInstance()"
1616
ng-show="ctrl.instance!=null">Delete Nodered</button>
1717
<button type="button" class="btn btn-secondary" ng-click="ctrl.GetNoderedInstance()">Get status</button>
18+
<button type="button" class="btn btn-secondary" ng-show="ctrl.instance!=null"
19+
ng-click="ctrl.GetNoderedInstanceLog()">Get Console</button>
1820
</div>
1921
</div>
2022
</section>
2123
</form>
24+
<section ng-show="ctrl.instancelog!=""">
25+
<div class="form-group">
26+
<label class="col-sm-3 control-label"><span translate lib="web">console</span>: </label>
27+
<div class="col-sm-9">
28+
<pre>{{ ctrl.instancelog }}</pre>
29+
</div>
30+
</div>
31+
</section>
2232
<section>
2333
<div class="form-group">
2434
<label class="col-sm-3 control-label"><span translate lib="web">status</span>: </label>

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.234
1+
0.0.235

0 commit comments

Comments
 (0)