refactor(contorller): update to consider iowa_2 and look at plant token vs server going forward
This commit is contained in:
@@ -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(`
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user