2 // ========================LICENSE_START=================================
5 // Copyright (C) 2021: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
30 "github.com/gorilla/mux"
31 "oransc.org/usecase/oruclosedloop/internal/ves"
38 r.HandleFunc("/create/{jobId}", createJobHandler).Methods(http.MethodPut)
39 r.HandleFunc("/delete/{jobId}", deleteJobHandler).Methods(http.MethodDelete)
41 fmt.Println("Listening on port 8085")
42 fmt.Println(http.ListenAndServe(":8085", r))
45 func createJobHandler(w http.ResponseWriter, r *http.Request) {
47 id, ok := vars["jobId"]
49 http.Error(w, "No job ID provided", http.StatusBadRequest)
54 fmt.Println("Start pushing messages for job: ", id)
55 go startPushingMessages()
58 func deleteJobHandler(w http.ResponseWriter, r *http.Request) {
60 id, ok := vars["jobId"]
62 http.Error(w, "No job ID provided", http.StatusBadRequest)
66 fmt.Println("Stop pushing messages for job: ", id)
70 func startPushingMessages() {
71 message := ves.FaultMessage{
73 CommonEventHeader: ves.CommonEventHeader{
75 SourceName: "ERICSSON-O-RU-11220",
77 FaultFields: ves.FaultFields{
83 client := &http.Client{
84 Timeout: 5 * time.Second,
88 for range time.Tick(2 * time.Second) {
93 message.Event.FaultFields.EventSeverity = "CRITICAL"
97 message.Event.FaultFields.EventSeverity = "NORMAL"
99 m, _ := json.Marshal(message)
100 msgToSend, _ := json.Marshal([]string{string(m)})
102 req, _ := http.NewRequest(http.MethodPost, "http://localhost:40935", bytes.NewBuffer(msgToSend))
103 req.Header.Set("Content-Type", "application/json; charset=utf-8")
105 r, err := client.Do(req)
107 fmt.Println("Error sending to consumer: ", err)
109 fmt.Printf("Sent %v message to consumer. Got response %v\n", message.Event.FaultFields.EventSeverity, r.Status)