Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1730 for trunk/sources


Ignore:
Timestamp:
05/02/09 22:43:01 (16 years ago)
Author:
gkronber
Message:

Implemented calculation of list of necessary plugins for a job in the HiveEngine #545 (Engine which can be executed in the Hive).

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngine.cs

    r1726 r1730  
    3232using System.IO;
    3333using System.Xml;
     34using System.IO.Compression;
    3435
    3536namespace HeuristicLab.Hive.Engine {
     
    7677      IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
    7778
    78       DiscoveryService dService = new DiscoveryService();
    79       PluginInfo depInfo = dService.GetDeclaringPlugin(typeof(HiveEngine));
    80       List<PluginInfo> dependentPlugins = PluginManager.Manager.GetDependentPluginsRec(depInfo);
    81       dependentPlugins.Add(depInfo);
    82 
     79      var jobObj = CreateJobObj();
     80
     81      ResponseObject<Contracts.BusinessObjects.Job> res = executionEngineFacade.AddJob(jobObj);
     82      jobId = res.Obj.Id;
     83    }
     84
     85    private HeuristicLab.Hive.Contracts.BusinessObjects.Job CreateJobObj() {
    8386      HeuristicLab.Hive.Contracts.BusinessObjects.Job jobObj = new HeuristicLab.Hive.Contracts.BusinessObjects.Job();
    84       jobObj.SerializedJob = PersistenceManager.SaveToGZip(job);
    85       jobObj.State = HeuristicLab.Hive.Contracts.BusinessObjects.State.offline;
     87
     88      MemoryStream memStream = new MemoryStream();
     89      GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
     90      XmlDocument document = PersistenceManager.CreateXmlDocument();
     91      Dictionary<Guid, IStorable> dictionary = new Dictionary<Guid, IStorable>();
     92      XmlNode rootNode = document.CreateElement("Root");
     93      document.AppendChild(rootNode);
     94      rootNode.AppendChild(PersistenceManager.Persist(job, document, dictionary));
     95      document.Save(stream);
     96      stream.Close();
     97      jobObj.SerializedJob = memStream.ToArray();
     98
     99      DiscoveryService service = new DiscoveryService();
     100      List<PluginInfo> plugins = new List<PluginInfo>();
     101
     102      foreach (IStorable storeable in dictionary.Values) {
     103        PluginInfo pluginInfo = service.GetDeclaringPlugin(storeable.GetType());
     104        if (!plugins.Contains(pluginInfo)) plugins.Add(pluginInfo);
     105      }
    86106
    87107      List<HivePluginInfo> pluginsNeeded =
    88108        new List<HivePluginInfo>();
    89 
    90       foreach (PluginInfo info in dependentPlugins) {
     109      foreach (PluginInfo uniquePlugin in plugins) {
    91110        HivePluginInfo pluginInfo =
    92111          new HivePluginInfo();
    93         pluginInfo.Name = info.Name;
    94         pluginInfo.Version = info.Version.ToString();
    95         pluginInfo.BuildDate = info.BuildDate;
     112        pluginInfo.Name = uniquePlugin.Name;
     113        pluginInfo.Version = uniquePlugin.Version.ToString();
     114        pluginInfo.BuildDate = uniquePlugin.BuildDate;
    96115        pluginsNeeded.Add(pluginInfo);
    97116      }
    98117
    99118      jobObj.PluginsNeeded = pluginsNeeded;
    100       ResponseObject<Contracts.BusinessObjects.Job> res = executionEngineFacade.AddJob(jobObj);
    101       jobId = res.Obj.Id;
     119      jobObj.State = HeuristicLab.Hive.Contracts.BusinessObjects.State.offline;
     120      return jobObj;
    102121    }
    103122
  • trunk/sources/HeuristicLab.PluginInfrastructure/PluginManager.cs

    r1715 r1730  
    263263    }
    264264
    265 
    266     /// <summary>
    267     /// Calculates a set of plugins that directly or transitively depend on the plugin given in the argument.
    268     /// </summary>
    269     /// <param name="pluginInfo">The plugin the other depend on.</param>
    270     /// <returns>a list of plugins that are directly of transitively dependent.</returns>
    271     public List<PluginInfo> GetDependentPluginsRec(PluginInfo pluginInfo) {
    272       List<PluginInfo> mergedList = new List<PluginInfo>();
    273       //Bugfix the hell out of this...
    274       //Bugfixed the hell out of this...
    275       foreach (PluginInfo info in pluginInfo.Dependencies) {
    276         if (!mergedList.Contains(info)) {
    277           mergedList.Add(info);
    278           AddDependenciesRecursive(info, mergedList);       
    279         }       
    280       }
    281       return mergedList;
    282     }
    283 
    284     private void AddDependenciesRecursive(PluginInfo info, List<PluginInfo> mergedList) {
    285       //if we've already processed this element => STOP IT!
    286       if(!mergedList.Contains(info)) {
    287         mergedList.Add(info);
    288         return;
    289       }
    290       foreach (PluginInfo depinfo in info.Dependencies)
    291         AddDependenciesRecursive(depinfo, mergedList);       
    292     }
    293 
    294265    /// <summary>
    295266    /// Unloads all plugins.
Note: See TracChangeset for help on using the changeset viewer.