Common OpenCloud Library
Go to file
2024-09-16 16:59:12 +02:00
config conf singleton issue 2024-09-04 14:21:01 +02:00
dbs State of an API with OClib :D 2024-08-21 10:58:24 +02:00
doc model update - shared workspaces 2024-08-07 18:50:25 +02:00
logs Refactor and doc 2024-09-04 10:53:12 +02:00
models Merge branch 'master' of https://cloud.o-forge.io/core/oc-lib 2024-09-16 16:59:12 +02:00
static A question refers to the comment ! And if not Ooopsy 2024-08-30 14:50:48 +02:00
tests improve testing 2024-07-17 17:19:42 +02:00
tools Refactor and doc 2024-09-04 10:53:12 +02:00
.gitignore First batch 2024-07-16 11:05:11 +02:00
entrypoint.go Add GetConfig to entrypoint 2024-09-04 15:54:49 +02:00
go.mod common config loader added to tools 2024-08-28 15:26:00 +02:00
go.sum common config loader added to tools 2024-08-28 15:26:00 +02:00
README.md doc fix 2024-09-04 14:41:27 +02:00

oc-lib

oc-lib allows read/write/search operations into the main OpenCloud databases.

It also provides common initialization and configuration utilities for all OpenCloud components

Usage example in a beego API

const appname = "oc-mycomponent"

func main() {
    // Init the oc-lib
    oclib.Init(appname)

    // Load the right config file

    /*  The configuration loader will load the configuration from the following sources:
    *  - the environment variables with the prefix OCAPPNAME_ - ex: OCMYCOMPONENT_MONGOURL
    *  - the file /etc/oc/appname.json - ex: /etc/oc/mycomponent.json
    *  - the file ./appname.json - ex: ./mycomponent.json
    *  The configuration loader will merge the configuration from the different sources
    *  The configuration loader will give priority to the environment variables
    *  The configuration loader will give priority to the local file over the default file
    */
    o := oclib.GetConfLoader()

    // init the local config object
    models.GetConfig().Port = o.GetIntDefault("port", 8080)
    models.GetConfig().LokiUrl = o.GetStringDefault("lokiurl", "")
    models.GetConfig().LogLevel = o.GetStringDefault("loglevel", "info")    
    models.GetConfig().MongoUrl = o.GetStringDefault("mongourl", "mongodb://127.0.0.1:27017")
    models.GetConfig().MongoDatabase = o.GetStringDefault("mongodatabase", "myDb")
    models.GetConfig().NatsUrl = o.GetStringDefault("natsurl", "nats://localhost:4222")

    models.GetConfig().mycomponentparam1 = o.GetStringDefault("mycomponentparam1", "mycomponentdefault1")    
    models.GetConfig().mycomponentparam2 = o.GetStringDefault("mycomponentparam2", "mycomponentdefault2")

    // feed the library with the loaded config, 
    // this will also initialize a logger available via oclib.GetLogger()
	oclib.SetConfig(
        models.GetConfig().MongoUrl
        models.GetConfig().MongoDatabase 
        models.GetConfig().NatsUrl
        models.GetConfig().LokiUrl
        models.GetConfig().LogLevel
	)

    // Beego init
    beego.BConfig.AppName = appname
    beego.BConfig.Listen.HTTPPort = models.GetConfig().Port
    beego.BConfig.WebConfig.DirectoryIndex = true
    beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"

    beego.Run()
}

SPECIAL FLOWS IN OC-LIB RESUME :

WORKFLOW AS ITS OWN WORKSPACE

A workflow on post, put, delete, manage a workspace with resources. This workspace is deeply related to workflow by sharing its naming such as : "<workflow_name>_worspace"

WORKFLOW GENERATE ITS OWN EXECUTION

A workflow on post, put, delete, with a schedule && schedule_active to "true", must manage execution by adding, deleting execution depending on change (update -> involved delete into add)

If schedule_active is set to "false" execution will be deleted.

WORKFLOW GENERATE ITS OWN BOOKING ON PEERS

A workflow on post, put, delete, with a schedule && schedule_active to "true", must manage booking by adding, deleting execution with http requests on peers depending on change (update -> involved delete into add)

If schedule_active is set to "false" booking will be deleted.

SHARED WORKSPACE : WORSPACE & WORKFLOW

You can create a share workspace with workspace & workflow. When a share workspace is post, put, delete it update workspace or workflow field. Workspace can be shared on one share workspace Workflow can be shared in multiple workspace

SHARED WORKSPACE SHARE TO PEER

When writing a shared workspace, it set up to date on peers involved in shared workspace It create or delete shared workspace in remote peers by http requests on oc-shared (update -> involved delete into add)

It create or delete workspace involved in shared workspace by http requests on oc-workspace (update -> involved delete into add) It create or delete workflow involved in shared workspace by http requests on oc-workflow (update -> involved delete into add)

WORKFLOW WRITE BUT SHARED

On delete & update & post, workflow will send to peer in field by http request on oc-workflow

WORKSPACE WRITE BUT SHARED

On delete & update & post, workspace will send to peer in field by http request on oc-workspace