Skip to content

Commit

Permalink
Separate get and reserve
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Jan 4, 2019
1 parent 4c4597a commit 54080e9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/shadowbox/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,29 @@ function reserveAccessKeyPorts(
dedupedPorts.forEach(p => portProvider.addReservedPort(p));
}

async function getPortForNewAccessKeys(
portProvider: PortProvider,
function getPortForNewAccessKeys(
serverConfig: json_config.JsonConfig<server_config.ServerConfigJson>,
keyConfig: json_config.JsonConfig<AccessKeyConfigJson>) {
keyConfig: json_config.JsonConfig<AccessKeyConfigJson>): number {
if (!serverConfig.data().portForNewAccessKeys) {
// NOTE(2019-01-04): For backward compatibility. Delete after servers have been migrated.
if (keyConfig.data().defaultPort) {
// Migrate setting from keyConfig to serverConfig.
serverConfig.data().portForNewAccessKeys = keyConfig.data().defaultPort;
serverConfig.write();
delete keyConfig.data().defaultPort;
keyConfig.write();
} else {
serverConfig.data().portForNewAccessKeys = await portProvider.reserveNewPort();
}
serverConfig.write();
}
return serverConfig.data().portForNewAccessKeys;
}

async function reservePortForNewAccessKeys(
portProvider: PortProvider,
serverConfig: json_config.JsonConfig<server_config.ServerConfigJson>): Promise<number> {
serverConfig.data().portForNewAccessKeys = await portProvider.reserveNewPort();
return serverConfig.data().portForNewAccessKeys;
}

// TODO: Get rid of this after 30 days of everyone's migration to Prometheus.
function createLegacyManagerMetrics(configFilename: string): LegacyManagerMetrics {
const metricsConfig = readMetricsConfig(configFilename);
Expand Down Expand Up @@ -203,8 +207,8 @@ async function main() {
// with that forever) and output new instructions for port configuration.
// - update manger UI to provide new instructions for port configuration in manual mode.
if (createRolloutTracker(serverConfig).isRolloutEnabled('single-port', 0)) {
const portForNewAccessKeys =
await getPortForNewAccessKeys(portProvider, serverConfig, accessKeyConfig);
const portForNewAccessKeys = getPortForNewAccessKeys(serverConfig, accessKeyConfig) ||
await reservePortForNewAccessKeys(portProvider, serverConfig);
accessKeyRepository.enableSinglePort(portForNewAccessKeys);
}

Expand Down

0 comments on commit 54080e9

Please sign in to comment.