Scalr\Server\Import\Platforms\Ec2ServerImport::validate PHP Method

validate() protected method

See also: AbstractServerImport::validate
protected 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))));
        }
    }