-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonstring.h
108 lines (89 loc) · 3.22 KB
/
jsonstring.h
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
99
100
101
102
103
104
105
106
107
108
#ifndef jsonstring
#define jsonstring
#include <bits/stdc++.h>
using namespace std;
//CS: Coordination Server
//SS: Slave Server
//leader slave server: the successor of the slave server that went down
/*Used to send either acknowledgemnt(parse_error, key_error, successful put, del, update), or
for successful get, use it to send data from SS to CS, or data from CS to Client
req_type - ack, data
message - client_connected , slave_server_connected, {actual value via get opn}, parse_error, key_error, put_success,
delete_success, update_success, registration_successful, migration_new_server, ready_for_migration, no_slave_server_active,{ip:port},
migration_ss_done, new_ss_succ_of_succ_done
*/
string ack_data_string(string req_type, string message){
string ackstr = "{ \"req_type\" : \"" + req_type + "\", \"message\" : \"" + message + "\" }";
return ackstr;
}
/*informs CS if SS is connecting to it or Client
id - slave_server , client
*/
string identity_string(string id){
string idstr = "{ \"req_type\" : \"identity\", \"id\" : \"" + id + "\" }";
return idstr;
}
/*client send get/delete requests to CS
req_type - get , delete
key - key
*/
string get_delete_CS(string req_type, string key){
string gdreq = "{\"req_type\": \"" + req_type + "\", \"key\" : \""+key +"\"}";
return gdreq;
}
/*client sends put/update request to CS
req_type=put,update
Key
Value
*/
string put_update_CS(string req_type, string key, string value){
string pureq = " { \"req_type\" : \"" +req_type+ "\", \"key\" : \"" +key+ "\", \"value\" : \""
+value+ "\" } ";
return pureq;
}
/*handle migration - inform the leader slave server to proceed with migration
role - leader,new_ss_leader, new_ss_pre,new_ss_succ,new_ss_succ_of_succ
pre_ip , succ_ip , succ_of_succ_ip- ip:ports of these 3
*/
string inform_leader_migration(string role, string pre_ip, string succ_ip, string s_of_succ_ip){
string inf = "{ \"role\" : \"" + role + "\", \"pre_ip\" : \"" +pre_ip+ "\", \"succ_ip\" : \""
+succ_ip+ "\", \"succ_of_succ_ip\" : \"" +s_of_succ_ip+ "\"}";
return inf;
}
/*update table to other member slave server
role - pre, succ_of_succ
table - own,prev
*/
string update_table_SS(string role, string table){
string updtss = "{ \"role\" : \"" + role + "\", \"table\" : \"" + table + "\" }";
return updtss;
}
/*send message from succ of succ to SS leader,
Send message from leader slave server to CS that migration done
message - “ready_for_table” , “migration_completed”
*/
string send_message_ready(string message){
string msgrdy = "{ \"message\" : \"" +message+ "\"}";
return msgrdy;
}
/*CS sends get/delete request to SS
req_type=get, delete
Key
Table = own/prev
*/
string get_delete_SS(string role, string key, string table){
string gdreq = " { \"role\" : \"" +role+ "\", \"key\" : \"" +key+ "\",\"table\" : \""
+table+ "\"} ";
return gdreq;
}
/*CS sends put/update request to SS
req_type=put, update
Key
Table = own/prev
*/
string put_update_SS(string role, string key, string value, string table){
string pureq = " { \"role\" : \"" +role+ "\", \"key\" : \"" +key+ "\", \"value\" : \""
+value+ "\", \"table\" : \"" +table+ "\" } ";
return pureq;
}
#endif