Exemplo n.º 1
0
 public function setConfigs($configs)
 {
     if (!empty($configs) && is_array($configs)) {
         foreach ($configs as $value) {
             if (!is_array($value) || !is_array($value['settings'])) {
                 continue;
             }
             $config = new FarmRoleStorageConfig($this->farmRole);
             $config->create($value);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param \DBFarmRole $farmRole
  * @return FarmRoleStorageConfig[]
  */
 public static function getByFarmRole(\DBFarmRole $farmRole)
 {
     $db = \Scalr::getDb();
     $configs = array();
     $ids = $db->GetCol('SELECT id FROM farm_role_storage_config WHERE farm_role_id = ?', array($farmRole->ID));
     foreach ($ids as $id) {
         $config = new FarmRoleStorageConfig($farmRole);
         if ($config->loadById($id)) {
             $configs[] = $config;
         }
     }
     return $configs;
 }
Exemplo n.º 3
0
 /**
  * Save storage configs
  *
  * @param   array   $configs    Array of storage config
  * @param   bool    $validate   optional    If true validate config before save
  * @throws  FarmRoleStorageException
  */
 public function setConfigs($configs, $validate = true)
 {
     $configs = is_array($configs) ? $configs : [];
     $ephemeralEc2 = [];
     $ephemeralGce = [];
     foreach ($configs as $value) {
         if (!is_array($value) || !is_array($value['settings'])) {
             continue;
         }
         $object = new FarmRoleStorageConfig($this->farmRole);
         $object->apply($value);
         if ($validate) {
             $r = $object->validate();
             if ($r !== true) {
                 throw new FarmRoleStorageException($r);
             }
         }
         $config = new FarmRoleStorageConfig($this->farmRole);
         $config->create($object);
         if ($config->type == FarmRoleStorageConfig::TYPE_EC2_EPHEMERAL) {
             $ephemeralEc2[$config->settings[FarmRoleStorageConfig::SETTING_EC2_EPHEMERAL_NAME]] = $config->id;
         } else {
             if ($config->type == FarmRoleStorageConfig::TYPE_GCE_EPHEMERAL) {
                 $ephemeralGce[$config->settings[FarmRoleStorageConfig::SETTING_GCE_EPHEMERAL_NAME]] = $config->id;
             }
         }
     }
     // validate ephemeral configs
     foreach (self::getConfigs() as $config) {
         if ($config->type == FarmRoleStorageConfig::TYPE_EC2_EPHEMERAL) {
             $name = $config->settings[FarmRoleStorageConfig::SETTING_EC2_EPHEMERAL_NAME];
             if (!isset($ephemeralEc2[$name]) || $ephemeralEc2[$name] != $config->id) {
                 $config->delete();
             }
         } else {
             if ($config->type == FarmRoleStorageConfig::TYPE_GCE_EPHEMERAL) {
                 $name = $config->settings[FarmRoleStorageConfig::SETTING_GCE_EPHEMERAL_NAME];
                 if (!isset($ephemeralGce[$name]) || $ephemeralGce[$name] != $config->id) {
                     $config->delete();
                 }
             }
         }
     }
 }