Esempio n. 1
0
    def init_data(self):
        print('Data initialization...')
        data = self.load_data()
        for d in data:
            req = Request('PUT', d)
            rdm_sockets = random.sample(list(self._sockets.keys()),
                                        self._options.k)

            for i in rdm_sockets:
                cur_socket = self._sockets[i]

                # Send request's OPTIONS
                cur_socket.send(req.get_options())
                cur_socket.recv(100)

                # Send request
                cur_socket.send(req.get_request())

                # Receive response's OPTIONS
                res_options = pickle.loads(cur_socket.recv(100))
                # Send confirmation
                confirm = Response()
                cur_socket.send(confirm.get_response())

                # Receive response
                res = pickle.loads(cur_socket.recv(res_options['res_size']))
Esempio n. 2
0
    def _is_root_key_duplicated(self, payload):
        root_key, temp_result = payload.split(':', 1)[0].strip('"'), {}
        req = Request('GET', root_key)
        for ip in self._sockets.keys():
            self._stream(req, ip, temp_result)

        # If there is a record with a given key, it will be removed
        if 200 in temp_result:
            if not self._is_all_servers_available():
                raise Exception(
                    '[WARNING] Cannot perform PUT operation in order to update a record. One or more servers are unavailable!'
                )
            else:
                req = Request('DELETE', root_key)
                for ip in self._sockets.keys():
                    self._stream(req, ip, {})
Esempio n. 3
0
 def retrieve_data(self):
     try:
         request = Request()
         result = request.get(SERVICE_ENDPOINT)
         if result:
             return json.loads(result)
     except ConnectionError as e:
         msg = str(e)
         logging.error(msg)
def add_uptime_information_entry():
    data = {'source': 'lasvegas'}

    try:
        request = Request()
        result = request.post(AWS_ENDPOINT, data)
        print(result)
    except ConnectionError as e:
        msg = str(e)
def is_reachable():
    status = None
    success = False

    try:
        request = Request()
        status = retrieve_status(request)
        success = status['success']
    except ConnectionError as e:
        msg = str(e)

    return success
Esempio n. 6
0
    def test_pass(self, params_init):
        """
        用例描述:登陆正向用例
        """
        self.request = Request()
        self.params = params_init.get_params_list('login')
        self.test_assert = Assertions()

        response = self.request.post_request(self.params['Login'][0]['url'],\
                                             self.params['Login'][0]['data'], \
                                             self.params['Login'][0]['header'])

        assert self.test_assert.assert_code(response['code'], 200)
        assert self.test_assert.assert_body(response['body'], 'msg', 'OK')
Esempio n. 7
0
    def _heart_beat(self):
        req = Request('HEART_BEAT')

        ip_address = list(self._sockets.keys())
        for ip in ip_address:
            try:
                # Send request's OPTIONS
                self._sockets[ip].send(req.get_options())
                pickle.loads(self._sockets[ip].recv(100))

                # Send request
                self._sockets[ip].send(req.get_request())
                # Receive response
                pickle.loads(self._sockets[ip].recv(100))

            except socket.error as e:
                print(f'[Error] {e}')
            except EOFError as e:
                del self._sockets[ip]
Esempio n. 8
0
def request_init():
    return Request()
Esempio n. 9
0

if len(sys.argv) < 2:
    print Colors.FAIL + "Please enter a hero name. Eg. 'Faceless Void'" + Colors.ENDC
else:
    hero_name = sys.argv[1]

    client = MongoClient('localhost', 27017)
    print Colors.OKGREEN + "Connected to MongoDB." + Colors.ENDC
    db = client.assignment_1

    heroes_coll = db.heroes
    benchmarks_coll = db.hero_benchmarks
    matchups_coll = db.hero_matchups

    # time.sleep(5) # hack for the mongoDb database to get running

    scrapper = Request()
    heroes = scrapper.getHeroes()

    get_heroes(db)

    selected_hero = get_selected_hero()
    if selected_hero != None:
        print Colors.OKGREEN + "\nDisplaying Hero Data for " + hero_name + ": " + Colors.ENDC
        print pd.DataFrame(selected_hero)
        selected_hero_id = selected_hero['id']

        get_hero_benchmark()
        get_hero_matchups()
Esempio n. 10
0
    def start_shell(self):
        while True:
            cmd = input('kvStore> ').strip()

            if not cmd:
                continue

            if cmd == '!DISCONNECT':
                sys.exit('kvBroker has been disconnected! Bye!')

            else:
                self._heart_beat()
                is_replication_valid = self._is_replication_valid()
                try:
                    req_type, payload = cmd.split(' ', 1)
                except ValueError as e:
                    print('[Error] Payload is missing!')
                    continue

                if req_type == 'PUT':
                    if self._is_replication_supported():
                        print(
                            '[WARNING] Not enough servers to support replication! Please restart the servers!'
                        )
                        continue

                    # Check if a record with the given root key already exists
                    try:
                        self._is_root_key_duplicated(payload)
                    except Exception as e:
                        print(e)
                        continue

                    # Create request
                    req = Request(req_type, payload)
                    # Select random sockets
                    rdm_sockets = random.sample(list(self._sockets.keys()),
                                                self._options.k)

                    # Send request to the selected servers
                    result = {}
                    for ip in rdm_sockets:
                        self._stream(req, ip, result)

                    self.print_result(payload, result)

                elif req_type == 'GET' or req_type == 'QUERY':
                    result = {}
                    req = Request(req_type, payload)

                    for ip in self._sockets.keys():
                        self._stream(req, ip, result)

                    if not is_replication_valid:
                        print(
                            f'[WARNING] Data may be inconsistent. {self._options.k} or more servers are unavailable!'
                        )

                    self.print_result(payload, result)

                elif req_type == 'DELETE':
                    if not self._is_all_servers_available():
                        print(
                            '[WARNING] Cannot perform delete operation. One or more servers are unavailable!'
                        )
                        continue

                    result = {}
                    req = Request(req_type, payload)
                    for ip in self._sockets.keys():
                        self._stream(req, ip, result)

                    self.print_result(payload, result)

                else:
                    print('[INFO] Invalid request type!')
                    print('[INFO] Supported types: PUT | GET | QUERY | DELETE')
Esempio n. 11
0
import asyncio
from config import TEAM_ID
from utils.Request import Request

request = Request()

class Api:
  @staticmethod
  async def getPlayer(nickname):
    return await request.get('/players?nickname=' + nickname + '&game=csgo')

  @staticmethod
  async def getPlayerStats(playerId):
    return await request.get('/players/' + playerId + '/stats/csgo')

  @staticmethod
  async def getTeamMembers():
    return await request.get('/teams/' + TEAM_ID)

  @staticmethod
  async def getPlayerMatch(playerId, rightBound):
    return await request.get('/players/' + playerId + '/history?game=csgo&from=' + str(rightBound) + '&offset=0&limit=1')

  @staticmethod
  async def getMatchInfo(gameId):
    return await request.get('/matches/' + gameId)

  @staticmethod
  async def getMatchStats(gameId):
    return await request.get('/matches/' + gameId + '/stats')