Statistiques
| Révision :

root / src / gZFS / zserver.java @ 53

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

1
/*******************************************************************
2
 * 
3
 * Copyright (C) 2013 Kevin Reverchon
4
 * This file/program is part of gZFS free software
5
 * See COPYING file for details
6
 * 
7
 *******************************************************************/
8
package gZFS;
9

    
10
import java.io.File;
11
import java.io.FileInputStream;
12
import java.io.FileNotFoundException;
13
import java.io.FileOutputStream;
14
import java.io.IOException;
15
import java.util.ArrayList;
16
import java.util.Arrays;
17
import java.util.Hashtable;
18
import java.util.List;
19
import java.util.Properties;
20

    
21
import org.apache.log4j.Logger;
22

    
23

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