Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5325


Ignore:
Timestamp:
01/18/11 15:51:14 (14 years ago)
Author:
ascheibe
Message:

#1233

  • allow different versions of the same plugin in PluginCache
  • fixes for the SlaveTests
Location:
branches/HeuristicLab.Hive-3.4/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs

    r5314 r5325  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.ServiceModel;
    2625using HeuristicLab.Clients.Common;
    2726using HeuristicLab.Services.Hive.Common;
     
    3332  [TestClass]
    3433  public class SlaveTest {
    35 
    36     private static ServiceHost slaveComm;
    3734    private static SlaveCommListener listener;
    3835
     
    4239      PluginLoader.pluginAssemblies.Any();
    4340      ServiceLocator.Instance = new MockServiceLocator();
    44       slaveComm = new ServiceHost(typeof(SlaveCommunicationService));
    45       slaveComm.Open();
    46       listener = new SlaveCommListener();
    47       listener.Open();
     41      /* listener = new SlaveCommListener();
     42       listener.Open();*/
    4843    }
    4944
    5045    [ClassCleanup]
    5146    public static void MyClassCleanup() {
    52       listener.Close();
    53       slaveComm.Close();
     47      //listener.Close();
    5448    }
    5549
     
    9791        Assert.AreEqual<int>(1, ms.ResultJobs.Count);
    9892        Assert.AreEqual<Guid>(testJob.Id, ms.ResultJobs[0].Id);
     93        core.Shutdown();
    9994      }
    10095    }
     
    131126        HeuristicLab.Clients.Hive.Slave.Core core = new Slave.Core();
    132127        core.Start();
    133 
    134128      }
    135129    }
     
    195189        core.Start();
    196190        Assert.AreEqual<int>(2, ms.ResultJobs.Count);
    197 
     191        core.Shutdown();
    198192      }
    199193    }
    200 
    201 
    202 
    203 
    204 
    205 
    206 
    207 
    208 
    209194  }
    210195}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs

    r5314 r5325  
    2727using System.Runtime.CompilerServices;
    2828using System.Threading;
    29 using HeuristicLab.Clients.Hive.Slave;
    30 using HeuristicLab.PluginInfrastructure;
    31 using HeuristicLab.PluginInfrastructure.Manager;
    3229using HeuristicLab.Services.Hive.Common.DataTransfer;
    3330
     
    4239    public string PluginTempBaseDir { get; set; }
    4340
    44     private List<PluginDescription> cachedPlugins = new List<PluginDescription>();
    45 
    46     private PluginManager pm;
     41    private List<Guid> cachedPluginsGuids = new List<Guid>();
    4742
    4843    public static PluginCache Instance {
     
    6459      PluginTempBaseDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PluginTemp");
    6560
    66       this.pm = new PluginManager(PluginCacheDir);
    6761      DoUpdateRun();
     62    }
     63
     64    private string getFilenameFromPath(string path) {
     65      string[] dirParts = path.Split(Path.DirectorySeparatorChar);
     66      if (dirParts.Length > 0) {
     67        string fileGuid = dirParts[dirParts.Length - 1];
     68        return fileGuid;
     69      } else
     70        return "";
    6871    }
    6972
     
    7275        Directory.CreateDirectory(PluginCacheDir);
    7376      }
    74       pm.DiscoverAndCheckPlugins();
    75       cachedPlugins = new List<PluginDescription>(pm.Plugins);
     77
     78      foreach (string dir in Directory.EnumerateDirectories(PluginCacheDir)) {
     79        cachedPluginsGuids.Add(Guid.Parse(getFilenameFromPath(dir)));
     80      }
    7681    }
    7782
     
    8489          Directory.Delete(targetDir, true);
    8590        }
    86 
    87         DirectoryInfo di = Directory.CreateDirectory(targetDir);
     91        Directory.CreateDirectory(targetDir);
     92
    8893
    8994        foreach (Plugin requestedPlugin in requests) {
    90           PluginDescription pd = cachedPlugins.Where(cp =>
    91             cp.Name == requestedPlugin.Name &&
    92             cp.Version.Major == requestedPlugin.Version.Major &&
    93             cp.Version.Minor == requestedPlugin.Version.Minor).SingleOrDefault();
    94           if (pd != null) {
    95             foreach (IPluginFile ipf in pd.Files) {
    96               File.Copy(ipf.Name, Path.Combine(targetDir, Path.GetFileName(ipf.Name)));
     95          string curPath = Path.Combine(PluginCacheDir, requestedPlugin.Id.ToString());
     96          if (Directory.Exists(curPath)) {
     97            foreach (string file in Directory.GetFiles(curPath)) {
     98              string fn = getFilenameFromPath(file);
     99              File.Copy(file, Path.Combine(targetDir, fn));
    97100            }
    98101          }
     
    142145
    143146        foreach (Plugin info in requiredPlugins) {
    144           //we MAY run in problems here - if there is a plugin twice in requests, there may be added two different versions of the plugin
    145           foreach (PluginDescription cachedPlugin in cachedPlugins) {
    146             if (info.Name == cachedPlugin.Name && info.Version == cachedPlugin.Version) {
    147               localPlugins.Add(new Plugin() { Id = new Guid(), Name = info.Name, Version = info.Version });
     147          foreach (Guid cachedPlugin in cachedPluginsGuids) {
     148            if (info.Id == cachedPlugin) {
     149              localPlugins.Add(new Plugin() { Id = cachedPlugin, Name = info.Name, Version = info.Version });
    148150              found = true;
    149151
     
    165167
    166168        foreach (PluginData updateablePlugin in updateablePlugins) {
    167           Plugin pluginDescription = pluginDescriptions.Where(desc => desc.Id == updateablePlugin.PluginId).SingleOrDefault();
    168           if (pluginDescription != null) {
    169 
    170             PluginDescription pd = cachedPlugins.Where(cachedPlugin =>
    171                 cachedPlugin.Name == pluginDescription.Name &&
    172                 cachedPlugin.Version.Major == pluginDescription.Version.Major &&
    173                 cachedPlugin.Version.Minor == pluginDescription.Version.Major).SingleOrDefault();
    174 
    175             if (pd != null) {
    176               foreach (IPluginFile ipf in pd.Files) {
    177                 SlaveClientCom.Instance.ClientCom.LogMessage(string.Format("deleting {0}", Path.GetFileName(ipf.Name)));
    178                 File.Delete(ipf.Name);
    179               }
    180             }
    181             File.WriteAllBytes(Path.Combine(PluginCacheDir, Path.GetFileName(updateablePlugin.FileName)), updateablePlugin.Data);
    182           }
    183           //TODO: error handling on pluginDescription, should be found
     169          string pluginDir = Path.Combine(PluginCacheDir, updateablePlugin.PluginId.ToString());
     170
     171          //put all files belonging to a plugin in the same directory
     172          if (!Directory.Exists(pluginDir)) {
     173            DirectoryInfo di = Directory.CreateDirectory(pluginDir);
     174          }
     175          File.WriteAllBytes(Path.Combine(pluginDir, Path.GetFileName(updateablePlugin.FileName)), updateablePlugin.Data);
    184176        }
    185177
     
    212204      }
    213205    }
    214 
    215 
    216206  }
    217207}
Note: See TracChangeset for help on using the changeset viewer.