2021-07-15 14:54:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
use App\Models\{Address,Domain,System,Zone};
|
|
|
|
|
|
|
|
class NodeHierarchy extends Seeder
|
|
|
|
{
|
2022-11-19 13:19:09 +00:00
|
|
|
public const DEBUG=TRUE;
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
DB::table('domains')
|
|
|
|
->insert([
|
2021-07-26 11:21:58 +00:00
|
|
|
'name'=>'domain-a',
|
2021-07-15 14:54:23 +00:00
|
|
|
'active'=>TRUE,
|
|
|
|
'public'=>TRUE,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
DB::table('domains')
|
|
|
|
->insert([
|
2021-07-26 11:21:58 +00:00
|
|
|
'name'=>'domain-b',
|
2021-07-15 14:54:23 +00:00
|
|
|
'active'=>TRUE,
|
|
|
|
'public'=>TRUE,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
2021-07-26 11:21:58 +00:00
|
|
|
foreach (['domain-a','domain-b'] as $domain) {
|
2022-11-11 11:57:40 +00:00
|
|
|
$do = Domain::where('name',$domain)->singleOrFail();
|
|
|
|
$this->hierarchy($do,100);
|
|
|
|
$this->hierarchy($do,101);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function hierarchy(Domain $domain,int $zoneid)
|
|
|
|
{
|
|
|
|
$regions = [1,2];
|
2022-11-19 13:19:09 +00:00
|
|
|
//$hosts = [20,30];
|
2021-07-15 14:54:23 +00:00
|
|
|
$hubs = [1000,2000];
|
|
|
|
$nodes = [1,2,3];
|
|
|
|
$hubnodes = [-1,+1];
|
|
|
|
|
|
|
|
$so = $this->system('ZC '.$domain->id);
|
|
|
|
DB::table('zones')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zoneid,
|
|
|
|
'active'=>TRUE,
|
|
|
|
'notes'=>sprintf('Zone: %03d:0/0.0@%s',$zoneid,$domain->name),
|
|
|
|
'domain_id'=>$domain->id,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$zo = Zone::where('zone_id',$zoneid)->where('domain_id',$domain->id)->singleOrFail();
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['zo'=>$zo->zone_id,'rid'=>0,'hid'=>0,'nid'=>0]);
|
|
|
|
|
2021-07-26 11:21:58 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
|
|
|
'region_id'=>0,
|
|
|
|
'host_id'=>0,
|
|
|
|
'node_id'=>0,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_ZC,
|
2021-07-26 11:21:58 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
// ZC Nodes
|
2021-07-15 14:54:23 +00:00
|
|
|
foreach ($nodes as $nid) {
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['rid'=>$zo->zone_id,'hid'=>$zo->zone_id,'nid'=>$nid]);
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (ZC Node)',$zoneid,0,$nid,$domain->name));
|
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
|
|
|
'region_id'=>0,
|
|
|
|
'host_id'=>0,
|
|
|
|
'node_id'=>$nid,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_ACTIVE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['end'=>'nodes top']);
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
// Regions
|
|
|
|
foreach ($regions as $rid) {
|
2022-11-19 13:19:09 +00:00
|
|
|
$hostid = $rid;
|
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>0]);
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
$so = $this->system(sprintf('Region %03d:%03d/%03d.0@%s',$zoneid,$rid,0,$domain->name));
|
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
|
|
|
'region_id'=>$rid,
|
2022-11-19 13:19:09 +00:00
|
|
|
'host_id'=>$rid,
|
2021-07-15 14:54:23 +00:00
|
|
|
'node_id'=>0,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_RC,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
// RC Nodes
|
2021-07-15 14:54:23 +00:00
|
|
|
foreach ($nodes as $nid) {
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>$nid]);
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (RC Node)',$zoneid,$rid,$nid,$domain->name));
|
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
|
|
|
'region_id'=>$rid,
|
2022-11-19 13:19:09 +00:00
|
|
|
'host_id'=>$rid,
|
2021-07-15 14:54:23 +00:00
|
|
|
'node_id'=>$nid,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_ACTIVE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
2022-11-19 13:19:09 +00:00
|
|
|
dump(['end'=>'NODES regions']);
|
2021-07-15 14:54:23 +00:00
|
|
|
|
|
|
|
// Hosts
|
2022-11-19 13:19:09 +00:00
|
|
|
foreach ($regions as $rrid) {
|
|
|
|
$hostid = $rid*10+$rrid-1;
|
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>0]);
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
$so = $this->system(sprintf('Host %03d:%03d/0.0@%s (Region %03d)',$zoneid,$hostid,$domain->name,$rid));
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
|
|
|
'region_id'=>$rid,
|
|
|
|
'host_id'=>$hostid,
|
|
|
|
'node_id'=>0,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_NC,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Nodes
|
|
|
|
foreach ($nodes as $nid) {
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
|
|
|
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>$nid]);
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (Region %03d) - Host Node',$zoneid,$hostid,$nid,$domain->name,$rid));
|
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
|
|
|
'region_id'=>$rid,
|
|
|
|
'host_id'=>$hostid,
|
|
|
|
'node_id'=>$nid,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_ACTIVE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hubs
|
|
|
|
foreach ($hubs as $bid) {
|
|
|
|
$so = $this->system(sprintf('Hub %03d:%03d/%03d.0@%s (Region %03d)',$zoneid,$hostid,$bid,$domain->name,$rid));
|
|
|
|
$hub = new Address;
|
|
|
|
$hub->zone_id = $zo->id;
|
|
|
|
$hub->active = TRUE;
|
|
|
|
$hub->region_id = $rid;
|
|
|
|
$hub->host_id = $hostid;
|
|
|
|
$hub->node_id = $bid;
|
|
|
|
$hub->point_id = 0;
|
|
|
|
$hub->system_id = $so->id;
|
2022-01-24 11:56:13 +00:00
|
|
|
$hub->role = Address::NODE_HC;
|
2021-07-15 14:54:23 +00:00
|
|
|
$hub->created_at = Carbon::now();
|
|
|
|
$hub->updated_at = Carbon::now();
|
|
|
|
$hub->save();
|
|
|
|
|
|
|
|
// Nodes
|
|
|
|
foreach ($hubnodes as $nid) {
|
|
|
|
$nodeid = $bid+$nid;
|
|
|
|
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (Region %03d) - Hub Node',$zoneid,$hostid,$nodeid,$domain->name,$rid));
|
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
|
|
|
'region_id'=>$rid,
|
|
|
|
'host_id'=>$hostid,
|
|
|
|
'node_id'=>$nodeid,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'hub_id'=>$hub->id,
|
2022-01-24 11:56:13 +00:00
|
|
|
'role'=>Address::NODE_ACTIVE,
|
2021-07-15 14:54:23 +00:00
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-19 13:19:09 +00:00
|
|
|
dump(['end'=>'NODES normal']);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
2022-11-19 13:19:09 +00:00
|
|
|
|
|
|
|
dump(['end'=>'heirarchy']);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function system(string $name): System
|
|
|
|
{
|
|
|
|
$o = new System;
|
|
|
|
$o->name = $name;
|
|
|
|
$o->sysop = 'Mr Sysop of '.$name;
|
|
|
|
$o->location = 'Some place for '.$name;
|
|
|
|
$o->active = TRUE;
|
|
|
|
$o->created_at = Carbon::now();
|
|
|
|
$o->updated_at = Carbon::now();
|
|
|
|
$o->save();
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|