//  Copyright 2006-2017, Matthew Welland.
// 
// This file is part of Megatest.
// 
//     Megatest is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     Megatest is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with Megatest.  If not, see <http://www.gnu.org/licenses/>.

digraph G {

    label = "Server Start Sequences";
    color=brown;
    rankdir="TB";

    subgraph cluster_1 {
	label="Find Prime Main Server";
	
        node [style=filled,shape=box];
	
	START;
        HaveServ [label="Look at .servinfo\nfiles for prime main"]; 
	AskPrime [label="Ask Prime for main"];
	PingPrime [label="Ping Prime"];
	AskPrime [label="Ask .servinfo prime for server"];
	StartServ [label="Launch Server Process for main.db"];
	
      	START -> HaveServ;
	HaveServ -> PingPrime;
	PingPrime -> AskPrime [label="Got response"];
	PingPrime -> StartServ [label="No reponse"];
	HaveServ -> StartServ [label="No files"];
	StartServ -> "Delay 2s" -> START;
        AskPrime -> DONE;
    }
    
    subgraph cluster_2 {
	label="Starting non-prime server"
        node [style=filled,shape=box];
	StartTCPServer [label="Start tcp server"];
	FindPrimeMain [label="Find Prime Main Server"];
	RegisterProcessViaPrime [label="Register process via prime server"];

	StartTCPServer -> FindPrimeMain -> START;
	DONE -> RegisterProcessViaPrime -> READY;
    }

    subgraph cluster_3 {
	label="Start Prime Main"
        node [style=filled,shape=box];
	StartTCPServer_prime [label="Start tcp server"];
	GetServInfoFiles [label="Get servinfo files"];
	CreateServInfoFile [label="Create servinfo file"];
	RegisterProcess [label="Register process in no-sync (direct access)"];
	ValidateServInfoFiles [label="Validate servinfo files with ping\nremove any files which do not respond to ping"];

	CheckHost [label="Verify that current host matches\nexisting servinfo files host"]
	StartTCPServer_prime -> GetServInfoFiles;
	GetServInfoFiles -> CreateServInfoFile [label="No servinfo\nfiles"];
	GetServInfoFiles -> ValidateServInfoFiles;
	ValidateServInfoFiles -> CreateServInfoFile [label="No valid files"];
	CreateServInfoFile -> GetServInfoFiles [label="servinfo file created"];
	KeepRunning [label="READY"];
		     
	ValidateServInfoFiles -> CheckHost;
	CheckHost -> RegisterProcess [label="Have valid\nservinfo files and same host"];
	RegisterProcess -> KeepRunning;
	CheckHost -> EXIT [label="Not same host"];	
    }
}

