Ejemplo n.º 1
0
 def test_place_in_multiple_servers(self):
     """
     Each client placed in a server, with multiplicative_factor one.
     For each server, the used capacity equals the sum of its clients' demands.
     """
     number_servers = 30
     number_clients = 1000
     server_manager = ServerManager()
     client_manager = ClientManager()
     servers = [
         server_manager.create_server() for i in range(number_servers)
     ]
     clients = [
         client_manager.create_client(random.randint(10, 30))
         for i in range(number_clients)
     ]
     placement_manager = PlacementManager(servers)
     server = 0
     for client in clients:
         placement_manager.place_client(client, servers[server])
         server = (server + 1) % number_servers
     for i in range(number_clients):
         self.assertEqual(placement_manager.get_servers(clients[i]),
                          [(servers[i % number_servers], 1.0)])
     for i in range(number_servers):
         served_clients = [
             clients[j] for j in range(i, number_clients, number_servers)
         ]
         self.assertEqual(
             placement_manager.get_clients_served_by(servers[i]),
             {client: 1.0
              for client in served_clients})
         self.assertEqual(servers[i].used_capacity,
                          sum(client.demand for client in served_clients))
Ejemplo n.º 2
0
def client_loop():
    print("-- Available commands:")

    CM = ClientManager()

    while True:
        choice = input(">> [L]ogin, [C]reate new Client account, e[x]it: ")

        if choice.lower().strip() not in LOGIN_CHOICES:
            print(f"I do not recognize {choice} command.")

        elif choice.lower().strip() == LOGIN_CHOICES[0]:
            print(CM.data)
            client = Client().sign_in(CM)
            if client:
                account_loop(client)
                CM.save_file()
            else:
                print("Cannot perform logging in.")

        elif choice.lower().strip() == LOGIN_CHOICES[1]:
            Client().create(CM)

        elif choice.lower().strip() == LOGIN_CHOICES[2]:
            print("\nSee you next time!")
            break
Ejemplo n.º 3
0
 def test_set_multiplicative_factors(self):
     """
     Place each clients i in two servers:
     server[0], with multiplicative_factor k, and servers[1] with multiplicative_factor 1.0-k.
     """
     number_servers = 2
     number_clients = 1000
     server_manager = ServerManager()
     client_manager = ClientManager()
     servers = [server_manager.create_server() for i in range(number_servers)]
     clients = [client_manager.create_client(random.randint(10, 30)) for i in range(number_clients)]
     placement_manager = PlacementManager(servers)
     multiplicative_factors = [random.random() for i in range(number_clients)]
     for i in range(number_clients):
         placement_manager.reset(clients[i:i+1])
         placement_manager.set_multiplicative_factor(servers[0], clients[i:i+1], multiplicative_factors[i])
         placement_manager.set_multiplicative_factor(servers[1], clients[i:i+1], 1.0 - multiplicative_factors[i])
     for i in range(number_clients):
         retrieved_servers = placement_manager.get_servers(clients[i])
         self.assertEqual(retrieved_servers[0][1], multiplicative_factors[i])
         self.assertEqual(retrieved_servers[1][1], 1.0 - multiplicative_factors[i])
     retrieved_clients = placement_manager.get_clients_served_by(servers[0])
     self.assertEqual(retrieved_clients,
                       {clients[i] : multiplicative_factors[i] for i in range(number_clients)})
     retrieved_clients = placement_manager.get_clients_served_by(servers[1])
     self.assertEqual(retrieved_clients,
                       {clients[i] : 1.0 - multiplicative_factors[i] for i in range(number_clients)})
Ejemplo n.º 4
0
 def test_create_clients(self):
     number_clients = 100
     demands = [random.randint(1, 100) for i in range(number_clients)]
     client_manager = ClientManager()
     clients = [client_manager.create_client(demand) for demand in demands]
     for i in range(number_clients):
         self.assertEqual(clients[i].id, i+1)
         self.assertEqual(clients[i].demand, demands[i])
Ejemplo n.º 5
0
 def test_create_clients(self):
     number_clients = 100
     demands = [random.randint(1, 100) for i in range(number_clients)]
     client_manager = ClientManager()
     clients = [client_manager.create_client(demand) for demand in demands]
     for i in range(number_clients):
         self.assertEqual(clients[i].id, i + 1)
         self.assertEqual(clients[i].demand, demands[i])
Ejemplo n.º 6
0
def disconnect(data):
    client_type = data['type']
    client_uuid = data['uuid']

    if client_type == 'bridge':
        pass
    ClientManager.instance().delete(client_uuid)

    print("disconnect")
Ejemplo n.º 7
0
def send(data):
    uuid = data['uuid']

    client = ClientManager.instance().find(uuid)
    target = ClientManager.instance().find(client.target_id)

    io.emit('send', data, room=target.id)

    print('send', request.sid)
 def __get_clients_and_servers(self, demands, number_servers):
     """
     Input: list with demands and integer number_servers.
     Output: list with clients and list with servers.
     """
     client_manager = ClientManager()
     server_manager = ServerManager()
     clients = [client_manager.create_client(demand) for demand in demands]
     servers = [server_manager.create_server() for i in range(number_servers)]
     return (clients, servers)
Ejemplo n.º 9
0
 def __get_clients_and_servers(self, demands, number_servers):
     """
     Input: list with demands and integer number_servers.
     Output: list with clients and list with servers.
     """
     client_manager = ClientManager()
     server_manager = ServerManager()
     clients = [client_manager.create_client(demand) for demand in demands]
     servers = [
         server_manager.create_server() for i in range(number_servers)
     ]
     return (clients, servers)
Ejemplo n.º 10
0
def room(data):
    client = ClientManager.instance().find(data['uuid'])

    for r in client.rooms:
        io.emit('room', {'title': r, 'caption': ''}, room=client.id)

    print('room', request.sid)
Ejemplo n.º 11
0
def index():
    result = ''

    for c in ClientManager.instance().all():
        result += 'id: %s, type: %s\n' % (c.id, c.type)

    return result
Ejemplo n.º 12
0
def connect(data):
    client_id = request.sid
    client_type = data['type']
    uuid = data['uuid']

    check = ClientManager.instance().find(uuid)

    if check is not None:
        ClientManager.instance().delete(uuid)

    if client_type == 'bridge':
        BridgeClient(client_id, uuid)
    elif client_type == 'user':
        UserClient(client_id, uuid, data['target'])
    else:
        Client(client_id, client_type, uuid)
Ejemplo n.º 13
0
def read_input(file_name):
    """
    Input: file name (string).
    File format:
        int algorithm (1 or 2)
        int number of servers
        list of int [client demands]
    Reads file and outputs a list of clients, a list of servers and the algorithm.
    """
    f = open(file_name, 'r')
    client_manager = ClientManager()
    server_manager = ServerManager()
    algorithm = int(f.readline())
    number_servers = int(f.readline())
    servers = [server_manager.create_server() for i in range(number_servers)]
    demands = map(int, f.readline().split())
    clients = [client_manager.create_client(demand) for demand in demands]
    return clients, servers, algorithm
Ejemplo n.º 14
0
def read_input(file_name):
    """
    Input: file name (string).
    File format:
        int algorithm (1 or 2)
        int number of servers
        list of int [client demands]
    Reads file and outputs a list of clients, a list of servers and the algorithm.
    """
    f = open(file_name, 'r')
    client_manager = ClientManager()
    server_manager = ServerManager()
    algorithm = int(f.readline())
    number_servers = int(f.readline())
    servers = [server_manager.create_server() for i in range(number_servers)]
    demands = map(int, f.readline().split())
    clients = [client_manager.create_client(demand) for demand in demands]
    return clients, servers, algorithm
Ejemplo n.º 15
0
 def test_set_multiplicative_factors(self):
     """
     Place each clients i in two servers:
     server[0], with multiplicative_factor k, and servers[1] with multiplicative_factor 1.0-k.
     """
     number_servers = 2
     number_clients = 1000
     server_manager = ServerManager()
     client_manager = ClientManager()
     servers = [
         server_manager.create_server() for i in range(number_servers)
     ]
     clients = [
         client_manager.create_client(random.randint(10, 30))
         for i in range(number_clients)
     ]
     placement_manager = PlacementManager(servers)
     multiplicative_factors = [
         random.random() for i in range(number_clients)
     ]
     for i in range(number_clients):
         placement_manager.reset(clients[i:i + 1])
         placement_manager.set_multiplicative_factor(
             servers[0], clients[i:i + 1], multiplicative_factors[i])
         placement_manager.set_multiplicative_factor(
             servers[1], clients[i:i + 1], 1.0 - multiplicative_factors[i])
     for i in range(number_clients):
         retrieved_servers = placement_manager.get_servers(clients[i])
         self.assertEqual(retrieved_servers[0][1],
                          multiplicative_factors[i])
         self.assertEqual(retrieved_servers[1][1],
                          1.0 - multiplicative_factors[i])
     retrieved_clients = placement_manager.get_clients_served_by(servers[0])
     self.assertEqual(retrieved_clients, {
         clients[i]: multiplicative_factors[i]
         for i in range(number_clients)
     })
     retrieved_clients = placement_manager.get_clients_served_by(servers[1])
     self.assertEqual(
         retrieved_clients, {
             clients[i]: 1.0 - multiplicative_factors[i]
             for i in range(number_clients)
         })
Ejemplo n.º 16
0
 def test_place_in_single_server(self):
     """
     All clients served by a single server.
     Its used capacity equals the total client demand.
     """
     server_manager = ServerManager()
     client_manager = ClientManager()
     server = server_manager.create_server()
     number_clients = 100
     demands = [random.randint(10, 30) for i in range(number_clients)]
     clients = [client_manager.create_client(demand) for demand in demands]
     placement_manager = PlacementManager([server])
     for client in clients:
         placement_manager.place_client(client, server)
     for client in clients:
         self.assertEqual(placement_manager.get_servers(client), [(server, 1.0)])
     self.assertEqual(placement_manager.get_clients_served_by(server),
                       {client : 1.0 for client in clients})
     self.assertEqual(server.used_capacity, sum(demands))
Ejemplo n.º 17
0
def message(data):
    r = data['room']
    text = data['text']
    data['date'] = str(datetime.datetime.now())

    client = ClientManager.instance().find(data['uuid'])
    users = ClientManager.instance().find_users(client.uuid)

    for user in users:
        if r not in user.rooms:
            json = {'title': r, 'caption': text}

            user.rooms.append(r)
            io.emit('room', json, room=user.id)

            print('room', request.sid)

        io.emit('message', data, room=user.id)

    print('message', request.sid)
Ejemplo n.º 18
0
 def test_place_in_single_server(self):
     """
     All clients served by a single server.
     Its used capacity equals the total client demand.
     """
     server_manager = ServerManager()
     client_manager = ClientManager()
     server = server_manager.create_server()
     number_clients = 100
     demands = [random.randint(10, 30) for i in range(number_clients)]
     clients = [client_manager.create_client(demand) for demand in demands]
     placement_manager = PlacementManager([server])
     for client in clients:
         placement_manager.place_client(client, server)
     for client in clients:
         self.assertEqual(placement_manager.get_servers(client),
                          [(server, 1.0)])
     self.assertEqual(placement_manager.get_clients_served_by(server),
                      {client: 1.0
                       for client in clients})
     self.assertEqual(server.used_capacity, sum(demands))
Ejemplo n.º 19
0
 def test_place_in_multiple_servers(self):
     """
     Each client placed in a server, with multiplicative_factor one.
     For each server, the used capacity equals the sum of its clients' demands.
     """
     number_servers = 30
     number_clients = 1000
     server_manager = ServerManager()
     client_manager = ClientManager()
     servers = [server_manager.create_server() for i in range(number_servers)]
     clients = [client_manager.create_client(random.randint(10, 30)) for i in range(number_clients)]
     placement_manager = PlacementManager(servers)
     server = 0
     for client in clients:
         placement_manager.place_client(client, servers[server])
         server = (server+1)%number_servers
     for i in range(number_clients):
         self.assertEqual(placement_manager.get_servers(clients[i]), [(servers[i%number_servers], 1.0)])
     for i in range(number_servers):
         served_clients = [clients[j] for j in range(i, number_clients, number_servers)]
         self.assertEqual(placement_manager.get_clients_served_by(servers[i]),
                          {client : 1.0 for client in served_clients})
         self.assertEqual(servers[i].used_capacity,
                          sum(client.demand for client in served_clients))
Ejemplo n.º 20
0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. 

"""
 The goal of this file is to serve as a functional example bullfrog ftp plugin.
"""

import pathsetup
from client import ClientManager, Request

client = ClientManager()

kernel_archive_readme = Request(
    source = "ftp://ftp.kernel.org/",
    ftp_cwd="/pub/",
    username = "",
    password = "",
    # File Pattern is a REGEX
    ftp_file_pattern = "^README$",
    ftp_output_dir = "/tmp/ftp_downloads",
)    

kernel_manpages = Request ( 
    source = "ftp://ftp.kernel.org/",
    ftp_cwd="/pub/linux/docs/man-pages/",
    username = '',
Ejemplo n.º 21
0
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

from pymongo import MongoClient

import time
import unicodedata
import json

from client import ClientManager

client = ClientManager()
client.setup()

mongoClient = MongoClient("mongodb+srv://aurelien:[email protected]/lkd?retryWrites=true&w=majority")
db_lkd = mongoClient['lkd']


Peoples = db_lkd['peoples']
Companies = db_lkd['companies']
print(Peoples)
print(Companies)

class Search:

    def __init__(self):
        self.driver = client.driver
Ejemplo n.º 22
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. 

"""
    Simple bullfrog example to pull down multiple rss feeds from
    in parallel, print out item headlines and if site was using http compression.
"""
import os,sys
from xml.dom.minidom import parse, parseString

import pathsetup
from client import ClientManager, Request

# Bullfrog Request
print "Create Client Manager"
client = ClientManager()
client.add_request(source='http://www.gamespot.com/rss/game_updates.php?', accept_compressed=True, timeout=2, nocache=True, key='Gamespot')
client.add_request(source='http://news.cnet.com/2547-1_3-0-20.xml', accept_compressed=True, nocache=True, key='News')
client.add_request(source='http://www.bnet.com/2408-11452_23-0.xml', nocache=True, key='The Insider')
result_set = client.execute()
print "Done executing Client Manager"

for r in result_set:
    if not r.exception:
        feed_dom = parseString(r.response_content) 
        for title in feed_dom.getElementsByTagName('title'):
                print r.key, "Headline: ", title.firstChild.data
        print "HTTP Compression Enabled: ", r.resp_was_compressed
        print "\n\n"