Statistiques
| Révision :

root / src / gZFS / zreplicas.java @ 53

Historique | Voir | Annoter | Télécharger (13,04 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.text.DateFormat;
11
import java.text.ParseException;
12
import java.text.SimpleDateFormat;
13
import java.util.Calendar;
14
import java.util.Date;
15
import java.util.GregorianCalendar;
16
import java.util.Hashtable;
17

    
18
public class zreplicas {
19
        public Hashtable<String,zProperties> zProperties = new Hashtable<String, zProperties>();
20
        public Hashtable<String,zProperties> zSchedulerProperties = new Hashtable<String, zProperties>();
21

    
22
        private Hashtable<Object, Object> cronMinute = new Hashtable<Object, Object>();
23
        private Hashtable<Object, Object> cronHour= new Hashtable<Object, Object>();
24
        private Hashtable<Object, Object> cronMonth= new Hashtable<Object, Object>();
25
        private Hashtable<Object, Object> cronDayOfMonth = new Hashtable<Object, Object>();
26
        private Hashtable<Object, Object> cronDayOfWeek = new Hashtable<Object, Object>();
27
        
28
        zreplicas(){
29
                String valueForHash = null;
30
                for (int i=1;i<61;i++){
31
                        
32
                        if ( i<10){
33
                                valueForHash="0"+String.valueOf(i);
34
                        }else{
35
                                valueForHash=String.valueOf(i);
36
                        }
37
                        cronMinute.put(String.valueOf(i), valueForHash);
38
                        if ( i ==1){
39
                                cronMinute.put("*", "All");
40
                        }else{
41
                                cronMinute.put("*/"+i, "Every "+valueForHash+" Minutes");        
42
                        }
43
                }
44
                
45
                for (int i=0;i<24;i++){
46
                        if ( i<10){
47
                                valueForHash="0"+String.valueOf(i);
48
                        }else{
49
                                valueForHash=String.valueOf(i);
50
                        }
51
                        cronHour.put(String.valueOf(i), valueForHash);
52
                        if ( i ==1){
53
                                cronHour.put("*", "All");
54
                        }else{
55
                                cronHour.put("*/"+i, "Every "+valueForHash+" Hours");        
56
                        }
57
                }
58
                
59
                cronMonth.put("01", "January");
60
                cronMonth.put("02", "February");
61
                cronMonth.put("03", "March");
62
                cronMonth.put("04", "April");
63
                cronMonth.put("05", "May");
64
                cronMonth.put("06", "June");
65
                cronMonth.put("07", "July");
66
                cronMonth.put("08", "August");
67
                cronMonth.put("09", "September");
68
                cronMonth.put("10", "October");
69
                cronMonth.put("11", "November");
70
                cronMonth.put("12", "December");
71
                cronMonth.put("*", "All");
72
                
73
                cronDayOfWeek.put("0", "Sunday");
74
                cronDayOfWeek.put("1", "Monday");
75
                cronDayOfWeek.put("2", "Tuesday");
76
                cronDayOfWeek.put("3", "Wednesday");
77
                cronDayOfWeek.put("4", "Thursday");
78
                cronDayOfWeek.put("5", "Friday");
79
                cronDayOfWeek.put("6", "Saturday");
80
                cronDayOfWeek.put("*", "All");
81
                
82
                
83
                for (int i=1;i<31;i++){
84
                        if ( i<10){
85
                                valueForHash="0"+String.valueOf(i);
86
                        }else{
87
                                valueForHash=String.valueOf(i);
88
                        }
89
                        cronDayOfMonth.put(String.valueOf(i), valueForHash);
90
                        if ( i ==1){
91
                                cronDayOfMonth.put("*", "All");
92
                        }else{
93
                                cronDayOfMonth.put("*/"+i, "Every "+valueForHash+" Days");        
94
                        }
95
                }
96

    
97
                Hashtable<Object, Object> permitValueNameVolFS = new Hashtable<Object, Object>();
98
                zProperties zPropertyNameVolFS = new zProperties();
99
                permitValueNameVolFS.clear();
100
                zPropertyNameVolFS.setNameProperty("name");
101
                zPropertyNameVolFS.setLabelProperty("Name Volume/FileSystem replicated");
102
                zPropertyNameVolFS.setType("noupdateable");
103
                zPropertyNameVolFS.setValue("");
104
                zPropertyNameVolFS.setPermitValue(null);
105
                zPropertyNameVolFS.setMultivalues(null);
106
                zSchedulerProperties.put("name", zPropertyNameVolFS);
107
                
108
                Hashtable<Object, Object> permitValueFileConf = new Hashtable<Object, Object>();
109
                zProperties zPropertyFileConf = new zProperties();
110
                permitValueFileConf.clear();
111
                zPropertyFileConf.setNameProperty("fileconf");
112
                zPropertyFileConf.setLabelProperty("Configuration File");
113
                zPropertyFileConf.setType("noupdateable");
114
                zPropertyFileConf.setValue("");
115
                zPropertyFileConf.setPermitValue(null);
116
                zPropertyFileConf.setMultivalues(null);
117
                zSchedulerProperties.put("fileconf", zPropertyFileConf);
118

    
119
                Hashtable<Object, Object> permitValueNameReplica = new Hashtable<Object, Object>();
120
                zProperties zPropertyNameReplica = new zProperties();
121
                permitValueNameReplica.clear();
122
                zPropertyNameReplica.setNameProperty("namereplica");
123
                zPropertyNameReplica.setLabelProperty("Replica Name");
124
                zPropertyNameReplica.setType("noupdateable");
125
                zPropertyNameReplica.setValue("");
126
                zPropertyNameReplica.setPermitValue(null);
127
                zPropertyNameReplica.setMultivalues(null);
128
                zSchedulerProperties.put("namereplica", zPropertyNameReplica);
129

    
130
                Hashtable<Object, Object> permitValueNbReplicas = new Hashtable<Object, Object>();
131
                zProperties zPropertyNbReplicas = new zProperties();
132
                permitValueNbReplicas.clear();
133
                zPropertyNbReplicas.setNameProperty("nbreplica");
134
                zPropertyNbReplicas.setLabelProperty("Number replicas to keep");
135
                zPropertyNbReplicas.setType("freeentry");
136
                zPropertyNbReplicas.setValue("");
137
                zPropertyNbReplicas.setPermitValue(null);
138
                zPropertyNbReplicas.setMultivalues(null);
139
                zSchedulerProperties.put("nbreplica", zPropertyNbReplicas);
140
                
141
                Hashtable<Object, Object> permitValueLastSnapshotReplicated = new Hashtable<Object, Object>();
142
                zProperties zPropertyLastSnapshotReplicated = new zProperties();
143
                permitValueLastSnapshotReplicated.clear();
144
                zPropertyLastSnapshotReplicated.setNameProperty("lastsnapshotreplicated");
145
                zPropertyLastSnapshotReplicated.setLabelProperty("Last Snapshot Replicated");
146
                zPropertyLastSnapshotReplicated.setType("noupdateable");
147
                zPropertyLastSnapshotReplicated.setValue("");
148
                zPropertyLastSnapshotReplicated.setPermitValue(null);
149
                zPropertyLastSnapshotReplicated.setMultivalues(null);
150
                zSchedulerProperties.put("lastsnapshotreplicated", zPropertyLastSnapshotReplicated);
151

    
152
                Hashtable<Object, Object> permitValueMinutesOfSReplicas = new Hashtable<Object, Object>();
153
                zProperties zPropertyMinutesOfSReplicas = new zProperties();
154
                permitValueMinutesOfSReplicas.clear();
155
                zPropertyMinutesOfSReplicas.setNameProperty("minutesofreplicas");
156
                zPropertyMinutesOfSReplicas.setLabelProperty("Minutes of replication [0-60]");
157
                zPropertyMinutesOfSReplicas.setType("nofreeentry");
158
                zPropertyMinutesOfSReplicas.setValue("");
159
                zPropertyMinutesOfSReplicas.setPermitValue(cronMinute);
160
                zPropertyMinutesOfSReplicas.setMultivalues(null);
161
                zSchedulerProperties.put("minutesofreplicas", zPropertyMinutesOfSReplicas);
162

    
163
                Hashtable<Object, Object> permitValueReplicaServer = new Hashtable<Object, Object>();
164
                zProperties zPropertyReplicaServer = new zProperties();
165
                permitValueReplicaServer.clear();
166
                zPropertyReplicaServer.setNameProperty("server");
167
                zPropertyReplicaServer.setLabelProperty("Server For Replication");
168
                zPropertyReplicaServer.setType("nofreeentry");
169
                zPropertyReplicaServer.setValue("");
170
                zPropertyReplicaServer.setPermitValue(null);
171
                zPropertyReplicaServer.setMultivalues(null);
172
                zSchedulerProperties.put("server", zPropertyReplicaServer);
173
                
174
                Hashtable<Object, Object> permitValueReplicaPool = new Hashtable<Object, Object>();
175
                zProperties zPropertyReplicaPool = new zProperties();
176
                permitValueReplicaPool.clear();
177
                zPropertyReplicaPool.setNameProperty("replicapool");
178
                zPropertyReplicaPool.setLabelProperty("Pool For Replication");
179
                zPropertyReplicaPool.setType("nofreeentry");
180
                zPropertyReplicaPool.setValue("");
181
                zPropertyReplicaPool.setPermitValue(null);
182
                zPropertyReplicaPool.setMultivalues(null);
183
                zSchedulerProperties.put("replicapool", zPropertyReplicaPool);
184
                
185
                
186
                Hashtable<Object, Object> permitValueReplicasHours = new Hashtable<Object, Object>();
187
                zProperties zPropertyReplicasHours = new zProperties();
188
                permitValueReplicasHours.clear();
189
                zPropertyReplicasHours.setNameProperty("hoursofreplicas");
190
                zPropertyReplicasHours.setLabelProperty("Hour of replication [0-23]");
191
                zPropertyReplicasHours.setType("nofreeentry");
192
                zPropertyReplicasHours.setValue("");
193
                zPropertyReplicasHours.setPermitValue(cronHour);
194
                zPropertyReplicasHours.setMultivalues(null);
195
                zSchedulerProperties.put("hoursofreplicas", zPropertyReplicasHours);
196

    
197
                Hashtable<Object, Object> permitValueDayOfWeekReplicas = new Hashtable<Object, Object>();
198
                zProperties zPropertyDayOfWeekReplicas = new zProperties();
199
                permitValueDayOfWeekReplicas.clear();
200
                zPropertyDayOfWeekReplicas.setNameProperty("dayofweekreplicas");
201
                zPropertyDayOfWeekReplicas.setLabelProperty("Day of week of Replication [0-6] 0 for Sunday");
202
                zPropertyDayOfWeekReplicas.setType("nofreeentry");
203
                zPropertyDayOfWeekReplicas.setValue("");
204
                zPropertyDayOfWeekReplicas.setPermitValue(cronDayOfWeek);
205
                zPropertyDayOfWeekReplicas.setMultivalues(null);
206
                zSchedulerProperties.put("dayofweekreplicas", zPropertyDayOfWeekReplicas);
207

    
208
                Hashtable<Object, Object> permitValueDayOfMonthReplicas = new Hashtable<Object, Object>();
209
                zProperties zPropertyDayOfMonthReplicas = new zProperties();
210
                permitValueDayOfMonthReplicas.clear();
211
                zPropertyDayOfMonthReplicas.setNameProperty("dayofmonthreplicas");
212
                zPropertyDayOfMonthReplicas.setLabelProperty("Day of Month of Snapshots [1-30]");
213
                zPropertyDayOfMonthReplicas.setType("nofreeentry");
214
                zPropertyDayOfMonthReplicas.setValue("");
215
                zPropertyDayOfMonthReplicas.setPermitValue(cronDayOfMonth);
216
                zPropertyDayOfMonthReplicas.setMultivalues(null);
217
                zSchedulerProperties.put("dayofmonthreplicas", zPropertyDayOfMonthReplicas);
218

    
219
                Hashtable<Object, Object> permitValueMonthReplicas = new Hashtable<Object, Object>();
220
                zProperties zPropertyMonthReplicas = new zProperties();
221
                permitValueMonthReplicas.clear();
222
                zPropertyMonthReplicas.setNameProperty("monthreplicas");
223
                zPropertyMonthReplicas.setLabelProperty("Month");
224
                zPropertyMonthReplicas.setType("nofreeentry");
225
                zPropertyMonthReplicas.setValue("");
226
                zPropertyMonthReplicas.setPermitValue(cronMonth);
227
                zPropertyMonthReplicas.setMultivalues(null);
228
                zSchedulerProperties.put("monthreplicas", zPropertyMonthReplicas);
229

    
230
                /*Hashtable<Object, Object> permitValueFreqSnapshots = new Hashtable<Object, Object>();
231
                zProperties zPropertyFreqSnapshots = new zProperties();
232
                permitValueFreqSnapshots.clear();
233
                zPropertyFreqSnapshots.setNameProperty("frequency");
234
                zPropertyFreqSnapshots.setLabelProperty("Frequency");
235
                zPropertyFreqSnapshots.setType("internaluse");
236
                zPropertyFreqSnapshots.setValue("");
237
                zPropertyFreqSnapshots.setPermitValue(null);
238
                zSchedulerProperties.put("frequency", zPropertyFreqSnapshots);*/
239

    
240

    
241
        }
242

    
243
        public void formatCronValue(String frequency, String DaySnapshot){
244
                String cronValue ="";
245

    
246
                if (frequency.contains("Hours")){
247
                        this.zSchedulerProperties.get("minutesofsnaphots").setValue("*");
248
                        this.zSchedulerProperties.get("hoursofsnaphots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Hours", ""));
249
                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*");
250
                        this.zSchedulerProperties.get("monthsnapshots").setValue("*");
251
                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
252

    
253
                }else{
254
                        this.zSchedulerProperties.get("hour").setValue(this.zSchedulerProperties.get("time").getValue().split(":")[0]);
255
                        this.zSchedulerProperties.get("minutes").setValue(this.zSchedulerProperties.get("time").getValue().split(":")[1]);
256
                        if (frequency.contains("Days")){
257
                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Days", ""));
258
                                this.zSchedulerProperties.get("monthsnapshots").setValue("*");
259
                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
260

    
261
                        }else{
262
                                if (frequency.contains("Months")){
263
                                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue(this.zSchedulerProperties.get("dayofmonthsnapshots").getValue());
264
                                        this.zSchedulerProperties.get("monthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Months", ""));
265
                                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
266

    
267
                                }else{
268
                                        if (frequency.contains("Hour")){
269
                                                this.zSchedulerProperties.get("minutes").setValue("*");
270
                                                this.zSchedulerProperties.get("hours").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Hour", ""));
271
                                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*");
272
                                                this.zSchedulerProperties.get("monthsnapshots").setValue("*");
273
                                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
274
                                        }else{
275
                                                if (frequency.contains("Day")){
276
                                                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Day", ""));
277
                                                        this.zSchedulerProperties.get("monthsnapshots").setValue("*");
278
                                                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
279
                                                }else{
280
                                                        if (frequency.contains("Month")){
281
                                                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue(this.zSchedulerProperties.get("dayofmonthsnapshots").getValue());
282
                                                                this.zSchedulerProperties.get("monthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Month", ""));
283
                                                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
284
                                                        }
285
                                                }
286
                                        }
287
                                }
288
                        }
289
                }
290
        }
291

    
292
        public static int getIntDayOfWeek(String dayOfWeek)  
293
        {  
294
                try   
295
                {   
296
                        DateFormat formatter ;   
297
                        Date date ;   
298
                        formatter = new SimpleDateFormat("EEE");  
299
                        date = (Date)formatter.parse(dayOfWeek);    
300
                        GregorianCalendar g = new GregorianCalendar();  
301
                        g.setTime(date);  
302
                        return g.get(Calendar.DAY_OF_WEEK);  
303
                }   
304
                catch (ParseException e)  
305
                {  
306
                        System.out.println("Exception :"+e);    
307
                }    
308
                return 0;  
309
        }
310
        
311
        
312
        
313
        
314
        
315
}