X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Fstub%2Fdmaap%2Fmrstub.go;fp=dmaap-mediator-producer%2Fstub%2Fdmaap%2Fmrstub.go;h=0000000000000000000000000000000000000000;hb=5e92b2132b2300080d8a928b7d9c44906724fd78;hp=451bc9a1cebb8c8a1e8e5736966f9c43a7e78237;hpb=df5eeb6e3fe42f87ac399f624edef20c87d1e475;p=nonrtric.git diff --git a/dmaap-mediator-producer/stub/dmaap/mrstub.go b/dmaap-mediator-producer/stub/dmaap/mrstub.go deleted file mode 100644 index 451bc9a1..00000000 --- a/dmaap-mediator-producer/stub/dmaap/mrstub.go +++ /dev/null @@ -1,103 +0,0 @@ -// - -// ========================LICENSE_START================================= -// O-RAN-SC -// %% -// Copyright (C) 2021: Nordix Foundation -// %% -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ========================LICENSE_END=================================== -// - -package main - -import ( - "encoding/json" - "flag" - "fmt" - "math/rand" - "net/http" - "time" -) - -var r = rand.New(rand.NewSource(time.Now().UnixNano())) - -type FaultMessage struct { - Event Event `json:"event"` -} - -type Event struct { - CommonEventHeader CommonEventHeader `json:"commonEventHeader"` - FaultFields FaultFields `json:"faultFields"` -} - -type CommonEventHeader struct { - Domain string `json:"domain"` - SourceName string `json:"sourceName"` -} - -type FaultFields struct { - AlarmCondition string `json:"alarmCondition"` - EventSeverity string `json:"eventSeverity"` -} - -func main() { - port := flag.Int("port", 3905, "The port this message router will listen on") - flag.Parse() - - http.HandleFunc("/events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/STD_Fault_Messages", handleData) - - fmt.Print("Starting mr on port: ", *port) - fmt.Println(http.ListenAndServeTLS(fmt.Sprintf(":%v", *port), "../../security/producer.crt", "../../security/producer.key", nil)) - -} - -var critical = true - -func handleData(w http.ResponseWriter, req *http.Request) { - time.Sleep(time.Duration(r.Intn(3)) * time.Second) - - w.Header().Set("Content-Type", "application/json") - - var responseBody []byte - if critical { - responseBody = getFaultMessage("CRITICAL") - fmt.Println("Sending CRITICAL") - critical = false - } else { - responseBody = getFaultMessage("NORMAL") - fmt.Println("Sending NORMAL") - critical = true - } - fmt.Fprint(w, string(responseBody)) -} - -func getFaultMessage(eventSeverity string) []byte { - linkFailureMessage := FaultMessage{ - Event: Event{ - CommonEventHeader: CommonEventHeader{ - Domain: "fault", - SourceName: "ERICSSON-O-RU-11220", - }, - FaultFields: FaultFields{ - AlarmCondition: "28", - EventSeverity: eventSeverity, - }, - }, - } - fmt.Printf("Sending message: %v\n", linkFailureMessage) - - messageAsByteArray, _ := json.Marshal(linkFailureMessage) - response := [1]string{string(messageAsByteArray)} - responseAsByteArray, _ := json.Marshal(response) - return responseAsByteArray -}