Beispiel #1
0
        public async Task <LauncherStatus> SubmitAsync(
            IConfiguration driverAppConfiguration,
            CancellationToken cancellationToken)
        {
            var driverClientConfiguration =
                Configurations.Merge(driverAppConfiguration,
                                     DriverBridgeConfiguration.ConfigurationModule
                                     .Set(DriverBridgeConfiguration.DriverServiceClient, GenericType <DriverServiceClient> .Class)
                                     .Set(DriverBridgeConfiguration.DriverClientService, GenericType <DriverClientService> .Class)
                                     .Build());
            var jobFolder = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));

            Log.Log(Level.Info, "Job folder {0}", jobFolder);
            Directory.CreateDirectory(jobFolder.FullName);
            AddDependencies(jobFolder, driverClientConfiguration);
            // Launch command
            if (File.Exists(DriverExe))
            {
                _driverClientConfiguration.DriverClientLaunchCommand = string.Format(
                    @"cmd.exe /c {0} {1}",
                    Path.Combine(_reefFileNames.GetGlobalFolderPath(), DriverExe),
                    _reefFileNames.GetClrDriverConfigurationPath());
            }
            else
            {
                _driverClientConfiguration.DriverClientLaunchCommand = string.Format(
                    @"dotnet {0} {1}",
                    Path.Combine(_reefFileNames.GetGlobalFolderPath(), DriverDll),
                    _reefFileNames.GetClrDriverConfigurationPath());
            }

            var driverClientConfigFile = Path.Combine(jobFolder.FullName, "driverclient.json");

            using (var outputFile = new StreamWriter(driverClientConfigFile))
            {
                outputFile.Write(JsonFormatter.Default.Format(_driverClientConfiguration));
            }
            // Submit a new job
            _clientService.Reset();
            var task = _javaClientLauncher.LaunchAsync(JavaLoggingSetting.Info,
                                                       JavaClientLauncherClass,
                                                       new[] { driverClientConfigFile, _grpcServerPort.ToString() },
                                                       cancellationToken);

            lock (_clientService)
            {
                while (!_clientService.IsDone && !cancellationToken.IsCancellationRequested)
                {
                    Monitor.Wait(_clientService, TimeSpan.FromMinutes(1));
                }
            }
            await task;

            return(_clientService.LauncherStatus);
        }
        /// <summary>
        /// Merges the Configurations in appParameters and serializes them into the right place within driverFolderPath,
        /// assuming
        /// that points to a Driver's working directory.
        /// </summary>
        /// <param name="appParameters"></param>
        /// <param name="driverFolderPath"></param>
        internal void CreateDriverConfiguration(AppParameters appParameters, string driverFolderPath)
        {
            var driverConfigurations = _driverConfigurationProviders.Select(configurationProvider => configurationProvider.GetConfiguration()).ToList();
            var driverConfiguration  = Configurations.Merge(driverConfigurations.Concat(appParameters.DriverConfigurations).ToArray());

            _configurationSerializer.ToFile(driverConfiguration,
                                            Path.Combine(driverFolderPath, _fileNames.GetClrDriverConfigurationPath()));
        }
Beispiel #3
0
        /// <summary>
        /// Merges the Configurations in jobSubmission and serializes them into the right place within driverFolderPath,
        /// assuming
        /// that points to a Driver's working directory.
        /// </summary>
        /// <param name="jobSubmission"></param>
        /// <param name="driverFolderPath"></param>
        internal void CreateDriverConfiguration(IJobSubmission jobSubmission, string driverFolderPath)
        {
            var driverConfiguration = Configurations.Merge(jobSubmission.DriverConfigurations.ToArray());

            _configurationSerializer.ToFile(driverConfiguration,
                                            Path.Combine(driverFolderPath, _fileNames.GetClrDriverConfigurationPath()));

            // TODO: Remove once we cleaned up the Evaluator to not expect this [REEF-216]
            _configurationSerializer.ToFile(driverConfiguration,
                                            Path.Combine(driverFolderPath, _fileNames.GetGlobalFolderPath(), Constants.ClrBridgeRuntimeConfiguration));
        }
        /// <summary>
        /// Merges the Configurations in appParameters and serializes them into the right place within driverFolderPath,
        /// assuming
        /// that points to a Driver's working directory.
        /// </summary>
        /// <param name="appParameters"></param>
        /// <param name="driverFolderPath"></param>
        internal void CreateDriverConfiguration(AppParameters appParameters, string driverFolderPath)
        {
            var driverConfiguration = Configurations.Merge(appParameters.DriverConfigurations.ToArray());

            _configurationSerializer.ToFile(driverConfiguration,
                                            Path.Combine(driverFolderPath, _fileNames.GetClrDriverConfigurationPath()));

            // TODO: Remove once we cleaned up the Evaluator to not expect this [REEF-217]
            _configurationSerializer.ToFile(driverConfiguration,
                                            Path.Combine(driverFolderPath, _fileNames.GetGlobalFolderPath(), _fileNames.GetClrBridgeConfigurationName()));
        }
        /// <summary>
        /// Finds the path to the bridge configuration
        /// </summary>
        /// <remarks>
        /// It tries both the new and the legacy locations and gives preference to the new locations. Warnings will be logged
        /// when both are present as well as when the configuration is only present in the legacy location.
        /// </remarks>
        /// <exception cref="FileNotFoundException">When neither the legacy nor the new file exists.</exception>
        /// <returns>The path to the bridge configuration</returns>
        internal string GetBridgeConfigurationPath()
        {
            var newBridgeConfigurationPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(),
                                                                           _fileNames.GetClrDriverConfigurationPath()));
            var legacyBridgeConfigurationPath =
                Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "reef", "global",
                                              "clrBridge.config"));

            var newExists = File.Exists(newBridgeConfigurationPath);
            var oldExists = File.Exists(legacyBridgeConfigurationPath);

            if (newExists && oldExists)
            {
                var msg = "Found configurations in both the legacy location (" + legacyBridgeConfigurationPath +
                          ") and the new location (" + newBridgeConfigurationPath +
                          "). Loading only the one found in the new location.";
                Logger.Log(Level.Warning, msg);
            }
            if (newExists)
            {
                return(newBridgeConfigurationPath);
            }
            if (oldExists)
            {
                var msg = "Only found configuration in the legacy location (" + legacyBridgeConfigurationPath +
                          ") and not the new location (" + newBridgeConfigurationPath +
                          "). Loading only the one found in the legacy location.";
                Logger.Log(Level.Warning, msg);
                return(legacyBridgeConfigurationPath);
            }

            // If we reached this, we weren't able to find the configuration file.
            var message = "Unable to find brigde configuration. Paths checked: ['" +
                          newBridgeConfigurationPath + "', '" +
                          legacyBridgeConfigurationPath + "']";

            Logger.Log(Level.Error, message);
            var exception = new FileNotFoundException(message);

            Exceptions.Throw(exception, Logger);
            throw exception;
        }