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