def __init__(self, name, status, current_job, address, mountpoints): """ Constructor for the Worker class, saves class attributes and commits to the database :param name: name of the worker :param status: status of the Worker :param current_job_id: id of the active job :param address: the base url :param storages_aliases: List of mounted storages """ self.name = name self.status = status self.address = address if mountpoints is not None: mountpoints = list(set(mountpoints)) for mountpoint in mountpoints: storage = Storage.get_storage_by_mountpoint(mountpoint) if storage is not None: meta.get_session(storage).close() self.storages.append(storage) else: pass if current_job is not None: self.current_job_id = current_job.id else: self.current_job_id = None session = meta.get_session(self) session.add(self) session.commit()
def delete(self, ): """ Permanently deletes the worker. Can not be recovered """ session = meta.get_session(self) session.delete(self) session.commit()
def set_value(self, key, value): session = meta.get_session(self) if hasattr(self, key): setattr(self, key, value) else: raise AttributeError('The attribute ' + key + 'doesn\'t exist.') session.commit()
def get_storages(self, ): """ Basic getter for the storage list :returns self.storages() """ session = meta.get_session(self) return self.storages
def remove(self): """ Deletes the job. WARNING: THIS IS NOT REVERSIBLE. Deleted Jobs can not be recovered. """ session = meta.get_session(self) session.delete(self) session.commit()
def set_status(self, status): """ Sets the status :param status: status to set :type status: WorkerStatus """ session = meta.get_session(self) self.status = status session.commit()
def set_end_time(self, end_time): """ Sets the time at which the job was finshed :param end_time: the time :type end_time: datetime """ session = meta.get_session(self) self.ended_at = end_time session.commit()
def set_enqueue_time(self, enqueued_at): """ Sets the time at which the job was accepted by the master :param enqueued_at: the time :type enqueued_at: datetime """ session = meta.get_session(self) self.enqueued_at = enqueued_at session.commit()
def set_priority(self, priority): """" Sets the priority :param priority: the new priority :type priority: int """ session = meta.get_session(self) self.priority = priority session.commit()
def __init__(self, name, token): try: User.get_user_by_username(name) except UserNotFoundException: super().__init__(name, token) User.get_user_by_username(name).set_user_type(UserRole.Administrator) session = meta.get_session(self) session.commit()
def set_error(self, error): """ Adds an error :param error: the error :type error: String (???) """ session = meta.get_session(self) self.error = error session.commit()
def set_start_time(self, start_time): """ Sets the time at which the job was started :param start_time: the time to set :type start_time: datetime """ session = meta.get_session(self) self.started_at = start_time session.commit()
def extend(self): session = meta.get_session(self) if self.max_extensions <= self.times_extended: raise OverflowError( 'This workspace\' lifetime can\'t be extended anymore') else: self.times_extended = self.times_extended + 1 self.expiration_date = self.expiration_date + timedelta( days=self.max_extension_period) session.commit()
def set_active_job(self, job): """ Sets the active job for this worker and updates its status to active :param job the job to use :type job: Job """ session = meta.get_session(self) session.add(self) self.current_job_id = job.id if job else None session.commit()
def set_user_type(self, user_type): """ Sets UserRole to type :param type: UserRole """ session = meta.get_session(self) self.user_type = user_type session.commit() session.flush() return
def __init__(self, alias, mountpoint, accept_jobs, has_home_dir, is_archive, max_extensions, max_extension_period, description): self.alias = alias self.mountpoint = mountpoint self.accept_jobs = accept_jobs self.has_home_dir = has_home_dir self.is_archive = is_archive self.max_extensions = max_extensions self.max_extension_period = max_extension_period self.description = description session = meta.get_session(self) session.commit()
def set_value(self, key, value): session = meta.get_session(self) if hasattr(self, key): if key in ['has_home_dir', 'accept_jobs', 'is_archive']: if value in ['True', 'true']: value = True elif value in ['False', 'false']: value = False else: raise ValueError('You cant set ' + key + ' to ' + value) setattr(self, key, value) else: raise AttributeError('The attribute ' + key + 'doesn\'t exist.') session.commit()
def __init__(self, source_alias: str, target_alias: str, source_path: str, notification, user=None, target_path: str=None, copy_options=None): self.source_alias = source_alias self.target_alias = target_alias self.source_path = source_path self.target_path = target_path #self.status = JobStatus.QUEUED self.user = user.get_username() self.copy_options = copy_options if notification is not None: self.notification_abort = notification[0] self.notification_begin = notification[1] self.notification_end = notification[2] session = meta.get_session(self) session.add(self) session.commit()
def __init__(self, username, label, storage, max_extension_period, max_extensions, counter): self.username = username self.label = label self.counter = counter self.full_name = ConfigHandler().assemble_workspace_full_name( username, label, counter) self.storage = storage self.time_created = datetime.now() self.max_extension_period = max_extension_period self.max_extensions = max_extensions self.times_extended = 0 self.expiration_date = datetime.now() + timedelta( days=max_extension_period) workspace_options = ConfigHandler().get_workspace_options() for option in workspace_options: for key in option: setattr(self, key, option[key]) session = meta.get_session(self) session.add(self) session.commit()
def set_full_path(self, path): session = meta.get_session(self) self.full_path = path session.commit()
def set_token(self, token): session = meta.get_session(self) self.token = token session.commit() session.flush() return
def set_workpool_size(self, size): session = meta.get_session(self) self.workpool_size = size session.commit()
def set_compression_rate(self, rate): session = meta.get_session(self) self.compression_rate = rate session.commit()
def set_n_of_dirs(self, n): session = meta.get_session(self) self.n_of_dirs = n session.commit()
def remove(self): session = meta.get_session(self) session.delete(self) session.commit()
def set_accept_jobs(self, v): session = meta.get_session(self) self.accept_jobs = v session.commit()
def set_status(self, status): session = meta.get_session(self) self.status = status session.commit()
def set_storage(self, storage): session = meta.get_session(self) self.storage = storage session.commit()