def buildJob(name_space, jobAction, ownerId): jobId = str(int(round(time.time() * 1000))) r = app_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 = app_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = app_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "email" r.body.job_op.data.options.value = "shajit4" nvs = app_pb2.NameValueSet() nvs.node_type = app_pb2.NameValueSet.NODE nvs.name = "test" nvs.value = "success" r.body.job_op.data.options.node.extend([nvs]) r.header.originator = 1 r.header.routing_id = app_pb2.Header.JOBS r.header.toNode = 0 msg = r.SerializeToString() return msg
def buildListCourse(ownerId): jobId = str(int(round(time.time() * 1000))) r = app_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = app_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 = app_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = app_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "listcourses" uId = app_pb2.NameValueSet() uId.node_type = app_pb2.NameValueSet.NODE uId.name = "uId" uId.value = "12" r.body.job_op.data.options.node.extend([uId]) r.header.originator = 1 r.header.routing_id = app_pb2.Header.JOBS r.header.toNode = 0 msg = r.SerializeToString() return msg
def buildNS(): r = app_pb2.Request() r.body.space_op.action = app_pb2.NameSpaceOperation.ADDSPACE r.header.originator = 1 r.header.tag = str(int(round(time.time() * 1000))) r.header.routing_id = app_pb2.Header.NAMESPACES m = r.SerializeToString() return m
def buildPing(tag, number): r = app_pb2.Request() r.body.ping.tag = str(tag) r.body.ping.number = number r.header.originator = 1 r.header.tag = str(tag + number + int(round(time.time() * 1000))) r.header.routing_id = app_pb2.Header.PING r.header.toNode = 0 msg = r.SerializeToString() return msg
def buildSignupJob(username, password, firstName, lastName, ownerId): jobId = str(int(round(time.time() * 1000))) r = app_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = app_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 = app_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = app_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "sign_up" email = app_pb2.NameValueSet() email.node_type = app_pb2.NameValueSet.NODE email.name = "email" email.value = username psw = app_pb2.NameValueSet() psw.node_type = app_pb2.NameValueSet.NODE psw.name = "password" psw.value = password fName = app_pb2.NameValueSet() fName.node_type = app_pb2.NameValueSet.NODE fName.name = "firstName" fName.value = firstName lName = app_pb2.NameValueSet() lName.node_type = app_pb2.NameValueSet.NODE lName.name = "lastName" lName.value = lastName r.body.job_op.data.options.node.extend([email, psw, fName, lName]) r.header.originator = 1 r.header.routing_id = app_pb2.Header.JOBS r.header.toNode = 0 msg = r.SerializeToString() return msg
def buildQuestionJob(myTitle, myDescription, myPostdate, ownerId): jobId = str(int(round(time.time() * 1000))) r = app_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = app_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 = app_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = app_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "QuestionJob" title = app_pb2.NameValueSet() title.node_type = app_pb2.NameValueSet.NODE title.name = "title" title.value = myTitle me = app_pb2.NameValueSet() me.node_type = app_pb2.NameValueSet.NODE me.name = "owner" me.value = str(ownerId) description = app_pb2.NameValueSet() description.node_type = app_pb2.NameValueSet.NODE description.name = "description" description.value = myDescription postdate = app_pb2.NameValueSet() postdate.node_type = app_pb2.NameValueSet.NODE postdate.name = "postdate" postdate.value = myPostdate r.body.job_op.data.options.node.extend([title, me, description, postdate]) r.header.originator = 1 r.header.routing_id = app_pb2.Header.JOBS r.header.toNode = 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 = app_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 = app_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = app_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 = app_pb2.JobDesc.JOBQUEUED r.header.originator = 1 r.header.routing_id = app_pb2.Header.JOBS r.header.toNode = 3 msg = r.SerializeToString() return msg
def buildAnswerJob(qId, myDescription, ownerId): jobId = str(int(round(time.time() * 1000))) r = app_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = app_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 = app_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = app_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "AnswerJob" question = app_pb2.NameValueSet() question.node_type = app_pb2.NameValueSet.NODE question.name = "qId" question.value = qId me = app_pb2.NameValueSet() me.node_type = app_pb2.NameValueSet.NODE me.name = "uId" me.value = str(ownerId) description = app_pb2.NameValueSet() description.node_type = app_pb2.NameValueSet.NODE description.name = "description" description.value = myDescription r.body.job_op.data.options.node.extend([question, me, description]) r.header.originator = 1 r.header.routing_id = app_pb2.Header.JOBS r.header.toNode = 0 msg = r.SerializeToString() return msg
def buildShowAnswersJob(ownerId): jobId = str(int(round(time.time() * 1000))) r = app_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = app_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 = app_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = app_pb2.NameValueSet.NODE r.body.job_op.data.options.name = "operation" r.body.job_op.data.options.value = "ShowAnswerJob" r.header.originator = 1 r.header.routing_id = app_pb2.Header.JOBS r.header.toNode = 0 msg = r.SerializeToString() return msg
def buildCourseDescJob(courseName, ownerId): jobId = str(int(round(time.time() * 1000))) r = app_pb2.Request() r.body.job_op.job_id = jobId r.body.job_op.action = app_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 = app_pb2.JobDesc.JOBQUEUED r.body.job_op.data.options.node_type = app_pb2.NameValueSet.VALUE r.body.job_op.data.options.name = "coursename" r.body.job_op.data.options.value = courseName r.header.originator = 1 r.header.routing_id = app_pb2.Header.JOBS r.header.toNode = 0 msg = r.SerializeToString() return msg