Exemplo n.º 1
0
 public function dependsOnIt(EtvaAsynchronousJob $j1, EtvaAsynchronousJob $j2)
 {
     if ($j2->getTasknamespace() == 'logicalvolume') {
         $j2_args = (array) json_decode($j1->getArguments());
         $j2_opts = (array) json_decode($j1->getOptions());
         $etva_node = EtvaNodePeer::getOrElectNodeFromArray(array_merge($j2_opts, $j2_args));
         if ($etva_node) {
             // original logical volume
             $original_lv = $j2_args['original'];
             $original_vg = $j2_opts['original-volumegroup'];
             // find orignal logical volume
             $etva_original_lv = $etva_node->retrieveLogicalvolumeByAny($original_lv, $original_vg);
             if ($etva_original_lv) {
                 $j1_args = (array) json_decode($j1->getArguments());
                 $lv_servers = $etva_original_lv->getServers();
                 // get servers where logical volume is attached
                 foreach ($lv_servers as $srv) {
                     if ($srv->getId() == $j1_args['server'] || $srv->getUuid() == $j1_args['server'] || $srv->getName() == $j1_args['server']) {
                         return true;
                         // depends on it
                     }
                 }
             }
         }
     }
     return false;
 }
Exemplo n.º 2
0
 public function dependsOnIt(EtvaAsynchronousJob $j1, EtvaAsynchronousJob $j2)
 {
     if ($j1->getTasknamespace() == $j2->getTasknamespace()) {
         if ($j2->getTaskname() !== 'clone') {
             return true;
         }
     } else {
         if ($j2->getTasknamespace() == 'volumegroup') {
             return true;
         } else {
             if ($j2->getTasknamespace() == 'physicalvolume') {
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 3
0
 public function executeNew(sfWebRequest $request)
 {
     //$this->form = new EtvaAsynchronousJobForm();
     $msg_i18n = $this->getContext()->getI18N()->__('unknown error', array());
     $result = array('success' => false, 'error' => $msg_i18n, 'agent' => sfConfig::get('config_acronym'));
     if ($request->isMethod('post')) {
         $formdata = (array) json_decode($request->getParameter('asynchronousjob'));
         $formdata['user'] = $this->getUser()->getGuardUser()->getUsername();
         $asyncjob = new EtvaAsynchronousJob();
         $asyncjob->fromArray($formdata, BasePeer::TYPE_FIELDNAME);
         try {
             $asynctask = $asyncjob->getTask($this->dispatcher);
         } catch (Exception $e) {
             $result = array('success' => false, 'error' => $e->getMessage(), 'agent' => sfConfig::get('config_acronym'));
         }
         if ($asynctask) {
             // calc dependencies
             if ($depends = $asyncjob->calcDepends($formdata['depends'], $this->dispatcher)) {
                 $asyncjob->setDepends($depends);
             }
             // save
             $asyncjob->save();
             $taskdesc = $asynctask->getBriefDescription() ? $asynctask->getBriefDescription() : $asyncjob->getTasknamespace() . ":" . $asyncjob->getTaskname();
             $taskdesc_i18n = $this->getContext()->getI18N()->__($taskdesc, array());
             $msg_i18n = $this->getContext()->getI18N()->__('Task \'%task%\' created successfully.', array('%task%' => $taskdesc_i18n));
             //error_log("executeNew Task '$taskdesc' deps=".$asyncjob->getDepends(). " formdata=".$formdata['depends']);
             $result = array('success' => true, 'response' => $msg_i18n, 'agent' => sfConfig::get('config_acronym'), 'asynchronousjob' => $asyncjob->toArray());
         } else {
             $msg_i18n = $this->getContext()->getI18N()->__('Asynchronous job with invalid task!', array());
             $result = array('success' => false, 'error' => $msg_i18n, 'agent' => sfConfig::get('config_acronym'));
         }
     }
     return $this->returnResponse($result);
 }