Пример #1
0
 $request = $app->request();
 $contentType = $request->headers('Content-Type');
 if ($contentType == 'application/json') {
     $testInfo = $request->getBody();
     $testInfo = json_decode($testInfo, true);
     if (!isset($testInfo['shard']) || empty($testInfo['shard'])) {
         $testInfo['shard'] = false;
     }
 } elseif (preg_match("/form-(data|urlencoded)/", $contentType)) {
     $testInfo = array();
     $testInfo['shard'] = $request->post('shard');
 }
 $islocked = NagTester::getDeploymentTestLock($deployment, $subdeployment, $revision);
 if ($islocked === false) {
     $force = $app->request()->post('force');
     $deploymentResults = NagTester::getDeploymentTestInfo($deployment, $subdeployment, $revision);
     if ($force !== null) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'revision' => $revision, 'type' => 'test', 'subdeployment' => $subdeployment, 'shard' => $testInfo['shard'])), 1024, 0, 900);
         $apiResponse = new APIViewData(0, $deployment, "Build process has been initiated, please change request type to GET to fetch results.");
     } elseif (empty($deploymentResults)) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'revision' => $revision, 'type' => 'test', 'subdeployment' => $subdeployment, 'shard' => $testInfo['shard'])), 1024, 0, 900);
         $apiResponse = new APIViewData(0, $deployment, "Build process has been initiated, please change request type to GET to fetch results.");
     } elseif (isset($deploymentResults['timestamp']) && $deploymentResults['timestamp'] < time() - 60) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'revision' => $revision, 'type' => 'test', 'subdeployment' => $subdeployment, 'shard' => $testInfo['shard'])), 1024, 0, 900);
         $apiResponse = new APIViewData(0, $deployment, "Build process has been initiated, please change request type to GET to fetch results.");
     } else {
         $apiResponse = new APIViewData(1, $deployment, "Build process initiation failed, unknown reasons at this time.");
         $app->halt(404, $apiResponse->returnJson());
 /**
  * test_configs - test configuration view / routine 
  * 
  * @access public
  * @return void
  */
 public function test_configs()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('deployment_error');
     $this->checkGroupAuth($deployment);
     $revision = $this->getParam('revision');
     if ($revision === false) {
         $viewData->header = $this->getErrorHeader('deployment_error');
         $viewData->error = 'Unable to detect revision parameter';
         $this->sendError('generic_error', $viewData);
     } elseif (RevDeploy::existsDeploymentRev($deployment, $revision) !== true) {
         $viewData->header = $this->getErrorHeader('deployment_error');
         $viewData->error = 'Unable to detect deployment revision in datastore';
         $this->sendError('generic_error', $viewData);
     }
     $subdeployment = $this->getParam('subdeployment');
     $shardposition = $this->getParam('shard');
     $islocked = NagTester::getDeploymentTestLock($deployment, $subdeployment, $revision);
     if ($islocked === false) {
         $viewData->running = false;
     } else {
         $viewData->running = true;
     }
     $deploymentResults = NagTester::getDeploymentTestInfo($deployment, $subdeployment, $revision);
     if (empty($deploymentResults) && $islocked !== false) {
         $viewData->jobadded = false;
         $deploymentResults['timestamp'] = '0000000000';
         $deploymentResults['output'] = base64_encode('Job is currently processing, this page will reload automatically...');
     } elseif (empty($deploymentResults) && $islocked === false) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'revision' => $revision, 'type' => 'test', 'subdeployment' => $subdeployment, 'shard' => $shardposition)), 1024, 0, 900);
         $viewData->jobadded = true;
         $deploymentResults['timestamp'] = '0000000000';
         $deploymentResults['output'] = base64_encode('Test Process has been initiated, this page will reload automatically...');
     } elseif (isset($deploymentResults['timestamp']) && $deploymentResults['timestamp'] < time() - 60 && $islocked === false) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'revision' => $revision, 'type' => 'test', 'subdeployment' => $subdeployment, 'shard' => $shardposition)), 1024, 0, 900);
         $viewData->jobadded = true;
         $deploymentResults['output'] = base64_encode('Test Process has been initiated, this page will reload automatically...');
     } elseif (isset($deploymentResults['subdeployment']) && $deploymentResults['subdeployment'] != $subdeployment && $islocked === false) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'revision' => $revision, 'type' => 'test', 'subdeployment' => $subdeployment, 'shard' => $shardposition)), 1024, 0, 900);
         $viewData->jobadded = true;
         $deploymentResults['output'] = base64_encode('Test Process has been initiated, this page will reload automatically...');
     } elseif (!empty($deploymentResults) && $islocked !== false) {
         $deploymentResults['output'] = base64_encode('Job is currently processing, this page will reload automatically...');
         $viewData->jobadded = false;
     } else {
         $viewData->jobadded = false;
     }
     if (isset($deploymentResults['starttime']) && $deploymentResults['timestamp'] != '0000000000') {
         $deploymentResults['totaltime'] = $deploymentResults['timestamp'] - $deploymentResults['starttime'];
         if ($deploymentResults['totaltime'] > 180) {
             $viewData->refresh = 60;
             $viewData->harsh = 5;
         } elseif ($deploymentResults['totaltime'] > 90) {
             $viewData->refresh = 45;
             $viewData->harsh = 4;
         } elseif ($deploymentResults['totaltime'] > 45) {
             $viewData->refresh = 30;
             $viewData->harsh = 3;
         } elseif ($deploymentResults['totaltime'] > 30) {
             $viewData->refresh = 15;
             $viewData->harsh = 2;
         } else {
             $viewData->refresh = 10;
             $viewData->harsh = 1;
         }
     } else {
         /* Unknown at this point... */
         $viewData->refresh = 10;
         $viewData->harsh = 1;
     }
     $viewData->test_output = $deploymentResults;
     $viewData->deployment = $deployment;
     $viewData->revision = $revision;
     $viewData->subdeployment = $subdeployment;
     $viewData->action = 'test_configs';
     $viewData->controller = 'deployment';
     $this->sendResponse('deployment_test_configs', $viewData);
 }