Beispiel #1
0
 def build_middleware(self, inj: Injector = None):
     inj = inj or self.injector
     # inj.build(ReceiveRequestMiddleware, ReceiveRequestMiddlewareImpl)
     inj.build(AuthAdminMiddleware, AuthAdminMiddlewareImpl)
     inj.build(AuthSlaveMiddleware, AuthSlaveMiddlewareImpl)
     inj.build(BootMiddleware, BootMiddlewareImpl)
     CORS(inj.require(Flask))
     return inj
Beispiel #2
0
def inject_service(inj: Injector):
    inj.build(AdminLoginService, AdminLoginServiceImpl)
    inj.build(AdminBootMasterDaemonService, AdminBootMasterDaemonServiceImpl)
    inj.build(AdminShutdownMasterDaemonService,
              AdminShutdownMasterDaemonServiceImpl)

    return inj
Beispiel #3
0
def inject_external_dependency(inj: Injector):
    # 无依赖接口
    inj.provide(Serializer, JSONSerializer())

    # system接口
    inj.provide(SystemEntropyProvider, SystemEntropyProviderImpl())

    # 日志
    logger = std_logging.StdLoggerImpl()
    logger.logger.addHandler(std_logging.StreamHandler())
    inj.provide(Logger, logger)
    inj.provide(Flask, Flask(APPName))

    inj.build(OptionProvider, StdArgParser)
    inj.build(ConfigurationProvider, FileConfigurationProvider)
    inj.build(RouteController, FlaskRouteController)
    inj.build(JWT, PyJWTImpl)

    return inj
Beispiel #4
0
def inject_controller(inj: Injector):
    inj.build(PingController, PingControllerFlaskImpl)
    inj.build(DaemonAdminController, FlaskDaemonAdminControllerImpl)
    return inj
Beispiel #5
0
def inject_middleware(inj: Injector):
    inj.build(AuthAdminMiddleware, AuthAdminMiddlewareImpl)
    CORS(inj.require(Flask))
    return inj
Beispiel #6
0
 def build_controller(self, inj: Injector = None):
     inj.build(ConnectController, ConnectControllerFlaskImpl)
     inj.build(PingController, PingControllerFlaskImpl)
     inj.build(AdminController, AdminControllerFlaskImpl)
     inj.build(MetricsController, MetricsControllerFlaskImpl)
     inj.build(StatisticsController, StatisticsControllerFlaskImpl)
     inj.build(SlaveStateControlController, SlaveStateControlControllerFlaskImpl)
     return inj
Beispiel #7
0
 def build_service(self, inj: Injector = None):
     inj = inj or self.injector
     inj.build(ConnectionService, ConnectionServiceImpl)
     inj.build(StartStateControlService, StartStateControlServiceImpl)
     inj.build(StopStateControlService, StopStateControlServiceImpl)
     inj.build(MetricsService, MetricsServiceImpl)
     inj.build(GenerateStatisticService, GenerateStatisticServiceImpl)
     inj.build(DisConnectionService, DisConnectionServiceImpl)
     inj.build(AdminGenerateReportService, AdminGenerateReportServiceImpl)
     inj.build(AdminGetConnectedSlavesService, AdminGetConnectedSlavesServiceImpl)
     inj.build(AdminGetConnectedSlaveService, AdminGetConnectedSlaveServiceImpl)
     inj.build(AdminGetServerStatusService, AdminGetServerStatusServiceImpl)
     inj.build(AdminGetSlaveStatisticsService, AdminGetSlaveStatisticsServiceImpl)
     inj.provide((AdminGetSlaveStatisticsService, 'V2'), AdminGetSlaveStatisticsServiceImplV2(inj))
     inj.build(AdminSetCurrentTemperatureService, AdminSetCurrentTemperatureServiceImpl)
     inj.build(AdminSetModeService, AdminSetModeServiceImpl)
     inj.build(AdminLoginService, AdminLoginServiceImpl)
     inj.build(AdminBootMasterService, AdminBootMasterServiceImpl)
     inj.build(AdminShutdownMasterService, AdminShutdownMasterServiceImpl)
     inj.build(AdminBootMasterDaemonService, AdminBootMasterDaemonServiceImpl)
     inj.build(AdminShutdownMasterDaemonService, AdminShutdownMasterDaemonServiceImpl)
     inj.build(AdminSetMetricDelayService, AdminSetMetricDelayServiceImpl)
     inj.build(AdminSetUpdateDelayService, AdminSetUpdateDelayServiceImpl)
     inj.build(AdminGetRoomCountService, AdminGetRoomCountServiceImpl)
     return inj
Beispiel #8
0
 def build_model(self, inj: Injector = None):
     inj = inj or self.injector
     inj.build(UserModel, UserModelImpl)
     inj.build(RoomModel, RoomModelImpl)
     inj.build(UserInRoomRelationshipModel, UserInRoomRelationshipModelImpl)
     inj.build(MetricModel, MetricsModelImpl)
     inj.build(StatisticModel, StatisticModelImpl)
     inj.build(EventModel, EventModelImpl)
     inj.build(ReportModel, ReportModelImpl)
     return inj
Beispiel #9
0
    def build_external_dependency(self, inj: Injector):
        # 无依赖接口
        inj.provide(Serializer, JSONSerializer())
        inj.build(RouteController, FlaskRouteController)

        # system接口
        inj.provide(SystemEntropyProvider, SystemEntropyProviderImpl())

        # 日志
        self.logger = std_logging.StdLoggerImpl()
        self.logger.logger.addHandler(std_logging.StreamHandler())
        inj.provide(Logger, self.logger)

        # 配置
        inj.build(OptionProvider, StdArgParser)
        inj.build(ConfigurationProvider, FileConfigurationProvider)

        # 数据库
        if self.cfg.use_test_database:
            self.db_conn = SQLite3(memory=True)
        else:
            self.db_conn = BaseSQLDatabaseImpl(inj)
        inj.provide(SQLDatabase, self.db_conn)

        inj.build(UUIDGenerator, SystemEntropyUUIDGeneratorImpl)
        inj.build(PasswordVerifier, BCryptPasswordVerifier)
        inj.build(JWT, PyJWTImpl)
        inj.provide(Flask, Flask(APPName))

        self.connection_pool = SafeMemoryConnectionPoolImpl(inj)
        inj.provide(ConnectionPool, self.connection_pool)

        # todo: should provide parameters later
        # inj.build(Dispatcher, PriQueueDispatcher())
        inj.provide(Dispatcher, QueueDispatcherWithThreadPool())

        self.websocket_conn = functional_flask_socket_io_connection_impl(inj)
        inj.provide(WebsocketConn, self.websocket_conn)
        inj.build(MasterFanPipe, MasterFanPipeImpl)
        inj.build(MasterAirCond, MasterAirCondImpl)
        return inj
Beispiel #10
0
def build_and_run_console(inj: Injector):
    inj.provide(MainConsole, MainConsoleImpl())
    inj.build(BootConsole, BootConsoleImpl)
    inj.build(MetricConsole, MetricConsoleImpl)
    inj.build(ReportConsole, ReportConsoleImpl)
    inj.build(SetMetricFrequencyConsole, SetMetricFrequencyConsoleImpl)
    inj.build(SetModeConsole, SetModeConsoleImpl)
    inj.build(SetStatisticFrequencyConsole, SetStatisticFrequencyConsoleImpl)
    inj.build(SetTemperatureConsole, SetTemperatureConsoleImpl)
    inj.build(ShutdownConsole, ShutdownConsoleImpl)
    inj.build(StatusConsole, StatusConsoleImpl)

    console = inj.require(MainConsole)
    console.start()