Commit 3d7227c3 authored by Simon Pastor's avatar Simon Pastor
Browse files

activate with automatic start of replay file through rest api

parent 2ed5fc63
Loading
Loading
Loading
Loading
+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: 0.0.1
- Build date: 2020-02-20T15:30:48.431-05:00
- Build date: 2020-02-21T16:24:22.905-05:00


### Running the server
+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: 0.0.1
- Build date: 2020-02-20T15:30:50.617-05:00
- Build date: 2020-02-21T16:24:24.872-05:00


### Running the server
+23 −0
Original line number Diff line number Diff line
@@ -208,6 +208,13 @@ paths:
        required: true
        type: "string"
        x-exportParamName: "Name"
      - in: "body"
        name: "activationInfo"
        description: "Activation information"
        required: true
        schema:
          $ref: "#/definitions/ActivationInfo"
        x-exportParamName: "ActivationInfo"
      responses:
        200:
          description: "OK"
@@ -1024,6 +1031,14 @@ definitions:
        type: "string"
        description: "Service protocol (TCP or UDP)"
    description: "External service exposed internally via specific port"
  ActivationInfo:
    type: "object"
    properties:
      replayFileName:
        type: "string"
        description: "Replay-file name to execute at deployment time"
    description: "Activation information"
    example: {}
  NodeServiceMaps:
    type: "object"
    properties:
@@ -1308,6 +1323,14 @@ parameters:
    schema:
      $ref: "http://localhost:8291/meep-model.yaml#/definitions/Scenario"
    x-exportParamName: "Scenario"
  ActivationInfo:
    in: "body"
    name: "activationInfo"
    description: "Activation information"
    required: true
    schema:
      $ref: "http://localhost:8291/meep-model.yaml#/definitions/ActivationInfo"
    x-exportParamName: "ActivationInfo"
  EventType:
    name: "type"
    in: "path"
+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: 1.0.0
- Build date: 2020-02-20T15:30:31.361-05:00
- Build date: 2020-02-21T16:24:05.382-05:00


### Running the server
+31 −2
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ const moduleMonEngine string = "mon-engine"
const eventTypeMobility = "MOBILITY"
const eventTypeNetCharUpdate = "NETWORK-CHARACTERISTICS-UPDATE"
const eventTypePoasInRange = "POAS-IN-RANGE"
const eventTypeOther = "OTHER"

var scenarioStore *couch.Connector
var replayStore *couch.Connector
@@ -425,6 +426,32 @@ func ceActivateScenario(w http.ResponseWriter, r *http.Request) {
		return
	}

	if r.Body != nil {
		var actInfo ceModel.ActivationInfo
		decoder := json.NewDecoder(r.Body)
		err = decoder.Decode(&actInfo)
		if err != nil {
			log.Error(err.Error())
			//we do not prevent normal proceeding if actInfo is nil
		} else {

			events, err := loadReplay(actInfo.ReplayFileName)
			if err != nil {
				log.Error(err.Error())
				http.Error(w, err.Error(), http.StatusNotFound)
				return
			}

			err = replayMgr.Start(actInfo.ReplayFileName, events, false, false)

			if err != nil {
				log.Error(err.Error())
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
		}
	}

	// Return response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
@@ -620,6 +647,8 @@ func ceSendEvent(w http.ResponseWriter, r *http.Request) {
		err, httpStatus, description = sendEventNetworkCharacteristics(event)
	case eventTypePoasInRange:
		err, httpStatus, description = sendEventPoasInRange(event)
	case eventTypeOther:
		//ignore the event
	default:
		err = errors.New("Unsupported event type")
		httpStatus = http.StatusBadRequest
@@ -1181,7 +1210,7 @@ func ceLoopReplay(w http.ResponseWriter, r *http.Request) {
		return
	}

	err = replayMgr.Start(replayFileName, events, true)
	err = replayMgr.Start(replayFileName, events, true, true)
	if err == nil {
		w.WriteHeader(http.StatusOK)
	} else {
@@ -1202,7 +1231,7 @@ func cePlayReplayFile(w http.ResponseWriter, r *http.Request) {
		return
	}

	err = replayMgr.Start(replayFileName, events, false)
	err = replayMgr.Start(replayFileName, events, false, true)

	if err == nil {
		w.WriteHeader(http.StatusOK)
Loading