Example #1
0
 public static function update_eve($parameters)
 {
     try {
         ClientId::add_maintenance_asset($parameters);
     } catch (Error $error) {
         syslog(LOG_ERR, ' EVE - ERROR IN When try to upload asset in' . $parameters['datacenter'] . '-' . $parameters['environment'] . ': ' . json_encode($error));
         throw $error;
     }
     $params = array();
     $parameters['updated_by'] = $parameters['user']['email'];
     $job_params = array();
     $job_params['order'] = array();
     $job_params['request_params'] = array();
     $job_params['client_id'] = $parameters['client_id'];
     $job_params['request_params']['alpha']['datacenter'] = $parameters['datacenter'];
     $job_params['request_params']['alpha']['environment'] = $parameters['environment'];
     $job_params['request_params']['alpha']['status'] = $parameters['status'];
     $job_params['request_params']['alpha']['updated_by'] = $parameters['updated_by'];
     $job_params['request_params']['beta']['datacenter'] = $parameters['datacenter'];
     $job_params['request_params']['beta']['environment'] = $parameters['environment'];
     $job_params['request_params']['beta']['status'] = $parameters['status'];
     $job_params['request_params']['beta']['updated_by'] = $parameters['updated_by'];
     $job_params['request_params']['gold']['datacenter'] = $parameters['datacenter'];
     $job_params['request_params']['gold']['environment'] = $parameters['environment'];
     $job_params['request_params']['gold']['status'] = $parameters['status'];
     $job_params['request_params']['gold']['updated_by'] = $parameters['updated_by'];
     $params['environment'] = $parameters['datacenter'] . '_' . $parameters['environment'];
     $params['user'] = $parameters['updated_by'];
     $job_params['delete_in'] = array();
     /* Set basic order */
     $first = 'beta';
     $second = 'gold';
     $last = 'alpha';
     /*Send delete to apply before make an update*/
     if (isset($parameters['id']) && strlen($parameters['id']) > 0) {
         $clientid = $parameters;
         if ($clientid != false && $clientid['datacenter'] != $parameters['datacenter']) {
             $job_params['delete_in']['alpha']['datacenter'] = $clientid['datacenter'];
             $job_params['delete_in']['beta']['datacenter'] = $clientid['datacenter'];
             $job_params['delete_in']['gold']['datacenter'] = $clientid['datacenter'];
             $delete_params = clone $parameters;
             $delete_params->environment = $clientid['environment'];
             $delete_params->datacenter = $clientid['datacenter'];
             try {
                 $this->remove_maintenance_asset($delete_params);
             } catch (Error $error) {
                 if ($error->getHttpErrorCode() == HTTP_NOT_FOUND_ERROR) {
                     //nothing to do;
                 } else {
                     syslog(LOG_ERR, ' EVE - ERROR When try to remove asset in' . $parameters['datacenter'] . '-' . $parameters['environment'] . ': ' . json_encode($error));
                     throw $error;
                 }
             }
         }
         if ($clientid['environment'] == 'gold' && $parameters['environment'] == 'gold') {
             $first = 'gold';
             $second = 'beta';
             $last = 'alpha';
         }
         if (in_array($clientid['environment'], array('alpha', 'beta')) && $parameters['environment'] == 'gold') {
             $first = 'gold';
             $second = 'beta';
             $last = 'alpha';
         }
         if (in_array($clientid['environment'], array('gold', 'beta', 'alpha')) && $parameters['environment'] == 'alpha') {
             $first = 'alpha';
             $second = 'gold';
             $last = 'beta';
         }
     } else {
         if ($parameters['environment'] == 'gold') {
             $first = 'gold';
             $second = 'beta';
             $last = 'alpha';
         }
         if ($parameters['environment'] == 'alpha') {
             $first = 'alpha';
             $second = 'gold';
             $last = 'beta';
         }
     }
     array_push($job_params['order'], $first, $second, $last);
     $params['params'] = json_encode($job_params);
     $response = Durona::update_eve_job((object) $params);
     return json_decode($response);
 }