Changeset 9166 for branches/OaaS/HeuristicLab.Services.Optimization.Controller/HL/HiveScenarioManager.cs
- Timestamp:
- 01/15/13 15:50:53 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HL/HiveScenarioManager.cs
r9062 r9166 20 20 using HeuristicLab.Services.Optimization.ControllerService.Azure; 21 21 using System.Data; 22 using HeuristicLab.Services.Optimization.ControllerService.General; 22 23 23 24 namespace HeuristicLab.Services.Optimization.ControllerService { … … 43 44 private static object lockable; 44 45 private Dictionary<string, IScenarioMapper> mappers = new Dictionary<string, IScenarioMapper>(); 45 private IDataAccessLayer dal = new AzureDataAccessLayer();46 private IDataAccessLayer dal = DataAccessLayerProvider.GetLayer(); 46 47 47 48 public static readonly string SCENARIO_TABLE = "Scenario"; … … 51 52 } 52 53 53 public void DispatchScenario(Model.User user, Model.OptimizationScenario scenario ) {54 Experiment experiment = new Experiment();55 var problem = new TravelingSalesmanProblem();56 var algo = new GeneticAlgorithm();57 algo.Problem = problem;54 public void DispatchScenario(Model.User user, Model.OptimizationScenario scenario, JobExecutionDetails details) { 55 // Experiment experiment = new Experiment(); 56 // var problem = new TravelingSalesmanProblem(); 57 // var algo = new GeneticAlgorithm(); 58 // algo.Problem = problem; 58 59 59 60 IScenarioMapper mapper = GetMapper(scenario); 60 mapper.MapScenario(scenario, algo); 61 62 //experiment.Optimizers.Add(algo); 63 SendExperimentToHive(user, algo); 61 IAlgorithm algo; 62 mapper.MapScenario(scenario, out algo); 63 if (details.Repititions > 1) { 64 BatchRun br = new BatchRun(); 65 //br.Name = details.JobTitle; 66 br.Optimizer = algo; 67 br.Repetitions = details.Repititions; 68 SendExperimentToHive(user, br, details); 69 } 70 else { 71 SendExperimentToHive(user, algo, details); 72 } 64 73 } 65 74 … … 73 82 } 74 83 75 p rivateIScenarioMapper CompileMapper(string scenarioMapper) {84 public static IScenarioMapper CompileMapper(string scenarioMapper) { 76 85 // http://stackoverflow.com/questions/3188882/compile-and-run-dynamic-code-without-generating-exe 77 86 using (var csCodeProvider = new Microsoft.CSharp.CSharpCodeProvider()) { … … 105 114 106 115 private IScenarioMapper GetMapper(Model.OptimizationScenario scenario) { 107 if (!mappers.ContainsKey(scenario.Name)) { 116 var id = scenario.Id; 117 if (!mappers.ContainsKey(id)) { 108 118 lock (lockable) { 109 if (mappers.ContainsKey( scenario.Name))110 return mappers[ scenario.Name];119 if (mappers.ContainsKey(id)) 120 return mappers[id]; 111 121 112 var mapperString = GetMapperFromBlobStore( scenario.Name);122 var mapperString = GetMapperFromBlobStore(id); 113 123 var mapper = CompileMapper(mapperString); 114 124 115 mappers[ scenario.Name] = mapper;125 mappers[id] = mapper; 116 126 return mapper; 117 127 } // lock … … 120 130 } 121 131 122 private void MapExperiment(Model.OptimizationScenario scenario, IAlgorithm algorithm) {132 private void MapExperiment(Model.OptimizationScenario scenario, out IAlgorithm algorithm) { 123 133 IScenarioMapper mapper = GetMapper(scenario); 124 mapper.MapScenario(scenario, algorithm); 125 } 126 127 private void SendExperimentToHive(Model.User user, IAlgorithm exp) { 134 mapper.MapScenario(scenario, out algorithm); 135 } 136 137 private void ConfigureHive(Model.User user) { 138 HiveServiceLocator.Instance.Username = user.Username; 139 HiveServiceLocator.Instance.Password = user.Password; 140 HiveServiceLocator.Instance.EndpointConfigurationName = Configuration.HiveEndpointName; 141 } 142 143 private void SendExperimentToHive(Model.User user, IOptimizer exp, JobExecutionDetails details) { 128 144 var job = new RefreshableJob(); 129 145 job.IsAllowedPrivileged = true; 130 job.Job.Name = "Web Scheduled Traveling Salesman Job"; 131 job.Job.ResourceNames = "TESTGROUP"; 132 job.RefreshAutomatically = false; 146 job.Job.Name = details.JobTitle; 147 job.Job.ResourceNames = details.Group; 148 job.RefreshAutomatically = false; 149 if (exp.ExecutionState != ExecutionState.Prepared) { 150 exp.Prepare(); 151 } 133 152 job.HiveTasks.Add(new OptimizerHiveTask(exp)); 134 HiveServiceLocator.Instance.Username = user.Username; 135 HiveServiceLocator.Instance.Password = user.Password; 136 HiveServiceLocator.Instance.EndpointConfigurationName = "WSHttpBinding_IHiveService"; 153 ConfigureHive(user); 137 154 138 155 HiveClient.StartJob((ex) => { … … 145 162 146 163 public IList<Model.Job> GetJobs(User user) { 147 HiveServiceLocator.Instance.Username = user.Username; 148 HiveServiceLocator.Instance.Password = user.Password; 149 HiveServiceLocator.Instance.EndpointConfigurationName = "WSHttpBinding_IHiveService"; 164 ConfigureHive(user); 150 165 var jobsLoaded = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.Job>>(s => s.GetJobs()); 151 166 IList<Model.Job> jobs = new List<Model.Job>(); 152 167 153 168 foreach (var job in jobsLoaded) { 154 169 jobs.Add(ConvertJob(user, job)); … … 163 178 if (job.CalculatingCount > 0) 164 179 state = JobState.Calculating; 165 else if (job.JobCount == job.FinishedCount)180 else if (job.JobCount > 0 && job.JobCount == job.FinishedCount) 166 181 state = JobState.Finished; 167 182 else 168 183 state = JobState.Waiting; 169 /*var jobTasks = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(job.Id));170 171 foreach (var task in jobTasks) {172 switch (task.State) {173 case TaskState.Aborted:174 state = JobState.Aborted;175 break;176 case TaskState.Failed:177 state = JobState.Failed;178 break;179 }180 }181 if (!state.HasValue) {182 if (job.CalculatingCount > 0)183 state = JobState.Calculating;184 else if (waitingJobs > 0)185 state = JobState.Waiting;186 else187 state = JobState.Finished;188 }*/189 184 return new Model.Job() { Id = job.Id.ToString(), Name = job.Name, Resource = job.ResourceNames, State = state.Value, DateCreated = job.DateCreated }; 190 185 } … … 192 187 193 188 public Model.Job GetJob(User user, string id) { 194 HiveServiceLocator.Instance.Username = user.Username; 195 HiveServiceLocator.Instance.Password = user.Password; 196 HiveServiceLocator.Instance.EndpointConfigurationName = "WSHttpBinding_IHiveService"; 189 ConfigureHive(user); 197 190 var guid = Guid.Parse(id); 198 191 return ConvertJob(user, HiveServiceLocator.Instance.CallHiveService<HeuristicLab.Clients.Hive.Job>(s => s.GetJob(guid))); … … 201 194 202 195 public void DeleteJob(User user, string id) { 203 HiveServiceLocator.Instance.Username = user.Username; 204 HiveServiceLocator.Instance.Password = user.Password; 205 HiveServiceLocator.Instance.EndpointConfigurationName = "WSHttpBinding_IHiveService"; 196 ConfigureHive(user); 206 197 var guid = Guid.Parse(id); 207 198 HiveServiceLocator.Instance.CallHiveService(s => s.DeleteJob(guid)); … … 209 200 210 201 public IList<Model.Run> GetJobResults(User user, string id) { 211 HiveServiceLocator.Instance.Username = user.Username; 212 HiveServiceLocator.Instance.Password = user.Password; 213 HiveServiceLocator.Instance.EndpointConfigurationName = "WSHttpBinding_IHiveService"; 202 ConfigureHive(user); 214 203 var guid = Guid.Parse(id); 215 204 var jobTasks = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(guid));
Note: See TracChangeset
for help on using the changeset viewer.