Ejemplo n.º 1
0
def add_profile():
    profile = request.get_json()
    # if the given parameter is not in the format of json, e.g. using curl
    if profile == None:
        profile = request.form.copy()
    profile['lastname'] = str(profile['lastname']).title()
    profile['firstname'] = str(profile['firstname']).title()
    profile['check_in'] = int(profile['check_in'])
    profile['public_tag'] = int(profile['public_tag'])
    profile['event_id'] = int(profile['event_id'])
    if 'event_name' in profile.keys():
        profile['event_name'] = str(profile['event_name'])
        DBoperations.add_event(profile['event_id'], profile['event_name'],
                               Event, db)
    if 'session_id' in profile.keys():
        profile['session_id'] = int(profile['session_id'])
        profile['session_name'] = str(profile['session_name'])
        DBoperations.add_session(profile['event_id'], profile['session_id'],
                                 profile['session_name'], Session, db)
    else:
        profile['session_id'] = -1
    user = List.query.filter_by(Email=profile['email']).first()

    # add a new person to database
    if user == None:
        return DBoperations.add_new_person2List(profile, db, List)

    # update the person's information
    else:
        return DBoperations.update_person_in_List(user, profile, db)
Ejemplo n.º 2
0
def add_profile():
    profile = request.get_json()
    # if the given parameter is not in the format of json, e.g. using curl
    if profile == None:
        profile = request.form.copy()
    profile['lastname'] = str(profile['lastname']).title()
    profile['firstname'] = str(profile['firstname']).title()
    profile['check_in'] = int(profile['check_in'])
    profile['public_tag'] = int(profile['public_tag'])
    profile['event_id'] = int(profile['event_id'])
    if 'event_name' in profile.keys():
        profile['event_name'] = str(profile['event_name'])
        DBoperations.add_event(profile['event_id'], profile['event_name'], Event, db)
    if 'session_id' in profile.keys():
        profile['session_id'] = int(profile['session_id'])
        profile['session_name'] = str(profile['session_name'])
        DBoperations.add_session(profile['event_id'], profile['session_id'], profile['session_name'], Session, db)
    else:
        profile['session_id'] = -1
    user = List.query.filter_by(Email=profile['email']).first()

    # add a new person to database
    if user == None:
        return DBoperations.add_new_person2List(profile, db, List)

    # update the person's information
    else:
        return DBoperations.update_person_in_List(user, profile, db)
def main():

    global args
    global table
    global seq_num
    global req_file
    global request_count
    global dbname_a

 
 
    parser = build_parser()
    args = parser.parse_args()
   
    dbname_a = args.name_all.split(',')

    #connect to sqs queues
    in_sqs = getSQSConn(args.inSQS_name)
    out_sqs = getSQSConn(args.outSQS_name)
    
    # Set up the Database
    db_table = getTable(args.name)
   
    #Initialize request id from durable storage
    if not os.path.isfile(REQ_ID_FILE):
        with open(REQ_ID_FILE, 'w', 0) as req_file:
            req_file.write("0\n")

    try:
        req_file = open(REQ_ID_FILE, 'r+', 0)
        request_count = int(req_file.readline())
    except IOError as exc:
        sys.stderr.write(
            "Exception reading request id file '{0}'\n".format(REQ_ID_FILE))
        sys.stderr.write(exc)
        sys.exit(1)

    # Open connection to ZooKeeper and context for zmq
    with kzcl(kazooclientlast.KazooClientLast(hosts=args.zkhost)) as kz, \
        zmqcm(zmq.Context.instance()) as zmq_context:

        # Set up publish and subscribe sockets
        setup_pub_sub(zmq_context, args.sub_to_name)

        # Initialize sequence numbering by ZooKeeper
        try:
            kz.create(path=SEQUENCE_OBJECT, value="0", makepath=True)
        except kazoo.exceptions.NodeExistsError as nee:
            kz.set(SEQUENCE_OBJECT, "0") # Another instance has already created the node
                                         # or it is left over from prior runs

        # Wait for all DBs to be ready
        barrier_path = APP_DIR+BARRIER_NAME
        kz.ensure_path(barrier_path)
        b = kz.create(barrier_path + '/' + args.name, ephemeral=True)
        while len(kz.get_children(barrier_path)) < args.number_dbs:
            time.sleep(1)
        print "Past rendezvous"

        # Now the instances can start responding to requests

        seq_num = kz.Counter(SEQUENCE_OBJECT)

        h = heap.sqsheapq(1)
        while True:
          
          req_msg = in_sqs.read()
          
          if req_msg:
            request = req_msg.get_body()
            in_sqs.delete_message(req_msg)
            seq_num+=1
            last_seq_num = seq_num.last_set
            
            #request = json.dumps(request)
            send(pub_socket, last_seq_num, request)
            #send(pub_socket, seq_num.value, request)
            h.add(last_seq_num, request)
            #h.add(seq_num.value, request)
            #seq_num+=1

          else:
            for soc in sub_sockets:
              try:
                datajson = soc.recv_json(zmq.NOBLOCK)
                seqid = datajson["seq"]
                seqdata = datajson["data"]
                h.add(seqid,seqdata)
              except zmq.ZMQError as e:
                if e.errno != zmq.EAGAIN:
                  raise e

          #while h.counter > 0:
          while h.getLength() > 0:
            top_item = h.remove()
            if top_item:
              #DO OPERATIONS
              import DBoperations
              request_message = top_item[1]

              DBoperations.do_operation(request_message,db_table,out_sqs,True)
              time.sleep(2)

            else:
              for soc in sub_sockets:
                try:
                  datajson = soc.recv_json(zmq.NOBLOCK)
                  seqid = datajson["seq"]
                  #print "3"
                  seqdata = datajson["data"]
                  h.add(seqid,seqdata)
                  #print "4"
                except zmq.ZMQError as e:
                  if e.errno != zmq.EAGAIN:
                    raise e

              time.sleep(5)
Ejemplo n.º 4
0
def recomd_get():
    args = request.args
    name = args['firstname'].title() + ' ' + args['lastname'].title()
    event_id = int(args['event_id'])
    status = List.query.filter_by(Name=name, Email=args['email']).first()
    if status == None:
        return 'Person not found\n'
    elif status.CheckIn != 1:
        return 'Person didn\'t check in\n'
    elif status.EventID != event_id:
        return 'Person checked in but event ID doesn\'t match\n'
    elif not 'session_id' in args.keys():
        user = RECMDLIST.query.filter_by(TARGET_PERSON=name).first()
        if user == None:
            return 'Sorry, we cannot find any recommendations for you'
        recomd_list = ''
        recomd_list += DBoperations.recommendations_filter_by_event(
            user.PERSON1, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(
            user.PERSON2, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(
            user.PERSON3, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(
            user.PERSON4, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(
            user.PERSON5, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(
            user.PERSON6, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(
            user.PERSON7, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(
            user.PERSON8, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(
            user.PERSON9, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(
            user.PERSON10, List, event_id)
    elif 'session_id' in args.keys():
        session_id = int(args['session_id'])
        user = RECMDLIST.query.filter_by(TARGET_PERSON=args['firstname'] +
                                         ', ' + args['lastname']).first()
        if user == None:
            return 'Sorry, we cannot find any recommendations for you'
        recomd_list = ''
        recomd_list += DBoperations.recommendations_filter_by_session(
            user.PERSON1, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(
            user.PERSON2, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(
            user.PERSON3, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(
            user.PERSON4, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(
            user.PERSON5, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(
            user.PERSON6, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(
            user.PERSON7, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(
            user.PERSON8, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(
            user.PERSON9, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(
            user.PERSON10, List, event_id, session_id)
    else:
        recomd_list = 'wrong input'
    return recomd_list
Ejemplo n.º 5
0
def init_recomd():
    DBoperations.get_recommendation_tables()
    return 'Recommedation tables initialiized\n'
Ejemplo n.º 6
0
def reset_List():
    DBoperations.init_List()
    DBoperations.init_event()
    DBoperations.init_session()
    DBlog.reset_logging('log/List.log')
    return 'Successfully reset\n'
Ejemplo n.º 7
0
	def db_main():
		AWS_REGION = AWS_REGION = "us-west-2"
		try:
		    conn = boto.sqs.connect_to_region(AWS_REGION)
		    if conn == None:
		        sys.stderr.write("Could not connect to AWS region '{0}'\n".format(AWS_REGION))
		        sys.exit(1)
		    input_q = conn.get_queue(sqsqueue)
		    #input_q.set_message_class()
		except Exception as e:
		    sys.stderr.write("Exception connecting to SQS\n")
		    sys.stderr.write(str(e))
		    sys.exit(1)

		try: #output quque 
		    conn = boto.sqs.connect_to_region(AWS_REGION)
		    if conn == None:
		        sys.stderr.write("Could not connect to AWS region '{0}'\n".format(AWS_REGION))
		        sys.exit(1)
		    output_q = conn.create_queue(sqsqueue)
		    #input_q.set_message_class()
		except Exception as e:
		    sys.stderr.write("Exception connecting to SQS\n")
		    sys.stderr.write(str(e))
		    sys.exit(1)
		
		try: 
				DB1_table = Table.create('DB1_table', schema=[HashKey('id')], connection = boto.dynamodb2.connect_to_region(AWS_REGION))
		except boto.exception.JSONResponseError	as table_warning:
				if table_warning.body['message'] == "Table already exists: DB1_table":
					DB1_table = Table('DB1_table',connection = boto.dynamodb2.connect_to_region(AWS_REGION))
				else:
					raise table_warning
				
		except Exception as e:
				sys.stderr.write("Exception connecting to DynamoDB\n")
				sys.stderr.write(str(e))
				sys.exit(1)


		while True:
			print "lalala"

			req_smg = input_q.read()
		
		
			if not req_smg:
				time.sleep(1)
			else:
				req = json.loads(req_smg.get_body())
				if req["req_type"] =="delete":
					print "Im deleting"
				#	time.sleep(4)
					import DBoperations
					msg = DBoperations.do_delete(req,DB1_table,output_q)
					
				elif req["req_type"]=="retrieve":
					print "Im retrieving"
					import DBoperations
					msg = DBoperations.do_retrieve(req,DB1_table,output_q)
				elif req["req_type"]== "create":
					print "Im creating"
					import DBoperations
					msg = DBoperations.do_create(req,DB1_table,output_q)
				elif req["req_type"]=="add_activities":
					print "Im addig activities"
					import DBoperations
					msg = DBoperations.do_add_activities(req,DB1_table,output_q)
Ejemplo n.º 8
0
def recomd_get():
    args = request.args
    name = args['firstname'].title() + ' ' + args['lastname'].title()
    event_id = int(args['event_id'])
    status = List.query.filter_by(Name=name, Email=args['email']).first()
    if status == None:
        return 'Person not found\n'
    elif status.CheckIn != 1:
        return 'Person didn\'t check in\n'
    elif status.EventID != event_id:
        return 'Person checked in but event ID doesn\'t match\n'
    elif not 'session_id' in args.keys():
        user = RECMDLIST.query.filter_by(TARGET_PERSON=name).first()
        if user == None:
            return 'Sorry, we cannot find any recommendations for you'
        recomd_list = ''
        recomd_list += DBoperations.recommendations_filter_by_event(user.PERSON1, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(user.PERSON2, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(user.PERSON3, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(user.PERSON4, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(user.PERSON5, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(user.PERSON6, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(user.PERSON7, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(user.PERSON8, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(user.PERSON9, List, event_id)
        recomd_list += DBoperations.recommendations_filter_by_event(user.PERSON10, List, event_id)
    elif 'session_id' in args.keys():
        session_id = int(args['session_id'])
        user = RECMDLIST.query.filter_by(TARGET_PERSON=args['firstname'] + ', ' + args['lastname']).first()
        if user == None:
            return 'Sorry, we cannot find any recommendations for you'
        recomd_list = ''
        recomd_list += DBoperations.recommendations_filter_by_session(user.PERSON1, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(user.PERSON2, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(user.PERSON3, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(user.PERSON4, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(user.PERSON5, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(user.PERSON6, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(user.PERSON7, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(user.PERSON8, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(user.PERSON9, List, event_id, session_id)
        recomd_list += DBoperations.recommendations_filter_by_session(user.PERSON10, List, event_id, session_id)
    else:
        recomd_list = 'wrong input'
    return recomd_list
Ejemplo n.º 9
0
def init_recomd():
    DBoperations.get_recommendation_tables()
    return 'Recommedation tables initialiized\n'
Ejemplo n.º 10
0
def reset_List():
    DBoperations.init_List()
    DBoperations.init_event()
    DBoperations.init_session()
    DBlog.reset_logging('log/List.log')
    return 'Successfully reset\n'