~michaeleguo/ubuntu/trusty/percona-xtradb-cluster-5.5/arm64fix

« back to all changes in this revision

Viewing changes to storage/ndb/src/cw/cpcc-win32/csharp/Computer.cs

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-10 14:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20140210144423-f2134l2gxuvq2m6l
Tags: upstream-5.5.34-25.9+dfsg
ImportĀ upstreamĀ versionĀ 5.5.34-25.9+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2004 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */
 
15
 
 
16
using System;
 
17
using System.Drawing;
 
18
using System.Collections;
 
19
using System.ComponentModel;
 
20
using System.Windows.Forms;
 
21
using System.Data;
 
22
using System.IO;
 
23
using NDB_CPC.socketcomm;
 
24
using NDB_CPC.simpleparser;
 
25
 
 
26
 
 
27
namespace NDB_CPC
 
28
{
 
29
        /// <summary>
 
30
        /// Summary description for Computer.
 
31
        /// </summary>
 
32
        public class Computer
 
33
        {
 
34
                public enum     Status {Disconnected=1,Connected=2, Unknown=3}
 
35
                private string m_ip;
 
36
                private int m_cpcdPort;
 
37
                private string m_name;
 
38
                private Status m_status;
 
39
                private ArrayList m_processes;
 
40
                private SocketComm m_socket;
 
41
                public Computer(string name, int port)
 
42
                {
 
43
                        m_name = name;
 
44
                        m_status = Status.Disconnected;
 
45
                        m_processes = new ArrayList();
 
46
                        m_cpcdPort=port;
 
47
                        m_socket = new SocketComm(m_name,m_cpcdPort);
 
48
                }
 
49
 
 
50
                public Computer(string name, string ip)
 
51
                {
 
52
                        m_ip = ip;
 
53
                        m_name = name;
 
54
                        m_status = Status.Disconnected;
 
55
                        m_processes = new ArrayList();
 
56
                        m_cpcdPort=1234; //default port
 
57
                        m_socket = new SocketComm(m_ip,m_cpcdPort);
 
58
                }
 
59
 
 
60
                public void connectToCpcd()
 
61
                {
 
62
                        m_socket.doConnect();
 
63
                }
 
64
 
 
65
                private bool sendMessage(string str)
 
66
                {       
 
67
                        return m_socket.writeMessage(str);
 
68
                        
 
69
                }
 
70
                
 
71
                public string getName() {return m_name;}
 
72
                public string getIp() {return m_ip;}
 
73
                public ArrayList getProcesses() 
 
74
                { 
 
75
                        if(m_processes.Count>0)
 
76
                                return m_processes;     
 
77
                        else
 
78
                                return null;
 
79
                }
 
80
                public string getStatusString() 
 
81
                {
 
82
                        try 
 
83
                        {
 
84
                                if(m_socket.isConnected())
 
85
                                        return "Connected";
 
86
                                else
 
87
                                        return "Disconnected";
 
88
                        }
 
89
                        catch(Exception e)
 
90
                        {
 
91
                                return "Unknown";
 
92
                        }
 
93
                }
 
94
 
 
95
                
 
96
                public bool isConnected() 
 
97
                {
 
98
                        if(m_socket.isConnected())
 
99
                                return true;
 
100
                        return false;           
 
101
                }
 
102
 
 
103
                public Status getStatus() 
 
104
                {
 
105
                        try 
 
106
                        {
 
107
                                if(m_socket.isConnected())
 
108
                                        return Status.Connected;
 
109
                                else
 
110
                                        return Status.Disconnected;
 
111
                        }
 
112
                        catch(Exception e)
 
113
                        {
 
114
                                return Status.Unknown;
 
115
                        }
 
116
                }
 
117
 
 
118
                public void setStatus(Status status) 
 
119
                {
 
120
                        m_status=status;
 
121
                }
 
122
 
 
123
                public void addProcess(Process process) 
 
124
                {
 
125
                        m_processes.Add(process);
 
126
                }
 
127
 
 
128
                public Process getProcessByName(string name) 
 
129
                {
 
130
                        foreach(Process process in m_processes)
 
131
                        {
 
132
                                if(process.getName().Equals(name))
 
133
                                        return process;
 
134
                        }
 
135
                        return null;
 
136
                }
 
137
 
 
138
 
 
139
                public bool removeProcess(string name, string database)
 
140
                {
 
141
                        foreach(Process p in m_processes)
 
142
                        {
 
143
                                if(p.getName().Equals(name) && p.getDatabase().Equals(database))
 
144
                                {
 
145
                                        m_processes.Remove(p);
 
146
                                        return true;
 
147
                                }
 
148
                        }
 
149
                        return false;
 
150
                }
 
151
 
 
152
                public void disconnect()
 
153
                {       
 
154
                        m_socket.disconnect();
 
155
                }
 
156
                public Process getProcess(string id) 
 
157
                {
 
158
                        foreach(Process process in m_processes)
 
159
                        {
 
160
                                if(process.getId().Equals(id))
 
161
                                        return process;
 
162
                        }
 
163
                        return null;
 
164
                }
 
165
 
 
166
                public int listProcesses()
 
167
                {
 
168
                        string list = "list processes\n\n";
 
169
 
 
170
                        if(!sendMessage(list))
 
171
                                return -2;
 
172
                        
 
173
                        SimpleCPCParser.parse(m_processes, this, m_socket);
 
174
                        return 1;
 
175
                }
 
176
 
 
177
                public int defineProcess(Process p)
 
178
                {
 
179
                        string define = "define process \n";
 
180
                        define = define + "name:" + p.getName() + "\n";
 
181
                        define = define + "group:" + p.getDatabase() + "\n";
 
182
                        define = define + "env:" + "NDB_CONNECTSTRING="+p.getConnectString() ;
 
183
                        if(p.getEnv().Equals(""))
 
184
                                define = define + "\n";
 
185
                        else
 
186
                                define = define + " " + p.getEnv() + "\n";
 
187
                                
 
188
                        //if(p.getPath().EndsWith("\\")) 
 
189
                        //      define = define + "path:" + p.getPath()+ "ndb" + "\n";
 
190
                        //else
 
191
                        define = define + "path:" + p.getPath() + "\n";
 
192
                        define = define + "args:" + p.getArgs() + "\n";
 
193
                        define = define + "type:" + "permanent" + "\n";
 
194
                        define = define + "cwd:" + p.getCwd() + "\n";
 
195
                        define = define + "owner:" + "ejohson" + "\n\n";
 
196
                        
 
197
                        if(!sendMessage(define))
 
198
                                return -2;
 
199
                        
 
200
                        SimpleCPCParser.parse(p, m_socket);
 
201
                        if(p.isDefined())
 
202
                                return 1;
 
203
                        else 
 
204
                                return -1;
 
205
                
 
206
                }
 
207
 
 
208
                public int startProcess(Process p)
 
209
                {
 
210
                        if(!p.isDefined())
 
211
                        {
 
212
                                this.defineProcess(p);
 
213
                                if(!p.isDefined())
 
214
                                        return -4; //process misconfigured
 
215
 
 
216
                        }
 
217
                        string start= "start process \n";
 
218
                        start = start + "id:" + p.getId() + "\n\n";
 
219
                        if(!sendMessage(start))
 
220
                                return -2;
 
221
                        SimpleCPCParser.parse(p, m_socket);
 
222
                        if(p.getStatus().Equals(Process.Status.Running))
 
223
                                return 1;
 
224
                        else 
 
225
                                return -1;
 
226
                }
 
227
 
 
228
                public int stopProcess(Process p)
 
229
                {
 
230
                        if(!p.isDefined())
 
231
                        {
 
232
                                return -4; //process not defined
 
233
                        }
 
234
                        string stop= "stop process \n";
 
235
                        stop = stop + "id:" + p.getId() + "\n\n";
 
236
                        if(!sendMessage(stop))
 
237
                                return -2;
 
238
                        SimpleCPCParser.parse(p, m_socket);
 
239
        
 
240
                        if(p.getStatus().Equals(Process.Status.Stopped))
 
241
                                return 1;
 
242
                        else 
 
243
                                return -1;
 
244
                }
 
245
 
 
246
                public int undefineProcess(Process p)
 
247
                {
 
248
                        if(!p.isDefined())
 
249
                        {
 
250
                                return -4; //process not defined
 
251
                        }
 
252
                        string undefine= "undefine process \n";
 
253
                        undefine = undefine + "id:" + p.getId() + "\n\n";
 
254
                        if(!sendMessage(undefine))
 
255
                                return -2;
 
256
                        SimpleCPCParser.parse(p, m_socket);
 
257
                        if(!p.isDefined()) 
 
258
                        {
 
259
                                return 1;
 
260
 
 
261
                        }
 
262
                        return -1;
 
263
                }
 
264
 
 
265
                public int getCpcdPort()
 
266
                {
 
267
                        return this.m_cpcdPort;
 
268
                }
 
269
 
 
270
        }
 
271
}