Subscription REST interface update
 - xapp-frame update v0.8.5 -> v0.9.3
 - Added REST interface chages introduced in new xapp-frame
 - Document updated
 - Added workarouds in dockerfile for outdated base image problem

Change-Id: Iad8b5f1450d91c1c650ae5537a7c3d79f347fe82
Signed-off-by: Anssi Mannila <anssi.mannila@nokia.com>
diff --git a/pkg/control/control.go b/pkg/control/control.go
index aaad625..9410925 100755
--- a/pkg/control/control.go
+++ b/pkg/control/control.go
@@ -318,7 +318,7 @@
 //-------------------------------------------------------------------
 //
 //-------------------------------------------------------------------
-func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string) (*RESTSubscription, string, string, error) {
+func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string) (*RESTSubscription, string, error) {
 
 	var restSubId string
 	var restSubscription *RESTSubscription
@@ -357,7 +357,7 @@
 			// Subscription with id in REST request does not exist
 			xapp.Logger.Error("%s", err.Error())
 			c.UpdateCounter(cRestSubFailToXapp)
-			return nil, "", models.SubscriptionInstanceRejectCauseRESTSubscriptionWithGivenIDDoesNotExist, err
+			return nil, "", err
 		}
 
 		if !exists {
@@ -367,7 +367,7 @@
 		}
 	}
 
-	return restSubscription, restSubId, "", nil
+	return restSubscription, restSubId, nil
 }
 
 //-------------------------------------------------------------------
@@ -389,14 +389,14 @@
 		err := fmt.Errorf("ClientEndpoint == nil")
 		xapp.Logger.Error("%v", err)
 		c.UpdateCounter(cRestSubFailToXapp)
-		return c.GetSubscriptionResponse(models.SubscriptionInstanceRejectCauseInvalidRESTRequestMessage, err.Error(), "SUBMGR", ""), common.SubscribeBadRequestCode
+		return nil, common.SubscribeBadRequestCode
 	}
 
 	_, xAppRmrEndpoint, err := ConstructEndpointAddresses(*p.ClientEndpoint)
 	if err != nil {
 		xapp.Logger.Error("%s", err.Error())
 		c.UpdateCounter(cRestSubFailToXapp)
-		return c.GetSubscriptionResponse(models.SubscriptionInstanceRejectCauseInvalidRESTRequestMessage, err.Error(), "SUBMGR", ""), common.SubscribeBadRequestCode
+		return nil, common.SubscribeBadRequestCode
 	}
 
 	md5sum, err := CalculateRequestMd5sum(params)
@@ -404,10 +404,10 @@
 		xapp.Logger.Error("Failed to generate md5sum from incoming request - %s", err.Error())
 	}
 
-	restSubscription, restSubId, rejectCause, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint)
+	restSubscription, restSubId, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint)
 	if err != nil {
-		xapp.Logger.Error("Failed to get/allocate REST subscription")
-		return c.GetSubscriptionResponse(rejectCause, err.Error(), "SUBMGR", ""), common.SubscribeBadRequestCode
+		xapp.Logger.Error("Subscription with id in REST request does not exist")
+		return nil, common.SubscribeNotFoundCode
 	}
 
 	subResp.SubscriptionID = &restSubId
@@ -418,7 +418,7 @@
 		restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum)
 		c.registry.DeleteRESTSubscription(&restSubId)
 		c.UpdateCounter(cRestSubFailToXapp)
-		return c.GetSubscriptionResponse(models.SubscriptionInstanceRejectCauseInvalidRESTRequestMessage, err.Error(), "SUBMGR", ""), common.SubscribeBadRequestCode
+		return nil, common.SubscribeBadRequestCode
 	}
 
 	duplicate := restDuplicateCtrl.IsDuplicateToOngoingTransaction(restSubId, md5sum)
@@ -433,7 +433,7 @@
 	e2SubscriptionDirectives, err := c.GetE2SubscriptionDirectives(p)
 	if err != nil {
 		xapp.Logger.Error("%s", err)
-		return c.GetSubscriptionResponse(models.SubscriptionInstanceRejectCauseInvalidRESTRequestMessage, err.Error(), "SUBMGR", ""), common.SubscribeBadRequestCode
+		return nil, common.SubscribeBadRequestCode
 	}
 	go c.processSubscriptionRequests(restSubscription, &subReqList, p.ClientEndpoint, p.Meid, &restSubId, xAppRmrEndpoint, md5sum, e2SubscriptionDirectives)
 
@@ -468,12 +468,7 @@
 				return nil, fmt.Errorf("p.E2SubscriptionDirectives.E2RetryCount out of range (0-10): %v", *p.E2SubscriptionDirectives.E2RetryCount)
 			}
 		}
-		if p.E2SubscriptionDirectives.RMRRoutingNeeded == nil {
-			xapp.Logger.Error("p.E2SubscriptionDirectives.RMRRoutingNeeded == nil")
-			e2SubscriptionDirectives.CreateRMRRoute = true
-		} else {
-			e2SubscriptionDirectives.CreateRMRRoute = *p.E2SubscriptionDirectives.RMRRoutingNeeded
-		}
+		e2SubscriptionDirectives.CreateRMRRoute = p.E2SubscriptionDirectives.RMRRoutingNeeded
 	}
 	xapp.Logger.Debug("e2SubscriptionDirectives.E2TimeoutTimerValue: %v", e2SubscriptionDirectives.E2TimeoutTimerValue)
 	xapp.Logger.Debug("e2SubscriptionDirectives.E2MaxTryCount: %v", e2SubscriptionDirectives.E2MaxTryCount)
@@ -484,24 +479,6 @@
 //-------------------------------------------------------------------
 //
 //-------------------------------------------------------------------
-func (c *Control) GetSubscriptionResponse(rejectCause string, errorCause string, errorSource string, timeoutType string) *models.SubscriptionResponse {
-	subResp := models.SubscriptionResponse{}
-	subscriptionInstance := models.SubscriptionInstance{}
-	subscriptionInstance.RejectCause = &rejectCause
-	subscriptionInstance.ErrorCause = &errorCause
-	subscriptionInstance.ErrorSource = &errorSource
-	if timeoutType != "" {
-		subscriptionInstance.TimeoutType = &timeoutType
-	}
-	subResp.SubscriptionInstances = append(subResp.SubscriptionInstances, &subscriptionInstance)
-	xapp.Logger.Error("etSubscriptionResponse() %+v", subscriptionInstance)
-
-	return &subResp
-}
-
-//-------------------------------------------------------------------
-//
-//-------------------------------------------------------------------
 
 func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription, subReqList *e2ap.SubscriptionRequestList,
 	clientEndpoint *models.SubscriptionParamsClientEndpoint, meid *string, restSubId *string, xAppRmrEndpoint string, md5sum string, e2SubscriptionDirectives *E2SubscriptionDirectives) {
@@ -624,9 +601,9 @@
 		SubscriptionID: restSubId,
 		SubscriptionInstances: []*models.SubscriptionInstance{
 			&models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID,
-				ErrorCause:          &errorInfo.ErrorCause,
-				ErrorSource:         &errorInfo.ErrorSource,
-				TimeoutType:         &errorInfo.TimeoutType,
+				ErrorCause:          errorInfo.ErrorCause,
+				ErrorSource:         errorInfo.ErrorSource,
+				TimeoutType:         errorInfo.TimeoutType,
 				XappEventInstanceID: &xAppEventInstanceID},
 		},
 	}
@@ -660,7 +637,7 @@
 		SubscriptionID: restSubId,
 		SubscriptionInstances: []*models.SubscriptionInstance{
 			&models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID,
-				ErrorCause:          nil,
+				ErrorCause:          "",
 				XappEventInstanceID: &xAppEventInstanceID},
 		},
 	}
@@ -1506,11 +1483,7 @@
 			fmt.Printf("    E2RetryCount = %v\n", *p.E2SubscriptionDirectives.E2RetryCount)
 		}
 		fmt.Printf("    E2TimeoutTimerValue = %v\n", p.E2SubscriptionDirectives.E2TimeoutTimerValue)
-		if p.E2SubscriptionDirectives.RMRRoutingNeeded == nil {
-			fmt.Println("    RMRRoutingNeeded == nil")
-		} else {
-			fmt.Printf("    RMRRoutingNeeded = %v\n", *p.E2SubscriptionDirectives.RMRRoutingNeeded)
-		}
+		fmt.Printf("    RMRRoutingNeeded = %v\n", p.E2SubscriptionDirectives.RMRRoutingNeeded)
 	}
 	for _, subscriptionDetail := range p.SubscriptionDetails {
 		if p.RANFunctionID != nil {
diff --git a/pkg/control/ut_messaging_test.go b/pkg/control/ut_messaging_test.go
index cd8a832..69e7c1f 100644
--- a/pkg/control/ut_messaging_test.go
+++ b/pkg/control/ut_messaging_test.go
@@ -2619,15 +2619,11 @@
 
 	// Subs Create
 	const subReqCount int = 1
-	//	const e2Timeout int64 = 2
-	//	const e2RetryCount int64 = 2
-	//	const routingNeeded bool = true
 
 	// In order to force both XAPP's to create their own subscriptions, force rtmgr to block a while so that 2nd create
 	// gets into execution before the rtmgrg responds for the first one.
 	waiter := rtmgrHttp.AllocNextSleep(10, true)
 	params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
-	//	params.SetSubscriptionDirectives(e2Timeout, e2RetryCount, routingNeeded)
 	restSubId1 := xappConn1.SendRESTSubsReq(t, params)
 	xappConn2.SendRESTSubsReq(t, params)
 
@@ -3683,8 +3679,12 @@
 	})
 
 	const subReqCount int = 1
+	const e2Timeout int64 = 2
+	const e2RetryCount int64 = 1
+	const routingNeeded bool = true
 
 	params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
+	params.SetSubscriptionDirectives(e2Timeout, e2RetryCount, routingNeeded)
 	restSubId := xappConn1.SendRESTSubsReq(t, params)
 
 	crereq1, cremsg1 := e2termConn1.RecvSubsReq(t)
diff --git a/pkg/teststube2ap/stubE2.go b/pkg/teststube2ap/stubE2.go
index a021cd0..719f214 100644
--- a/pkg/teststube2ap/stubE2.go
+++ b/pkg/teststube2ap/stubE2.go
@@ -838,21 +838,9 @@
 			if resp.SubscriptionInstances[0].E2EventInstanceID != nil {
 				e2RestIds.E2SubsId = uint32(*resp.SubscriptionInstances[0].E2EventInstanceID)
 			}
-			if resp.SubscriptionInstances[0].ErrorCause != nil {
-				e2RestIds.ErrorCause = *resp.SubscriptionInstances[0].ErrorCause
-			} else {
-				e2RestIds.ErrorCause = "nil"
-			}
-			if resp.SubscriptionInstances[0].ErrorSource != nil {
-				e2RestIds.ErrorSource = *resp.SubscriptionInstances[0].ErrorSource
-			} else {
-				e2RestIds.ErrorSource = "nil"
-			}
-			if resp.SubscriptionInstances[0].TimeoutType != nil {
-				e2RestIds.TimeoutType = *resp.SubscriptionInstances[0].TimeoutType
-			} else {
-				e2RestIds.TimeoutType = "nil"
-			}
+			e2RestIds.ErrorCause = resp.SubscriptionInstances[0].ErrorCause
+			e2RestIds.ErrorSource = resp.SubscriptionInstances[0].ErrorSource
+			e2RestIds.TimeoutType = resp.SubscriptionInstances[0].TimeoutType
 		}
 	}
 	return e2RestIds
@@ -900,11 +888,6 @@
 		// Swagger generated code makes checks for the values that are inserted the subscription function
 		// If error cause is unknown and POST is not done, the problem is in the inserted values
 		tc.Error("======== REST subscription request failed %s ========", err.Error())
-		if resp != nil {
-			tc.PrintSubscriptionInsctanceErrorInfo(resp)
-		} else {
-			tc.Error("Subscribe resp == nil")
-		}
 		return ""
 	}
 	tc.subscriptionId = *resp.SubscriptionID
@@ -915,28 +898,6 @@
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
-func (tc *E2Stub) PrintSubscriptionInsctanceErrorInfo(resp *clientmodel.SubscriptionResponse) {
-	for _, subscriptionInstance := range resp.SubscriptionInstances {
-		if subscriptionInstance != nil {
-			if subscriptionInstance.RejectCause != nil {
-				tc.Error("subscriptionInstance.RejectCause= %s", *subscriptionInstance.RejectCause)
-			}
-			if subscriptionInstance.ErrorCause != nil {
-				tc.Error("subscriptionInstance.ErrorCause= %s", *subscriptionInstance.ErrorCause)
-			}
-			if subscriptionInstance.ErrorSource != nil {
-				tc.Error("subscriptionInstance.ErrorSource= %s", *subscriptionInstance.ErrorSource)
-			}
-			if subscriptionInstance.TimeoutType != nil {
-				tc.Error("subscriptionInstance.TimeoutType = %s", *subscriptionInstance.TimeoutType)
-			}
-		}
-	}
-}
-
-//-----------------------------------------------------------------------------
-//
-//-----------------------------------------------------------------------------
 func (tc *E2Stub) GetRESTSubsReqReportParams(subReqCount int) *RESTSubsReqParams {
 
 	reportParams := RESTSubsReqParams{}
@@ -1033,7 +994,7 @@
 	p.SubsReqParams.E2SubscriptionDirectives = E2SubscriptionDirectives
 	p.SubsReqParams.E2SubscriptionDirectives.E2RetryCount = &E2RetryCount
 	p.SubsReqParams.E2SubscriptionDirectives.E2TimeoutTimerValue = E2TimeoutTimerValue
-	p.SubsReqParams.E2SubscriptionDirectives.RMRRoutingNeeded = &RMRRoutingNeeded
+	p.SubsReqParams.E2SubscriptionDirectives.RMRRoutingNeeded = RMRRoutingNeeded
 }
 
 func (p *RESTSubsReqParams) RemoveE2SubscriptionDirectives() {
@@ -1227,7 +1188,7 @@
 	e2SubscriptionDirectives := &clientmodel.SubscriptionParamsE2SubscriptionDirectives{}
 	e2SubscriptionDirectives.E2TimeoutTimerValue = e2Timeout
 	e2SubscriptionDirectives.E2RetryCount = &e2RetryCount
-	e2SubscriptionDirectives.RMRRoutingNeeded = &routingNeeded
+	e2SubscriptionDirectives.RMRRoutingNeeded = routingNeeded
 	p.SubsReqParams.E2SubscriptionDirectives = e2SubscriptionDirectives
 
 }