コード例 #1
0
class Coordinator(AbstractCoordinator):

    SCHEDULING_SYSTEMS = {
        NO_SCHEDULER: NoScheduler,
        PRIORITY_QUEUE: PriorityQueueScheduler,
        EXTERNAL_WEBLAB_DEUSTO: ExternalWebLabDeustoScheduler,
        ILAB_BATCH_QUEUE: ILabBatchScheduler,
    }

    AGGREGATOR = IndependentSchedulerAggregator

    def __init__(self, locator, cfg_manager, ConfirmerClass=None):
        coordination_database_manager = CoordinationDatabaseManager.CoordinationDatabaseManager(
            cfg_manager)
        self._session_maker = coordination_database_manager.session_maker
        super(Coordinator, self).__init__(self._session_maker, locator,
                                          cfg_manager, ConfirmerClass)

    def _initial_clean(self, coordination_configuration_parser):
        session = self._session_maker()
        try:
            external_servers_config = coordination_configuration_parser.parse_external_servers(
            )
            for external_server_str in external_servers_config:
                for resource_type_name in external_servers_config[
                        external_server_str]:
                    self.resources_manager.add_experiment_id(
                        session, ExperimentId.parse(external_server_str),
                        resource_type_name)

            session.commit()
        finally:
            session.close()

    def _initialize_managers(self):
        self.reservations_manager = ReservationsManager.ReservationsManager(
            self._session_maker)
        self.resources_manager = ResourcesManager.ResourcesManager(
            self._session_maker)
        self.post_reservation_data_manager = PostReservationDataManager.PostReservationDataManager(
            self._session_maker, self.time_provider)

    @typecheck(Resource, ITERATION(basestring))
    @logged()
    def mark_resource_as_broken(self, resource_instance, messages=[]):
        scheduler = self._get_scheduler_per_resource(resource_instance)

        anything_changed = False
        session = self._session_maker()
        try:
            changed = scheduler.removing_current_resource_slot(
                session, resource_instance)
            anything_changed = anything_changed or changed

            changed = self.resources_manager.mark_resource_as_broken(
                session, resource_instance)
            anything_changed = anything_changed or changed
            if anything_changed:
                session.commit()
        finally:
            session.close()

        if anything_changed:
            log.log(
                Coordinator, log.level.Warning,
                "Resource %s marked as broken: %r" %
                (resource_instance, messages))

            if self.notifications_enabled:
                self._notify_experiment_status('broken', resource_instance,
                                               messages)

    def _release_resource_instance(self, experiment_instance_id):
        session = self._session_maker()
        try:
            resource_instance = self.resources_manager.get_resource_instance_by_experiment_instance_id(
                experiment_instance_id)
            self.resources_manager.release_resource_instance(
                session, resource_instance)
            session.commit()
        finally:
            session.close()

    def _delete_reservation(self, reservation_id):
        session = self._session_maker()
        try:
            self.reservations_manager.delete(session, reservation_id)
            session.commit()
        finally:
            session.close()

    def _clean(self):
        for scheduler in self.schedulers.values():
            scheduler._clean()

        self.reservations_manager._clean()
        self.resources_manager._clean()
        self.post_reservation_data_manager._clean()
コード例 #2
0
        result = {}
        for reservation_id in reservation_ids:
            try:
                aggregator = self._get_scheduler_aggregator_per_reservation(
                    reservation_id)
                best_reservation_status = aggregator.get_reservation_status(
                    reservation_id)
            except CoordExc.CoordinatorError:
                # The reservation_id may expire since we called list_sessions,
                # so if there is a coordinator exception we just skip this
                # reservation_id
                continue
            result[reservation_id] = best_reservation_status
        return result

    @typecheck(ExperimentInstanceId, ITERATION(basestring))
    @logged()
    def mark_experiment_as_broken(self, experiment_instance_id, messages):
        resource_instance = self.resources_manager.get_resource_instance_by_experiment_instance_id(
            experiment_instance_id)
        return self.mark_resource_as_broken(resource_instance, messages)

    @typecheck(Resource)
    @logged()
    def mark_resource_as_fixed(self, resource_instance):
        anything_changed = self.resources_manager.mark_resource_as_fixed(
            resource_instance)

        if anything_changed:
            log.log(AbstractCoordinator, log.level.Warning,
                    "Resource %s marked as fixed" % resource_instance)
コード例 #3
0
class Coordinator(AbstractCoordinator):

    SCHEDULING_SYSTEMS = {
        NO_SCHEDULER: NoScheduler,
        PRIORITY_QUEUE: PriorityQueueScheduler,
        EXTERNAL_WEBLAB_DEUSTO: ExternalWebLabDeustoScheduler,
        ILAB_BATCH_QUEUE: ILabBatchScheduler,
    }

    AGGREGATOR = IndependentSchedulerAggregator

    def __init__(self, locator, cfg_manager, ConfirmerClass=None):
        connection_kwargs = {}
        db = cfg_manager.get_value(COORDINATOR_REDIS_DB, None)
        password = cfg_manager.get_value(COORDINATOR_REDIS_PASSWORD, None)
        port = cfg_manager.get_value(COORDINATOR_REDIS_PORT, None)
        host = cfg_manager.get_value(COORDINATOR_REDIS_HOST, None)
        if db is not None:
            connection_kwargs['db'] = db
        if password is not None:
            connection_kwargs['password'] = password
        if port is not None:
            connection_kwargs['port'] = port
        if host is not None:
            connection_kwargs['host'] = host
        self.pool = redis.ConnectionPool(**connection_kwargs)
        self._redis_maker = lambda: redis.Redis(connection_pool=self.pool)

        super(Coordinator, self).__init__(self._redis_maker, locator,
                                          cfg_manager, ConfirmerClass)

    def stop(self):
        super(Coordinator, self).stop()

        self.pool.disconnect()

    def _initial_clean(self, coordination_configuration_parser):
        external_servers_config = coordination_configuration_parser.parse_external_servers(
        )
        for external_server_str in external_servers_config:
            for resource_type_name in external_servers_config[
                    external_server_str]:
                self.resources_manager.add_experiment_id(
                    ExperimentId.parse(external_server_str),
                    resource_type_name)

    def _initialize_managers(self):
        self.reservations_manager = ReservationsManager.ReservationsManager(
            self._redis_maker)
        self.resources_manager = ResourcesManager.ResourcesManager(
            self._redis_maker)
        self.post_reservation_data_manager = PostReservationDataManager.PostReservationDataManager(
            self._redis_maker, self.time_provider)

    @typecheck(Resource, ITERATION(basestring))
    @logged()
    def mark_resource_as_broken(self, resource_instance, messages=[]):
        scheduler = self._get_scheduler_per_resource(resource_instance)

        anything_changed = False
        client = self._redis_maker()
        changed = scheduler.removing_current_resource_slot(
            client, resource_instance)
        anything_changed = anything_changed or changed

        changed = self.resources_manager.mark_resource_as_broken(
            resource_instance)
        anything_changed = anything_changed or changed

        if anything_changed:
            log.log(
                Coordinator, log.level.Warning,
                "Resource %s marked as broken: %r" %
                (resource_instance, messages))

            if self.notifications_enabled:
                return self._notify_experiment_status('broken',
                                                      resource_instance,
                                                      messages)
        return {}

    def _release_resource_instance(self, experiment_instance_id):
        resource_instance = self.resources_manager.get_resource_instance_by_experiment_instance_id(
            experiment_instance_id)
        self.resources_manager.release_resource_instance(resource_instance)

    def _delete_reservation(self, reservation_id):
        self.reservations_manager.delete(reservation_id)

    def _clean(self):
        for scheduler in self.schedulers.values():
            scheduler._clean()

        self.reservations_manager._clean()
        self.resources_manager._clean()
        self.post_reservation_data_manager._clean()