Exemplo n.º 1
0
	def _Initialise(self):
		from Logger.ConsoleLogPrint import ConsoleLogPrint
		consoleLogPrint = ConsoleLogPrint('ConsoleLogPrint', AllLogLevels)
		LoggerInst.RegisterSink(consoleLogPrint)

		LoggerInst.Log(LogLevel.Info, TitleStr, ServiceVersion)
		LoggerInst.Log(LogLevel.Info, CopyrightStr)
		LoggerInst.Log(LogLevel.Info, LicenseStr)

		# Create authentication network interface message processor and the
		# related message factory.
		from Network.AuthInterfaceMsgProcessor import AuthInterfaceMsgProcessor
		from Network.AuthInterface import AuthInterfaceFactory
		self.__authMsgProcessor = AuthInterfaceMsgProcessor()
		self.__authInterfaceFactory = AuthInterfaceFactory(
			self.__authMsgProcessor, self)

		# Initialise the authentication service network connection state.
		self.__svcConnState_Auth = SvcConnState.Disconnected

		###############################
		# Service level 0 : Bootstrapping
		###############################
		LoggerInst.Log(LogLevel.Info,
			"Entering service level 0 - Bootstrapping")

		# Set the signal handler.
		signal.signal(signal.SIGINT, self.SignalHandler)

		LoggerInst.Log(LogLevel.Info,
		"Reading configuration file '{0}'".format(self.ConfigFile))

		# Create an instance of the config reader and then parse the XML file.
		configReader = ConfigReader()
		self._config, errCode = configReader.ReadXMLConfig(self.ConfigFile)

		if self._config == None:
			failStr = "Config file read failed : {0}".format(errCode)
			LoggerInst.Log(LogLevel.Emergency, failStr)
			return False

		###############################
		# Service level 1 : Bringing up all network connections
		###############################
		LoggerInst.Log(LogLevel.Info,
			"Entering service level 1 - Bringing up all network connections")

		# Check if the service 'authenticator' is set to disabled in the
		# configuration file, then set it as disabled so it won't connect.
		if self._config.Service_Auth.DiscoveryMode == DiscoveryMode.Disabled:
			self.__svcConnState_Auth = SvcConnState.Disabled
			LoggerInst.Log(LogLevel.Info,
				"Service 'Authenticator' Interface [Disabled]")
			self.__authInterfaceOK = True

		else:
			LoggerInst.Log(LogLevel.Info,
				"Service 'Authenticator' Interface [Auto]")
			# Attempt to connect to the authentication service when running.
			reactor.callLater(0.5, self.ConnectToAuthService)

		# If the client interface is enabled then start listening.
		if self._config.ClientInterface.StartState == True:
			LoggerInst.Log(LogLevel.Info, "Client Interface : Enabled")
			reactor.callLater(0.5, self.StartClientInterface) 

		else:
			LoggerInst.Log(LogLevel.Info, "Client Interface : Disabled")
			self.__clientInterfaceOK = True

		# Set to running.
		self.IsRunning = True

		return True
Exemplo n.º 2
0
    def Initialise(self):
        self.LogEvent(LogLevel.Informational, TitleStr, ServiceVersion)
        self.LogEvent(LogLevel.Informational, CopyrightStr)
        self.LogEvent(LogLevel.Informational, LicenseStr)

        self.LogEvent(LogLevel.Informational,
                      "Entering service level 0 - Bootstrapping")

        # Set the signal handler.
        signal.signal(signal.SIGINT, self.SignalHandler)

        self.LogEvent(LogLevel.Informational,
                      "Reading configuration file 'config.xml'")

        # Create an instance of the config reader and then parse the XML file.
        configReader = ConfigReader()
        self._config, errCode = configReader.ReadXMLConfig(self.ConfigFile)

        if self._config == None:
            failStr = "Config file read failed : {0}".format(errCode)
            self.LogEvent(LogLevel.Emergency, failStr)
            return False

        # Register 'Start handshake' event.
        self.__gatewayMsgProcessor.RegisterMessageID(MsgID_StartHandshake)

        # Register 'End handshake' event.
        self.__gatewayMsgProcessor.RegisterMessageID(MsgID_EndHandshake)

        # Opening connection to the database
        self.LogEvent(LogLevel.Informational,
                      "Database Connection : Not implemented")

        # Change mode to 'Opening Network Connections'
        self.ReceiveEvent(
            ServiceEvent(0, ServiceEventType.ModeChange,
                         ServiceMode.OpeningNetworkConnections))
        self.LogEvent(LogLevel.Informational,
                      "Service Mode changed to 'Opening Network Connections'")

        # Start state of all network connection states.
        networkConnsOpen = False

        # Check if the service 'Business Logic' is disabled in the config file
        # then set it as disabled so it won't connect.
        if self._config.Service_BusinessLogic.DiscoveryMode == DiscoveryMode.Disabled:
            self.__svcConnState_BusinessLogic = SvcConnState.Disabled
            self.LogEvent(LogLevel.Informational,
                          "Service 'Business Logic' Interface [Disabled]")
        else:
            self.LogEvent(LogLevel.Informational,
                          "Service 'Business Logic' Interface [Auto]")

        # Check if the service 'Gateway' is disabled in the config file then
        # set it as disabled so it won't connect.
        if self._config.Service_Gateway.DiscoveryMode == DiscoveryMode.Disabled:
            self.__svcConnState_Gateway = SvcConnState.Disabled
            self.LogEvent(LogLevel.Informational,
                          "Service 'Gateway' Interface : Disabled")
            networkConnsOpen = True
        else:
            self.LogEvent(LogLevel.Informational,
                          "Service 'Gateway' Interface [Auto]")

            gatewayConf = self._config.Service_Gateway
            self._gatewayConn = TCP4ServerEndpoint(reactor,
                                                   gatewayConf.NetworkPort)
            self._gatewayConn.listen(
                GatewayInterfaceFactory(self.__gatewayMsgProcessor))

        self.LogEvent(LogLevel.Informational,
                      "Bringing up all network connections")

        self._networkThread = threading.Thread(
            target=reactor.run, kwargs={"installSignalHandlers": False})
        self._networkThread.start()

        # Try to open any required network connections.
        while networkConnsOpen == False:

            try:
                time.sleep(0.01)
            except KeyboardInterrupt:
                if e.errno == errno.EINTR:
                    pass

            # If all of the services are either connected or disabled then
            # continue bringing up the service.
            if (self.__svcConnState_Gateway == SvcConnState.Disabled or \
             self.__svcConnState_Gateway == SvcConnState.Connected) and \
             (self.__svcConnState_BusinessLogic == SvcConnState.Disabled or \
             self.__svcConnState_BusinessLogic == SvcConnState.Connected):
                networkConnsOpen = True

            if self.__shutdownRequested == True:
                return False

        if self.__svcConnState_Gateway == SvcConnState.Disabled:
            self.LogEvent(LogLevel.Informational,
                          "Gateway disabled : No network connections open")
        else:
            self.LogEvent(LogLevel.Informational,
                          "All network connections open")

        self.ReceiveEvent(
            ServiceEvent(0, ServiceEventType.ModeChange,
                         ServiceMode.StartingService))
        self.LogEvent(LogLevel.Informational,
                      "Service Mode changed to 'StartingService'")

        self.ReceiveEvent(
            ServiceEvent(0, ServiceEventType.ModeChange, ServiceMode.Open))
        self.LogEvent(LogLevel.Informational, "Service Mode changed to 'Open'")

        # Set the service as running.
        self.ServiceRunning = True

        return True