Skip to content

Commit

Permalink
Refactor other controllers to be analog to new Storage one.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van Wieringen committed Jul 26, 2016
1 parent 8bf4e65 commit d524ff1
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 85 deletions.
36 changes: 22 additions & 14 deletions module/Client/src/Client/Controller/ClientController.php
Expand Up @@ -50,32 +50,40 @@ public function indexAction()
if(empty($action)) {
return new ViewModel();
}
elseif($action == "enable") {
$clientname = $this->params()->fromQuery('client');
else {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getClientModel()->enableClient($this->bsock, $clientname);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
return new ViewModel(
array(
'result' => $result
)
);
}
elseif($action == "disable") {
$clientname = $this->params()->fromQuery('client');

if($action == "enable") {
$clientname = $this->params()->fromQuery('client');
try {
$result = $this->getClientModel()->enableClient($this->bsock, $clientname);
}
catch(Exception $e) {
echo $e->getMessage();
}
}
elseif($action == "disable") {
$clientname = $this->params()->fromQuery('client');
try {
$result = $this->getClientModel()->disableClient($this->bsock, $clientname);
}
catch(Exception $e) {
echo $e->getMessage();
}
}

try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getClientModel()->disableClient($this->bsock, $clientname);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}

return new ViewModel(
array(
'result' => $result
Expand Down
111 changes: 62 additions & 49 deletions module/Job/src/Job/Controller/JobController.php
Expand Up @@ -59,13 +59,27 @@ public function indexAction()
)
);
}
elseif($action == "rerun") {
$jobid = $this->params()->fromQuery('jobid');

$result = null;
else {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->rerunJob($this->bsock, $jobid);
}
catch(Exception $e) {
echo $e->getMessage();
}

if($action == "rerun") {
$jobid = $this->params()->fromQuery('jobid');

$result = null;
try {
$result = $this->getJobModel()->rerunJob($this->bsock, $jobid);
}
catch(Exception $e) {
echo $e->getMessage();
}
}

try {
$this->bsock->disconnect();
}
catch(Exception $e) {
Expand Down Expand Up @@ -153,48 +167,49 @@ public function actionsAction()
if(empty($action)) {
return new ViewModel();
}
elseif($action == "queue") {
$jobname = $this->params()->fromQuery('job');
else {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->runJob($this->bsock, $jobname);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
return new ViewModel(
array(
'result' => $result
)
);
}
elseif($action == "enable") {
$jobname = $this->params()->fromQuery('job');
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->enableJob($this->bsock, $jobname);
$this->bsock->disconnect();

if($action == "queue") {
$jobname = $this->params()->fromQuery('job');
try {
$result = $this->getJobModel()->runJob($this->bsock, $jobname);
}
catch(Exception $e) {
echo $e->getMessage();
}
}
catch(Exception $e) {
echo $e->getMessage();
elseif($action == "enable") {
$jobname = $this->params()->fromQuery('job');
try {
$result = $this->getJobModel()->enableJob($this->bsock, $jobname);
}
catch(Exception $e) {
echo $e->getMessage();
}
}
return new ViewModel(
array(
'result' => $result
)
);
}
elseif($action == "disable") {
$jobname = $this->params()->fromQuery('job');
elseif($action == "disable") {
$jobname = $this->params()->fromQuery('job');
try {
$result = $this->getJobModel()->disableJob($this->bsock, $jobname);
}
catch(Exception $e) {
echo $e->getMessage();
}
}

try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->disableJob($this->bsock, $jobname);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}

return new ViewModel(
array(
'result' => $result
Expand All @@ -218,57 +233,55 @@ public function getDataAction()
$status = $this->params()->fromQuery('status');
$period = $this->params()->fromQuery('period');

try {
$this->bsock = $this->getServiceLocator()->get('director');
}
catch(Exception $e) {
echo $e->getMessage();
}

if($data == "jobs" && $status == "all") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->getJobs($this->bsock, $status, $period);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
}
elseif($data == "jobs" && $status == "successful") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$jobs_T = $this->getJobModel()->getJobsByStatus($this->bsock, 'T', $period, null); // Terminated
$jobs_W = $this->getJobModel()->getJobsByStatus($this->bsock, 'W', $period, null); // Terminated with warnings
$result = array_merge($jobs_T, $jobs_W);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
}
elseif($data == "jobs" && $status == "unsuccessful") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$jobs_A = $this->getJobModel()->getJobsByStatus($this->bsock, 'A', $period, null); // Canceled jobs
$jobs_E = $this->getJobModel()->getJobsByStatus($this->bsock, 'E', $period, null); //
$jobs_e = $this->getJobModel()->getJobsByStatus($this->bsock, 'e', $period, null); //
$jobs_f = $this->getJobModel()->getJobsByStatus($this->bsock, 'f', $period, null); //
$result = array_merge($jobs_A, $jobs_E, $jobs_e, $jobs_f);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
}
elseif($data == "jobs" && $status == "running") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$jobs_R = $this->getJobModel()->getJobsByStatus($this->bsock, 'R', $period, null);
$jobs_l = $this->getJobModel()->getJobsByStatus($this->bsock, 'l', $period, null);
$result = array_merge($jobs_R, $jobs_l);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
}
elseif($data == "jobs" && $status == "waiting") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$jobs_F = $this->getJobModel()->getJobsByStatus($this->bsock, 'F', $period, null);
$jobs_S = $this->getJobModel()->getJobsByStatus($this->bsock, 'S', $period, null);
$jobs_m = $this->getJobModel()->getJobsByStatus($this->bsock, 'm', $period, null);
Expand All @@ -286,43 +299,43 @@ public function getDataAction()
$jobs_s,$jobs_j,$jobs_c,$jobs_d,
$jobs_t,$jobs_p,$jobs_q,$jobs_C
);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
}
elseif($data == "backupjobs") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->getBackupJobs($this->bsock);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
}
elseif($data == "details") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->getJob($this->bsock, $jobid);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
}
elseif($data == "logs" && isset($jobid)) {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->getJobLog($this->bsock, $jobid);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
}

try {
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}

$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Content-Type', 'application/json');

Expand Down
48 changes: 27 additions & 21 deletions module/Schedule/src/Schedule/Controller/ScheduleController.php
Expand Up @@ -48,9 +48,15 @@ public function indexAction()
$action = $this->params()->fromQuery('action');
$schedulename = $this->params()->fromQuery('schedule');

try {
$this->bsock = $this->getServiceLocator()->get('director');
}
catch(Exception $e) {
echo $e->getMessage();
}

if(empty($action)) {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$schedules = $this->getScheduleModel()->getSchedules($this->bsock);
$this->bsock->disconnect();
}
Expand All @@ -63,33 +69,33 @@ public function indexAction()
)
);
}
elseif($action == "enable") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$schedules = $this->getScheduleModel()->getSchedules($this->bsock);
$result = $this->getScheduleModel()->enableSchedule($this->bsock, $schedulename);
$this->bsock->disconnect();
else {
if($action == "enable") {
try {
$schedules = $this->getScheduleModel()->getSchedules($this->bsock);
$result = $this->getScheduleModel()->enableSchedule($this->bsock, $schedulename);
}
catch(Exception $e) {
echo $e->getMessage();
}
}
catch(Exception $e) {
echo $e->getMessage();
elseif($action == "disable") {
try {
$schedules = $this->getScheduleModel()->getSchedules($this->bsock);
$result = $this->getScheduleModel()->disableSchedule($this->bsock, $schedulename);
}
catch(Exception $e) {
echo $e->getMessage();
}
}
return new ViewModel(
array(
'schedules' => $schedules,
'result' => $result
)
);
}
elseif($action == "disable") {

try {
$this->bsock = $this->getServiceLocator()->get('director');
$schedules = $this->getScheduleModel()->getSchedules($this->bsock);
$result = $this->getScheduleModel()->disableSchedule($this->bsock, $schedulename);
$this->bsock->disconnect();
}
}
catch(Exception $e) {
echo $e->getMessage();
}

return new ViewModel(
array(
'schedules' => $schedules,
Expand Down
3 changes: 2 additions & 1 deletion module/Storage/src/Storage/Controller/StorageController.php
Expand Up @@ -63,7 +63,8 @@ public function detailsAction()
return new ViewModel(array(
'storagename' => $storagename
));
} else {
}
else {
try {
$this->bsock = $this->getServiceLocator()->get('director');
}
Expand Down

0 comments on commit d524ff1

Please sign in to comment.