@aitianyu.cn/tianyu-csp v0.1.0
TIANYU - Common Service Platform
A Common Service Platform of Tianyu includes Data API, Network API, Schedule Job and Status Monitor.
MOTIVATION
Most of backend services, need to handle Database Access, Network Connection, Job Management, etc. And need to have a common Status Monitor to get current service status.
Currently, Tianyu has a generic module Server-Base to provide some database and network APIs which can make the program be simple. But there is also a problem that the module only provides APIs, does not have a full status and jobs management.
For the further service development of Smart Home, we need a solution to contain full basic components and provide better ability to extension, also should have a state statistics mechanism.
REQUIREMENTS
Abstracted Data Operation Interface
Data operation includes Data Base Access, Local Storage Access, Cache & Store Management.
Data Base Access
DB access interface, should provide some common operation API like
add,insert,delete,updateand etc. And also should have a sql execution API that accepts user to run a custom operation.Local Storage Access
Local Storage Access should provide some disk operation API, file & directory operation API. Allow user to access and operate local file, dir and disk.
Cache & Store Management
Cache and Store are the runtime storage. The difference of the two components is that Cache is a simple
Key - Valuepair to provide data save and read. Store is a status tools, not only to save the data and read, but also can record the data change. Base on Store, the service can support data rollback and revert-rollback.
Abstracted Network Communication Interface
Network communication includes HTTP, Socket and low-level TCP and UDP operation APIs. For supporting multi-medias, it also should provide FTP, RTMP, RTSP.
Common Object Management Interface
Object management is a core functionality contains
Authorization,Resources Control,Operations AuditandSchedule.Authorization
Authorization is the security core for the whole platform. It contains User Management to verify the user access and Privileges Management to control the user activities.
User Authorization includes
User,LicensesandTeamsthree parts.Licenses: this is a privilege controller contains all functions permission description. There will be a
roletable as additional description to record each privilege status.Teams: this is an additional records to create a group for users.
User: this is a user main part for logon authorization, operation permission control and relationship management.
Resources Control
Resources Control is the virtual data center to allow user to save data into program internal space. (The data of internal space will be persist in local storage or data base.) According to the data type and configuration, the data will be persist in different target entity and managed in a common place
Operations Audit
Operations Audit is used to record all of the user activities, contains Data Change, Configuration Change and any other operations even they do not have impaction to data.
Schedule
Schedule is a calendar manager to support execute timer task.
Common Job Execution Platform
Job Execution Platform is a multi-threads worker to execute some scripts and 3rd-application (like native command, internal JS scripts).
Multi-Threads Worker
Worker is an execution engine to execute local JS scripts, native command applications and remote host functions.
Worker Management
Worker Management is a manager to control workers lifecycle, record worker status and to save the execution result temporarily.
Job Management
Job Management is a manager to provide job list to receive jobs, and job dispatch functionality to send job to worker management. After the Job execution done, Job Management should call the callback function to notify job creator or just save the result in store and waiting for reading.
Common Status Monitor Platform
Status Monitor Platform is used for collecting all the data before mentioned, and to generate a report to user.
MODULES
Infrastructure
Infrastructure contains basic API and some default resources (international strings, exported json data, etc..).
All of components under this folder, based on the database accessment. In this part, will define an inner database API implementation.
Database & Code
There are some infra database API definitions. To provide infra part needed database operation interfaces and database interaction implementations.
Database API is exported in
TIANYU.db.Managers
Managers of infra are the main API for
Tianyu-CSP. There are some default and basic operation interface and will be post only byTIANYU.${function name}. Containsimport,logger,request,session,trace,usage,fwkandenvironment.import: this is a packaged API for import module and files from specified path. It also provides
htmlmethod which receive a path string to import a html file as string, andMODULEobject to export all internal Objects which are out of infra. (NOTE: All internal objects will not be able to use by importing and require. All objects can only used byTIANYU.${function name}andTIANYU.import.MODULE.)logger: this is a logger tool to record runtime logs and to do persistence.
request: this is a request context and work for request and sub-job. For each thread, it will have its independent request instance with the network info.
session: this is same like request, to provide user info, privilege checking. For each request or sub-job, it will have a session instance belongs to itself.
trace: to provide a recorder API to record error trace data. there is only a write API.
usage: to provide a recorder API to record function usage data. there is only a write API.
fwk: this is a framework instance for each request or sub-job. the purpose of it to decouple the dependencies. in
Tianyu-CSP, there are some predefined API for internally using. PLEASE DO NOT USE THE PRE-DEFINED API IN YOUR CODE.environment: this is a constant object to provide some application data, includes
version,developmentMode,application nameand etc...feature: this is a feature tool to get a specified feature is enabled or not.
Handler & Service
Handler
provides data pre-processing, data dispatching and exception handling. By using
TIANYU.fwk, they are totally decoupled. Data transferring uses internal pip.Service
provides all external network interaction implementations, include
http-service,socket-serviceand etc...
Job
Job contains the implementation of Node.JS multi-thread. By JobManager, the jobs will be managed to control the jobs' lifecycle. Job manager has a max-workers option, to control the maximum threads count, if the threads count is over maximum, the new jobs will be stored and to be executed when has thread released.
Modules
This is some exported tools class. All the objects in modules should only be used by TIANYU.import.MODULE.
Utils
This is some public tools to process data, convert data type and other data generation.