admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Quintiq file version 2.0
#parent: #root
Method ReceiveConfigurationRequestJoin (NamedValueTree nvt_i, NamedValue body_i, LibDEF_IntegrationEvent event_i)
{
  Description: 'Receive Configuration message for requesting to join domain.'
  TextBody:
  [*
    // Jacky CHAN Apr-22-2016 (created)
    LibDEF_Util::EventLog( event_i, "Receiving join request" );
    
    // retrieve requestor's hostname
    hostName   := LibDEF_DataAccessor::GetBodyPropertyAsString( nvt_i, LibDEF_DataAccessor::HANDLE_CONFIGURATION(), LibDEF_DataAccessor::HEADER_HOSTNAME() );
    
    // retrieve requestor's portnumber
    portNumber := LibDEF_DataAccessor::GetBodyPropertyAsNumber( nvt_i, LibDEF_DataAccessor::HANDLE_CONFIGURATION(), LibDEF_DataAccessor::HEADER_PORTNUMBER() );
    
    // retrieve requestor's systemname
    systemName := LibDEF_DataAccessor::GetBodyPropertyAsString( nvt_i, LibDEF_DataAccessor::HANDLE_CONFIGURATION(), LibDEF_DataAccessor::HEADER_SYSTEMNAME() );
    
    // retrieve requestor's (assuming) SystemGUID
    systemGUID := LibDEF_DataAccessor::GetHeaderPropertyAsString( nvt_i, LibDEF_DataAccessor::HEADER_SYSTEMGUID_FROM() );
    
    // check if requesting System has registered before
    requestorSystem := LibDEF_System::FindSystemByGUID( this, systemGUID );
    // check if any System with matching host and port
    matchedSystem   := LibDEF_System::FindSystemByCoordinate( this, hostName, portNumber );
    
    if( not isnull( matchedSystem ) and matchedSystem.GUID() <> systemGUID )
    {
      LibDEF_Util::EventLogError( event_i,
                                  "Cannot accept Request to join Domain",
                                  "Cannot accept Request to join Domain. System with same coordinate " +
                                  LibDEF_Util::FormatCoordinateToString( matchedSystem.HostName(), matchedSystem.PortNumber() ) + " already exists." );
    }
    else
    {
      if( isnull( requestorSystem ) )
      {
        // create the joining System
        if( this.IsBootNode() )
        {
          // assign a new System-GUID instead
          requestorSystem := LibDEF_System::Create( this, hostName, portNumber );
        }
        else
        {
          // use the System-GUID as assigned by the BootNode before broadcast
          requestorSystem := LibDEF_System::Create( this, systemGUID, hostName, portNumber );
        }
      }
      else
      {
        requestorSystem.ChangeKeySystemByCoordinate( hostName, portNumber, event_i );
      }
    
      // update
      requestorSystem.Name( systemName );
    
      // sync channels
      systems := construct( LibDEF_Systems );
      systems.Add( requestorSystem );
      this.SyncChannelMetasFromRoutingTable( nvt_i, body_i, systems, requestorSystem.GUID(), event_i );
    
      // reply with success
      this.SendConfigurationSuccessJoin( requestorSystem, event_i );
    }
  *]
}