Statistiques
| Révision :

root / src / gZFS / zsnapshots.java @ 60

Historique | Voir | Annoter | Télécharger (11,32 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.ArrayList;
14
import java.util.Calendar;
15
import java.util.Date;
16
import java.util.GregorianCalendar;
17
import java.util.Hashtable;
18
import java.util.List;
19

    
20

    
21
public class zsnapshots {
22

    
23
        public Hashtable<String,zProperties> zProperties = new Hashtable<String, zProperties>();
24
        public Hashtable<String,zProperties> zSchedulerProperties = new Hashtable<String, zProperties>();
25

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

    
101
                Hashtable<Object, Object> permitValueNameVolFS = new Hashtable<Object, Object>();
102
                zProperties zPropertyNameVolFS = new zProperties();
103
                permitValueNameVolFS.clear();
104
                zPropertyNameVolFS.setNameProperty("name");
105
                zPropertyNameVolFS.setLabelProperty("Snapshot Name");
106
                zPropertyNameVolFS.setType("noupdateable");
107
                zPropertyNameVolFS.setValue("");
108
                zPropertyNameVolFS.setPermitValue(null);
109
                zPropertyNameVolFS.setMultivalues(null);
110
                zSchedulerProperties.put("name", zPropertyNameVolFS);
111
                
112
                Hashtable<Object, Object> permitValueFileConf = new Hashtable<Object, Object>();
113
                zProperties zPropertyFileConf = new zProperties();
114
                permitValueFileConf.clear();
115
                zPropertyFileConf.setNameProperty("fileconf");
116
                zPropertyFileConf.setLabelProperty("Configuration File");
117
                zPropertyFileConf.setType("noupdateable");
118
                zPropertyFileConf.setValue("");
119
                zPropertyFileConf.setPermitValue(null);
120
                zPropertyFileConf.setMultivalues(null);
121
                zSchedulerProperties.put("fileconf", zPropertyFileConf);
122

    
123
                Hashtable<Object, Object> permitValueType = new Hashtable<Object, Object>();
124
                zProperties zPropertyType = new zProperties();
125
                permitValueType.clear();
126
                zPropertyType.setNameProperty("type");
127
                zPropertyType.setLabelProperty("Snapshot Type");
128
                zPropertyType.setType("noupdateable");
129
                zPropertyType.setValue("");
130
                zPropertyType.setPermitValue(null);
131
                zPropertyType.setMultivalues(null);
132
                zSchedulerProperties.put("type", zPropertyType);
133

    
134
                Hashtable<Object, Object> permitValueNbSnapshots = new Hashtable<Object, Object>();
135
                zProperties zPropertyNbSnapshots = new zProperties();
136
                permitValueNbSnapshots.clear();
137
                zPropertyNbSnapshots.setNameProperty("nbsnapshots");
138
                zPropertyNbSnapshots.setLabelProperty("Number Snapshots to keep");
139
                zPropertyNbSnapshots.setType("freeentry");
140
                zPropertyNbSnapshots.setValue("");
141
                zPropertyNbSnapshots.setPermitValue(null);
142
                zPropertyNbSnapshots.setMultivalues(null);
143
                zSchedulerProperties.put("nbsnapshots", zPropertyNbSnapshots);
144

    
145
                Hashtable<Object, Object> permitValueMinutesOfSnapshots = new Hashtable<Object, Object>();
146
                zProperties zPropertyMinutesOfSnapshots = new zProperties();
147
                permitValueMinutesOfSnapshots.clear();
148
                zPropertyMinutesOfSnapshots.setNameProperty("minutesofsnapshots");
149
                zPropertyMinutesOfSnapshots.setLabelProperty("Minutes of snapshots [0-60]");
150
                zPropertyMinutesOfSnapshots.setType("nofreeentry");
151
                zPropertyMinutesOfSnapshots.setValue("");
152
                zPropertyMinutesOfSnapshots.setPermitValue(cronMinute);
153
                zPropertyMinutesOfSnapshots.setMultivalues(null);
154
                zSchedulerProperties.put("minutesofsnapshots", zPropertyMinutesOfSnapshots);
155

    
156
                Hashtable<Object, Object> permitValueSnapshotsHours = new Hashtable<Object, Object>();
157
                zProperties zPropertySnapshotsHours = new zProperties();
158
                permitValueSnapshotsHours.clear();
159
                zPropertySnapshotsHours.setNameProperty("hoursofsnapshots");
160
                zPropertySnapshotsHours.setLabelProperty("Hour of snapshots [0-23]");
161
                zPropertySnapshotsHours.setType("nofreeentry");
162
                zPropertySnapshotsHours.setValue("");
163
                zPropertySnapshotsHours.setPermitValue(cronHour);
164
                zPropertySnapshotsHours.setMultivalues(null);
165
                zSchedulerProperties.put("hoursofsnapshots", zPropertySnapshotsHours);
166

    
167
                Hashtable<Object, Object> permitValueDayOfWeekSnapshots = new Hashtable<Object, Object>();
168
                zProperties zPropertyDayOfWeekSnapshots = new zProperties();
169
                permitValueDayOfWeekSnapshots.clear();
170
                zPropertyDayOfWeekSnapshots.setNameProperty("dayofweeksnapshots");
171
                zPropertyDayOfWeekSnapshots.setLabelProperty("Day of week of Snapshots [0-6] 0 for Sunday");
172
                zPropertyDayOfWeekSnapshots.setType("nofreeentry");
173
                zPropertyDayOfWeekSnapshots.setValue("");
174
                zPropertyDayOfWeekSnapshots.setPermitValue(cronDayOfWeek);
175
                zPropertyDayOfWeekSnapshots.setMultivalues(null);
176
                zSchedulerProperties.put("dayofweeksnapshots", zPropertyDayOfWeekSnapshots);
177

    
178
                Hashtable<Object, Object> permitValueDayOfMonthSnapshots = new Hashtable<Object, Object>();
179
                zProperties zPropertyDayOfMonthSnapshots = new zProperties();
180
                permitValueDayOfMonthSnapshots.clear();
181
                zPropertyDayOfMonthSnapshots.setNameProperty("dayofmonthsnapshots");
182
                zPropertyDayOfMonthSnapshots.setLabelProperty("Day of Month of Snapshots [1-30]");
183
                zPropertyDayOfMonthSnapshots.setType("nofreeentry");
184
                zPropertyDayOfMonthSnapshots.setValue("");
185
                zPropertyDayOfMonthSnapshots.setPermitValue(cronDayOfMonth);
186
                zPropertyDayOfMonthSnapshots.setMultivalues(null);
187
                zSchedulerProperties.put("dayofmonthsnapshots", zPropertyDayOfMonthSnapshots);
188

    
189
                Hashtable<Object, Object> permitValueMonthSnapshots = new Hashtable<Object, Object>();
190
                zProperties zPropertyMonthSnapshots = new zProperties();
191
                permitValueMonthSnapshots.clear();
192
                zPropertyMonthSnapshots.setNameProperty("monthsnapshots");
193
                zPropertyMonthSnapshots.setLabelProperty("Month");
194
                zPropertyMonthSnapshots.setType("nofreeentry");
195
                zPropertyMonthSnapshots.setValue("");
196
                zPropertyMonthSnapshots.setPermitValue(cronMonth);
197
                zPropertyMonthSnapshots.setMultivalues(null);
198
                zSchedulerProperties.put("monthsnapshots", zPropertyMonthSnapshots);
199

    
200
                /*Hashtable<Object, Object> permitValueFreqSnapshots = new Hashtable<Object, Object>();
201
                zProperties zPropertyFreqSnapshots = new zProperties();
202
                permitValueFreqSnapshots.clear();
203
                zPropertyFreqSnapshots.setNameProperty("frequency");
204
                zPropertyFreqSnapshots.setLabelProperty("Frequency");
205
                zPropertyFreqSnapshots.setType("internaluse");
206
                zPropertyFreqSnapshots.setValue("");
207
                zPropertyFreqSnapshots.setPermitValue(null);
208
                zSchedulerProperties.put("frequency", zPropertyFreqSnapshots);*/
209

    
210

    
211
        }
212

    
213
        public void formatCronValue(String frequency, String DaySnapshot){
214
                String cronValue ="";
215

    
216
                if (frequency.contains("Hours")){
217
                        this.zSchedulerProperties.get("minutesofsnaphots").setValue("*");
218
                        this.zSchedulerProperties.get("hoursofsnaphots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Hours", ""));
219
                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*");
220
                        this.zSchedulerProperties.get("monthsnapshots").setValue("*");
221
                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
222

    
223
                }else{
224
                        this.zSchedulerProperties.get("hour").setValue(this.zSchedulerProperties.get("time").getValue().split(":")[0]);
225
                        this.zSchedulerProperties.get("minutes").setValue(this.zSchedulerProperties.get("time").getValue().split(":")[1]);
226
                        if (frequency.contains("Days")){
227
                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Days", ""));
228
                                this.zSchedulerProperties.get("monthsnapshots").setValue("*");
229
                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
230

    
231
                        }else{
232
                                if (frequency.contains("Months")){
233
                                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue(this.zSchedulerProperties.get("dayofmonthsnapshots").getValue());
234
                                        this.zSchedulerProperties.get("monthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Months", ""));
235
                                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
236

    
237
                                }else{
238
                                        if (frequency.contains("Hour")){
239
                                                this.zSchedulerProperties.get("minutes").setValue("*");
240
                                                this.zSchedulerProperties.get("hours").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Hour", ""));
241
                                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*");
242
                                                this.zSchedulerProperties.get("monthsnapshots").setValue("*");
243
                                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
244
                                        }else{
245
                                                if (frequency.contains("Day")){
246
                                                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Day", ""));
247
                                                        this.zSchedulerProperties.get("monthsnapshots").setValue("*");
248
                                                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
249
                                                }else{
250
                                                        if (frequency.contains("Month")){
251
                                                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue(this.zSchedulerProperties.get("dayofmonthsnapshots").getValue());
252
                                                                this.zSchedulerProperties.get("monthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Month", ""));
253
                                                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
254
                                                        }
255
                                                }
256
                                        }
257
                                }
258
                        }
259
                }
260
        }
261

    
262
        public static int getIntDayOfWeek(String dayOfWeek)  
263
        {  
264
                try   
265
                {   
266
                        DateFormat formatter ;   
267
                        Date date ;   
268
                        formatter = new SimpleDateFormat("EEE");  
269
                        date = (Date)formatter.parse(dayOfWeek);    
270
                        GregorianCalendar g = new GregorianCalendar();  
271
                        g.setTime(date);  
272
                        return g.get(Calendar.DAY_OF_WEEK);  
273
                }   
274
                catch (ParseException e)  
275
                {  
276
                        System.out.println("Exception :"+e);    
277
                }    
278
                return 0;  
279
        }
280
}
281