Example #1
0
 public function postDispatch()
 {
     $vaversion = $this->getVAVersion(true);
     //Create image list for unpubished working version
     if ($vaversion->published === false && $vaversion->archived === false && $vaversion->enabled === true && $vaversion->status === "init") {
         VMCaster::createImageList($vaversion->id, "unpublished");
     } else {
         if ($vaversion->published === true && $vaversion->archived === false && $vaversion->enabled === true && $vaversion->status === "verified") {
             VMCaster::createImageList($vaversion->id, "published");
         } else {
             if ($this->state->toBeIntegrityChecked()) {
                 VMCaster::startIntegrityCheck($vaversion->id);
             }
         }
     }
     return true;
 }
Example #2
0
 public static function convertImage($result, $format = 'xml')
 {
     return VMCaster::convertImage($result, $format);
 }
Example #3
0
 public static function cleararchivedvappversions($appid, $fromindex)
 {
     if (!is_numeric($appid) || $appid <= 0) {
         return "Invalid vapplication id";
     }
     if (!is_numeric($fromindex) || $fromindex <= 0) {
         return "Invalid index value";
     }
     if ($fromindex < 20) {
         //Make sure it will never delete all of the vapp archived versions
         $fromindex = 20;
     }
     db()->setFetchMode(Zend_Db::FETCH_BOTH);
     $res = db()->query("select vapp_old_archived_versions(?,?);", array($appid, $fromindex))->fetchAll();
     $result = array();
     if (count($res) > 0) {
         foreach ($res as $r) {
             $vappversions = new Default_Model_VAversions();
             $vappversions->filter->id->equals($r[0]);
             if (count($vappversions->items) > 0) {
                 $vappversion = $vappversions->items[0];
                 $deleted = VMCaster::deleteVersion($vappversion);
                 if ($deleted !== true) {
                     error_log("[VMCaster::cleararchivedvappversions]: " . $deleted);
                 } else {
                     $result[] = $vappversion->id;
                 }
             }
         }
     }
     return implode(",", $result);
 }
Example #4
0
 public function cleararchivedvappversionsAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $islocal = localRequest();
     $appid = isset($_GET["id"]) ? $_GET["id"] : "0";
     $fromindex = isset($_GET["fromindex"]) ? $_GET["fromindex"] : "200";
     if (!is_numeric($appid) || intval($appid) <= 0 || !$islocal) {
         header('HTTP/1.0 404 Not Found');
         header("Status: 404 Not Found");
         return;
     }
     $appid = intval($appid);
     $fromindex = intval($fromindex);
     echo VMCaster::cleararchivedvappversions($appid, $fromindex);
 }
Example #5
0
 public function voimageAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $format = $this->getRequest()->getParam("format");
     $guid = trim($this->getRequest()->getParam("guid"));
     $accesstoken = trim($this->getRequest()->getParam("accesstoken"));
     $strict = isset($_GET["strict"]) ? true : false;
     if ($format === null || $format === "json") {
         header('Content-type: application/json');
     } else {
         if ($format === "xml") {
             header('Content-type: application/xml');
         }
     }
     if ($guid !== "") {
         $imageid = null;
         if (strpos($guid, ":") !== false) {
             $tmp = explode(":", $guid);
             if (count($tmp) > 1) {
                 $guid = $tmp[0];
                 $imageid = $tmp[1];
             }
         }
         if ($imageid !== null) {
             $result = VoAdmin::getImageInfoById($imageid, $guid, $strict);
         } else {
             $result = VoAdmin::getImageInfoByIdentifier($guid);
         }
         $canaccessvadata = false;
         if ($result !== null) {
             $result["isprivateimage"] = false;
             $result["canaccessprivate"] = true;
             $vapp = $result["va"];
             if ($vapp->imglstprivate) {
                 $result["isprivateimage"] = true;
                 $result["canaccessprivate"] = false;
                 $vapp = $result["va"];
                 $app = $vapp->getApplication();
                 if ($privs !== null) {
                     $canaccessvadata = $privs->canAccessVAPrivateData($app->guid);
                 }
                 $result["canaccessprivate"] = $canaccessvadata;
             }
         }
         if ($result !== null && isset($result['image'])) {
             $im = $result['image'];
             $result['sites'] = VMCaster::getSitesByVMI($im->guid, $im->id);
         }
         if ($result !== null && $format == null) {
             //UI call
             $result["result"] = "success";
             $va = $result["va"];
             $app = $va->getApplication();
             $version = $result["version"];
             $image = $result["image"];
             $vo = $result["vo"];
             $voimage = $result["voimage"];
             $voimagelist = $result["voimagelist"];
             $result["app"] = array("id" => $app->id, "name" => $app->name, "cname" => $app->cname);
             $result["va"] = array("id" => $va->id);
             $result["version"] = array("id" => $version->id, "version" => $version->version, "published" => $version->published, "archived" => $version->archived, "enabled" => $version->enabled);
             $result["image"] = array("id" => $image->id, "identifier" => $voimage->guid, "baseidentifier" => $image->guid);
             $result["vo"] = array("id" => $vo->id, "name" => $vo->name, "domain" => $vo->domain->name);
             $result["voimagelist"] = array("id" => $voimagelist->id, "state" => $voimagelist->state);
             $result["voimage"] = array("id" => $voimage->id, "state" => $voimage->state);
             echo json_encode($result, JSON_HEX_TAG | JSON_NUMERIC_CHECK);
             return;
         } else {
             if ($format !== null) {
                 if ($result !== null) {
                     $result = VMCaster::convertImage($result, $format);
                 }
                 if ($result !== null) {
                     echo $result;
                 } else {
                     header('HTTP/1.0 404 Not Found');
                     header("Status: 404 Not Found");
                 }
                 return;
             }
         }
     }
     echo json_encode(array("result" => "error", "message" => "Image not found"));
 }
Example #6
0
 public function parse($xml)
 {
     $vapp = null;
     $app = null;
     $originalxml = '' . $xml;
     if (!is_null($this->_user)) {
         try {
             $xml = new SimpleXMLElement($xml);
             $xml->registerXPathNamespace('virtualization', 'http://appdb.egi.eu/api/1.0/virtualization');
         } catch (Exception $e) {
             $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION;
             $this->_extError = 'Could not parse xml';
             return new Default_Model_VA();
         }
         $this->_xml = $xml;
         if (count($xml->xpath("//vmc2appdb")) > 0) {
             $xml = VMCaster::transformXml($originalxml);
             try {
                 $xml = new SimpleXMLElement($xml);
                 $xml->registerXPathNamespace('virtualization', 'http://appdb.egi.eu/api/1.0/virtualization');
                 $this->isexternalrequest = true;
             } catch (Exception $e) {
                 $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION;
                 $this->_extError = 'Could not parse xml';
                 return new Default_Model_VA();
             }
         }
         if (count($xml->xpath("./virtualization:appliance")) > 0) {
             $xml = $xml->xpath("./virtualization:appliance");
             $xml = $xml[0];
         }
         $vapp = $this->parseVAppliance($xml);
         if ($vapp === false) {
             return false;
         }
         /*
          * Check if an external action is required, such as publishing a version
          */
         $service = $this->createVApplianceService();
         $result = $service->dispatch();
         if ($result !== true) {
             $this->_setErrorMessage($result);
             return false;
         }
         return $vapp;
     } else {
         $this->_error = RestErrorEnum::RE_ACCESS_DENIED;
         return false;
     }
 }