Spaces:
Sleeping
Sleeping
File size: 4,887 Bytes
e2dcb4d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
/**
* VM Placement Configuration Module
*
* Provides configurable infrastructure and workload settings for the VM placement
* quickstart, including sliders for racks, servers, VMs, and solver time.
*/
// =============================================================================
// Configuration State
// =============================================================================
let currentConfig = {
rackCount: 3,
serversPerRack: 4,
vmCount: 20,
solverTime: 30
};
// =============================================================================
// Initialization
// =============================================================================
/**
* Initialize configuration UI and event handlers.
* Called automatically when the script loads.
*/
function initConfig() {
// Rack count slider
$("#rackCountSlider").on("input", function() {
currentConfig.rackCount = parseInt(this.value);
$("#rackCountValue").text(this.value);
updateConfigSummary();
});
// Servers per rack slider
$("#serversPerRackSlider").on("input", function() {
currentConfig.serversPerRack = parseInt(this.value);
$("#serversPerRackValue").text(this.value);
updateConfigSummary();
});
// VM count slider
$("#vmCountSlider").on("input", function() {
currentConfig.vmCount = parseInt(this.value);
$("#vmCountValue").text(this.value);
updateConfigSummary();
});
// Solver time slider
$("#solverTimeSlider").on("input", function() {
currentConfig.solverTime = parseInt(this.value);
$("#solverTimeValue").text(formatSolverTime(this.value));
});
// Generate button
$("#generateDataBtn").click(function() {
generateCustomData();
});
// Initialize summary
updateConfigSummary();
}
// =============================================================================
// UI Updates
// =============================================================================
function updateConfigSummary() {
const totalServers = currentConfig.rackCount * currentConfig.serversPerRack;
$("#configSummary").text(
`${totalServers} servers across ${currentConfig.rackCount} rack${currentConfig.rackCount > 1 ? 's' : ''}, ` +
`${currentConfig.vmCount} VMs to place`
);
}
function formatSolverTime(seconds) {
if (seconds >= 60) {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
}
return `${seconds}s`;
}
// =============================================================================
// Data Generation
// =============================================================================
function generateCustomData() {
const btn = $("#generateDataBtn");
const originalHtml = btn.html();
// Show loading state
btn.prop("disabled", true);
btn.html('<i class="fas fa-spinner fa-spin me-1"></i> Generating...');
$.ajax({
url: "/demo-data/generate",
type: "POST",
data: JSON.stringify({
rack_count: currentConfig.rackCount,
servers_per_rack: currentConfig.serversPerRack,
vm_count: currentConfig.vmCount
}),
contentType: "application/json"
})
.done(function(placement) {
// Reset animation state for new data
isFirstRender = true;
vmPositionCache = {};
previousScore = null;
placementId = null;
// Store and render new data
loadedPlacement = placement;
renderPlacement(placement);
// Flash success
btn.html('<i class="fas fa-check me-1"></i> Generated!');
btn.removeClass("btn-primary").addClass("btn-success");
setTimeout(() => {
btn.html(originalHtml);
btn.removeClass("btn-success").addClass("btn-primary");
btn.prop("disabled", false);
}, 1500);
})
.fail(function(xhr) {
showError("Failed to generate custom data", xhr);
btn.html(originalHtml);
btn.prop("disabled", false);
});
}
// =============================================================================
// Solver Time Integration
// =============================================================================
/**
* Get the current solver time setting.
* Can be used by app.js to configure solver termination.
*/
function getSolverTime() {
return currentConfig.solverTime;
}
/**
* Get the current configuration.
*/
function getCurrentConfig() {
return { ...currentConfig };
}
// Export for use in app.js
window.currentConfig = currentConfig;
window.getSolverTime = getSolverTime;
window.getCurrentConfig = getCurrentConfig;
window.initConfig = initConfig;
// Initialize when DOM is ready
$(document).ready(function() {
initConfig();
});
|