configure() public method

public configure ( $repo, $schedule )
Ejemplo n.º 1
0
 public function xSaveSzrUpdSettingsAction()
 {
     $dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
     $this->user->getPermissions()->validate($dbFarm);
     $schedule = implode(" ", array($this->getParam("hh"), $this->getParam("dd"), $this->getParam("dw")));
     $repo = $this->getParam("szrRepository");
     $dbFarm->SetSetting(DBFarm::SETTING_SZR_UPD_REPOSITORY, $repo);
     $dbFarm->SetSetting(DBFarm::SETTING_SZR_UPD_SCHEDULE, $schedule);
     $servers = $dbFarm->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
     foreach ($servers as $dbServer) {
         try {
             $port = $dbServer->GetProperty(SERVER_PROPERTIES::SZR_UPDC_PORT);
             if (!$port) {
                 $port = 8008;
             }
             $updClient = new Scalr_Net_Scalarizr_UpdateClient($dbServer, $port);
             $updClient->configure($repo, $schedule);
         } catch (Exception $e) {
             Logger::getLogger('Farm')->error(new FarmLogMessage($dbFarm->ID, sprintf("Unable to update scalarizr update settings on server %s: %s", $dbServer->serverId, $e->getMessage())));
             $err = true;
         }
     }
     if (!$err) {
         $this->response->success('Scalarizr auto-update settings successfully saved');
     } else {
         $this->response->warning('Scalarizr auto-update settings successfully saved, but some servers were not updated. Please check "Logs -> System log" for more details.');
     }
 }
Ejemplo n.º 2
0
 private function onHostInit($message, DBServer $dbserver)
 {
     if ($dbserver->status == SERVER_STATUS::PENDING) {
         // 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->platform != SERVER_PLATFORMS::CLOUDSTACK) {
             $srv_props[SERVER_PROPERTIES::SZR_SNMP_PORT] = $message->snmpPort;
             $remoteIp = $message->remoteIp;
         } else {
             if ($dbserver->farmRoleId) {
                 $dbFarmRole = $dbserver->GetFarmRoleObject();
                 $networkType = $dbFarmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE);
                 if ($networkType == 'Direct') {
                     $remoteIp = $message->localIp;
                     $srv_props[SERVER_PROPERTIES::SZR_SNMP_PORT] = $message->snmpPort;
                 } else {
                     $env = $dbserver->GetEnvironmentObject();
                     $remoteIp = $env->getPlatformConfigValue(Modules_Platforms_Cloudstack::SHARED_IP . "." . $dbserver->GetProperty(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION), false);
                 }
             } else {
                 $remoteIp = $message->localIp;
                 $srv_props[SERVER_PROPERTIES::SZR_SNMP_PORT] = $message->snmpPort;
             }
         }
         //Update auto-update settings
         //TODO: Check auto-update client version
         if ($dbserver->IsSupported('0.7.225')) {
             $dbserver->SetProperties($srv_props);
             try {
                 $repo = $dbserver->GetFarmObject()->GetSetting(DBFarm::SETTING_SZR_UPD_REPOSITORY);
                 $schedule = $dbserver->GetFarmObject()->GetSetting(DBFarm::SETTING_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(DbFarmRole::SETTING_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);
                 $srv_props[Scalr_Db_Msr::REPLICATION_MASTER] = 1;
             }
         }
         $dbserver->SetProperties($srv_props);
         return new HostInitEvent($dbserver, $message->localIp, $remoteIp, $message->sshPubKey);
     } else {
         $this->logger->error("Strange situation. Received HostInit message" . " from server '{$dbserver->serverId}' ({$message->remoteIp})" . " with state {$dbserver->status}!");
     }
 }
Ejemplo n.º 3
0
 private function onHostInit($message, DBServer $dbserver)
 {
     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;
         }
         $srv_props[SERVER_PROPERTIES::SZR_SNMP_PORT] = $message->snmpPort;
         if ($dbserver->isCloudstack()) {
             $ips = $platform->GetServerIPAddresses($dbserver);
             if ($ips['remoteIp']) {
                 $remoteIp = $ips['remoteIp'];
                 $dbserver->GetFarmRoleObject()->SetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE, 'Direct', DBFarmRole::TYPE_LCL);
             } else {
                 if ($dbserver->farmRoleId) {
                     $dbFarmRole = $dbserver->GetFarmRoleObject();
                     $networkType = $dbFarmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE);
                     if ($networkType == 'Direct') {
                         $remoteIp = $message->localIp;
                     } else {
                         $useStaticNat = $dbFarmRole->GetSetting(DBFarmRole::SETIING_CLOUDSTACK_USE_STATIC_NAT);
                         if (!$useStaticNat) {
                             $sharedIp = $dbFarmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_SHARED_IP_ADDRESS);
                             if (!$sharedIp) {
                                 $env = $dbserver->GetEnvironmentObject();
                                 $remoteIp = $platform->getConfigVariable(CloudstackPlatformModule::SHARED_IP . "." . $dbserver->GetProperty(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION), $env, false);
                             } else {
                                 $remoteIp = $sharedIp;
                             }
                         }
                     }
                 }
             }
         }
         if ($dbserver->isOpenstack()) {
             if ($dbserver->farmRoleId) {
                 $ipPool = $dbserver->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_OPENSTACK_IP_POOL);
                 if ($ipPool && empty($dbserver->remoteIp)) {
                     return false;
                 } else {
                     $remoteIp = $dbserver->remoteIp;
                 }
             }
         }
         if (!$remoteIp) {
             $ips = $platform->GetServerIPAddresses($dbserver);
             if ($ips['remoteIp']) {
                 $remoteIp = $ips['remoteIp'];
             } else {
                 $remoteIp = $message->remoteIp ? $ips['remoteIp'] : '';
             }
         }
         $dbserver->remoteIp = $remoteIp;
         $dbserver->Save();
         //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(DBFarm::SETTING_SZR_UPD_REPOSITORY);
                 }
                 $schedule = $dbserver->GetFarmObject()->GetSetting(DBFarm::SETTING_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(DBFarmRole::SETTING_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, DBFarmRole::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->logger->error("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
     }
 }