-
Notifications
You must be signed in to change notification settings - Fork 0
/
starter.go
98 lines (82 loc) · 2.93 KB
/
starter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
)
func main() {
log.SetOutput(os.Stdout)
log.Fatal(http.ListenAndServe(":9702", makeRouter()))
}
func makeRouter() *mux.Router {
router := mux.NewRouter()
router.HandleFunc("/hitec/orchestration/app/observe/google-play/package-name/{package_name}/interval/{interval}", postObserveAppGooglePlay).Methods("POST")
router.HandleFunc("/hitec/orchestration/app/process/google-play/package-name/{package_name}", postProcessAppGooglePlay).Methods("POST")
return router
}
/*
* This method calls for each step the reponsible MS
*
* Steps:
* 1. store app to observe
* 2. notify the observer (crawler)
* 2.1 notify the processing layer to classify the newly addded reviews
*/
func postObserveAppGooglePlay(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
packageName := params["package_name"]
interval := params["interval"] // possible intervals: minutely, hourly, daily, monthly
// 1. store app to observe
ok := RESTPostStoreObserveAppGooglePlay(packageName, interval)
w.Header().Set("Content-Type", "application/json")
if !ok {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(Response{Status: false, Message: "storage layer unreachable"})
return
}
// 2. notify the observer (crawler)
RestartObservation()
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(Response{Status: true, Message: "observation successfully initiated"})
}
/*
* This method calls for each step the reponsible MS
*
* Steps:
* 1. crawl app page
* 2. store app page
* 2. crawl app reviews
* 3. process reviews
* 4. store processed app reviews
*/
func postProcessAppGooglePlay(w http.ResponseWriter, r *http.Request) {
fmt.Println("postProcessAppGooglePlay called")
params := mux.Vars(r)
packageName := params["package_name"]
// 1. crawl app page
fmt.Println("1. crawl app page")
appPage := RESTGetAppPageGooglePlay(packageName)
// 2. store app page
fmt.Println("2. store app page")
ok := RESTPostStoreAppPageGooglePlay(appPage)
fmt.Println("Could store app page", ok)
// 3. crawl app reviews
fmt.Println("3. crawl app reviews")
crawledAppReviews := RESTGetAppReviewsGooglePlay(packageName, 0)
nonExistingAppReviews := RESTPostNonExistingAppReviewsGooglePlay(crawledAppReviews) // just consider app reviews that are not processed yet
// 4. process reviews
fmt.Println("4. process reviews")
processedAppReviess := RESTPostProcessAppReviewsGooglePlay(nonExistingAppReviews)
// 5. store processed app reviews
fmt.Println("5. store processed app reviews")
if ok := RESTPostStoreProcessedAppReviewsGooglePlay(processedAppReviess); !ok {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(Response{Status: false, Message: "storage service is not available"})
return
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(Response{Status: true, Message: "crawled, processed, and stored app reviews"})
}