Enzo 1 rok temu
rodzic
commit
60ae803037
3 zmienionych plików z 77 dodań i 70 usunięć
  1. 1 0
      .gitignore
  2. 1 1
      package.json
  3. 75 69
      test/test4.ts

+ 1 - 0
.gitignore

@@ -2,6 +2,7 @@ node_modules
 *.js.map
 *.js
 appLocation.json
+genericdatas.json
 appLogLoc.json
 appProfile.json
 log.json

+ 1 - 1
package.json

@@ -14,7 +14,7 @@
     "start3a": "node test/test3a.js",
     "start3b": "node test/test3b.js",
     "start3c": "node test/test3c.js",
-    "start4": "node test/test4.js",
+    "start4": "node test/test4a.js",
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   "repository": {

+ 75 - 69
test/test4.ts

@@ -3,6 +3,8 @@
 Highly advisable to refer to test3c for the overall explanation of the logic flow in these
 test cases. Test4 is an adjusted version of test3 to cater for the need to deal with 
 different types of data aside from messageLogs. */
+/* Note: MessageAudit will not work if storage is FIle. Search does not work at logging service
+does not cater for File system storage */
 import * as mongoose from 'mongoose'
 import { Observable, map, Subject, takeUntil, take, of, timer, from } from "rxjs";
 import { ErrorTrigger, MessageSynchronisationServiceSetting } from "../type/datatype";
@@ -16,6 +18,8 @@ import * as fs from "fs"
 /* Convert all the non message data in the database into messageLog type. This is to ensure it's compatibility 
 to be used by the interface from logging and audit message features. */
 const Schema = mongoose.Schema;
+// Use existing schema. 
+const messageSchema = require('../dependencies/log/type/schemas/message.schema')
 // Create the fingerprint schema. This is the type of the data to be transformed into messageLog type
 const fingerPrintSchema = new Schema({
     uuid: { type: String, required: true, lowercase: true, unique: true },
@@ -25,69 +29,23 @@ const fingerPrintSchema = new Schema({
     fileData: { type: Object, required: true },
 });
 
-// Use existing schema. 
-const messageSchema = require('../dependencies/log/type/schemas/message.schema')
-
-// This function is used for convert existing generic data in the designated database to be prepared for
-// AuditMessage service. 
-function convertDataInMongo(url: string) {
-    // Create a subject to stream data received from query at mongo, instantiate convert service and also the database location to read the datas
-    let data: Subject<any> = new Subject()
-    let convertService = new LoggingService()
-    let dbConnection = mongoose.createConnection(url)
-    let dataModel = dbConnection.model('genericdata', fingerPrintSchema)
-    let messages = dbConnection.model('message', messageSchema)
-    
-    // Once the data is queried, it will be streamed into the data Subject declared earlier
-    dataModel.find().then((res) => {
-        // console.log(res)
-        res.forEach((element) => {
-            data.next(element)
-        })
-    })
-    
-    // Assign a `handler` so to speak to handle the element receivd in the data Subject
-    // This is where the transformation happens. The logic is written on the logging service side.
-    // Once that is done, the transformed data will be saved again bacn in the mongo database in a different databse/collection
-    data.subscribe((element) => {
-        let res = convertService.convertCDMStoMessageLog(element, settings.incomingSource.tags)
-        console.log(`Converting fingerprint .... ${res.appData.msgId}`)
-        messages.create(res)
-    })
-}
-
-
-// These declaration are for the secondary to log the converted missing data back in it's own collection at their corresponding servers
-const dbConnection = mongoose.createConnection("mongodb+srv://testDB:h1nt1OyXw6QeUnzS@cluster0.29sklte.mongodb.net/secondary")
-const dataModel = dbConnection.model('genericdata', fingerPrintSchema)
-
-// TO be used by the secondary Subject to convert the message log it receives to complete the synchronization process.
-function convertMessageLogToCDMS(args: MessageLog){
-    let converted = secondary_log.convertMessageLogtoCDMS(args)
-    dataModel.create(converted)
-}
-
-
 /* For basic explanation, pleas refer to test3c. Here we are just instantiating audit and logging service for both
 the primary and the secondary soures. And then the instantiation of the corresponding subjects. 
 The idea is that the subject will receive the missing info provided by the auditor and then log the 
 missing data in the designated database location.
  */
-const primary_sync = new MessageAuditorService()
+const auditor = new MessageAuditorService()
 const primary_Log = new LoggingService()
 const primary: Subject<MessageLog> = new Subject()
 primary.subscribe((element) => {
     console.log(`Primary Received ${element.appData.msgId}`)
 })
-
 const secondary_log = new LoggingService()
 const secondary: Subject<MessageLog> = new Subject()
 secondary.subscribe((element: MessageLog) => {
     console.log(`Secondary Received ${element.appData.msgId}`)
     convertMessageLogToCDMS(element)
 })
-
-
 /* For basic explanation, please refer to test3c. Declaration of the source and target location. */
 let primary_storage: LogSetting = {
     cacheMessageLimit: 0,
@@ -98,11 +56,11 @@ let primary_storage: LogSetting = {
         logLocName: 'To be generated in client',
     },
     customSetting: {
-        server: "192.168.100.59:27017",
-        database: "primary"
+        url: 'mongodb://192.168.100.59:27017/primary'
+        // server: "192.168.100.59:27017",
+        // database: "primary"
     }
 }
-
 let secondary_storage: LogSetting = {
     cacheMessageLimit: 0,
     storage: "MongoDB",
@@ -112,11 +70,12 @@ let secondary_storage: LogSetting = {
         logLocName: 'To be generated in client',
     },
     customSetting: {
-        srv: true,
-        user: "testDB",
-        password: "h1nt1OyXw6QeUnzS",
-        server: "cluster0.29sklte.mongodb.net",
-        database: "secondary",
+        url: 'mongodb+srv://testDB:h1nt1OyXw6QeUnzS@cluster0.29sklte.mongodb.net/secondary'
+        // srv: true,
+        // user: "testDB",
+        // password: "h1nt1OyXw6QeUnzS",
+        // server: "cluster0.29sklte.mongodb.net",
+        // database: "secondary",
     }
 }
 
@@ -132,17 +91,20 @@ let settings: MessageSynchronisationServiceSetting = {
         tags: ['Fingerprint']
     }  //LogSetting & {tags:string[] }  
 }
- 
+
+
+
+
 
 /* -------- SYNCHRONIZATION --------- */
 // Primary will call the syncrhonization service
-primary_sync.init(settings)
+auditor.init(settings)
 
 /* This is where the synchronization logic is called. The errorSubject will act as a trigger
 mechanism to execute the synchronization. */
 let errorSubject: Subject<ErrorTrigger> = new Subject()
 // Subscribe to errorSubject notification 
-let sync = primary_sync.subscribe(errorSubject)
+let sync = auditor.subscribe(errorSubject)
 sync.subscribe({
     next: (msgToBeSynchronized: MessageLog) => {
         console.log(`passing missing message: ${msgToBeSynchronized.appData.msgId} into target/secondary subject.`)
@@ -163,9 +125,63 @@ setTimeout(() => {
     errorSubject.next(sampleError)
 }, 3000)
 
+countdown()
+
+// Convert all the existing cdms into message log
+convertDataInMongo('mongodb://192.168.100.59:27017/primary')
+convertDataInMongo('mongodb+srv://testDB:h1nt1OyXw6QeUnzS@cluster0.29sklte.mongodb.net/secondary')
+
+// These declaration are for the secondary to log the converted missing data back in it's own collection at their corresponding servers
+const dbConnection = mongoose.createConnection("mongodb+srv://testDB:h1nt1OyXw6QeUnzS@cluster0.29sklte.mongodb.net/secondary")
+const dataModel = dbConnection.model('genericdata', fingerPrintSchema)
+
+// Manually log the missing data given by audit
+primary_Log.init(settings.incomingSource).then(() => {
+    primary_Log.subscribe(primary)
+})
+secondary_log.init(settings.target).then(() => {
+    secondary_log.subscribe(secondary)
+})
+
+
+// This function is used for convert existing generic data in the designated database to be prepared for
+// AuditMessage service. 
+function convertDataInMongo(url: string) {
+    // Create a subject to stream data received from query at mongo, instantiate convert service and also the database location to read the datas
+    let data: Subject<any> = new Subject()
+    let convertService = new LoggingService()
+    let dbConnection = mongoose.createConnection(url)
+    let dataModel = dbConnection.model('genericdata', fingerPrintSchema)
+    let messages = dbConnection.model('message', messageSchema)
+
+    // Once the data is queried, it will be streamed into the data Subject declared earlier
+    dataModel.find().then((res) => {
+        // console.log(res)
+        res.forEach((element) => {
+            data.next(element)
+        })
+    })
+
+    // Assign a `handler` so to speak to handle the element receivd in the data Subject
+    // This is where the transformation happens. The logic is written on the logging service side.
+    // Once that is done, the transformed data will be saved again bacn in the mongo database in a different databse/collection
+    data.subscribe((element) => {
+        let res = convertService.convertCDMStoMessageLog(element, settings.incomingSource.tags)
+        console.log(`Converting fingerprint .... ${res.appData.msgId}`)
+        messages.create(res)
+    })
+}
+
+// TO be used by the secondary Subject to convert the message log it receives to complete the synchronization process.
+function convertMessageLogToCDMS(args: MessageLog) {
+    let converted = secondary_log.convertMessageLogtoCDMS(args)
+    dataModel.create(converted)
+}
+
+
 /* THis is testing for generating error message to be fed into the error subject
 to act as additional trigger to exectute the synchronization when there's no internet
-connection. */
+connection. */ // THis part is not mandatory and can be commented out---
 const dns = require('dns');
 
 // Function to check internet connectivity. Basically just look up the site of example.com
@@ -206,13 +222,3 @@ function countdown() {
     }, 1000); // Update every second (1000 milliseconds)
 }
 
-countdown()
-
-// convertDataInMongo('mongodb://192.168.100.59:27017/primary')
-// convertDataInMongo('mongodb+srv://testDB:h1nt1OyXw6QeUnzS@cluster0.29sklte.mongodb.net/secondary')
-
-// // Manually log the missing data given by audit
-secondary_log.init(settings.target).then(() => {
-    secondary_log.subscribe(secondary) 
-})
-