static function makeHtml($notification = null) { if ($notification == null) { return ""; } $auth_id = $notification->info; if ($auth_id == null) { return ""; } $auth = ConnectionAuth::findOne($auth_id); if (!$auth) { return ""; } $connection = Connection::findOne($auth->connection_id); $source = ConnectionPath::findOne(['conn_id' => $connection->id, 'path_order' => 0])->domain; $path_order = ConnectionPath::find()->where(['conn_id' => $connection->id])->count() - 1; $destination = ConnectionPath::findOne(['conn_id' => $connection->id, 'path_order' => $path_order])->domain; $reservation = Reservation::findOne($connection->reservation_id); $title = Yii::t("notify", 'Pending authorization'); $msg = Yii::t("notify", 'The connection is from') . " <b>" . $source . "</b> " . Yii::t("notify", 'to') . " <b>" . $destination . "</b>"; $msg .= ". " . Yii::t("notify", 'The request bandwidth is') . " " . $reservation->bandwidth . " Mbps."; $date = Yii::$app->formatter->asDatetime($notification->date); $link = '/circuits/authorization/answer?id=' . $reservation->id . '&domain=' . $auth->domain; $html = Notification::makeHtml('pending_authorization.png', $date, $title, $msg, $link); if ($notification->viewed == true) { return '<li>' . $html . '</li>'; } return '<li class="notification_new">' . $html . '</li>'; }
public function __construct($reservation, $connection_id, $domain) { $this->reservation_id = $reservation->id; $this->reservation_name = $reservation->name; $path = ConnectionPath::findOne(['conn_id' => $connection_id, 'path_order' => 0]); if ($path) { $this->source_domain = $path->domain; } else { $this->source_domain = Yii::t('circuits', 'deleted'); } $path = ConnectionPath::find()->where(['conn_id' => $connection_id])->orderBy("path_order DESC")->one(); if ($path) { $this->destination_domain = $path->domain; } else { $this->destination_domain = Yii::t('circuits', 'deleted'); } $user = User::findOne(['id' => $reservation->request_user_id]); if ($user) { $this->requester = $user->name; } $this->bandwidth = $reservation->bandwidth . " Mbps"; $paths_domain = ConnectionPath::find()->where(['conn_id' => $connection_id, 'domain' => $domain])->orderBy("path_order ASC")->all(); $this->port_in = $paths_domain[0]->port_urn; $this->port_out = $paths_domain[count($paths_domain) - 1]->port_urn; }
static function makeHtml($notification = null) { if ($notification == null) { return ""; } $reservation = Reservation::findOne($notification->info); if (!$reservation) { return ""; } $connection = Connection::find()->where(['reservation_id' => $reservation->id])->one(); $source = ConnectionPath::findOne(['conn_id' => $connection->id, 'path_order' => 0])->domain; $path_order = ConnectionPath::find()->where(['conn_id' => $connection->id])->count() - 1; $destination = ConnectionPath::findOne(['conn_id' => $connection->id, 'path_order' => $path_order])->domain; $title = Yii::t("notify", 'Reservation') . " (" . $reservation->name . ")"; $connections = Connection::find()->where(['reservation_id' => $reservation->id])->all(); //Se possui apenas uma conexão, então pode informar diretamente se foi aceito ou negado if (count($connections) < 2) { $msg = Yii::t("notify", 'The connection between') . " <b>" . $source . " </b>" . Yii::t("notify", 'and') . " <b>" . $destination . "</b> "; $date = Yii::$app->formatter->asDatetime($notification->date); $link = '/circuits/reservation/view?id=' . $reservation->id; if ($connections[0]->status == Connection::STATUS_FAILED_CREATE || $connections[0]->status == Connection::STATUS_FAILED_CONFIRM || $connections[0]->status == Connection::STATUS_FAILED_SUBMIT || $connections[0]->status == Connection::STATUS_FAILED_PROVISION || $connections[0]->status == Connection::STATUS_CANCELLED || $connections[0]->status == Connection::STATUS_CANCEL_REQ || $connections[0]->auth_status == Connection::AUTH_STATUS_REJECTED || $connections[0]->auth_status == Connection::AUTH_STATUS_EXPIRED) { $msg .= " " . Yii::t("notify", 'can not be provisioned.'); $html = Notification::makeHtml('circuit_reject.png', $date, $title, $msg, $link); } else { $msg .= " " . Yii::t("notify", 'was provisioned.'); $html = Notification::makeHtml('circuit_accept.png', $date, $title, $msg, $link); } } else { //Conta o número de provisionadas, rejeitadas (aglomera todos estados em que não vai ser gerado o circuito) //e pendentes (aglomera todos estados de processamento intermediário) $provisioned = 0; $reject = 0; $pending = 0; foreach ($connections as $conn) { if ($conn->status == Connection::STATUS_PROVISIONED) { $provisioned++; } else { if ($conn->status == Connection::STATUS_FAILED_CREATE || $conn->status == Connection::STATUS_FAILED_CONFIRM || $conn->status == Connection::STATUS_FAILED_SUBMIT || $conn->status == Connection::STATUS_FAILED_PROVISION || $conn->status == Connection::STATUS_CANCELLED || $conn->status == Connection::STATUS_CANCEL_REQ || $conn->auth_status == Connection::AUTH_STATUS_REJECTED || $conn->auth_status == Connection::AUTH_STATUS_EXPIRED) { $reject++; } else { $pending++; } } } $msg = Yii::t("notify", 'The status of connections changed:') . "<br />"; $msg .= Yii::t("notify", 'Provisioned:') . " " . $provisioned . ", "; $msg .= Yii::t("notify", 'Rejected:') . " " . $reject . ", "; $msg .= Yii::t("notify", 'Pending:') . " " . $pending; $date = Yii::$app->formatter->asDatetime($notification->date); $link = '/circuits/reservation/view?id=' . $reservation->id; $html = Notification::makeHtml('circuit_changed.png', $date, $title, $msg, $link); } if ($notification->viewed == true) { return '<li>' . $html . '</li>'; } return '<li class="notification_new">' . $html . '</li>'; }
private static function saveCircuit($gri, $desc, $status, $start, $end, $bandwidth, $path) { $conn = Connection::findOne(['external_id' => $gri]); if ($conn == null) { $conn = new Connection(); $conn->external_id = $gri; $conn->name = $desc; $conn->type = 'OSCARS'; $conn->status = 'PROVISIONED'; $conn->version = 1; $conn->dataplane_status = $status == 'ACTIVE' ? 'ACTIVE' : 'INACTIVE'; $conn->auth_status = 'UNEXECUTED'; $conn->resources_status = 'PROVISIONED'; $conn->start = DateUtils::timestampToDB($start); $conn->finish = DateUtils::timestampToDB($end); $conn->bandwidth = $bandwidth; if ($conn->save()) { Yii::trace($path); for ($i = 0; $i < count($path); $i++) { $point = new ConnectionPath(); $point->conn_id = $conn->id; $point->path_order = $i; $urnArray = explode(":", $path[$i]); Yii::trace($urnArray); $point->vlan = explode('=', $urnArray[7])[1]; Yii::trace($point->vlan); $point->domain = explode('=', $urnArray[3])[1]; Yii::trace($point->domain); $urnArray[7] = ''; $urnArray[6] = ''; $point->port_urn = substr(implode(':', $urnArray), 0, -2); Yii::trace($point->port_urn); $point->save(); } OscarsService::associateNSICircuits($conn); } else { Yii::trace($conn->getErrors()); } } else { $conn->dataplane_status = $status == 'ACTIVE' ? 'ACTIVE' : 'INACTIVE'; $conn->save(); } }
public function actionGetOthers($domainTop = null, $reservationId = null, $type = null) { if ($domainTop && $reservationId && $type) { $connectionsPath = ConnectionPath::find()->select('DISTINCT `conn_id`')->where(['domain' => $domainTop])->all(); $others = []; foreach ($connectionsPath as $path) { $con = Connection::findOne(['id' => $path->conn_id]); //Tipo 1 significa que esta retornando os provisionados if ($type == 1 && $con->status == Connection::STATUS_PROVISIONED) { //Se é a mesma reserva, testa para garantir que é de outro dominio antes de exibir if ($con->reservation_id != $reservationId) { $others[] = ['id' => $con->id, 'title' => "\n" . $con->getReservation()->one()->bandwidth . " Mbps", 'start' => Yii::$app->formatter->asDatetime($con->start, "php:Y-m-d H:i:s"), 'end' => Yii::$app->formatter->asDatetime($con->finish, "php:Y-m-d H:i:s")]; } } else { if ($type == 2 && $con->status != Connection::STATUS_PROVISIONED && $con->auth_status == Connection::AUTH_STATUS_PENDING) { //Se é a mesma reserva, testa para garantir que é de outro dominio antes de exibir if ($con->reservation_id == $reservationId) { if (ConnectionAuth::findOne(['connection_id' => $con->id, 'status' => Connection::AUTH_STATUS_PENDING])->domain != $domainTop) { $others[] = ['id' => $con->id, 'title' => "\n" . $con->getReservation()->one()->bandwidth . " Mbps", 'start' => Yii::$app->formatter->asDatetime($con->start, "php:Y-m-d H:i:s"), 'end' => Yii::$app->formatter->asDatetime($con->finish, "php:Y-m-d H:i:s")]; } } else { $others[] = ['id' => $con->id, 'title' => "\n" . $con->getReservation()->one()->bandwidth . " Mbps", 'start' => Yii::$app->formatter->asDatetime($con->start, "php:Y-m-d H:i:s"), 'end' => Yii::$app->formatter->asDatetime($con->finish, "php:Y-m-d H:i:s")]; } } } } echo json_encode($others); } }
public function createConnections($events) { $paths = $this->getPaths()->all(); Yii::trace($events); for ($i = 0; $i < count($events['start']); $i++) { $conn = new Connection(); $date = new \DateTime($events['start'][$i]); $conn->start = $date->format('Y-m-d H:i'); $date = new \DateTime($events['finish'][$i]); $conn->finish = $date->format('Y-m-d H:i'); $conn->reservation_id = $this->id; $conn->status = Connection::STATUS_PENDING; $conn->dataplane_status = Connection::DATA_STATUS_INACTIVE; $conn->auth_status = Connection::AUTH_STATUS_UNEXECUTED; $conn->resources_status = Connection::RES_STATUS_RELEASED; $conn->version = 0; $conn->bandwidth = $this->bandwidth; $conn->type = Connection::TYPE_NSI; if ($conn->save()) { $k = 0; foreach ($paths as $resPath) { $connPath = new ConnectionPath(); $connPath->path_order = $k; $connPath->conn_id = $conn->id; $connPath->domain = explode(":", $resPath->port_urn)[0]; $k++; $connPath->port_urn = $resPath->port_urn; $connPath->vlan = $resPath->vlan; $connPath->save(); } } else { Yii::trace($conn->getErrors()); } } }
public function actionCancel($id) { $conn = Connection::findOne($id); $permission = false; $reservation = Reservation::findOne(['id' => $conn->reservation_id]); if (Yii::$app->user->getId() == $reservation->request_user_id) { $permission = true; } else { $domains_name = []; foreach (self::whichDomainsCan('reservation/delete') as $domain) { $domains_name[] = $domain->name; } $paths = ConnectionPath::find()->where(['in', 'domain', $domains_name])->andWhere(['conn_id' => $conn->id])->select(["conn_id"])->distinct(true)->one(); if (!empty($paths)) { $permission = true; } } if ($permission) { $conn->requestCancel(); return true; } else { return false; } }
use meican\circuits\models\ConnectionAuth; use meican\aaa\models\User; $this->params['header'] = [Yii::t('circuits', 'Pending Authorization'), ['Home', Yii::t('circuits', 'Circuits')]]; ?> <div class="box box-default"> <div class="box-body"> <?php echo Grid::widget(['options' => ['class' => 'list'], 'dataProvider' => $data, 'id' => 'gridInfo', 'filterModel' => $searchModel, 'layout' => "{items}{summary}{pager}", 'columns' => array(['label' => Yii::t('circuits', 'Reply request as '), 'value' => 'domain', 'filter' => Html::activeDropDownList($searchModel, 'domain', ArrayHelper::map(ConnectionAuth::find()->select(["domain"])->distinct(true)->orderBy(['domain' => SORT_ASC])->asArray()->all(), 'domain', 'domain'), ['class' => 'form-control', 'prompt' => Yii::t("circuits", 'any')]), 'contentOptions' => ['style' => 'font-weight: bold;'], 'headerOptions' => ['style' => 'width: 23%;']], ['label' => Yii::t('circuits', 'Source Domain'), 'value' => function ($aut) { if ($aut->source) { return $aut->source; } else { return Yii::t('circuits', 'deleted'); } }, 'filter' => Html::activeDropDownList($searchModel, 'src_domain', ArrayHelper::map(ConnectionPath::find()->select(["domain"])->distinct(true)->orderBy(['domain' => SORT_ASC])->asArray()->all(), 'domain', 'domain'), ['class' => 'form-control', 'prompt' => Yii::t("circuits", 'any')]), 'headerOptions' => ['style' => 'width: 21%;']], ['label' => Yii::t('circuits', 'Destination Domain'), 'value' => function ($aut) { if ($aut->destination) { return $aut->destination; } else { return Yii::t('circuits', 'deleted'); } }, 'filter' => Html::activeDropDownList($searchModel, 'dst_domain', ArrayHelper::map(ConnectionPath::find()->select(["domain"])->distinct(true)->orderBy(['domain' => SORT_ASC])->asArray()->all(), 'domain', 'domain'), ['class' => 'form-control', 'prompt' => Yii::t("circuits", 'any')]), 'headerOptions' => ['style' => 'width: 21%;']], ['label' => Yii::t('circuits', 'Requester'), 'value' => function ($aut) { $user_id = $aut->request_user_id; return User::findOne(['id' => $user_id])->name; }, 'headerOptions' => ['style' => 'width: 12%;']], ['label' => Yii::t('circuits', 'Bandwidth'), 'value' => function ($aut) { return $aut->bandwidth . " Mbps"; }, 'headerOptions' => ['style' => 'width: 12%;']], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{answer}', 'buttons' => ['answer' => function ($url, $model) { return Html::a(Html::button(Yii::t('circuits', 'Answer'), ['class' => 'btn btn-sm btn-primary']), ['answer', 'id' => $model->id, 'domain' => $model->domain]); }], 'headerOptions' => ['style' => 'width: 11%;']])]); ?> </div> </div>
private function updateConnectionPath($conn, $response) { //updating path //clean old points $oldPaths = $conn->getPaths()->all(); foreach ($oldPaths as $oldPath) { $oldPath->delete(); } //save new points $pathNodes = $response->reservation->criteria->children->child; if (count($pathNodes) < 2) { $pathNodes = [$pathNodes]; } Yii::trace(print_r($pathNodes, true)); $i = 0; foreach ($pathNodes as $pathNode) { Yii::trace(print_r($pathNode, true)); $pathNodeXml = $pathNode->any; $pathNodeXml = str_replace("<nsi_p2p:p2ps>", "<p2p>", $pathNodeXml); $pathNodeXml = str_replace("</nsi_p2p:p2ps>", "</p2p>", $pathNodeXml); $pathNodeXml = '<?xml version="1.0" encoding="UTF-8"?>' . $pathNodeXml; $xml = new \DOMDocument(); $xml->loadXML($pathNodeXml); $parser = new \DOMXpath($xml); $src = $parser->query("//sourceSTP"); $dst = $parser->query("//destSTP"); $path = new ConnectionPath(); $path->conn_id = $conn->id; $path->path_order = $i; $i++; $path->setPortBySTP($src->item(0)->nodeValue); $path->setDomainBySTP($src->item(0)->nodeValue); if (!$path->save()) { Yii::trace($path); return false; } $path = new ConnectionPath(); $path->conn_id = $conn->id; $path->path_order = $i; $i++; $path->setPortBySTP($dst->item(0)->nodeValue); $path->setDomainBySTP($dst->item(0)->nodeValue); if (!$path->save()) { Yii::trace($path); return false; } } return true; }
public function checkDomain($flow, $connection) { Yii::trace("Testando Domain"); switch ($flow->operator) { case 'source': $domain = ConnectionPath::findOne(['conn_id' => $connection->id, 'path_order' => 0])->domain; break; case 'previous': $cp = ConnectionPath::findOne(['conn_id' => $connection->id, 'domain' => $flow->domain]); if (!isset($cp)) { //Se dominio deletado $flow->status = self::STATUS_YES; return; } $domain = ConnectionPath::findOne(['conn_id' => $connection->id, 'path_order' => $cp->path_order - 1]); if (!isset($domain)) { //Se dominio deletado $flow->status = self::STATUS_YES; return; } $domain = $domain->domain; break; case 'next': $cp = ConnectionPath::findOne(['conn_id' => $connection->id, 'domain' => $flow->domain]); if (!isset($cp)) { //Se dominio deletado $flow->status = self::STATUS_YES; return; } $domain = ConnectionPath::findOne(['conn_id' => $connection->id, 'path_order' => $cp->path_order + 1]); if (!isset($domain)) { //Se dominio deletado $flow->status = self::STATUS_YES; return; } $domain = $domain->domain; break; case 'destination': $path_order = ConnectionPath::find()->where(['conn_id' => $connection->id])->count() - 1; $domain = ConnectionPath::findOne(['conn_id' => $connection->id, 'path_order' => $path_order])->domain; break; } if (isset($domain) && $flow->value == $domain) { $flow->status = self::STATUS_YES; } else { Yii::trace("Não passou em DOMAIN"); $flow->status = self::STATUS_NO; } }
public function searchTerminatedByDomains($params, $allowed_domains) { $validDomains = []; $this->load($params); $userId = Yii::$app->user->getId(); $domains_name = []; foreach ($allowed_domains as $domain) { $domains_name[] = $domain->name; } $connPaths = []; if ($this->src_domain && $this->dst_domain) { //if(in_array($this->src_domain, $domains_name) && in_array($this->dst_domain, $domains_name)){ $dstPaths = ConnectionPath::findBySql("\n SELECT cp1.conn_id\n FROM (\n SELECT conn_id, MAX(`path_order`) AS last_path\n FROM `meican_connection_path`\n GROUP BY `conn_id`\n ) cp2\n JOIN `meican_connection_path` cp1\n ON cp1.conn_id = cp2.conn_id AND cp1.domain = '" . $this->dst_domain . "' AND cp1.path_order = cp2.last_path")->asArray()->all(); $allowedConns = []; foreach ($dstPaths as $dstPath) { $allowedConns[] = $dstPath['conn_id']; } //filtra por conn aceitas pela query anterior $connPaths = ConnectionPath::find()->where(['in', 'domain', [$this->src_domain]])->andWhere(['path_order' => 0])->andWhere(['in', 'conn_id', $allowedConns])->select(["conn_id"])->distinct(true)->asArray()->all(); //} } elseif ($this->src_domain) { //if(in_array($this->src_domain, $domains_name)){ $connPaths = ConnectionPath::find()->where(['in', 'domain', [$this->src_domain]])->andWhere(['path_order' => 0])->select(["conn_id"])->distinct(true)->asArray()->all(); //} } elseif ($this->dst_domain) { //if(in_array($this->dst_domain, $domains_name)){ $connPaths = ConnectionPath::findBySql("\n SELECT cp1.conn_id\n FROM (\n SELECT conn_id, MAX(`path_order`) AS last_path\n FROM `meican_connection_path`\n GROUP BY `conn_id`\n ) cp2\n JOIN `meican_connection_path` cp1\n ON cp1.conn_id = cp2.conn_id AND cp1.domain = '" . $this->dst_domain . "' AND cp1.path_order = cp2.last_path")->asArray()->all(); //} } else { foreach ($allowed_domains as $domain) { $validDomains[] = $domain->name; } $connPaths = ConnectionPath::find()->where(['in', 'domain', $validDomains])->select(["conn_id"])->distinct(true)->asArray()->all(); } $validConnIds = []; foreach ($connPaths as $connPath) { $validConnIds[] = $connPath['conn_id']; } $validConns = Connection::find()->where(['in', 'id', $validConnIds])->select('reservation_id')->distinct(true)->asArray()->all(); $validIds = []; foreach ($validConns as $conn) { $validIds[] = $conn['reservation_id']; } $invalidConnections = Connection::find()->where(['>=', 'finish', DateUtils::now()])->andWhere(['status' => ["PENDING", "CREATED", "CONFIRMED", "SUBMITTED", "PROVISIONED"]])->select(["reservation_id"])->distinct(true)->asArray()->all(); $invalidIds = []; foreach ($invalidConnections as $conn) { $invalidIds[] = $conn['reservation_id']; } if (!$this->src_domain && !$this->dst_domain) { $reservations = Reservation::find()->where(['in', 'id', $validIds])->orWhere(['request_user_id' => Yii::$app->user->getId()])->andWhere(['not in', 'id', $invalidIds])->andWhere(['type' => self::TYPE_NORMAL])->orderBy(['date' => SORT_DESC])->asArray()->all(); } else { $reservations = Reservation::find()->where(['not in', 'id', $invalidIds])->andWhere(['in', 'id', $validIds])->andWhere(['type' => self::TYPE_NORMAL])->orderBy(['date' => SORT_DESC])->asArray()->all(); } $validResIds = []; foreach ($reservations as $res) { if ($res['request_user_id'] == $userId) { $validResIds[] = $res['id']; } else { if (!$this->request_user) { $conns = Connection::find()->where(['reservation_id' => $res['id']])->select(["id"])->asArray()->all(); if (!empty($conns)) { $conn_ids = []; foreach ($conns as $conn) { $conn_ids[] = $conn['id']; } $paths = ConnectionPath::find()->where(['in', 'domain', $domains_name])->andWhere(['in', 'conn_id', $conn_ids])->select(["conn_id"])->distinct(true)->asArray()->all(); if (!empty($paths)) { $validResIds[] = $res['id']; } } } } } $dataProvider = new ActiveDataProvider(['query' => Reservation::find()->where(['in', 'id', $validResIds])->orderBy(['date' => SORT_DESC]), 'sort' => false, 'pagination' => ['pageSize' => 10]]); return $dataProvider; }
public static function continueWorkflows($id, $asking = true) { Yii::trace("CONTINUA WORKFLOWS"); $paths = ConnectionPath::find()->select('DISTINCT `domain`')->where(['conn_id' => $id])->all(); Yii::trace("Dominios envolvidos:"); foreach ($paths as $path) { Yii::trace($path->domain); } //Analisa se existem pedidos em espera. Neste momento, realiza as perguntas aos admins. foreach ($paths as $path) { if (Connection::findOne(['id' => $id])->auth_status == self::AUTH_STATUS_REJECTED) { break; } else { $domain = Domain::findOne(['name' => $path->domain]); if (isset($domain)) { BpmFlow::doRequest($id, $domain->name, $asking); } } if (ConnectionAuth::find()->where(['connection_id' => $id, 'status' => self::AUTH_STATUS_PENDING])->count() > 0) { break; } //Se tem uma pergunta ativa. } if (!$asking || ConnectionAuth::find()->where(['connection_id' => $id, 'status' => self::AUTH_STATUS_PENDING])->count() > 0) { return; } $conn = Connection::findOne(['id' => $id]); if ($conn->auth_status == self::AUTH_STATUS_PENDING) { $conn->auth_status = self::AUTH_STATUS_APPROVED; if (!$conn->save()) { } if (!$conn->isCancelStatus()) { $conn->requestProvision(); } } //Remove fluxos não finalizados BpmFlow::removeFlows($id); }