コード例 #1
0
ファイル: DeviceSearch.php プロジェクト: ufrgs-hyman/meican
 public function searchByDomains($params, $domains)
 {
     $validDomains = [];
     $this->load($params);
     if ($this->domain_name) {
         Yii::trace($this->domain_name);
         $domain = Domain::findOne(['name' => $this->domain_name]);
         $devices = Device::find()->where(['domain_id' => $domain->id]);
     } else {
         foreach ($domains as $domain) {
             $validDomains[] = $domain->id;
         }
         $devices = Device::find()->where(['in', 'domain_id', $validDomains]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $devices, 'sort' => false, 'pagination' => ['pageSize' => 15]]);
     return $dataProvider;
 }
コード例 #2
0
 private function search()
 {
     foreach ($this->parser->getData()['domains'] as $domainName => $domainData) {
         $domain = Domain::findByName($domainName)->one();
         if ($domain == null) {
             $change = $this->buildChange();
             $change->domain = $domainName;
             $change->item_type = Change::ITEM_TYPE_DOMAIN;
             $change->data = json_encode(['' => '']);
             $change->type = Change::TYPE_CREATE;
             $change->save();
             $invalidDevices = false;
         } else {
             //VERIFICA DEVICES
             if ($this->parser instanceof NSIParser) {
                 $invalidDevices = Device::find()->where(['domain_id' => $domain->id]);
             } else {
                 $invalidDevices = false;
             }
             ///////////
         }
         if ($this->parser instanceof NSIParser && isset($domainData['nsa'])) {
             foreach ($domainData['nsa'] as $nsaId => $nsaData) {
                 $provider = Provider::find()->where(['nsa' => $nsaId])->one();
                 if (!$provider) {
                     $change = $this->buildChange();
                     $change->type = Change::TYPE_CREATE;
                     $change->domain = $domainName;
                     $change->item_type = Change::ITEM_TYPE_PROVIDER;
                     $change->data = json_encode(['name' => $nsaData['name'], 'type' => $nsaData['type'], 'lat' => $nsaData["lat"], 'lng' => $nsaData["lng"], 'nsa' => $nsaId]);
                     $change->save();
                 } elseif ($nsaData['lat'] && $nsaData['lng'] && intval($provider->latitude) != intval($nsaData['lat']) || intval($provider->longitude) != intval($nsaData['lng'])) {
                     $change = $this->buildChange();
                     $change->type = Change::TYPE_UPDATE;
                     $change->item_id = $provider->id;
                     $change->domain = $domainName;
                     $change->item_type = Change::ITEM_TYPE_PROVIDER;
                     $change->data = json_encode(['name' => $nsaData['name'], 'type' => $nsaData['type'], 'lat' => $nsaData["lat"], 'lng' => $nsaData["lng"], 'nsa' => $nsaId]);
                     $change->save();
                 }
                 if ($provider) {
                     $oldPeerings = $provider->getPeerings();
                     $oldServices = $provider->getServices();
                 }
                 $newPeerings = [];
                 $newServices = [];
                 if (isset($nsaData['peerings'])) {
                     foreach ($nsaData['peerings'] as $dstNsaId) {
                         if ($provider) {
                             $dstProv = Provider::findOneByNsa($dstNsaId);
                             if ($dstProv) {
                                 $peering = Peering::findOne(['src_id' => $provider->id, 'dst_id' => $dstProv->id]);
                                 if ($peering) {
                                     //$newPeerings[] = $peering->id;
                                     continue;
                                 }
                             }
                         }
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_CREATE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_PEERING;
                         $change->data = json_encode(['srcNsaId' => $nsaId, 'dstNsaId' => $dstNsaId]);
                         $change->save();
                     }
                 }
                 foreach ($nsaData['services'] as $serviceUrl => $serviceType) {
                     $service = Service::findOneByUrl($serviceUrl);
                     if (!$service) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_CREATE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_SERVICE;
                         $change->data = json_encode(['provName' => $nsaData['name'], 'provNsa' => $nsaId, 'type' => $serviceType, 'url' => $serviceUrl]);
                         $change->save();
                     } else {
                         $newServices[] = $service->id;
                     }
                 }
                 if ($provider) {
                     $oldServices = $oldServices->andWhere(['not in', 'id', $newServices])->select(['id'])->asArray()->all();
                     foreach ($oldServices as $invalidService) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_DELETE;
                         $change->domain = $domainName;
                         $change->item_id = $invalidService['id'];
                         $change->item_type = Change::ITEM_TYPE_SERVICE;
                         $change->data = json_encode(['' => '']);
                         $change->save();
                     }
                 }
             }
         }
         //PERFSONAR
         if ($this->parser instanceof NMWGParser) {
             if (isset($domainData['devices'])) {
                 $this->importDevices($domainData["devices"], $domainName, $invalidDevices);
             }
             //NSI
         } else {
             if (isset($domainData['nets'])) {
                 $this->importNetworks($domainData["nets"], $domainName, $invalidDevices);
                 if ($invalidDevices) {
                     $invalidDevices = $invalidDevices->select(['id', 'node'])->asArray()->all();
                     foreach ($invalidDevices as $device) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_DELETE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_DEVICE;
                         $change->item_id = $device['id'];
                         $change->data = json_encode(["node" => $device['node']]);
                         $change->save();
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
 public function actionGetAllColor($cols = null)
 {
     $query = Device::find()->orderBy(['name' => 'SORT ASC'])->asArray();
     $cols ? $data = $query->select(array_merge(json_decode($cols), ['domain_id']))->all() : ($data = $query->all());
     foreach ($data as &$dev) {
         $dev['color'] = Domain::find()->where(['id' => $dev['domain_id']])->select(['color'])->asArray()->one()['color'];
     }
     $temp = Json::encode($data);
     Yii::trace($temp);
     return $temp;
 }
コード例 #4
0
 public function actionGetDevicePorts($dom = null, $type = null)
 {
     if ($dom != null) {
         $validDevs = Device::find()->where(['domain_id' => $dom])->asArray()->select('id')->all();
         $devs = [];
         foreach ($validDevs as $value) {
             $devs[] = $value['id'];
         }
         $portsWithAlias = Port::find()->where(['in', 'device_id', $devs])->andWhere(['type' => $type])->select(['id', 'name', 'directionality', 'max_capacity', 'device_id', 'alias_id'])->all();
     } else {
         $portsWithAlias = Port::find()->select(['id', 'name', 'directionality', 'max_capacity', 'device_id', 'alias_id'])->all();
     }
     $ports = [];
     foreach ($portsWithAlias as $port) {
         $devId1 = $port->device_id;
         $aliasPort = $port->getAlias()->select(['id', 'device_id'])->asArray()->one();
         $devId2 = $aliasPort['device_id'];
         isset($ports[$devId1]) ? null : ($ports[$devId1] = []);
         $devId2 ? isset($ports[$devId2]) ? null : ($ports[$devId2] = []) : null;
         if (!in_array($port->id, $ports[$devId1])) {
             $ports[$devId1][$port->id] = ['dir' => $port->directionality, 'name' => $port->name, 'cap' => $port->max_capacity, 'link' => ['dev' => $devId2, 'port' => $aliasPort['id']]];
         }
     }
     Yii::trace($ports);
     return json_encode($ports);
 }
コード例 #5
0
ファイル: Device.php プロジェクト: ufrgs-hyman/meican
 static function findOneParentLocation($id)
 {
     $dev = Device::find()->where(['id' => $id])->select(['id', 'name', 'latitude', 'longitude', 'domain_id'])->one();
     if (!$dev) {
         return null;
     }
     if ($dev->latitude != null) {
         return $dev;
     }
     foreach ($dev->getPorts()->select(['network_id'])->distinct(true)->all() as $port) {
         $net = $port->getNetwork()->select(['latitude', 'longitude'])->asArray()->one();
         if ($net && $net['latitude']) {
             $dev->latitude = $net['latitude'];
             $dev->longitude = $net['longitude'];
             return $dev;
         }
     }
     $prov = Provider::find()->where(['domain_id' => $dev->domain_id])->select(['latitude', 'longitude'])->asArray()->one();
     if ($prov) {
         $dev->latitude = $prov['latitude'];
         $dev->longitude = $prov['longitude'];
     }
     return $dev;
 }
コード例 #6
0
 public function actionEditorUpdate($id = null)
 {
     $this->layout = 'wireit';
     if ($id) {
         $workflow = BpmWorkflow::findOne(['id' => $id]);
         if ($workflow) {
             $domain = Domain::findOne(['name' => $workflow->domain]);
             if ($domain) {
                 if (!self::can('workflow/update', $domain->name)) {
                     if (!self::can("workflow/read")) {
                         return $this->goHome();
                     } else {
                         Yii::$app->getSession()->setFlash('warning', Yii::t("bpm", 'You are not allowed to edit in domain {domain}', ['domain' => $domain->name]));
                         return $this->redirect(array('/bpm/workflow/index'));
                     }
                 }
                 $ownerDomain = [];
                 $ownerDomain[$domain->name] = $domain->name;
                 $domains = Domain::find()->orderBy(['name' => SORT_ASC])->all();
                 $allDomains = [];
                 foreach ($domains as $dom) {
                     $allDomains[$dom->name] = $dom->name;
                 }
                 $roles = $domain->getUserDomainsRoles()->all();
                 $adminsNames = [];
                 foreach ($roles as $role) {
                     $adminsNames[$role->getUser()->id] = $role->getUser()->name;
                 }
                 foreach (User::find()->all() as $user) {
                     $usersNames[$user->id] = $user->name;
                 }
                 $groupsNames = [];
                 foreach (Group::find()->where(['type' => Group::TYPE_DOMAIN, 'domain' => $domain->name])->orWhere(['type' => Group::TYPE_DOMAIN, 'domain' => null])->all() as $group) {
                     $groupsNames[$group->id] = $group->name;
                 }
                 $devicesNames = [];
                 foreach (Device::find()->where(['domain_id' => $domain->id])->all() as $device) {
                     $devicesNames[$device->id] = $device->name;
                 }
                 Yii::trace($roles);
                 Yii::trace($usersNames);
                 Yii::trace($groupsNames);
                 Yii::trace($devicesNames);
                 return $this->render('editor', array('owner_domain' => $ownerDomain, 'domains' => $allDomains, 'groups' => $groupsNames, 'users' => $usersNames, 'admins' => $adminsNames, 'devices' => $devicesNames, 'id' => $_GET['id']));
             }
         }
     }
     if (!self::can("workflow/read")) {
         return $this->goHome();
     } else {
         return $this->redirect(array('/bpm/workflow/index'));
     }
 }
コード例 #7
0
ファイル: Domain.php プロジェクト: ufrgs-hyman/meican
 public function getBiPorts()
 {
     $portsArray = [];
     $devices = Device::find()->where(['domain_id' => $this->id])->all();
     foreach ($devices as $device) {
         $ports = Port::find()->where(['device_id' => $device->id, 'type' => Port::TYPE_NSI, 'directionality' => Port::DIR_BI])->all();
         foreach ($ports as $port) {
             $portsArray[$port->id] = $port;
         }
     }
     return $portsArray;
 }