Statistiques
| Révision :

root / src / gZFS / zsnapshots.java @ 23

Historique | Voir | Annoter | Télécharger (11,05 ko)

1
package gZFS;
2

    
3
import java.text.DateFormat;
4
import java.text.ParseException;
5
import java.text.SimpleDateFormat;
6
import java.util.ArrayList;
7
import java.util.Calendar;
8
import java.util.Date;
9
import java.util.GregorianCalendar;
10
import java.util.Hashtable;
11
import java.util.List;
12

    
13

    
14
public class zsnapshots {
15

    
16
        public Hashtable<String,zProperties> zProperties = new Hashtable<String, zProperties>();
17
        public Hashtable<String,zProperties> zSchedulerProperties = new Hashtable<String, zProperties>();
18

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

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

    
116
                Hashtable<Object, Object> permitValueType = new Hashtable<Object, Object>();
117
                zProperties zPropertyType = new zProperties();
118
                permitValueType.clear();
119
                zPropertyType.setNameProperty("type");
120
                zPropertyType.setLabelProperty("Snapshot Type");
121
                zPropertyType.setType("noupdateable");
122
                zPropertyType.setValue("");
123
                zPropertyType.setPermitValue(null);
124
                zPropertyType.setMultivalues(null);
125
                zSchedulerProperties.put("type", zPropertyType);
126

    
127
                Hashtable<Object, Object> permitValueNbSnapshots = new Hashtable<Object, Object>();
128
                zProperties zPropertyNbSnapshots = new zProperties();
129
                permitValueNbSnapshots.clear();
130
                zPropertyNbSnapshots.setNameProperty("nbsnapshots");
131
                zPropertyNbSnapshots.setLabelProperty("Number Snapshots to keep");
132
                zPropertyNbSnapshots.setType("freeentry");
133
                zPropertyNbSnapshots.setValue("");
134
                zPropertyNbSnapshots.setPermitValue(null);
135
                zPropertyNbSnapshots.setMultivalues(null);
136
                zSchedulerProperties.put("nbsnapshots", zPropertyNbSnapshots);
137

    
138
                Hashtable<Object, Object> permitValueMinutesOfSnapshots = new Hashtable<Object, Object>();
139
                zProperties zPropertyMinutesOfSnapshots = new zProperties();
140
                permitValueMinutesOfSnapshots.clear();
141
                zPropertyMinutesOfSnapshots.setNameProperty("minutesofsnapshots");
142
                zPropertyMinutesOfSnapshots.setLabelProperty("Minutes of snapshots [0-60]");
143
                zPropertyMinutesOfSnapshots.setType("nofreeentry");
144
                zPropertyMinutesOfSnapshots.setValue("");
145
                zPropertyMinutesOfSnapshots.setPermitValue(cronMinute);
146
                zPropertyMinutesOfSnapshots.setMultivalues(null);
147
                zSchedulerProperties.put("minutesofsnapshots", zPropertyMinutesOfSnapshots);
148

    
149
                Hashtable<Object, Object> permitValueSnapshotsHours = new Hashtable<Object, Object>();
150
                zProperties zPropertySnapshotsHours = new zProperties();
151
                permitValueSnapshotsHours.clear();
152
                zPropertySnapshotsHours.setNameProperty("hoursofsnapshots");
153
                zPropertySnapshotsHours.setLabelProperty("Hour of snapshots [0-23]");
154
                zPropertySnapshotsHours.setType("nofreeentry");
155
                zPropertySnapshotsHours.setValue("");
156
                zPropertySnapshotsHours.setPermitValue(cronHour);
157
                zPropertySnapshotsHours.setMultivalues(null);
158
                zSchedulerProperties.put("hoursofsnapshots", zPropertySnapshotsHours);
159

    
160
                Hashtable<Object, Object> permitValueDayOfWeekSnapshots = new Hashtable<Object, Object>();
161
                zProperties zPropertyDayOfWeekSnapshots = new zProperties();
162
                permitValueDayOfWeekSnapshots.clear();
163
                zPropertyDayOfWeekSnapshots.setNameProperty("dayofweeksnapshots");
164
                zPropertyDayOfWeekSnapshots.setLabelProperty("Day of week of Snapshots [0-6] 0 for Sunday");
165
                zPropertyDayOfWeekSnapshots.setType("nofreeentry");
166
                zPropertyDayOfWeekSnapshots.setValue("");
167
                zPropertyDayOfWeekSnapshots.setPermitValue(cronDayOfWeek);
168
                zPropertyDayOfWeekSnapshots.setMultivalues(null);
169
                zSchedulerProperties.put("dayofweeksnapshots", zPropertyDayOfWeekSnapshots);
170

    
171
                Hashtable<Object, Object> permitValueDayOfMonthSnapshots = new Hashtable<Object, Object>();
172
                zProperties zPropertyDayOfMonthSnapshots = new zProperties();
173
                permitValueDayOfMonthSnapshots.clear();
174
                zPropertyDayOfMonthSnapshots.setNameProperty("dayofmonthsnapshots");
175
                zPropertyDayOfMonthSnapshots.setLabelProperty("Day of Month of Snapshots [1-30]");
176
                zPropertyDayOfMonthSnapshots.setType("nofreeentry");
177
                zPropertyDayOfMonthSnapshots.setValue("");
178
                zPropertyDayOfMonthSnapshots.setPermitValue(cronDayOfMonth);
179
                zPropertyDayOfMonthSnapshots.setMultivalues(null);
180
                zSchedulerProperties.put("dayofmonthsnapshots", zPropertyDayOfMonthSnapshots);
181

    
182
                Hashtable<Object, Object> permitValueMonthSnapshots = new Hashtable<Object, Object>();
183
                zProperties zPropertyMonthSnapshots = new zProperties();
184
                permitValueMonthSnapshots.clear();
185
                zPropertyMonthSnapshots.setNameProperty("monthsnapshots");
186
                zPropertyMonthSnapshots.setLabelProperty("Month");
187
                zPropertyMonthSnapshots.setType("nofreeentry");
188
                zPropertyMonthSnapshots.setValue("");
189
                zPropertyMonthSnapshots.setPermitValue(cronMonth);
190
                zPropertyMonthSnapshots.setMultivalues(null);
191
                zSchedulerProperties.put("monthsnapshots", zPropertyMonthSnapshots);
192

    
193
                /*Hashtable<Object, Object> permitValueFreqSnapshots = new Hashtable<Object, Object>();
194
                zProperties zPropertyFreqSnapshots = new zProperties();
195
                permitValueFreqSnapshots.clear();
196
                zPropertyFreqSnapshots.setNameProperty("frequency");
197
                zPropertyFreqSnapshots.setLabelProperty("Frequency");
198
                zPropertyFreqSnapshots.setType("internaluse");
199
                zPropertyFreqSnapshots.setValue("");
200
                zPropertyFreqSnapshots.setPermitValue(null);
201
                zSchedulerProperties.put("frequency", zPropertyFreqSnapshots);*/
202

    
203

    
204
        }
205

    
206
        public void formatCronValue(String frequency, String DaySnapshot){
207
                String cronValue ="";
208

    
209
                if (frequency.contains("Hours")){
210
                        this.zSchedulerProperties.get("minutesofsnaphots").setValue("*");
211
                        this.zSchedulerProperties.get("hoursofsnaphots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Hours", ""));
212
                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*");
213
                        this.zSchedulerProperties.get("monthsnapshots").setValue("*");
214
                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
215

    
216
                }else{
217
                        this.zSchedulerProperties.get("hour").setValue(this.zSchedulerProperties.get("time").getValue().split(":")[0]);
218
                        this.zSchedulerProperties.get("minutes").setValue(this.zSchedulerProperties.get("time").getValue().split(":")[1]);
219
                        if (frequency.contains("Days")){
220
                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Days", ""));
221
                                this.zSchedulerProperties.get("monthsnapshots").setValue("*");
222
                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
223

    
224
                        }else{
225
                                if (frequency.contains("Months")){
226
                                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue(this.zSchedulerProperties.get("dayofmonthsnapshots").getValue());
227
                                        this.zSchedulerProperties.get("monthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Months", ""));
228
                                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
229

    
230
                                }else{
231
                                        if (frequency.contains("Hour")){
232
                                                this.zSchedulerProperties.get("minutes").setValue("*");
233
                                                this.zSchedulerProperties.get("hours").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Hour", ""));
234
                                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*");
235
                                                this.zSchedulerProperties.get("monthsnapshots").setValue("*");
236
                                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
237
                                        }else{
238
                                                if (frequency.contains("Day")){
239
                                                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Day", ""));
240
                                                        this.zSchedulerProperties.get("monthsnapshots").setValue("*");
241
                                                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
242
                                                }else{
243
                                                        if (frequency.contains("Month")){
244
                                                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue(this.zSchedulerProperties.get("dayofmonthsnapshots").getValue());
245
                                                                this.zSchedulerProperties.get("monthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Month", ""));
246
                                                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
247
                                                        }
248
                                                }
249
                                        }
250
                                }
251
                        }
252
                }
253
        }
254

    
255
        public static int getIntDayOfWeek(String dayOfWeek)  
256
        {  
257
                try   
258
                {   
259
                        DateFormat formatter ;   
260
                        Date date ;   
261
                        formatter = new SimpleDateFormat("EEE");  
262
                        date = (Date)formatter.parse(dayOfWeek);    
263
                        GregorianCalendar g = new GregorianCalendar();  
264
                        g.setTime(date);  
265
                        return g.get(Calendar.DAY_OF_WEEK);  
266
                }   
267
                catch (ParseException e)  
268
                {  
269
                        System.out.println("Exception :"+e);    
270
                }    
271
                return 0;  
272
        }
273
}
274