Example #1
0
 def get_valid_cache(self) -> Cache:
     last_available_cache = self._cache_dao.select_one({'is_valid': True})
     if last_available_cache is not None:
         if datetime.fromtimestamp(
                 datetime.timestamp(datetime.now()) -
                 last_available_cache.timestamp).time().hour > 1:
             last_available_cache.is_valid = False
             self._cache_dao.update(last_available_cache)
         return last_available_cache
     else:
         return Cache()
Example #2
0
 def update_cache(self):
     self._cache_dao.insert(Cache())
Example #3
0
 def select_one(self, ftr: dict) -> Cache:
     cache = self.db_connection.select_one(self.collection, ftr)
     return Cache().from_dict(cache) if cache is not None else Cache()
Example #4
0
 def select_many(self, ftr: dict) -> [Cache]:
     return list(
         map(lambda obj: Cache(obj["is_valid"], obj["timestamp"]),
             self.db_connection.select_many(self.collection, ftr)))
Example #5
0
def parseInputs():
    script, filename = argv

    txt = open(filename)

    lines = txt.read().split('\n')

    first_line = lines[0]

    (no_videos, no_endpoints, no_requests, no_caches,
     cache_size) = intTuple(first_line)

    video_size = intTuple(lines[1])

    debug("Video %d" % no_videos)
    debug("Videos size : ")
    debug(video_size)

    videos = []
    for i in range(no_videos):
        videos.append(Video(i, video_size[i]))
    debug(videos)

    caches = []
    for i in range(no_caches):
        caches.append(Cache(i, cache_size, []))

    debug(caches)

    idx = 2

    # loop endpoint
    endpoints = []
    endpoint_id = 0
    while (no_endpoints > 0):
        (latency_to_dc, no_caches) = intTuple(lines[idx])
        idx = idx + 1

        latency_to_caches = dict()
        for i in range(no_caches):
            (cache_server, latency) = intTuple(lines[idx])
            latency_to_caches[cache_server] = latency
            idx = idx + 1

        en = Endpoint(endpoint_id, latency_to_caches, latency_to_dc)
        endpoints.append(en)

        endpoint_id = endpoint_id + 1
        no_endpoints = no_endpoints - 1

    debug(endpoints)

    requests = []
    while (no_requests > 0):
        (video_id, endpoint_id, reqs) = intTuple(lines[idx])

        requests.append(Request(video_id, endpoint_id, reqs))
        idx = idx + 1
        no_requests = no_requests - 1

    debug(requests)

    idx = 2

    return (caches, endpoints, requests, videos)