Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/18/09 17:43:23 (15 years ago)
Author:
gkronber
Message:

Fixed a few bugs in bridge from grid to hive. #642 (Hive backend for CEDMA)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Grid.HiveBridge/3.2/HiveGridServerWrapper.cs

    r2058 r2064  
    6565      ResponseObject<JobResult> response = executionEngineFacade.GetLastResult(guid, false);
    6666      if (response.Success && response.Obj != null) {
    67         Job restoredJob = (Job)PersistenceManager.RestoreFromGZip(response.Obj.Result);
    68         return restoredJob.SerializedJob;
     67        HeuristicLab.Hive.Engine.Job restoredJob = (HeuristicLab.Hive.Engine.Job)PersistenceManager.RestoreFromGZip(response.Obj.Result);
     68        // Serialize the engine
     69        MemoryStream memStream = new MemoryStream();
     70        GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
     71        XmlDocument document = PersistenceManager.CreateXmlDocument();
     72        Dictionary<Guid, IStorable> dictionary = new Dictionary<Guid, IStorable>();
     73        XmlNode rootNode = document.CreateElement("Root");
     74        document.AppendChild(rootNode);
     75        rootNode.AppendChild(PersistenceManager.Persist(restoredJob.Engine, document, dictionary));
     76        document.Save(stream);
     77        stream.Close();
     78        return memStream.ToArray();
    6979      } else return null;
    7080    }
     
    7383      HeuristicLab.Hive.Contracts.BusinessObjects.Job jobObj = new HeuristicLab.Hive.Contracts.BusinessObjects.Job();
    7484
     85      List<HivePluginInfo> requiredPlugins = new List<HivePluginInfo>();
     86      IEngine engine = RestoreEngine(serializedEngine, requiredPlugins);
     87
     88      HeuristicLab.Hive.Engine.Job job = new HeuristicLab.Hive.Engine.Job();
     89      job.Engine.OperatorGraph.AddOperator(engine.OperatorGraph.InitialOperator);
     90      job.Engine.OperatorGraph.InitialOperator = engine.OperatorGraph.InitialOperator;
     91
     92      // Serialize the job
     93      MemoryStream memStream = new MemoryStream();
     94      GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
     95      XmlDocument document = PersistenceManager.CreateXmlDocument();
     96      Dictionary<Guid, IStorable> dictionary = new Dictionary<Guid, IStorable>();
     97      XmlNode rootNode = document.CreateElement("Root");
     98      document.AppendChild(rootNode);
     99      rootNode.AppendChild(PersistenceManager.Persist(job, document, dictionary));
     100      document.Save(stream);
     101      stream.Close();
     102
     103      jobObj.SerializedJob = memStream.ToArray();
     104      jobObj.CoresNeeded = 1;
     105      jobObj.PluginsNeeded = requiredPlugins;
     106      jobObj.State = HeuristicLab.Hive.Contracts.BusinessObjects.State.offline;
     107      return jobObj;
     108    }
     109
     110    private IEngine RestoreEngine(byte[] serializedEngine, List<HivePluginInfo> requiredPlugins) {
    75111      // unzip and restore to determine the list of required plugins (NB: inefficient!)
    76       MemoryStream memStream = new MemoryStream();
     112      MemoryStream memStream = new MemoryStream(serializedEngine);
    77113      GZipStream stream = new GZipStream(memStream, CompressionMode.Decompress, true);
    78114      XmlDocument document = new XmlDocument();
     
    80116
    81117      Dictionary<Guid, IStorable> dictionary = new Dictionary<Guid, IStorable>();
    82       XmlNode rootNode = document.ChildNodes[0].ChildNodes[0];
    83       PersistenceManager.Restore(rootNode, dictionary);
     118      XmlNode rootNode = document.ChildNodes[1].ChildNodes[0];
     119      IEngine engine = (IEngine)PersistenceManager.Restore(rootNode, dictionary);
    84120      stream.Close();
    85121
     
    97133      }
    98134
    99       List<HivePluginInfo> pluginsNeeded =
    100         new List<HivePluginInfo>();
    101135      foreach (PluginInfo uniquePlugin in plugins) {
    102136        HivePluginInfo pluginInfo =
     
    105139        pluginInfo.Version = uniquePlugin.Version.ToString();
    106140        pluginInfo.BuildDate = uniquePlugin.BuildDate;
    107         pluginsNeeded.Add(pluginInfo);
     141        requiredPlugins.Add(pluginInfo);
    108142      }
    109 
    110       jobObj.SerializedJob = serializedEngine;
    111       jobObj.CoresNeeded = 1;
    112       jobObj.PluginsNeeded = pluginsNeeded;
    113       jobObj.State = HeuristicLab.Hive.Contracts.BusinessObjects.State.offline;
    114       return jobObj;
     143      return engine;
    115144    }
    116145  }
Note: See TracChangeset for help on using the changeset viewer.