persist the uuid in the DB.
diff --git a/apigee_sync.go b/apigee_sync.go index a065389..6c63a14 100644 --- a/apigee_sync.go +++ b/apigee_sync.go
@@ -94,7 +94,7 @@ * Check to see if we have lastSequence already saved in the DB, * in which case, it has to be used to prevent re-reading same data */ - lastSequence = findLastSeqInfo(gapidConfigId) + lastSequence = findapidConfigInfo("lastSequence") for { log.Debug("polling...") if tokenActive == false { @@ -281,7 +281,7 @@ * Skip Downloading snapshot, if there is already a snapshot * available from previous run of APID */ - gsnapshotInfo = findSnapshotInfo(gapidConfigId) + gsnapshotInfo = findapidConfigInfo("snapshotInfo") if gsnapshotInfo != "" { downloadDataSnapshot = true downloadBootSnapshot = true @@ -440,40 +440,17 @@ } /* - * Retrieve LastSequence for the given apidConfigId from apid_config table - */ -func findLastSeqInfo(configId string) (info string) { - - db, err := data.DB() - if err != nil { - log.Errorf("DB open Error: %s", err) - return "" - } - - rows, err := db.Query("select lastSequence from APID_CONFIG where id = $1", configId) - if err != nil { - log.Errorf("Failed to query APID_CONFIG. Err: %s", err) - return "" - } - defer rows.Close() - for rows.Next() { - rows.Scan(&info) - } - return info -} - -/* * Retrieve SnapshotInfo for the given apidConfigId from apid_config table */ -func findSnapshotInfo(configId string) (info string) { +func findapidConfigInfo(qparam string) (info string) { db, err := data.DB() if err != nil { log.Errorf("DB open Error: %s", err) return "" } - - rows, err := db.Query("select snapshotInfo from APID_CONFIG where id = $1", configId) + query := "select " + qparam + " from APID_CONFIG" + rows, err := db.Query(query) if err != nil { log.Errorf("Failed to query APID_CONFIG. Err: %s", err) return "" @@ -500,14 +477,14 @@ log.Error("Unable to create Sqlite transaction") return false } - prep, err := txn.Prepare("UPDATE APID_CONFIG SET lastSequence=$1 WHERE id=$2;") + prep, err := txn.Prepare("UPDATE APID_CONFIG SET lastSequence=$1;") if err != nil { log.Error("INSERT APID_CONFIG Failed: ", err) return false } defer prep.Close() s := txn.Stmt(prep) - _, err = s.Exec(lastChange, gapidConfigId) + _, err = s.Exec(lastChange) s.Close() if err != nil { log.Error("UPDATE APID_CONFIG_SCOPE Failed: ", err)
diff --git a/apigee_sync_test.go b/apigee_sync_test.go index d6825b3..2fa9e9a 100644 --- a/apigee_sync_test.go +++ b/apigee_sync_test.go
@@ -53,6 +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")) res := oauthTokenResp{} res.AccessToken = "accesstoken"
diff --git a/init.go b/init.go index dd290c1..b6fe63a 100644 --- a/init.go +++ b/init.go
@@ -47,7 +47,7 @@ if numRead != len(buff) || err != nil { panic(err) } - return fmt.Sprintf("%x-%x-%x-%x-%x-%x\n", unix32bits, buff[0:2], buff[2:4], buff[4:6], buff[6:8], buff[8:]) + return fmt.Sprintf("%x-%x-%x-%x-%x-%x", unix32bits, buff[0:2], buff[2:4], buff[4:6], buff[6:8], buff[8:]) } func init() { @@ -103,7 +103,10 @@ config = services.Config() data = services.Data() events = services.Events() - guuid = generate_uuid() + guuid = findapidConfigInfo("instance_id") + if guuid == "" { + guuid = generate_uuid() + } /* If The Instance has no name configured, just re-use UUID */ ginstName = config.GetString(configName) @@ -150,6 +153,7 @@ _, err := db.Exec(` CREATE TABLE apid_config ( id text, + instance_id text, name text, description text, umbrella_org_app_name text,
diff --git a/listener.go b/listener.go index 32a1d94..b924c76 100644 --- a/listener.go +++ b/listener.go
@@ -100,7 +100,7 @@ var scope, id, name, orgAppName, createdBy, updatedBy, Description string var updated, created int64 - prep, err := txn.Prepare("INSERT INTO APID_CONFIG (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);") + 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);") if err != nil { log.Error("INSERT APID_CONFIG Failed: ", err) return false @@ -121,6 +121,7 @@ s := txn.Stmt(prep) _, err = s.Exec( id, + guuid, scope, name, orgAppName,