Example #1
0
 /**
  * @return int
  */
 protected function showServers()
 {
     $_servers = Models\Server::orderBy('server_id_text')->get();
     if (empty($_servers)) {
         $this->info('** No servers found **');
         return 0;
     }
     $this->writeln('Registered servers (* denotes cluster assignment)');
     $this->writeln('-------------------------------------------------');
     foreach ($_servers as $_server) {
         $_used = 0 != Models\ClusterServer::where('server_id', $_server->id)->count();
         $this->writeln(($_used ? '*' : ' ') . '<info>' . $_server->server_id_text . "</info>\t" . '<comment>' . $_server->serverType->type_name_text . '@' . $_server->host_text . '</comment>');
     }
     return 0;
 }
 public function destroy($ids)
 {
     try {
         $cluster_names = [];
         if ($ids == 'multi') {
             $params = \Input::all();
             $selected = $params['_selected'];
             $id_array = explode(',', $selected);
         } else {
             $id_array = explode(',', $ids);
         }
         foreach ($id_array as $id) {
             $cluster = Cluster::where('id', '=', $id);
             $cluster_name = $cluster->get(['cluster_id_text']);
             array_push($cluster_names, '"' . $cluster_name[0]->cluster_id_text . '"');
             $cluster->delete();
             ClusterServer::where('server_id', '=', intval($id))->delete();
         }
         if (count($id_array) > 1) {
             $clusters = '';
             foreach ($cluster_names as $i => $name) {
                 $clusters .= $name;
                 if (count($cluster_names) > $i + 1) {
                     $clusters .= ', ';
                 }
             }
             $result_text = 'The servers ' . $clusters . ' were deleted successfully!';
         } else {
             $result_text = 'The server ' . $cluster_names[0] . ' was deleted successfully!';
         }
         $result_status = 'alert-success';
         $_redirect = '/';
         $_redirect .= $this->getUiPrefix();
         $_redirect .= '/clusters';
         return \Redirect::to($_redirect)->with('flash_message', $result_text)->with('flash_type', $result_status);
     } catch (QueryException $e) {
         //$res_text = $e->getMessage();
         Session::flash('flash_message', 'An error occurred! Please try again.');
         Session::flash('flash_type', 'alert-danger');
         return redirect('/v1/clusters')->withInput();
     }
 }
 /**
  * Returns an collection of clusters to which $serverId is assigned
  *
  * @param string|int $serverId
  *
  * @return array|\Illuminate\Database\Eloquent\Collection|static[]
  */
 protected static function findServerClusters($serverId)
 {
     return ClusterServer::with(['server', 'cluster'])->where('server_id', '=', $serverId)->get();
 }
Example #4
0
 /**
  * @param int $clusterId
  *
  * @return bool True if this instance
  */
 public function belongsToCluster($clusterId)
 {
     return 0 != ClusterServer::whereRaw('cluster_id = :cluster_id AND server_id = :server_id', [':cluster_id' => $clusterId, ':server_id' => $this->id])->count();
 }
Example #5
0
 /**
  * Returns a list of servers assigned to me
  *
  * @return \DreamFactory\Enterprise\Database\Models\ClusterServer[]|\Illuminate\Database\Eloquent\Collection
  */
 public function assignedServers()
 {
     return ClusterServer::with('server')->where('cluster_id', $this->id)->get();
 }