Beispiel #1
0
    def get(self, path, prefix_dir=defines.BLOCKS_DIR):
        path = prefix_dir + path
        while True:
            try:
                retry = True
                cont = 0
                while retry and cont < 5:
                    list_cypher_data = []
                    for provider in self.providers:
                        list_cypher_data.append(
                            self.executor.submit(provider.get, path))

                    if any(x.result() is None for x in list_cypher_data):
                        return None

                    retry = len(
                        set([len(x.result()) for x in list_cypher_data])) != 1

                    if retry:
                        time.sleep(1)
                        cont += 1
            except Exception:
                self.logger.exception("Magic Exception")
                defines.retry_provider_op()
                continue
            defines.provider_op_resumed()
            break

        raw_data_list = []
        for el in list_cypher_data:
            raw_data_list.append(el.result())

        data = decypher(raw_data_list)
        self.downloadBytes += len(data)
        return data
Beispiel #2
0
 def delete(self, path, prefix_dir=defines.BLOCKS_DIR):
     path = prefix_dir + path
     while True:
         try:
             res = []
             for provider in self.providers:
                 res.append(self.executor.submit(provider.delete, path))
             for i in range(0, len(res)):
                 res[i].result()
         except Exception as e:
             self.logger.error("Magic Exception: " + str(e))
             defines.retry_provider_op()
             continue
         defines.provider_op_resumed()
         break
Beispiel #3
0
 def clean(self):
     while True:
         try:
             res = []
             for provider in self.providers:
                 res.append(
                     self.executor.submit(provider.clean,
                                          defines.SAFECLOUD_DIR))
             for i in range(0, len(res)):
                 res[i].result()
         except Exception as e:
             self.logger.error("Magic Exception: " + str(e))
             defines.retry_provider_op()
             continue
         defines.provider_op_resumed()
         break
Beispiel #4
0
 def createDir(self, path):
     # Must go to all providers
     while True:
         try:
             res = []
             for i in range(0, len(self.providers)):
                 res.append(
                     self.executor.submit(self.providers[i].createDir,
                                          path))
                 self.logger.info("magic:createDir:i:" + str(i) + ":path:" +
                                  str(path))
             for i in range(0, len(res)):
                 res[i].result()
         except Exception as e:
             self.logger.error("Magic Exception: " + str(e))
             defines.retry_provider_op()
             continue
         defines.provider_op_resumed()
         break
Beispiel #5
0
    def put(self, data, path, prefix_dir=defines.BLOCKS_DIR):
        path = prefix_dir + path
        while True:
            try:
                list_cypher_data = cypher(data, len(self.providers))
                res = []
                for i in range(0, len(self.providers)):
                    res.append(
                        self.executor.submit(self.providers[i].put,
                                             list_cypher_data[i], path))
                    self.logger.info("magic:put:i:" + str(i) + ":path:" +
                                     str(path))

                for i in range(0, len(res)):
                    res[i].result()
            except Exception as e:
                self.logger.error("Magic Exception: " + str(e))
                defines.retry_provider_op()
                continue
            defines.provider_op_resumed()
            break
        self.uploadBytes += len(data)