Statistiques
| Révision :

root / src / gZFS / zserver.java @ 24

Historique | Voir | Annoter | Télécharger (16,32 ko)

1
package gZFS;
2

    
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileNotFoundException;
6
import java.io.FileOutputStream;
7
import java.io.IOException;
8
import java.util.ArrayList;
9
import java.util.Arrays;
10
import java.util.Hashtable;
11
import java.util.List;
12
import java.util.Properties;
13

    
14
import org.apache.log4j.Logger;
15

    
16

    
17
public class zserver {
18
        private Logger log = Logger.getLogger(getClass().getPackage().getName()+" "+getClass().getCanonicalName());
19
        public Hashtable<String,zProperties> zProperties = new Hashtable<String, zProperties>();
20
        zserver(){
21
        List<Object> permitValueServerIP = new ArrayList<Object>();
22
        zProperties zPropertyServerIP = new zProperties();
23
        permitValueServerIP.clear();
24
        zPropertyServerIP.setNameProperty("serverIP");
25
        zPropertyServerIP.setLabelProperty("Address IP or Server Name");
26
        zPropertyServerIP.setType("freeentry");
27
        zPropertyServerIP.setValue("");
28
        zPropertyServerIP.setPermitValue(null);
29
        zProperties.put("serverIP", zPropertyServerIP);
30
        
31
        List<Object> permitValueUserLogin = new ArrayList<Object>();
32
        zProperties zPropertyUserLogin = new zProperties();
33
        permitValueServerIP.clear();
34
        zPropertyUserLogin.setNameProperty("userLogin");
35
        zPropertyUserLogin.setLabelProperty("User Login");
36
        zPropertyUserLogin.setType("freeentry");
37
        zPropertyUserLogin.setValue("");
38
        zPropertyUserLogin.setPermitValue(null);
39
        zProperties.put("userLogin", zPropertyUserLogin);
40
        
41
        List<Object> permitValueUserPasswd = new ArrayList<Object>();
42
        zProperties zPropertyUserPasswd = new zProperties();
43
        permitValueUserPasswd.clear();
44
        zPropertyUserPasswd.setNameProperty("userPasswd");
45
        zPropertyUserPasswd.setLabelProperty("User Password");
46
        zPropertyUserPasswd.setType("freeentry");
47
        zPropertyUserPasswd.setValue("");
48
        zPropertyUserPasswd.setPermitValue(null);
49
        zProperties.put("userPasswd", zPropertyUserPasswd);
50
        
51
        List<Object> permitValueZfsBinStatus = new ArrayList<Object>();
52
        zProperties zPropertyZfsBinStatus  = new zProperties();
53
        permitValueZfsBinStatus.clear();
54
        zPropertyZfsBinStatus.setNameProperty("binzfs");
55
        zPropertyZfsBinStatus.setLabelProperty("Binary : ZFS");
56
        zPropertyZfsBinStatus.setType("noupdateable");
57
        zPropertyZfsBinStatus.setValue("");
58
        zPropertyZfsBinStatus.setPermitValue(null);
59
        zProperties.put("binzfs", zPropertyZfsBinStatus);
60
        
61
        List<Object> permitValueBinZpool = new ArrayList<Object>();
62
        zProperties zPropertyBinZpool  = new zProperties();
63
        permitValueBinZpool.clear();
64
        zPropertyBinZpool.setNameProperty("binzpool");
65
        zPropertyBinZpool.setLabelProperty("Binary : Zpool");
66
        zPropertyBinZpool.setType("noupdateable");
67
        zPropertyBinZpool.setValue("");
68
        zPropertyBinZpool.setPermitValue(null);
69
        zProperties.put("binzpool", zPropertyBinZpool);
70
        
71
        List<Object> permitValueIscsiGetConfBinStatus = new ArrayList<Object>();
72
        zProperties zPropertyIscsiGetConfBinStatus  = new zProperties();
73
        permitValueIscsiGetConfBinStatus.clear();
74
        zPropertyIscsiGetConfBinStatus.setNameProperty("biniscsigetconf");
75
        zPropertyIscsiGetConfBinStatus.setLabelProperty("Tool : get ISCSI Configuration");
76
        zPropertyIscsiGetConfBinStatus.setType("noupdateable");
77
        zPropertyIscsiGetConfBinStatus.setValue("");
78
        zPropertyIscsiGetConfBinStatus.setPermitValue(null);
79
        zProperties.put("biniscsigetconf", zPropertyIscsiGetConfBinStatus);
80
        
81
        List<Object> permitValueBinGetProvisionedSpace = new ArrayList<Object>();
82
        zProperties zPropertyBinGetProvisionedSpace  = new zProperties();
83
        permitValueBinGetProvisionedSpace.clear();
84
        zPropertyBinGetProvisionedSpace.setNameProperty("bingetprovisionedspace");
85
        zPropertyBinGetProvisionedSpace.setLabelProperty("Tool : Provisionned Space");
86
        zPropertyBinGetProvisionedSpace.setType("noupdateable");
87
        zPropertyBinGetProvisionedSpace.setValue("");
88
        zPropertyBinGetProvisionedSpace.setPermitValue(null);
89
        zProperties.put("bingetprovisionedspace", zPropertyBinGetProvisionedSpace);
90
        
91
        List<Object> permitValueGetConfSnapshot = new ArrayList<Object>();
92
        zProperties zPropertyGetConfSnapshot  = new zProperties();
93
        permitValueGetConfSnapshot.clear();
94
        zPropertyGetConfSnapshot.setNameProperty("bingetconfsnapshot");
95
        zPropertyGetConfSnapshot.setLabelProperty("Tool : get Snapshot Configuration");
96
        zPropertyGetConfSnapshot.setType("noupdateable");
97
        zPropertyGetConfSnapshot.setValue("");
98
        zPropertyGetConfSnapshot.setPermitValue(null);
99
        zProperties.put("bingetconfsnapshot", zPropertyGetConfSnapshot);
100
        
101
        
102
        List<Object> permitValueBinZfsSnapshots = new ArrayList<Object>();
103
        zProperties zPropertyBinZfsSnapshots  = new zProperties();
104
        permitValueBinZfsSnapshots.clear();
105
        zPropertyBinZfsSnapshots.setNameProperty("binzfssnapshots");
106
        zPropertyBinZfsSnapshots.setLabelProperty("Tool : ZFS Snapshots");
107
        zPropertyBinZfsSnapshots.setType("noupdateable");
108
        zPropertyBinZfsSnapshots.setValue("");
109
        zPropertyBinZfsSnapshots.setPermitValue(null);
110
        zProperties.put("binzfssnapshots", zPropertyBinZfsSnapshots);
111
        
112
        List<Object> permitValueBinZfsEnableSnapshots = new ArrayList<Object>();
113
        zProperties zPropertyBinZfsEnableSnapshots  = new zProperties();
114
        permitValueBinZfsEnableSnapshots.clear();
115
        zPropertyBinZfsEnableSnapshots.setNameProperty("binzfsenablesnapshots");
116
        zPropertyBinZfsEnableSnapshots.setLabelProperty("Tool : Enable ZFS Snapshots");
117
        zPropertyBinZfsEnableSnapshots.setType("noupdateable");
118
        zPropertyBinZfsEnableSnapshots.setValue("");
119
        zPropertyBinZfsEnableSnapshots.setPermitValue(null);
120
        zProperties.put("binzfsenablesnapshots", zPropertyBinZfsEnableSnapshots);
121
        
122
        List<Object> permitValueBinZfsDisableSnapshots = new ArrayList<Object>();
123
        zProperties zPropertyBinZfsDisableSnapshots  = new zProperties();
124
        permitValueBinZfsDisableSnapshots.clear();
125
        zPropertyBinZfsDisableSnapshots.setNameProperty("binzfsdisablesnapshots");
126
        zPropertyBinZfsDisableSnapshots.setLabelProperty("Tool : Disable ZFS Snapshots");
127
        zPropertyBinZfsDisableSnapshots.setType("noupdateable");
128
        zPropertyBinZfsDisableSnapshots.setValue("");
129
        zPropertyBinZfsDisableSnapshots.setPermitValue(null);
130
        zProperties.put("binzfsdisablesnapshots", zPropertyBinZfsDisableSnapshots);
131
        
132
        
133
        List<Object> permitValuePathZfsconfSnapshots = new ArrayList<Object>();
134
        zProperties zPropertyPathZfsconfSnapshots  = new zProperties();
135
        permitValuePathZfsconfSnapshots.clear();
136
        zPropertyPathZfsconfSnapshots.setNameProperty("pathzfsconfsnapshots");
137
        zPropertyPathZfsconfSnapshots.setLabelProperty("Path : Snapshot Configuration File");
138
        zPropertyPathZfsconfSnapshots.setType("noupdateable");
139
        zPropertyPathZfsconfSnapshots.setValue("");
140
        zPropertyPathZfsconfSnapshots.setPermitValue(null);
141
        zProperties.put("pathzfsconfsnapshots", zPropertyPathZfsconfSnapshots);
142
        
143
        List<Object> permitValuePathZfsConfTools = new ArrayList<Object>();
144
        zProperties zPropertyPathZfsConfTools  = new zProperties();
145
        permitValuePathZfsConfTools.clear();
146
        zPropertyPathZfsConfTools.setNameProperty("pathzfsconftools");
147
        zPropertyPathZfsConfTools.setLabelProperty("Path : ZFS Tools");
148
        zPropertyPathZfsConfTools.setType("noupdateable");
149
        zPropertyPathZfsConfTools.setValue("");
150
        zPropertyPathZfsConfTools.setPermitValue(null);
151
        zProperties.put("pathzfsconftools", zPropertyPathZfsConfTools);
152
        
153
        List<Object> permitValuePathZfsConf = new ArrayList<Object>();
154
        zProperties zPropertyPathZfsConf  = new zProperties();
155
        permitValuePathZfsConf.clear();
156
        zPropertyPathZfsConf.setNameProperty("pathzfsconf");
157
        zPropertyPathZfsConf.setLabelProperty("Path : gZFS");
158
        zPropertyPathZfsConf.setType("noupdateable");
159
        zPropertyPathZfsConf.setValue("");
160
        zPropertyPathZfsConf.setPermitValue(null);
161
        zProperties.put("pathzfsconf", zPropertyPathZfsConf);
162
        
163
        List<Object> permitValuePathZfsVolDevice = new ArrayList<Object>();
164
        zProperties zPropertyPathZfsVolDevice  = new zProperties();
165
        permitValuePathZfsVolDevice.clear();
166
        zPropertyPathZfsVolDevice.setNameProperty("pathzfsvoldevice");
167
        zPropertyPathZfsVolDevice.setLabelProperty("Path : ZFS Volume Device");
168
        zPropertyPathZfsVolDevice.setType("noupdateable");
169
        zPropertyPathZfsVolDevice.setValue("");
170
        zPropertyPathZfsVolDevice.setPermitValue(null);
171
        zProperties.put("pathzfsvoldevice", zPropertyPathZfsVolDevice);
172
        
173
        List<Object> permitValueBinZfsAddISCSI = new ArrayList<Object>();
174
        zProperties zPropertyBinZfsAddISCSI  = new zProperties();
175
        permitValueBinZfsAddISCSI.clear();
176
        zPropertyBinZfsAddISCSI.setNameProperty("binzfsaddiscsi");
177
        zPropertyBinZfsAddISCSI.setLabelProperty("Tool : Create ISCSI Volume");
178
        zPropertyBinZfsAddISCSI.setType("noupdateable");
179
        zPropertyBinZfsAddISCSI.setValue("");
180
        zPropertyBinZfsAddISCSI.setPermitValue(null);
181
        zProperties.put("binzfsaddiscsi", zPropertyBinZfsAddISCSI);
182
        
183
        List<Object> permitValueBinZfsDelISCSI = new ArrayList<Object>();
184
        zProperties zPropertyBinZfsDelISCSI  = new zProperties();
185
        permitValueBinZfsDelISCSI.clear();
186
        zPropertyBinZfsDelISCSI.setNameProperty("binzfsadelscsi");
187
        zPropertyBinZfsDelISCSI.setLabelProperty("Tool : Delete ISCSI Volume");
188
        zPropertyBinZfsDelISCSI.setType("noupdateable");
189
        zPropertyBinZfsDelISCSI.setValue("");
190
        zPropertyBinZfsDelISCSI.setPermitValue(null);
191
        zProperties.put("binzfsdeliscsi", zPropertyBinZfsDelISCSI);
192
        
193
        List<Object> permitValueBinZfsCreateVol = new ArrayList<Object>();
194
        zProperties zPropertyBinZfsCreateVol  = new zProperties();
195
        permitValueBinZfsCreateVol.clear();
196
        zPropertyBinZfsCreateVol.setNameProperty("binzfscreatevolume");
197
        zPropertyBinZfsCreateVol.setLabelProperty("Tool : Create ZFS Volume");
198
        zPropertyBinZfsCreateVol.setType("noupdateable");
199
        zPropertyBinZfsCreateVol.setValue("");
200
        zPropertyBinZfsCreateVol.setPermitValue(null);
201
        zProperties.put("binzfscreatevolume", zPropertyBinZfsCreateVol);
202
        
203
        List<Object> permitValueBinZfsCreateFS = new ArrayList<Object>();
204
        zProperties zPropertyBinZfsCreateFS  = new zProperties();
205
        permitValueBinZfsCreateFS.clear();
206
        zPropertyBinZfsCreateFS.setNameProperty("binzfscreatefilesystem");
207
        zPropertyBinZfsCreateFS.setLabelProperty("Tool : Create ZFS FileSystem");
208
        zPropertyBinZfsCreateFS.setType("noupdateable");
209
        zPropertyBinZfsCreateFS.setValue("");
210
        zPropertyBinZfsCreateFS.setPermitValue(null);
211
        zProperties.put("binzfscreatefilesystem", zPropertyBinZfsCreateFS);
212
        
213
        List<Object> permitValueBinZfsDelFS = new ArrayList<Object>();
214
        zProperties zPropertyBinZfsDelFS  = new zProperties();
215
        permitValueBinZfsDelFS.clear();
216
        zPropertyBinZfsDelFS.setNameProperty("binzfsdelfilesystem");
217
        zPropertyBinZfsDelFS.setLabelProperty("Tool : Delete ZFS FileSystem");
218
        zPropertyBinZfsDelFS.setType("noupdateable");
219
        zPropertyBinZfsDelFS.setValue("");
220
        zPropertyBinZfsDelFS.setPermitValue(null);
221
        zProperties.put("binzfsdelfilesystem", zPropertyBinZfsDelFS);
222
        
223
        List<Object> permitValueBinZfsDelVolume = new ArrayList<Object>();
224
        zProperties zPropertyBinZfsDelVolume  = new zProperties();
225
        permitValueBinZfsDelVolume.clear();
226
        zPropertyBinZfsDelVolume.setNameProperty("binzfsdelvolume");
227
        zPropertyBinZfsDelVolume.setLabelProperty("Tool : Delete ZFS Volume");
228
        zPropertyBinZfsDelVolume.setType("noupdateable");
229
        zPropertyBinZfsDelVolume.setValue("");
230
        zPropertyBinZfsDelVolume.setPermitValue(null);
231
        zProperties.put("binzfsdelvolume", zPropertyBinZfsDelVolume);
232
        
233
        List<Object> permitValueBinGetDiskInfo = new ArrayList<Object>();
234
        zProperties zPropertyBinGetDiskInfo  = new zProperties();
235
        permitValueBinGetDiskInfo.clear();
236
        zPropertyBinGetDiskInfo.setNameProperty("bingetdiskinfo");
237
        zPropertyBinGetDiskInfo.setLabelProperty("Tool : Get Disk Informations");
238
        zPropertyBinGetDiskInfo.setType("noupdateable");
239
        zPropertyBinGetDiskInfo.setValue("");
240
        zPropertyBinGetDiskInfo.setPermitValue(null);
241
        zProperties.put("bingetdiskinfo", zPropertyBinGetDiskInfo);
242
        
243
        List<Object> permitValueBinZFSClone = new ArrayList<Object>();
244
        zProperties zPropertyBinZFSClone  = new zProperties();
245
        permitValueBinZFSClone.clear();
246
        zPropertyBinZFSClone.setNameProperty("binzfsclone");
247
        zPropertyBinZFSClone.setLabelProperty("Tool : ZFS Clone");
248
        zPropertyBinZFSClone.setType("noupdateable");
249
        zPropertyBinZFSClone.setValue("");
250
        zPropertyBinZFSClone.setPermitValue(null);
251
        zProperties.put("binzfsclone", zPropertyBinZFSClone);
252
        
253
        List<Object> permitValueBinZpoolGetState = new ArrayList<Object>();
254
        zProperties zPropertyBinZpoolGetState  = new zProperties();
255
        permitValueBinZpoolGetState.clear();
256
        zPropertyBinZpoolGetState.setNameProperty("binzpoolgetstate");
257
        zPropertyBinZpoolGetState.setLabelProperty("Tool : ZFS Clone");
258
        zPropertyBinZpoolGetState.setType("noupdateable");
259
        zPropertyBinZpoolGetState.setValue("");
260
        zPropertyBinZpoolGetState.setPermitValue(null);
261
        zProperties.put("binzpoolgetstate", zPropertyBinZpoolGetState);
262
        
263
        List<Object> permitValueBinGetConfReplica = new ArrayList<Object>();
264
        zProperties zPropertyBinGetConfReplica  = new zProperties();
265
        permitValueBinGetConfReplica.clear();
266
        zPropertyBinGetConfReplica.setNameProperty("bingetconfreplica");
267
        zPropertyBinGetConfReplica.setLabelProperty("Tool : ZFS Replication");
268
        zPropertyBinGetConfReplica.setType("noupdateable");
269
        zPropertyBinGetConfReplica.setValue("");
270
        zPropertyBinGetConfReplica.setPermitValue(null);
271
        zProperties.put("bingetconfreplica", zPropertyBinGetConfReplica);
272
        
273
        List<Object> permitValueBinEnableReplica = new ArrayList<Object>();
274
        zProperties zPropertyBinEnableReplica  = new zProperties();
275
        permitValueBinEnableReplica.clear();
276
        zPropertyBinEnableReplica.setNameProperty("binzfsenablereplicas");
277
        zPropertyBinEnableReplica.setLabelProperty("Tool :Enable ZFS Replication");
278
        zPropertyBinEnableReplica.setType("noupdateable");
279
        zPropertyBinEnableReplica.setValue("");
280
        zPropertyBinEnableReplica.setPermitValue(null);
281
        zProperties.put("binzfsenablereplicas", zPropertyBinEnableReplica);
282
        
283
        List<Object> permitValueBinDisableReplica = new ArrayList<Object>();
284
        zProperties zPropertyBinDisableReplica  = new zProperties();
285
        permitValueBinDisableReplica.clear();
286
        zPropertyBinDisableReplica.setNameProperty("binzfsdisablereplicas");
287
        zPropertyBinDisableReplica.setLabelProperty("Tool :Disable ZFS Replication");
288
        zPropertyBinDisableReplica.setType("noupdateable");
289
        zPropertyBinDisableReplica.setValue("");
290
        zPropertyBinDisableReplica.setPermitValue(null);
291
        zProperties.put("binzfsdisablereplicas", zPropertyBinDisableReplica);
292
        
293
        List<Object> permitValueBinReplica = new ArrayList<Object>();
294
        zProperties zPropertyBinReplica  = new zProperties();
295
        permitValueBinReplica.clear();
296
        zPropertyBinReplica.setNameProperty("binzfsreplica");
297
        zPropertyBinReplica.setLabelProperty("Tool : Binary ZFS Replication");
298
        zPropertyBinReplica.setType("noupdateable");
299
        zPropertyBinReplica.setValue("");
300
        zPropertyBinReplica.setPermitValue(null);
301
        zProperties.put("binzfsreplica", zPropertyBinReplica);
302
        
303
        /*List<Object> permitValueBinDisableReplica = new ArrayList<Object>();
304
        zProperties zPropertyBinDisableReplica  = new zProperties();
305
        permitValueBinDisableReplica.clear();
306
        zPropertyBinDisableReplica.setNameProperty("binzfsdisablereplicas");
307
        zPropertyBinDisableReplica.setLabelProperty("Tool :Disable ZFS Replication");
308
        zPropertyBinDisableReplica.setType("noupdateable");
309
        zPropertyBinDisableReplica.setValue("");
310
        zPropertyBinDisableReplica.setPermitValue(null);
311
        zProperties.put("binzfsdisablereplicas", zPropertyBinDisableReplica);*/
312
        
313
        }
314
        
315
        
316
        public boolean add(String fileName){
317
                
318
                try {
319
                        Properties prop = new Properties();
320
                        String[] keysProp = (String[])this.zProperties.keySet().toArray(new String[0]);
321
                        Arrays.sort(keysProp);
322
                        for (int i = 0; i < keysProp.length; i++) {
323
                                String keyProp = keysProp[i];
324
                                log.debug("keyProp :"+keyProp);
325
                                prop.setProperty(keyProp, this.zProperties.get(keyProp).getValue());        
326
                        }
327
                        prop.store(new FileOutputStream(fileName), null);
328
                } catch (FileNotFoundException e) {
329
                        // TODO Auto-generated catch block
330
                        e.printStackTrace();
331
                        return false;
332
                } catch (IOException e) {
333
                        // TODO Auto-generated catch block
334
                        e.printStackTrace();
335
                        return false;
336
                }
337
                return true;
338
        }
339
        
340
        public boolean load(String fileName){
341
                try {
342
                        Properties prop = new Properties();
343
                    prop.load(new FileInputStream(fileName));
344
                        String[] keysProp = (String[])this.zProperties.keySet().toArray(new String[0]);
345
                        Arrays.sort(keysProp);
346
                        for (int i = 0; i < keysProp.length; i++) {
347
                                String keyProp = keysProp[i];        
348
                                if ( prop.containsKey(keyProp)){
349
                                        this.zProperties.get(keyProp).setValue(prop.getProperty(keyProp));        
350
                                }else{
351
                                        this.zProperties.get(keyProp).setValue("");
352
                                }
353
                                        
354
                        }
355
                } catch (FileNotFoundException e) {
356
                        // TODO Auto-generated catch block
357
                        e.printStackTrace();
358
                        return false;
359
                } catch (IOException e) {
360
                        // TODO Auto-generated catch block
361
                        e.printStackTrace();
362
                        return false;
363
                }
364
                return true;
365
        }
366
        
367
        public boolean remove(String fileName){
368
                File f = new File(fileName);
369
                if (f.exists()){
370
                        if (f.delete()){
371
                                return true;
372
                        }
373
                }
374
                return false;
375
        }
376
}