Scalr\Server\Import\AbstractServerImport::validate PHP Method

validate() protected method

Check if instances are valid
protected validate ( )
    protected function validate()
    {
        $farm = $this->farmRole->getFarm();
        if ($farm->status != Entity\Farm::STATUS_RUNNING) {
            throw new ValidationErrorException('Farm should be in the Running state to import the Instance.');
        }
        $role = $this->farmRole->getRole();
        if ($role->isScalarized) {
            throw new ValidationErrorException('Only non-scalarized Roles are supported.');
        }
        if ($this->farmRole->getImage()->id != $this->orphaned->imageId) {
            throw new ValidationErrorException('ID of the FarmRole Image must match ID of the Image of the Instance.');
        }
        if ($this->farmRole->settings[Entity\FarmRoleSetting::SCALING_ENABLED] == 1) {
            throw new ValidationErrorException('Scaling should be set to manual before importing instance');
        }
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  * @see AbstractServerImport::validate
  */
 protected function validate()
 {
     parent::validate();
     if ($this->orphaned->status != DataType\InstanceStateData::NAME_RUNNING) {
         throw new ValidationErrorException("Instance must be in the Running state.");
     }
     if (isset($this->tags[Scalr_Governance::SCALR_META_TAG_NAME])) {
         throw new ValidationErrorException(sprintf("It is not permitted to set %s tag. Scalr itself sets this tag.", Scalr_Governance::SCALR_META_TAG_NAME));
     }
     $tags = [Scalr_Governance::SCALR_META_TAG_NAME => Scalr_Governance::SCALR_META_TAG_NAME];
     $tags = array_merge($tags, $this->tags);
     foreach ($this->orphaned->tags as $t) {
         $tags[$t['key']] = $t['value'];
     }
     if (count($tags) > Ec2PlatformModule::MAX_TAGS_COUNT) {
         throw new ValidationErrorException(sprintf("Not enough capacity to add tags to the Instance. %d tags are allowed.", Ec2PlatformModule::MAX_TAGS_COUNT));
     }
     if ($this->farmRole->getFarm()->settings[Entity\FarmSetting::EC2_VPC_ID] != $this->orphaned->vpcId) {
         throw new ValidationErrorException(sprintf("Instance and Farm must correspond to the same VPC, but they differ: Farm: %s, Instance: %s.", $this->farmRole->getFarm()->settings[Entity\FarmSetting::EC2_VPC_ID], $this->orphaned->vpcId));
     }
     if ($this->orphaned->subnetId && !in_array($this->orphaned->subnetId, json_decode($this->farmRole->settings[Entity\FarmRoleSetting::AWS_VPC_SUBNET_ID]))) {
         throw new ValidationErrorException(sprintf("Instance subnet '%s' must be enabled in FarmRole. Enabled subnets: %s.", $this->orphaned->subnetId, join(", ", json_decode($this->farmRole->settings[Entity\FarmRoleSetting::AWS_VPC_SUBNET_ID], true))));
     }
 }