예제 #1
0
def perform_operation(action,
                      input_id="-1",
                      input_name="-1",
                      input_activities=""):
    print "Performing operation: {0} on instance {1}".format(
        action, args.my_name)  # [debug]
    op_res = False

    if (action == "create"):
        response = create(args.my_name, input_id, input_name, input_activities)
        if (response[0] == 201):  # success
            op_res = True
    elif (action == "retrieve"):
        if (input_id != "-1"
            ):  # "-1" is what we receive if the user didn't provide the id
            response = retrieve_id(args.my_name, input_id)
        else:
            response = retrieve_name(args.my_name, input_name)
        if (response[0] == 200):  #success
            op_res = True
    elif (action == "delete"):
        if (input_id != "-1"
            ):  # "-1" is what we receive if the user didn't provide the id
            response = delete_id(args.my_name, input_id)
        else:
            response = delete_name(args.my_name, input_name)
        if (response[0] == 200):
            op_res = True
    elif (action == "add_activities"):
        response = add(args.my_name, input_id, input_activities)
        if (response[0] == 200):
            op_res = True
    return op_res
예제 #2
0
def perform_operation_msg(in_msg):
    parse_res = parse_sqs_msg(in_msg)
    action = parse_res[0]
    user_id = parse_res[1]
    user_name = parse_res[2]
    user_activities = parse_res[3]
    print "Performing operation: {0} on instance {1}".format(
        action, args.my_name)  # [debug]
    message_out = Message()

    if (action == "create"):
        response = create(args.my_name, user_id, user_name, user_activities)
        # Grab the entire json body and put in the message for SQS
        message_out.set_body(json.dumps(response[1]))
        # Set the response code of the request as a message attribute
        message_out.message_attributes = {
            "response_code": {
                "data_type": "Number",
                "string_value": response[0]
            }
        }
    elif (action == "retrieve"):
        if (user_id != "-1"
            ):  # "-1" is what we receive if the user didn't provide the id
            response = retrieve_id(args.my_name, user_id)
        else:
            response = retrieve_name(args.my_name, user_name)
        message_out.set_body(json.dumps(response[1]))
        message_out.message_attributes = {
            "response_code": {
                "data_type": "Number",
                "string_value": response[0]
            }
        }
    elif (action == "delete"):
        if (user_id != "-1"
            ):  # "-1" is what we receive if the user didn't provide the id
            response = delete_id(args.my_name, user_id)
        else:
            response = delete_name(args.my_name, user_name)

        message_out.set_body(json.dumps(response[1]))
        message_out.message_attributes = {
            "response_code": {
                "data_type": "Number",
                "string_value": response[0]
            }
        }
    elif (action == "add_activities"):
        response = add(args.my_name, user_id, user_activities)

        message_out.set_body(json.dumps(response[1]))
        message_out.message_attributes = {
            "response_code": {
                "data_type": "Number",
                "string_value": response[0]
            }
        }

    return message_out
예제 #3
0
def perform_operation(action, input_id="-1", input_name="-1", input_activities=""):
	print "Performing operation: {0} on instance {1}".format(action, args.my_name) # [debug]
	op_res = False

	if (action == "create"):
		response = create(args.my_name, input_id, input_name, input_activities)
		if (response[0] == 201): # success
			op_res = True
	elif (action == "retrieve"):
		if (input_id != "-1"): # "-1" is what we receive if the user didn't provide the id
			response = retrieve_id(args.my_name, input_id)
		else:
			response = retrieve_name(args.my_name, input_name)
		if (response[0] == 200): #success
			op_res = True
	elif (action == "delete"):
		if (input_id != "-1"): # "-1" is what we receive if the user didn't provide the id
			response = delete_id(args.my_name, input_id)
		else:
			response = delete_name(args.my_name, input_name)
		if (response[0] == 200):
			op_res = True
	elif (action == "add_activities"):
		response = add(args.my_name, input_id, input_activities)
		if (response[0] == 200):
			op_res = True
	return op_res
예제 #4
0
def perform_operation_msg(in_msg):
	parse_res = parse_sqs_msg(in_msg)
	action = parse_res[0]
	user_id = parse_res[1]
	user_name = parse_res[2]
	user_activities = parse_res[3]
	print "Performing operation: {0} on instance {1}".format(action, args.my_name) # [debug]
	message_out = Message()

	if (action == "create"):
		response = create(args.my_name, user_id, user_name, user_activities)
		# Grab the entire json body and put in the message for SQS
		message_out.set_body(json.dumps(response[1]))
		# Set the response code of the request as a message attribute
		message_out.message_attributes = {
			"response_code": {
				"data_type": "Number",
				"string_value": response[0]
			}
		}
	elif (action == "retrieve"):
		if (user_id != "-1"): # "-1" is what we receive if the user didn't provide the id
			response = retrieve_id(args.my_name, user_id)
		else:
			response = retrieve_name(args.my_name, user_name)
		message_out.set_body(json.dumps(response[1]))
		message_out.message_attributes = {
			"response_code": {
				"data_type": "Number",
				"string_value": response[0]
			}
		}
	elif (action == "delete"):
		if (user_id != "-1"): # "-1" is what we receive if the user didn't provide the id
			response = delete_id(args.my_name, user_id)
		else:
			response = delete_name(args.my_name, user_name)

		message_out.set_body(json.dumps(response[1]))
		message_out.message_attributes = {
			"response_code": {
				"data_type": "Number",
				"string_value": response[0]
			}
		}
	elif (action == "add_activities"):
		response = add(args.my_name, user_id, user_activities)

		message_out.set_body(json.dumps(response[1]))
		message_out.message_attributes = {
			"response_code": {
				"data_type": "Number",
				"string_value": response[0]
			}
		}

	return message_out
예제 #5
0
def debug_populate_table():
    create("12", "John", "swimming,sleeping")
    create("13", "SolidSnake", "espionage,cqc")
    create("14", "RevolverOcelot", "six,bullets,more,than,enough")
    create("15", "SniperWolf", "sniping,dying,hankerchieves")
    create("16", "Otacon", "anime")
    create("17", "GrayFox", "pain,snake,anime")
    return
def debug_populate_table():
	create("12", "John", "swimming,sleeping")
	create("13", "SolidSnake", "espionage,cqc")
	create("14", "RevolverOcelot", "six,bullets,more,than,enough")
	create("15", "SniperWolf", "sniping,dying,hankerchieves")
	create("16", "Otacon", "anime")
	create("17", "GrayFox", "pain,snake,anime")
	return