Unverified Commit 142db3b6 authored by Kevin Di Lallo's avatar Kevin Di Lallo Committed by GitHub
Browse files

Merge pull request #287 from pastorsx/sp_dev_services_termination_notifications

Termination Notification Support for MEC services
parents 97ac5d5e 90972f5b
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -255,12 +255,14 @@ func applicationsConfirmTerminationPOST(w http.ResponseWriter, r *http.Request)
		}
	}
	if !found {
		log.Error("AppInstanceId not subscribed for graceful termination")
		http.Error(w, "AppInstanceId not subscribed for graceful termination", http.StatusBadRequest)
		return
	}

	// Check if Confirm Termination was expected
	if appTerminationGracefulTimeoutMap[appInstanceId] == nil {
		log.Error("Unexpected App Confirmation Termination Notification")
		http.Error(w, "Unexpected App Confirmation Termination Notification", http.StatusBadRequest)
		return
	}
@@ -525,7 +527,7 @@ func deregisterAppTermination(subIdStr string) {

func deleteAppSubscriptions(appInstanceId string) {
	for id, sub := range appTerminationNotificationSubscriptionMap {
		if sub.AppInstanceId == appInstanceId {
		if sub != nil && sub.AppInstanceId == appInstanceId {
			subIdStr := strconv.Itoa(id)
			key := baseKey + ":app:" + appInstanceId + ":" + mappsupportKey + ":sub:" + subIdStr
			_ = rc.JSONDelEntry(key, ".")
@@ -606,10 +608,7 @@ func processAppTerminate(appInstanceId string, mep string) {
		notif.OperationAction = &operationAction
		notif.MaxGracefulTimeout = DEFAULT_GRACEFUL_TIMEOUT

		sendAppTermNotification(sub.CallbackReference, notif)
		log.Info("App Termination Notification" + "(" + subIdStr + ") for " + appInstanceId)

		// Start graceful timeout
		// Start graceful timeout prior to sending the app termination notification, or the answer could be received before the timer is started
		gracefulTimeoutTicker := time.NewTicker(time.Duration(DEFAULT_GRACEFUL_TIMEOUT) * time.Second)
		appTerminationGracefulTimeoutMap[appInstanceId] = gracefulTimeoutTicker
		go func() {
@@ -622,6 +621,9 @@ func processAppTerminate(appInstanceId string, mep string) {
				deleteAppInstance(appInstanceId)
			}
		}()
		sendAppTermNotification(sub.CallbackReference, notif)
		log.Info("App Termination Notification" + "(" + subIdStr + ") for " + appInstanceId)

	}

	// Delete App instance immediately if no graceful termination subscription
+96 −0
Original line number Diff line number Diff line
@@ -1652,6 +1652,33 @@ paths:
        '429':
          $ref: '#/components/responses/429'
      x-swagger-router-controller: 'subscriptions'
  /notifications/mec011/appTermination:
    post:
      tags:
      - 'location'
      summary: 'MEC011 Application Termination notification for self termination'
      description: 'Terminates itself.'
      operationId: mec011AppTerminationPOST
      requestBody:
        description: 'Termination notification details'
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AppTerminationNotification'
            example:
                notificationType: 'AppTerminationNotification'
                operationAction: 'TERMINATING'
                maxGracefulTimeout: 10
                links:
                  subscription:
                    href: 'http://mec011Server.example.com/mec_app_support/v1/applications/appId1234/subscriptions/sub123'
                  confirmTermination:
                    href: 'http://mec011Server.example.com/mec_app_support/v1/confirm_termination'
      responses:
        '204':
          description: No Content
      x-swagger-router-controller: 'notifications'
components:
  responses:
    200:
@@ -2988,3 +3015,72 @@ components:
      properties:
        problemDetails:
          $ref: '#/components/schemas/ProblemDetails'
    AppTerminationNotification.Links:
      description: >-
        Object containing hyperlinks related to the resource.
      type: object
      required:
        - subscription
      properties:
        subscription:
          $ref: '#/components/schemas/LinkType'
        confirmTermination:
          $ref: '#/components/schemas/LinkType.ConfirmTermination'
    AppTerminationNotification.MaxGracefulTimeout:
      description: >-
        Maximum timeout value in seconds for graceful termination or graceful
        stop of an application instance.
      type: integer
      format: uint32
      example: 10
    AppTerminationNotification.NotificationType:
      description: Shall be set to AppTerminationNotification.
      type: string
      example: 'AppTerminationNotification'
    AppTerminationNotification:
      description: >-
        This type represents the information that the MEC platform
        notifies the subscribed application instance about  the corresponding
        application instance termination/stop.
      type: object
      required:
        - notificationType
        - operationAction
        - maxGracefulTimeout
        - _links
      properties:
        notificationType:
          $ref: '#/components/schemas/AppTerminationNotification.NotificationType'
        operationAction:
          $ref: '#/components/schemas/OperationActionType'
        maxGracefulTimeout:
          $ref: '#/components/schemas/AppTerminationNotification.MaxGracefulTimeout'
        _links:
          $ref: '#/components/schemas/AppTerminationNotification.Links'
    LinkType:
      description: This type represents a type of link and may be referenced from data structures
      type: object
      properties:
        href:
          $ref: '#/components/schemas/Href'
    LinkType.ConfirmTermination:
      description: >-
        Link to the task resource where to confirm termination in case the
        application is ready to be terminated before expiry of the timeout.
      type: object
      properties:
        href:
          $ref: '#/components/schemas/Href'
    Href:
      description: URI referring to a resource
      type: string
      format: uri
      example: '/mecAppSuptApi/example'
    OperationActionType:
      description: Operation that is being performed on the MEC application instance.
      type: string
      enum:
        - STOPPING
        - TERMINATING
      example: 'TERMINATING'
+2 −0
Original line number Diff line number Diff line
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-ctrl-client v0.0.0-20210505162607-cc887b7a0c0a h1:2aY//J49Jo+U//MDa9kr/lC2KmKm6hLH/mKkT9tEKh0=
github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-ctrl-client v0.0.0-20210505162607-cc887b7a0c0a/go.mod h1:RlTJLiOIOlQ1IRl/un3Ut1tch5NqxNdIaV4HMuFOdr0=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/RyanCarrier/dijkstra v0.0.0-20190726134004-b51cadb5ae52 h1:trnwuu/Q8T59kgRjXcSDBODnyZP9wes+bnLn0lx4PgM=
github.com/RyanCarrier/dijkstra v0.0.0-20190726134004-b51cadb5ae52/go.mod h1:DdR6ymcLl8+sN/XOVNjnYO1NDYfgHskGjreZUDuQCTY=
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)

- API version: 2.1.1
- Build date: 2021-07-30T10:28:27.117574-04:00[America/Toronto]
- Build date: 2021-07-30T17:37:24.731-04:00[America/New_York]


### Running the server
+4 −0
Original line number Diff line number Diff line
@@ -79,6 +79,10 @@ func DistanceSubPUT(w http.ResponseWriter, r *http.Request) {
	distanceSubPut(w, r)
}

func Mec011AppTerminationPOST(w http.ResponseWriter, r *http.Request) {
	mec011AppTerminationPost(w, r)
}

func PeriodicSubDELETE(w http.ResponseWriter, r *http.Request) {
	periodicSubDelete(w, r)
}
Loading