/** * Get all resources registered on the server * @return array with fields: id, name, type, zone, class, loc, info, comment, ctime, mtime, vault_path, free_space. If user not found return empty array. */ public function getResources() { // set selected value $flds = array("COL_R_RESC_ID" => NULL, "COL_R_RESC_NAME" => NULL, "COL_R_ZONE_NAME" => NULL, "COL_R_TYPE_NAME" => NULL, "COL_R_CLASS_NAME" => NULL, "COL_R_LOC" => NULL, "COL_R_VAULT_PATH" => NULL, "COL_R_FREE_SPACE" => NULL, "COL_R_RESC_INFO" => NULL, "COL_R_RESC_COMMENT" => NULL, "COL_R_CREATE_TIME" => NULL, "COL_R_MODIFY_TIME" => NULL); $select = new RODSGenQueSelFlds(array_keys($flds), array_values($flds)); $condition = new RODSGenQueConds(); $conn = RODSConnManager::getConn($this->account); $results = $conn->query($select, $condition); RODSConnManager::releaseConn($conn); $result_vals = $results->getValues(); $retval = array(); for ($i = 0; $i < $results->getNumRow(); $i++) { $retval_row = array(); $retval_row['id'] = $result_vals["COL_R_RESC_ID"][$i]; $retval_row['name'] = $result_vals["COL_R_RESC_NAME"][$i]; $retval_row['type'] = $result_vals["COL_R_TYPE_NAME"][$i]; $retval_row['zone'] = $result_vals["COL_R_ZONE_NAME"][$i]; $retval_row['class'] = $result_vals["COL_R_CLASS_NAME"][$i]; $retval_row['loc'] = $result_vals["COL_R_LOC"][$i]; $retval_row['info'] = $result_vals["COL_R_RESC_INFO"][$i]; $retval_row['comment'] = $result_vals["COL_R_RESC_COMMENT"][$i]; $retval_row['ctime'] = $result_vals["COL_R_CREATE_TIME"][$i]; $retval_row['mtime'] = $result_vals["COL_R_MODIFY_TIME"][$i]; $retval_row['vault_path'] = $result_vals["COL_R_VAULT_PATH"][$i]; $retval_row['free_space'] = $result_vals["COL_R_FREE_SPACE"][$i]; $retval[] = $retval_row; } return $retval; }
/** * Excute the rule, assign * @return an associative array. Each array key is the lable, and each array value's type will depend on the type of $out_param, at this moment, only string and RODSKeyValPair are supported */ public function execute() { $conn = RODSConnManager::getConn($this->account); $result = $conn->execUserRule($this->rule_body, $this->inp_params, $this->out_params, $this->remotesvr, $this->options = null); RODSConnManager::releaseConn($conn); return $result; }
public static function getConn(RODSAccount $account) { $manager = $GLOBALS['RODSConnManager']; $conn = new RODSConn($account); $conn_sig = $conn->getSignature(); if (!isset($manager->conn_map[$conn_sig])) { $manager->conn_map[$conn_sig] = array(); } //check if there is any opened connection idle foreach ($manager->conn_map[$conn_sig] as &$opened_conn) { if ($opened_conn->isIdle()) { //$opened_conn->lock(); $account = $opened_conn->getAccount(); //update account if needed... return $opened_conn; } } //check if there is any more new connection allowed if (count($manager->conn_map[$conn_sig]) < MAX_NUM_CONN_PER_USER_SERVER) { $conn->connect(); $id = count($manager->conn_map[$conn_sig]); $manager->conn_map[$conn_sig][$id] = $conn; $conn->setId($id); //$conn->lock(); $account = $conn->getAccount(); //update account if needed... return $conn; } //because PHP doesn't support multithread, if we run out of connections, //there is probably something went wrong. throw new RODSException("Unexpectedly ran out of connections. Maybe some connections are not released??? ", "PERR_INTERNAL_ERR"); //if no connection are available, sleep for 100ms and retry usleep(100); echo "i am sleeping... <br/> \n"; return RODSConnManager::getConn($account); }
/** * rename() handler. * * @access private */ function rename($url_from, $url_to) { try { $file_from = ProdsDir::fromURI($url_from); $file_to = ProdsDir::fromURI($url_to); $conn = RODSConnManager::getConn($file_from->account); if (file_exists($url_to)) { unlink($url_to); } if (is_file($url_from)) { $conn->rename($file_from->path_str, $file_to->path_str, 0); } else { $conn->rename($file_from->path_str, $file_to->path_str, 1); } RODSConnManager::releaseConn($conn); return true; } catch (Exception $e) { trigger_error("Got an exception:{$e}", E_USER_WARNING); return false; } }
/** * query metadata, and find matching diretories. * @param array $terms an assositive array of search conditions, supported ones are: * - 'name' (string) - partial name of the target (file or dir) * - 'descendantOnly' (boolean) - whether to search among this directory's decendents. default is false. * - 'recursive' (boolean) - whether to search recursively, among all decendents and their children. default is false. This option only works when 'descendantOnly' is true * - 'smtime' (int) - start last-modified-time in unix timestamp. The specified time is included in query, in other words the search can be thought was "mtime >= specified time" * - 'emtime' (int) - end last-modified-time in unix timestamp. The specified time is not included in query, in other words the search can be thought was "mtime < specified time" * - 'owner' (string) - owner name of the dir * - 'metadata' (array of RODSMeta) - array of metadata. * @param int &$total_count This value (passed by reference) returns the total potential count of search results * @param int $start starting index of search results. * @param int $limit up to how many results to be returned. If negative, give all results back. * @param array $sort_flds associative array with following keys: * - 'name' - name of the dir * - 'mtime' - last modified time * - 'ctime' - creation time * - 'owner' - owner of the dir * The results are sorted by specified array keys. * The possible array value must be boolean: true stands for 'asc' and false stands for 'desc', default is 'asc' * @return array of ProdsPath objects (ProdsFile or ProdsDir). */ public function findDirs(array $terms, &$total_count, $start = 0, $limit = -1, array $sort_flds = array()) { $flds = array("COL_COLL_NAME" => NULL, "COL_COLL_ID" => NULL, "COL_COLL_OWNER_NAME" => NULL, 'COL_COLL_OWNER_ZONE' => NULL, "COL_COLL_CREATE_TIME" => NULL, "COL_COLL_MODIFY_TIME" => NULL, "COL_COLL_COMMENTS" => NULL); foreach ($sort_flds as $sort_fld_key => $sort_fld_val) { switch ($sort_fld_key) { case 'name': if ($sort_fld_val === false) { $flds['COL_COLL_NAME'] = 'order_by_desc'; } else { $flds['COL_COLL_NAME'] = 'order_by_asc'; } break; case 'mtime': if ($sort_fld_val === false) { $flds['COL_COLL_MODIFY_TIME'] = 'order_by_desc'; } else { $flds['COL_COLL_MODIFY_TIME'] = 'order_by_asc'; } break; case 'ctime': if ($sort_fld_val === false) { $flds['COL_COLL_CREATE_TIME'] = 'order_by_desc'; } else { $flds['COL_COLL_CREATE_TIME'] = 'order_by_asc'; } break; case 'owner': if ($sort_fld_val === false) { $flds['COL_COLL_OWNER_NAME'] = 'order_by_desc'; } else { $flds['COL_COLL_OWNER_NAME'] = 'order_by_asc'; } break; default: /* throw new RODSException("Sort field name '$sort_fld_key' is not valid", 'PERR_USER_INPUT_ERROR'); */ break; } } $select = new RODSGenQueSelFlds(array_keys($flds), array_values($flds)); $descendantOnly = false; $recursive = false; $condition = new RODSGenQueConds(); foreach ($terms as $term_key => $term_val) { switch ($term_key) { case 'name': //$condition->add('COL_COLL_NAME', 'like', '%'.$term_val.'%'); $condition->add('COL_COLL_NAME', 'like', $term_val); break; case 'smtime': $condition->add('COL_COLL_MODIFY_TIME', '>=', $term_val); break; case 'emtime': $condition->add('COL_COLL_MODIFY_TIME', '<', $term_val); break; case 'owner': $condition->add('COL_COLL_OWNER_NAME', '=', $term_val); break; case 'metadata': $meta_array = $term_val; foreach ($meta_array as $meta) { $condition->add('COL_META_COLL_ATTR_NAME', '=', $meta->name); if (isset($meta->op)) { $op = $meta->op; } else { $op = '='; } if ($op == 'like') { //$value='%'.$meta->value.'%'; $value = $meta->value; } else { $value = $meta->value; } $condition->add('COL_META_COLL_ATTR_VALUE', $op, $value); } break; case 'descendantOnly': if (true === $term_val) { $descendantOnly = true; } break; case 'recursive': if (true === $term_val) { $recursive = true; } break; default: throw new RODSException("Term field name '{$term_key}' is not valid", 'PERR_USER_INPUT_ERROR'); break; } } if ($descendantOnly === true) { // eliminate '/' from children, if current path is already root if ($this->path_str == '/') { $condition->add('COL_COLL_NAME', '<>', '/'); } if ($recursive === true) { $condition->add('COL_COLL_PARENT_NAME', 'like', $this->path_str . '/%', array(array('op' => '=', 'val' => $this->path_str))); } else { $condition->add('COL_COLL_PARENT_NAME', '=', $this->path_str); } } $conn = RODSConnManager::getConn($this->account); $results = $conn->query($select, $condition, $start, $limit); RODSConnManager::releaseConn($conn); $total_count = $results->getTotalCount(); $result_values = $results->getValues(); $found = array(); for ($i = 0; $i < $results->getNumRow(); $i++) { $full_path = $result_values['COL_COLL_NAME'][$i]; $acctual_name = basename($result_values['COL_COLL_NAME'][$i]); $stats = new RODSDirStats($acctual_name, $result_values['COL_COLL_OWNER_NAME'][$i], $result_values['COL_COLL_OWNER_ZONE'][$i], $result_values['COL_COLL_MODIFY_TIME'][$i], $result_values['COL_COLL_CREATE_TIME'][$i], $result_values['COL_COLL_ID'][$i], $result_values['COL_COLL_COMMENTS'][$i]); $found[] = new ProdsDir($this->account, $full_path, false, $stats); } return $found; }
public function deleteTicket($ticket) { $conn = RODSConnManager::getConn($this->account); $ticket = $conn->deleteTicket($ticket); RODSConnManager::releaseConn($conn); }
try { echo "--- trying to connect --- " . microtime() . " <br/>\n"; $conn = RODSConnManager::getConn($account); $que_result = $conn->dirExists($home_dir_str); if ($que_result === true) { echo "{$home_dir_str} exists! <br/>\n"; } else { echo "{$home_dir_str} doesn't exists! <br/>\n"; } $que_result = $conn->dirExists($home_dir_str . "/blah"); if ($que_result === true) { echo "{$home_dir_str}/blah exists! <br/>\n"; } else { echo "{$home_dir_str}/blah doesn't exists! <br/>\n"; } RODSConnManager::releaseConn($conn); $dir = new ProdsDir($account, "/tempZone/home/rods"); $childdirs = $dir->getChildDirs(); echo "Child dirs: <br/>\n"; foreach ($childdirs as $childdir) { echo $childdir . "<br/>\n"; } $childfiles = $dir->getChildFiles(); echo "Child files: <br/>\n"; foreach ($childfiles as $childfile) { echo $childfile . " <br/>\n"; /* $childfile->open("r"); echo "desc=".$childfile->getL1desc()."<br/>\n"; echo "<pre>".$childfile->read($childfile->stats->size)."</pre><br/>\n"; $cur_offset=$childfile->seek(3);
<?php require_once "../src/Prods.inc.php"; $account = new RODSAccount("localhost", 1247, "rods", "rods", "tempZone"); $home_dir_str = '/tempZone/home/rods'; try { echo "--- trying to connect --- " . microtime() . " <br/>\n"; $conn = RODSConnManager::getConn($account); echo "--- trying temp password #1 --- " . microtime() . " <br/>\n"; $key = $conn->connect(); $key = $conn->getKeyForTempPassword(); echo "key = {$key} <br/> \n"; $temppass = $conn->getTempPassword($key); echo "temppass = {$temppass} <br/> \n"; $account2 = clone $account; $account2->pass = $temppass; echo "--- trying to connect with temp password--- " . microtime() . " <br/>\n"; $conn2 = new RODSConn($account2); $conn2->connect(); echo "--- temp password #1 passed --- " . microtime() . " <br/>\n"; echo "--- trying temp password #2 --- " . microtime() . " <br/>\n"; $temppass = $account->getTempPassword(); echo "temppass#2 = {$temppass} <br/> \n"; $account2 = clone $account; $account2->pass = $temppass; echo "--- trying to connect with temp password #2 --- " . microtime() . " <br/>\n"; $conn2 = new RODSConn($account2); $conn2->connect(); echo "--- temp password #2 passed --- " . microtime() . " <br/>\n"; echo "--- test successful! --- " . microtime() . " <br/>\n"; } catch (RODSException $e) {
/** * Get ACL (users and their rights on a file) * @param string $filepath input file path string * @return RODSFileStats. If file does not exists, return fales. */ public function getACL() { $filepath = $this->path_str; $parent = dirname($filepath); $filename = basename($filepath); // $cond = array(new RODSQueryCondition("COL_COLL_NAME", $parent), // new RODSQueryCondition("COL_DATA_NAME", $filename)); $cond = array(new RODSQueryCondition("COL_DATA_NAME", $filename), new RODSQueryCondition("COL_COLL_NAME", $parent)); $connLocal = RODSConnManager::getConn($this->account); $que_result = $connLocal->genQuery(array("COL_USER_NAME", "COL_USER_ZONE", "COL_DATA_ACCESS_NAME"), $cond, array()); RODSConnManager::releaseConn($connLocal); if ($que_result === false) { return false; } for ($i = 0; $i < sizeof($que_result['COL_USER_NAME']); $i++) { $users[] = (object) array("COL_USER_NAME" => $que_result['COL_USER_NAME'][$i], "COL_USER_ZONE" => $que_result['COL_USER_ZONE'][$i], "COL_DATA_ACCESS_NAME" => $que_result['COL_DATA_ACCESS_NAME'][$i]); } return $users; }
public function __construct() { parent::__construct(); }