/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     ///应用组用户只可查看所在组的应用
     $svr_pool_con = "";
     if (Yii::$app->user->getIdentity()->admin != 1) {
         $app_con = "svr_gid in (0";
         $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $app_con .= "," . $item['gid'];
             }
         }
         $app_con .= ")";
         $query = DcmdApp::find()->where($app_con)->asArray()->all();
         $svr_pool_con = "app_id in (0";
         foreach ($query as $item) {
             $svr_pool_con .= "," . $item['app_id'];
         }
         $svr_pool_con .= ")";
     }
     $query = DcmdServicePool::find()->where($svr_pool_con)->orderBy('svr_pool');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['svr_pool_id' => $this->svr_pool_id, 'svr_id' => $this->svr_id, 'app_id' => $this->app_id, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]);
     $query->andFilterWhere(['like', 'svr_pool', $this->svr_pool])->andFilterWhere(['like', 'repo', $this->repo])->andFilterWhere(['like', 'env_ver', $this->env_ver])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
 /**
  * Lists all DcmdServicePoolNode models.
  * @return mixed
  */
 public function actionIndex()
 {
     $params = array();
     if (array_key_exists('DcmdServicePoolNodeSearch', Yii::$app->request->queryParams)) {
         $params['DcmdServicePoolNodeSearch'] = Yii::$app->request->queryParams['DcmdServicePoolNodeSearch'];
         if ($params['DcmdServicePoolNodeSearch']['app_id'] == "") {
             $params['DcmdServicePoolNodeSearch']['svr_id'] = "";
         }
         if ($params['DcmdServicePoolNodeSearch']['svr_id'] == "") {
             $params['DcmdServicePoolNodeSearch']['svr_pool_id'] = "";
         }
     }
     ///应用足用户只可查看所在组的应用
     $app_con = "";
     if (Yii::$app->user->getIdentity()->admin != 1) {
         $app_con = "svr_gid in (0";
         $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $app_con .= "," . $item['gid'];
             }
         }
         $app_con .= ")";
     }
     $query = DcmdApp::find()->where($app_con)->orderBy('app_name')->asArray()->all();
     $app = array();
     foreach ($query as $item) {
         $app[$item['app_id']] = $item['app_alias'];
     }
     $svr = array();
     if (array_key_exists('DcmdServicePoolNodeSearch', $params) && array_key_exists('app_id', $params['DcmdServicePoolNodeSearch'])) {
         $query = DcmdService::find()->andWhere(['app_id' => $params['DcmdServicePoolNodeSearch']['app_id']])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $svr[$item['svr_id']] = $item['svr_name'];
             }
         }
         if (!array_key_exists($params['DcmdServicePoolNodeSearch']['svr_id'], $svr)) {
             $params['DcmdServicePoolNodeSearch']['svr_id'] = "";
         }
     }
     $svr_pool = array();
     if (array_key_exists('DcmdServicePoolNodeSearch', $params) && array_key_exists('svr_id', $params['DcmdServicePoolNodeSearch']) && array_key_exists($params['DcmdServicePoolNodeSearch']['svr_id'], $svr)) {
         $query = DcmdServicePool::find()->andWhere(['svr_id' => $params['DcmdServicePoolNodeSearch']['svr_id']])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $svr_pool[$item['svr_pool_id']] = $item['svr_pool'];
             }
         }
     }
     if (array_key_exists('DcmdServicePoolNodeSearch', $params)) {
         if (!array_key_exists($params['DcmdServicePoolNodeSearch']['svr_pool_id'], $svr_pool)) {
             $params['DcmdServicePoolNodeSearch']['svr_pool_id'] = "";
         }
     }
     $searchModel = new DcmdServicePoolNodeSearch();
     $dataProvider = $searchModel->search($params);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'app' => $app, 'svr' => $svr, 'svr_pool' => $svr_pool]);
 }
Esempio n. 3
0
 public function getSvrPoolId($svr_pool)
 {
     $query = DcmdServicePool::findOne(['svr_pool' => $svr_pool]);
     if ($query) {
         return $query['svr_pool_id'];
     }
     return "";
 }
 public function getServicePool($svr_pool_id)
 {
     $query = DcmdServicePool::findOne($svr_pool_id);
     if ($query) {
         return $query['svr_pool'];
     }
     return "";
 }
 /**
  * Updates an existing DcmdServicePoolAttr model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id, $svr_pool_id)
 {
     $svr_pool = DcmdServicePool::findOne($svr_pool_id);
     ///仅仅用户与该应用在同一个系统组才可以操作
     $temp = DcmdApp::findOne($svr_pool->app_id);
     $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $temp['sa_gid']]);
     if ($query == NULL) {
         Yii::$app->getSession()->setFlash('success', NULL);
         Yii::$app->getSession()->setFlash('error', "对不起, 你没有权限!");
         return $this->redirect(array('dcmd-service-pool/view', 'id' => $svr_pool_id, 'show_div' => 'dcmd-service-pool-attr'));
     }
     if ($id == 0) {
         ///需要新建
         $attr_id = Yii::$app->request->queryParams['attr_id'];
         $def_attr = DcmdServicePoolAttrDef::findOne($attr_id);
         $query = DcmdServicePoolAttr::findOne(['svr_pool_id' => $svr_pool_id, 'attr_name' => $def_attr->attr_name]);
         if (count($query) > 0) {
             $id = $query['id'];
         } else {
             $model = new DcmdServicePoolAttr();
             $model->app_id = $svr_pool->app_id;
             $model->svr_id = $svr_pool->svr_id;
             $model->svr_pool_id = $svr_pool_id;
             $model->attr_name = $def_attr->attr_name;
             $model->attr_value = $def_attr->def_value;
             $model->comment = $def_attr->comment;
             $model->utime = date('Y-m-d H:i:s');
             $model->ctime = $model->utime;
             $model->opr_uid = Yii::$app->user->getId();
             $model->save();
             $id = $model->id;
         }
     }
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('success', '修改成功!');
         return $this->redirect(['/dcmd-service-pool/view', 'id' => $model->svr_pool_id, 'show_div' => 'dcmd-service-pool-attr']);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
 public function actionGetServicePool($svr_id)
 {
     #return '<tr data-key="15"><td><input type="checkbox" name="selection[]" checked value="15"></td><td>ducter_agent_qcloud1111</td><td>r1.1</td></tr>';
     $query = DcmdServicePool::find()->andWhere(['svr_id' => $svr_id])->all();
     $content = "";
     foreach ($query as $item) {
         $content .= '<tr><td><input type="checkbox" name="selection[]" checked value="' . $item->svr_pool_id . '"></td><td>' . $item->svr_pool . "</td><td>" . $item->env_ver . '</td></tr>';
     }
     return $content;
 }
Esempio n. 7
0
 public function actionGetAppSvr($id)
 {
     $arr = array();
     ///获取应用命令
     $dcmd_app = $this->findModel($id);
     $arr['name'] = $dcmd_app->app_name;
     $arr['children'] = array();
     ///获取应用
     $query = DcmdService::find()->andWhere(['app_id' => $id])->asArray()->all();
     foreach ($query as $item) {
         $svr = array();
         $svr['name'] = $item['svr_name'];
         $svr['children'] = array();
         ///获取应用池子
         $pool = DcmdServicePool::find()->andWhere(['svr_id' => $item['svr_id']])->asArray()->all();
         foreach ($pool as $p) {
             $svrp = array();
             $svrp['name'] = $p['svr_pool'];
             $svrp['children'] = array();
             ///获取节点
             $node = DcmdServicePoolNode::find()->andWhere(['svr_pool_id' => $p['svr_pool_id']])->asArray()->all();
             foreach ($node as $n) {
                 array_push($svrp['children'], array('name' => $n['ip']));
             }
             array_push($svr['children'], $svrp);
         }
         array_push($arr['children'], $svr);
     }
     return json_encode($arr);
 }
 /**
  * Finds the DcmdServicePool model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DcmdServicePool the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DcmdServicePool::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionDeleteAll()
 {
     if (!array_key_exists('selection', Yii::$app->request->post())) {
         Yii::$app->getSession()->setFlash('error', '未选择服务!');
         return $this->redirect(['index']);
     }
     $select = Yii::$app->request->post()['selection'];
     $suc_msg = "";
     $err_msg = "";
     foreach ($select as $k => $id) {
         $model = $this->findModel($id);
         ///仅仅用户与该应用在同一个系统组才可以操作
         $temp = DcmdApp::findOne($model['app_id']);
         $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $temp['sa_gid']]);
         if ($query == NULL) {
             $err_msg .= $model->svr_name . ":没有权限删除<br>";
             continue;
         }
         $node = DcmdServicePool::find()->where(['svr_id' => $id])->one();
         if ($node) {
             $err_msg .= $model->svr_name . ':服务池子不为空,不可删除<br>';
             continue;
         } else {
             $this->oprlog(3, "delete svrvice:" . $model->svr_name);
             $this->deleteDiagram($id);
             $model->delete();
             $suc_msg .= $model->svr_name . ':删除成功<br>';
         }
     }
     if ($suc_msg != "") {
         Yii::$app->getSession()->setFlash('success', $suc_msg);
     }
     if ($err_msg != "") {
         Yii::$app->getSession()->setFlash('error', $err_msg);
     }
     return $this->redirect(['index']);
 }
 /**
  * Creates a new DcmdTaskTemplateServicePool model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($task_tmpt_id)
 {
     if (Yii::$app->user->getIdentity()->admin != 1) {
         Yii::$app->getSession()->setFlash('success', NULL);
         Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!");
         return $this->redirect(array('dcmd-task-template/view', 'id' => $task_tmpt_id));
     }
     if (Yii::$app->request->post()) {
         $tm = date('Y-m-d H:i:s');
         if (array_key_exists("selection", Yii::$app->request->post())) {
             foreach (Yii::$app->request->post()['selection'] as $k => $v) {
                 $dcmd_task_template_service_pool = new DcmdTaskTemplateServicePool();
                 $dcmd_task_template_service_pool->task_tmpt_id = $task_tmpt_id;
                 $dcmd_task_template_service_pool->utime = $tm;
                 $dcmd_task_template_service_pool->ctime = $tm;
                 $dcmd_task_template_service_pool->opr_uid = Yii::$app->user->getId();
                 $dcmd_task_template_service_pool->svr_pool_id = $v;
                 $dcmd_task_template_service_pool->save();
             }
             Yii::$app->getSession()->setFlash('success', "添加服务池子成功!");
         } else {
             Yii::$app->getSession()->setFlash('success', "没有选择服务池!");
         }
         return $this->redirect(['dcmd-task-template/view', 'id' => $task_tmpt_id]);
     }
     $model = new DcmdTaskTemplateServicePool();
     $query = DcmdTaskTemplate::findOne($task_tmpt_id);
     $svr_id = 0;
     if ($query) {
         $svr_id = $query['svr_id'];
     }
     ///获取未添加的服务池子列表
     $query = DcmdTaskTemplateServicePool::find()->andWhere(['task_tmpt_id' => $task_tmpt_id])->asArray()->all();
     $exist_svr_pool = "svr_pool_id not in ( 0";
     if ($query) {
         foreach ($query as $item) {
             $exist_svr_pool .= "," . $item['svr_pool_id'];
         }
     }
     $exist_svr_pool .= ") and svr_id=" . $svr_id;
     $query = DcmdServicePool::find()->where($exist_svr_pool);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $searchModel = new DcmdServicePoolSearch();
     ///获取任务模板名称
     $task_tmpt_name = "";
     $query = DcmdTaskTemplate::findOne($task_tmpt_id);
     if ($query) {
         $task_tmpt_name = $query['task_tmpt_name'];
     }
     $model->task_tmpt_id = $task_tmpt_id;
     return $this->render('create', ['model' => $model, 'task_tmpt_id' => $task_tmpt_id, 'task_tmpt_name' => $task_tmpt_name, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }