Skip to content

Commit 5df282f

Browse files
committed
reverted accidental changes
1 parent a52e5bd commit 5df282f

File tree

1 file changed

+89
-25
lines changed

1 file changed

+89
-25
lines changed

main.go

Lines changed: 89 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,111 @@
11
package main
22

33
import (
4-
"context"
5-
"encoding/json"
4+
"bufio"
65
"fmt"
76
"log"
87
"os"
98

10-
"github.com/jalapeno-api-gateway/protorepo-jagw-go/jagw"
119
"google.golang.org/grpc"
1210
"google.golang.org/grpc/credentials/insecure"
11+
"github.com/jalapeno-api-gateway/demo-sr-app/fetch"
12+
"github.com/jalapeno-api-gateway/protorepo-jagw-go/jagw"
1313
)
1414

1515
func main() {
16-
// Get Endpoint as <ip-address>:<port> using the parameters passed by the user
17-
endpoint := fmt.Sprintf("%s:%s", os.Args[1], os.Args[2])
16+
log.Print("Starting SR-App.")
17+
18+
// Get Endpoints
19+
rsEndpoint := getRequestServiceEndpoint()
20+
ssEndpoint := getSubscriptionServiceEndpoint()
1821

1922
// Setup Request Service Connection
20-
var connection *grpc.ClientConn
21-
connection, err := grpc.Dial(endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
22-
if err != nil {
23-
log.Fatalf("Failed to setup request service connection: %s", err)
23+
var rsConnection *grpc.ClientConn
24+
rsConnection, rsErr := grpc.Dial(rsEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
25+
if rsErr != nil {
26+
log.Fatalf("Failed to setup request service connection: %s", rsErr)
2427
}
25-
defer connection.Close()
28+
defer rsConnection.Close()
2629

27-
// Create Client
28-
client := jagw.NewRequestServiceClient(connection)
29-
30-
// Request all Nodes
31-
request := &jagw.TopologyRequest{
32-
Keys: []string{},
33-
Properties: []string{},
30+
// Setup Subscription Service Connection
31+
var ssConnection *grpc.ClientConn
32+
ssConnection, ssErr := grpc.Dial(ssEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
33+
if ssErr != nil {
34+
log.Fatalf("Failed to setup subscription service connection: %s", ssErr)
3435
}
36+
defer ssConnection.Close()
3537

36-
response, err := client.GetLsNodes(context.Background(), request)
37-
if err != nil {
38-
log.Fatalf("Error when calling GetLsNodes on request service: %s", err)
39-
}
38+
// Create Clients
39+
rsClient := jagw.NewRequestServiceClient(rsConnection)
40+
ssClient := jagw.NewSubscriptionServiceClient(ssConnection)
4041

41-
prettyPrint(response)
42+
// Demo requests and subscriptions
43+
makeTopologyRequests(rsClient)
44+
makeTelemetryRequests(rsClient)
45+
makeTopologySubscriptions(ssClient)
46+
makeTelemetrySubscriptions(ssClient)
4247
}
4348

44-
func prettyPrint(any interface{}) {
45-
s, _ := json.MarshalIndent(any, "", " ")
46-
fmt.Printf("%s\n\n", string(s))
49+
func getRequestServiceEndpoint() string {
50+
serverAddress := os.Args[1]
51+
requestServicePort := os.Args[2]
52+
return fmt.Sprintf("%s:%s", serverAddress, requestServicePort) // Returns Endpoint as <ip-address>:<port>
53+
}
54+
55+
func getSubscriptionServiceEndpoint() string {
56+
serverAddress := os.Args[1]
57+
subscriptionServicePort := os.Args[3]
58+
return fmt.Sprintf("%s:%s", serverAddress, subscriptionServicePort) // Returns Endpoint as <ip-address>:<port>
59+
}
60+
61+
func makeTopologyRequests(rsClient jagw.RequestServiceClient) {
62+
// Just for demo purposes:
63+
// Use as stdin scanner to wait for user input before continuing to next request
64+
input := bufio.NewScanner(os.Stdin)
65+
66+
// Make requests
67+
fmt.Print("Press 'Enter' to: REQUEST ALL NODES")
68+
input.Scan()
69+
fetch.GetAllNodes(rsClient)
70+
71+
fmt.Print("Press 'Enter' to: REQUEST SPECIFIC NODES AND SPECIFIC PROPERTIES")
72+
input.Scan()
73+
fetch.GetSpecificNodes(rsClient)
4774
}
75+
76+
func makeTelemetryRequests(rsClient jagw.RequestServiceClient) {
77+
// Just for demo purposes:
78+
// Use as stdin scanner to wait for user input before continuing to next request
79+
input := bufio.NewScanner(os.Stdin)
80+
81+
// Make requests
82+
fmt.Print("Press 'Enter' to: REQUEST DATA RATES OF PAST 60 SECONDS OF SPECIFIC NODE")
83+
input.Scan()
84+
fetch.GetDataRatesOfSpecificNode(rsClient)
85+
}
86+
87+
func makeTopologySubscriptions(ssClient jagw.SubscriptionServiceClient) {
88+
// Just for demo purposes:
89+
// Use as stdin scanner to wait for user input before continuing to next request
90+
input := bufio.NewScanner(os.Stdin)
91+
92+
// Make subscriptions
93+
fmt.Print("Press 'Enter' to: SUBSCRIBE TO ALL LINKS")
94+
input.Scan()
95+
fetch.SubscribeToAllLinks(ssClient)
96+
97+
fmt.Print("Press 'Enter' to: SUBSCRIBE TO SPECIFIC LINK")
98+
input.Scan()
99+
fetch.SubscribeToSpecificLink(ssClient)
100+
}
101+
102+
func makeTelemetrySubscriptions(ssClient jagw.SubscriptionServiceClient) {
103+
// Just for demo purposes:
104+
// Use as stdin scanner to wait for user input before continuing to next request
105+
input := bufio.NewScanner(os.Stdin)
106+
107+
// Make subscriptions
108+
fmt.Print("Press 'Enter' to: SUBSCRIBE TO TELEMETRY DATA OF SPECIFIC NODE")
109+
input.Scan()
110+
fetch.SubscribeToTelemetryDataOfSpecificNode(ssClient)
111+
}

0 commit comments

Comments
 (0)