Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/14/11 18:23:37 (13 years ago)
Author:
cneumuel
Message:

#1233

  • removed GetConfigurationFile from service -> configuration is now submitted as a plugin with one file (the configuration file)
  • resource ids are now checked before uploading a hive experiment, only valid resource names are accepted
  • added SharpZipLib License to ConsoleClient project, so dependecies are satisfied
Location:
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveExperimentClient.cs

    r5404 r5458  
    3838  using HeuristicLab.PluginInfrastructure;
    3939  using System.IO;
     40  using System.Configuration;
     41  using System.Reflection;
     42  using HeuristicLab.PluginInfrastructure.Manager;
    4043
    4144  /// <summary>
     
    7679    }
    7780
    78     private string resourceIds;
    79     public string ResourceIds {
    80       get { return resourceIds; }
     81    private string resourceNames;
     82    public string ResourceNames {
     83      get { return resourceNames; }
    8184      set {
    82         if (resourceIds != value) {
    83           resourceIds = value;
    84           OnResourceIdsChanged();
     85        if (resourceNames != value) {
     86          resourceNames = value;
     87          OnResourceNamesChanged();
    8588        }
    8689      }
     
    117120    public IEnumerable<Plugin> OnlinePlugins {
    118121      get { return onlinePlugins; }
    119       set { onlinePlugins = value; } 
     122      set { onlinePlugins = value; }
    120123    }
    121124
     
    131134      set { useLocalPlugins = value; }
    132135    }
    133    
    134     public HiveExperimentClient() : base(itemName, itemDescription) {
    135       // TODO //this.ResourceIds = HeuristicLab.Hive.Experiment.Properties.Settings.Default.ResourceIds;
    136       this.ResourceIds = "HEAL";
     136
     137    public HiveExperimentClient()
     138      : base(itemName, itemDescription) {
     139      this.ResourceNames = "HEAL";
    137140      this.log = new Log();
    138141      InitTimer();
    139142    }
    140     public HiveExperimentClient(DT.HiveExperiment hiveExperimentDto) : this() {
     143    public HiveExperimentClient(DT.HiveExperiment hiveExperimentDto)
     144      : this() {
    141145      UpdateFromDto(hiveExperimentDto);
    142146    }
    143147    protected HiveExperimentClient(HiveExperimentClient original, Cloner cloner)
    144148      : base(original, cloner) {
    145       this.ResourceIds = original.resourceIds;
     149      this.ResourceNames = original.resourceNames;
    146150      this.ExecutionState = original.executionState;
    147151      this.ExecutionTime = original.executionTime;
     
    158162      this.Name = hiveExperimentDto.Name;
    159163      this.Description = hiveExperimentDto.Description;
    160       // TODO: this.ResourceIds = hiveExperimentDto.ResourceIds;
     164      this.ResourceNames = hiveExperimentDto.ResourceNames;
    161165      this.rootJobId = hiveExperimentDto.RootJobId;
    162166    }
     
    167171        Name = this.Name,
    168172        Description = this.Description,
    169         //ResourceIds = this.ResourceIds,
     173        ResourceNames = this.ResourceNames,
    170174        RootJobId = this.rootJobId
    171175      };
     
    227231
    228232    public void Prepare() {
    229       // do nothing
     233      this.timer.Stop();
     234      this.ExecutionState = Core.ExecutionState.Prepared;
     235      this.ExecutionTime = TimeSpan.Zero;
    230236    }
    231237
    232238    public void Start() {
    233239      OnStarted();
    234       ExecutionTime = new TimeSpan();
     240      ExecutionTime = TimeSpan.Zero;
    235241      lastUpdateTime = DateTime.Now;
    236242      this.ExecutionState = Core.ExecutionState.Started;
     
    246252        IsProgressing = true;
    247253        using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
    248           IEnumerable<string> groups = ToResourceIdList(this.ResourceIds);
     254          IEnumerable<string> resourceNames = ToResourceNameList(this.ResourceNames);
     255          var resourceIds = new List<Guid>();
     256          foreach (var resourceName in resourceNames) {
     257            Guid resourceId = service.Obj.GetResourceId(resourceName);
     258            if (resourceId == Guid.Empty) {
     259              throw new ResourceNotFoundException(string.Format("Could not find the resource '{0}'", resourceName));
     260            }
     261            resourceIds.Add(resourceId);
     262          }
     263
    249264          this.HiveJob.SetIndexInParentOptimizerList(null);
    250265
     
    255270          this.OnlinePlugins = service.Obj.GetPlugins();
    256271          this.AlreadyUploadedPlugins = new List<Plugin>();
     272          Plugin configFilePlugin = UploadConfigurationFile(service.Obj);
     273          this.alreadyUploadedPlugins.Add(configFilePlugin);
    257274
    258275          this.progress.Status = "Uploading jobs...";
    259           UploadJobWithChildren(service.Obj, this.HiveJob, null, groups, ref jobCount, totalJobCount);
     276          UploadJobWithChildren(service.Obj, this.HiveJob, null, resourceIds, ref jobCount, totalJobCount, configFilePlugin.Id);
    260277          this.rootJobId = this.HiveJob.Job.Id;
    261278          LogMessage("Finished sending jobs to hive");
     
    272289      catch (Exception e) {
    273290        OnExceptionOccured(e);
     291        this.Prepare();
    274292      }
    275293      finally {
    276294        IsProgressing = false;
    277295      }
     296    }
     297
     298    /// <summary>
     299    /// Uploads the local configuration file as plugin
     300    /// </summary>
     301    private static Plugin UploadConfigurationFile(IHiveService service) {
     302      string exeFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HeuristicLab 3.3.exe");
     303      string configFileName = ConfigurationManager.OpenExeConfiguration(exeFilePath).FilePath;
     304
     305      Plugin configPlugin = new Plugin() {
     306        Name = "Configuration",
     307        IsLocal = true,
     308        Version = new Version()
     309      };
     310      PluginData configFile = new PluginData() {
     311        FileName = configFileName,
     312        Data = File.ReadAllBytes(configFileName)
     313      };
     314      configPlugin.Id = service.AddPlugin(configPlugin, new List<PluginData> { configFile });
     315      return configPlugin;
    278316    }
    279317
     
    286324    /// <param name="parentHiveJob">shall be null if its the root job</param>
    287325    /// <param name="groups"></param>
    288     private void UploadJobWithChildren(IHiveService service, HiveJob hiveJob, HiveJob parentHiveJob, IEnumerable<string> groups, ref int jobCount, int totalJobCount) {
     326    private void UploadJobWithChildren(IHiveService service, HiveJob hiveJob, HiveJob parentHiveJob, IEnumerable<Guid> groups, ref int jobCount, int totalJobCount, Guid configPluginId) {
    289327      jobCount++;
    290328      this.progress.Status = string.Format("Serializing job {0} of {1}", jobCount, totalJobCount);
     
    301339
    302340      hiveJob.Job.PluginsNeededIds = GetPluginDependencies(service, onlinePlugins, alreadyUploadedPlugins, plugins, useLocalPlugins);
     341      hiveJob.Job.PluginsNeededIds.Add(configPluginId);
    303342
    304343      this.progress.Status = string.Format("Uploading job {0} of {1} ({2} kb)", jobCount, totalJobCount, jobData.Data.Count() / 1024);
     
    306345
    307346      if (parentHiveJob != null) {
    308         //response = service.AddChildJob(parentHiveJob.Job.Id, serializedJob);
    309347        hiveJob.Job.Id = service.AddChildJob(parentHiveJob.Job.Id, hiveJob.Job, jobData);
    310348      } else {
    311         // response = service.AddJobWithGroupStrings(serializedJob, groups);
    312         hiveJob.Job.Id = service.AddJob(hiveJob.Job, jobData, null); // todo: use ResourceIds
     349        hiveJob.Job.Id = service.AddJob(hiveJob.Job, jobData, groups);
    313350      }
    314351
     
    316353
    317354      foreach (HiveJob child in hiveJob.ChildHiveJobs) {
    318         UploadJobWithChildren(service, child, hiveJob, groups, ref jobCount, totalJobCount);
    319       }
    320     }
    321    
     355        UploadJobWithChildren(service, child, hiveJob, groups, ref jobCount, totalJobCount, configPluginId);
     356      }
     357    }
     358
    322359    /// <summary>
    323360    /// Converts a string which can contain Ids separated by ';' to a enumerable
    324361    /// </summary>
    325     private IEnumerable<string> ToResourceIdList(string resourceGroups) {
     362    private IEnumerable<string> ToResourceNameList(string resourceGroups) {
    326363      if (!string.IsNullOrEmpty(resourceGroups)) {
    327         return resourceIds.Split(';');
     364        return resourceNames.Split(';');
    328365      } else {
    329366        return new List<string>();
     
    395432    }
    396433
    397     public event EventHandler ResourceIdsChanged;
    398     protected virtual void OnResourceIdsChanged() {
    399       EventHandler handler = ResourceIdsChanged;
     434    public event EventHandler ResourceNamesChanged;
     435    protected virtual void OnResourceNamesChanged() {
     436      EventHandler handler = ResourceNamesChanged;
    400437      if (handler != null) handler(this, EventArgs.Empty);
    401438    }
     
    649686      }
    650687    }
    651     #endregion 
     688    #endregion
    652689
    653690    #region Plugin Management
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/HeuristicLab.Clients.Hive-3.4.csproj

    r5457 r5458  
    102102    </Reference>
    103103    <Reference Include="System" />
     104    <Reference Include="System.Configuration" />
    104105    <Reference Include="System.Core" />
    105106    <Reference Include="System.Drawing" />
     
    118119    <Compile Include="Exceptions\OptimizerNotFoundException.cs" />
    119120    <Compile Include="ExperimentManager\PluginClient.cs" />
     121    <Compile Include="Exceptions\ResourceNotFoundException.cs" />
    120122    <Compile Include="IServiceLocator.cs" />
    121123    <Compile Include="Jobs\OptimizerJob.cs" />
Note: See TracChangeset for help on using the changeset viewer.