Page MenuHomePhabricator
Paste P8589

import.php
ActivePublic

Authored by CDanis on Jun 4 2019, 7:25 PM.
Tags
None
Referenced Files
F29879431: raw.txt
Jul 26 2019, 8:02 PM
F29879396: raw.txt
Jul 26 2019, 7:59 PM
F29343396: raw.txt
Jun 4 2019, 7:25 PM
Subscribers
None
#!/usr/bin/env php
<?php
$argc == 3 or die("usage: $argv[0] INPUTFILE DC-NAME\n");
$inputfile = $argv[1] or die;
$dc = $argv[2] or die;
include $inputfile;
$INSTANCES = [];
$SECTIONS = [];
foreach ($wgLBFactoryConf['sectionLoads'] as $section => $secinsts) {
if ($section == "DEFAULT") $section = "s3";
foreach ($secinsts as $instance => $weight) {
if ($instance === array_key_first($secinsts)) {
# First in sectionLoads --> the master. also create an associated section object.
$SECTIONS[$section] = [
'master' => $instance,
'min_replicas' => 0,
'readonly' => FALSE,
'ro_reason' => "PLACEHOLDER"
];
}
# If needed, create an initial instance object for this instance.
if (!isset($INSTANCES[$instance])) {
[$host, $port] = explode(':', $instance);
$INSTANCES[$instance] = [
'host_ip' => explode(':', $wgLBFactoryConf['hostsByName'][$instance])[0],
'sections' => [],
];
if (isset($port)) {
$INSTANCES[$instance]['port'] = intval($port);
}
}
# now append to sections
$INSTANCES[$instance]['sections'][$section] = [
'weight' => $weight,
'pooled' => TRUE,
'percentage' => 100
];
}
}
foreach ($wgLBFactoryConf['groupLoadsBySection'] as $section => $groupblob) {
if ($section == "DEFAULT") $section = "s3";
foreach ($groupblob as $group => $groupinsts) {
foreach ($groupinsts as $instance => $weight) {
#echo "$section $group $instance $weight\n";
if (!isset($INSTANCES[$instance]['sections'][$section]['groups'])) {
$INSTANCES[$instance]['sections'][$section]['groups'] = [];
}
$INSTANCES[$instance]['sections'][$section]['groups'][$group] = [
'pooled' => TRUE, 'weight' => $weight];
}
}
}
foreach ($wgLBFactoryConf['readOnlyBySection'] as $section => $reason) {
$SECTIONS[$section]['readonly'] = TRUE;
$SECTIONS[$section]['ro_reason'] = $reason;
}
ksort($INSTANCES);
ksort($SECTIONS);
{
$instfile = fopen("import/dbconfig-instance/instances-$dc.yaml", "w");
fwrite($instfile, "$dc:\n");
foreach ($INSTANCES as $instance => $data) {
fwrite($instfile, " - $instance\n");
{
$datafile = fopen("import/instances/$dc/$instance", "w");
fwrite($datafile, json_encode($data));
}
}
}
{
$secfile = fopen("import/dbconfig-section/sections-$dc.yaml", "w");
fwrite($secfile, "$dc:\n");
foreach ($SECTIONS as $section => $data) {
fwrite($secfile, " - $section\n");
{
$datafile = fopen("import/sections/$dc/$section", "w");
fwrite($datafile, json_encode($data));
}
}
}