Add numbered step logging for game and dev provisioning
- STEP 0: Starting provisioning (game/dev indicator) - STEP 1: allocate VMID - STEP 2: port allocation (or skip message if not needed) - STEP 3: clone template - STEP 4: configure CPU/mem/bridge/tags - STEP 5: start container - STEP 6: detect container IP - STEP 7: build agent payload - STEP 8: POST /config to agent - STEP 9: wait for agent running via /status - STEP 10: DB save - STEP 11: commit ports - STEP 12: publish edge - Matches original provision.js logging format
This commit is contained in:
parent
9eb678ea25
commit
26db484c2e
@ -278,6 +278,8 @@ async function waitForAgentRunning({ ip, timeoutMs = 10 * 60_000 }) {
|
||||
export async function provisionAgentInstance(body = {}) {
|
||||
const ctype = body.ctype || "game";
|
||||
|
||||
console.log(`[agentProvision] STEP 0: Starting ${ctype} container provisioning`);
|
||||
|
||||
const req =
|
||||
ctype === "dev"
|
||||
? normalizeDevRequest(body)
|
||||
@ -289,11 +291,13 @@ export async function provisionAgentInstance(body = {}) {
|
||||
let txnId = null;
|
||||
|
||||
try {
|
||||
console.log('[agentProvision] STEP 1: allocate VMID');
|
||||
vmid = await allocateVmid(ctype);
|
||||
console.log(`[agentProvision] → Allocated vmid=${vmid}`);
|
||||
|
||||
// Allocate ports if needed
|
||||
if (req.portsNeeded && req.portsNeeded > 0) {
|
||||
console.log(`[agentProvision] Allocating ${req.portsNeeded} port(s)`);
|
||||
console.log(`[agentProvision] STEP 2: port allocation`);
|
||||
txnId = crypto.randomUUID();
|
||||
|
||||
const portObjs = await PortAllocationService.reserve({
|
||||
@ -311,7 +315,9 @@ export async function provisionAgentInstance(body = {}) {
|
||||
? portObjs.map(p => typeof p === 'object' ? p.port : p)
|
||||
: [portObjs];
|
||||
|
||||
console.log(`[agentProvision] Allocated ports: ${allocatedPorts.join(', ')}`);
|
||||
console.log(`[agentProvision] → Allocated ports: ${allocatedPorts.join(', ')}`);
|
||||
} else {
|
||||
console.log(`[agentProvision] STEP 2: port allocation (skipped - no ports needed)`);
|
||||
}
|
||||
|
||||
const hostname = generateSystemHostname({
|
||||
@ -324,6 +330,7 @@ export async function provisionAgentInstance(body = {}) {
|
||||
// Generate FQDN for DNS/EdgePublisher
|
||||
const slotHostname = `${hostname}.${ZONE}`;
|
||||
|
||||
console.log(`[agentProvision] STEP 3: clone template ${AGENT_TEMPLATE_VMID} → vmid=${vmid}`);
|
||||
await cloneContainer({
|
||||
templateVmid: AGENT_TEMPLATE_VMID,
|
||||
vmid,
|
||||
@ -331,6 +338,7 @@ export async function provisionAgentInstance(body = {}) {
|
||||
full: 1,
|
||||
});
|
||||
|
||||
console.log(`[agentProvision] STEP 4: configure CPU/mem/bridge/tags`);
|
||||
await configureContainer({
|
||||
vmid,
|
||||
cpu: req.cpuCores || 2,
|
||||
@ -338,10 +346,14 @@ export async function provisionAgentInstance(body = {}) {
|
||||
bridge: ctype === "dev" ? "vmbr2" : "vmbr3",
|
||||
});
|
||||
|
||||
console.log(`[agentProvision] STEP 5: start container`);
|
||||
await startWithRetry(vmid);
|
||||
|
||||
console.log(`[agentProvision] STEP 6: detect container IP`);
|
||||
ctIp = await getCtIpWithRetry(vmid);
|
||||
console.log(`[agentProvision] → ctIp=${ctIp}`);
|
||||
|
||||
console.log(`[agentProvision] STEP 7: build agent payload`);
|
||||
// Build payload WITH ports
|
||||
const payload =
|
||||
ctype === "dev"
|
||||
@ -358,9 +370,13 @@ export async function provisionAgentInstance(body = {}) {
|
||||
ports: allocatedPorts,
|
||||
});
|
||||
|
||||
console.log(`[agentProvision] STEP 8: POST /config to agent (async provision+start)`);
|
||||
await sendAgentConfig({ ip: ctIp, payload });
|
||||
|
||||
console.log(`[agentProvision] STEP 9: wait for agent to be running via /status`);
|
||||
await waitForAgentRunning({ ip: ctIp });
|
||||
|
||||
console.log(`[agentProvision] STEP 10: DB save`);
|
||||
await prisma.containerInstance.create({
|
||||
data: {
|
||||
vmid,
|
||||
@ -377,7 +393,10 @@ export async function provisionAgentInstance(body = {}) {
|
||||
|
||||
// Enqueue EdgePublisher with ALL required fields
|
||||
if (allocatedPorts.length > 0) {
|
||||
console.log(`[agentProvision] Enqueuing EdgePublisher for vmid=${vmid}`);
|
||||
console.log(`[agentProvision] STEP 11: commit ports`);
|
||||
await PortAllocationService.commit({ vmid, ports: allocatedPorts });
|
||||
|
||||
console.log(`[agentProvision] STEP 12: publish edge`);
|
||||
await enqueuePublishEdge({
|
||||
vmid,
|
||||
slotHostname, // ← FQDN for DNS records
|
||||
@ -387,25 +406,24 @@ export async function provisionAgentInstance(body = {}) {
|
||||
game: req.game,
|
||||
txnId,
|
||||
});
|
||||
|
||||
// Commit ports to mark them as in-use
|
||||
await PortAllocationService.commit({ vmid, ports: allocatedPorts });
|
||||
console.log(`[agentProvision] Ports committed for vmid=${vmid}`);
|
||||
} else {
|
||||
console.log(`[agentProvision] STEP 11-12: port commit + edge publish (skipped - no ports)`);
|
||||
}
|
||||
|
||||
await confirmVmidAllocated(vmid);
|
||||
|
||||
console.log(`[agentProvision] COMPLETE: success`);
|
||||
return { vmid, hostname, ip: ctIp, ports: allocatedPorts };
|
||||
} catch (err) {
|
||||
console.error(`[agentProvision] ERROR for vmid=${vmid}:`, err.message);
|
||||
console.error(`[agentProvision] ERROR:`, err.message);
|
||||
|
||||
// Rollback ports on failure
|
||||
if (vmid && allocatedPorts.length > 0) {
|
||||
try {
|
||||
await PortAllocationService.releaseByVmid(vmid);
|
||||
console.log(`[agentProvision] Rolled back ports for vmid=${vmid}`);
|
||||
console.log(`[agentProvision] → Rolled back ports for vmid=${vmid}`);
|
||||
} catch (rollbackErr) {
|
||||
console.error(`[agentProvision] Port rollback failed:`, rollbackErr.message);
|
||||
console.error(`[agentProvision] → Port rollback failed:`, rollbackErr.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user