Commit e585d3b6 authored by Yann Garcia's avatar Yann Garcia
Browse files

Add support of Application Context Delete notification

parent be428c87
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -175,6 +175,27 @@ paths:
      summary: Obtain the location constraints for a new application context.
      tags:
      - DAI
  /dai/callback/ApplicationContextDeleteNotification:
    post:
      tags:
      - notification
      summary: Callback endpoint for MEC016 Notifications
      description: Callback endpoint for MEC016 Notifications
      operationId: ApplicationContextDeleteNotificationCallback
      requestBody:
        description: MEC application termination
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApplicationContextDeleteNotification'
        required: true
      responses:
        "200":
          description: OK
        "400":
          description: Bad request
        "404":
          description: Not found
  /services/callback/service-availability:
    post:
      tags:
+4 −0
Original line number Diff line number Diff line
@@ -20,3 +20,7 @@ func AppTerminationNotificationCallback(w http.ResponseWriter, r *http.Request)
func ServiceAvailNotificationCallback(w http.ResponseWriter, r *http.Request) {
	serviceAvailNotificationCallback(w, r)
}

func ApplicationContextDeleteNotificationCallback(w http.ResponseWriter, r *http.Request) {
	applicationContextDeleteNotificationCallback(w, r)
}
+23 −0
Original line number Diff line number Diff line
@@ -468,6 +468,29 @@ func Terminate() {

}

// REST API handle service subscription callback notification
func applicationContextDeleteNotificationCallback(w http.ResponseWriter, r *http.Request) {
	log.Info(">>> applicationContextDeleteNotificationCallback: ", r.Body)

	// Decode request body
	var notification ApplicationContextDeleteNotification
	decoder := json.NewDecoder(r.Body)
	err := decoder.Decode(&notification)
	if err != nil {
		log.Error(err)
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprintf(w, "Error Decoding Notification")
	}
	log.Info("Application Context Delete notification: notification: ", notification)

	// Remove AppContext entry
	delete(appContexts, notification.ContextId)
	log.Debug("Application Context Delete notification, contextId: " + notification.ContextId + " [200]")
	appActivityLogs = append(appActivityLogs, mep + " Application Context Delete notification, contextId: " + notification.ContextId + " [200]")

	w.WriteHeader(http.StatusOK)
}

// REST API handle service subscription callback notification
func serviceAvailNotificationCallback(w http.ResponseWriter, r *http.Request) {

+8 −0
Original line number Diff line number Diff line
@@ -139,4 +139,12 @@ var routes = Routes{
		"/application/termination",
		AppTerminationNotificationCallback,
	},

	Route{
		"ApplicationContextDeleteNotificationCallback",
		strings.ToUpper("Post"),
		"/dai/callback/ApplicationContextDeleteNotification",
		ApplicationContextDeleteNotificationCallback,
	},

}
+28 −3
Original line number Diff line number Diff line
@@ -10,14 +10,17 @@
package main

import (
	"context"
	"log"
	"net/http"
	"os"
	"os/signal"

	server "github.com/InterDigitalInc/AdvantEDGE/example/demo4/src/onboarded-demo/server"
)

const (
	port = ":31124"
	port = ":31124" // hardcoded in mepp-dai Chart template
)

func main() {
@@ -35,5 +38,27 @@ func main() {
	router := server.NewRouter(FrontendApiController)

	log.Printf("Server started on port " + port)
	log.Fatal(http.ListenAndServe(port, router))
	srv := &http.Server{Addr: port, Handler: router}
	go func() {
		//returns ErrServerClosed on graceful close
		log.Printf("Call ListenAndServe")
		if err := srv.ListenAndServe(); err != http.ErrServerClosed {
			log.Printf("ListenAndServe(): %s", err)
			return
		}
		log.Printf("Terminate goroutine")
	}()

	//	log.Fatal(http.ListenAndServe(port, router))
	log.Printf("Configure signals")
	c := make(chan os.Signal)
	signal.Notify(c, os.Interrupt)
	sig := <-c
	log.Printf("Got %s signal. Aborting...\n", sig)
	server.Terminate()
	err = srv.Shutdown(context.TODO())
	if err != nil {
		log.Printf("Shutdown(): %s", err)
		return
	}
}
Loading