Merge pull request #4 from 30x/newschema
Updated schema
diff --git a/.gitignore b/.gitignore
index 5ed7dc5..1e2283b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,6 @@
cover.html
coverage.txt
vendor
+*.iml
+.idea
+*.lock
\ No newline at end of file
diff --git a/README.md b/README.md
index a274032..dc5ce38 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,6 @@
| name | description |
|------------------------------|--------------------------|
| apigeesync_poll_interval | int. seconds. default: 5 |
-| apigeesync_organization | string. name. required. |
| apigeesync_proxy_server_base | string. url. required. |
| apigeesync_consumer_key | string. required. |
| apigeesync_consumer_secret | string. required. |
diff --git a/apigee_sync.go b/apigee_sync.go
index 947fc29..a3de787 100644
--- a/apigee_sync.go
+++ b/apigee_sync.go
@@ -434,9 +434,9 @@
return nil
}
- rows, err := db.Query("select scope from APID_CONFIG_SCOPE where apid_config_id = $1", configId)
+ rows, err := db.Query("select scope from DATA_SCOPE where apid_cluster_id = $1", configId)
if err != nil {
- log.Errorf("Failed to query APID_CONFIG_SCOPE. Err: %s", err)
+ log.Errorf("Failed to query DATA_SCOPE. Err: %s", err)
return nil
}
defer rows.Close()
@@ -457,10 +457,10 @@
log.Errorf("DB open Error: %s", err)
return ""
}
- query := "select " + qparam + " from APID_CONFIG"
+ query := "select " + qparam + " from APID_CLUSTER"
rows, err := db.Query(query)
if err != nil {
- log.Errorf("Failed to query APID_CONFIG. Err: %s", err)
+ log.Errorf("Failed to query APID_CLUSTER. Err: %s", err)
return ""
}
defer rows.Close()
@@ -485,9 +485,9 @@
log.Error("Unable to create Sqlite transaction")
return false
}
- prep, err := txn.Prepare("UPDATE APID_CONFIG SET lastSequence=$1;")
+ prep, err := txn.Prepare("UPDATE APID_CLUSTER SET lastSequence=$1;")
if err != nil {
- log.Error("UPDATE APID_CONFIG Failed: ", err)
+ log.Error("UPDATE APID_CLUSTER Failed: ", err)
return false
}
defer prep.Close()
@@ -495,11 +495,11 @@
_, err = s.Exec(lastChange)
s.Close()
if err != nil {
- log.Error("UPDATE APID_CONFIG_SCOPE Failed: ", err)
+ log.Error("UPDATE DATA_SCOPE Failed: ", err)
txn.Rollback()
return false
} else {
- log.Info("UPDATE APID_CONFIG_SCOPE Success: (", lastChange, ")")
+ log.Info("UPDATE DATA_SCOPE Success: (", lastChange, ")")
txn.Commit()
return true
}
diff --git a/apigee_sync_test.go b/apigee_sync_test.go
index 4f2374d..507aa99 100644
--- a/apigee_sync_test.go
+++ b/apigee_sync_test.go
@@ -53,7 +53,7 @@
err = json.Unmarshal(plinfo, &plugInfo)
Expect(err).NotTo(HaveOccurred())
Expect(plugInfo[0].Name).To(Equal("apidApigeeSync"))
- Expect(plugInfo[0].SchemaVersion).To(Equal("0.0.1"))
+ Expect(plugInfo[0].SchemaVersion).To(Equal("0.0.2"))
res := oauthTokenResp{}
res.AccessToken = "accesstoken"
@@ -86,7 +86,7 @@
Value: scope,
Type: 1,
}
- apidcfgItem["_apid_scope"] = scv
+ apidcfgItem["_change_selector"] = scv
apidcfgItems = append(apidcfgItems, apidcfgItem)
scv = &common.ColumnVal{
@@ -99,20 +99,36 @@
Value: "apid_config_scope_id_0",
Type: 1,
}
- apidcfgItemCh["_apid_scope"] = scv
+ apidcfgItemCh["_change_selector"] = scv
scv = &common.ColumnVal{
Value: scope,
Type: 1,
}
- apidcfgItemCh["apid_config_id"] = scv
+ apidcfgItemCh["apid_cluster_id"] = scv
scv = &common.ColumnVal{
- Value: "att~prod",
+ Value: "ert452",
Type: 1,
}
apidcfgItemCh["scope"] = scv
+ {
+ scv = &common.ColumnVal{
+ Value: "att",
+ Type: 1,
+ }
+ apidcfgItemCh["org"] = scv
+
+ }
+ {
+ scv = &common.ColumnVal{
+ Value: "prod",
+ Type: 1,
+ }
+ apidcfgItemCh["env"] = scv
+ }
+
apidcfgItemsCh = append(apidcfgItemsCh, apidcfgItemCh)
res := &common.Snapshot{}
@@ -120,11 +136,11 @@
res.Tables = []common.Table{
{
- Name: "edgex.apid_config",
+ Name: "edgex.apid_cluster",
Rows: apidcfgItems,
},
{
- Name: "edgex.apid_config_scope",
+ Name: "edgex.data_scope",
Rows: apidcfgItemsCh,
},
}
@@ -135,7 +151,7 @@
return
} else {
phase = 2
- Expect(q.Get("scope")).To(Equal("att~prod"))
+ Expect(q.Get("scope")).To(Equal("ert452"))
res := &common.Snapshot{}
res.SnapshotInfo = "snapinfo1"
@@ -161,7 +177,7 @@
q := req.URL.Query()
Expect(q.Get("snapshot")).To(Equal("snapinfo1"))
scparams := q["scope"]
- Expect(scparams).To(ContainElement("att~prod"))
+ Expect(scparams).To(ContainElement("ert452"))
Expect(scparams).To(ContainElement("bootstrap"))
res := &common.ChangeList{}
@@ -179,17 +195,31 @@
Value: scope,
Type: 1,
}
- mpItems["apid_config_id"] = scv
+ mpItems["apid_cluster_id"] = scv
scv = &common.ColumnVal{
- Value: "att~test",
+ Value: "ert452",
Type: 1,
}
mpItems["scope"] = scv
+ {
+ scv = &common.ColumnVal{
+ Value: "att",
+ Type: 1,
+ }
+ mpItems["org"] = scv
+ }
+ {
+ scv = &common.ColumnVal{
+ Value: "prod",
+ Type: 1,
+ }
+ mpItems["env"] = scv
+ }
res.Changes = []common.Change{
{
- Table: "edgex.apid_config_scope",
+ Table: "edgex.data_scope",
NewRow: mpItems,
Operation: 1,
},
@@ -206,11 +236,11 @@
config.Set(configProxyServerBaseURI, server.URL)
config.Set(configSnapServerBaseURI, server.URL)
config.Set(configChangeServerBaseURI, server.URL)
- config.Set(configScopeId, "apid_config_scope_0")
+ config.Set(configApidClusterId, "apid_config_scope_0")
config.Set(configName, "testhost")
config.Set(configSnapshotProtocol, "json")
- config.Set(configScopeId, scope)
+ config.Set(configApidClusterId, scope)
config.Set(configConsumerKey, key)
config.Set(configConsumerSecret, secret)
@@ -233,7 +263,7 @@
db, err := data.DB()
Expect(err).NotTo(HaveOccurred())
// verify event data (post snapshot)
- err = db.QueryRow("Select count(scp.id) from apid_config_scope as scp INNER JOIN apid_config as ap WHERE scp.apid_config_id = ap.id").Scan(&scount)
+ err = db.QueryRow("Select count(scp.id) from data_scope as scp INNER JOIN apid_cluster as ap WHERE scp.apid_cluster_id = ap.id").Scan(&scount)
Expect(err).NotTo(HaveOccurred())
Expect(scount).Should(Equal(1))
}
@@ -245,7 +275,7 @@
time.Sleep(200 * time.Millisecond)
db, err := data.DB()
Expect(err).NotTo(HaveOccurred())
- err = db.QueryRow("Select count(scp.id) from apid_config_scope as scp INNER JOIN apid_config as ap WHERE scp.apid_config_id = ap.id").Scan(&scount)
+ err = db.QueryRow("Select count(scp.id) from data_scope as scp INNER JOIN apid_cluster as ap WHERE scp.apid_cluster_id = ap.id").Scan(&scount)
Expect(err).NotTo(HaveOccurred())
Expect(scount).Should(Equal(2))
close(done)
diff --git a/glide.lock b/glide.lock
deleted file mode 100644
index 48d04cc..0000000
--- a/glide.lock
+++ /dev/null
@@ -1,111 +0,0 @@
-hash: d08d25e5d3cf18bae11145be87817c2c7c0bbe7608b1b8126bc0d3eea53931b8
-updated: 2016-09-22T11:06:44.785980058-07:00
-imports:
-- name: github.com/30x/apid
- version: e0cf0bd9ca044ba1643e979a356573551f3c4595
- subpackages:
- - api
- - config
- - data
- - events
- - factory
- - logger
-- name: github.com/fsnotify/fsnotify
- version: f12c6236fe7b5cf6bcf30e5935d08cb079d78334
-- name: github.com/gorilla/context
- version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42
-- name: github.com/gorilla/mux
- version: 757bef944d0f21880861c2dd9c871ca543023cba
-- name: github.com/hashicorp/hcl
- version: ef8133da8cda503718a74741312bf50821e6de79
- subpackages:
- - hcl/ast
- - hcl/parser
- - hcl/scanner
- - hcl/strconv
- - hcl/token
- - json/parser
- - json/scanner
- - json/token
-- name: github.com/kr/fs
- version: 2788f0dbd16903de03cb8186e5c7d97b69ad387b
-- name: github.com/magiconair/properties
- version: 0723e352fa358f9322c938cc2dadda874e9151a9
-- name: github.com/mattn/go-sqlite3
- version: 3fb7a0e792edd47bf0cf1e919dfc14e2be412e15
-- name: github.com/mitchellh/mapstructure
- version: ca63d7c062ee3c9f34db231e352b60012b4fd0c1
-- name: github.com/pelletier/go-buffruneio
- version: df1e16fde7fc330a0ca68167c23bf7ed6ac31d6d
-- name: github.com/pelletier/go-toml
- version: 45932ad32dfdd20826f5671da37a5f3ce9f26a8d
-- name: github.com/pkg/errors
- version: a887431f7f6ef7687b556dbf718d9f351d4858a0
-- name: github.com/pkg/sftp
- version: 8197a2e580736b78d704be0fc47b2324c0591a32
-- name: github.com/Sirupsen/logrus
- version: 3ec0642a7fb6488f65b06f9040adc67e3990296a
-- name: github.com/spf13/afero
- version: 52e4a6cfac46163658bd4f123c49b6ee7dc75f78
- subpackages:
- - mem
- - sftp
-- name: github.com/spf13/cast
- version: 60e7a69a428e9ac1cf7e0c865fc2fe810d34363e
-- name: github.com/spf13/jwalterweatherman
- version: 33c24e77fb80341fe7130ee7c594256ff08ccc46
-- name: github.com/spf13/pflag
- version: c7e63cf4530bcd3ba943729cee0efeff2ebea63f
-- name: github.com/spf13/viper
- version: a78f70b5b977efe08e313a9e2341c3f5457abdaf
-- name: golang.org/x/crypto
- version: 8e06e8ddd9629eb88639aba897641bff8031f1d3
- subpackages:
- - curve25519
- - ed25519
- - ed25519/internal/edwards25519
- - ssh
-- name: golang.org/x/sys
- version: 8f0908ab3b2457e2e15403d3697c9ef5cb4b57a9
- subpackages:
- - unix
-- name: golang.org/x/text
- version: 9c8be9c425872eec4348571de4bcd4113104fceb
- subpackages:
- - transform
- - unicode/norm
-- name: gopkg.in/yaml.v2
- version: 31c299268d302dd0aa9a0dcf765a3d58971ac83f
-testImports:
-- name: github.com/onsi/ginkgo
- version: 46c87bb63f2d8d62b3076873b7a84da124da72ce
- subpackages:
- - config
- - ginkgo
- - internal/codelocation
- - internal/containernode
- - internal/failer
- - internal/leafnodes
- - internal/remote
- - internal/spec
- - internal/specrunner
- - internal/suite
- - internal/testingtproxy
- - internal/writer
- - reporters
- - reporters/stenographer
- - types
-- name: github.com/onsi/gomega
- version: d59fa0ac68bb5dd932ee8d24eed631cdd519efc3
- subpackages:
- - format
- - internal/assertion
- - internal/asyncassertion
- - internal/oraclematcher
- - internal/testingtsupport
- - matchers
- - matchers/support/goraph/bipartitegraph
- - matchers/support/goraph/edge
- - matchers/support/goraph/node
- - matchers/support/goraph/util
- - types
diff --git a/init.go b/init.go
index b6fe63a..54745d9 100644
--- a/init.go
+++ b/init.go
@@ -15,7 +15,7 @@
configChangeServerBaseURI = "apigeesync_change_server_base"
configConsumerKey = "apigeesync_consumer_key"
configConsumerSecret = "apigeesync_consumer_secret"
- configScopeId = "apigeesync_bootstrap_id"
+ configApidClusterId = "apigeesync_cluster_id"
configSnapshotProtocol = "apigeesync_snapshot_proto"
configName = "apigeesync_instance_name"
ApigeeSyncEventSelector = "ApigeeSync"
@@ -122,7 +122,7 @@
events.ListenFunc(apid.SystemEventsSelector, postInitPlugins)
config.SetDefault(configPollInterval, 120)
- gapidConfigId = config.GetString(configScopeId)
+ gapidConfigId = config.GetString(configApidClusterId)
db, err := data.DB()
if err != nil {
log.Panic("Unable to access DB", err)
@@ -136,7 +136,7 @@
}
var count int
- row := db.QueryRow("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='apid_config' COLLATE NOCASE;")
+ row := db.QueryRow("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='apid_cluster' COLLATE NOCASE;")
if err := row.Scan(&count); err != nil {
log.Panic("Unable to setup database", err)
}
@@ -151,7 +151,7 @@
func createTables(db apid.DB) {
_, err := db.Exec(`
-CREATE TABLE apid_config (
+CREATE TABLE apid_cluster (
id text,
instance_id text,
name text,
@@ -161,20 +161,22 @@
created_by text,
updated int64,
updated_by text,
- _apid_scope text,
+ _change_selector text,
snapshotInfo text,
lastSequence text,
PRIMARY KEY (id)
);
-CREATE TABLE apid_config_scope (
+CREATE TABLE data_scope (
id text,
- apid_config_id text,
+ apid_cluster_id text,
scope text,
+ org text,
+ env text,
created int64,
created_by text,
updated int64,
updated_by text,
- _apid_scope text,
+ _change_selector text,
PRIMARY KEY (id)
);
`)
diff --git a/listener.go b/listener.go
index b924c76..c5f154a 100644
--- a/listener.go
+++ b/listener.go
@@ -55,10 +55,10 @@
for _, payload := range snapshot.Tables {
switch payload.Name {
- case "edgex.apid_config":
- res = insertApidConfig(payload.Rows, txn, snapshot.SnapshotInfo)
- case "edgex.apid_config_scope":
- res = insertApidConfigScopes(payload.Rows, txn)
+ case "edgex.apid_cluster":
+ res = insertApidCluster(payload.Rows, txn, snapshot.SnapshotInfo)
+ case "edgex.data_scope":
+ res = insertDataScopes(payload.Rows, txn)
}
if res == false {
log.Error("Error encountered in Downloading Snapshot for ApidApigeeSync")
@@ -77,11 +77,11 @@
for _, payload := range changes.Changes {
rows = nil
switch payload.Table {
- case "edgex.apid_config_scope":
+ case "edgex.data_scope":
switch payload.Operation {
case common.Insert:
rows = append(rows, payload.NewRow)
- res = insertApidConfigScopes(rows, txn)
+ res = insertDataScopes(rows, txn)
}
}
if res == false {
@@ -95,21 +95,21 @@
/*
* INSERT INTO APP_CREDENTIAL op
*/
-func insertApidConfig(rows []common.Row, txn *sql.Tx, snapInfo string) bool {
+func insertApidCluster(rows []common.Row, txn *sql.Tx, snapInfo string) bool {
var scope, id, name, orgAppName, createdBy, updatedBy, Description string
var updated, created int64
- prep, err := txn.Prepare("INSERT INTO APID_CONFIG (id, instance_id, _apid_scope, name, umbrella_org_app_name, created, created_by, updated, updated_by, snapshotInfo)VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);")
+ prep, err := txn.Prepare("INSERT INTO APID_CLUSTER (id, instance_id, _change_selector, name, umbrella_org_app_name, created, created_by, updated, updated_by, snapshotInfo)VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);")
if err != nil {
- log.Error("INSERT APID_CONFIG Failed: ", err)
+ log.Error("INSERT APID_CLUSTER Failed: ", err)
return false
}
defer prep.Close()
for _, ele := range rows {
ele.Get("id", &id)
- ele.Get("_apid_scope", &scope)
+ ele.Get("_change_selector", &scope)
ele.Get("name", &name)
ele.Get("umbrella_org_app_name", &orgAppName)
ele.Get("created", &created)
@@ -132,10 +132,10 @@
snapInfo)
s.Close()
if err != nil {
- log.Error("INSERT APID_CONFIG Failed: ", id, ", ", scope, ")", err)
+ log.Error("INSERT APID_CLUSTER Failed: ", id, ", ", scope, ")", err)
return false
} else {
- log.Info("INSERT APID_CONFIG Success: (", id, ", ", scope, ")")
+ log.Info("INSERT APID_CLUSTER Success: (", id, ", ", scope, ")")
}
}
return true
@@ -144,14 +144,14 @@
/*
* INSERT INTO APP_CREDENTIAL op
*/
-func insertApidConfigScopes(rows []common.Row, txn *sql.Tx) bool {
+func insertDataScopes(rows []common.Row, txn *sql.Tx) bool {
- var id, scopeId, apiConfigId, scope, createdBy, updatedBy string
+ var id, scopeId, apiConfigId, scope, createdBy, updatedBy, org, env string
var created, updated int64
- prep, err := txn.Prepare("INSERT INTO APID_CONFIG_SCOPE (id, _apid_scope, apid_config_id, scope, created, created_by, updated, updated_by)VALUES($1,$2,$3,$4,$5,$6,$7,$8);")
+ prep, err := txn.Prepare("INSERT INTO DATA_SCOPE (id, _change_selector, apid_cluster_id, scope, org, env, created, created_by, updated, updated_by)VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);")
if err != nil {
- log.Error("INSERT APID_CONFIG_SCOPE Failed: ", err)
+ log.Error("INSERT DATA_SCOPE Failed: ", err)
return false
}
defer prep.Close()
@@ -159,9 +159,11 @@
for _, ele := range rows {
ele.Get("id", &id)
- ele.Get("_apid_scope", &scopeId)
- ele.Get("apid_config_id", &apiConfigId)
+ ele.Get("_change_selector", &scopeId)
+ ele.Get("apid_cluster_id", &apiConfigId)
ele.Get("scope", &scope)
+ ele.Get("org", &org)
+ ele.Get("env", &env)
ele.Get("created", &created)
ele.Get("created_by", &createdBy)
ele.Get("updated", &updated)
@@ -173,6 +175,8 @@
scopeId,
apiConfigId,
scope,
+ org,
+ env,
created,
createdBy,
updated,
@@ -180,10 +184,10 @@
s.Close()
if err != nil {
- log.Error("INSERT APID_CONFIG_SCOPE Failed: ", id, ", ", scope, ")", err)
+ log.Error("INSERT DATA_SCOPE Failed: ", id, ", ", scope, ")", err)
return false
} else {
- log.Info("INSERT APID_CONFIG_SCOPE Success: (", id, ", ", scope, ")")
+ log.Info("INSERT DATA_SCOPE Success: (", id, ", ", scope, ")")
}
}
return true
diff --git a/pluginData.go b/pluginData.go
index b65effc..ef93e2e 100644
--- a/pluginData.go
+++ b/pluginData.go
@@ -4,8 +4,8 @@
var pluginData = apid.PluginData{
Name: "apidApigeeSync",
- Version: "0.0.1",
+ Version: "0.0.2",
ExtraData: map[string]interface{}{
- "schemaVersion": "0.0.1",
+ "schemaVersion": "0.0.2",
},
}