From df21e384c3cbad6b12b903e94b2112504a494078 Mon Sep 17 00:00:00 2001 From: Levichev Dmitry Date: Tue, 21 Jan 2020 22:59:17 +0300 Subject: [PATCH] Revert "fix v3.0.0 access" This reverts commit ad7f525f66d2803fd3b65dea674be8ee3445b757. --- v3/.dockerignore | 4 - v3/.gitignore | 6 - v3/.vscode/launch.json | 31 --- v3/LICENSE | 21 -- v3/Makefile | 10 - v3/Readme.md | 32 --- v3/build.ps1 | 35 --- v3/build/DefaultContainerFactory.go | 49 ---- v3/build/doc.go | 5 - v3/clean.ps1 | 19 -- v3/component.json | 6 - v3/config/ComponentConfig.go | 78 ------- v3/config/ContainerConfig.go | 57 ----- v3/config/ContainerConfigReader.go | 83 ------- v3/config/doc.go | 11 - v3/container/Container.go | 296 ------------------------ v3/container/ProcessContainer.go | 213 ----------------- v3/container/doc.go | 22 -- v3/docker/Dockerfile.build | 21 -- v3/docker/Dockerfile.test | 15 -- v3/docker/docker-compose.test.yml | 10 - v3/docs/Development.md | 103 --------- v3/docs/Downloads.md | 19 -- v3/examples/DummyController.go | 72 ------ v3/examples/DummyFactory.go | 16 -- v3/examples/DummyProcess.go | 10 - v3/examples/dummy.yaml | 21 -- v3/go.mod | 9 - v3/go.sum | 25 -- v3/index.go.bak | 7 - v3/main.go | 11 - v3/refer/BuildReferencesDecorator.go | 215 ----------------- v3/refer/ContainerReferences.go | 91 -------- v3/refer/LinkReferencesDecorator.go | 112 --------- v3/refer/ManagedReferences.go | 90 ------- v3/refer/ReferencesDecorator.go | 158 ------------- v3/refer/RunReferencesDecorator.go | 115 --------- v3/refer/doc.go | 17 -- v3/tag.ps1 | 26 --- v3/test.ps1 | 21 -- v3/test/config/ComponentConfig_test.go | 80 ------- v3/test/refer/ManagedReferences_test.go | 47 ---- 42 files changed, 2289 deletions(-) delete mode 100644 v3/.dockerignore delete mode 100644 v3/.gitignore delete mode 100644 v3/.vscode/launch.json delete mode 100644 v3/LICENSE delete mode 100644 v3/Makefile delete mode 100644 v3/Readme.md delete mode 100644 v3/build.ps1 delete mode 100644 v3/build/DefaultContainerFactory.go delete mode 100644 v3/build/doc.go delete mode 100644 v3/clean.ps1 delete mode 100644 v3/component.json delete mode 100644 v3/config/ComponentConfig.go delete mode 100644 v3/config/ContainerConfig.go delete mode 100644 v3/config/ContainerConfigReader.go delete mode 100644 v3/config/doc.go delete mode 100644 v3/container/Container.go delete mode 100644 v3/container/ProcessContainer.go delete mode 100644 v3/container/doc.go delete mode 100644 v3/docker/Dockerfile.build delete mode 100644 v3/docker/Dockerfile.test delete mode 100644 v3/docker/docker-compose.test.yml delete mode 100644 v3/docs/Development.md delete mode 100644 v3/docs/Downloads.md delete mode 100644 v3/examples/DummyController.go delete mode 100644 v3/examples/DummyFactory.go delete mode 100644 v3/examples/DummyProcess.go delete mode 100644 v3/examples/dummy.yaml delete mode 100644 v3/go.mod delete mode 100644 v3/go.sum delete mode 100644 v3/index.go.bak delete mode 100644 v3/main.go delete mode 100644 v3/refer/BuildReferencesDecorator.go delete mode 100644 v3/refer/ContainerReferences.go delete mode 100644 v3/refer/LinkReferencesDecorator.go delete mode 100644 v3/refer/ManagedReferences.go delete mode 100644 v3/refer/ReferencesDecorator.go delete mode 100644 v3/refer/RunReferencesDecorator.go delete mode 100644 v3/refer/doc.go delete mode 100644 v3/tag.ps1 delete mode 100644 v3/test.ps1 delete mode 100644 v3/test/config/ComponentConfig_test.go delete mode 100644 v3/test/refer/ManagedReferences_test.go diff --git a/v3/.dockerignore b/v3/.dockerignore deleted file mode 100644 index 9b70979..0000000 --- a/v3/.dockerignore +++ /dev/null @@ -1,4 +0,0 @@ -/vendor -/docker/Dockerfile* -/docker/docker-compose*.yml -/*.ps1 diff --git a/v3/.gitignore b/v3/.gitignore deleted file mode 100644 index ccbfd88..0000000 --- a/v3/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/dist -/vendor -/data/configs.test.json -/data/device_configs.json -/docker/id_rsa* -*.exe \ No newline at end of file diff --git a/v3/.vscode/launch.json b/v3/.vscode/launch.json deleted file mode 100644 index f4292f1..0000000 --- a/v3/.vscode/launch.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Go Main", - "type": "go", - "request": "launch", - "mode": "debug", - "remotePath": "", - "port": 2345, - "host": "127.0.0.1", - "program": "${workspaceRoot}", - "env": {}, - "args": [], - "showLog": true - }, - { - "name": "Go Test", - "type": "go", - "request": "launch", - "mode": "test", - "remotePath": "", - "port": 2345, - "host": "127.0.0.1", - "program": "${file}", - "env": {}, - "args": [], - "showLog": true - } - ] -} \ No newline at end of file diff --git a/v3/LICENSE b/v3/LICENSE deleted file mode 100644 index 1976bb0..0000000 --- a/v3/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2018 pip-services-go - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/v3/Makefile b/v3/Makefile deleted file mode 100644 index 3087fdc..0000000 --- a/v3/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -.PHONY: all build clean install uninstall fmt simplify check run test - -install: - @go install main.go - -run: install - @go run main.go - -test: - @go test ./test/... \ No newline at end of file diff --git a/v3/Readme.md b/v3/Readme.md deleted file mode 100644 index 24585e1..0000000 --- a/v3/Readme.md +++ /dev/null @@ -1,32 +0,0 @@ -# Pip.Services Logo
IoC container for Golang - -This framework is a part of the [Pip.Services](https://github.com/pip-services/pip-services) project. -It provides an inversion-of-control component container to facilitate the development of composable services and applications. - -As all Pip.Services projects this framework is implemented in a variety of different languages: Java, .NET, Python, Node.js, Golang. - -The framework provides a light-weight container that can be embedded inside a service or application, or can be run by itself, -as a system process, for example. Container configuration serves as a recipe for instantiating and configuring components inside the container. -The default container factory provides generic functionality on-demand, such as logging and performance monitoring. - -- [**Container**](https://godoc.org/github.com/pip-services3-go/pip-services3-container-go/container) - Component container and container as a system process -- [**Build**](https://godoc.org/github.com/pip-services3-go/pip-services3-container-go/build) - Container default factory -- [**Config**](https://godoc.org/github.com/pip-services3-go/pip-services3-container-go/config) - Container configuration -- [**Refer**](https://godoc.org/github.com/pip-services3-go/pip-services3-container-go/refer) - Container references - -Quick Links: - -* [Downloads](https://github.com/pip-services3-go/pip-services3-container-go/blob/master/docs/Downloads.md) -* [API Reference](https://godoc.org/github.com/pip-services3-go/pip-services3-container-go/) -* [Building and Testing](https://github.com/pip-services3-go/pip-services3-container-go/blob/master/docs/Development.md) -* [Contributing](https://github.com/pip-services3-go/pip-services3-container-go/blob/master/docs/Development.md#contrib) - -## Acknowledgements - -The Golang version of Pip.Services is created and maintained by: -- **Volodymyr Tkachenko** -- **Sergey Seroukhov** -- **Mark Zontak** - -The documentation is written by: -- **Levichev Dmitry** \ No newline at end of file diff --git a/v3/build.ps1 b/v3/build.ps1 deleted file mode 100644 index 2805a3b..0000000 --- a/v3/build.ps1 +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env pwsh - -Set-StrictMode -Version latest -$ErrorActionPreference = "Stop" - -# Get component data and set necessary variables -$component = Get-Content -Path "component.json" | ConvertFrom-Json -$buildImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-build" -$container=$component.name - -# Get buildnumber from teamcity agent -$component.build = $env:BUILD_NUMBER -Set-Content -Path "component.json" -Value $($component | ConvertTo-Json) - -# Remove build files -if (Test-Path "dist") { - Remove-Item -Recurse -Force -Path "dist" -} - -# Build docker image -docker build -f docker/Dockerfile.build -t $buildImage . - -# Create and copy compiled files, then destroy -docker create --name $container $buildImage -docker cp "$($container):/go/bin" ./dist -docker rm $container - -if (!(Test-Path ./dist) -and $env:RETRY -eq $true) { - # if build failed and retries enabled run build again - Write-Host "Build failed, but retries enabled, so restarting build script again..." - ./build.ps1 -} elseif (!(Test-Path ./dist)) { - Write-Host "dist folder doesn't exist in root dir. Build failed. Watch logs above." - exit 1 -} \ No newline at end of file diff --git a/v3/build/DefaultContainerFactory.go b/v3/build/DefaultContainerFactory.go deleted file mode 100644 index c3b888c..0000000 --- a/v3/build/DefaultContainerFactory.go +++ /dev/null @@ -1,49 +0,0 @@ -package build - -/* -Creates default container components (loggers, counters, caches, locks, etc.) by their descriptors. -*/ -import ( - "github.com/pip-services3-go/pip-services3-components-go/v3/auth" - cbuild "github.com/pip-services3-go/pip-services3-components-go/v3/build" - "github.com/pip-services3-go/pip-services3-components-go/v3/cache" - "github.com/pip-services3-go/pip-services3-components-go/v3/config" - "github.com/pip-services3-go/pip-services3-components-go/v3/connect" - "github.com/pip-services3-go/pip-services3-components-go/v3/count" - "github.com/pip-services3-go/pip-services3-components-go/v3/info" - "github.com/pip-services3-go/pip-services3-components-go/v3/log" - "github.com/pip-services3-go/pip-services3-components-go/v3/test" -) - -// Create a new instance of the factory and sets nested factories. -// Returns *DefaultContainerFactory -func NewDefaultContainerFactory() *cbuild.CompositeFactory { - c := cbuild.NewCompositeFactory() - - c.Add(info.NewDefaultInfoFactory()) - c.Add(log.NewDefaultLoggerFactory()) - c.Add(count.NewDefaultCountersFactory()) - c.Add(config.NewDefaultConfigReaderFactory()) - c.Add(cache.NewDefaultCacheFactory()) - c.Add(auth.NewDefaultCredentialStoreFactory()) - c.Add(connect.NewDefaultDiscoveryFactory()) - c.Add(log.NewDefaultLoggerFactory()) - c.Add(test.NewDefaultTestFactory()) - - return c -} - -// Create a new instance of the factory and sets nested factories. -// Parameters: -// - factories ...cbuild.IFactory -// a list of nested factories -// Returns *cbuild.CompositeFactory -func NewDefaultContainerFactoryFromFactories(factories ...cbuild.IFactory) *cbuild.CompositeFactory { - c := NewDefaultContainerFactory() - - for _, factory := range factories { - c.Add(factory) - } - - return c -} diff --git a/v3/build/doc.go b/v3/build/doc.go deleted file mode 100644 index 9157608..0000000 --- a/v3/build/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -/* -The default container factory provides generic functionality on-demand, such as logging and performance monitoring. -*/ - -package build diff --git a/v3/clean.ps1 b/v3/clean.ps1 deleted file mode 100644 index f1d9f2d..0000000 --- a/v3/clean.ps1 +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env pwsh - -# Get component data and set necessary variables -$component = Get-Content -Path "component.json" | ConvertFrom-Json -$buildImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-build" -$testImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-test" -$rcImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-rc" - -# Clean up build directories -Get-ChildItem -Path "." -Include "obj" -Recurse | foreach($_) { Remove-Item -Force -Recurse $_.FullName } - -# Remove docker images -docker rmi $buildImage --force -docker rmi $testImage --force -docker rmi $rcImage --force -docker image prune --force - -# Remove existed containers -docker ps -a | Select-String -Pattern "Exit" | foreach($_) { docker rm $_.ToString().Split(" ")[0] } \ No newline at end of file diff --git a/v3/component.json b/v3/component.json deleted file mode 100644 index 540f713..0000000 --- a/v3/component.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "pip-services3-container-go", - "registry": "pip-services", - "version": "3.0.0", - "build": null -} diff --git a/v3/config/ComponentConfig.go b/v3/config/ComponentConfig.go deleted file mode 100644 index 074c107..0000000 --- a/v3/config/ComponentConfig.go +++ /dev/null @@ -1,78 +0,0 @@ -package config - -import ( - "github.com/pip-services3-go/pip-services3-commons-go/v3/config" - "github.com/pip-services3-go/pip-services3-commons-go/v3/errors" - "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - "github.com/pip-services3-go/pip-services3-commons-go/v3/reflect" -) - -/* -Configuration of a component inside a container. - -The configuration includes type information or descriptor, and component configuration parameters. -*/ -type ComponentConfig struct { - Descriptor *refer.Descriptor - Type *reflect.TypeDescriptor - Config *config.ConfigParams -} - -// Creates a new instance of the component configuration. -// Parameters: -// - descriptor *refer.Descriptor -// a components descriptor (locator). -// - config *config.ConfigParams -// component configuration parameters. -// Returns *ComponentConfig -func NewComponentConfigFromDescriptor(descriptor *refer.Descriptor, - config *config.ConfigParams) *ComponentConfig { - return &ComponentConfig{ - Descriptor: descriptor, - Config: config, - } -} - -// Creates a new instance of the component configuration. -// Parameters: -// - typ *reflect.TypeDescriptor -// a components type descriptor. -// - config *config.ConfigParams -// component configuration parameters. -// Returns *ComponentConfig -func NewComponentConfigFromType(typ *reflect.TypeDescriptor, - config *config.ConfigParams) *ComponentConfig { - return &ComponentConfig{ - Type: typ, - Config: config, - } -} - -// Creates a new instance of ComponentConfig based on section from container configuration. -// Parameters: -// - config *config.ConfigParams -// component parameters from container configuration -// Returns *ComponentConfig, error -// a newly created ComponentConfig and ConfigError when neither component descriptor or type is found. -func ReadComponentConfigFromConfig(config *config.ConfigParams) (result *ComponentConfig, err error) { - descriptor, err1 := refer.ParseDescriptorFromString(config.GetAsString("descriptor")) - if err1 != nil { - return nil, err1 - } - - typ, err2 := reflect.ParseTypeDescriptorFromString(config.GetAsString("type")) - if err2 != nil { - return nil, err2 - } - - if descriptor == nil && typ == nil { - err = errors.NewConfigError("", "BAD_CONFIG", "Component configuration must have descriptor or type") - return nil, err - } - - return &ComponentConfig{ - Descriptor: descriptor, - Type: typ, - Config: config, - }, nil -} diff --git a/v3/config/ContainerConfig.go b/v3/config/ContainerConfig.go deleted file mode 100644 index e68b89a..0000000 --- a/v3/config/ContainerConfig.go +++ /dev/null @@ -1,57 +0,0 @@ -package config - -import ( - "github.com/pip-services3-go/pip-services3-commons-go/v3/config" -) - -/* -Container configuration defined as a list of component configurations. -*/ -type ContainerConfig []*ComponentConfig - -// Creates a new instance of container configuration. -// Parameters: -// - components *ComponentConfig -// a list of component configurations. -// Returns ContainerConfig -func NewContainerConfig(components ...*ComponentConfig) ContainerConfig { - return components -} - -// Creates a new ContainerConfig object filled with key-value pairs from specified object. The value is converted into ConfigParams object which is used to create the object. -// see -// fromConfig -// Parameters: -// - value interface{} -// an object with key-value pairs used to initialize a new ContainerConfig. -// Returns ContainerConfig -// a new ContainerConfig object. -func NewContainerConfigFromValue(value interface{}) ContainerConfig { - config := config.NewConfigParamsFromValue(value) - result, _ := ReadContainerConfigFromConfig(config) - return result -} - -// Creates a new ContainerConfig object based on configuration parameters. Each section in the configuration parameters is converted into a component configuration. -// Parameters: -// - config *config.ConfigParams -// Returns ContainerConfig, error -// a new ContainerConfig object and error -func ReadContainerConfigFromConfig(config *config.ConfigParams) (ContainerConfig, error) { - if config == nil { - return []*ComponentConfig{}, nil - } - - names := config.GetSectionNames() - result := make([]*ComponentConfig, len(names)) - for i, v := range names { - c := config.GetSection(v) - componentConfig, err := ReadComponentConfigFromConfig(c) - if err != nil { - return nil, err - } - result[i] = componentConfig - } - - return result, nil -} diff --git a/v3/config/ContainerConfigReader.go b/v3/config/ContainerConfigReader.go deleted file mode 100644 index f29aef5..0000000 --- a/v3/config/ContainerConfigReader.go +++ /dev/null @@ -1,83 +0,0 @@ -package config - -import ( - "path/filepath" - - "github.com/pip-services3-go/pip-services3-commons-go/v3/config" - "github.com/pip-services3-go/pip-services3-commons-go/v3/errors" - cconfig "github.com/pip-services3-go/pip-services3-components-go/v3/config" -) - -/* -Helper class that reads container configuration from JSON or YAML file. -*/ -type TContainerConfigReader struct{} - -var ContainerConfigReader = &TContainerConfigReader{} - -// Reads container configuration from JSON or YAML file. The type of the file is determined by file extension. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// - path string -// a path to component configuration file. -// - parameters *config.ConfigParams -// values to parameters the configuration or null to skip parameterization. -// Returns ContainerConfig, error -// the read container configuration and error -func (c *TContainerConfigReader) ReadFromFile(correlationId string, - path string, parameters *config.ConfigParams) (ContainerConfig, error) { - if path == "" { - return nil, errors.NewConfigError(correlationId, "NO_PATH", "Missing config file path") - } - - ext := filepath.Ext(path) - - if ext == ".json" { - return c.ReadFromJsonFile(correlationId, path, parameters) - } - - if ext == ".yaml" || ext == ".yml" { - return c.ReadFromYamlFile(correlationId, path, parameters) - } - - return c.ReadFromJsonFile(correlationId, path, parameters) -} - -// Reads container configuration from JSON file. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// - path string -// a path to component configuration file. -// - parameters *config.ConfigParams -// values to parameters the configuration or null to skip parameterization. -// Returns ContainerConfig, error -// the read container configuration and error -func (c *TContainerConfigReader) ReadFromJsonFile(correlationId string, - path string, parameters *config.ConfigParams) (ContainerConfig, error) { - config, err := cconfig.ReadJsonConfig(correlationId, path, parameters) - if err != nil { - return nil, err - } - return ReadContainerConfigFromConfig(config) -} - -// Reads container configuration from YAML file. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// - path string -// a path to component configuration file. -// - parameters *config.ConfigParams -// values to parameters the configuration or null to skip parameterization. -// Returns ContainerConfig, error -// the read container configuration and error -func (c *TContainerConfigReader) ReadFromYamlFile(correlationId string, - path string, parameters *config.ConfigParams) (ContainerConfig, error) { - config, err := cconfig.ReadYamlConfig(correlationId, path, parameters) - if err != nil { - return nil, err - } - return ReadContainerConfigFromConfig(config) -} diff --git a/v3/config/doc.go b/v3/config/doc.go deleted file mode 100644 index 79fad83..0000000 --- a/v3/config/doc.go +++ /dev/null @@ -1,11 +0,0 @@ -/* -Container configuration serves as a recipe for instantiating and configuring components inside the container. - -External configurations (stored as YAML or JSON) are passed to the container and define the structure of objects that need to be recreated in the container. Objects can be defined in two ways: - -using descriptors (using which registered factories can recreate the object) -using hard-coded types (objects are recreated directly, based on their type, bypassing factories). -In addition, various configurations are stored for each object. The container recreates the objects and, if they implement the IConfigurable interface, passes them their configurations. -*/ - -package config diff --git a/v3/container/Container.go b/v3/container/Container.go deleted file mode 100644 index 0d8b970..0000000 --- a/v3/container/Container.go +++ /dev/null @@ -1,296 +0,0 @@ -package container - -import ( - cconfig "github.com/pip-services3-go/pip-services3-commons-go/v3/config" - "github.com/pip-services3-go/pip-services3-commons-go/v3/errors" - crefer "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - cbuild "github.com/pip-services3-go/pip-services3-components-go/v3/build" - "github.com/pip-services3-go/pip-services3-components-go/v3/info" - "github.com/pip-services3-go/pip-services3-components-go/v3/log" - "github.com/pip-services3-go/pip-services3-container-go/v3/build" - "github.com/pip-services3-go/pip-services3-container-go/v3/config" - "github.com/pip-services3-go/pip-services3-container-go/v3/refer" -) - -/* -Inversion of control (IoC) container that creates components and manages their lifecycle. - -The container is driven by configuration, that usually stored in JSON or YAML file. The configuration contains a list of components identified by type or locator, followed by component configuration. - -On container start it performs the following actions: - -Creates components using their types or calls registered factories to create components using their locators -Configures components that implement IConfigurable interface and passes them their configuration parameters -Sets references to components that implement IReferenceable interface and passes them references of all components in the container -Opens components that implement IOpenable interface -On container stop actions are performed in reversed order: - -Closes components that implement ICloseable interface -Unsets references in components that implement IUnreferenceable interface -Destroys components in the container. -The component configuration can be parameterized by dynamic values. That allows specialized containers to inject parameters from command line or from environment variables. - -The container automatically creates a ContextInfo component that carries detail information about the container and makes it available for other components. - -see -IConfigurable (in the PipServices "Commons" package) - -see -IReferenceable (in the PipServices "Commons" package) - -see -IOpenable (in the PipServices "Commons" package) - -Configuration parameters -name: the context (container or process) name -description: human-readable description of the context -properties: entire section of additional descriptive properties - - ... -Example -======= config.yml ======== -- descriptor: mygroup:mycomponent1:default:default:1.0 - param1: 123 - param2: ABC - -- type: mycomponent2,mypackage - param1: 321 - param2: XYZ -============================ - -container := NewEmptyContainer(); -container.AddFactory(newMyComponentFactory()); - -parameters := NewConfigParamsFromValue(process.env); -container.ReadConfigFromFile("123", "./config/config.yml", parameters); - -container.Open("123", (err) => { - console.Log("Container is opened"); - ... - container.Close("123", (err) => { - console.Log("Container is closed"); - }); -}); -*/ -type Container struct { - logger log.ILogger - factories *cbuild.CompositeFactory - info *info.ContextInfo - config config.ContainerConfig - references *refer.ContainerReferences - referenceable crefer.IReferenceable - unreferenceable crefer.IUnreferenceable -} - -// Creates a new empty instance of the container. -// Returns *Container -func NewEmptyContainer() *Container { - return &Container{ - logger: log.NewNullLogger(), - factories: build.NewDefaultContainerFactory(), - info: info.NewContextInfo(), - } -} - -// Creates a new instance of the container. -// Parameters: -// - name string -// a container name (accessible via ContextInfo) -// - description string -// a container description (accessible via ContextInfo) -// Returns *Container -func NewContainer(name string, description string) *Container { - c := NewEmptyContainer() - - c.info.Name = name - c.info.Description = description - - return c -} - -// Creates a new instance of the container inherit from reference. -// Parameters: -// - name string -// a container name (accessible via ContextInfo) -// - description string -// a container description (accessible via ContextInfo) -// - referenceable crefer.IReferenceable -// - referenceble object for inherit -// Returns *Container -func InheritContainer(name string, description string, - referenceable crefer.IReferenceable) *Container { - c := NewEmptyContainer() - - c.info.Name = name - c.info.Description = description - c.referenceable = referenceable - c.unreferenceable, _ = referenceable.(crefer.IUnreferenceable) - - return c -} - -// Configures component by passing configuration parameters. -// Parameters: -// - config *cconfig.ConfigParams -// configuration parameters to be set. -func (c *Container) Configure(conf *cconfig.ConfigParams) { - c.config, _ = config.ReadContainerConfigFromConfig(conf) -} - -// Reads container configuration from JSON or YAML file and parameterizes it with given values. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// - path string -// a path to configuration file -// - parameters *cconfig.ConfigParams -// values to parameters the configuration or null to skip parameterization. -func (c *Container) ReadConfigFromFile(correlationId string, - path string, parameters *cconfig.ConfigParams) error { - - var err error - c.config, err = config.ContainerConfigReader.ReadFromFile(correlationId, path, parameters) - //c.logger.Trace(correlationId, config.String()) - return err -} - -func (c *Container) initReferences(references crefer.IReferences) { - existingInfo, ok := references.GetOneOptional( - crefer.NewDescriptor("pip-services", "context-info", "*", "*", "1.0"), - ).(*info.ContextInfo) - if !ok { - references.Put( - crefer.NewDescriptor("pip-services", "context-info", "default", "default", "1.0"), - c.info, - ) - } else { - c.info = existingInfo - } - - references.Put( - crefer.NewDescriptor("pip-services", "factory", "container", "default", "1.0"), - c.factories, - ) -} - -func (c *Container) Logger() log.ILogger { - return c.logger -} - -func (c *Container) SetLogger(logger log.ILogger) { - c.logger = logger -} - -func (c *Container) Info() *info.ContextInfo { - return c.info -} - -// Adds a factory to the container. The factory is used to create components added to the container by their locators (descriptors). -// Parameters: -// - factory IFactory -// a component factory to be added. -func (c *Container) AddFactory(factory cbuild.IFactory) { - c.factories.Add(factory) -} - -// Checks if the component is opened. -// Returns bool -// true if the component has been opened and false otherwise. -func (c *Container) IsOpen() bool { - return c.references != nil -} - -// Opens the component. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// Returns error -func (c *Container) Open(correlationId string) error { - var err error - - if c.references != nil { - return errors.NewInvalidStateError( - correlationId, "ALREADY_OPENED", "Container was already opened", - ) - } - - defer func() { - if r := recover(); r != nil { - err, _ = r.(error) - c.logger.Error(correlationId, err, "Failed to start container") - c.Close(correlationId) - } - }() - - c.logger.Trace(correlationId, "Starting container.") - - // Create references with configured components - c.references = refer.NewContainerReferences() - c.initReferences(c.references) - c.references.PutFromConfig(c.config) - - if c.referenceable != nil { - c.referenceable.SetReferences(c.references) - } - - // Get custom description if available - infoDescriptor := crefer.NewDescriptor("*", "context-info", "*", "*", "*") - info, ok := c.references.GetOneOptional(infoDescriptor).(*info.ContextInfo) - if ok { - c.info = info - } - - // Get reference to logger - c.logger = log.NewCompositeLoggerFromReferences(c.references) - - // Open references - err = c.references.Open(correlationId) - if err == nil { - c.logger.Info(correlationId, "Container %s started", c.info.Name) - } else { - c.logger.Fatal(correlationId, err, "Failed to start container") - c.Close(correlationId) - } - - return err -} - -// Closes component and frees used resources. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// Returns error -func (c *Container) Close(correlationId string) error { - // Skip if container wasn't opened - if c.references == nil { - return nil - } - - var err error - - defer func() { - if r := recover(); r != nil { - err, _ = r.(error) - c.logger.Error(correlationId, err, "Failed to stop container") - } - }() - - c.logger.Trace(correlationId, "Stopping %s container", c.info.Name) - - // Unset references for child container - if c.unreferenceable != nil { - c.unreferenceable.UnsetReferences() - } - - // Close and dereference components - err = c.references.Close(correlationId) - - c.references = nil - - if err == nil { - c.logger.Info(correlationId, "Container %s stopped", c.info.Name) - } else { - c.logger.Error(correlationId, err, "Failed to stop container") - } - - return err -} diff --git a/v3/container/ProcessContainer.go b/v3/container/ProcessContainer.go deleted file mode 100644 index 803f5e0..0000000 --- a/v3/container/ProcessContainer.go +++ /dev/null @@ -1,213 +0,0 @@ -package container - -import ( - "fmt" - "os" - "os/signal" - "strings" - "time" - - cconfig "github.com/pip-services3-go/pip-services3-commons-go/v3/config" - crefer "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - "github.com/pip-services3-go/pip-services3-components-go/v3/log" -) - -/* -Inversion of control (IoC) container that runs as a system process. It processes command line arguments and handles unhandled exceptions and Ctrl-C signal to gracefully shutdown the container. - -Command line arguments ---config / -c path to JSON or YAML file with container configuration (default: "./config/config.yml") ---param / --params / -p value(s) to parameterize the container configuration ---help / -h prints the container usage help -see -Container - -Example -container = NewEmptyProcessContainer(); -container.Container.AddFactory(NewMyComponentFactory()); - -container.Run(process.args); -*/ -type ProcessContainer struct { - Container - configPath string -} - -// Creates a new empty instance of the container. -// Returns ProcessContainer -func NewEmptyProcessContainer() *ProcessContainer { - c := &ProcessContainer{ - Container: *NewEmptyContainer(), - configPath: "./config/config.yml", - } - c.SetLogger(log.NewConsoleLogger()) - return c -} - -// Creates a new instance of the container. -// Parameters: -// - name string -// a container name (accessible via ContextInfo) -// - description string -// a container description (accessible via ContextInfo) -// Returns ProcessContainer -func NewProcessContainer(name string, description string) *ProcessContainer { - c := &ProcessContainer{ - Container: *NewContainer(name, description), - configPath: "./config/config.yml", - } - c.SetLogger(log.NewConsoleLogger()) - return c -} - -// Creates a new instance of the container inherit from reference. -// Parameters: -// - name string -// a container name (accessible via ContextInfo) -// - description string -// a container description (accessible via ContextInfo) -// - referenceable crefer.IReferenceable -// - referenceble object for inherit -// Returns *Container -func InheritProcessContainer(name string, description string, - referenceable crefer.IReferenceable) *ProcessContainer { - c := &ProcessContainer{ - Container: *InheritContainer(name, description, referenceable), - configPath: "./config/config.yml", - } - c.SetLogger(log.NewConsoleLogger()) - return c -} - -// Set path for configuration file -func (c *ProcessContainer) SetConfigPath(configPath string) { - c.configPath = configPath -} - -func (c *ProcessContainer) getConfigPath(args []string) string { - for index, arg := range args { - nextArg := "" - if index < len(args)-1 { - nextArg = args[index+1] - if strings.HasPrefix(nextArg, "-") { - nextArg = "" - } - } - - if arg == "--config" || arg == "-c" { - return nextArg - } - } - - return c.configPath -} - -func (c *ProcessContainer) getParameters(args []string) *cconfig.ConfigParams { - line := "" - - for index := 0; index < len(args); index++ { - arg := args[index] - nextArg := "" - if index < len(args)-1 { - nextArg = args[index+1] - if strings.HasPrefix(nextArg, "-") { - nextArg = "" - } - } - - if nextArg != "" { - if arg == "--param" || arg == "--params" || arg == "-p" { - if line != "" { - line = line + ";" - } - line = line + nextArg - index++ - } - } - } - - parameters := cconfig.NewConfigParamsFromString(line) - - for _, e := range os.Environ() { - env := strings.Split(e, "=") - parameters.SetAsObject(env[0], env[1]) - } - - return parameters -} - -func (c *ProcessContainer) showHelp(args []string) bool { - for _, arg := range args { - if arg == "--help" || arg == "-h" { - return true - } - } - return false -} - -func (c *ProcessContainer) printHelp() { - fmt.Println("Pip.Services process container - http://www.github.com/pip-services/pip-services") - fmt.Println("run [-h] [-c ] [-p =]*") -} - -func (c *ProcessContainer) captureErrors(correlationId string) { - if r := recover(); r != nil { - err, _ := r.(error) - c.Logger().Fatal(correlationId, err, "Process is terminated") - os.Exit(1) - } -} - -func (c *ProcessContainer) captureExit(correlationId string) { - c.Logger().Info(correlationId, "Press Control-C to stop the microservice...") - - ch := make(chan os.Signal) - signal.Notify(ch, os.Interrupt) - - go func() { - select { - case <-ch: - c.Close(correlationId) - c.Logger().Info(correlationId, "Googbye!") - os.Exit(0) - } - }() -} - -// Runs the container by instantiating and running components inside the container. -// It reads the container configuration, creates, configures, references and opens components. On process exit it closes, unreferences and destroys components to gracefully shutdown. -// Parameters: -// - args []string -// command line arguments -func (c *ProcessContainer) Run(args []string) { - if c.showHelp(args) { - c.printHelp() - os.Exit(0) - return - } - - correlationId := c.Info().Name - path := c.getConfigPath(args) - parameters := c.getParameters(args) - - err := c.ReadConfigFromFile(correlationId, path, parameters) - if err != nil { - c.Logger().Fatal(correlationId, err, "Process is terminated") - os.Exit(1) - return - } - - defer c.captureErrors(correlationId) - c.captureExit(correlationId) - - err = c.Open(correlationId) - if err != nil { - c.Logger().Fatal(correlationId, err, "Process is terminated") - os.Exit(1) - return - } - - for { - time.Sleep(100) - } -} diff --git a/v3/container/doc.go b/v3/container/doc.go deleted file mode 100644 index 99e3d55..0000000 --- a/v3/container/doc.go +++ /dev/null @@ -1,22 +0,0 @@ -/* -Contains implementation of the inversion of control container, which creates objects and controls their lifecycle(*) using various configurations. - -Using generic containers, we can create more specialized containers – one of which is the process container. It represents a system process, receives its configuration file via the command line, and creates -a container, starts it, reads its configuration, recreates objects, runs them, and then, after pressing ctrl-c, turns off and destroys the objects. - -Another example of containers are lambda functions, service fabric containers, and so on. - -(*) Compont lifecycle: -External configurations (stored as YAML or JSON) are passed to the container and define the structure of objects that need to be recreated in the container. Objects can be defined in two ways: - -using descriptors (using which registered factories can recreate the object) -using hard-coded types (objects are recreated directly, based on their type, bypassing factories). -In addition, various configurations are stored for each object. The container recreates the objects and, if they implement the IConfigurable interface, passes them their configurations. - -Once the objects of a container are configured, if they implement the IReferencable interface, they are passed a set of references for recreating links between objects in the container. If objects implement the -IOpenable interface, the open() method is called and they start to work. Connections to various services are made, after which the objects start, -the container starts running, and the objects carry out their tasks. When the container starts to close, the objects that implement the ICloseable interface are closed via their close() method (which should make - them stop working and disconnect from other services), after which objects that implement the IUnreferencable interface delete various links between objects, and, finally, the contains destroys all objects and turns off. -*/ - -package container diff --git a/v3/docker/Dockerfile.build b/v3/docker/Dockerfile.build deleted file mode 100644 index a5ebca3..0000000 --- a/v3/docker/Dockerfile.build +++ /dev/null @@ -1,21 +0,0 @@ -# golang image where workspace (GOPATH) configured at /go. -FROM golang:1.12 - -# Setting up working directory -WORKDIR /app - -# Copy project dependencies -ADD ./go.* ./ - -# Restore dependencies -ENV GO111MODULE=on -RUN go mod download - -# Copy the local package files to the container's workspace -ADD . . - -# Build the main binary -RUN go build -o /go/bin/run . - - - diff --git a/v3/docker/Dockerfile.test b/v3/docker/Dockerfile.test deleted file mode 100644 index 410d0a6..0000000 --- a/v3/docker/Dockerfile.test +++ /dev/null @@ -1,15 +0,0 @@ -# golang image where workspace (GOPATH) configured at /go. -FROM golang:1.12 - -# Setting up working directory -WORKDIR /app - -# Copy project dependencies -ADD ./go.* ./ - -# Restore dependencies -ENV GO111MODULE=on -RUN go mod download - -# Copy the local package files to the container's workspace -ADD . . diff --git a/v3/docker/docker-compose.test.yml b/v3/docker/docker-compose.test.yml deleted file mode 100644 index 699e147..0000000 --- a/v3/docker/docker-compose.test.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: '3.3' - -services: - - test: - build: - context: .. - dockerfile: docker/Dockerfile.test - image: ${IMAGE:-pip/test} - command: ${TEST_CMD:-go test ./test/...} diff --git a/v3/docs/Development.md b/v3/docs/Development.md deleted file mode 100644 index 612aed3..0000000 --- a/v3/docs/Development.md +++ /dev/null @@ -1,103 +0,0 @@ -# Development and Testing Guide
Pip.Services Container for Golang - -This document provides high-level instructions on how to build and test the microservice. - -* [Environment Setup](#setup) -* [Installing](#install) -* [Building](#build) -* [Testing](#test) -* [Release](#release) -* [Contributing](#contrib) - -## Environment Setup - -This is a Golang project and you have to install Golang tools. -You can download them from official Golang website: https://golang.org/dl/ - -After go is installed you can check it by running the following command: -```bash -go version -``` - -To work with GitHub code repository you need to install Git from: https://git-scm.com/downloads - -If you are planning to develop and test using persistent storages other than flat files -you may need to install database servers: -- Download and install MongoDB database from https://www.mongodb.org/downloads - -## Installing - -After your environment is ready you can check out source code from the Github repository: -```bash -git clone git@github.com:pip-services/pip-services-container-go.git -``` - -If you worked with the microservice before you can check out latest changes and update the dependencies: -```bash -# Enable modules -go mod init mod - -# Update source code updates from github -go get -u - -## Building - -The commons is written in Golang language which is transcompiled into JavaScript. -So, if you make changes to the source code you need to compile it before running or committing to github. -The process will output compiled javascript files into /bin folder. - -```bash -go buld -``` - -## Testing - -Before you execute tests you need to set configuration options in config.yaml file. -As a starting point you can use example from config.example.json: - -```bash -copy config/config.example.yaml config/config.yaml -``` - -After that check all configuration options. Specifically, pay attention to connection options -for database and dependent microservices. For more information check [Configuration Guide](Configuration.md) - -Command to run unit tests and benchmarks as: -```bash -go test -``` - -## Release - -Formal release process consistents of few steps. -First of all it is required to tag guthub repository with a version number: - -```bash -git commit -m "Emphasize our friendliness" testmod.go -git tag v1.0.1 -git push --tags origin v1 -``` - -Microservice releases additionally require generation and publishing -binary packages at http://downloads.pipservices.org - - -## Contributing - -Developers interested in contributing should read the following instructions: - -- [How to Contribute](http://www.pipservices.org/contribute/) -- [Guidelines](http://www.pipservices.org/contribute/guidelines) -- [Styleguide](http://www.pipservices.org/contribute/styleguide) -- [ChangeLog](../CHANGELOG.md) - -> Please do **not** ask general questions in an issue. Issues are only to report bugs, request - enhancements, or request new features. For general questions and discussions, use the - [Contributors Forum](http://www.pipservices.org/forums/forum/contributors/). - -It is important to note that for each release, the [ChangeLog](../CHANGELOG.md) is a resource that will -itemize all: - -- Bug Fixes -- New Features -- Breaking Changes \ No newline at end of file diff --git a/v3/docs/Downloads.md b/v3/docs/Downloads.md deleted file mode 100644 index 7cf3d39..0000000 --- a/v3/docs/Downloads.md +++ /dev/null @@ -1,19 +0,0 @@ -# Pip.Services Container for Golang Downloads - -Binary releases of the container are available through GIT global repository. -To use the container you can either include dependency into your go file: - -```golang - - ... - import ( - cauth "github.com/pip-services3-go/pip-services3-container-go/v3/auth" - ) - -``` - -Source code can be checked out from github repository: - -```bash -git clone git@github.com:pip-services-go/pip-services-container-go.git -``` \ No newline at end of file diff --git a/v3/examples/DummyController.go b/v3/examples/DummyController.go deleted file mode 100644 index 73ec587..0000000 --- a/v3/examples/DummyController.go +++ /dev/null @@ -1,72 +0,0 @@ -package examples - -import ( - "github.com/pip-services3-go/pip-services3-commons-go/v3/config" - "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - "github.com/pip-services3-go/pip-services3-commons-go/v3/run" - "github.com/pip-services3-go/pip-services3-components-go/v3/log" -) - -type DummyController struct { - timer *run.FixedRateTimer - logger *log.CompositeLogger - message string - counter int -} - -func NewDummyController() *DummyController { - c := &DummyController { - logger: log.NewCompositeLogger(), - message: "Hello World!", - counter: 0, - } - - c.timer = run.NewFixedRateTimerFromTask(c, 1000, 1000) - - return c -} - -func (c *DummyController) Message() string { - return c.message -} - -func (c *DummyController) SetMessage(value string) { - c.message = value -} - -func (c *DummyController) Counter() int { - return c.counter -} - -func (c *DummyController) SetCounter(value int) { - c.counter = value -} - -func (c *DummyController) Configure(config *config.ConfigParams) { - c.message = config.GetAsStringWithDefault("message", c.message) -} - -func (c *DummyController) SetReferences(references refer.IReferences) { - c.logger.SetReferences(references) -} - -func (c *DummyController) IsOpen() bool { - return c.timer.IsStarted() -} - -func (c *DummyController) Open(correlationId string) error { - c.timer.Start() - c.logger.Trace(correlationId, "Dummy controller opened") - return nil -} - -func (c *DummyController) Close(correlationId string) error { - c.timer.Stop() - c.logger.Trace(correlationId, "Dummy controller closed") - return nil -} - -func (c *DummyController) Notify(correlationId string, args *run.Parameters) { - c.logger.Info(correlationId, "%d - %s", c.counter, c.message) - c.counter++ -} \ No newline at end of file diff --git a/v3/examples/DummyFactory.go b/v3/examples/DummyFactory.go deleted file mode 100644 index e902276..0000000 --- a/v3/examples/DummyFactory.go +++ /dev/null @@ -1,16 +0,0 @@ -package examples - -import ( - "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - "github.com/pip-services3-go/pip-services3-components-go/v3/build" -) - -var ControllerDescriptor = refer.NewDescriptor("pip-services-dummies", "controller", "default", "*", "1.0") - -func NewDummyFactory() *build.Factory { - factory := build.NewFactory() - - factory.RegisterType(ControllerDescriptor, NewDummyController) - - return factory -} diff --git a/v3/examples/DummyProcess.go b/v3/examples/DummyProcess.go deleted file mode 100644 index a964c21..0000000 --- a/v3/examples/DummyProcess.go +++ /dev/null @@ -1,10 +0,0 @@ -package examples - -import "github.com/pip-services3-go/pip-services3-container-go/v3/container" - -func NewDummyProcess() *container.ProcessContainer { - c := container.NewProcessContainer("dummy", "Sample dummy process") - c.SetConfigPath("./examples/dummy.yaml") - c.AddFactory(NewDummyFactory()) - return c -} \ No newline at end of file diff --git a/v3/examples/dummy.yaml b/v3/examples/dummy.yaml deleted file mode 100644 index 8845031..0000000 --- a/v3/examples/dummy.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- descriptor: "pip-services:logger:console:default:1.0" - level: "trace" - -- descriptor: "pip-services:shutdown:default:default:1.0" - mode: exception - min_timeout: 3000 - max_timeout: 10000 - -- descriptor: "pip-services-dummies:controller:default:ctrl1:1.0" - message: "Hello {{ USER }} from dummy controller #1" - -#- type: "DummyController,./obj/examples/DummyController" -- descriptor: "pip-services-dummies:controller:default:ctrl2:1.0" - message: "Hello {{ USER }} from dummy controller #2" - -{{#THIRD_CONTROLLER}} -#- type: "DummyController,./obj/examples/DummyController" -- descriptor: "pip-services-dummies:controller:default:ctrl3:1.0" - message: "Hello {{ USER }} from dummy controller #3" -{{/THIRD_CONTROLLER}} \ No newline at end of file diff --git a/v3/go.mod b/v3/go.mod deleted file mode 100644 index f308bf3..0000000 --- a/v3/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/pip-services3-go/pip-services3-container-go/v3 - -go 1.12 - -require ( - github.com/pip-services3-go/pip-services3-commons-go/v3 v3.0.0 - github.com/pip-services3-go/pip-services3-components-go/v3 v3.0.0 - github.com/stretchr/testify v1.3.0 -) diff --git a/v3/go.sum b/v3/go.sum deleted file mode 100644 index 0621dbc..0000000 --- a/v3/go.sum +++ /dev/null @@ -1,25 +0,0 @@ -github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0= -github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pip-services3-go/pip-services3-commons-go v0.0.0-20190804203000-6456cc90b324 h1:mLft5fZNFNKmURq6Hx5rc+T4Syj5gpYWjoiSGAES0/Y= -github.com/pip-services3-go/pip-services3-commons-go v0.0.0-20190804203000-6456cc90b324/go.mod h1:bcPnEp+IIvYa4zP4Qb6E6VYM9ByV7qcSSrq6yL2GQlo= -github.com/pip-services3-go/pip-services3-components-go v0.0.0-20190807202040-060944d786b8 h1:/IlbSI9RksTUURVhrcmf3zIxv2q7wxUiWHlQxW5qJe4= -github.com/pip-services3-go/pip-services3-components-go v0.0.0-20190807202040-060944d786b8/go.mod h1:HXw/ZY1ptv0WEICtazRu6ZeWjtmn90maApMBGfzRj8I= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/v3/index.go.bak b/v3/index.go.bak deleted file mode 100644 index b840e91..0000000 --- a/v3/index.go.bak +++ /dev/null @@ -1,7 +0,0 @@ -package container - -import ( - _ "github.com/pip-services3-go/pip-services3-container-go/v3/build" - _ "github.com/pip-services3-go/pip-services3-container-go/v3/config" - _ "github.com/pip-services3-go/pip-services3-container-go/v3/refer" -) \ No newline at end of file diff --git a/v3/main.go b/v3/main.go deleted file mode 100644 index 4900263..0000000 --- a/v3/main.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "os" - "github.com/pip-services3-go/pip-services3-container-go/v3/examples" -) - -func main() { - process := examples.NewDummyProcess() - process.Run(os.Args) -} \ No newline at end of file diff --git a/v3/refer/BuildReferencesDecorator.go b/v3/refer/BuildReferencesDecorator.go deleted file mode 100644 index 1597d4a..0000000 --- a/v3/refer/BuildReferencesDecorator.go +++ /dev/null @@ -1,215 +0,0 @@ -package refer - -import ( - "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - crefer "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - "github.com/pip-services3-go/pip-services3-components-go/v3/build" -) - -/* -References decorator that automatically creates missing components using available -component factories upon component retrival. -*/ -type BuildReferencesDecorator struct { - ReferencesDecorator -} - -// Creates a new instance of the decorator. -// Parameters: -// - nextReferences crefer.IReferences -// the next references or decorator in the chain. -// - topReferences IReferences -// the decorator at the top of the chain. -// Returns *BuildReferencesDecorator -func NewBuildReferencesDecorator(nextReferences crefer.IReferences, - topReferences crefer.IReferences) *BuildReferencesDecorator { - return &BuildReferencesDecorator{ - ReferencesDecorator: *NewReferencesDecorator(nextReferences, topReferences), - } -} - -// Finds a factory capable creating component by given descriptor from the components registered in the -// references. -// Parameters: -// - locator interface{} -// a locator of component to be created. -// Returns build.IFactory -// found factory or nil if factory was not found. -func (c *BuildReferencesDecorator) FindFactory(locator interface{}) build.IFactory { - components := c.GetAll() - - for _, component := range components { - factory, ok := component.(build.IFactory) - if ok && factory.CanCreate(locator) != nil { - return factory - } - } - - return nil -} - -// Creates a component identified by given locator. -// throws -// a CreateEerror if the factory is not able to create the component. -// see -// findFactory -// Parameters: -// - locator interface{} -// a locator to identify component to be created. -// - factory build.IFactory -// a factory that shall create the component. -// Returns interface{} -// the created component. -func (c *BuildReferencesDecorator) Create(locator interface{}, - factory build.IFactory) interface{} { - - if factory == nil { - return nil - } - - var result interface{} - - defer func() { - recover() - }() - - result, _ = factory.Create(locator) - - return result -} - -// Clarifies a component locator by merging two descriptors into one to replace missing fields. -// That allows to get a more complete descriptor that includes all possible fields. -// Parameters: -// - locator intrface{} -// a component locator to clarify. -// - factory build.IFactory -// a factory that shall create the component. -// Returns interface{} -// clarified component descriptor (locator) -func (c *BuildReferencesDecorator) ClarifyLocator(locator interface{}, - factory build.IFactory) interface{} { - - if factory == nil { - return nil - } - - descriptor, ok := locator.(*refer.Descriptor) - if !ok { - return locator - } - - anotherLocator := factory.CanCreate(locator) - anotherDescriptor, ok1 := anotherLocator.(*refer.Descriptor) - if !ok1 { - return locator - } - - group := descriptor.Group() - if group == "" { - group = anotherDescriptor.Group() - } - typ := descriptor.Type() - if typ == "" { - typ = anotherDescriptor.Type() - } - kind := descriptor.Kind() - if kind == "" { - kind = anotherDescriptor.Kind() - } - name := descriptor.Name() - if name == "" { - name = anotherDescriptor.Name() - } - version := descriptor.Version() - if version == "" { - version = anotherDescriptor.Version() - } - - return refer.NewDescriptor(group, typ, kind, name, version) -} - -// Gets an optional component reference that matches specified locator. -// Parameters: -// - locator interface{} -// the locator to find references by. -// Returns interface{} -// a matching component reference or nil if nothing was found. -func (c *BuildReferencesDecorator) GetOneOptional(locator interface{}) interface{} { - components, err := c.Find(locator, false) - if err != nil || len(components) == 0 { - return nil - } - return components[0] -} - -// Gets a required component reference that matches specified locator. -// throws -// a [[ReferenceException]] when no references found. -// Parameters: -// - locator interface{} -// the locator to find a reference by. -// Returns interface{}, error -// a matching component reference and error. -func (c *BuildReferencesDecorator) GetOneRequired(locator interface{}) (interface{}, error) { - components, err := c.Find(locator, true) - if err != nil || len(components) == 0 { - return nil, err - } - return components[0], nil -} - -// Gets all component references that match specified locator. -// Parameters: -// - locator interface{} -// the locator to find references by. -// Returns []interface{} -// a list with matching component references or empty list if nothing was found. -func (c *BuildReferencesDecorator) GetOptional(locator interface{}) []interface{} { - components, _ := c.Find(locator, false) - return components -} - -// Gets all component references that match specified locator. At least one component reference must be present. -// If it doesn't the method throws an error. -// throws -// a [[ReferenceException]] when no references found. -// Parameters: -// - locator interface{} -// the locator to find references by. -// Returns []interface{}, erorr -// a list with matching component references and error. -func (c *BuildReferencesDecorator) GetRequired(locator interface{}) ([]interface{}, error) { - return c.Find(locator, true) -} - -// Gets all component references that match specified locator. -// throws -// a [[ReferenceError]] when required is set to true but no references found. -// Parameters: -// - locator interface -// the locator to find a reference by. -// - required bool -// forces to raise an exception if no reference is found. -// Returns []interface, error -// a list with matching component references and error. -func (c *BuildReferencesDecorator) Find(locator interface{}, required bool) ([]interface{}, error) { - components, _ := c.ReferencesDecorator.Find(locator, required) - - if required && len(components) == 0 { - factory := c.FindFactory(locator) - component := c.Create(locator, factory) - if component != nil { - locator = c.ClarifyLocator(locator, factory) - c.ReferencesDecorator.TopReferences.Put(locator, component) - components = append(components, component) - } - } - - if required && len(components) == 0 { - err := refer.NewReferenceError("", locator) - return nil, err - } - - return components, nil -} diff --git a/v3/refer/ContainerReferences.go b/v3/refer/ContainerReferences.go deleted file mode 100644 index d78ddcb..0000000 --- a/v3/refer/ContainerReferences.go +++ /dev/null @@ -1,91 +0,0 @@ -package refer - -import ( - "fmt" - - cconfig "github.com/pip-services3-go/pip-services3-commons-go/v3/config" - "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - "github.com/pip-services3-go/pip-services3-commons-go/v3/reflect" - "github.com/pip-services3-go/pip-services3-components-go/v3/build" - "github.com/pip-services3-go/pip-services3-container-go/v3/config" -) - -/* -Container managed references that can be created from container configuration. -*/ -type ContainerReferences struct { - ManagedReferences -} - -// Creates a new instance of the references -// Returns *ContainerReferences -func NewContainerReferences() *ContainerReferences { - return &ContainerReferences{ - ManagedReferences: *NewEmptyManagedReferences(), - } -} - -// Puts components into the references from container configuration. -// Parameters: -// - config config.ContainerConfig -// a container configuration with information of components to be added. -// Returns error -// CreateError when one of component cannot be created. -func (c *ContainerReferences) PutFromConfig(config config.ContainerConfig) error { - var err error - var locator interface{} - var component interface{} - - defer func() { - if r := recover(); r != nil { - err, _ = r.(error) - } - }() - - for _, componentConfig := range config { - if componentConfig.Type != nil { - // Create component dynamically - locator = componentConfig.Type - component, err = reflect.TypeReflector.CreateInstanceByDescriptor(componentConfig.Type) - } else if componentConfig.Descriptor != nil { - // Or create component statically - locator = componentConfig.Descriptor - factory := c.ManagedReferences.Builder.FindFactory(locator) - component = c.ManagedReferences.Builder.Create(locator, factory) - if component == nil { - return refer.NewReferenceError("", locator) - } - locator = c.ManagedReferences.Builder.ClarifyLocator(locator, factory) - } - - // Check that component was created - if component == nil { - return build.NewCreateError( - "CANNOT_CREATE_COMPONENT", - "Cannot create component", - ).WithDetails("config", config) - } - - fmt.Printf("Created component %v\n", locator) - - // Add component to the list - c.ManagedReferences.References.Put(locator, component) - - // Configure component - configurable, ok := component.(cconfig.IConfigurable) - if ok { - configurable.Configure(componentConfig.Config) - } - - // Set references to factories - _, ok = component.(build.IFactory) - if ok { - referenceable, ok := component.(refer.IReferenceable) - if ok { - referenceable.SetReferences(c) - } - } - } - - return err -} diff --git a/v3/refer/LinkReferencesDecorator.go b/v3/refer/LinkReferencesDecorator.go deleted file mode 100644 index d5103d7..0000000 --- a/v3/refer/LinkReferencesDecorator.go +++ /dev/null @@ -1,112 +0,0 @@ -package refer - -import ( - crefer "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" -) - -/* -References decorator that automatically sets references to newly added components that implement IReferenceable -interface and unsets references from removed components that implement IUnreferenceable interface. -*/ -type LinkReferencesDecorator struct { - ReferencesDecorator - opened bool -} - -// Creates a new instance of the decorator. -// Parameters: -// - nextReferences crefer.IReferences -// the next references or decorator in the chain. -// - topReferences crefer.IReferences -// the decorator at the top of the chain. -// Returns *LinkReferencesDecorator -func NewLinkReferencesDecorator(nextReferences crefer.IReferences, - topReferences crefer.IReferences) *LinkReferencesDecorator { - return &LinkReferencesDecorator{ - ReferencesDecorator: *NewReferencesDecorator(nextReferences, topReferences), - } -} - -// Checks if the component is opened. -// Returns bool -// true if the component has been opened and false otherwise. -func (c *LinkReferencesDecorator) IsOpen() bool { - return c.opened -} - -// Opens the component. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// Returns error -func (c *LinkReferencesDecorator) Open(correlationId string) error { - if !c.opened { - c.opened = true - components := c.GetAll() - crefer.Referencer.SetReferences(c.ReferencesDecorator.TopReferences, components) - } - return nil -} - -// Closes component and frees used resources. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// Returns error -func (c *LinkReferencesDecorator) Close(correlationId string) error { - if c.opened { - c.opened = false - components := c.GetAll() - crefer.Referencer.UnsetReferences(components) - } - return nil -} - -// Puts a new reference into this reference map. -// Parameters: -// - locator intrface{} -// a locator to find the reference by. -// - component interface{} -// a component reference to be added. -func (c *LinkReferencesDecorator) Put(locator interface{}, component interface{}) { - c.ReferencesDecorator.Put(locator, component) - - if c.opened { - crefer.Referencer.SetReferencesForOne(c.ReferencesDecorator.TopReferences, component) - } -} - -// Removes a previously added reference that matches specified locator. If many references match the locator, it removes only the first one. -// When all references shall be removed, use removeAll method instead. -// see -// removeAll -// Parameters: -// - locator interface -// a locator to remove reference -// Returns interface{} -// the removed component reference. -func (c *LinkReferencesDecorator) Remove(locator interface{}) interface{} { - component := c.ReferencesDecorator.Remove(locator) - - if c.opened { - crefer.Referencer.UnsetReferencesForOne(component) - } - - return component -} - -// Removes all component references that match the specified locator. -// Parameters: -// -locator interface{} -// the locator to remove references by. -// Returns []interface{} -// a list, containing all removed references. -func (c *LinkReferencesDecorator) RemoveAll(locator interface{}) []interface{} { - components := c.NextReferences.RemoveAll(locator) - - if c.opened { - crefer.Referencer.UnsetReferences(components) - } - - return components -} diff --git a/v3/refer/ManagedReferences.go b/v3/refer/ManagedReferences.go deleted file mode 100644 index 7848cc5..0000000 --- a/v3/refer/ManagedReferences.go +++ /dev/null @@ -1,90 +0,0 @@ -package refer - -import ( - crefer "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" -) - -/* -Managed references that in addition to keeping and locating references can also manage their lifecycle: - -Auto-creation of missing component using available factories -Auto-linking newly added components -Auto-opening newly added components -Auto-closing removed components -*/ -type ManagedReferences struct { - ReferencesDecorator - References *crefer.References - Builder *BuildReferencesDecorator - Linker *LinkReferencesDecorator - Runner *RunReferencesDecorator -} - -// Creates a new instance of the references -// Parameters: -// - tuples []interface{} -// tuples where odd values are component locators (descriptors) and even values are component references -// Returns *ManagedReferences -func NewManagedReferences(tuples []interface{}) *ManagedReferences { - c := &ManagedReferences{ - ReferencesDecorator: *NewReferencesDecorator(nil, nil), - } - - c.References = crefer.NewReferences(tuples) - c.Builder = NewBuildReferencesDecorator(c.References, c) - c.Linker = NewLinkReferencesDecorator(c.Builder, c) - c.Runner = NewRunReferencesDecorator(c.Linker, c) - - c.ReferencesDecorator.NextReferences = c.Runner - - return c -} - -// Creates a new instance of the references -// Returns *ManagedReferences -func NewEmptyManagedReferences() *ManagedReferences { - return NewManagedReferences([]interface{}{}) -} - -// Creates a new ManagedReferences object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of locator1, component1, locator2, component2, ... pairs. -// Parameters: -// - tuples ...interface{} -// the tuples to fill a new ManagedReferences object. -// Returns *ManagedReferences -// a new ManagedReferences object. -func NewManagedReferencesFromTuples(tuples ...interface{}) *ManagedReferences { - return NewManagedReferences(tuples) -} - -// Checks if the component is opened. -// Returns bool -// true if the component has been opened and false otherwise. -func (c *ManagedReferences) IsOpen() bool { - return c.Linker.IsOpen() && c.Runner.IsOpen() -} - -// Opens the component. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// Returns error -func (c *ManagedReferences) Open(correlationId string) error { - err := c.Linker.Open(correlationId) - if err == nil { - err = c.Runner.Open(correlationId) - } - return err -} - -// Closes component and frees used resources. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// Returns error -func (c *ManagedReferences) Close(correlationId string) error { - err := c.Runner.Close(correlationId) - if err == nil { - err = c.Linker.Close(correlationId) - } - return err -} diff --git a/v3/refer/ReferencesDecorator.go b/v3/refer/ReferencesDecorator.go deleted file mode 100644 index 443ee84..0000000 --- a/v3/refer/ReferencesDecorator.go +++ /dev/null @@ -1,158 +0,0 @@ -package refer - -import crefer "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - -/* -Chainable decorator for IReferences that allows to inject additional capabilities such as -automatic component creation, automatic registration and opening. -*/ - -type ReferencesDecorator struct { - NextReferences crefer.IReferences - TopReferences crefer.IReferences -} - -// Creates a new instance of the decorator. -// Parameters: -// - nextReferences crefer.IReferences -// the next references or decorator in the chain. -// - topReferences crefer.IReferences -// the decorator at the top of the chain. -// Returns *ReferencesDecorator -func NewReferencesDecorator(nextReferences crefer.IReferences, - topReferences crefer.IReferences) *ReferencesDecorator { - c := &ReferencesDecorator{ - NextReferences: nextReferences, - TopReferences: topReferences, - } - - if c.NextReferences == nil { - c.NextReferences = topReferences - } - if c.TopReferences == nil { - c.TopReferences = nextReferences - } - - return c -} - -// Puts a new reference into this reference map. -// Parameters: -// - locator interface{} -// a locator to find the reference by. -// - component interface{} -// a component reference to be added. -func (c *ReferencesDecorator) Put(locator interface{}, component interface{}) { - c.NextReferences.Put(locator, component) -} - -// Removes a previously added reference that matches specified locator. If many references match the locator, it removes only the first one. When all references shall be removed, use removeAll method instead. -// see -// RemoveAll -// Parameters: -// - locator interface{} -// a locator to remove reference -// Returns interface{} -// the removed component reference. -func (c *ReferencesDecorator) Remove(locator interface{}) interface{} { - return c.NextReferences.Remove(locator) -} - -// Removes all component references that match the specified locator. -// Parameters: -// - locator interface{} -// the locator to remove references by. -// Returns []interface{} -// a list, containing all removed references. -func (c *ReferencesDecorator) RemoveAll(locator interface{}) []interface{} { - return c.NextReferences.RemoveAll(locator) -} - -// Gets locators for all registered component references in this reference map. -// Returns []interface{} -// a list with component locators. -func (c *ReferencesDecorator) GetAllLocators() []interface{} { - return c.NextReferences.GetAllLocators() -} - -// Gets all component references registered in this reference map. -// Returns []interface{} -// a list with component references. -func (c *ReferencesDecorator) GetAll() []interface{} { - return c.NextReferences.GetAll() -} - -// Gets an optional component reference that matches specified locator. -// Parameters: -// - locator interface{} -// the locator to find references by. -// Returns interface{} -// a matching component reference or null if nothing was found. -func (c *ReferencesDecorator) GetOneOptional(locator interface{}) interface{} { - var component interface{} - - defer func() { - recover() - }() - - components, err := c.Find(locator, false) - if err == nil && len(components) > 0 { - component = components[0] - } - - return component -} - -// Gets a required component reference that matches specified locator. -// Parameters: -// - locator interface{} -// the locator to find a reference by. -// Returns interface{}, error -// a matching component reference, a [[ReferenceError]] when no references found. -func (c *ReferencesDecorator) GetOneRequired(locator interface{}) (interface{}, error) { - components, err := c.Find(locator, true) - if err != nil || len(components) == 0 { - return nil, err - } - return components[0], nil -} - -// Gets all component references that match specified locator. -// Parameters: -// - locator interface{} -// the locator to find references by. -// Returns []interface{} -// a list with matching component references or empty list if nothing was found. -func (c *ReferencesDecorator) GetOptional(locator interface{}) []interface{} { - components := []interface{}{} - - defer func() { - recover() - }() - - components, _ = c.Find(locator, false) - - return components -} - -// Gets all component references that match specified locator. At least one component reference must be present. If it doesn't the method throws an error. -// Parameters: -// - locator interface{} -// the locator to find references by. -// Returns []interface{} -// a list with matching component references and error a ReferenceError when no references found. -func (c *ReferencesDecorator) GetRequired(locator interface{}) ([]interface{}, error) { - return c.Find(locator, true) -} - -// Gets all component references that match specified locator. -// Parameters: -// - locator interface{} -// the locator to find a reference by. -// - required bool -// forces to raise an exception if no reference is found. -// Returns []interface{}, error -// a list with matching component references and a ReferenceError when required is set to true but no references found -func (c *ReferencesDecorator) Find(locator interface{}, required bool) ([]interface{}, error) { - return c.NextReferences.Find(locator, required) -} diff --git a/v3/refer/RunReferencesDecorator.go b/v3/refer/RunReferencesDecorator.go deleted file mode 100644 index 2937481..0000000 --- a/v3/refer/RunReferencesDecorator.go +++ /dev/null @@ -1,115 +0,0 @@ -package refer - -import ( - crefer "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - "github.com/pip-services3-go/pip-services3-commons-go/v3/run" -) - -/* - -References decorator that automatically opens to newly added components that implement IOpenable interface and -closes removed components that implement ICloseable interface. -*/ -type RunReferencesDecorator struct { - ReferencesDecorator - opened bool -} - -// Creates a new instance of the decorator. -// Parameters: -// - nextReferences crefer.IReferences -// the next references or decorator in the chain. -// - topReferences crefer.IReferences -// the decorator at the top of the chain. -// Returns *RunReferencesDecorator -func NewRunReferencesDecorator(nextReferences crefer.IReferences, - topReferences crefer.IReferences) *RunReferencesDecorator { - return &RunReferencesDecorator{ - ReferencesDecorator: *NewReferencesDecorator(nextReferences, topReferences), - } -} - -// Checks if the component is opened. -// Returns bool -// true if the component has been opened and false otherwise. -func (c *RunReferencesDecorator) IsOpen() bool { - return c.opened -} - -// Opens the component. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// Returns error -func (c *RunReferencesDecorator) Open(correlationId string) error { - if !c.opened { - components := c.GetAll() - err := run.Opener.Open(correlationId, components) - c.opened = err == nil - return err - } - return nil -} - -// Closes component and frees used resources. -// Parameters: -// - correlationId string -// transaction id to trace execution through call chain. -// Returns error -func (c *RunReferencesDecorator) Close(correlationId string) error { - if c.opened { - components := c.GetAll() - err := run.Closer.Close(correlationId, components) - c.opened = false - return err - } - return nil -} - -// Puts a new reference into this reference map. -// Parameters: -// - locator interface{} -// a locator to find the reference by. -// - component interface{} -// a component reference to be added. -func (c *RunReferencesDecorator) Put(locator interface{}, component interface{}) { - c.ReferencesDecorator.Put(locator, component) - - if c.opened { - run.Opener.OpenOne("", component) - } -} - -// Removes a previously added reference that matches specified locator. If many references match the locator, it removes only the first one. When all references shall be removed, use removeAll method instead. -// see -// removeAll -// Parameters: -// - locator interface{} -// a locator to remove reference -// Returns interfce{} -// the removed component reference. -func (c *RunReferencesDecorator) Remove(locator interface{}) interface{} { - component := c.ReferencesDecorator.Remove(locator) - - if c.opened { - run.Closer.CloseOne("", component) - } - - return component -} - -// Removes all component references that match the specified locator. -// Parameters: -// - locator interface{} -// the locator to remove references by. -// Returns []interface{} -// a list, containing all removed references. -func (c *RunReferencesDecorator) RemoveAll(locator interface{}) []interface{} { - components := c.NextReferences.RemoveAll(locator) - - if c.opened { - run.Closer.Close("", components) - } - - return components -} diff --git a/v3/refer/doc.go b/v3/refer/doc.go deleted file mode 100644 index 8c73bdf..0000000 --- a/v3/refer/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -/* -Provides the inversion of control design pattern but does not contain the fully functional container -(we can just only create a class that will set various references). - -Once the objects of a container are configured, if they implement the IReferencable interface, -they are passed a set of references for recreating links between objects in the container. If objects -implement the IOpenable interface, the Open() method is called and they start to work. Connections to various -services are made, after which the objects start, the container starts running, and the objects carry out their tasks. -When the container starts to close, the objects that implement the ICloseable interface are closed via their close() method -(which should make them stop working and disconnect from other services), after which objects that implement the IUnreferencable -interface delete various links between objects, and, finally, the contains destroys all objects and turns off. - -Build, Link, and Run - ReferenceDecorators are used during the corresponding building, linking, - and running stages and are united in ManagedReferences, which are extended by ContainerReferences. -*/ - -package refer diff --git a/v3/tag.ps1 b/v3/tag.ps1 deleted file mode 100644 index 6ed8386..0000000 --- a/v3/tag.ps1 +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env pwsh - -Set-StrictMode -Version latest -$ErrorActionPreference = "Stop" - -# Get component data and set necessary variables -$component = Get-Content -Path "component.json" | ConvertFrom-Json -$tag="v$($component.version)-$($component.build)" - -# Define group name -$pos = $component.registry.IndexOf("/") -$groupName = "" -if ($pos -gt 0) { - $groupName = $component.registry.Substring($pos + 1, $component.registry.Length - $pos - 1) -} - -# Change git remote so git use ssh on push -git remote set-url origin git@gitlab.com:$groupName/$($component.name).git - -git add ./obj/* -git add ./component.json -git commit -m "project build by GitLab CI [skip ci]" - -# Set git tag -git tag $tag -a -m "Generated tag from GitLabCI for build #$($component.build) [ci skip]" -git push --tags origin HEAD:master \ No newline at end of file diff --git a/v3/test.ps1 b/v3/test.ps1 deleted file mode 100644 index a03eb53..0000000 --- a/v3/test.ps1 +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env pwsh - -Set-StrictMode -Version latest -$ErrorActionPreference = "Stop" - -# Get component data and set necessary variables -$component = Get-Content -Path "component.json" | ConvertFrom-Json -$testImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-test" - -# Set environment variables -$env:IMAGE = $testImage - -try { - # Workaround to remove dangling images - docker-compose -f ./docker/docker-compose.test.yml down - - docker-compose -f ./docker/docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from test -} finally { - # Workaround to remove dangling images - docker-compose -f ./docker/docker-compose.test.yml down -} diff --git a/v3/test/config/ComponentConfig_test.go b/v3/test/config/ComponentConfig_test.go deleted file mode 100644 index 44caf88..0000000 --- a/v3/test/config/ComponentConfig_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package test_config - -import ( - "testing" - - conf "github.com/pip-services3-go/pip-services3-commons-go/v3/config" - "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - "github.com/pip-services3-go/pip-services3-commons-go/v3/reflect" - cconf "github.com/pip-services3-go/pip-services3-container-go/v3/config" - - "github.com/stretchr/testify/assert" -) - -func TestComponentConfigType(t *testing.T) { - typ := reflect.NewTypeDescriptor("new name", "") - config := conf.NewConfigParamsFromTuples( - "config.key", "key", - "config.key2", "key2", - ) - componentConfig := cconf.NewComponentConfigFromType(typ, config) - - assert.NotNil(t, componentConfig.Type) - assert.Nil(t, componentConfig.Descriptor) - assert.NotNil(t, componentConfig.Config) -} - -func TestComponentConfigDescriptor(t *testing.T) { - descriptor := refer.NewDescriptor("group", "type", "id", "default", "version") - config := conf.NewConfigParamsFromTuples( - "config.key", "key", - "config.key2", "key2", - ) - componentConfig := cconf.NewComponentConfigFromDescriptor(descriptor, config) - - assert.Nil(t, componentConfig.Type) - assert.NotNil(t, componentConfig.Descriptor) - assert.NotNil(t, componentConfig.Config) -} - -func TestComponentConfigFromEmptyConfig(t *testing.T) { - config := conf.NewEmptyConfigParams() - componentConfig, err := cconf.ReadComponentConfigFromConfig(config) - - assert.NotNil(t, err) - assert.Nil(t, componentConfig) -} - -func TestComponentConfigFromWrongConfig(t *testing.T) { - config := conf.NewConfigParamsFromTuples( - "descriptor", "descriptor_name", - "type", "type", - "config.key", "key", - "config.key2", "key2", - ) - componentConfig, err := cconf.ReadComponentConfigFromConfig(config) - - assert.NotNil(t, err) - assert.Nil(t, componentConfig) -} - -func TestComponentConfigFromCorrectConfig(t *testing.T) { - config := conf.NewConfigParamsFromTuples( - "descriptor", "group:type:kind:name:version", - "type", "type", - "config.key", "key", - "config.key2", "key2", - ) - componentConfig, err := cconf.ReadComponentConfigFromConfig(config) - - assert.Nil(t, err) - assert.NotNil(t, componentConfig) - assert.NotNil(t, componentConfig.Descriptor) - assert.NotNil(t, componentConfig.Type) - - assert.Equal(t, "group", componentConfig.Descriptor.Group()) - assert.Equal(t, "type", componentConfig.Descriptor.Type()) - assert.Equal(t, "kind", componentConfig.Descriptor.Kind()) - assert.Equal(t, "name", componentConfig.Descriptor.Name()) - assert.Equal(t, "version", componentConfig.Descriptor.Version()) -} diff --git a/v3/test/refer/ManagedReferences_test.go b/v3/test/refer/ManagedReferences_test.go deleted file mode 100644 index 0bb5140..0000000 --- a/v3/test/refer/ManagedReferences_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package test_refer - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/pip-services3-go/pip-services3-commons-go/v3/refer" - "github.com/pip-services3-go/pip-services3-components-go/v3/log" - crefer "github.com/pip-services3-go/pip-services3-container-go/v3/refer" -) - -func TestAutoCreateComponent(t *testing.T) { - refs := crefer.NewEmptyManagedReferences() - - factory := log.NewDefaultLoggerFactory() - refs.Put(nil, factory) - - logger, err := refs.GetOneRequired( - refer.NewDescriptor("*", "logger", "*", "*", "*"), - ) - - assert.Nil(t, err) - assert.NotNil(t, logger) -} - -func TestStringLocator(t *testing.T) { - refs := crefer.NewEmptyManagedReferences() - - factory := log.NewDefaultLoggerFactory() - refs.Put(nil, factory) - - logger := refs.GetOneOptional("ABC") - - assert.Nil(t, logger) -} - -func TestNilLocator(t *testing.T) { - refs := crefer.NewEmptyManagedReferences() - - factory := log.NewDefaultLoggerFactory() - refs.Put(nil, factory) - - logger := refs.GetOneOptional(nil) - - assert.Nil(t, logger) -}