コード例 #1
0
ファイル: Tasks.php プロジェクト: mheydt/scalr
 public function xListTasksAction()
 {
     $this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'dtadded', 'direction' => 'DESC'))));
     $sql = "\n            SELECT\n                dt.id, dma.name AS application_name, servers.index AS server_index, farms.name AS farm_name, roles.name AS role_name,\n                dt.status AS status, dt.dtadded AS dtadded\n            FROM dm_deployment_tasks dt\n            LEFT JOIN dm_applications dma ON dt.dm_application_id = dma.id\n            LEFT JOIN servers ON servers.id = dt.server_id\n            LEFT JOIN farms ON servers.farm_id = farms.id\n            LEFT JOIN roles ON servers.farm_roleid = roles.id\n            WHERE dt.`status` != ? AND dt.env_id = ?\n        ";
     $args = array(Scalr_Dm_DeploymentTask::STATUS_ARCHIVED, $this->getEnvironmentId());
     list($sql, $args) = $this->request->prepareFarmSqlQuery($sql, $args, 'farms');
     $response = $this->buildResponseFromSql2($sql, array('id', 'application_name', 'farm_name', 'role_name', 'server_index', 'status', 'dtadded', 'dtdeployed'), array(), $args);
     foreach ($response["data"] as $k => $row) {
         $data = false;
         try {
             $deploymentTask = Scalr_Dm_DeploymentTask::init()->loadById($row['id']);
             $application = $deploymentTask->getApplication();
             try {
                 $dbServer = DBServer::LoadByID($deploymentTask->serverId);
                 $serverIndex = $dbServer->index;
             } catch (Exception $e) {
             }
             $data = array('id' => $deploymentTask->id, 'application_name' => $application->name, 'application_id' => $deploymentTask->applicationId, 'server_id' => $deploymentTask->serverId, 'server_index' => $serverIndex, 'remote_path' => $deploymentTask->remotePath, 'status' => $deploymentTask->status, 'dtadded' => $deploymentTask->dtAdded ? Scalr_Util_DateTime::convertTz($deploymentTask->dtAdded) : "", 'dtdeployed' => $deploymentTask->dtDeployed ? Scalr_Util_DateTime::convertTz($deploymentTask->dtDeployed) : "Never");
             try {
                 $dbFarmRole = DBFarmRole::LoadByID($deploymentTask->farmRoleId);
                 $data['farm_roleid'] = $dbFarmRole->ID;
                 $data['role_name'] = $dbFarmRole->GetRoleObject()->name;
                 $data['farm_id'] = $dbFarmRole->FarmID;
                 $data['farm_name'] = $dbFarmRole->GetFarmObject()->Name;
             } catch (Exception $e) {
             }
         } catch (Exception $e) {
         }
         $response["data"][$k] = $data;
     }
     $this->response->data($response);
 }
コード例 #2
0
ファイル: Tasks.php プロジェクト: rakesh-mohanta/scalr
 public function xListTasksAction()
 {
     $this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'dtadded', 'direction' => 'DESC'))));
     $sql = "SELECT id FROM dm_deployment_tasks WHERE status !='" . Scalr_Dm_DeploymentTask::STATUS_ARCHIVED . "' AND env_id = '{$this->getEnvironmentId()}'";
     $response = $this->buildResponseFromSql($sql, array("id"));
     foreach ($response["data"] as $k => $row) {
         $data = false;
         try {
             $deploymentTask = Scalr_Dm_DeploymentTask::init()->loadById($row['id']);
             $application = $deploymentTask->getApplication();
             try {
                 $dbServer = DBServer::LoadByID($deploymentTask->serverId);
                 $serverIndex = $dbServer->index;
             } catch (Exception $e) {
             }
             $data = array('id' => $deploymentTask->id, 'application_name' => $application->name, 'application_id' => $deploymentTask->applicationId, 'server_id' => $deploymentTask->serverId, 'server_index' => $serverIndex, 'remote_path' => $deploymentTask->remotePath, 'status' => $deploymentTask->status, 'dtadded' => $deploymentTask->dtAdded ? Scalr_Util_DateTime::convertTz($deploymentTask->dtAdded) : "", 'dtdeployed' => $deploymentTask->dtDeployed ? Scalr_Util_DateTime::convertTz($deploymentTask->dtDeployed) : "Never");
             try {
                 $dbFarmRole = DBFarmRole::LoadByID($deploymentTask->farmRoleId);
                 $data['farm_roleid'] = $dbFarmRole->ID;
                 $data['role_name'] = $dbFarmRole->GetRoleObject()->name;
                 $data['farm_id'] = $dbFarmRole->FarmID;
                 $data['farm_name'] = $dbFarmRole->GetFarmObject()->Name;
             } catch (Exception $e) {
             }
         } catch (Exception $e) {
         }
         $response["data"][$k] = $data;
     }
     $this->response->data($response);
 }
コード例 #3
0
ファイル: Applications.php プロジェクト: mheydt/scalr
 public function xDeployAction()
 {
     $this->request->defineParams(array('applicationId' => array('type' => 'int'), 'farmId' => array('type' => 'int'), 'farmRoleId' => array('type' => 'int'), 'remotePath'));
     $application = Scalr_Dm_Application::init()->loadById($this->getParam('applicationId'));
     $this->user->getPermissions()->validate($application);
     $dbFarmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
     $this->user->getPermissions()->validate($dbFarmRole);
     $servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
     if (!$this->getParam('remotePath')) {
         throw new Exception("Remote path reuired for deployment");
     }
     if (count($servers) == 0) {
         throw new Exception("There is no running servers on selected farm/role");
     }
     foreach ($servers as $dbServer) {
         $deploymentTask = Scalr_Dm_DeploymentTask::init();
         $deploymentTask->create($this->getParam('farmRoleId'), $this->getParam('applicationId'), $dbServer->serverId, Scalr_Dm_DeploymentTask::TYPE_MANUAL, $this->getParam('remotePath'));
     }
     $this->response->success('Deployment task created');
 }
コード例 #4
0
 public function DmApplicationDeploy($ApplicationID, $FarmRoleID, $RemotePath)
 {
     $this->restrictAccess(Acl::RESOURCE_DEPLOYMENTS_APPLICATIONS);
     $application = Scalr_Model::init(Scalr_Model::DM_APPLICATION)->loadById($ApplicationID);
     if ($application->envId != $this->Environment->id) {
         throw new Exception("Aplication not found in database");
     }
     $dbFarmRole = DBFarmRole::LoadByID($FarmRoleID);
     if ($dbFarmRole->GetFarmObject()->EnvID != $this->Environment->id) {
         throw new Exception("Farm Role not found in database");
     }
     $this->user->getPermissions()->validate($dbFarmRole);
     $servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
     if (count($servers) == 0) {
         throw new Exception("There is no running servers on selected farm/role");
     }
     $response = $this->CreateInitialResponse();
     $response->DeploymentTasksSet = new stdClass();
     $response->DeploymentTasksSet->Item = array();
     foreach ($servers as $dbServer) {
         $taskId = Scalr_Dm_DeploymentTask::getId($ApplicationID, $dbServer->serverId, $RemotePath);
         $deploymentTask = Scalr_Model::init(Scalr_Model::DM_DEPLOYMENT_TASK);
         if (!$taskId) {
             try {
                 if (!$dbServer->IsSupported("0.7.38")) {
                     throw new Exception("Scalr agent installed on this server doesn't support deployments. Please update it to the latest version");
                 }
                 $deploymentTask->create($FarmRoleID, $ApplicationID, $dbServer->serverId, Scalr_Dm_DeploymentTask::TYPE_API, $RemotePath, $this->Environment->id);
             } catch (Exception $e) {
                 $itm = new stdClass();
                 $itm->ServerID = $dbServer->serverId;
                 $itm->ErrorMessage = $e->getMessage();
                 $response->DeploymentTasksSet->Item[] = $itm;
                 continue;
             }
         } else {
             $deploymentTask->loadById($taskId);
             $deploymentTask->status = Scalr_Dm_DeploymentTask::STATUS_PENDING;
             $deploymentTask->log("Re-deploying application. Status: pending");
             $deploymentTask->save();
         }
         $itm = new stdClass();
         $itm->ServerID = $dbServer->serverId;
         $itm->DeploymentTaskID = $deploymentTask->id;
         $itm->FarmRoleID = $deploymentTask->farmRoleId;
         $itm->RemotePath = $deploymentTask->remotePath;
         $itm->Status = $deploymentTask->status;
         $response->DeploymentTasksSet->Item[] = $itm;
     }
     return $response;
 }
コード例 #5
0
ファイル: Behavior.php プロジェクト: sacredwebsite/scalr
 public function extendMessage(Scalr_Messaging_Msg $message, DBServer $dbServer)
 {
     if (in_array(ROLE_BEHAVIORS::BASE, $message->handlers)) {
         return $message;
     }
     if ($dbServer->farmRoleId) {
         $dbFarmRole = DBFarmRole::LoadByID($dbServer->farmRoleId);
     }
     switch (get_class($message)) {
         case "Scalr_Messaging_Msg_BeforeHostTerminate":
             //Storage
             try {
                 if ($dbFarmRole) {
                     $storage = new FarmRoleStorage($dbFarmRole);
                     $volumes = $storage->getVolumesConfigs($dbServer, false);
                     if (!empty($volumes)) {
                         $message->volumes = $volumes;
                     }
                 }
             } catch (Exception $e) {
                 $this->logger->error(new FarmLogMessage($dbServer->farmId, "Cannot init storage: {$e->getMessage()}"));
             }
             break;
         case "Scalr_Messaging_Msg_HostInit":
             $configuration = $this->getBaseConfiguration($dbServer, true, true);
             $message->base = $configuration->base;
             break;
         case "Scalr_Messaging_Msg_HostInitResponse":
             //Deployments
             try {
                 if ($dbFarmRole) {
                     $appId = $dbFarmRole->GetSetting(self::ROLE_DM_APPLICATION_ID);
                     if ($appId) {
                         $application = Scalr_Dm_Application::init()->loadById($appId);
                         $deploymentTask = Scalr_Dm_DeploymentTask::init();
                         $deploymentTask->create($dbServer->farmRoleId, $appId, $dbServer->serverId, Scalr_Dm_DeploymentTask::TYPE_AUTO, $dbFarmRole->GetSetting(self::ROLE_DM_REMOTE_PATH), $dbServer->envId, Scalr_Dm_DeploymentTask::STATUS_DEPLOYING);
                         $message->deploy = $deploymentTask->getDeployMessageProperties();
                     }
                 }
             } catch (Exception $e) {
                 $this->logger->error(new FarmLogMessage($dbServer->farmId, "Cannot init deployment: {$e->getMessage()}"));
             }
             $configuration = $this->getBaseConfiguration($dbServer, true);
             if ($configuration->volumes) {
                 $message->volumes = $configuration->volumes;
             }
             $message->base = $configuration->base;
             break;
     }
     $message->handlers[] = ROLE_BEHAVIORS::BASE;
     return $message;
 }
コード例 #6
0
ファイル: Behavior.php プロジェクト: recipe/scalr
 public function extendMessage(Scalr_Messaging_Msg $message, DBServer $dbServer)
 {
     if (in_array(ROLE_BEHAVIORS::BASE, $message->handlers)) {
         return $message;
     }
     if ($dbServer->farmRoleId) {
         $dbFarmRole = DBFarmRole::LoadByID($dbServer->farmRoleId);
     }
     switch (get_class($message)) {
         case "Scalr_Messaging_Msg_BeforeHostTerminate":
             //Storage
             try {
                 if ($dbFarmRole) {
                     $storage = new FarmRoleStorage($dbFarmRole);
                     $volumes = $storage->getVolumesConfigs($dbServer->index);
                     if (!empty($volumes)) {
                         $message->volumes = $volumes;
                     }
                 }
             } catch (Exception $e) {
                 $this->logger->error(new FarmLogMessage($dbServer->farmId, "Cannot init storage: {$e->getMessage()}"));
             }
             break;
         case "Scalr_Messaging_Msg_HostInitResponse":
             //Deployments
             try {
                 if ($dbFarmRole) {
                     $appId = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_DM_APPLICATION_ID);
                     if (!$message->deploy && $appId) {
                         $application = Scalr_Dm_Application::init()->loadById($appId);
                         $deploymentTask = Scalr_Dm_DeploymentTask::init();
                         $deploymentTask->create($dbServer->farmRoleId, $appId, $dbServer->serverId, Scalr_Dm_DeploymentTask::TYPE_AUTO, $dbFarmRole->GetSetting(self::ROLE_DM_REMOTE_PATH), $dbServer->envId, Scalr_Dm_DeploymentTask::STATUS_DEPLOYING);
                         $message->deploy = $deploymentTask->getDeployMessageProperties();
                     }
                 }
             } catch (Exception $e) {
                 $this->logger->error(new FarmLogMessage($dbServer->farmId, "Cannot init deployment: {$e->getMessage()}"));
             }
             //Storage
             try {
                 if ($dbFarmRole) {
                     $storage = new FarmRoleStorage($dbFarmRole);
                     $volumes = $storage->getVolumesConfigs($dbServer->index);
                     if (!empty($volumes)) {
                         $message->volumes = $volumes;
                     }
                 }
             } catch (Exception $e) {
                 $this->logger->error(new FarmLogMessage($dbServer->farmId, "Cannot init storage: {$e->getMessage()}"));
             }
             // Base
             try {
                 if ($dbFarmRole) {
                     $scriptingLogTimeout = $dbFarmRole->GetSetting(self::ROLE_BASE_KEEP_SCRIPTING_LOGS_TIME);
                     if (!$scriptingLogTimeout) {
                         $scriptingLogTimeout = 3600;
                     }
                     $message->base = new stdClass();
                     $message->base->keepScriptingLogsTime = $scriptingLogTimeout;
                     $hostNameFormat = $dbFarmRole->GetSetting(self::ROLE_BASE_HOSTNAME_FORMAT);
                     $message->base->hostname = !empty($hostNameFormat) ? $dbServer->applyGlobalVarsToValue($hostNameFormat) : '';
                 }
                 //keep_scripting_logs_time
             } catch (Exception $e) {
             }
             break;
     }
     $message->handlers[] = ROLE_BEHAVIORS::BASE;
     return $message;
 }
コード例 #7
0
ファイル: Behavior.php プロジェクト: rakesh-mohanta/scalr
 public function extendMessage(Scalr_Messaging_Msg $message, DBServer $dbServer)
 {
     switch (get_class($message)) {
         case "Scalr_Messaging_Msg_HostInitResponse":
             try {
                 if ($dbServer->farmRoleId) {
                     $appId = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_DM_APPLICATION_ID);
                     if (!$message->deploy && $appId) {
                         $application = Scalr_Dm_Application::init()->loadById($appId);
                         $deploymentTask = Scalr_Dm_DeploymentTask::init();
                         $deploymentTask->create($dbServer->farmRoleId, $appId, $dbServer->serverId, Scalr_Dm_DeploymentTask::TYPE_AUTO, $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_DM_REMOTE_PATH), $dbServer->envId, Scalr_Dm_DeploymentTask::STATUS_DEPLOYING);
                         $msg = $deploymentTask->getDeployMessage();
                         $message->deploy = $msg;
                     }
                 }
             } catch (Exception $e) {
                 $this->logger->error(new FarmLogMessage($dbServer->farmId, "Cannot init deployment: {$e->getMessage()}"));
             }
             break;
     }
     return $message;
 }