/** * @param int|string|Cluster $clusterId * * @return bool True if server removed from cluster */ public function removeFromCluster($clusterId) { $_cluster = $this->findCluster($clusterId); if ($this->belongsToCluster($_cluster->id)) { return 1 == ClusterServer::where('cluster_id', '=', $_cluster->id)->where('server_id', '=', $this->id)->delete(); } return false; }
/** * @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(); } }