Scalr_Scripting_GlobalVariables::validateValues PHP Méthode

validateValues() public méthode

Validate values
public validateValues ( array | ArrayObject $variables, integer $roleId, integer $farmId, integer $farmRoleId, string $serverId = "" ) : array | boolean
$variables array | ArrayObject
$roleId integer
$farmId integer
$farmRoleId integer
$serverId string
Résultat array | boolean Returns true if no errors or array of errors [name of variable => [name of property => [errors]]
    public function validateValues($variables, $roleId = 0, $farmId = 0, $farmRoleId = 0, $serverId = "")
    {
        $this->errors = [];
        $usedNames = [];
        $existedNames = [];
        $currentValues = $this->_getValues($roleId, $farmId, $farmRoleId, $serverId);
        foreach ($currentValues as $v) {
            $existedNames[strtolower($v['name'])] = $v['name'];
        }
        foreach ($variables as $variable) {
            $deleteFlag = isset($variable['flagDelete']) && $variable['flagDelete'] == 1;
            $name = $variable['name'];
            if (empty($name)) {
                continue;
            }
            $lowerName = strtolower($name);
            if (!empty($variable['current'])) {
                $variable = $variable['current'];
            }
            // check for required variable
            if (!empty($currentValues[$name]['locked']) && $currentValues[$name]['locked']['flagRequired'] == $this->scope) {
                if (!($currentValues[$name]['default']['value'] != '' || isset($variable['value']) && trim($variable['value']) != '')) {
                    $this->setError($name, 'value', sprintf('%s is required variable', $name));
                }
            }
            $variable['value'] = isset($variable['value']) ? trim($variable['value']) : "";
            if ($variable['value'] == '' && isset($currentValues[$name]['default'])) {
                $deleteFlag = true;
            }
            if ($deleteFlag) {
                continue;
            }
            $errorByteMessage = "Variable " . $variable['name'] . " contains invalid non-printable characters (e.g. NULL characters).\n                You might have copied it from another application that submitted invalid characters.\n                To solve this issue, you can type in the variable manually.";
            if (strpos($variable['value'], chr(0)) !== false) {
                $this->setError($name, 'value', $errorByteMessage);
            }
            if (!preg_match('/^[A-Za-z]{1,1}[A-Za-z0-9_]{1,127}$/', $name)) {
                $this->setError($name, 'name', "Name should contain only letters, numbers and underscores, start with letter and be from 2 to 128 chars long.");
            } else {
                if (in_array($name, $usedNames)) {
                    $this->setError($name, 'name', "This variable name is already in use.");
                } else {
                    $usedNames[] = $lowerName;
                }
            }
            if (array_key_exists($lowerName, $existedNames) && $existedNames[$lowerName] != $name) {
                if ($this->doNotValidateNameCaseSensitivity) {
                    \Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->warn(new \FarmLogMessage(!empty($farmId) ? $farmId : null, sprintf('Variable "%s" has been already defined as "%s"', !empty($name) ? $name : null, !empty($existedNames[$lowerName]) ? $existedNames[$lowerName] : null), !empty($serverId) ? $serverId : null, null, !empty($farmRoleId) ? $farmRoleId : null));
                } else {
                    $this->setError($name, 'name', sprintf("Name has been already defined as \"%s\"", $existedNames[$lowerName]));
                }
            }
            if (substr($lowerName, 0, 6) == 'scalr_' && !array_key_exists($lowerName, $existedNames) && !array_key_exists($name, $this->configurationVars) || array_key_exists($name, $this->configurationVars) && !in_array($this->scope, [ScopeInterface::SCOPE_SCALR, ScopeInterface::SCOPE_ACCOUNT, ScopeInterface::SCOPE_ENVIRONMENT])) {
                $this->setError($name, 'name', "Prefix 'SCALR_' is reserved and cannot be used for user GVs");
            }
            if (array_key_exists($name, $this->configurationVars) && empty($currentValues[$name]['default'])) {
                $variable = array_merge($variable, $this->configurationVarsDefaults, $this->configurationVars[$name]);
            }
            // set advanced flags only on first level
            if (!empty($currentValues[$name]['default'])) {
                $msg = "You can't redefine advanced settings (flags, format, validator, category)";
                if (!empty($variable['flagRequired'])) {
                    $this->setError($name, 'flagRequired', $msg);
                }
                if (!empty($variable['flagFinal']) && $variable['flagFinal'] == 1) {
                    $this->setError($name, 'flagFinal', $msg);
                }
                if (!empty($variable['flagHidden']) && $variable['flagHidden'] == 1) {
                    $this->setError($name, 'flagHidden', $msg);
                }
                if (!empty($variable['format'])) {
                    $this->setError($name, 'format', $msg);
                }
                if (!empty($variable['validator'])) {
                    $this->setError($name, 'validator', $msg);
                }
                if (!empty($variable['category'])) {
                    $this->setError($name, 'category', $msg);
                }
            } else {
                if (!empty($variable['flagRequired'])) {
                    if ($this->scope == ScopeInterface::SCOPE_FARMROLE || $this->scope == ScopeInterface::SCOPE_SERVER) {
                        $this->setError($name, 'flagRequired', "You can't set required flag on farmrole or server level");
                    } else {
                        $sc = $this->listScopes;
                        array_pop($sc);
                        // exclude SERVER scope
                        $sc = array_slice($sc, array_search($this->scope, $sc) + 1);
                        if (!in_array($variable['flagRequired'], $sc)) {
                            $this->setError($name, 'flagRequired', 'Wrong required scope');
                        }
                    }
                }
                if (!empty($variable['flagFinal']) && $variable['flagFinal'] == 1 && !empty($variable['flagRequired'])) {
                    $this->setError($name, 'flagFinal', "You can't set final and required flags both");
                    $this->setError($name, 'flagRequired', "You can't set final and required flags both");
                }
                if (!empty($variable['validator'])) {
                    if (strpos($variable['validator'], chr(0)) !== false) {
                        $this->setError($name, 'validator', "Validation pattern is not valid (NULL byte)");
                    } else {
                        $this->errorHandlerLastError = '';
                        if (preg_match('/^\\/(.*)\\/[imsxADSUXu]*$/', $variable['validator']) == 1) {
                            set_error_handler([$this, 'errorHandler']);
                            preg_match($variable['validator'], 'test');
                            restore_error_handler();
                        } else {
                            $this->errorHandlerLastError = 'invalid structure';
                        }
                        if ($this->errorHandlerLastError) {
                            $this->setError($name, 'validator', sprintf("Validation pattern is not valid: %s", $this->errorHandlerLastError));
                        } else {
                            if ($variable['value'] != '') {
                                if (preg_match($variable['validator'], $variable['value']) != 1) {
                                    $this->setError($name, 'value', "Value isn't valid because of validation pattern");
                                }
                            }
                        }
                    }
                }
                if (!empty($variable['format'])) {
                    if ($variable['format'] == self::FORMAT_JSON) {
                        json_decode($variable['value']);
                        if (json_last_error() !== JSON_ERROR_NONE) {
                            $this->setError($name, 'value', "The value is not valid JSON");
                        }
                    } else {
                        $cnt = count_chars($variable['format']);
                        if ($cnt[ord('%')] != 1) {
                            $this->setError($name, 'format', "Format isn't valid");
                        }
                    }
                }
                if (!empty($variable['category'])) {
                    if (preg_match('/^[A-Za-z0-9]+[A-Za-z0-9-_]*[A-Za-z0-9]+$/i', $variable['category']) != 1 || strlen($variable['category']) > 31) {
                        $this->setError($name, 'category', "Category should contain only letters, numbers, dashes and underscores, start and end with letter and be from 2 to 32 chars long");
                    }
                    if (substr(strtolower($variable['category']), 0, 6) == 'scalr_' && !array_key_exists($name, $this->configurationVars)) {
                        $this->setError($name, 'category', "Prefix 'SCALR_' is reserved and cannot be used for user GVs");
                    }
                }
            }
            if (!empty($currentValues[$name]['locked'])) {
                if ($currentValues[$name]['locked']['flagFinal'] && $variable['value'] != '') {
                    $this->setError($name, 'value', sprintf('You can\'t change final variable locked on %s level', $currentValues[$name]['locked']['scope']));
                }
                if ($currentValues[$name]['locked']['validator'] && $variable['value'] != '') {
                    $validator = $currentValues[$name]['locked']['validator'];
                    if (preg_match($validator, $variable['value']) != 1) {
                        $this->setError($name, 'value', "Value isn't valid because of validation pattern");
                    }
                }
                if ($currentValues[$name]['locked']['format'] == self::FORMAT_JSON) {
                    json_decode($variable['value']);
                    if (json_last_error() !== JSON_ERROR_NONE) {
                        $this->setError($name, 'value', "The value is not valid JSON");
                    }
                }
            }
        }
        return count($this->errors) ? $this->errors : true;
    }

Usage Example

Exemple #1
0
 /**
  *
  * @param array $farmSettings
  * @param array $roles
  * @return bool
  */
 private function isFarmConfigurationValid($farmId, $farmSettings, array $roles = array())
 {
     $this->errors = array('error_count' => 0);
     $farmVariables = new Scalr_Scripting_GlobalVariables($this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARM);
     $farmRoleVariables = new Scalr_Scripting_GlobalVariables($this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARMROLE);
     if ($farmSettings['variables']) {
         $result = $farmVariables->validateValues($farmSettings['variables'], 0, $farmId);
         if ($result !== TRUE) {
             $this->setBuildError('variables', $result);
         }
     }
     if (!empty($roles)) {
         $cloudFoundryStack = array();
         $hasVpcRouter = false;
         $nginxFound = 0;
         foreach ($roles as $role) {
             $dbRole = DBRole::loadById($role['role_id']);
             if (!$dbRole->getImageId($role['platform'], $role['cloud_location'])) {
                 $this->setBuildError($dbRole->name, sprintf(_("Role '%s' is not available in %s on %s"), $dbRole->name, $role['platform'], $role['cloud_location']), $role['farm_role_id']);
             }
             if ($role['alias']) {
                 if (!preg_match("/^[A-Za-z0-9]+[A-Za-z0-9-]*[A-Za-z0-9]+\$/si", $role['alias'])) {
                     $this->setBuildError('alias', sprintf(_("Alias for role '%s' should start and end with letter or number and contain only letters, numbers and dashes."), $dbRole->name, $role['platform'], $role['cloud_location']), $role['farm_role_id']);
                 }
             }
             // Validate deployments
             $appId = $role[Scalr_Role_Behavior::ROLE_DM_APPLICATION_ID];
             if ($appId) {
                 $application = Scalr_Dm_Application::init()->loadById($appId);
                 $this->user->getPermissions()->validate($application);
                 if (!$role[Scalr_Role_Behavior::ROLE_DM_REMOTE_PATH]) {
                     $this->setBuildError(Scalr_Role_Behavior::ROLE_DM_REMOTE_PATH, sprintf("Remote path required for deployment on role '%s'", $dbRole->name), $role['farm_role_id']);
                 }
             }
             //-- CloudFoundryStuff
             if ($dbRole->hasBehavior(ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER)) {
                 $cloudFoundryStack[ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER] = true;
             }
             if ($dbRole->hasBehavior(ROLE_BEHAVIORS::CF_DEA)) {
                 $cloudFoundryStack[ROLE_BEHAVIORS::CF_DEA] = true;
             }
             if ($dbRole->hasBehavior(ROLE_BEHAVIORS::CF_HEALTH_MANAGER)) {
                 $cloudFoundryStack[ROLE_BEHAVIORS::CF_HEALTH_MANAGER] = true;
             }
             if ($dbRole->hasBehavior(ROLE_BEHAVIORS::CF_ROUTER)) {
                 $cloudFoundryStack[ROLE_BEHAVIORS::CF_ROUTER] = true;
             }
             if ($dbRole->hasBehavior(ROLE_BEHAVIORS::CF_SERVICE)) {
                 $cloudFoundryStack[ROLE_BEHAVIORS::CF_SERVICE] = true;
             }
             if ($dbRole->hasBehavior(ROLE_BEHAVIORS::VPC_ROUTER)) {
                 $hasVpcRouter = true;
             }
             if ($dbRole->hasBehavior(ROLE_BEHAVIORS::NGINX)) {
                 $nginxFound++;
             }
             //-- End CloudFoundry stuff
             if ($dbRole->hasBehavior(ROLE_BEHAVIORS::RABBITMQ)) {
                 $role['settings'][DBFarmRole::SETTING_SCALING_MAX_INSTANCES] = $role['settings'][DBFarmRole::SETTING_SCALING_MIN_INSTANCES];
                 $role['settings'][Scalr_Role_Behavior_RabbitMQ::ROLE_NODES_RATIO] = (int) $role['settings'][Scalr_Role_Behavior_RabbitMQ::ROLE_NODES_RATIO];
                 if ($role['settings'][Scalr_Role_Behavior_RabbitMQ::ROLE_NODES_RATIO] < 1 || $role['settings'][Scalr_Role_Behavior_RabbitMQ::ROLE_NODES_RATIO] > 100) {
                     $this->setBuildError(Scalr_Role_Behavior_RabbitMQ::ROLE_NODES_RATIO, sprintf("Nodes ratio for RabbitMq role '%s' should be between 1 and 100", $dbRole->name), $role['farm_role_id']);
                 }
             }
             if ($dbRole->hasBehavior(ROLE_BEHAVIORS::MONGODB)) {
                 if ($role['settings'][Scalr_Role_Behavior_MongoDB::ROLE_DATA_STORAGE_ENGINE] == 'ebs') {
                     if ($role['settings'][Scalr_Role_Behavior_MongoDB::ROLE_DATA_STORAGE_EBS_SIZE] < 10 || $role['settings'][Scalr_Role_Behavior_MongoDB::ROLE_DATA_STORAGE_EBS_SIZE] > 1000) {
                         $this->setBuildError(Scalr_Role_Behavior_MongoDB::ROLE_DATA_STORAGE_EBS_SIZE, sprintf("EBS size for mongoDB role should be between 10 and 1000 GB", $dbRole->name), $role['farm_role_id']);
                     }
                 }
             }
             /* Validate scaling */
             $minCount = (int) $role['settings'][DBFarmRole::SETTING_SCALING_MIN_INSTANCES];
             if (!$minCount && $minCount != 0) {
                 $minCount = 1;
             }
             if ($minCount < 0 || $minCount > 400) {
                 $this->setBuildError(DBFarmRole::SETTING_SCALING_MIN_INSTANCES, sprintf(_("Min instances for '%s' must be a number between 1 and 400"), $dbRole->name), $role['farm_role_id']);
             }
             $maxCount = (int) $role['settings'][DBFarmRole::SETTING_SCALING_MAX_INSTANCES];
             if (!$maxCount) {
                 $maxCount = 1;
             }
             if ($maxCount < 1 || $maxCount > 400) {
                 $this->setBuildError(DBFarmRole::SETTING_SCALING_MAX_INSTANCES, sprintf(_("Max instances for '%s' must be a number between 1 and 400"), $dbRole->name), $role['farm_role_id']);
             }
             if ($maxCount < $minCount) {
                 $this->setBuildError(DBFarmRole::SETTING_SCALING_MAX_INSTANCES, sprintf(_("Max instances should be greater or equal than Min instances for role '%s'"), $dbRole->name), $role['farm_role_id']);
             }
             if (isset($role['settings'][DBFarmRole::SETTING_SCALING_POLLING_INTERVAL]) && $role['settings'][DBFarmRole::SETTING_SCALING_POLLING_INTERVAL] > 0) {
                 $polling_interval = (int) $role['settings'][DBFarmRole::SETTING_SCALING_POLLING_INTERVAL];
             } else {
                 $polling_interval = 2;
             }
             if ($polling_interval < 1 || $polling_interval > 50) {
                 $this->setBuildError(DBFarmRole::SETTING_SCALING_POLLING_INTERVAL, sprintf(_("Polling interval for role '%s' must be a number between 1 and 50"), $dbRole->name), $role['farm_role_id']);
             }
             /** Validate platform specified settings **/
             switch ($role['platform']) {
                 case SERVER_PLATFORMS::EC2:
                     if ($dbRole->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
                         if ($role['settings'][DBFarmRole::SETTING_MYSQL_DATA_STORAGE_ENGINE] == MYSQL_STORAGE_ENGINE::EBS) {
                             if ($dbRole->generation != 2) {
                                 if ($role['settings'][DBFarmRole::SETTING_AWS_AVAIL_ZONE] == "" || $role['settings'][DBFarmRole::SETTING_AWS_AVAIL_ZONE] == "x-scalr-diff" || stristr($role['settings'][DBFarmRole::SETTING_AWS_AVAIL_ZONE], 'x-scalr-custom')) {
                                     $this->setBuildError(DBFarmRole::SETTING_AWS_AVAIL_ZONE, sprintf(_("Requirement for EBS MySQL data storage is specific 'Placement' parameter for role '%s'"), $dbRole->name), $role['farm_role_id']);
                                 }
                             }
                         }
                     }
                     if ($dbRole->getDbMsrBehavior()) {
                         if ($role['settings'][Scalr_Db_Msr::DATA_STORAGE_ENGINE] == MYSQL_STORAGE_ENGINE::EPH) {
                             if (!$role['settings'][Scalr_Db_Msr::DATA_STORAGE_EPH_DISK] && !$role['settings'][Scalr_Db_Msr::DATA_STORAGE_EPH_DISKS]) {
                                 $this->setBuildError(Scalr_Db_Msr::DATA_STORAGE_EPH_DISK, sprintf(_("Ephemeral disk settings is required for role '%s'"), $dbRole->name), $role['farm_role_id']);
                             }
                         }
                         if ($role['settings'][Scalr_Db_Msr::DATA_STORAGE_ENGINE] == MYSQL_STORAGE_ENGINE::LVM) {
                             if (!$role['settings'][Scalr_Role_DbMsrBehavior::ROLE_DATA_STORAGE_LVM_VOLUMES]) {
                                 $this->setBuildError(Scalr_Role_DbMsrBehavior::ROLE_DATA_STORAGE_LVM_VOLUMES, sprintf(_("Ephemeral disks settings is required for role '%s'"), $dbRole->name), $role['farm_role_id']);
                             }
                         }
                         if ($role['settings'][Scalr_Db_Msr::DATA_STORAGE_ENGINE] == MYSQL_STORAGE_ENGINE::RAID_EBS) {
                             if (!$this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_RAID)) {
                                 $this->setBuildError(Scalr_Db_Msr::DATA_STORAGE_ENGINE, 'RAID arrays are not available for your pricing plan. <a href="#/billing">Please upgrade your account to be able to use this feature.</a>', $role['farm_role_id']);
                             }
                         }
                         if ($role['settings'][Scalr_Db_Msr::DATA_STORAGE_FSTYPE] && $role['settings'][Scalr_Db_Msr::DATA_STORAGE_FSTYPE] != 'ext3') {
                             if (!$this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_MFS)) {
                                 $this->setBuildError(Scalr_Db_Msr::DATA_STORAGE_ENGINE, 'Only ext3 filesystem available for your pricing plan. <a href="#/billing">Please upgrade your account to be able to use other filesystems.</a>', $role['farm_role_id']);
                             }
                         }
                     }
                     if ($dbRole->hasBehavior(ROLE_BEHAVIORS::MONGODB)) {
                         if ($role['settings'][Scalr_Role_Behavior_MongoDB::ROLE_DATA_STORAGE_ENGINE] == MYSQL_STORAGE_ENGINE::RAID_EBS) {
                             if (!$this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_RAID)) {
                                 $this->setBuildError(Scalr_Role_Behavior_MongoDB::ROLE_DATA_STORAGE_ENGINE, 'RAID arrays are not available for your pricing plan. <a href="#/billing">Please upgrade your account to be able to use this feature.</a>', $role['farm_role_id']);
                             }
                         }
                     }
                     if ($role['settings'][DBFarmRole::SETTING_AWS_AVAIL_ZONE] == 'x-scalr-custom=') {
                         $this->setBuildError(DBFarmRole::SETTING_AWS_AVAIL_ZONE, sprintf(_("Availability zone for role \"%s\" should be selected"), $dbRole->name), $role['farm_role_id']);
                     }
                     break;
                 case SERVER_PLATFORMS::CLOUDSTACK:
                     if (!$role['settings'][DBFarmRole::SETTING_CLOUDSTACK_SERVICE_OFFERING_ID]) {
                         $this->setBuildError(DBFarmRole::SETTING_CLOUDSTACK_SERVICE_OFFERING_ID, sprintf(_("Service offering for '%s' cloudstack role should be selected on 'Cloudstack settings' tab"), $dbRole->name), $role['farm_role_id']);
                     }
                     break;
                 case SERVER_PLATFORMS::RACKSPACE:
                     if (!$role['settings'][DBFarmRole::SETTING_RS_FLAVOR_ID]) {
                         $this->setBuildError(DBFarmRole::SETTING_CLOUDSTACK_SERVICE_OFFERING_ID, sprintf(_("Flavor for '%s' rackspace role should be selected on 'Placement and type' tab"), $dbRole->name), $role['farm_role_id']);
                     }
                     break;
             }
             if ($role['settings'][DBFarmRole::SETTING_DNS_CREATE_RECORDS]) {
                 if ($role['settings'][DBFarmRole::SETTING_DNS_EXT_RECORD_ALIAS]) {
                     if (!preg_match("/^[A-Za-z0-9-%_]+\$/si", $role['settings'][DBFarmRole::SETTING_DNS_EXT_RECORD_ALIAS])) {
                         $this->setBuildError(DBFarmRole::SETTING_DNS_EXT_RECORD_ALIAS, "ext-%rolename% record alias for role '{$dbRole->name}' should contain only [A-Za-z0-9-] chars. First and last char should not by hypen.", $role['farm_role_id']);
                     }
                 }
                 if ($role['settings'][DBFarmRole::SETTING_DNS_INT_RECORD_ALIAS]) {
                     if (!preg_match("/^[A-Za-z0-9-%_]+\$/si", $role['settings'][DBFarmRole::SETTING_DNS_INT_RECORD_ALIAS])) {
                         $this->setBuildError(DBFarmRole::SETTING_DNS_INT_RECORD_ALIAS, "int-%rolename% record alias for role '{$dbRole->name}' should contain only [A-Za-z0-9-] chars. First and last char should not by hypen.", $role['farm_role_id']);
                     }
                 }
             }
             //DEPRECATED
             $rParams = $dbRole->getParameters();
             if (count($rParams) > 0 && strpos($role['farm_role_id'], 'virtual_') === false) {
                 if (empty($role['params'])) {
                     try {
                         $dbFarmRole = DBFarmRole::LoadByID($role['farm_role_id']);
                         foreach ($rParams as $param) {
                             $farmRoleOption = $this->db->GetRow("SELECT id, value FROM farm_role_options WHERE farm_roleid=? AND `hash`=? LIMIT 1", array($dbFarmRole->ID, $param['hash']));
                             if ($farmRoleOption['id']) {
                                 $value = $farmRoleOption['value'];
                             }
                             $role['params'][$param['hash']] = $value;
                         }
                     } catch (Exception $e) {
                     }
                 }
             }
             //Validate role parameters
             foreach ($rParams as $p) {
                 if ($p['required'] && $role['params'][$p['hash']] == "" && !$p['defval']) {
                     $this->setBuildError($p['name'], "Missed required parameter '{$p['name']}' for role '{$dbRole->name}'", $role['farm_role_id']);
                 }
             }
             // Validate Global variables
             if (!strstr($role['farm_role_id'], 'virtual_')) {
                 $farmRole = DBFarmRole::LoadByID($role['farm_role_id']);
             } else {
                 $farmRole = null;
             }
             $result = $farmRoleVariables->validateValues($role['variables'], $dbRole->id, $farmId, $farmRole ? $farmRole->ID : 0);
             if ($result !== TRUE) {
                 $this->setBuildError('variables', $result, $role['farm_role_id']);
             }
         }
     }
     try {
         if (!empty($cloudFoundryStack)) {
             if (!$cloudFoundryStack[ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER]) {
                 throw new Exception("CF CloudContoller role required for CloudFoundry stack. Please add All-in-one CF or separate CCHM role to farm");
             }
             if (!$cloudFoundryStack[ROLE_BEHAVIORS::CF_HEALTH_MANAGER]) {
                 throw new Exception("CF HealthManager role required for CloudFoundry stack. Please add All-in-one CF or separate CCHM role to farm");
             }
             if (!$cloudFoundryStack[ROLE_BEHAVIORS::CF_ROUTER]) {
                 throw new Exception("CF Router role required for CloudFoundry stack. Please add All-in-one CF or separate CF Router role to farm");
             }
             if (!$cloudFoundryStack[ROLE_BEHAVIORS::CF_DEA]) {
                 throw new Exception("CF DEA role required for CloudFoundry stack. Please add All-in-one CF or separate CF DEA role to farm");
             }
             if (!$nginxFound) {
                 throw new Exception("Nginx load balancer role required for CloudFoundry stack. Please add it to the farm");
             }
             if ($cloudFoundryStack[ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER] > 1) {
                 throw new Exception("CloudFoundry stack can work only with ONE CF CloudController role. Please leave only one CloudController role in farm");
             }
             if ($cloudFoundryStack[ROLE_BEHAVIORS::CF_HEALTH_MANAGER] > 1) {
                 throw new Exception("CloudFoundry stack can work only with ONE CF HealthManager role. Please leave only one HealthManager role in farm");
             }
             if ($nginxFound > 1) {
                 throw new Exception("CloudFoundry stack can work only with ONE nginx role. Please leave only one nginx role in farm");
             }
         }
     } catch (Exception $e) {
         $this->setBuildError('general', $e->getMessage(), null);
     }
     if ($farmSettings['vpc_id']) {
         $vpcRouterRequired = false;
         if (\Scalr::config('scalr.instances_connection_policy') != 'local' && !$hasVpcRouter) {
             foreach ($this->getParam('roles') as $role) {
                 if ($role['settings'][DBFarmRole::SETTING_AWS_VPC_INTERNET_ACCESS] == 'outbound-only') {
                     $vpcRouterRequired = true;
                     break;
                 }
             }
             if ($vpcRouterRequired) {
                 $this->setBuildError('general', "VPC Router role required for farm that running inside VPC with roles configured for outbound-only internet access", null);
             }
         }
     }
     return $this->errors['error_count'] == 0 ? true : false;
 }
All Usage Examples Of Scalr_Scripting_GlobalVariables::validateValues