Ejemplo n.º 1
0
 function __construct()
 {
     //$host, $user, $password, $name, $port, $table_name=null)
     $this->dataBase = new Database(Conf::get('pkg_db_host'), Conf::get('pkg_db_port'), Conf::get('pkg_db_user'), Conf::get('pkg_db_password'), Conf::get('pkg_db_name'), Conf::get('pkg_db_device_table'));
     $this->table = Conf::get('pkg_db_device_table');
     $this->privateKey = Conf::get('private_key');
     $this->aes256Key = hash("SHA256", $this->privateKey, true);
 }
Ejemplo n.º 2
0
Archivo: User.php Proyecto: rgwybb/tars
 public function __construct()
 {
     //$host, $user, $password, $name, $port, $table_name=null)
     $this->dataBase = new Database(Conf::get('pkg_db_host'), Conf::get('pkg_db_port'), Conf::get('pkg_db_user'), Conf::get('pkg_db_password'), Conf::get('pkg_db_name'), Conf::get('pkg_db_info_table'));
     if (isset($_SERVER['HTTP_TARS_TOKEN'])) {
         $this->token = $_SERVER['HTTP_TARS_TOKEN'];
     } else {
         $this->token = null;
     }
 }
Ejemplo n.º 3
0
 public function __construct()
 {
     $svnUser = Conf::get('svn_user');
     $svnPassword = Conf::get('svn_password');
     $this->repo = Conf::get('svn_repo');
     $this->svnCmd = "/usr/bin/svn --username={$svnUser} --password={$svnPassword} --non-interactive ";
     $this->svnCopy = Conf::get('package_home');
     $this->pkgTmpPath = Conf::get('package_path_export');
     $this->updTmpPath = Conf::get('package_path_update');
     $this->tmpPath = Conf::get('svn_tmp');
     $this->pkgFramework = Conf::get('package_framework');
 }
Ejemplo n.º 4
0
 public function __construct($execName, $path = null, $header = "result", $delimiter = "%%")
 {
     if ($path == null) {
         $path = Conf::get('tool_shell');
     }
     $this->path = $path;
     $this->execName = $execName;
     $this->header = $header;
     $this->delimiter = $delimiter;
     // initialize
     $this->result = array();
     $this->done = false;
     $this->output = array();
     $this->rtCode = NULL;
     $this->log = new Log(__CLASS__);
 }
Ejemplo n.º 5
0
 public function __construct()
 {
     //$host, $user, $password, $name, $port, $table_name=null)
     $this->dataBase = new Database(Conf::get('pkg_db_host'), Conf::get('pkg_db_port'), Conf::get('pkg_db_user'), Conf::get('pkg_db_password'), Conf::get('pkg_db_name'), Conf::get('pkg_db_info_table'));
 }
Ejemplo n.º 6
0
 /**
  * [updateStatus 更新实例信息]
  * @param  [type] $ipList      [description]
  * @param  [type] $packagePath [description]
  * @param  [type] $installPath [description]
  * @param  [type] $status      [description]
  * @return [type]              [description]
  */
 public function updateStatus($ipList, $packagePath, $installPath, $status)
 {
     $ipStr = implode('\',\'', $ipList);
     $keys = array('status' => $status, 'packagePath' => $packagePath, 'installPath' => $installPath);
     $sql = "update " . Conf::get('pkg_db_instance_table') . " set status=:status where ip in (";
     foreach ($ipList as $index => $ip) {
         $name = "ip{$index}";
         if ($index != count($ipList) - 1) {
             $sql .= ":{$name}, ";
         } else {
             $sql .= ":{$name})";
         }
         $keys[$name] = $ip;
     }
     $sql .= "and packagePath=:packagePath and installPath=:installPath";
     // var_dump($sql);exit;
     $result = $this->dataBase->executeSql($sql, $keys, false);
     return $result;
 }
Ejemplo n.º 7
0
 /**
  * [submitVersion 撤销版本]
  * @return [type] [description]
  */
 public function deleteVersion()
 {
     //获取post数据 调用
     $data = Flight::request()->data->getData();
     $errorArray = array('error' => '');
     $this->log->info("START FUNCTION " . __FUNCTION__);
     $data = Flight::request()->query->getData();
     $this->log->info('data:' . json_encode($data));
     //参数检查
     if (!isset($data['product']) || !isset($data['name']) || !isset($data['version'])) {
         $errorArray['error'] = "missing parameters:product, name, version, last";
         Flight::json($errorArray, 400);
     }
     $this->log->info(json_encode($data));
     $packageProduct = $data['product'];
     $packageName = $data['name'];
     $packageVersion = $data['version'];
     //是否还是要checkout svn路径先 也就是checkoutmethod
     $checkoutRes = $this->checkOutMethod($packageProduct, $packageName, $packageVersion);
     if ($checkoutRes['code'] != 0) {
         $errorArray['error'] = $checkoutRes['error'];
         $this->log->info("package checkout failed:" . $checkoutRes['error']);
         Flight::json($errorArray, 400);
     }
     //to delete cache
     $hostIp = Conf::get('file_manage_host');
     $hostName = Conf::get('file_manage_hostname');
     $url = $hostName . Conf::get('file_manage_mainurl') . Conf::get('file_manage_suburl_deletecache');
     $requestData = array('product' => $packageProduct, 'name' => $packageName, 'version' => $packageVersion);
     $option = array('ip' => $hostIp, 'method' => 'GET', 'data' => $data, 'decode' => true);
     $magic = new MagicTool();
     $deleteCacheResult = $magic->httpRequest($url, $option);
     //判断delete cache是否成功
     if ($deleteCacheResult == null || isset($deleteCacheResult['error']) && !empty($deleteCacheResult['error'])) {
         $errorArray['error'] = 'delete cache step failed';
         if (isset($deleteCacheResult['error'])) {
             $errorArray['error'] .= $deleteCacheResult['error'];
         }
         $this->log->info("package delete cache failed:" . $errorArray['error']);
         Flight::json($errorArray, 400);
     }
     //获取数据库的记录
     $packageItem = new Package();
     $packageInfo = $packageItem->getInfo($packageProduct, $packageName, $packageVersion);
     //无该包
     if (!is_array($packageInfo) || count($packageInfo) == 0) {
         $errorArray['error'] = "指定的包不存在 product={$packageProduct}, name={$packageName}, version={$packageVersion}";
         $this->log->info("package not exists");
         Flight::json($errorArray, 404);
     }
     $svnPath = $packageInfo['path'];
     $instanceItem = new Instance();
     $instanceList = $instanceItem->getInstance($svnPath, $packageVersion);
     if ($instanceList && count($instanceList) > 0) {
         $errorArray['error'] = "该版本存在已安装的实例,如需撤销,请先到实例管理中卸载或删除相关记录后重试";
         $this->log->info("package has instance using it");
         Flight::json($errorArray, 400);
     }
     $shellRun = new ExecShell('pkg_delete.sh', Conf::get('tool_operate'));
     $shellRun->run("pkg_path={$svnPath}", "version={$packageVersion}");
     $this->log->info('shell run result:' . json_encode($shellRun->getOutput()));
     $returnCode = $shellRun->rtCode();
     if ($returnCode != 0 || $shellRun->result(1) != "success") {
         $errorArray['error'] = "撤销失败:" . $shellRun->result(2);
         $this->log->info("run script pkg_delete fail:" . $shellRun->result(2));
         Flight::json($errorArray, 400);
     }
     $packageId = $packageInfo['packageId'];
     $svnVersion = $packageInfo['packageId'];
     // 是否包剩下的唯一版本
     $last = $packageItem->isLastPackage($svnPath);
     if ($last != true) {
         $this->log->info("not the only valid package");
         //撤销时 将包回到上一版本提交
         $backupPath = Conf::get('package_backup');
         $operateScriptDir = Conf::get('tool_operate');
         $svnScriptDir = Conf::get('tool_svn');
         $pkgTmpPath = Conf::get('package_tmp');
         $srcDir = $this->pkgHome;
         $srcPath = $srcDir . $svnPath;
         $tmpSvnExportPath = $pkgTmpPath . $svnPath;
         $previousPackage = $packageItem->getLastValidPackage($svnPath, $packageId, $packageVersion);
         if ($previousPackage != null) {
             //存在上个版本 可以继续
             $this->log->info("has a previous version, can do revert ");
             $previousPackageVersion = $previousPackage['version'];
             $previousPackageSvnVersion = $previousPackage['svnVersion'];
             if (intval($previousPackageSvnVersion) == 0) {
                 //上个版本svn版本号不正确 撤销失败
                 $errorArray['error'] = "撤销失败:上个版本svn版本号不正确";
                 $this->log->info("revert failed:svn tag incorrect");
                 Flight::json($errorArray, 400);
             }
             $pkgsvn = new PkgSvn();
             $svnRunRes = $pkgsvn->export($svnPath, $tmpSvnExportPath, $previousPackageSvnVersion);
             if ($svnRunRes['code'] != 0) {
                 $errorArray['error'] = "撤销失败:导出上个版本包失败:{$svnRunRes['msg']}";
                 $this->log->info("导出上个版本包失败");
                 Flight::json($errorArray, 400);
             }
             $commandList = array("cp {$srcPath} {$backupPath} -r -f ; echo \$?", "cd {$srcPath} ; rm -rf `ls|egrep -v '(.svn)'`; echo \$?", "cp {$tmpSvnExportPath}/* {$srcPath}/ -r ; echo \$?");
             $stepPass = true;
             foreach ($commandList as $singleCommand) {
                 // $singleCommand = escapeshellcmd($singleCommand);
                 $runRes = shell_exec($singleCommand);
                 $this->log->info($singleCommand);
                 $this->log->info("result:" . $runRes);
                 if (strpos($runRes, 'fail') !== false) {
                     $stepPass = false;
                 }
                 if (strpos($runRes, 'success') !== false) {
                     $this->log->info("step ok");
                 } elseif (strpos($runRes, '0') !== false) {
                     $this->log->info("step ok");
                 } else {
                     $this->log->info("step fail");
                     $stepPass = false;
                 }
                 if (!$stepPass) {
                     $errorArray['error'] = "撤销失败:恢复上个版本包步骤失败";
                     Flight::json($errorArray, 400);
                 }
             }
             //提交版本
             $svnRunRes = $pkgsvn->commit($srcPath, "go back to previous version");
             $this->log->info(json_encode($svnRunRes));
             if ($svnRunRes['code'] != 0) {
                 $errorArray['error'] = "撤销失败:提交为上个版本包失败:{$svnRunRes['msg']}";
                 $this->log->info("提交失败");
                 Flight::json($errorArray, 400);
             }
         }
     }
     $packageItem->setStatus($packageId, 4);
     //标记包状态作废
     //唯一的包版本被撤销 则删掉关联svn文件夹
     if ($last == true && !empty($svnPath)) {
         $this->log->info("delete the svn dir too");
         $pkgSvnScript = new PkgSvn();
         $shellRunRes = $pkgSvnScript->allDelete($svnPath);
         $this->log->info('svn delete' . json_encode($shellRunRes));
         if ($shellRunRes['code'] != 0) {
             $errorArray['error'] = "删除包svn文件失败";
             $this->log->info("run script:pkg_all_delete.sh fail");
             Flight::json($errorArray, 400);
         }
     }
     $this->log->info("delete version completed");
     //成功
     Flight::json($errorArray, 200);
 }
Ejemplo n.º 8
0
 /**
  * [deleteCache 清除缓存]
  * @return [type] [description]
  */
 public function deleteCache()
 {
     $this->log->info("START FUNCTION " . __FUNCTION__);
     $errorArray = array('error' => '');
     $data = Flight::request()->query->getData();
     //参数检查
     $needPara = array('product', 'name', 'version');
     $optionalPara = array();
     $error = $this->checkParameter($needPara, $data, $optionalPara);
     $this->log->info('data:' . json_encode($data));
     $product = $data['product'];
     $name = $data['name'];
     $version = $data['version'];
     $packageItem = new Package();
     $packageInfo = $packageItem->getInfo($product, $name, $version);
     if ($packageInfo == null) {
         $errorArray['error'] = "package not exists";
         Flight::json($errorArray, 404);
     }
     //run scripts
     $svnPath = $packageInfo['path'];
     $shellRun = new ExecShell('pkg_delete.sh', Conf::get('tool_operate'));
     $shellRun->run('version=' . $version, 'pkg_path=' . $svnPath);
     $this->log->info('shell run result:' . json_encode($shellRun->getOutput()));
     if ($shellRun->rtCode() != 0) {
         $errorArray['error'] = $shellRun->result(2);
         Flight::json($errorArray, 400);
     }
     //success
     Flight::json($errorArray, 200);
 }
Ejemplo n.º 9
0
 /**
  * [addTask 将任务信息加到数据库表中]
  * @param [array] $ipList         [ip列表]
  * @param [string] $operation      [install ..]
  * @param [string] $operator       [description]
  * @param [array] $parameterArray [description]
  */
 public function addTask($ipList, $operation, $operator, $parameterArray)
 {
     //无需加参数检查 都在调用处检查
     $result = true;
     $startTime = date('Y-m-d H:i:s');
     $database = new Database(Conf::get('pkg_db_host'), Conf::get('pkg_db_port'), Conf::get('pkg_db_user'), Conf::get('pkg_db_password'), Conf::get('pkg_db_name'), Conf::get('pkg_db_task_table'));
     $taskId = uniqid();
     $toInsert = array('task_id' => $taskId, 'op_type' => $operation, 'operator' => $operator, 'ip_list' => implode(";", $ipList), 'param' => json_encode($parameterArray), 'task_status' => 'wait', 'success_num' => 0, 'fail_num' => 0, 'task_num' => count($ipList), 'product' => $parameterArray['product'], 'name' => $parameterArray['name'], 'start_time' => $startTime);
     $dbRes = $database->insertValue($toInsert);
     if (!$dbRes) {
         $result = false;
     }
     foreach ($ipList as $ip) {
         $toInsert = array('task_id' => $taskId, 'operate' => $operation, 'ip' => $ip, 'status' => 'wait', 'start_time' => $startTime);
         $dbRes = $database->insertValue($toInsert, Conf::get('pkg_db_task_result_table'));
         if (!$dbRes) {
             $result = false;
         }
     }
     return $taskId;
 }
Ejemplo n.º 10
0
 function __construct()
 {
     //$host, $user, $password, $name, $port, $table_name=null)
     $this->dataBase = new Database(Conf::get('pkg_db_host'), Conf::get('pkg_db_port'), Conf::get('pkg_db_user'), Conf::get('pkg_db_password'), Conf::get('pkg_db_name'), Conf::get('pkg_db_info_table'));
     $this->packageInfo = array("id" => "", 'billId' => '', "product" => "", "name" => "", "version" => "", "path" => "", "svnVersion" => "", "user" => "", "stateless" => "", "frameworkType" => "", "os" => "", "remark" => "", "status" => "");
 }