GetCategoryId() public static method

public static GetCategoryId ( $const )
示例#1
0
 public function Run()
 {
     global $db;
     $time = microtime(true);
     $db->Execute("ALTER TABLE  `roles` ADD  `cat_id` INT( 11 ) NULL AFTER  `env_id`");
     $db->Execute("CREATE TABLE IF NOT EXISTS `role_categories` (\n          `id` int(11) NOT NULL AUTO_INCREMENT,\n          `env_id` int(11) NOT NULL,\n          `name` varchar(30) NOT NULL,\n          PRIMARY KEY (`id`)\n         ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;\n        ");
     $db->Execute("INSERT INTO `role_categories` (`id`, `env_id`, `name`) VALUES\n            (1, 0, 'Base'),\n            (2, 0, 'Databases'),\n            (3, 0, 'Application Servers'),\n            (4, 0, 'Load Balancers'),\n            (5, 0, 'Message Queues'),\n            (6, 0, 'Caches'),\n            (7, 0, 'Cloudfoundry'),\n            (8, 0, 'Mixed');\n        ");
     $roles = $db->Execute("SELECT id, behaviors FROM roles");
     while ($role = $roles->FetchRow()) {
         $db->Execute("UPDATE roles SET cat_id = ? WHERE id = ?", array(ROLE_BEHAVIORS::GetCategoryId($role['behaviors']), $role['id']));
     }
     print "Done.\n";
     $t = round(microtime(true) - $time, 2);
     printf("Upgrade process took %0.2f seconds\n\n\n", $t);
 }
示例#2
0
 public static function createFromBundleTask(BundleTask $BundleTask)
 {
     $db = \Scalr::getDb();
     $DBServer = DBServer::LoadByID($BundleTask->serverId);
     if ($BundleTask->prototypeRoleId) {
         $proto_role = $db->GetRow("SELECT * FROM roles WHERE id=? LIMIT 1", array($BundleTask->prototypeRoleId));
         if (!$proto_role['architecture']) {
             $proto_role['architecture'] = $DBServer->GetProperty(SERVER_PROPERTIES::ARCHITECTURE);
         }
     } else {
         $behaviors = array_unique(explode(',', $DBServer->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR)));
         sort($behaviors);
         $proto_role = array("behaviors" => join(',', $behaviors), "architecture" => $DBServer->GetProperty(SERVER_PROPERTIES::ARCHITECTURE), "name" => "*import*");
     }
     if (!$proto_role['architecture']) {
         $proto_role['architecture'] = 'x86_64';
     }
     if (!$BundleTask->cloudLocation) {
         if ($DBServer) {
             $BundleTask->cloudLocation = $DBServer->GetCloudLocation();
         }
     }
     $osId = $BundleTask->osId;
     $meta = $BundleTask->getSnapshotDetails();
     if (!$osId) {
         if ($proto_role) {
             $osId = $proto_role['os_id'];
         } elseif ($meta['os'] && $meta['os']->version) {
             /*
                             if ($meta['os']->version == '2008Server') {
                                 $osInfo->name = 'Windows 2008 Server';
                                 $osInfo->family = 'windows';
                                 $osInfo->generation = '2008';
                                 $osInfo->version = '2008Server';
                             } elseif ($meta['os']->version == '2008ServerR2') {
                                 $osInfo->name = 'Windows 2008 Server R2';
                                 $osInfo->family = 'windows';
                                 $osInfo->generation = '2008';
                                 $osInfo->version = '2008ServerR2';
                             }*/
             //TODO:
         }
     }
     if ($proto_role['cat_id']) {
         $catId = $proto_role['cat_id'];
     } else {
         $catId = ROLE_BEHAVIORS::GetCategoryId($proto_role['behaviors']);
     }
     $db->Execute("INSERT INTO roles SET\n            name\t\t\t= ?,\n            origin\t\t\t= ?,\n            dtadded         = NOW(),\n            client_id\t\t= ?,\n            env_id\t\t\t= ?,\n            cat_id          = ?,\n            description\t\t= ?,\n            behaviors\t\t= ?,\n            generation\t\t= ?,\n            added_by_email  = ?,\n            added_by_userid = ?,\n            os_id\t\t\t= ?\n        ", array($BundleTask->roleName, ROLE_TYPE::CUSTOM, $BundleTask->clientId, $BundleTask->envId, $catId, $BundleTask->description, $proto_role['behaviors'], 2, $BundleTask->createdByEmail, $BundleTask->createdById, $osId));
     $role_id = $db->Insert_Id();
     $BundleTask->roleId = $role_id;
     $BundleTask->Save();
     $BundleTask->Log(sprintf("Created new role. Role name: %s. Role ID: %s", $BundleTask->roleName, $BundleTask->roleId));
     $role = self::loadById($role_id);
     $behaviors = explode(",", $proto_role['behaviors']);
     foreach ($behaviors as $behavior) {
         $db->Execute("INSERT IGNORE INTO role_behaviors SET\n                role_id\t\t\t= ?,\n                behavior\t\t= ?\n            ", array($role_id, $behavior));
     }
     // Set image
     $role->__getNewRoleObject()->setImage($BundleTask->platform, $BundleTask->cloudLocation, $BundleTask->snapshotId, $BundleTask->createdById, $BundleTask->createdByEmail);
     // Set params
     if ($proto_role['id']) {
         $dbSecRules = $db->GetAll("SELECT * FROM role_security_rules WHERE role_id = ?", array($proto_role['id']));
         foreach ($dbSecRules as $dbSecRule) {
             $db->Execute("INSERT INTO role_security_rules SET role_id = ?, rule = ?", array($role_id, $dbSecRule['rule']));
         }
         $props = $db->GetAll("SELECT * FROM role_properties WHERE role_id=?", array($proto_role['id']));
         foreach ($props as $prop) {
             $role->setProperty($prop['name'], $prop['value']);
         }
         $scripts = $db->GetAll("SELECT * FROM role_scripts WHERE role_id=?", array($proto_role['id']));
         foreach ($scripts as &$script) {
             $script['params'] = unserialize($script['params']);
         }
         $role->setScripts($scripts);
         $variables = new Scalr_Scripting_GlobalVariables($BundleTask->clientId, $proto_role['env_id'], ScopeInterface::SCOPE_ROLE);
         $variables->setValues($variables->getValues($proto_role['id']), $role->id);
     }
     $role->syncAnalyticsTags();
     return $role;
 }
示例#3
0
 public static function createFromBundleTask(BundleTask $BundleTask)
 {
     $db = \Scalr::getDb();
     $DBServer = DBServer::LoadByID($BundleTask->serverId);
     if ($BundleTask->prototypeRoleId) {
         $proto_role = $db->GetRow("SELECT * FROM roles WHERE id=? LIMIT 1", array($BundleTask->prototypeRoleId));
         if (!$proto_role['architecture']) {
             $proto_role['architecture'] = $DBServer->GetProperty(SERVER_PROPERTIES::ARCHITECTURE);
         }
     } else {
         $proto_role = array("behaviors" => $DBServer->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR), "architecture" => $DBServer->GetProperty(SERVER_PROPERTIES::ARCHITECTURE), "name" => "*import*");
     }
     if (!$proto_role['architecture']) {
         $proto_role['architecture'] = 'x86_64';
     }
     if (!$BundleTask->cloudLocation) {
         if ($DBServer) {
             $BundleTask->cloudLocation = $DBServer->GetCloudLocation();
         }
     }
     $osInfo = $BundleTask->getOsDetails();
     $meta = $BundleTask->getSnapshotDetails();
     if (!$osInfo->family || !$osInfo->generation) {
         $osInfo = new stdClass();
         if ($proto_role) {
             $osInfo->name = $proto_role['os'];
             $osInfo->family = $proto_role['os_family'];
             $osInfo->generation = $proto_role['os_generation'];
             $osInfo->version = $proto_role['os_version'];
         } elseif ($meta['os'] && $meta['os']->version) {
             if ($meta['os']->version == '2008Server') {
                 $osInfo->name = 'Windows 2008 Server';
                 $osInfo->family = 'windows';
                 $osInfo->generation = '2008';
                 $osInfo->version = '2008Server';
             } elseif ($meta['os']->version == '2008ServerR2') {
                 $osInfo->name = 'Windows 2008 Server R2';
                 $osInfo->family = 'windows';
                 $osInfo->generation = '2008';
                 $osInfo->version = '2008ServerR2';
             }
         }
     }
     if ($proto_role['cat_id']) {
         $catId = $proto_role['cat_id'];
     } else {
         $catId = ROLE_BEHAVIORS::GetCategoryId($proto_role['behaviors']);
     }
     $db->Execute("INSERT INTO roles SET\n            name\t\t\t= ?,\n            origin\t\t\t= ?,\n            dtadded         = NOW(),\n            client_id\t\t= ?,\n            env_id\t\t\t= ?,\n            cat_id          = ?,\n            description\t\t= ?,\n            behaviors\t\t= ?,\n            history\t\t\t= ?,\n            generation\t\t= ?,\n            added_by_email  = ?,\n            added_by_userid = ?,\n            os\t\t\t\t= ?,\n            os_family       = ?,\n            os_version      = ?,\n            os_generation   = ?\n        ", array($BundleTask->roleName, ROLE_TYPE::CUSTOM, $BundleTask->clientId, $BundleTask->envId, $catId, $BundleTask->description, $proto_role['behaviors'], trim("{$proto_role['history']},{$proto_role['name']}", ","), 2, $BundleTask->createdByEmail, $BundleTask->createdById, $osInfo->name, $osInfo->family, $osInfo->version, $osInfo->generation));
     $role_id = $db->Insert_Id();
     $BundleTask->roleId = $role_id;
     $BundleTask->Save();
     $BundleTask->Log(sprintf("Created new role. Role name: %s. Role ID: %s", $BundleTask->roleName, $BundleTask->roleId));
     $role = self::loadById($role_id);
     $behaviors = explode(",", $proto_role['behaviors']);
     foreach ($behaviors as $behavior) {
         $db->Execute("INSERT INTO role_behaviors SET\n                role_id\t\t\t= ?,\n                behavior\t\t= ?\n            ", array($role_id, $behavior));
     }
     // Set image
     $role->setImage($BundleTask->snapshotId, $BundleTask->platform, $BundleTask->platform != SERVER_PLATFORMS::GCE ? $BundleTask->cloudLocation : "", $meta['szr_version'], $proto_role['architecture']);
     // Set params
     if ($proto_role['id']) {
         $dbParams = $db->GetAll("SELECT name,type,isrequired,defval,allow_multiple_choice,options,hash,issystem\n                FROM role_parameters WHERE role_id = ?", array($proto_role['id']));
         $role->setParameters($dbParams);
         $dbSecRules = $db->GetAll("SELECT * FROM role_security_rules WHERE role_id = ?", array($proto_role['id']));
         foreach ($dbSecRules as $dbSecRule) {
             $db->Execute("INSERT INTO role_security_rules SET role_id = ?, rule = ?", array($role_id, $dbSecRule['rule']));
         }
         $props = $db->GetAll("SELECT * FROM role_properties WHERE role_id=?", array($proto_role['id']));
         foreach ($props as $prop) {
             $role->setProperty($prop['name'], $prop['value']);
         }
         $scripts = $db->GetAll("SELECT * FROM role_scripts WHERE role_id=?", array($proto_role['id']));
         foreach ($scripts as &$script) {
             $script['params'] = unserialize($script['params']);
         }
         $role->setScripts($scripts);
         $variables = new Scalr_Scripting_GlobalVariables($proto_role['env_id'], Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
         $variables->setValues($variables->getValues($proto_role['id']), $role->id);
     }
     // Set software
     if ($meta) {
         $software = array();
         foreach ((array) $meta['software'] as $soft) {
             $software[$soft->name] = $soft->version;
         }
         $role->setSoftware($software);
         $role->setTags((array) $meta['tags']);
         if ($BundleTask->platform == SERVER_PLATFORMS::NIMBULA) {
             $props = array(array('name' => self::PROPERTY_NIMBULA_INIT_ROOT_USER, 'value' => $meta['init_root_user']), array('name' => self::PROPERTY_NIMBULA_INIT_ROOT_PASS, 'value' => $meta['init_root_pass']), array('name' => self::PROPERTY_NIMBULA_ENTRY, 'value' => ''));
             foreach ($props as $prop) {
                 $role->setProperty($prop['name'], $prop['value']);
             }
         }
     }
     return $role;
 }