def recover_basic(self):
        """
        Recover Basic entities such as Container GUID and time
        """
        if self.is_fresh():
            raise ContainerException("A fresh container cannot be recovered")
        try:
            self.container_lock.acquire()
            if self.state != ContainerState.Starting:
                raise ContainerException(f"Invalid state for recovery: {self.state}")
            self.state = ContainerState.Recovering
        finally:
            self.container_lock.release()

        self.recover_guid()
        self.recover_time()
    def initialize(self, *, config: Configuration):
        """
        Initialize container and actor
        """
        if config is None:
            raise ContainerException("handlers cannot be null")

        with self.container_lock:
            if self.state != ContainerState.Unknown:
                raise ContainerException(f"Cannot initialize container in state: {self.state}")

            self.state = ContainerState.Starting

        self.config = config
        failed = False

        try:
            self.determine_boot_mode()
            self.create_database()
            self.boot()

            if self.is_fresh():
                try:
                    from fabric_cf.actor.core.container.globals import GlobalsSingleton
                    GlobalsSingleton.get().cleanup_neo4j()
                    from fabric_cf.actor.boot.configuration_loader import ConfigurationLoader
                    loader = ConfigurationLoader()
                    loader.process(config=self.config)
                except Exception as e:
                    self.logger.error(traceback.format_exc())
                    self.logger.error(f"Failed to instantiate actors {e}")
                    self.logger.error("This container may need to be restored to a clean state")
                    raise e
                # Create State file only after successful fresh boot
                self.create_super_block()
        except Exception as e:
            self.logger.error(traceback.format_exc())
            self.logger.error(e)
            failed = True
            raise e
        finally:
            with self.container_lock:
                if failed:
                    self.state = ContainerState.Failed
                else:
                    self.state = ContainerState.Started
 def recover_guid(self):
     """
     Recover GUID from database
     """
     self.logger.debug("Recovering container GUID")
     properties = self.db.get_container_properties()
     stored_guid = properties.get(Constants.PROPERTY_CONF_CONTAINER_GUID, None)
     if stored_guid is None:
         raise ContainerException("Could not obtain saved container GUID from database")
     self.guid = ID(uid=stored_guid)
     self.logger.info(f"Recovered container guid: {self.guid}")
    def recover_time(self):
        """
        Recover time from database
        """
        self.logger.debug("Recovering container time settings")
        time_obj = self.db.get_time()
        if time_obj is None:
            raise ContainerException("Could not obtain container saved state from database")
        beginning_of_time = time_obj.get(self.PropertyBeginningOfTime, None)
        cycle_millis = time_obj.get(self.PropertyCycleMillis, None)
        manual = time_obj.get(self.PropertyManualTicks, None)

        self.create_and_start_tick(start_time=beginning_of_time, cycle_millis=cycle_millis, manual=manual)
 def get_management_object(self, *, key: ID):
     if key is None:
         raise ContainerException("key cannot be null")
     return self.management_object_manager.get_management_object(key=key)
 def get_actor_clock(self) -> ActorClock:
     if self.ticker is None:
         raise ContainerException("No tick")
     return ActorClock(beginning_of_time=self.ticker.get_beginning_of_time(),
                       cycle_millis=self.ticker.get_cycle_millis())
 def tick(self):
     if self.ticker is not None:
         self.ticker.tick()
     else:
         raise ContainerException("The container does not have a clock")