Loading go-apps/meep-ams/server/convert.go 100755 → 100644 +0 −0 File mode changed from 100755 to 100644. View file go-apps/meep-vis/server/vis.go +35 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "errors" "fmt" "net/http" "net/url" "os" Loading Loading @@ -138,7 +139,7 @@ var svcMgmtClient *smc.APIClient var sbxCtrlClient *scc.APIClient var registrationTicker *time.Ticker var subMgr *sm.SubscriptionMgr var subMgr *sm.SubscriptionMgr = nil func notImplemented(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") Loading Loading @@ -567,7 +568,9 @@ func cleanUp() { log.Info("Terminate all") // Flush subscriptions if subMgr != nil { _ = subMgr.DeleteAllSubscriptions() } // Flush all service data rc.DBFlush(baseKey) Loading @@ -592,6 +595,36 @@ func updateStoreName(storeName string) { } } func predictedQosPost(w http.ResponseWriter, r *http.Request) { log.Info(">>> predictedQosPost") w.Header().Set("Content-Type", "application/json; charset=UTF-8") // This hadr-coded response is just for testing purpose // VIS QoS logic shall be imlemented here // Initialize the data structure for the POST request // MEC-030 Clause 6.2.5 // MEC-030 Clause 7.6.3.4 expected_pointA := LocationInfoGeoArea{7.413917, 43.733505} expected_locationInfoA := LocationInfo{nil, &expected_pointA} expected_pointB := LocationInfoGeoArea{7.413916, 43.733515} expected_locationInfoB := LocationInfo{nil, &expected_pointB} // Fill PredictedQosRoutesRouteInfo with LocationInfo list expected_routeInfo := make([]PredictedQosRoutesRouteInfo, 2) expected_routeInfo[0] = PredictedQosRoutesRouteInfo{&expected_locationInfoA, 0, 0, nil} expected_routeInfo[1] = PredictedQosRoutesRouteInfo{&expected_locationInfoB, 0, 0, nil} // PredictedQosRoutes with PredictedQosRoutesRouteInfo list expected_predictedQosRoutes := PredictedQosRoutes{expected_routeInfo} // Fill PredictedQos with PredictedQosRoutes list expected_routes := make([]PredictedQosRoutes, 1) expected_routes[0] = expected_predictedQosRoutes response := PredictedQos{"100", expected_routes, nil} fmt.Println("response: ", response) jsonResponse, err := json.Marshal(response) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) fmt.Fprintf(w, string(jsonResponse)) } go-apps/meep-vis/server/vis_test.go +100 −5 Original line number Diff line number Diff line Loading @@ -20,8 +20,8 @@ import ( "github.com/gorilla/mux" ) const INITIAL = 0 const UPDATED = 1 //const INITIAL = 0 //const UPDATED = 1 //json format using spacing to facilitate reading const testScenario string = ` Loading Loading @@ -492,6 +492,21 @@ func TestPredictedQosPost(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) initializeVars() err := Init() if err != nil { t.Fatalf("Error initializing test basic procedure") } err = Run() if err != nil { t.Fatalf("Error running test basic procedure") } fmt.Println("Set a scenario") initialiseScenario(testScenario) fmt.Println("Scenario was set") /****************************** * expected response section ******************************/ Loading Loading @@ -554,17 +569,97 @@ func TestPredictedQosPost(t *testing.T) { rr, err := sendRequest(http.MethodPost, "/provide_predicted_qos", bytes.NewBuffer(body), nil, nil, http.StatusOK, PredictedQosPOST) if err != nil { t.Fatalf("Failed to get expected expected") t.Fatalf(err.Error()) } log.Info("sendRequest done") var respBody PredictedQos err = json.Unmarshal([]byte(rr), &respBody) if err != nil { t.Fatalf("Failed to get expected response") t.Fatalf(err.Error()) } fmt.Println("respBody: ", respBody) if rr != string(expected_predictedQos_str) { t.Fatalf("Failed to get expected response") t.Fatalf(err.Error()) } log.Info("Received expected response") /****************************** * back to initial state section ******************************/ terminateScenario() } func initializeVars() { mod.DbAddress = redisTestAddr redisAddr = redisTestAddr influxAddr = influxTestAddr sandboxName = testScenarioName } func initialiseScenario(testScenario string) { log.Info(">>> initialiseScenario") //clear DB cleanUp() cfg := mod.ModelCfg{ Name: testScenarioName, Namespace: sandboxName, Module: "test-mod", UpdateCb: nil, DbAddr: redisAddr, } var err error m, err = mod.NewModel(cfg) if err != nil { log.Error("Failed to create model: ", err) return } log.Info("initialiseScenario: model created") // Create message queue mqLocal, err = mq.NewMsgQueue(mq.GetLocalName(testScenarioName), "test-mod", testScenarioName, redisAddr) if err != nil { log.Error("Failed to create Message Queue with error: ", err) return } log.Info("Message Queue created") fmt.Println("Set Model") err = m.SetScenario([]byte(testScenario)) if err != nil { log.Error("Failed to set model: ", err) return } err = m.Activate() if err != nil { log.Error("Failed to activate scenario with err: ", err.Error()) return } msg := mqLocal.CreateMsg(mq.MsgScenarioActivate, mq.TargetAll, testScenarioName) err = mqLocal.SendMsg(msg) if err != nil { log.Error("Failed to send message: ", err) return } time.Sleep(100 * time.Millisecond) } func terminateScenario() { if mqLocal != nil { _ = Stop() msg := mqLocal.CreateMsg(mq.MsgScenarioTerminate, mq.TargetAll, testScenarioName) err := mqLocal.SendMsg(msg) if err != nil { log.Error("Failed to send message: ", err) } time.Sleep(100 * time.Millisecond) } } Loading Loading
go-apps/meep-ams/server/convert.go 100755 → 100644 +0 −0 File mode changed from 100755 to 100644. View file
go-apps/meep-vis/server/vis.go +35 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "errors" "fmt" "net/http" "net/url" "os" Loading Loading @@ -138,7 +139,7 @@ var svcMgmtClient *smc.APIClient var sbxCtrlClient *scc.APIClient var registrationTicker *time.Ticker var subMgr *sm.SubscriptionMgr var subMgr *sm.SubscriptionMgr = nil func notImplemented(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") Loading Loading @@ -567,7 +568,9 @@ func cleanUp() { log.Info("Terminate all") // Flush subscriptions if subMgr != nil { _ = subMgr.DeleteAllSubscriptions() } // Flush all service data rc.DBFlush(baseKey) Loading @@ -592,6 +595,36 @@ func updateStoreName(storeName string) { } } func predictedQosPost(w http.ResponseWriter, r *http.Request) { log.Info(">>> predictedQosPost") w.Header().Set("Content-Type", "application/json; charset=UTF-8") // This hadr-coded response is just for testing purpose // VIS QoS logic shall be imlemented here // Initialize the data structure for the POST request // MEC-030 Clause 6.2.5 // MEC-030 Clause 7.6.3.4 expected_pointA := LocationInfoGeoArea{7.413917, 43.733505} expected_locationInfoA := LocationInfo{nil, &expected_pointA} expected_pointB := LocationInfoGeoArea{7.413916, 43.733515} expected_locationInfoB := LocationInfo{nil, &expected_pointB} // Fill PredictedQosRoutesRouteInfo with LocationInfo list expected_routeInfo := make([]PredictedQosRoutesRouteInfo, 2) expected_routeInfo[0] = PredictedQosRoutesRouteInfo{&expected_locationInfoA, 0, 0, nil} expected_routeInfo[1] = PredictedQosRoutesRouteInfo{&expected_locationInfoB, 0, 0, nil} // PredictedQosRoutes with PredictedQosRoutesRouteInfo list expected_predictedQosRoutes := PredictedQosRoutes{expected_routeInfo} // Fill PredictedQos with PredictedQosRoutes list expected_routes := make([]PredictedQosRoutes, 1) expected_routes[0] = expected_predictedQosRoutes response := PredictedQos{"100", expected_routes, nil} fmt.Println("response: ", response) jsonResponse, err := json.Marshal(response) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) fmt.Fprintf(w, string(jsonResponse)) }
go-apps/meep-vis/server/vis_test.go +100 −5 Original line number Diff line number Diff line Loading @@ -20,8 +20,8 @@ import ( "github.com/gorilla/mux" ) const INITIAL = 0 const UPDATED = 1 //const INITIAL = 0 //const UPDATED = 1 //json format using spacing to facilitate reading const testScenario string = ` Loading Loading @@ -492,6 +492,21 @@ func TestPredictedQosPost(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) initializeVars() err := Init() if err != nil { t.Fatalf("Error initializing test basic procedure") } err = Run() if err != nil { t.Fatalf("Error running test basic procedure") } fmt.Println("Set a scenario") initialiseScenario(testScenario) fmt.Println("Scenario was set") /****************************** * expected response section ******************************/ Loading Loading @@ -554,17 +569,97 @@ func TestPredictedQosPost(t *testing.T) { rr, err := sendRequest(http.MethodPost, "/provide_predicted_qos", bytes.NewBuffer(body), nil, nil, http.StatusOK, PredictedQosPOST) if err != nil { t.Fatalf("Failed to get expected expected") t.Fatalf(err.Error()) } log.Info("sendRequest done") var respBody PredictedQos err = json.Unmarshal([]byte(rr), &respBody) if err != nil { t.Fatalf("Failed to get expected response") t.Fatalf(err.Error()) } fmt.Println("respBody: ", respBody) if rr != string(expected_predictedQos_str) { t.Fatalf("Failed to get expected response") t.Fatalf(err.Error()) } log.Info("Received expected response") /****************************** * back to initial state section ******************************/ terminateScenario() } func initializeVars() { mod.DbAddress = redisTestAddr redisAddr = redisTestAddr influxAddr = influxTestAddr sandboxName = testScenarioName } func initialiseScenario(testScenario string) { log.Info(">>> initialiseScenario") //clear DB cleanUp() cfg := mod.ModelCfg{ Name: testScenarioName, Namespace: sandboxName, Module: "test-mod", UpdateCb: nil, DbAddr: redisAddr, } var err error m, err = mod.NewModel(cfg) if err != nil { log.Error("Failed to create model: ", err) return } log.Info("initialiseScenario: model created") // Create message queue mqLocal, err = mq.NewMsgQueue(mq.GetLocalName(testScenarioName), "test-mod", testScenarioName, redisAddr) if err != nil { log.Error("Failed to create Message Queue with error: ", err) return } log.Info("Message Queue created") fmt.Println("Set Model") err = m.SetScenario([]byte(testScenario)) if err != nil { log.Error("Failed to set model: ", err) return } err = m.Activate() if err != nil { log.Error("Failed to activate scenario with err: ", err.Error()) return } msg := mqLocal.CreateMsg(mq.MsgScenarioActivate, mq.TargetAll, testScenarioName) err = mqLocal.SendMsg(msg) if err != nil { log.Error("Failed to send message: ", err) return } time.Sleep(100 * time.Millisecond) } func terminateScenario() { if mqLocal != nil { _ = Stop() msg := mqLocal.CreateMsg(mq.MsgScenarioTerminate, mq.TargetAll, testScenarioName) err := mqLocal.SendMsg(msg) if err != nil { log.Error("Failed to send message: ", err) } time.Sleep(100 * time.Millisecond) } } Loading