Example #1
0
 protected function run1($stage)
 {
     $this->console->out("Initializing instance_type_name field in servers_history table");
     $result = $this->db->Execute("\n            SELECT sh.* FROM servers_history sh\n            JOIN servers s USING(server_id)\n            WHERE sh.instance_type_name IS NULL\n                AND sh.type IS NOT NULL\n                AND sh.cloud_location IS NOT NULL\n            ORDER BY sh.env_id, sh.platform DESC\n        ");
     $env = null;
     $platform = null;
     $this->db->BeginTrans();
     try {
         $sql = "UPDATE servers_history sh SET sh.instance_type_name = ? WHERE sh.server_id = ?";
         while ($record = $result->FetchRow()) {
             if (!isset($env) || $env->id != $record['env_id']) {
                 $env = Scalr_Environment::init()->loadById($record['env_id']);
                 $platform = null;
             }
             if (in_array($record['platform'], [\SERVER_PLATFORMS::EC2, \SERVER_PLATFORMS::GCE])) {
                 $this->db->Execute($sql, [$record['type'], $record['server_id']]);
                 continue;
             }
             if (!isset($platform) || $platform != $record['platform']) {
                 $platform = $record['platform'];
                 $platformModule = PlatformFactory::NewPlatform($record['platform']);
                 $url = $platformModule->getEndpointUrl($env);
             }
             $cloudLocationId = CloudLocation::calculateCloudLocationId($record['platform'], $record['cloud_location'], $url);
             $instanceTypeEntity = CloudInstanceType::findPk($cloudLocationId, $record['type']);
             /* @var $instanceTypeEntity CloudInstanceType */
             if ($instanceTypeEntity) {
                 $this->db->Execute($sql, [$instanceTypeEntity->name, $record['server_id']]);
             }
         }
         $this->db->CommitTrans();
     } catch (Exception $e) {
         $this->db->RollbackTrans();
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::getInstanceType()
  */
 public function getInstanceType($instanceTypeId, \Scalr_Environment $env, $cloudLocation = null)
 {
     $cloudLocationId = CloudLocation::calculateCloudLocationId(SERVER_PLATFORMS::GCE, $cloudLocation, $this->getEndpointUrl($env));
     $cit = CloudInstanceType::findPk($cloudLocationId, $instanceTypeId);
     if ($cit === null) {
         $instanceTypes = $this->getInstanceTypes($env, $cloudLocation, true);
         if (!empty($instanceTypes[$instanceTypeId])) {
             $cit = CloudInstanceType::findPk($cloudLocationId, $instanceTypeId);
         }
     }
     return $cit;
 }