protected function run1($stage)
{
$envs = [];
$platform = SERVER_PLATFORMS::GCE;
$platformModule = PlatformFactory::NewPlatform($platform);
/* @var $platformModule GoogleCEPlatformModule*/
$result = $this->db->Execute("\n SELECT s.`server_id`, s.`cloud_location`, s.`type`, s.`env_id`, sp.`value` AS vcpus\n FROM servers AS s\n LEFT JOIN server_properties sp ON sp.`server_id`= s.`server_id` AND sp.`name` = ?\n WHERE s.`status` NOT IN (?, ?)\n AND s.`type` IS NOT NULL\n AND s.`platform` = ?\n ", [Server::INFO_INSTANCE_VCPUS, Server::STATUS_PENDING_TERMINATE, Server::STATUS_TERMINATED, $platform]);
while ($row = $result->FetchRow()) {
if (!empty($row["type"]) && empty($row['vcpus'])) {
if (!array_key_exists($row["env_id"], $envs)) {
$envs[$row["env_id"]] = \Scalr_Environment::init()->loadById($row["env_id"]);
}
try {
$instanceTypeInfo = $platformModule->getInstanceType($row["type"], $envs[$row["env_id"]], $row["cloud_location"]);
if ($instanceTypeInfo instanceof CloudInstanceType) {
$vcpus = $instanceTypeInfo->vcpus;
} else {
trigger_error("Value of vcpus for instance type " . $row["type"] . " is missing for platform " . $platform, E_USER_WARNING);
$vcpus = 0;
}
if ((int) $vcpus > 0) {
$this->db->Execute("\n INSERT INTO server_properties (`server_id`, `name`, `value`) VALUES (?, ?, ?)\n ON DUPLICATE KEY UPDATE `value` = ?\n ", [$row["server_id"], Server::INFO_INSTANCE_VCPUS, $vcpus, $vcpus]);
}
} catch (\Exception $e) {
$this->console->warning("Can't get access to %s, error: %s", $platform, $e->getMessage());
}
}
}
}