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"
33 var client = &http.Client{
34 Timeout: 5 * time.Second,
38 port := flag.Int("port", 8083, "The port this consumer will listen on")
40 fmt.Println("Starting ICS stub on port ", *port)
43 r.HandleFunc("/data-consumer/v1/info-jobs/{jobId}", handleCalls).Methods(http.MethodPut, http.MethodDelete)
44 fmt.Println(http.ListenAndServe(fmt.Sprintf(":%v", *port), r))
47 func getEnv(key string, defaultVal string) string {
48 if value, exists := os.LookupEnv(key); exists {
55 func handleCalls(w http.ResponseWriter, r *http.Request) {
56 producer_addr := getEnv("PRODUCER_ADDR", "http://producer-sim:8085/")
58 id, ok := vars["jobId"]
60 fmt.Println(r.Method, " of job ", id)
61 if r.Method == http.MethodPut {
62 req, _ := http.NewRequest(http.MethodPut, producer_addr+"create/"+id, nil)
63 r, err := client.Do(req)
65 fmt.Println("Failed to create job in producer ", err)
68 fmt.Println("Created job in producer ", r.Status)
70 req, _ := http.NewRequest(http.MethodDelete, producer_addr+"delete/"+id, nil)
71 r, err := client.Do(req)
73 fmt.Println("Failed to delete job in producer ", err)
76 fmt.Println("Deleted job in producer ", r.Status)