def signUp(): fullname = raw_input("Enter Full Name : ") uname = raw_input("Enter User Name : ") password = raw_input("Enter Password : "******"client" header.tag = "SignUp" #request request = comm_pb2.Request() request.header.CopyFrom(header) request.body.CopyFrom(payload) write(request.SerializeToString(), sock) #SignUp response from server requestResponse = comm_pb2.Request() print_str2 = get_message(sock, requestResponse) print '\n' print print_str2.header.reply_msg
def getCourseList(): #courselist requestList = comm_pb2.RequestList() #payload payload = comm_pb2.Payload() payload.req_list.CopyFrom(requestList) #header header = comm_pb2.Header() header.routing_id = 13 header.originator = "client" header.tag = "CourseList" #request request = comm_pb2.Request() request.header.CopyFrom(header) request.body.CopyFrom(payload) write(request.SerializeToString(), sock) #get Course List from server requestResponse = comm_pb2.Request() getCourseList = comm_pb2.GetCourse() print_str3 = get_message(sock, requestResponse) #print print_str3 list = print_str3.body.req_list.CourseList for course in list: getCourseList = course print "\nCourse ID : " + str(getCourseList.course_id) print "Course Name : " + getCourseList.course_name print "Course Desc : " + getCourseList.course_description
def courseEnrollment(): #print "\nAvailable Courses" #getCourseList() #GetCourse by ID courseId = input("\nEnter Course ID to Enroll : ") getCourse = comm_pb2.GetCourse() getCourse.course_id = courseId #payload payload = comm_pb2.Payload() payload.get_course.CopyFrom(getCourse) #header header = comm_pb2.Header() header.routing_id = 13 header.originator = "client" header.tag = "Enroll" #request request = comm_pb2.Request() request.header.CopyFrom(header) request.body.CopyFrom(payload) write(request.SerializeToString(), sock) #GetCourseID response from server requestResponse = comm_pb2.Request() print_str5 = get_message(sock, requestResponse) print "\nCourse ID : " + str(print_str5.body.get_course.course_id) print "Course Name : " + print_str5.body.get_course.course_name print "Course Description : " + print_str5.body.get_course.course_description print "Enrollment Status : " + print_str5.header.reply_msg
def signIn(): uname = raw_input("Enter User Name : ") password = raw_input("Enter Password : "******"client" header.tag = "SignIn" #request request = comm_pb2.Request() request.header.CopyFrom(header) request.body.CopyFrom(payload) write(request.SerializeToString(), sock) #SignIn reponse from server requestResponse = comm_pb2.Request() headerResp = comm_pb2.Header() print_str1 = get_message(sock, requestResponse) print '\n' print print_str1.header.reply_msg
def handle_desc(): #Build for Get Desc course_value = raw_input( "Enter Course Name for which Desc has to be received : ") request = comm_pb2.Request() #Header request.header.routing_id = request.header.JOBS request.header.originator = "client" request.header.tag = "header for desc Files" request.header.time = long(time.time()) request.header.toNode = "zero" # Sending to node with node.id "zero" #Payload request.body.job_op.action = request.body.job_op.ADDJOB request.body.job_op.data.name_space = "coursedescription" request.body.job_op.data.owner_id = 1 request.body.job_op.data.job_id = "coursedescription" request.body.job_op.data.status = request.body.job_op.data.JOBQUEUED request.body.job_op.data.options.name = "coursename" request.body.job_op.data.options.value = course_value request.body.job_op.data.options.node_type = request.body.job_op.data.options.VALUE #Serialize Data response = serialize_and_send(request) print "##################################" print course_value + "::" + response.body.job_op.data.options.value print "##################################"
def buildListCourse(ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = "listcourses" r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "listcourses" uId = comm_pb2.NameValueSet() uId.node_type = comm_pb2.NameValueSet.NODE uId.name = "uId" uId.value = "12" r.body.job_op.data.options.node.extend([uId]) r.header.originator = "python client" r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = str(0) msg = r.SerializeToString() return msg
def buildListRegisteredCourse(user): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = "listregisteredcourses" r.body.job_op.data.owner_id = 1234 r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "List Register Courses" uId = comm_pb2.NameValueSet() uId.node_type = comm_pb2.NameValueSet.NODE uId.name = "userName" uId.value = user r.body.job_op.data.options.node.extend([uId]) r.header.originator = 100 r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = 1 msg = r.SerializeToString() return msg
def buildRegisterJob(courseName, ownerId, username): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = "register_course" r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "Operation" r.body.job_op.data.options.value = "Course Registration" course = comm_pb2.NameValueSet() course.node_type = comm_pb2.NameValueSet.NODE course.name = "Course Name" course.value = courseName user = comm_pb2.NameValueSet() user.node_type = comm_pb2.NameValueSet.NODE user.name = "User" user.value = username r.body.job_op.data.options.node.extend([course, user]) r.header.originator = 100 r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = 1 msg = r.SerializeToString() return msg
def buildJob(name_space, jobAction, ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = jobAction r.body.job_op.data.name_space = name_space r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "email" r.body.job_op.data.options.value = "shajit4" nvs = comm_pb2.NameValueSet() nvs.node_type = comm_pb2.NameValueSet.NODE nvs.name = "test" nvs.value = "success" r.body.job_op.data.options.node.extend([nvs]) r.header.originator = "python client" r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = str(0) msg = r.SerializeToString() return msg
def handle_signin(): email = raw_input("Enter Email ID: ") password = raw_input("Enter Password: "******"client" request.header.tag = "header for signup" request.header.time = long(time.time()) request.header.toNode = "zero" # Sending to node with node.id "zero" request.body.job_op.action = request.body.job_op.ADDJOB request.body.job_op.data.name_space = "signin" request.body.job_op.data.owner_id = 1 request.body.job_op.data.job_id = "signin" request.body.job_op.data.status = request.body.job_op.data.JOBQUEUED request.body.job_op.data.options.node_type = request.body.job_op.data.options.NODE nvm3 = request.body.job_op.data.options.node.add() nvm3.name = "email" nvm3.value = email nvm3.node_type = request.body.job_op.data.options.VALUE nvm4 = request.body.job_op.data.options.node.add() nvm4.name = "password" nvm4.value = password nvm4.node_type = request.body.job_op.data.options.VALUE response = serialize_and_send(request) print response
def handle_list(): #Build for ListFiles request = comm_pb2.Request() #Header request.header.routing_id = request.header.JOBS request.header.originator = "client" request.header.tag = "header for list Files" request.header.time = long(time.time()) request.header.toNode = "zero" # Sending to node with node.id "zero" #Payload request.body.job_op.action = request.body.job_op.ADDJOB request.body.job_op.data.name_space = "listcourses" request.body.job_op.data.owner_id = 1 request.body.job_op.data.job_id = "listcourses" request.body.job_op.data.status = request.body.job_op.data.JOBQUEUED response = serialize_and_send(request) #Parsing Protobuf File total_courses = len(response.body.job_op.data.options.node) print "List Of Course ::" print "##################################" for i in range(0, total_courses): print response.body.job_op.data.options.node[i].value print "##################################"
def __init__(self): self.host = '' self.port = '' self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) while (self.host == '' and self.port == ''): print('Enter Valid host and port') #host = raw_input ( "host: " ) #port = raw_input ( "port: " ) self.port = "5570" #client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.client_socket.connect(("localhost", int(self.port))) voting = comm_pb2.InitVoting() #voting.voting_id = "1" header = comm_pb2.Header() header.tag = 'Voting' header.originator = 'client' header.routing_id = 2 payload = comm_pb2.Payload() payload.init_voting.MergeFrom(voting) request = comm_pb2.Request() request.body.MergeFrom(payload) request.header.MergeFrom(header) print 'the byte size is' print request.ByteSize() success = self.write(request.SerializeToString()) #received = self.read() requestResponse = comm_pb2.Request() received = self.client_socket.recv(60000) requestResponse.ParseFromString(received) #received = client_socket.recv(60000) #success = client_socket.send("Hit") #data = client_socket.listen();# to do listen print success print requestResponse self.client_socket.close()
def buildGetImageJob(gImage): r = comm_pb2.Request() r.header.photoHeader.requestType = 0 #0 is the requestType for read r.body.photoPayload.uuid = gImage r.header.originator = 0 r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = 1 msg = r.SerializeToString() return msg
def buildDeleteImageJob(dImage): r = comm_pb2.Request() r.header.photoHeader.requestType = 2 #2 is the requestType for delete r.body.photoPayload.uuid = dImage r.header.originator = 0 r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = 1 msg = r.SerializeToString() return msg
def buildNS(): r = comm_pb2.Request() r.body.space_op.action = comm_pb2.NameSpaceOperation.ADDSPACE r.header.originator = "python client" r.header.tag = str(int(round(time.time() * 1000))) r.header.routing_id = comm_pb2.Header.NAMESPACES m = r.SerializeToString() return m
def startVoting(): print "\Asking Cluster to Start Voting" #initvoting voting = comm_pb2.InitVoting() #payload payload = comm_pb2.Payload() payload.init_voting.MergeFrom(voting) #header header = comm_pb2.Header() header.routing_id = 13 header.originator = "client" header.tag = "Voting" #request request = comm_pb2.Request() request.header.MergeFrom(header) request.body.MergeFrom(payload) #write write(request.SerializeToString(), sock) requestResponse = comm_pb2.Request() print_str6 = get_message(sock, requestResponse) print print_str6.body.host_ip
def buildPing(tag, number): r = comm_pb2.Request() r.body.ping.tag = str(tag) r.body.ping.number = number r.header.originator = "python client" r.header.tag = str(tag + number + int(round(time.time() * 1000))) r.header.routing_id = comm_pb2.Header.PING r.header.toNode = str(0) msg = r.SerializeToString() return msg
def buildSaveImageJob(iname, data, ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.header.photoHeader.requestType = 1 #1 is for write r.body.photoPayload.name = iname r.body.photoPayload.data = data r.header.originator = 0 r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = 1 msg = r.SerializeToString() return msg
def getCoursebyID(): #GetCourse by ID courseId = input("Enter Course ID : ") getCourse = comm_pb2.GetCourse() getCourse.course_id = courseId #payload payload = comm_pb2.Payload() payload.get_course.CopyFrom(getCourse) #header header = comm_pb2.Header() header.routing_id = 13 header.originator = "client" header.tag = "SearchCourse" #request request = comm_pb2.Request() request.header.CopyFrom(header) request.body.CopyFrom(payload) write(request.SerializeToString(), sock) #GetCourseID response from server requestResponse = comm_pb2.Request() print_str4 = get_message(sock, requestResponse) print "\nCourse ID : " + str(print_str4.body.get_course.course_id) print "Course Name : " + print_str4.body.get_course.course_name print "Course Description : " + print_str4.body.get_course.course_description
def buildSignupJob(username, password, firstName, lastName, ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = "sign_up" r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "sign_up" email = comm_pb2.NameValueSet() email.node_type = comm_pb2.NameValueSet.NODE email.name = "email" email.value = username psw = comm_pb2.NameValueSet() psw.node_type = comm_pb2.NameValueSet.NODE psw.name = "password" psw.value = password fName = comm_pb2.NameValueSet() fName.node_type = comm_pb2.NameValueSet.NODE fName.name = "firstName" fName.value = firstName lName = comm_pb2.NameValueSet() lName.node_type = comm_pb2.NameValueSet.NODE lName.name = "lastName" lName.value = lastName r.body.job_op.data.options.node.extend([email, psw, fName, lName]) r.header.originator = "python client" r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = str(0) msg = r.SerializeToString() return msg
def buildQuestionJob(myTitle, myDescription, myPostdate, ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = "questionadd" r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "QuestionJob" title = comm_pb2.NameValueSet() title.node_type = comm_pb2.NameValueSet.NODE title.name = "title" title.value = myTitle me = comm_pb2.NameValueSet() me.node_type = comm_pb2.NameValueSet.NODE me.name = "owner" me.value = str(ownerId) description = comm_pb2.NameValueSet() description.node_type = comm_pb2.NameValueSet.NODE description.name = "description" description.value = myDescription postdate = comm_pb2.NameValueSet() postdate.node_type = comm_pb2.NameValueSet.NODE postdate.name = "postdate" postdate.value = myPostdate r.body.job_op.data.options.node.extend([title, me, description, postdate]) r.header.originator = "python client" r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = str(0) msg = r.SerializeToString() return msg
def sendMsg(msg_out, port, host): s = socket.socket() # host = socket.gethostname() # host = "192.168.0.87" s.connect((host, port)) msg_len = struct.pack('>L', len(msg_out)) s.sendall(msg_len + msg_out) len_buf = receiveMsg(s, 4) msg_in_len = struct.unpack('>L', len_buf)[0] msg_in = receiveMsg(s, msg_in_len) r = comm_pb2.Request() r.ParseFromString(msg_in) # print msg_in # print r.body.job_status # print r.header.reply_msg # print r.body.job_op.data.options s.close return r
def buildCompetitionJob(name_space, jobAction, ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = name_space r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.header.originator = "python client" r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = str(3) msg = r.SerializeToString() return msg
def buildAnswerJob(qId, myDescription, ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = "answeradd" r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "AnswerJob" question = comm_pb2.NameValueSet() question.node_type = comm_pb2.NameValueSet.NODE question.name = "qId" question.value = qId me = comm_pb2.NameValueSet() me.node_type = comm_pb2.NameValueSet.NODE me.name = "uId" me.value = str(ownerId) description = comm_pb2.NameValueSet() description.node_type = comm_pb2.NameValueSet.NODE description.name = "description" description.value = myDescription r.body.job_op.data.options.node.extend([question, me, description]) r.header.originator = "python client" r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = str(0) msg = r.SerializeToString() return msg
def buildShowAnswersJob(ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = "answershow" r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "ShowAnswerJob" r.header.originator = "python client" r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = str(0) msg = r.SerializeToString() return msg
def buildIntercluster(ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = "intercluster" r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "interclsuter" r.header.originator = 100 r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = 1 msg = r.SerializeToString() return msg
def buildCourseDescJob(courseName, ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = "getdescription" r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.VALUE r.body.job_op.data.options.name = "coursename" r.body.job_op.data.options.value = courseName r.header.originator = "python client" r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = str(0) msg = r.SerializeToString() return msg
def buildSigninJob(username, password, ownerId): jobId = str(int(round(time.time() * 1000))) r = comm_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = comm_pb2.JobOperation.ADDJOB r.body.job_op.data.name_space = "sign_in" r.body.job_op.data.owner_id = ownerId r.body.job_op.data.job_id = jobId r.body.job_op.data.status = comm_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = comm_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "sign_in" email = comm_pb2.NameValueSet() email.node_type = comm_pb2.NameValueSet.NODE email.name = "email" email.value = username psw = comm_pb2.NameValueSet() psw.node_type = comm_pb2.NameValueSet.NODE psw.name = "password" psw.value = password r.body.job_op.data.options.node.extend([email, psw]) r.header.originator = 0 r.header.routing_id = comm_pb2.Header.JOBS r.header.toNode = 1 msg = r.SerializeToString() return msg
import comm_pb2 import sys import google import socket import struct import time HOST = 'localhost' PORT = 5570 req = comm_pb2.Request() header = req.header body = req.body global s global msg #global msg_buf #res=comm_pb2.Response() def makeHeader(routingId): header.originator = "client" #current time in milliseconds millis = int(round(time.time() * 1000)) header.time = millis header.routing_id = routingId header.tag = "List Courses" return header # This function fills in a Person message based on user input. def sendToChannel(req): for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,