/** * Setups callback to API HTTP client configured for specified server * * @param PlatformModuleInterface $platformModule Platform module for the server * @param callable $callback optional Settable callback * @param DBServer $dbServer optional Server to configure client */ private function setupClientCallback(PlatformModuleInterface $platformModule, callable $callback = null, DBServer $dbServer = null) { $client = $platformModule->getHttpClient($dbServer); if ($client instanceof CallbackInterface) { $client->setCallback($callback); } }
/** * Gets instance types with its prices * * @param string $cloudLocation * @param string $url * @param PlatformModuleInterface $pm * @param string $platformName * @param DateTime $effectiveDate optional The date on which prices should be applied * @param Scalr_Environment $env optional * @return array */ private function getTypesWithPrices($cloudLocation, $url, $pm, $platformName, $effectiveDate = null, Scalr_Environment $env = null) { $result = ['cloudLocation' => $cloudLocation, 'url' => $this->getContainer()->analytics->prices->normalizeUrl($url)]; try { $typeNames = $pm->getInstanceTypes($env, $cloudLocation); } catch (Exception $e) { //Has no connection to cloud provider or invalid keys $typeNames = []; //Fetches cloud location entity from the cache $cl = CloudLocation::findPk(CloudLocation::calculateCloudLocationId($platformName, $result['cloudLocation'], $result['url'])); //It is possible that it might have been already removed if ($cl instanceof CloudLocation) { foreach ($cl->getActiveInstanceTypes() as $instanceTypeEntity) { /* @var $instanceTypeEntity CloudInstanceType */ $typeNames[$instanceTypeEntity->instanceTypeId] = $instanceTypeEntity->name; } } } $result['types'] = array_keys($typeNames); $pricing = $this->getPlatformPricing($platformName, $result['cloudLocation'], $result['url'], $effectiveDate); if (!empty($pricing["prices"])) { foreach ($pricing['prices'] as $price) { if (false !== ($pos = array_search($price['type'], $result['types']))) { unset($result['types'][$pos]); } } } else { $pricing["prices"] = []; } foreach ($result['types'] as $type) { $pricing['prices'][] = ['type' => $type, 'name' => isset($typeNames[$type]) ? $typeNames[$type] : $type]; } $result = array_merge($result, $pricing); unset($result['types']); //Prices should be ordered by name if (!empty($result['prices']) && is_array($result['prices'])) { usort($result['prices'], function ($a, $b) { if ($a['type'] == $b['type']) { return 0; } return $a['type'] < $b['type'] ? -1 : 1; }); } return $result; }
/** * Gets instance types with its prices * * @param string $cloudLocation * @param string $url * @param PlatformModuleInterface $pm * @param string $platformName * @param DateTime $effectiveDate optional The date on which prices should be applied * @param Scalr_Environment $env optional * @return array */ private function getTypesWithPrices($cloudLocation, $url, $pm, $platformName, $effectiveDate = null, Scalr_Environment $env = null) { $typeNames = $pm->getInstanceTypes($env, $cloudLocation); $result = ['cloudLocation' => $cloudLocation, 'types' => array_keys($typeNames), 'url' => $this->getContainer()->analytics->prices->normalizeUrl($url)]; $pricing = $this->getPlatformPricing($platformName, $result['cloudLocation'], $result['url'], $effectiveDate); if ($pricing['prices']) { foreach ($pricing['prices'] as $price) { if (false !== ($pos = array_search($price['type'], $result['types']))) { unset($result['types'][$pos]); } } } foreach ($result['types'] as $type) { $pricing['prices'][] = ['type' => $type, 'name' => isset($typeNames[$type]) ? $typeNames[$type] : $type]; } $result = array_merge($result, $pricing); unset($result['types']); //Prices should be ordered by name if (!empty($result['prices']) && is_array($result['prices'])) { usort($result['prices'], function ($a, $b) { if ($a['type'] == $b['type']) { return 0; } return $a['type'] < $b['type'] ? -1 : 1; }); } return $result; }