Esempio n. 1
0
 def post(cls):
     args = request.get_json()
     if not validate_args(args, delete_data_attributes):
         raise BadDataException('Invalid request')
     delete_data_res = []
     for arg in args:
         service: str = arg['service'].upper()
         app: InstallableApp = get_app_from_service(service)
         try:
             res = {
                 'service': service,
                 'deletion': False,
                 'backup_data': False,
                 'stop': False,
                 'error': ''
             }
             stop: bool = app.stop()
             backup_data: bool = app.backup_data()
             deletion: bool = delete_existing_folder(app.get_data_dir())
             res = {
                 **res, 'deletion': deletion,
                 'backup_data': backup_data,
                 'stop': stop
             }
         except Exception as e:
             res = {'error': str(e)}
         delete_data_res.append(res)
     return delete_data_res
Esempio n. 2
0
 def post(cls):
     args = request.get_json()
     if not validate_args(args, download_attributes):
         raise BadDataException('Invalid request')
     download_state: str = get_download_state().get('state')
     if download_state == DownloadState.DOWNLOADING.name:
         raise PreConditionException('Download is in progress')
     elif download_state == DownloadState.DOWNLOADED.name:
         raise PreConditionException('Download state is not cleared')
     update_download_state(DownloadState.DOWNLOADING)
     gevent.spawn(download_async,
                  current_app._get_current_object().app_context, args)
     return {"message": "Download started"}
Esempio n. 3
0
 def delete(cls):
     args = request.get_json()
     if not validate_args(args, restart_job_delete_attributes):
         raise BadDataException('Invalid request')
     restart_res = []
     for arg in args:
         service: str = arg['service'].upper()
         res = {'service': service, 'error': ''}
         try:
             cls.validate_service(service)
             delete_service_restart_job(service)
         except Exception as e:
             res = {**res, 'error': str(e)}
         restart_res.append(res)
     return restart_res
Esempio n. 4
0
 def post(cls):
     args = request.get_json()
     if not validate_args(args, control_attributes):
         raise BadDataException('Invalid request')
     control_res = []
     for arg in args:
         service: str = arg['service']
         action: str = arg['action']
         res = {'service': service, 'action': action, 'error': ''}
         try:
             _action: str = validate_and_create_action(arg['action'])
             service_cmd: str = cls.validate_and_create_service_cmd(
                 _action, arg['service'])
             execute_command_with_exception(service_cmd)
         except Exception as e:
             res = {**res, 'error': str(e)}
         control_res.append(res)
     return control_res
Esempio n. 5
0
 def post(cls):
     args = request.get_json()
     if not validate_args(args, install_attributes):
         raise BadDataException('Invalid request')
     download_state: str = get_download_state().get('state')
     if download_state == DownloadState.DOWNLOADING.name:
         raise PreConditionException('Download is in progress')
     install_res = []
     rubix_plat = args.pop(next((i for i, item in enumerate(args) if item["service"].upper() == "RUBIX_PLAT"), -1))
     processes = []
     for arg in args:
         processes.append(gevent.spawn(install_app_async, current_app._get_current_object().app_context, arg))
     gevent.joinall(processes)
     for process in processes:
         install_res.append(process.value)
     if rubix_plat:
         install_res.append(install_app(rubix_plat))
     return install_res
Esempio n. 6
0
 def post(cls, service):
     service = service.upper()
     args = request.get_json()
     if not validate_args(args, install_plugin_attributes):
         raise BadDataException('Invalid request')
     uninstall_res = []
     try:
         app: InstallableApp = get_app_from_service(service)
         for arg in args:
             plugin: str = arg["plugin"].lower()
             installation = app.uninstall_plugin(plugin)
             uninstall_res.append({
                 'plugin': plugin,
                 'uninstall': installation,
                 'error': ''
             })
     except (Exception, NotFoundException) as e:
         raise NotFoundException(str(e))
     return uninstall_res
Esempio n. 7
0
 def post(cls, service):
     service = service.upper()
     args = request.get_json()
     if not validate_args(args, download_plugin_attributes):
         raise BadDataException('Invalid request')
     download_state: str = get_plugin_download_state(service).get('state')
     if download_state == DownloadState.DOWNLOADING.name:
         raise PreConditionException('Download is in progress')
     elif download_state == DownloadState.DOWNLOADED.name:
         raise PreConditionException('Download state is not cleared')
     app: InstallableApp = get_app_from_service(service)
     _version: str = app.get_installed_version()
     if not _version:
         return {"message": f"Please install service {service} first"}
     app.set_version(_version)
     update_plugin_download_state(DownloadState.DOWNLOADING, service,
                                  _version)
     gevent.spawn(download_plugins_async,
                  current_app._get_current_object().app_context, app, args)
     return {"message": "Download started"}
Esempio n. 8
0
 def post(cls, service):
     service = service.upper()
     args = request.get_json()
     if not validate_args(args, install_plugin_attributes):
         raise BadDataException('Invalid request')
     install_res = []
     try:
         app: InstallableApp = get_app_from_service(service)
         _version: str = app.get_installed_version()
         if not _version:
             return {"message": f"Please install service {service} first"}
         for arg in args:
             plugin: str = arg["plugin"].lower()
             installation = app.install_plugin(plugin)
             install_res.append({
                 'plugin': plugin,
                 'installation': installation,
                 'error': ''
             })
     except (Exception, NotFoundException) as e:
         raise NotFoundException(str(e))
     return install_res
Esempio n. 9
0
 def post(cls):
     args = request.get_json()
     if not validate_args(args, restart_job_attributes):
         raise BadDataException('Invalid request')
     restart_res = []
     for arg in args:
         service: str = arg['service'].upper()
         timer: int = arg['timer']
         res = {'service': service, 'timer': timer, 'error': ''}
         try:
             cmd: str = cls.validate_and_create_restart_service_cmd(arg['service'].upper())
             restart_job: dict = {
                 service: {
                     "timer": timer,
                     "cmd": cmd,
                     "prev_time": str(datetime.now()),
                     "next_time": str(datetime.now() + timedelta(minutes=timer))
                 }
             }
             create_service_restart_job(restart_job)
         except Exception as e:
             res = {**res, 'error': str(e)}
         restart_res.append(res)
     return restart_res