Scalr\System\Zmq\Cron\Task\ScalarizrMessaging::onHostInit PHP Метод

onHostInit() приватный Метод

private onHostInit ( $message, DBServer $dbserver )
$dbserver DBServer
    private function onHostInit($message, DBServer $dbserver)
    {
        $update = [];
        $remoteIp = null;
        if ($dbserver->status == SERVER_STATUS::PENDING) {
            $platform = PlatformFactory::NewPlatform($dbserver->platform);
            // Update server crypto key
            $srv_props = array();
            if ($message->cryptoKey) {
                $srv_props[SERVER_PROPERTIES::SZR_KEY] = trim($message->cryptoKey);
                $srv_props[SERVER_PROPERTIES::SZR_KEY_TYPE] = SZR_KEY_TYPE::PERMANENT;
            }
            if ($dbserver->isCloudstack()) {
                $remoteIp = CloudstackHelper::getSharedIP($dbserver);
            }
            if ($dbserver->isOpenstack()) {
                if ($dbserver->farmRoleId) {
                    $ipPool = $dbserver->GetFarmRoleObject()->GetSetting(Entity\FarmRoleSetting::OPENSTACK_IP_POOL);
                    if ($ipPool && empty($dbserver->remoteIp)) {
                        return false;
                    } else {
                        $remoteIp = $dbserver->remoteIp;
                    }
                }
                if (!$dbserver->cloudLocationZone) {
                    $info = $platform->GetServerExtendedInformation($dbserver);
                    if (!empty($info['Availability zone'])) {
                        $dbserver->cloudLocationZone = $update['cloudLocationZone'] = $info['Availability zone'];
                        $dbserver->SetProperty(\OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION_ZONE, $dbserver->cloudLocationZone);
                    }
                }
            }
            if (!$remoteIp) {
                $ips = $platform->GetServerIPAddresses($dbserver);
                if ($ips['remoteIp']) {
                    $remoteIp = $ips['remoteIp'];
                } else {
                    $remoteIp = $message->remoteIp ? $ips['remoteIp'] : '';
                }
            }
            $update['remoteIp'] = $remoteIp;
            $dbserver->update($update);
            //Update auto-update settings
            //TODO: Check auto-update client version
            if ($dbserver->IsSupported('0.7.225') && !$dbserver->IsSupported('2.7.10')) {
                $dbserver->SetProperties($srv_props);
                try {
                    $repo = $dbserver->GetFarmRoleObject()->GetSetting(Scalr_Role_Behavior::ROLE_BASE_SZR_UPD_REPOSITORY);
                    if (!$repo) {
                        $repo = $dbserver->GetFarmObject()->GetSetting(Entity\FarmSetting::SZR_UPD_REPOSITORY);
                    }
                    $schedule = $dbserver->GetFarmObject()->GetSetting(Entity\FarmSetting::SZR_UPD_SCHEDULE);
                    if ($repo && $schedule) {
                        $updateClient = new Scalr_Net_Scalarizr_UpdateClient($dbserver);
                        $updateClient->configure($repo, $schedule);
                    }
                } catch (Exception $e) {
                }
            }
            // MySQL specific
            $dbFarmRole = $dbserver->GetFarmRoleObject();
            if ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
                $master = $dbFarmRole->GetFarmObject()->GetMySQLInstances(true);
                // If no masters in role this server becomes it
                if (!$master[0] && !(int) $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_SLAVE_TO_MASTER)) {
                    $srv_props[SERVER_PROPERTIES::DB_MYSQL_MASTER] = 1;
                }
            }
            //MSR Replication Master
            //TODO: MySQL
            if ($dbFarmRole->GetRoleObject()->getDbMsrBehavior()) {
                $servers = $dbFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
                if (!$dbFarmRole->GetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER)) {
                    $masterFound = false;
                    foreach ($servers as $server) {
                        if ($server->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER)) {
                            $masterFound = true;
                        }
                    }
                    if (!$masterFound) {
                        $srv_props[Scalr_Db_Msr::REPLICATION_MASTER] = 1;
                    }
                } elseif ($dbFarmRole->GetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER) && count($servers) == 0) {
                    $dbFarmRole->SetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER, 0, Entity\FarmRoleSetting::TYPE_LCL);
                    $srv_props[Scalr_Db_Msr::REPLICATION_MASTER] = 1;
                }
            }
            $dbserver->SetProperties($srv_props);
            return new HostInitEvent($dbserver, $message->localIp, $remoteIp, $message->sshPubKey);
        } else {
            $this->getLogger()->debug("Strange situation. Received HostInit message" . " from server '{$dbserver->serverId}' ({$message->remoteIp})" . " with state {$dbserver->status}!");
            //TOOD: Check if instance terminating we probably can cancel termination and continue initialization
        }
    }