Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 55.dockter.1 #61

Merged
merged 20 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Based on
# -https://github.com/marketplace/actions/setup-go-environment

name: go-test.yaml

on: [push]

env:
LD_LIBRARY_PATH: /opt/senzing/g2/lib
SENZING_ACCEPT_EULA: I_ACCEPT_THE_SENZING_EULA
SENZING_TOOLS_DATABASE_URL: "sqlite3://na:na@/tmp/sqlite/G2C.db"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.20"]
name: Go ${{ matrix.go }} sample
steps:
- uses: actions/checkout@v3
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- run: pwd
- run: wget -qO /tmp/senzingrepo_1.0.1-1_amd64.deb https://senzing-production-apt.s3.amazonaws.com/senzingrepo_1.0.1-1_amd64.deb
- run: sudo apt-get -y install /tmp/senzingrepo_1.0.1-1_amd64.deb
- run: sudo apt-get update
- run: sudo --preserve-env apt-get -y install senzingapi
- run: sudo mv /opt/senzing/data/3.0.0/* /opt/senzing/data/
- run: sudo mkdir /etc/opt/senzing
- run: sudo cp /opt/senzing/g2/resources/templates/cfgVariant.json /etc/opt/senzing
- run: sudo cp /opt/senzing/g2/resources/templates/customGn.txt /etc/opt/senzing
- run: sudo cp /opt/senzing/g2/resources/templates/customOn.txt /etc/opt/senzing
- run: sudo cp /opt/senzing/g2/resources/templates/customSn.txt /etc/opt/senzing
- run: sudo cp /opt/senzing/g2/resources/templates/defaultGNRCP.config /etc/opt/senzing
- run: sudo cp /opt/senzing/g2/resources/templates/stb.config /etc/opt/senzing
- run: sudo cp testdata/senzing-license/g2.lic /etc/opt/senzing
- run: mkdir /tmp/sqlite
- run: cp testdata/sqlite/G2C.db /tmp/sqlite/G2C.db
- run: go test -v -p 1 ./...
# - run: go test -v ./.
# - run: go test -v ./g2configserver
# - run: go test -v ./g2configmgrserver
# - run: go test -v ./g2diagnosticserver
# - run: go test -v ./g2engineserver
# - run: go test -v ./g2productserver
# - run: go test -v ./grpcserver
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

-

## [0.3.9] - 2023-03-27

### Added in 0.3.9

- Added Stream methods
- g2diagnosticserver.StreamEntityListBySize()
- g2engineserver.StreamExportCSVEntityReport()
- g2engineserver.StreamExportJSONEntityReport()
- Update dependencies

## [0.3.8] - 2023-03-14

Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ run-servegrpc-trace: build
# Utility targets
# -----------------------------------------------------------------------------

.PHONY: new-sqlite
new-sqlite:
@rm -rf /tmp/sqlite
@mkdir /tmp/sqlite
@cp testdata/sqlite/G2C.db /tmp/sqlite/G2C.db

.PHONY: update-pkg-cache
update-pkg-cache:
@GOPROXY=https://proxy.golang.org GO111MODULE=on \
Expand All @@ -164,9 +170,6 @@ clean:
@docker rmi --force $(DOCKER_IMAGE_NAME) $(DOCKER_BUILD_IMAGE_NAME) 2> /dev/null || true
@rm -rf $(TARGET_DIRECTORY) || true
@rm -f $(GOPATH)/bin/$(PROGRAM_NAME) || true
@rm -rf /tmp/sqlite
@mkdir /tmp/sqlite
@cp testdata/sqlite/G2C.db /tmp/sqlite/G2C.db


.PHONY: print-make-variables
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
var (
buildIteration string = "0"
buildVersion string = "0.3.7"
defaultEngineModuleName string = fmt.Sprintf("initdatabase-%d", time.Now().Unix())
defaultEngineModuleName string = fmt.Sprintf("servegrpc-%d", time.Now().Unix())
)

// If a configuration file is present, load it.
Expand Down
8 changes: 4 additions & 4 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ One or two paragraph overview of this module...

(This page describes the nature of the entire Go module or the top-level command, not an individual package.)

More information at https://github.com/senzing/initdatabase
More information at https://github.com/senzing/servegrpc

# Example Package

Expand All @@ -16,7 +16,7 @@ documentation, tests, and examples should be done. This paragraph (or two)
should provide a brief overview while linking the reader to the documentation
included in the package itself.

More information can be found in the [pkg/github.com/senzing/initdatabase/examplepackage] documentation.
More information can be found in the [pkg/github.com/senzing/servegrpc/examplepackage] documentation.

# Another Header: Package or other module features...

Expand All @@ -33,8 +33,8 @@ Examples of use can be seen in the main_test.go files.
import (
fmt

"github.com/senzing/initdatabase/examplepackage"
"github.com/senzing/initdatabase/anotherpackage"
"github.com/senzing/servegrpc/examplepackage"
"github.com/senzing/servegrpc/anotherpackage"
)

func main() {
Expand Down
47 changes: 42 additions & 5 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,50 @@ Since the Senzing library is a prerequisite, it must be installed first.

```

1. Clean up.
## Run

After running `make build`,
the binary built can be run.

1. Identify the database by setting the `SENZING_TOOLS_DATABASE_URL` environment variable.

1. :pencil2: Create a new Sqlite database.
Examples:

```console
export SENZING_TOOLS_DATABASE_URL=sqlite3://na:na@/tmp/sqlite/G2C.db
export LD_LIBRARY_PATH=/opt/senzing/g2/lib/
senzing-tools initdatabase

```

1. :pencil2: Identify an existing PostgreSQL database.
Example:

```console
export LOCAL_IP_ADDRESS=$(curl --silent https://raw.githubusercontent.com/Senzing/knowledge-base/main/gists/find-local-ip-address/find-local-ip-address.py | python3 -)
export SENZING_TOOLS_DATABASE_URL=postgresql://postgres:postgres@${LOCAL_IP_ADDRESS}:5432/G2/?sslmode=disable

```

1. Set `LD_LIBRARY_PATH` and run the command.
Example:

```console
cd ${GIT_REPOSITORY_DIR}
make clean
export LD_LIBRARY_PATH=/opt/senzing/g2/lib/
${GIT_REPOSITORY_DIR}/target/linux/servegrpc

```

## Test

### Test using SQLite database

1. Run tests.

```console
cd ${GIT_REPOSITORY_DIR}
make clean test
make clean new-sqlite test

```

Expand Down Expand Up @@ -342,4 +370,13 @@ The actual packaging is done in the [senzing-tools](https://github.com/Senzing/s

```

### FIXME: remove
### Cleanup

1. Clean up.
Example:

```console
cd ${GIT_REPOSITORY_DIR}
make clean

```
52 changes: 33 additions & 19 deletions g2configmgrserver/g2configmgrserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/senzing/g2-sdk-go-base/g2config"
"github.com/senzing/g2-sdk-go-base/g2configmgr"
"github.com/senzing/g2-sdk-go-base/g2engine"
"github.com/senzing/g2-sdk-go/g2error"
g2configpb "github.com/senzing/g2-sdk-proto/go/g2config"
g2pb "github.com/senzing/g2-sdk-proto/go/g2configmgr"
"github.com/senzing/go-common/g2engineconfigurationjson"
Expand All @@ -35,6 +36,10 @@ var (
// Internal functions
// ----------------------------------------------------------------------------

func createError(errorId int, err error) error {
return g2error.Cast(localLogger.Error(errorId, err), err)
}

func getTestObject(ctx context.Context, test *testing.T) G2ConfigmgrServer {
if g2configmgrServerSingleton == nil {
g2configmgrServerSingleton = &G2ConfigmgrServer{}
Expand Down Expand Up @@ -131,6 +136,15 @@ func testErrorNoFail(test *testing.T, ctx context.Context, g2configmgr G2Configm
func TestMain(m *testing.M) {
err := setup()
if err != nil {
if g2error.Is(err, g2error.G2Unrecoverable) {
fmt.Printf("\nUnrecoverable error detected. \n\n")
}
if g2error.Is(err, g2error.G2Retryable) {
fmt.Printf("\nRetryable error detected. \n\n")
}
if g2error.Is(err, g2error.G2BadUserInput) {
fmt.Printf("\nBad user input error detected. \n\n")
}
fmt.Print(err)
os.Exit(1)
}
Expand All @@ -148,60 +162,60 @@ func setupSenzingConfig(ctx context.Context, moduleName string, iniParams string
aG2config := &g2config.G2config{}
err := aG2config.Init(ctx, moduleName, iniParams, verboseLogging)
if err != nil {
return localLogger.Error(5906, err)
return createError(5906, err)
}

configHandle, err := aG2config.Create(ctx)
if err != nil {
return localLogger.Error(5907, err)
return createError(5907, err)
}

datasourceNames := []string{"CUSTOMERS", "REFERENCE", "WATCHLIST"}
for _, datasourceName := range datasourceNames {
datasource := truthset.TruthsetDataSources[datasourceName]
_, err := aG2config.AddDataSource(ctx, configHandle, datasource.Json)
if err != nil {
return localLogger.Error(5908, err)
return createError(5908, err)
}
}

configStr, err := aG2config.Save(ctx, configHandle)
if err != nil {
return localLogger.Error(5909, err)
return createError(5909, err)
}

err = aG2config.Close(ctx, configHandle)
if err != nil {
return localLogger.Error(5910, err)
return createError(5910, err)
}

err = aG2config.Destroy(ctx)
if err != nil {
return localLogger.Error(5911, err)
return createError(5911, err)
}

// Persist the Senzing configuration to the Senzing repository.

aG2configmgr := &g2configmgr.G2configmgr{}
err = aG2configmgr.Init(ctx, moduleName, iniParams, verboseLogging)
if err != nil {
return localLogger.Error(5912, err)
return createError(5912, err)
}

configComments := fmt.Sprintf("Created by g2diagnostic_test at %s", now.UTC())
configID, err := aG2configmgr.AddConfig(ctx, configStr, configComments)
if err != nil {
return localLogger.Error(5913, err)
return createError(5913, err)
}

err = aG2configmgr.SetDefaultConfigID(ctx, configID)
if err != nil {
return localLogger.Error(5914, err)
return createError(5914, err)
}

err = aG2configmgr.Destroy(ctx)
if err != nil {
return localLogger.Error(5915, err)
return createError(5915, err)
}
return err
}
Expand All @@ -210,49 +224,49 @@ func setupPurgeRepository(ctx context.Context, moduleName string, iniParams stri
aG2engine := &g2engine.G2engine{}
err := aG2engine.Init(ctx, moduleName, iniParams, verboseLogging)
if err != nil {
return localLogger.Error(5903, err)
return createError(5903, err)
}

err = aG2engine.PurgeRepository(ctx)
if err != nil {
return localLogger.Error(5904, err)
return createError(5904, err)
}

err = aG2engine.Destroy(ctx)
if err != nil {
return localLogger.Error(5905, err)
return createError(5905, err)
}
return err
}

func setup() error {
var err error = nil
ctx := context.TODO()
moduleName := "Test module name"
verboseLogging := 0
localLogger, err := messagelogger.NewSenzingApiLogger(ProductId, IdMessages, IdStatuses, messagelogger.LevelInfo)
localLogger, err = messagelogger.NewSenzingApiLogger(ProductId, IdMessages, IdStatuses, messagelogger.LevelInfo)
if err != nil {
return localLogger.Error(5901, err)
return createError(5901, err)
}

iniParams, err := g2engineconfigurationjson.BuildSimpleSystemConfigurationJson("")
if err != nil {
return localLogger.Error(5902, err)
return createError(5902, err)
}

// Add Data Sources to Senzing configuration.

err = setupSenzingConfig(ctx, moduleName, iniParams, verboseLogging)
if err != nil {
return localLogger.Error(5920, err)
return createError(5920, err)
}

// Purge repository.

err = setupPurgeRepository(ctx, moduleName, iniParams, verboseLogging)
if err != nil {
return localLogger.Error(5921, err)
return createError(5921, err)
}

return err
}

Expand Down
Loading