refactor(contorller): update to consider iowa_2 and look at plant token vs server going forward

This commit is contained in:
2025-09-29 12:44:46 -05:00
parent 99e70fcafb
commit a5a67660e8
4 changed files with 214 additions and 93 deletions

View File

@@ -13,7 +13,7 @@ import (
socketio "github.com/googollee/go-socket.io"
)
func copyBuild(server *socketio.Server, plant string, drive string) {
func copyBuild(server *socketio.Server, plant string, location string) {
// Load from environment in real-life code!
user := os.Getenv("ADM_USER")
pass := os.Getenv("ADM_PASS")
@@ -21,7 +21,7 @@ func copyBuild(server *socketio.Server, plant string, drive string) {
// latest build
latestbuild := lastestBuild()
src := latestbuild
plantServer := fmt.Sprintf("\\\\%v\\%v$\\lst", plant, drive)
plantServer := fmt.Sprintf("\\\\%v\\%v", plant, location)
// Build PowerShell
psScript := fmt.Sprintf(`

View File

@@ -32,6 +32,28 @@
.error {
color: #f33;
}
#server-buttons {
display: grid;
grid-template-columns: repeat(4, 1fr); /* 4 equal columns */
gap: 0.75rem; /* roughly Tailwind gap-3 */
margin: 1rem 0;
}
#server-buttons button {
padding: 0.5rem 1rem;
font-family: monospace;
border: 1px solid #444;
background: #222;
color: #eee;
cursor: pointer;
border-radius: 4px;
transition: all 0.2s ease;
}
#server-buttons button:hover {
background: #333;
border-color: #888;
}
</style>
</head>
<body>
@@ -74,15 +96,9 @@
</div>
<div id="logWindow"></div>
<div>
<button id="USMCD1VMS036">USMCD1VMS036</button>
<button id="USBET1VMS006">USBET1VMS006</button>
<button id="USBOW1VMS006">USBOW1VMS006</button>
<button id="USKSC1VMS006">USKSC1VMS006</button>
<button id="USMCD1VMS006">USMCD1VMS006</button>
<button id="USSLC1VMS006">USSLC1VMS006</button>
<button id="USSTP1VMS006">USSTP1VMS006</button>
<button id="USDAY1VMS006">USDAY1VMS006</button>
<div id="controls">
<div id="server-buttons"></div>
<button id="btnAll">Copy to ALL</button>
</div>
<script>
@@ -98,6 +114,91 @@
transports: ["polling"],
});
const servers = [
{
name: "Test server",
server: "USMCD1VMS036",
location: "E$\\LST",
},
{
name: "Bethlehem",
server: "USBET1VMS006",
location: "E$\\LST",
},
{
name: "Bowling Green 1",
server: "USBOW1VMS006",
location: "E$\\LST",
},
{
name: "Bowling Green 2",
server: "USBOW2VMS006",
location: "E$\\LST",
},
{
name: "Flornece",
server: "USFLO1VMS006",
location: "E$\\LST",
},
{
name: "Kasnas City",
server: "USKSC1VMS006",
location: "E$\\LST",
},
{
name: "Marked Tree",
server: "USMAR1VMS006",
location: "E$\\LST",
},
{
name: "McDonough",
server: "USMCD1VMS006",
location: "E$\\LST",
},
{
name: "Salt Lake City",
server: "USSLC1VMS006",
location: "E$\\LST",
},
{
name: "St.Peters",
server: "USSTP1VMS006",
location: "D$\\LST",
},
{ name: "Dayton", server: "USDAY1VMS006", location: "E$\\LST" },
{ name: "Lima", server: "USLIM1VMS006", location: "E$\\LST" },
{
name: "Iowa - EBM",
server: "USIOW1VMS006",
location: "D$\\LST\\LST",
},
{
name: "Iowa - ISBM",
server: "USIOW1VMS006",
location: "D$\\LST\\LST_2",
},
{
name: "Houston",
server: "USHOU1VMS006",
location: "E$\\LST\\LST",
},
{
name: "Sherman",
server: "USSHE1VMS006",
location: "E$\\LST\\LST",
},
{
name: "West Bend",
server: "USWEB1VMS006",
location: "E$\\LST\\LST",
},
{
name: "Jerfferson City",
server: "USJCI1VMS006",
location: "E$\\LST\\LST",
},
];
// log window reference
const logWindow = document.getElementById("logWindow");
@@ -208,73 +309,89 @@
};
};
// all the server copy buttons
document.getElementById("USMCD1VMS036").onclick = () => {
socket.emit("update", {
action: "copy",
target: "USMCD1VMS036",
drive: "e",
}); // "frontend" = payload target
logMessage("info", "Copying to USMCD1VMS036");
const serverButtonsDiv = document.getElementById("server-buttons");
servers.forEach((srv) => {
const btn = document.createElement("button");
btn.textContent = srv.name;
btn.dataset.server = srv.server;
btn.dataset.drive = srv.drive;
btn.addEventListener("click", () => {
socket.emit("update", {
action: "copy",
target: srv.server,
location: srv.location,
});
logMessage(
"info",
`Copying to ${
srv.name
} (drive ${srv.drive.toUpperCase()})`
);
});
serverButtonsDiv.appendChild(btn);
});
let copyQueue = []; // Holds list of servers left
let currentServer = null; // Track which server is waiting confirmation
let isRunningAll = false;
document.getElementById("btnAll").onclick = () => {
if (isRunningAll) {
logMessage("info", "⚠️ Copy to ALL already running...");
return;
}
copyQueue = [...servers]; // fresh clone of the servers
isRunningAll = true;
logMessage(
"info",
"▶️ Starting sequential copy to ALL servers..."
);
runNextInQueue();
};
document.getElementById("USBET1VMS006").onclick = () => {
socket.emit("update", {
action: "copy",
target: "USBET1VMS006",
drive: "e",
}); // "frontend" = payload target
logMessage("info", "Copying to USBET1VMS006");
};
document.getElementById("USBOW1VMS006").onclick = () => {
socket.emit("update", {
action: "copy",
target: "USBOW1VMS006",
drive: "e",
}); // "frontend" = payload target
logMessage("info", "Copying to USBOW1VMS006");
};
document.getElementById("USSLC1VMS006").onclick = () => {
socket.emit("update", {
action: "copy",
target: "USSLC1VMS006",
drive: "e",
}); // "frontend" = payload target
logMessage("info", "Copying to USSLC1VMS006");
};
function runNextInQueue() {
if (copyQueue.length === 0) {
logMessage("info", "✅ Finished copying to ALL servers!");
isRunningAll = false;
currentServer = null;
return;
}
currentServer = copyQueue.shift();
logMessage(
"info",
`🚀 Copying to ${
currentServer.name
} (drive ${currentServer.drive.toUpperCase()})`
);
document.getElementById("USSTP1VMS006").onclick = () => {
socket.emit("update", {
action: "copy",
target: "USSTP1VMS006",
drive: "d",
}); // "frontend" = payload target
logMessage("info", "Copying to USSTP1VMS006");
};
document.getElementById("USKSC1VMS006").onclick = () => {
socket.emit("update", {
action: "copy",
target: "USksc1VMS006",
drive: "e",
}); // "frontend" = payload target
logMessage("info", "Copying to USKSC1VMS006");
};
document.getElementById("USDAY1VMS006").onclick = () => {
socket.emit("update", {
action: "copy",
target: "USDAY1VMS006",
drive: "e",
}); // "frontend" = payload target
logMessage("info", "Copying to USDAY1VMS006");
};
document.getElementById("USMCD1VMS006").onclick = () => {
socket.emit("update", {
action: "copy",
target: "USMCD1VMS006",
drive: "e",
}); // "frontend" = payload target
logMessage("info", "Copying to USMCD1VMS006");
};
target: currentServer.name,
drive: currentServer.drive,
});
}
socket.on("updateLogs", (msg) => {
//logMessage("update", msg);
// Only check queue progress if we're in All mode and have a currentServer
if (isRunningAll && currentServer) {
const expected = `✅ Copy to ${currentServer.name} successful`;
if (msg.includes(expected)) {
logMessage(
"info",
`✅ Confirmed: ${currentServer.name} done`
);
runNextInQueue(); // trigger the next server
}
}
});
socket.on("logs", (msg) => logMessage("logs", msg));
socket.on("errors", (msg) => logMessage("errors", msg));

View File

@@ -15,9 +15,9 @@ import (
)
type UpdatePayload struct {
Action string `json:"action"`
Target string `json:"target"`
Drive string `json:"drive"`
Action string `json:"action"`
Target string `json:"target"`
Location string `json:"location"`
}
func registerUpdateChannel(server *socketio.Server) {
@@ -32,7 +32,7 @@ func registerUpdateChannel(server *socketio.Server) {
server.OnEvent("/", "update", func(s socketio.Conn, payload UpdatePayload) {
switch strings.ToLower(payload.Action) {
case "copy":
copyLatestBuild(server, payload.Target, payload.Drive)
copyLatestBuild(server, payload.Target, payload.Location)
case "update":
updateServer(server, payload.Target)
@@ -81,13 +81,13 @@ func updateServer(server *socketio.Server, target string) {
}
}
func copyLatestBuild(server *socketio.Server, target string, drive string) {
func copyLatestBuild(server *socketio.Server, target string, location string) {
server.BroadcastToRoom("/", "update", "updateLogs",
fmt.Sprintf("🚀 Copying latest build to %v", target))
copyBuild(server, target, drive)
copyBuild(server, target, location)
}
func triggerRemoteUpdate(server *socketio.Server, remoteURL string, payload UpdatePayload) {
func triggerRemoteUpdate(server *socketio.Server, token string, payload UpdatePayload) {
fmt.Println("running the update process")
basePath := "/api/controller"
@@ -98,7 +98,7 @@ func triggerRemoteUpdate(server *socketio.Server, remoteURL string, payload Upda
// send POST request with JSON, expect SSE / streaming text back
body, _ := json.Marshal(payload)
url := fmt.Sprintf("https://%v.alpla.net%v/update", remoteURL, basePath)
url := fmt.Sprintf("https://%vprod.alpla.net%v/update", token, basePath)
fmt.Println(url)
//url := fmt.Sprintf("http://%v:8080/api/controller/update", remoteURL)
fmt.Println(url)

View File

@@ -14,24 +14,28 @@ param (
# example string to pass over, you must be in the script dir when you run this script. or it will fail to find the linked scripts
# If we do not pass plant to update over it will auto do all plants if we want a specific plant we need to do like below
# .\update-controllers.ps1 -App_Path "C:\Users\matthes01\Documents\lst" -Token "usiow2" -BuildController no -PlantToUpdate "usiow1vms006" -Remote_Path "D$\LST\lst_2"
# .\update-controllers.ps1 -App_Path "C:\Users\matthes01\Documents\lst" -Token "usstp1" -BuildController yes -PlantToUpdate "usstp1vms006" -Remote_Path "D$\LST"
# .\update-controllers.ps1 -App_Path "C:\Users\matthes01\Documents\lst" -Token "test3" -BuildController yes
$Plants = @(
@{ Server = "usmcd1vms036"; Token = "test3"; Remote_Path = "E$\LST" }
@{ Server = "usmar1vms006"; Token = "usmar1" ; Remote_Path = "E$\LST" }
@{ Server = "usbet1vms006"; Token = "usbet1"; Remote_Path = "E$\LST" }
@{ Server = "usbow1vms006"; Token = "usbow1" ; Remote_Path = "E$\LST" }
@{ Server = "usbow2vms006"; Token = "usbow2" ; Remote_Path = "E$\LST" }
@{ Server = "usday1vms006"; Token = "usday1" ; Remote_Path = "E$\LST" }
@{ Server = "usflo1vms006"; Token = "usflo1" ; Remote_Path = "E$\LST" }
@{ Server = "usiow1vms006"; Token = "usiow1" ; Remote_Path = "D$\LST\lst" }
@{ Server = "usiow1vms006"; Token = "usiow2" ; Remote_Path = "D$\LST\lst_2" }
@{ Server = "uslim1vms006"; Token = "uslim1" ; Remote_Path = "E$\LST" }
@{ Server = "usmcd1vms006"; Token = "usmcd1" ; Remote_Path = "E$\LST" }
@{ Server = "usmcd1vms036"; Token = "test3"; Remote_Path = "E$\LST" }
@{ Server = "usmar1vms006"; Token = "usmar1" ; Remote_Path = "E$\LST" }
@{ Server = "usbet1vms006"; Token = "usbet1"; Remote_Path = "E$\LST" }
@{ Server = "usbow1vms006"; Token = "usbow1" ; Remote_Path = "E$\LST" }
@{ Server = "usbow2vms006"; Token = "usbow2" ; Remote_Path = "E$\LST" }
@{ Server = "usday1vms006"; Token = "usday1" ; Remote_Path = "E$\LST" }
@{ Server = "usflo1vms006"; Token = "usflo1" ; Remote_Path = "E$\LST" }
@{ Server = "usiow1vms006"; Token = "usiow1" ; Remote_Path = "D$\LST\lst" }
@{ Server = "usiow1vms006"; Token = "usiow2" ; Remote_Path = "D$\LST\lst_2" }
@{ Server = "uslim1vms006"; Token = "uslim1" ; Remote_Path = "E$\LST" }
@{ Server = "usmcd1vms006"; Token = "usmcd1" ; Remote_Path = "E$\LST" }
@{ Server = "usslc1vms006"; Token = "usslc1" ; Remote_Path = "E$\LST" }
@{ Server = "usstp1vms006"; Token = "usstp1" ; Remote_Path = "D$\LST" }
@{ Server = "usksc1vms006"; Token = "usksc1" ; Remote_Path = "E$\LST" }
@{ Server = "ushou1vms006"; Token = "ushou1" ; Remote_Path = "E$\LST" } #15
@{ Server = "usshe1vms006"; Token = "usshe1" ; Remote_Path = "E$\LST" }#16
@{ Server = "usweb1vms006"; Token = "usweb1" ; Remote_Path = "E$\LST" }#17
@{ Server = "usjci1vms006"; Token = "usjci1" ; Remote_Path = "E$\LST" }
)