Skip to content

Commit 912f685

Browse files
committed
test
1 parent 6f260b7 commit 912f685

1 file changed

Lines changed: 36 additions & 6 deletions

File tree

OpenFlowNodeRED/src/node-red-contrib-openflow-storage.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,28 @@ export class noderedcontribopenflowstorage {
604604
public bussy: boolean = false;
605605
public async onupdate(msg: any) {
606606
try {
607+
// let events = this.RED.runtime.events;
608+
// events.emit("runtime-event", { id: "runtime-deploy", payload: { revision: "1" }, retain: true });
609+
// events.emit("runtime-event", { id: Math.random().toString(36).substr(2, 9), payload: { type: "warning", text: "Hi mom1" }, retain: false });
610+
// events.emit("runtime-event", { id: Math.random().toString(36).substr(2, 9), payload: { type: "warning", text: "Hi mom2" }, retain: true });
611+
// events.emit("runtime-event", { id: Math.random().toString(36).substr(2, 9), payload: { text: "Hi mom3" }, retain: true });
612+
// events.emit("runtime-event", { id: Math.random().toString(36).substr(2, 9), payload: { text: "Hi mom4" }, retain: false });
613+
// events.emit("runtime-event", { id: "runtime-state", payload: { type: "warning", text: "Hi mom" }, retain: true });
614+
// events.emit("runtime-event", { id: "runtime-state", payload: { type: "warning", text: "Hi mom" }, retain: false });
615+
// events.emit("runtime-event", { id: "node/added", retain: false, payload: "Hi mom" });
616+
// events.emit("runtime-event", { id: "runtime-state", retain: true });
617+
// events.emit("runtime-event", { id: "node/enabled", retain: false, payload: "Hi mom" });
618+
// try {
619+
// events.emit("runtime-event", { id: Math.random().toString(36).substr(2, 9), payload: { text: "Hi mom" }, retain: false });
620+
// events.emit("runtime-event", { id: Math.random().toString(36).substr(2, 9), payload: { type: "info", text: "Hi mom" }, retain: false });
621+
// events.emit("runtime-event", { id: Math.random().toString(36).substr(2, 9), payload: { text: "Hi mom" } });
622+
// } catch (error) {
623+
// console.error(error);
624+
// }
607625
const begin: number = this.last_reload.getTime();
608626
const end: number = new Date().getTime();
609627
const seconds = Math.round((end - begin) / 1000);
628+
var r = this.RED.runtime;
610629
if (seconds < 2 || this.bussy) {
611630
return;
612631
}
@@ -675,15 +694,18 @@ export class noderedcontribopenflowstorage {
675694
if (newsettings.nodes[key] == null) {
676695
// this._logger.info("**************************************************");
677696
this._logger.info("Remove module " + key + "@" + version);
697+
this.RED.log.warn("Remove module " + key + "@" + version);
678698
await this.RED.runtime.nodes.removeModule({ user: "admin", module: key, version: version });
679699
// HACK
680700
// exitprocess = true;
681701
} else if (version != oldversion) {
682702
// this._logger.info("**************************************************");
683703
this._logger.info("Install module " + key + "@" + version + " up from " + oldversion);
704+
this.RED.log.warn("Install module " + key + "@" + version + " up from " + oldversion);
684705
let result = await this.RED.runtime.nodes.addModule({ user: "admin", module: key, version: version });
685706
if (result != null && result.pending_version != null && result.pending_version != result.version) {
686707
this._logger.info(key + " now has pending_version " + result.pending_version + " request process exit");
708+
this.RED.log.warn(key + " now has pending_version " + result.pending_version + " request process exit");
687709
exitprocess = true;
688710
}
689711
// HACK
@@ -694,10 +716,12 @@ export class noderedcontribopenflowstorage {
694716
this._logger.error(message);
695717
if (message == "Uninstall failed") {
696718
this._logger.info("Uninstall failed, request process exit");
719+
this.RED.log.error("Uninstall failed, request process exit");
697720
exitprocess = true;
698721
}
699722
if (message == "Install failed") {
700723
this._logger.info("Install failed, request process exit");
724+
this.RED.log.error("Install failed, request process exit");
701725
exitprocess = true;
702726
}
703727
if (message == "Module already loaded") {
@@ -729,35 +753,35 @@ export class noderedcontribopenflowstorage {
729753
}
730754
try {
731755
if (oldsettings.nodes[key] == null) {
732-
// this._logger.info("**************************************************");
733756
this._logger.info("Install new module " + key + "@" + version);
757+
this.RED.log.warn("Install new module " + key + "@" + version);
734758
let result = await this.RED.runtime.nodes.addModule({ user: "admin", module: key, version: version });
735759
if (result != null && result.pending_version != null && result.pending_version != result.version) {
736760
this._logger.info(key + " now has pending_version " + result.pending_version + " request process exit");
761+
this.RED.log.warn(key + " now has pending_version " + result.pending_version + " request process exit");
737762
exitprocess = true;
738763
}
739-
// HACK
740-
// exitprocess = true;
741764
} else if (version != oldversion) {
742-
// this._logger.info("**************************************************");
743765
this._logger.info("Install module " + key + "@" + version + " up from " + oldversion);
766+
this.RED.log.warn("Install module " + key + "@" + version + " up from " + oldversion);
744767
let result = await this.RED.runtime.nodes.addModule({ user: "admin", module: key, version: version });
745768
if (result != null && result.pending_version != null && result.pending_version != result.version) {
746769
this._logger.info(key + " now has pending_version " + result.pending_version + " request process exit");
770+
this.RED.log.warn(key + " now has pending_version " + result.pending_version + " request process exit");
747771
exitprocess = true;
748772
}
749-
// HACK
750-
// exitprocess = true;
751773
}
752774
} catch (error) {
753775
var message = (error.message ? error.message : error);
754776
this._logger.error(message);
755777
if (message == "Uninstall failed") {
756778
this._logger.info("Uninstall failed, request process exit");
779+
this.RED.log.error("Uninstall failed, request process exit");
757780
exitprocess = true;
758781
}
759782
if (message == "Install failed") {
760783
this._logger.info("Install failed, request process exit");
784+
this.RED.log.error("Install failed, request process exit");
761785
exitprocess = true;
762786
}
763787
if (message == "Module already loaded") {
@@ -784,21 +808,26 @@ export class noderedcontribopenflowstorage {
784808
if (exitprocess && Config.auto_restart_when_needed) {
785809
if (NoderedUtil.isDocker()) {
786810
this._logger.info("noderedcontribopenflowstorage::onupdate: Running as docker, just quit process, kubernetes will start a new version");
811+
this.RED.log.warn("noderedcontribopenflowstorage::onupdate: Running as docker, just quit process, kubernetes will start a new version");
787812
process.exit(1);
788813
} else {
789814
if (servicename != "service-name-not-set") {
790815
var _servicename = path.basename(servicename)
791816
this._logger.info("noderedcontribopenflowstorage::onupdate: Restarting service " + _servicename);
817+
this.RED.log.warn("noderedcontribopenflowstorage::onupdate: Restarting service " + _servicename);
792818
RestartService(_servicename);
793819
// process.exit(1);
794820
} else {
821+
this.RED.log.error("noderedcontribopenflowstorage::onupdate: Not running in docker, nor started as a service, please restart Node-Red manually");
795822
this._logger.info("noderedcontribopenflowstorage::onupdate: Not running in docker, nor started as a service, please restart Node-Red manually");
796823
}
797824
}
798825
} else if (exitprocess) {
799826
this._logger.info("noderedcontribopenflowstorage::onupdate: Restart is needed, auto_restart_when_needed is false");
827+
this.RED.log.warn("noderedcontribopenflowstorage::onupdate: Restart is needed, auto_restart_when_needed is false");
800828
} else if (!exitprocess) {
801829
this._logger.info("noderedcontribopenflowstorage::onupdate: Restart not needed");
830+
this.RED.log.warn("noderedcontribopenflowstorage::onupdate: Restart not needed");
802831
}
803832

804833
}
@@ -808,6 +837,7 @@ export class noderedcontribopenflowstorage {
808837
this._logger.info("* " + entity._type + " was updated, reloading NodeRED flows");
809838
this._logger.info("* loadFlows last updated " + seconds + " seconds ago");
810839
this._logger.info("**************************************************");
840+
this.RED.log.warn("Reloading flows");
811841
await this.RED.nodes.loadFlows(true);
812842
} else {
813843
this._logger.info("noderedcontribopenflowstorage::onupdate " + entity._type + " - COMPLETE !! " + new Date().toLocaleTimeString());

0 commit comments

Comments
 (0)