{
    "$ref": "#/definitions/system",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "links" : [
	{
	    "title" : "List the cluster of active hosts running NorthStar",
	    "href" : "/hosts",
	    "method" : "GET",
	    "schema" : {"$ref" : "#/definitions/hostList"}
	},
        {
	    "title" : "Request the primary node to stop, triggers a switchover",
	    "href" : "/stepdown",
	    "method" : "POST"
	},
	{
	    "title" : "List the highAvailability preferences",
	    "href" : "/highAvailability",
	    "rel" : "self",
	    "schema" : {"$ref" : "#/definitions/highAvailability"}
	},
        {
	    "title" : "Show the status of the Zookeeper Components",
	    "href" : "/zookeeperStatus",
	    "rel" : "self",
	    "schema" : {"$ref" : "#/definitions/zookeeperStatus"}
	},
        {
            "title" : "Describe the list of URLs",
            "href"  : "/",
            "schema" : {"$ref" : "#/definitions/endpointList"}
        }
    ],
    "definitions": {
        "endpointList"  : {
                "type" : "object", "properties" : {
                    "links": {"$ref" : "common.json#/definitions/APILinkList","description" :"list of urls supported."}
                }                        
        },
        "zookeeperStatus" : {
            "type" : "object",
            "properties" :  {
                "master": {
                    "description": "Hostname of the current zookeeper master",
                    "type": "string"
                },
                "followers" : {
                    "type" : "array",
                    "description" : "List of hosts following the master that are cluster members",
                    "items" : {
                        "type" :"object",
                        "properties" : {
                             "host": {
                                 "description": "hostname of the node.",
                                 "type": "string"
                             },
                            "synched" : {
                                "description": "Indicate the zookeeper synchronization status.",
                                "type": "boolean"
                            },
                            "ip" : {"type":"string","description":"IP address used for northStar clustering", "format" : "ipv4"}
                        }
                    }
                }
            }
        },
        "hostList" : {
		"type" : "array",
		"items" : {"$ref" : "#/definitions/host"}
	},
	"system" : {
	    "type" :"object",
	    "properties" : {
		"hosts" : {
		    "type" : "array",
		    "items" : {"$ref" : "#/definitions/host"}
		},
		"highAvailability" : {"$ref" : "#/definitions/highAvailability"}
	    }
	},
        "highAvailailityRole": {
            "description": " HA Role",
            "enum": [
                "Active",
                "Standby",
                "Active,Coordinator",
                "Standby,Coordinator",
                "Infrastructure"
            ],
            "type": "string"
        },
        "hostStatus": {
            "description": "Host Status",
            "enum": [
                "Up",
                "Down"
            ],
            "type": "string"
        },
        "preferenceType": {
            "description": "Host Status",
            "enum": [
                "primaryNode",
                "pathComputation",
                "topology"
            ],
            "type": "string"
        },
        "highAvailability": {
            "description": "contains the user preference for highAvailability host selection",
            "items": {
                "type" : "object",                
                "additionalProperties": false,
                "properties": {
                    "host": {
                        "description": "The host to which the priority applies",
                        "type": "string"
                    },
                    "preferenceType": {
                        "$ref": "#/definitions/preferenceType",
                        "description": "The type of preference"
                    },
                    "priority": {
                        "description": "Priority : 0 being not set, 1 being the highest priority, 255 the least",
                        "type": "integer"
                    }
                }
            },
            "type": "array"
        },
        "host": {
            "additionalProperties": false,
            "properties": {
                "hostname": {
                    "description": "Unique identifier for machine",
                    "type": "string"
                },
                "version" : {
                    "description": "The version of the NorthStar-Bundle installed on that host",
                    "type": "string"
                },
                "ipv4" : {"type":"string","description":"IP address used for northStar clustering", "format" : "ipv4"},
                "lastActive" : {
                    "type": "string",
                    "format" : "date-time",
                    "description": "Timestamp of time the node last became active"
                },
                "processes": {
                    "items": {
                        "additionalProperties": false,
                        "properties": {
                            "processId": {
                                "description": "The process pid",
                                "type": "integer"
                            },
                            "processName": {
                                "description": " The process name",
                                "type": "string"
                            },
                            "role": {
                                "$ref": "#/definitions/highAvailailityRole",
                                "description": "Indicate the role of the process."
                                },
                            "startTime": {
                                "type": "string",
                                "format" : "date-time",
                                "description": "timestamp when the process was started"
                            }
                        },
                        "requiredProperties": [
                            "processId"
                        ],
                        "type": "object"
                    },
                    "type": "array"
                },
                "role": {
                    "$ref": "#/definitions/highAvailailityRole",
                    "description": "The role of the node in the cluster"
                },
                "status": {
                    "$ref": "#/definitions/hostStatus",
                    "description": "The host Status."
                }
            },
            "requiredProperties": [
                "hostname",
                "status",
                "role"
            ],
            "type": "object"
        }
    },
    "id": "ha.json"
}
