PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/apps/circuits/controllers/reservations.php

https://github.com/jplante815/meican
PHP | 1191 lines | 856 code | 198 blank | 137 comment | 112 complexity | 2332d3dbdae4b2ba3d43cab973af482e MD5 | raw file
  1. <?php
  2. defined('__MEICAN') or die("Invalid access.");
  3. include_once 'libs/controller.php';
  4. include_once 'libs/common.php';
  5. include_once 'apps/circuits/controllers/flows.php';
  6. include_once 'apps/circuits/controllers/timers.php';
  7. include_once 'apps/circuits/models/reservation_info.php';
  8. include_once 'apps/circuits/models/gri_info.php';
  9. include_once 'apps/circuits/models/flow_info.php';
  10. include_once 'apps/circuits/models/timer_info.php';
  11. include_once 'apps/circuits/models/client_info.php';
  12. include_once 'apps/circuits/models/oscars_reservation.php';
  13. include_once 'apps/aaa/models/user_info.php';
  14. include_once 'apps/bpm/models/request_info.php';
  15. include_once 'apps/topology/models/domain_info.php';
  16. include_once 'apps/topology/models/topology.php';
  17. include_once 'libs/nuSOAP/lib/nusoap.php';
  18. class reservations extends Controller {
  19. public function reservations() {
  20. $this->app = 'circuits';
  21. $this->controller = 'reservations';
  22. $this->defaultAction = 'show';
  23. parent::__construct();
  24. }
  25. public function show($filterArray=array()) {
  26. // inicializa variável de sessão
  27. Common::destroySessionVariable('res_begin_timestamp');
  28. $res_info = new reservation_info();
  29. if ($filterArray)
  30. $res_info->res_id = $filterArray;
  31. $allResevartionsToShow = $res_info->fetch();
  32. //$allResevartionsToShow = $res_info->getReservationsToShow($filterArray);
  33. if ($allResevartionsToShow) {
  34. $reservations = array();
  35. $src_domains = array();
  36. foreach ($allResevartionsToShow as $r) {
  37. $res = new stdClass();
  38. $res->id = $r->res_id;
  39. $res->name = $r->res_name;
  40. $res->bandwidth = $r->bandwidth;
  41. $status_obj = $r->getStatus();
  42. $res->original_status = $status_obj->original_status;
  43. $res->status = $status_obj->status;
  44. $flow = new flow_info();
  45. $flow->flw_id = $r->flw_id;
  46. $res->flow = $flow->getFlowDetails(false);
  47. $timer = new timer_info();
  48. $timer->tmr_id = $r->tmr_id;
  49. $res->timer = $timer->getTimerDetails();
  50. /*
  51. $user = new user_info();
  52. $user->usr_id = $r->usr_id;
  53. $res->usr_login = $user->get('usr_login', FALSE);
  54. */
  55. $dom = new domain_info();
  56. if ($domain = $dom->getOSCARSDomain($res->flow->source->urn)) {
  57. $res->flow->source->domain = $domain->dom_descr;
  58. $res->flow->source->dom_id = $domain->dom_id;
  59. $src_domains[] = $domain->dom_id;
  60. } else {
  61. $urn = new urn_info();
  62. $urn->urn_string = $res->flow->source->urn;
  63. $urn_id = $urn->get('urn_id',FALSE);
  64. $urn_aco = new Acos($urn_id, "urn_info");
  65. $dev_aco = $urn_aco->getParentNodes();
  66. $net_aco = $dev_aco[0]->getParentNodes();
  67. $dom_aco = $net_aco[0]->getParentNodes();
  68. $dom = new domain_info();
  69. $dom->dom_id = $dom_aco[0]->obj_id;
  70. $res->flow->source->domain = $dom->get('dom_descr');
  71. $res->flow->source->dom_id = $dom->get('dom_id');
  72. $src_domains[] = $dom_aco[0]->obj_id;
  73. }
  74. $dom = new domain_info();
  75. if ($domain = $dom->getOSCARSDomain($res->flow->dest->urn)) {
  76. $res->flow->dest->domain = $domain->dom_descr;
  77. } else {
  78. $urn = new urn_info();
  79. $urn->urn_string = $res->flow->dest->urn;
  80. $urn_id = $urn->get('urn_id',FALSE);
  81. $urn_aco = new Acos($urn_id, "urn_info");
  82. $dev_aco = $urn_aco->getParentNodes();
  83. $net_aco = $dev_aco[0]->getParentNodes();
  84. $dom_aco = $net_aco[0]->getParentNodes();
  85. $dom = new domain_info();
  86. $dom->dom_id = $dom_aco[0]->obj_id;
  87. $res->flow->dest->domain = $dom->get('dom_descr');
  88. }
  89. $reservations[] = $res;
  90. }
  91. if ($this->action == "status") {
  92. $domains_to_js = array_unique($src_domains);
  93. $this->setArgsToScript(array(
  94. 'domains' => $domains_to_js,
  95. 'str_error_refresh_status' => _("Error to get status")
  96. ));
  97. $this->addScriptForLayout(array('reservations', 'reservations_status'));
  98. }
  99. $this->set(array(
  100. 'reservations' => $reservations,
  101. 'refresh' => ($this->action == 'status') ? 1 : 0
  102. ));
  103. $this->render('show');
  104. } else {
  105. $args = new stdClass();
  106. $args->title = ($this->action == 'status') ? _("Active and pending reservations") : _("History reservations");
  107. $args->message = ($this->action == 'status') ? _("You have no active or pending reservation, try <a href='history'>history</a> or click the button below to create a <a href='add'>new</a> one")
  108. : _("You have no reservation in history, click the button below to create a <a href='add'>new</a> one");
  109. $args->link = array("action" => "add");
  110. $this->setArgsToBody($args);
  111. $this->render('empty');
  112. }
  113. }
  114. public function status() {
  115. $gri = new gri_info();
  116. $resIdArray = $gri->getStatusResId();
  117. $this->action = "status";
  118. $this->show($resIdArray);
  119. }
  120. public function history() {
  121. $gri = new gri_info();
  122. $resIdArray = $gri->getHistoryResId();
  123. $this->action = "history";
  124. $this->show($resIdArray);
  125. }
  126. public function refresh_status() {
  127. $dom_id = Common::POST('dom_id');
  128. $gris = new gri_info();
  129. $resToRefresh = $gris->getStatusResId($dom_id);
  130. //debug("res array to refresh",$resToRefresh);
  131. $res_info = new reservation_info();
  132. $res_info->res_id = $resToRefresh;
  133. $reservations = $res_info->fetch();
  134. //$reservations = $res_info->getReservationsToShow($resToRefresh);
  135. //debug("res to refresh",$reservations);
  136. /**
  137. * Transforma a lista bidimensional de gris para uma lista unidimensional -> para realizar uma só consulta ao OSCARS
  138. * Preenche vetor griList
  139. */
  140. $griList = array();
  141. if ($reservations) {
  142. foreach ($reservations as $res) {
  143. $gri = new gri_info();
  144. $gri->res_id = $res->res_id;
  145. $gri->dom_id = $dom_id;
  146. $gris = $gri->fetch(FALSE);
  147. if ($gris) {
  148. foreach ($gris as $g) {
  149. $griList[] = $g->gri_descr;
  150. }
  151. }
  152. }
  153. } else {
  154. Log::write('debug', "Falha ao buscar reservas no refresh status");
  155. return $this->renderJson(FALSE);
  156. }
  157. /**
  158. * Realiza a consulta com o vetor preenchido
  159. */
  160. $statusResult = array();
  161. if ($griList) {
  162. $dom = new domain_info();
  163. $dom->dom_id = $dom_id;
  164. $idc_url = $dom->get('idc_url',false);
  165. Log::write('debug', "gri list ro refresh:\n" . print_r($griList,true));
  166. //$oscarsRes = new OSCARSReservation(); // OLD DESIGN
  167. $versTest = new OSCARSVersionTester($dom->getDomVersion()); // Added by Jeremy
  168. $oscarsRes = $versTest->checkVersion(); // NEW DESIGN -- Added by Jeremy
  169. $oscarsRes->setOscarsUrl($idc_url);
  170. $oscarsRes->setGrisString($griList);
  171. if ($oscarsRes->listReservations()) {
  172. $statusResult = $oscarsRes->getStatusArray();
  173. } else {
  174. Log::write('debug', "Falha ao conectar OSCARS ($idc_url) no refresh status");
  175. return $this->renderJson(FALSE);
  176. }
  177. }
  178. if (count($statusResult) != count($griList)) {
  179. Log::write('debug', "Problema de consistencia na refresh status " . print_r($statusResult, true));
  180. return $this->renderJson(FALSE);
  181. }
  182. //Log::write('debug', "refresh status result:\n" . print_r($statusResult,true));
  183. /**
  184. * Atualiza no banco os status que mudaram
  185. * Recalcula novo status para cada reserva
  186. */
  187. $cont = 0;
  188. $statusList = array();
  189. foreach ($reservations as $res) {
  190. $gri = new gri_info();
  191. $gri->res_id = $res->res_id;
  192. $gris = $gri->fetch(FALSE);
  193. if ($gris) {
  194. foreach ($gris as $g) {
  195. // testa se status atual da GRI é diferente do status que retornou do OSCARS
  196. if ($statusResult[$cont] != $g->status) {
  197. // atualiza o banco de dados com o novo status (retornado do OSCARS)
  198. $gri_tmp = new gri_info();
  199. $gri_tmp->gri_id = $g->gri_id;
  200. $gri_tmp->updateTo(array('status' => $statusResult[$cont]), FALSE);
  201. }
  202. $cont++;
  203. }
  204. }
  205. /**
  206. * recalcula novo status
  207. * @todo algum tipo de cache para não executar getStatus toda vez
  208. */
  209. $status = $res->getStatus();
  210. $status_obj = new stdClass();
  211. $status_obj->id = $res->res_id;
  212. $status_obj->original_status = $status->original_status;
  213. $status_obj->status = $status->status;
  214. $statusList[] = $status_obj;
  215. }
  216. $this->renderJson($statusList);
  217. }
  218. public function gri_refresh_status() {
  219. $res_id = Common::POST("res_id");
  220. $gri = new gri_info();
  221. $gri->res_id = $res_id;
  222. $gris = $gri->fetch(FALSE);
  223. if ($gris)
  224. {
  225. $statusList = array();
  226. // testa se tem requisição, se tem, então mostra o status do ODE
  227. $req = new request_info();
  228. $req->resource_id = $res_id;
  229. $req->resource_type = 'reservation_info';
  230. $req->answerable = 'no';
  231. //Log::write("debug","res req".print_r($req,true));
  232. $request = $req->fetch(false);
  233. //Log::write("debug","request".print_r($request,true));
  234. if ($request && $request[0]->response != 'accept')
  235. {
  236. // show request status
  237. // a reserva possui requisição
  238. foreach ($gris as $g)
  239. {
  240. $status_obj = new stdClass();
  241. $status_obj->id = $g->gri_id;
  242. if ($request[0]->response == 'reject')
  243. {
  244. // reservation request was denied
  245. $status_obj->status = gri_info::translateStatus('REJECTED');
  246. $status_obj->original_status = 'REJECTED';
  247. }
  248. else
  249. {
  250. // reservation request is pending
  251. $status = ($request[0]->status) ? $request[0]->status : "UNKNOWN";
  252. $status_obj->status = gri_info::translateStatus($status);
  253. $status_obj->original_status = "REQ_PENDING";
  254. }
  255. $statusList[] = $status_obj;
  256. }
  257. }
  258. else
  259. {
  260. // show GRI status
  261. // consulta o OSCARS
  262. $control = array();
  263. $griList = array();
  264. $ind = 0;
  265. foreach ($gris as $g) {
  266. switch ($g->status) {
  267. case "FINISHED":
  268. case "CANCELLED":
  269. case "FAILED":
  270. $control[$ind] = FALSE;
  271. break;
  272. default:
  273. $griList[] = $g->gri_descr;
  274. $control[$ind] = TRUE;
  275. }
  276. $ind++;
  277. }
  278. if ($griList) {
  279. $dom = new domain_info();
  280. $dom->dom_id = $gris[0]->dom_id;
  281. $idc_url = $dom->get('idc_url');
  282. //$oscarsRes = new OSCARSReservation(); // OLD DESIGN
  283. $versTest = new OSCARSVersionTester($dom->getDomVersion()); // Added by Jeremy
  284. $oscarsRes = $versTest->checkVersion(); // NEW DESIGN -- Added by Jeremy
  285. $oscarsRes->setOscarsUrl($idc_url);
  286. $oscarsRes->setGrisString($griList);
  287. if ($oscarsRes->listReservations()) {
  288. $statusResult = $oscarsRes->getStatusArray();
  289. } else {
  290. Log::write("error", "Failed to connect to OSCARS in refresh status");
  291. return $this->renderJson(FALSE);
  292. }
  293. $ind = 0;
  294. $cont = 0;
  295. foreach ($gris as $g)
  296. {
  297. if ($control[$ind])
  298. {
  299. // se posição no control for TRUE, é porque atualizou o status
  300. $newStatus = $statusResult[$cont];
  301. $cont++;
  302. // testa se status atual da GRI é diferente do status que retornou do OSCARS
  303. if ($g->status != $newStatus)
  304. {
  305. $g->status = $newStatus;
  306. // atualiza o banco de dados com o novo status (retornado do OSCARS)
  307. $gri_tmp = new gri_info();
  308. $gri_tmp->gri_id = $g->gri_id;
  309. $gri_tmp->updateTo(array('status' => $newStatus), FALSE);
  310. }
  311. }
  312. $status_obj = new stdClass();
  313. $status_obj->id = $g->gri_id;
  314. $status_obj->original_status = $g->status;
  315. $status_obj->status = gri_info::translateStatus($g->status);
  316. $statusList[] = $status_obj;
  317. $ind++;
  318. }
  319. }
  320. }
  321. $this->renderJson($statusList);
  322. } else {
  323. Log::write("error", "Fail to get GRIs in refresh status");
  324. $this->renderJson(FALSE);
  325. }
  326. }
  327. public function add_form() {
  328. $this->add();
  329. }
  330. public function add() {
  331. // get Timestamp to calc reservation creation time by user
  332. Common::setSessionVariable("res_begin_timestamp", microtime(true));
  333. // STEP 1 VARIABLES ---------------------
  334. //$name = "Default_reservation_name";
  335. //---------------------------------------
  336. // STEP 2 VARIABLES ---------------------
  337. $domain = new domain_info();
  338. $allDomains = $domain->fetch(FALSE);
  339. //$allUrns = array();
  340. $domToMapArray = array();
  341. //$domains = array();
  342. foreach ($allDomains as $d) {
  343. // $dom = new stdClass();
  344. // $dom->id = $d->dom_id;
  345. // $dom->name = $d->dom_descr;
  346. // $dom->topology_id = $d->topo_domain_id;
  347. // $domains[] = $dom;
  348. if ($networks = MeicanTopology::getURNDetails($d->dom_id)) {
  349. $domain = new stdClass();
  350. $domain->id = $d->dom_id;
  351. $domain->name = $d->dom_descr;
  352. $domain->topology_id = $d->topology_id;
  353. $before = microtime(true);
  354. $domain->networks = $networks;
  355. $domToMapArray[] = $domain;
  356. //debug("tempo", (microtime(true) - $before));
  357. //$urns_tmp = Common::arrayExtractAttr(MeicanTopology::getURNs($d->dom_id), 'urn_string');
  358. //array_push($allUrns, $urns_tmp);
  359. }
  360. }
  361. // array for autoComplete host
  362. $client = new client_info();
  363. $hostArray = array();
  364. $hostArray[] = "urn:ogf:network:domain=";
  365. if ($allClients = $client->fetch(false)) {
  366. foreach ($allClients as $c) {
  367. if ($c->alias)
  368. $hostArray[] = $c->alias;
  369. if ($c->ip_dcn)
  370. $hostArray[] = $c->ip_dcn;
  371. if ($c->ip_internet)
  372. $hostArray[] = $c->ip_internet;
  373. if ($c->mac_address)
  374. $hostArray[] = $c->mac_address;
  375. }
  376. }
  377. // --------------------------------------
  378. // STEP 3 VARIABLES ---------------
  379. $bmin = 100;
  380. $bmax = 1000;
  381. $bdiv = 100;
  382. $bwarn = 0.7;
  383. // --------------------------------
  384. // STEP 4 VARIABLES --------------------------
  385. $dateFormat = "d/m/Y";
  386. $js_dateFormat = "dd/mm/yy";
  387. //$dateFormat = "M j, Y";
  388. //$js_dateFormat = "M d, yy";
  389. $hourFormat = "H:i";
  390. //$hourFormat = "g:i a";
  391. $hoursArray = array();
  392. for ($h = 0; $h < 24; $h++) {
  393. for ($m = 0; $m < 60; $m = $m + 30) {
  394. $hour = ($h < 10) ? "0$h" : $h;
  395. $min = ($m < 10) ? "0$m" : $m;
  396. $hoursArray[] = "$hour:$min";
  397. }
  398. }
  399. $today_check = DayofWeek();
  400. $lang = explode(".", Language::getLang());
  401. $js_lang = str_replace("_", "-", $lang[0]);
  402. // --------------------------------------------
  403. //if ($domToMapArray) {
  404. // Args to Script
  405. $this->setArgsToScript(array(
  406. // bandwidth
  407. "band_min" => $bmin,
  408. "band_max" => $bmax,
  409. "band_div" => $bdiv,
  410. "band_warning" => $bwarn,
  411. "warning_string" => _("Authorization from Network Administrator will be required."),
  412. // flash messages
  413. "flash_nameReq" => _("A name is required"),
  414. "flash_bandInv" => _("Invalid value for bandwidth"),
  415. "flash_sourceReq" => _("A source is required"),
  416. "flash_srcVlanInv" => _("Invalid value for source VLAN"),
  417. "flash_srcVlanReq" => _("Source VLAN type required"),
  418. "flash_destReq" => _("A destination is required"),
  419. "flash_dstVlanInv" => _("Invalid value for destination VLAN"),
  420. "flash_dstVlanReq" => _("Destination VLAN type required"),
  421. "flash_timerReq" => _("Timer is required"),
  422. "flash_timerInvalid" => _("The end time occurs before the start time"),
  423. "flash_invalidDuration" => _("Invalid duration"),
  424. "flash_missingEndpoints" => _("Missing endpoints"),
  425. "flash_sameSrcDst" => _("Source and destination endpoints cannot be the same"),
  426. "flash_couldNotGetHost" => _("Could not get host"),
  427. "flash_domainNotFound" => _("Domain not found"),
  428. "flash_deviceNotFound" => _("Device not found"),
  429. "flash_portNotFound" => _("Port not found"),
  430. "flash_pointNotSet" => _("Could not set point, probably there is not enough parameters"),
  431. "flash_deviceNotSet" => _("Device not set"),
  432. "flash_portNotSet" => _("Port not set"),
  433. "flash_pointCannotBeSource" => _("The point specified cannot be set as source"),
  434. "flash_deviceCannotBeSource" => _("Device cannot be set as source"),
  435. "flash_portCannotBeSource" => _("Port cannot be set as source"),
  436. // endpoints
  437. "domain_string" => _("Domain"),
  438. "domains_string" => _("Domains"),
  439. "network_string" => _("Network"),
  440. "networks_string" => _("Networks"),
  441. "device_string" => _("Device"),
  442. "devices_string" => _("Devices"),
  443. "from_here_string" => _("From here"),
  444. "to_here_string" => _("To here"),
  445. "cluster_information_string" => _("Information about cluster"),
  446. "coordinates_string" => _("Coordinates"),
  447. "any_string" => _("any"),
  448. "value_string" => _("Value"),
  449. "ok_string" => _("Ok"),
  450. "cancel_string" => _("Cancel"),
  451. // timers
  452. "date_format" => $js_dateFormat,
  453. "language" => $js_lang,
  454. "horas" => $hoursArray,
  455. "today" => $today_check,
  456. "repeat_every_string" => _("Repeat every"),
  457. "day_string" => _("day"),
  458. "days_string" => _("days"),
  459. "week_string" => _("week"),
  460. "weeks_string" => _("weeks"),
  461. "on_string" => _("on"),
  462. "month_string" => _("month"),
  463. "months_string" => _("months"),
  464. "year_string" => _("year"),
  465. "years_string" => _("years"),
  466. "hour_string" => _("hour"),
  467. "hours_string" => _("hours"),
  468. "minute_string" => _("minute"),
  469. "minutes_string" => _("minutes"),
  470. "and_string" => _("and"),
  471. "until_string" => _("until"),
  472. "times_string" => _("times"),
  473. "time_string" => _("time"),
  474. "end_rule_string" => _("Please set an end rule"),
  475. "select_day_string" => _("Select at least one day"),
  476. "set_name_string" => _("Set name"),
  477. "invalid_time_string" => _("Invalid time"),
  478. "active_string" => _("Active from"),
  479. "at_string" => _("at"),
  480. "reset_zoom" => _("Reset Zoom"),
  481. "any_string" => _("any"),
  482. "domains" => $domToMapArray,
  483. "hosts" => $hostArray
  484. //"urn_string" => $allUrns
  485. ));
  486. //}
  487. // ARGS to body ----------------------------------------------------------------
  488. $args = new stdClass();
  489. // arg name
  490. //$args->name = $name;
  491. // arg endpoints
  492. //$args->domains = $domains;
  493. // arg bandwidth
  494. //$args->bandwidthTip = "(" . $min . ", " . ($min + $div) . ", " . ($min + 2 * $div) . ", " . ($min + 3 * $div) . ", ... , " . $max . ")";
  495. // arg timer
  496. $args->start_date = date($dateFormat);
  497. $args->finish_date = date($dateFormat);
  498. $args->start_time = date($hourFormat, (time() + 30 * 60));
  499. $args->finish_time = date($hourFormat, (time() + 90 * 60));
  500. $this->setArgsToBody($args);
  501. // -----------------------------------------------------------------------------
  502. // SCRIPTS -----------------------------------------
  503. $this->addScriptForLayout(array(/*'googlemaps', 'StyledMarker', 'reservations', 'reservation_map', 'flows',*/'markerClusterer', 'timers', 'jquery.timePicker', 'reservations_add'/*, 'map_init'*/));
  504. if ($js_lang != "en-US") {
  505. $this->addScript("jquery.ui.datepicker-$js_lang");
  506. }
  507. $this->render('add');
  508. }
  509. public function selectThisHost() {
  510. $endpointObj = client_info::getBestEndpoint($_SERVER['REMOTE_ADDR']);
  511. $this->renderJson($endpointObj);
  512. }
  513. public function chooseHost() {
  514. $endpointObj = client_info::getBestEndpoint(Common::POST('edp_reference'));
  515. $this->renderJson($endpointObj);
  516. }
  517. public function submit() {
  518. $res_end_timestamp = microtime(true);
  519. $res_begin_timestamp = Common::getSessionVariable("res_begin_timestamp");
  520. $res_diff_timestamp = $res_end_timestamp - $res_begin_timestamp;
  521. Log::write("circuits", "Reservation data POST".print_r($_POST,TRUE));
  522. /**
  523. * insere o flow
  524. */
  525. $flow_cont = new flows();
  526. $new_flow = $flow_cont->add();
  527. /**
  528. * insere o timer
  529. */
  530. $timer_cont = new timers();
  531. $new_timer = $timer_cont->add();
  532. if ($new_flow && $new_timer) {
  533. $reservation = new reservation_info();
  534. $reservation->res_name = Common::POST("res_name");
  535. $reservation->bandwidth = Common::POST("bandwidth");
  536. $reservation->flw_id = $new_flow->flw_id;
  537. $reservation->tmr_id = $new_timer->tmr_id;
  538. $reservation->creation_time = $res_diff_timestamp;
  539. $reservation->usr_id = AuthSystem::getUserId();
  540. } else {
  541. $this->setFlash(_('Failed to save endpoints or timer on database'), 'error');
  542. $this->show();
  543. return;
  544. }
  545. /**
  546. * 1- envia ao OSCARS como signal-xml todas as recorrências da reserva
  547. * 2- insere a tabela gri_info com send=0
  548. * 3- envia ao ode com o wsdl correspondente ao dominio origem
  549. * 4- o workflow é executado
  550. * 5- ao receber uma açao de notifyresponse, se for
  551. * 5.1- accept: atualiza o campo send=1, atualiza o status da requisicao
  552. * em aceita.
  553. * 5.2- No momento de início da reserva, o daemon executa a
  554. * função check e envia um createPath ao OSCARS.
  555. * Atualiza o status da requisição para SENT TO OSCARS.
  556. * O status dos gris agora correspondem o status da reserva no OSCARS
  557. * 5.2- reject: cancela a reserva no oscars, coloca o status da
  558. * requisicao em denied e apaga os gris do banco do MEICAN.
  559. * A reserva é finalizada.
  560. *
  561. */
  562. //buscar urn source para adicionar a reserva embaixo
  563. $urn = new urn_info();
  564. $urn->urn_string = $new_flow->src_urn_string;
  565. $src_urn = $urn->fetch(FALSE);
  566. //buscar urn destino para adicionar a reserva embaixo
  567. if ($res = $reservation->insert($src_urn[0]->urn_id, 'urn_info')) {
  568. $result = $this->send($res);
  569. switch ($result) {
  570. case 0:
  571. $res->delete();
  572. $new_flow->delete();
  573. $new_timer->delete();
  574. $this->setFlash(_('Error sending reservation to OSCARS'), 'error');
  575. $this->show();
  576. return;
  577. break;
  578. case 1:
  579. $this->setFlash(_('Reservation submitted'), 'success');
  580. break;
  581. default:
  582. $this->setFlash("$result " . _('reservations submitted'), 'success');
  583. break;
  584. }
  585. $this->view(array("res_id" => $res->res_id, "refresh" => '1'));
  586. } else {
  587. $new_flow->delete();
  588. $new_timer->delete();
  589. $this->setFlash(_('Failed to save reservation on database'), 'error');
  590. $this->show();
  591. }
  592. }
  593. public function view2($param_array){
  594. $this->view($param_array);
  595. }
  596. public function view($param_array) {
  597. $resId = NULL;
  598. $refresh = 0;
  599. if (array_key_exists('res_id', $param_array)) {
  600. $resId = $param_array['res_id'];
  601. } else {
  602. $this->setFlash(_("Invalid index"), "fatal");
  603. $this->show();
  604. return;
  605. }
  606. if (array_key_exists('refresh', $param_array))
  607. $refresh = (integer) $param_array['refresh'];
  608. $res_info = new reservation_info();
  609. $res_info->res_id = $resId;
  610. $resResult = $res_info->fetch();
  611. if (!$resResult) {
  612. $this->setFlash(_("Reservation not found"), "fatal");
  613. $this->show();
  614. return;
  615. } else {
  616. $reservation = $resResult[0];
  617. }
  618. $flow_info = new flow_info();
  619. $flow_info->flw_id = $reservation->flw_id;
  620. $flow = $flow_info->getFlowDetails();
  621. $usr_info = new user_info();
  622. $usr_info->usr_id = $reservation->usr_id;
  623. $usr_login = $usr_info->get('usr_login', FALSE);
  624. $dom = new domain_info();
  625. if ($domain = $dom->getOSCARSDomain($flow->source->urn)) {
  626. $flow->source->domain = $domain->dom_descr;
  627. } else {
  628. $urn = new urn_info();
  629. $urn->urn_string = $flow->source->urn;
  630. $urn_id = $urn->get('urn_id');
  631. $urn_aco = new Acos($urn_id, "urn_info");
  632. $dev_aco = $urn_aco->getParentNodes();
  633. $net_aco = $dev_aco[0]->getParentNodes();
  634. $dom_aco = $net_aco[0]->getParentNodes();
  635. $dom = new domain_info();
  636. $dom->dom_id = $dom_aco[0]->obj_id;
  637. $flow->source->domain = $dom->get('dom_descr');
  638. }
  639. $dom = new domain_info();
  640. if ($domain = $dom->getOSCARSDomain($flow->dest->urn)) {
  641. $flow->dest->domain = $domain->dom_descr;
  642. } else {
  643. $urn = new urn_info();
  644. $urn->urn_string = $flow->dest->urn;
  645. $urn_id = $urn->get('urn_id');
  646. $urn_aco = new Acos($urn_id, "urn_info");
  647. $dev_aco = $urn_aco->getParentNodes();
  648. $net_aco = $dev_aco[0]->getParentNodes();
  649. $dom_aco = $net_aco[0]->getParentNodes();
  650. $dom = new domain_info();
  651. $dom->dom_id = $dom_aco[0]->obj_id;
  652. $flow->dest->domain = $dom->get('dom_descr');
  653. }
  654. if ($flow->path)
  655. $flow->path = MeicanTopology::getWaypoints($flow->path);
  656. if (!$flow) {
  657. $this->setFlash(_("Flow not found or could not get endpoints information"), "fatal");
  658. $this->show();
  659. return;
  660. }
  661. $timer_info = new timer_info();
  662. $timer_info->tmr_id = $reservation->tmr_id;
  663. $timer = $timer_info->getTimerDetails();
  664. if (!$timer) {
  665. $this->setFlash(_("Timer not found"), "fatal");
  666. $this->show();
  667. return;
  668. }
  669. $req = new request_info();
  670. $req->resource_id = $reservation->res_id;
  671. $req->resource_type = 'reservation_info';
  672. $req->answerable = 'no';
  673. $request = null;
  674. if ($result = $req->fetch()) {
  675. // a reserva possui requisição
  676. $request = new stdClass();
  677. $request->response = $result[0]->response;
  678. //$request->message = $result[0]->message;
  679. $request->status = $result[0]->status;
  680. }
  681. $status = array();
  682. $gri = new gri_info();
  683. if ($gris = $gri->getGrisToView($reservation->res_id))
  684. {
  685. foreach ($gris as $g)
  686. {
  687. $stat_obj = new stdClass();
  688. $stat_obj->id = $g->id;
  689. $stat_obj->status = $g->original_status;
  690. $status[] = $stat_obj;
  691. }
  692. }
  693. $this->setArgsToScript(array(
  694. "refreshReservation" => $refresh,
  695. "reservation_id" => $reservation->res_id,
  696. "user_login" => $usr_login,
  697. "status_array" => $status,
  698. "src_lat_network" => $flow->source->latitude,
  699. "src_lng_network" => $flow->source->longitude,
  700. "dst_lat_network" => $flow->dest->latitude,
  701. "dst_lng_network" => $flow->dest->longitude,
  702. "reservation_path" => $flow->path,
  703. "domain_string" => _("Domain"),
  704. "domains_string" => _("Domains"),
  705. "network_string" => _("Network"),
  706. "networks_string" => _("Networks"),
  707. "device_string" => _("Device"),
  708. "devices_string" => _("Devices"),
  709. "from_here_string" => _("From Here"),
  710. "to_here_string" => _("To Here"),
  711. "cluster_information_string" => _("Information about cluster"),
  712. 'str_error_refresh_status' => _("Error to get status")
  713. ));
  714. $this->set(array(
  715. 'res_name' => $reservation->res_name,
  716. 'res_id' => $reservation->res_id,
  717. 'bandwidth' => $reservation->bandwidth
  718. ));
  719. $this->set(compact('gris', 'flow', 'timer',
  720. 'request', 'refresh', 'usr_login'));
  721. $this->addScriptForLayout(array('reservations', 'reservations_view'));
  722. $this->render('view');
  723. }
  724. /**
  725. * @todo Cancelar reservas no OSCARS (ativas e pendentes) antes de excluir do banco
  726. */
  727. public function delete($param_array) {
  728. if (array_key_exists('refresh', $param_array))
  729. $refresh = (integer) $param_array['refresh'];
  730. $del_reservations = Common::POST("del_checkbox");
  731. if ($del_reservations) {
  732. foreach ($del_reservations as $resId) {
  733. $gris_to_cancel = array();
  734. $reservation = new reservation_info();
  735. $reservation->res_id = $resId;
  736. $gri = new gri_info();
  737. $gri->res_id = $resId;
  738. if ($gris = $gri->fetch(FALSE)) {
  739. foreach ($gris as $g) {
  740. $g->delete(FALSE);
  741. //$gris_to_cancel[] = $g->gri_descr;
  742. }
  743. }
  744. if ($tmp = $reservation->fetch()) {
  745. $result = $tmp[0];
  746. $flow = new flow_info();
  747. $flow->flw_id = $result->flw_id;
  748. $flow->delete();
  749. $timer = new timer_info();
  750. $timer->tmr_id = $result->tmr_id;
  751. $timer->delete();
  752. //if ($client->cancel($gris_to_cancel)) {
  753. if ($reservation->delete())
  754. $this->setFlash(_("Reservation") . " '$result->res_name' " . _("deleted"), 'success');
  755. //} else
  756. //$this->setFlash(_("Reservation") . " '$result->res_name' " . _("could not be cancelled"), 'error');
  757. }
  758. }
  759. }
  760. if ($refresh)
  761. $this->status();
  762. else
  763. $this->history();
  764. }
  765. function query($reservation_info) {
  766. //descobrir IP do dominio origem da reserva para enviar ao OSCARS adequado
  767. $result = $reservation_info->fetch();
  768. $res = $result[0];
  769. $flow = new flow_info();
  770. $flow->flw_id = $res->flw_id;
  771. $flw = $flow->getFlowDetails();
  772. $gri = new gri_info();
  773. $gri->res_id = $reservation_info->res_id;
  774. $gris = $gri->fetch();
  775. foreach ($gris as $g) {
  776. //$oscarsRes = new OSCARSReservation(); // OLD DESIGN
  777. $versTest = new OSCARSVersionTester($dom->getDomVersion()); // Added by Jeremy
  778. $oscarsRes = $versTest->checkVersion(); // NEW DESIGN -- Added by Jeremy
  779. $oscarsRes->setOscarsUrl($flw->source->idc_url);
  780. $oscarsRes->setGri($g->gri_descr);
  781. $oscarsRes->queryReservation();
  782. unset($oscarsRes);
  783. }
  784. }
  785. public function cancel($param_array) {
  786. $cancel_gris = Common::POST('cancel_checkbox');
  787. $gri = new gri_info();
  788. $gri->gri_id = $cancel_gris;
  789. $gris = $gri->fetch(FALSE);
  790. $cont = 0;
  791. if ($gris) {
  792. $dom = new domain_info();
  793. $dom->dom_id = $gris[0]->dom_id;
  794. if ($idc_url = $dom->get('idc_url')) {
  795. foreach ($gris as $g)
  796. {
  797. if ($g->status == "ACTIVE" || $g->status == "PENDING" || $g->status == "ACCEPTED")
  798. {
  799. //$oscarsRes = new OSCARSReservation(); // OLD DESIGN
  800. $versTest = new OSCARSVersionTester($dom->getDomVersion()); // Added by Jeremy
  801. $oscarsRes = $versTest->checkVersion(); // NEW DESIGN -- Added by Jeremy
  802. $oscarsRes->setOscarsUrl($idc_url);
  803. $oscarsRes->setGri($g->gri_descr);
  804. Log::write("info", "GRI to cancel: ".print_r($g->gri_descr, TRUE));
  805. /**
  806. * @todo cancelar várias reservas de uma só vez
  807. */
  808. if ($oscarsRes->cancelReservation()) {
  809. $cont++;
  810. $status_ret = $oscarsRes->getStatus();
  811. if ($status_ret != $g->status) {
  812. $gri_tmp = new gri_info();
  813. $gri_tmp->gri_id = $g->gri_id;
  814. $gri->updateTo(array('status' => $status_ret), FALSE);
  815. }
  816. }
  817. }
  818. }
  819. }
  820. }
  821. switch ($cont) {
  822. case 0:
  823. $this->setFlash(_("No reservation was cancelled"), "warning");
  824. break;
  825. case 1:
  826. $this->setFlash(_("One reservation was cancelled"), "success");
  827. break;
  828. default:
  829. $this->setFlash("$cont " . _("reservations were cancelled"), "success");
  830. break;
  831. }
  832. sleep(3);
  833. $this->view($param_array);
  834. }
  835. function listStatus($grisArray) {
  836. $dom = new domain_info();
  837. $src_dom = $dom->getOSCARSDomain($src_urn_string);
  838. //$oscarsRes = new OSCARSReservation(); // OLD DESIGN
  839. $versTest = new OSCARSVersionTester($dom->getDomVersion()); // Added by Jeremy
  840. $oscarsRes = $versTest->checkVersion(); // NEW DESIGN -- Added by Jeremy
  841. //$oscarsRes->setOscarsUrl("200.132.1.28:8080"); //oscars2
  842. $oscarsRes->setOscarsUrl($src_dom->idc_url);
  843. $oscarsRes->setGrisString($grisArray);
  844. $result = $oscarsRes->listReservations();
  845. debug("result do list", $result);
  846. }
  847. function send($reservation_info) {
  848. Log::write("circuits", "Reservation to be sent:\n".print_r($reservation_info,TRUE));
  849. $flow_info = new flow_info();
  850. $flow_info->flw_id = $reservation_info->flw_id;
  851. $flow_res = $flow_info->fetch();
  852. $flow = $flow_res[0];
  853. $src_urn_string = $flow->src_urn_string;
  854. $domain = new domain_info();
  855. $src_dom = $domain->getOSCARSDomain($src_urn_string);
  856. //$oscarsRes = new OSCARSReservation(); // OLD DESIGN
  857. $versTest = new OSCARSVersionTester($domain->getDomVersion()); // Added by Jeremy
  858. $oscarsRes = $versTest->checkVersion(); // NEW DESIGN -- Added by Jeremy
  859. $oscarsRes->setOscarsUrl($src_dom->idc_url);
  860. $oscarsRes->setDescription($reservation_info->res_name);
  861. $oscarsRes->setBandwidth($reservation_info->bandwidth);
  862. $oscarsRes->setSrcEndpoint($flow->src_urn_string);
  863. $oscarsRes->setDestEndpoint($flow->dst_urn_string);
  864. if ($path = $flow->path)
  865. $oscarsRes->setPath($path);
  866. if ($flow->src_vlan !== null) {
  867. $flow->src_vlan = (integer) $flow->src_vlan;
  868. if ($flow->src_vlan === 0)
  869. $oscarsRes->setSrcIsTagged(false);
  870. else {
  871. $oscarsRes->setSrcIsTagged(true);
  872. $oscarsRes->setSrcTag($flow->src_vlan);
  873. }
  874. }
  875. if ($flow->dst_vlan !== null) {
  876. $flow->dst_vlan = (integer) $flow->dst_vlan;
  877. if ($flow->dst_vlan === 0)
  878. $oscarsRes->setDestIsTagged(false);
  879. else {
  880. $oscarsRes->setDestIsTagged(true);
  881. $oscarsRes->setDestTag($flow->dst_vlan);
  882. }
  883. }
  884. //precisa descobrir se a reserva deve ou não ser enviada para AUTORIZAÇÃO
  885. if ($src_dom->ode_ip && $src_dom->ode_wsdl_path && $src_dom->ode_start) {
  886. //irá para autorização
  887. //cria reserva do tipo signal-xml
  888. $oscarsRes->setPathSetupMode('timer-automatic');
  889. } else
  890. $oscarsRes->setPathSetupMode('timer-automatic');
  891. $tim = new timer_info();
  892. $tim->tmr_id = $reservation_info->tmr_id;
  893. $timer = $tim->get();
  894. $arrayRec = $timer->getRecurrences();
  895. $resSent = 0;
  896. foreach ($arrayRec as $t) {
  897. $tmp = $oscarsRes;
  898. $tmp->setStartTimestamp($t->start); //em timestamp
  899. $tmp->setEndTimestamp($t->finish);
  900. Log::write("circuits", "Sending reservation:\n".print_r($tmp,TRUE));
  901. if ($tmp->createReservation()) {
  902. $resSent++;
  903. $new_gri = new gri_info();
  904. $new_gri->gri_descr = $tmp->getGri();
  905. $new_gri->status = $tmp->getStatus();
  906. $new_gri->res_id = $reservation_info->res_id;
  907. $new_gri->dom_id = $src_dom->dom_id;
  908. $date = new DateTime();
  909. $date->setTimestamp($t->start);
  910. $new_gri->start = $date->format('Y-m-d H:i');
  911. $date->setTimestamp($t->finish);
  912. $new_gri->finish = $date->format('Y-m-d H:i');
  913. $new_gri->send = "0"; //para as reservas sem autorização do tipo
  914. //timer-automatic o daemon nao precisa enviar o createPath
  915. $new_gri->insert();
  916. }
  917. unset($tmp);
  918. }
  919. //para buscar o dst_ode_ip
  920. $dst_urn_string = $flow->dst_urn_string;
  921. $domain = new domain_info();
  922. $dst_dom = $domain->getOSCARSDomain($dst_urn_string);
  923. if ($resSent && $src_dom->ode_ip && $src_dom->ode_wsdl_path && $src_dom->ode_start && $dst_dom->ode_ip) {
  924. //cria nova request com o domínio $src_dom
  925. $newReq = new request_info();
  926. $newReq->req_id = $newReq->getNextId('req_id');
  927. $newReq->src_ode_ip = $src_dom->ode_ip;
  928. $newReq->src_usr = $reservation_info->usr_id;
  929. $newReq->dst_ode_ip = $dst_dom->ode_ip;
  930. $newReq->resource_type = 'reservation_info';
  931. $newReq->resource_id = $reservation_info->res_id;
  932. $newReq->answerable = 'no';
  933. $newReq->response = NULL;
  934. $newReq->message = NULL;
  935. $newReq->crr_ode_ip = NULL;
  936. $newReq->response_user = NULL;
  937. $newReq->start_time = NULL;
  938. $newReq->finish_time = NULL;
  939. $requestSOAP = array(
  940. 'req_id' => $newReq->req_id,
  941. 'src_ode_ip' => $newReq->src_ode_ip,
  942. 'dst_ode_ip' => $newReq->dst_ode_ip,
  943. 'usr_src' => $newReq->src_usr);
  944. Log::write("circuits","Sending for authorization:\n". print_r($requestSOAP,TRUE));
  945. try {
  946. $client = new SoapClient($src_dom->ode_wsdl_path, array('cache_wsdl' => WSDL_CACHE_NONE));
  947. $client->{$src_dom->ode_start}($requestSOAP);
  948. //$client->__soapCall($src_dom->ode_start, $requestSOAP);
  949. $newReq->status = 'SENT FOR AUTHORIZATION';
  950. if ($newReq->insert())
  951. return $resSent;
  952. else {
  953. Log::write("error", "Failed to save request");
  954. return FALSE;
  955. }
  956. } catch (Exception $e) {
  957. Log::write("error", "Caught exception while trying to connect to ODE:\n". print_r($e->getMessage()));
  958. $this->setFlash("error", _('Error at invoking business layer.'));
  959. $newReq->status = 'SENT FOR AUTHORIZATION';
  960. $newReq->insert();
  961. return FALSE;
  962. }
  963. } else
  964. return $resSent;
  965. }
  966. public function check() {
  967. $this->autoRender = false;
  968. Log::write("debug", "check chegou no controller");
  969. $gris = gri_info::getGrisToCreatePath();
  970. Log::write("debug", print_r($gris, true));
  971. if ($gris) {
  972. foreach ($gris as $g) {
  973. $dom = new domain_info();
  974. $dom->dom_id = $g->dom_id;
  975. $domain = $dom->fetch(false);
  976. //$oscars_reservation = new OSCARSReservation(); // OLD DESIGN
  977. $versTest = new OSCARSVersionTester($dom->getDomVersion()); // Added by Jeremy
  978. $oscars_reservation = $versTest->checkVersion(); // NEW DESIGN -- Added by Jeremy
  979. $oscars_reservation->setOscarsUrl($domain[0]->idc_url);
  980. $oscars_reservation->setGri($g->gri_descr);
  981. Log::write("debug","oscars res class\n".print_r($oscars_reservation,true));
  982. //if (true) {
  983. if ($oscars_reservation->createPath()) {
  984. Log::write("debug","Create path successful\n".print_r($g,true));
  985. $status = $oscars_reservation->getStatus();
  986. //$status="INCREATE";
  987. $g->updateTo(array("send" => "0", "status" => $status), false);
  988. }
  989. }
  990. }
  991. }
  992. }
  993. ?>