Beispiel #1
0
 def update(self, venv_id, name, description, source_path):
     result = True
     try:
         data = {}
         need_update = False
         if name:
             data["name"] = name
         if description:
             data["description"] = description
         if os.path.exists(source_path) and os.path.isfile(source_path):
             sha1 = file_sha1sum(source_path)
             data["sha1"] = sha1
             LOG.debug("sha1: %s, %s", sha1, type(sha1))
             venv_path = self.make_venv_version_path(venv_id, sha1)
             if os.path.exists(venv_path):
                 shutil.rmtree(venv_path)
             os.makedirs(venv_path)
             shutil.copy2(source_path, os.path.join(venv_path,
                                                    "venv.tar.gz"))
             os.remove(source_path)
             need_update = True
         if data or need_update:
             success = Venvs.instance().update(venv_id, data)
             if success:
                 if "sha1" in data:
                     description = "" if "description" not in data else data[
                         "description"]
                     VenvHistory.instance().add(venv_id,
                                                data["sha1"],
                                                description=description)
             else:
                 result = False
     except Exception as e:
         LOG.exception(e)
     return result
Beispiel #2
0
 def create(self, name, description, source_path):
     sha1 = file_sha1sum(source_path)
     LOG.debug("sha1: %s, %s", sha1, type(sha1))
     venv_id = Venvs.instance().add(name, sha1, description=description)
     venv_path = self.make_venv_version_path(venv_id, sha1)
     if os.path.exists(venv_path):
         shutil.rmtree(venv_path)
     os.makedirs(venv_path)
     shutil.copy2(source_path, os.path.join(venv_path, "venv.tar.gz"))
     os.remove(source_path)
     VenvHistory.instance().add(venv_id, sha1, description=description)
     return venv_id
Beispiel #3
0
 def create(self, name, description, source_path):
     sha1 = file_sha1sum(source_path)
     LOG.debug("sha1: %s, %s", sha1, type(sha1))
     venv_id = Venvs.instance().add(name, sha1, description=description)
     venv_path = self.make_venv_version_path(venv_id, sha1)
     self.ldfs.delete_directory(venv_path)
     self.ldfs.create_file(source_path,
                           os.path.join(venv_path, "venv.zip"),
                           replica=1)
     os.remove(source_path)
     VenvHistory.instance().add(venv_id, sha1, description=description)
     return venv_id
Beispiel #4
0
 def delete(self, venv_id):
     result = False
     try:
         success = Venvs.instance().delete(venv_id)
         if success:
             VenvHistory.instance().delete_by_venv_id(venv_id)
             venv_path = self.make_venv_path(venv_id)
             self.ldfs.delete_directory(venv_path)
             LOG.debug("remove ldfs directory: %s", venv_path)
             result = True
     except Exception as e:
         LOG.exception(e)
     return result
Beispiel #5
0
 def delete(self, venv_id):
     result = False
     try:
         success = Venvs.instance().delete(venv_id)
         if success:
             VenvHistory.instance().delete_by_venv_id(venv_id)
             venv_path = self.make_venv_path(venv_id)
             if os.path.exists(venv_path):
                 shutil.rmtree(venv_path)
                 LOG.debug("remove directory: %s", venv_path)
             result = True
     except Exception as e:
         LOG.exception(e)
     return result
Beispiel #6
0
 def activate_history(self, history_id, venv_id=""):
     result = False
     try:
         if venv_id:
             history = self.info_history(history_id, venv_id=venv_id)
             if history:
                 data = {"sha1": history["sha1"]}
                 if history["description"]:
                     data["description"] = history["description"]
                 success = Venvs.instance().update(venv_id, data)
                 if success:
                     result = True
     except Exception as e:
         LOG.exception(e)
     return result
Beispiel #7
0
 def info(self, venv_id):
     return Venvs.instance().get(venv_id)
Beispiel #8
0
 def list(self, offset, limit, filters={}):
     return Venvs.instance().list(offset=offset,
                                  limit=limit,
                                  filters=filters)
Beispiel #9
0
def main():
    parser = argparse.ArgumentParser(prog='litemanager')
    parser.add_argument("-c",
                        "--config",
                        required=True,
                        help="configuration file path")
    parser.add_argument("-v",
                        "--version",
                        action='version',
                        version='%(prog)s ' + __version__)
    args = parser.parse_args()

    if args.config:
        success = load_config(args.config)
        if success:
            common.init_storage()
            logger.config_logging(file_name="manager.log",
                                  log_level=CONFIG["log_level"],
                                  dir_name=CONFIG["log_path"],
                                  day_rotate=False,
                                  when="D",
                                  interval=1,
                                  max_size=20,
                                  backup_count=5,
                                  console=True)

            LOG.info("service start")

            try:
                if CONFIG["ldfs_http_host"] and CONFIG["ldfs_http_port"]:
                    LDFS = LiteDFS(CONFIG["ldfs_http_host"],
                                   CONFIG["ldfs_http_port"])
                venvs_db = Venvs()
                venv_history_db = VenvHistory()
                tasks_db = Tasks()
                applications_db = Applications()
                application_history_db = ApplicationHistory()
                workflows_db = Workflows()
                works_db = Works()
                schedules_db = Schedules()
                services_db = Services()
                venv_manager = VenvManager()
                app_manager = AppManager()
                task_scheduler = Scheduler(CONFIG["scheduler_interval"])
                http_server = tornado.httpserver.HTTPServer(
                    Application(),
                    max_buffer_size=CONFIG["max_buffer_size"],
                    chunk_size=10 * 1024 * 1024)
                http_server.listen(CONFIG["http_port"],
                                   address=CONFIG["http_host"])
                # http_server.bind(CONFIG["http_port"], address = CONFIG["http_host"])
                listener = DiscoveryListener(Connection, task_scheduler)
                listener.listen(CONFIG["tcp_port"], CONFIG["tcp_host"])
                stop_service.Servers.HTTP_SERVER = http_server
                stop_service.Servers.SERVERS.append(task_scheduler)
                stop_service.Servers.SERVERS.append(venvs_db)
                stop_service.Servers.SERVERS.append(venv_history_db)
                stop_service.Servers.SERVERS.append(applications_db)
                stop_service.Servers.SERVERS.append(application_history_db)
                stop_service.Servers.SERVERS.append(tasks_db)
                stop_service.Servers.SERVERS.append(workflows_db)
                stop_service.Servers.SERVERS.append(works_db)
                stop_service.Servers.SERVERS.append(schedules_db)
                stop_service.Servers.SERVERS.append(services_db)
                stop_service.Servers.SERVERS.append(venv_manager)
                stop_service.Servers.SERVERS.append(app_manager)
                signal.signal(signal.SIGTERM, stop_service.sig_handler)
                signal.signal(signal.SIGINT, stop_service.sig_handler)
                tornado.ioloop.IOLoop.instance().start()
            except Exception as e:
                LOG.exception(e)

            LOG.info("service end")
        else:
            print("failed to load configuration: %s" % args.config)
    else:
        parser.print_help()