Esempio n. 1
0
 def test_default_log_file_location(self):
     config = YamlConfig({}, Path("/tmp/test/.dstack/config.yaml"))
     configure(config)
     log.enable()
     if isinstance(log.get_logger(), log.FileLogger):
         self.assertEqual(
             f"/tmp/test/.dstack/logs/{datetime.now().strftime('%Y-%m-%d.log')}",
             log.get_logger().filename)
     else:
         self.fail("logger must be a FileLogger")
Esempio n. 2
0
 def setUp(self):
     config = InPlaceConfig()
     config.add_or_replace_profile(
         Profile("default",
                 "user",
                 "my_token",
                 "https://api.dstack.ai",
                 verify=True))
     configure(config)
     self.protocol = TestProtocol()
     setup_protocol(TestProtocolFactory(self.protocol))
Esempio n. 3
0
 def test_default_log_file_location(self):
     dstack_path = Path(tempfile.gettempdir()) / ".dstack"
     config_path = dstack_path / "config.yaml"
     config = YamlConfig({}, config_path.resolve())
     configure(config)
     log.enable()
     if isinstance(log.get_logger(), log.FileLogger):
         expected_path = dstack_path / "logs" / datetime.now().strftime(
             '%Y-%m-%d.log')
         self.assertEqual(str(expected_path.resolve()),
                          log.get_logger().filename)
     else:
         self.fail("logger must be a FileLogger")
Esempio n. 4
0
    def __init__(self, config: Config = None, base_path: Optional[Path] = None,
                 java_factory: Optional[_JavaFactory] = None, verify: bool = True):

        def my_java_factory(java_home: Path) -> Java:
            return Java(java_home)

        config_path = _get_config_path()

        self.base_path = base_path or config_path.parent
        self._conf = config or from_yaml_file(path=config_path)
        self._java_factory = java_factory if java_factory else my_java_factory
        self._verify = verify

        if not self._conf.get_profile("dstack"):
            profile = Profile(self._PROFILE, "dstack", None, API_SERVER, verify=verify)
            self._conf.add_or_replace_profile(profile)

        configure(self._conf)
Esempio n. 5
0
    def setUp(self):
        super().setUp()
        if os.getenv("JAVA_HOME"):
            del os.environ["JAVA_HOME"]
        self.temp = Path(tempfile.gettempdir()) / f"dstack-f{uuid4()}"
        self.temp.mkdir()
        self.installer_path = self.temp / ".dstack-installer"
        self.config = InPlaceConfig()
        self.config.add_or_replace_profile(
            Profile(Installer._PROFILE,
                    Installer._USER,
                    "fake_token",
                    API_SERVER,
                    verify=True))
        configure(self.config)

        self.installer = Installer(config=self.config,
                                   installer_path=self.installer_path,
                                   java_factory=self._java_factory)
        self.java_version = "1.8.0_221"
Esempio n. 6
0
executions_home = sys.argv[1]

user = sys.argv[2]
token = sys.argv[3]
server = sys.argv[4]
if len(sys.argv) > 5:
    function_type = sys.argv[5]
    function_data = sys.argv[6]
else:
    function_type = None
    function_data = None

in_place_config = InPlaceConfig()
in_place_config.add_or_replace_profile(
    Profile("default", user, token, server, verify=True))
dstack_config.configure(in_place_config)

encoder = AutoHandler()

cached_executions = ExpiringDict(max_len=30, max_age_seconds=60 * 5)


def find_cached_execution(previous_execution_id):
    return cached_executions.get(previous_execution_id)


def cache_execution(execution):
    previous_execution_id = execution.get("previous_execution_id")
    if previous_execution_id is not None:
        cached_executions.pop(previous_execution_id)
    cached_executions[execution["id"]] = execution