1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ServiceModel;
|
---|
25 | using System.Windows.Forms;
|
---|
26 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
27 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
28 | using HeuristicLab.Hive.Contracts.ResponseObjects;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
31 |
|
---|
32 | public delegate void addDelegate();
|
---|
33 |
|
---|
34 | public partial class AddJobForm : Form {
|
---|
35 |
|
---|
36 | public event addDelegate addJobEvent;
|
---|
37 |
|
---|
38 | ResponseList<ProjectDto> projects = null;
|
---|
39 | IJobManager jobManager;
|
---|
40 | ISlaveManager slaveManager;
|
---|
41 | ResponseList<SlaveGroupDto> clientGroups;
|
---|
42 |
|
---|
43 | Dictionary<Guid, string> clients = null;
|
---|
44 |
|
---|
45 | public AddJobForm() {
|
---|
46 | InitializeComponent();
|
---|
47 |
|
---|
48 | clients = new Dictionary<Guid, string>();
|
---|
49 | AddJob();
|
---|
50 |
|
---|
51 | }
|
---|
52 |
|
---|
53 | private void AddJob() {
|
---|
54 | try {
|
---|
55 | jobManager = ServiceLocator.GetJobManager();
|
---|
56 | projects = jobManager.GetAllProjects();
|
---|
57 | slaveManager = ServiceLocator.GetSlaveManager();
|
---|
58 | clientGroups = slaveManager.GetAllSlaveGroups();
|
---|
59 | cbProject.Items.Add("none");
|
---|
60 | cbProject.SelectedIndex = 0;
|
---|
61 | foreach (ProjectDto project in projects.List) {
|
---|
62 | cbProject.Items.Add(project.Name);
|
---|
63 | }
|
---|
64 |
|
---|
65 | AddSlaveGroups();
|
---|
66 |
|
---|
67 | foreach (KeyValuePair<Guid, string> kvp in clients) {
|
---|
68 | lbGroupsOut.Items.Add(kvp.Value + " (" + kvp.Key + ")");
|
---|
69 | }
|
---|
70 | }
|
---|
71 | catch (FaultException fe) {
|
---|
72 | MessageBox.Show(fe.Message);
|
---|
73 | }
|
---|
74 |
|
---|
75 | }
|
---|
76 |
|
---|
77 | private void AddSlaveGroups() {
|
---|
78 | foreach (SlaveGroupDto cg in clientGroups.List) {
|
---|
79 | if (cg.Id != Guid.Empty)
|
---|
80 | clients.Add(cg.Id, cg.Name);
|
---|
81 | AddSlaveOrGroup(cg);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | private void AddSlaveOrGroup(SlaveGroupDto clientGroup) {
|
---|
86 | foreach (ResourceDto resource in clientGroup.Resources) {
|
---|
87 | if (resource is SlaveGroupDto) {
|
---|
88 | if (resource.Id != Guid.Empty)
|
---|
89 | clients.Add(resource.Id, resource.Name);
|
---|
90 | AddSlaveOrGroup(resource as SlaveGroupDto);
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | }
|
---|
95 |
|
---|
96 | private void BtnAdd_Click(object sender, EventArgs e) {
|
---|
97 | try {
|
---|
98 | lblError.Text = "";
|
---|
99 | int numJobs = Convert.ToInt32(tbNumJobs.Text);
|
---|
100 | if (numJobs > 0) {
|
---|
101 | for (int i = 0; i < numJobs; i++) {
|
---|
102 | JobDto job = new JobDto { State = JobState.Offline, CoresNeeded = 1 };
|
---|
103 |
|
---|
104 | // if project selected (0 -> none)
|
---|
105 | if (cbProject.SelectedIndex != 0) {
|
---|
106 | job.Project = projects.List[cbProject.SelectedIndex - 1];
|
---|
107 | }
|
---|
108 |
|
---|
109 | if (!cbAllGroups.Checked) {
|
---|
110 | List<Guid> groupsToCalculate = new List<Guid>();
|
---|
111 | foreach (string item in lbGroupsIn.Items) {
|
---|
112 | int start = item.IndexOf("(");
|
---|
113 | int end = item.IndexOf(")");
|
---|
114 | string substring = item.Substring(start + 1, end - start - 1);
|
---|
115 | Guid guid = new Guid(substring);
|
---|
116 | groupsToCalculate.Add(guid);
|
---|
117 | }
|
---|
118 | job.AssignedResourceIds = groupsToCalculate;
|
---|
119 | }
|
---|
120 |
|
---|
121 | SerializedJob computableJob = new SerializedJob();
|
---|
122 | computableJob.JobInfo = job;
|
---|
123 |
|
---|
124 | // [chn] TODO: persist to zip
|
---|
125 | // computableJob.SerializedJobData = PersistenceManager.SaveToGZip(new TestJob());
|
---|
126 | Response resp = jobManager.AddNewJob(computableJob);
|
---|
127 | }
|
---|
128 | if (addJobEvent != null) {
|
---|
129 | addJobEvent();
|
---|
130 | }
|
---|
131 | this.Close();
|
---|
132 | } else {
|
---|
133 | lblError.Text = "Wrong number of Jobs";
|
---|
134 | }
|
---|
135 |
|
---|
136 | }
|
---|
137 | catch {
|
---|
138 | lblError.Text = "There should be a number";
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | private void BtnClose_Click(object sender, EventArgs e) {
|
---|
143 | this.Close();
|
---|
144 | }
|
---|
145 |
|
---|
146 | private void cbAllGroups_CheckedChanged(object sender, EventArgs e) {
|
---|
147 | foreach (Control control in gbGroups.Controls) {
|
---|
148 | control.Enabled = !cbAllGroups.Checked;
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | private void btnAddGroup_Click(object sender, EventArgs e) {
|
---|
153 | AddGroup();
|
---|
154 | }
|
---|
155 |
|
---|
156 | private void btnRemoveGroup_Click(object sender, EventArgs e) {
|
---|
157 | RemoveGroup();
|
---|
158 | }
|
---|
159 |
|
---|
160 | private void lbGroupsOut_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
161 | AddGroup();
|
---|
162 | }
|
---|
163 |
|
---|
164 | private void lbGroupsIn_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
165 | RemoveGroup();
|
---|
166 | }
|
---|
167 |
|
---|
168 | private void AddGroup() {
|
---|
169 | if (lbGroupsOut.SelectedItem != null) {
|
---|
170 | lbGroupsIn.Items.Add(lbGroupsOut.SelectedItem);
|
---|
171 | lbGroupsOut.Items.RemoveAt(lbGroupsOut.SelectedIndex);
|
---|
172 | }
|
---|
173 |
|
---|
174 | }
|
---|
175 |
|
---|
176 | private void RemoveGroup() {
|
---|
177 | if (lbGroupsIn.SelectedItem != null) {
|
---|
178 | lbGroupsOut.Items.Add(lbGroupsIn.SelectedItem);
|
---|
179 | lbGroupsIn.Items.RemoveAt(lbGroupsIn.SelectedIndex);
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | private void btnLoad_Click(object sender, EventArgs e) {
|
---|
184 |
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | }
|
---|
189 | }
|
---|