Statistiques
| Révision :

root / src / gZFS / zsnapshots.java @ 14

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

1 14 kreverch
package gZFS;
2 14 kreverch
3 14 kreverch
import java.text.DateFormat;
4 14 kreverch
import java.text.ParseException;
5 14 kreverch
import java.text.SimpleDateFormat;
6 14 kreverch
import java.util.ArrayList;
7 14 kreverch
import java.util.Calendar;
8 14 kreverch
import java.util.Date;
9 14 kreverch
import java.util.GregorianCalendar;
10 14 kreverch
import java.util.Hashtable;
11 14 kreverch
import java.util.List;
12 14 kreverch
13 14 kreverch
14 14 kreverch
public class zsnapshots {
15 14 kreverch
16 14 kreverch
        public Hashtable<String,zProperties> zProperties = new Hashtable<String, zProperties>();
17 14 kreverch
        public Hashtable<String,zProperties> zSchedulerProperties = new Hashtable<String, zProperties>();
18 14 kreverch
19 14 kreverch
        private Hashtable<Object, Object> cronMinute = new Hashtable<Object, Object>();
20 14 kreverch
        private Hashtable<Object, Object> cronHour= new Hashtable<Object, Object>();
21 14 kreverch
        private Hashtable<Object, Object> cronMonth= new Hashtable<Object, Object>();
22 14 kreverch
        private Hashtable<Object, Object> cronDayOfMonth = new Hashtable<Object, Object>();
23 14 kreverch
        private Hashtable<Object, Object> cronDayOfWeek = new Hashtable<Object, Object>();
24 14 kreverch
25 14 kreverch
        zsnapshots(){
26 14 kreverch
                String valueForHash = null;
27 14 kreverch
                for (int i=1;i<61;i++){
28 14 kreverch
29 14 kreverch
                        if ( i<10){
30 14 kreverch
                                valueForHash="0"+String.valueOf(i);
31 14 kreverch
                        }else{
32 14 kreverch
                                valueForHash=String.valueOf(i);
33 14 kreverch
                        }
34 14 kreverch
                        cronMinute.put(String.valueOf(i), valueForHash);
35 14 kreverch
                        if ( i ==1){
36 14 kreverch
                                cronMinute.put("*", "All");
37 14 kreverch
                        }else{
38 14 kreverch
                                cronMinute.put("*/"+i, "Every "+valueForHash+" Minutes");
39 14 kreverch
                        }
40 14 kreverch
                }
41 14 kreverch
42 14 kreverch
                for (int i=0;i<24;i++){
43 14 kreverch
                        if ( i<10){
44 14 kreverch
                                valueForHash="0"+String.valueOf(i);
45 14 kreverch
                        }else{
46 14 kreverch
                                valueForHash=String.valueOf(i);
47 14 kreverch
                        }
48 14 kreverch
                        cronHour.put(String.valueOf(i), valueForHash);
49 14 kreverch
                        if ( i ==1){
50 14 kreverch
                                cronHour.put("*", "All");
51 14 kreverch
                        }else{
52 14 kreverch
                                cronHour.put("*/"+i, "Every "+valueForHash+" Hours");
53 14 kreverch
                        }
54 14 kreverch
                }
55 14 kreverch
56 14 kreverch
                cronMonth.put("01", "January");
57 14 kreverch
                cronMonth.put("02", "February");
58 14 kreverch
                cronMonth.put("03", "March");
59 14 kreverch
                cronMonth.put("04", "April");
60 14 kreverch
                cronMonth.put("05", "May");
61 14 kreverch
                cronMonth.put("06", "June");
62 14 kreverch
                cronMonth.put("07", "July");
63 14 kreverch
                cronMonth.put("08", "August");
64 14 kreverch
                cronMonth.put("09", "September");
65 14 kreverch
                cronMonth.put("10", "October");
66 14 kreverch
                cronMonth.put("11", "November");
67 14 kreverch
                cronMonth.put("12", "December");
68 14 kreverch
                cronMonth.put("*", "All");
69 14 kreverch
70 14 kreverch
                cronDayOfWeek.put("0", "Sunday");
71 14 kreverch
                cronDayOfWeek.put("1", "Monday");
72 14 kreverch
                cronDayOfWeek.put("2", "Tuesday");
73 14 kreverch
                cronDayOfWeek.put("3", "Wednesday");
74 14 kreverch
                cronDayOfWeek.put("4", "Thursday");
75 14 kreverch
                cronDayOfWeek.put("5", "Friday");
76 14 kreverch
                cronDayOfWeek.put("6", "Saturday");
77 14 kreverch
                cronDayOfWeek.put("*", "All");
78 14 kreverch
79 14 kreverch
80 14 kreverch
                for (int i=1;i<31;i++){
81 14 kreverch
                        if ( i<10){
82 14 kreverch
                                valueForHash="0"+String.valueOf(i);
83 14 kreverch
                        }else{
84 14 kreverch
                                valueForHash=String.valueOf(i);
85 14 kreverch
                        }
86 14 kreverch
                        cronDayOfMonth.put(String.valueOf(i), valueForHash);
87 14 kreverch
                        if ( i ==1){
88 14 kreverch
                                cronDayOfMonth.put("*", "All");
89 14 kreverch
                        }else{
90 14 kreverch
                                cronDayOfMonth.put("*/"+i, "Every "+valueForHash+" Days");
91 14 kreverch
                        }
92 14 kreverch
                }
93 14 kreverch
94 14 kreverch
                Hashtable<Object, Object> permitValueNameVolFS = new Hashtable<Object, Object>();
95 14 kreverch
                zProperties zPropertyNameVolFS = new zProperties();
96 14 kreverch
                permitValueNameVolFS.clear();
97 14 kreverch
                zPropertyNameVolFS.setNameProperty("name");
98 14 kreverch
                zPropertyNameVolFS.setLabelProperty("Snapshot Name");
99 14 kreverch
                zPropertyNameVolFS.setType("noupdateable");
100 14 kreverch
                zPropertyNameVolFS.setValue("");
101 14 kreverch
                zPropertyNameVolFS.setPermitValue(null);
102 14 kreverch
                zPropertyNameVolFS.setMultivalues(null);
103 14 kreverch
                zSchedulerProperties.put("name", zPropertyNameVolFS);
104 14 kreverch
105 14 kreverch
                Hashtable<Object, Object> permitValueFileConf = new Hashtable<Object, Object>();
106 14 kreverch
                zProperties zPropertyFileConf = new zProperties();
107 14 kreverch
                permitValueFileConf.clear();
108 14 kreverch
                zPropertyFileConf.setNameProperty("fileconf");
109 14 kreverch
                zPropertyFileConf.setLabelProperty("Configuration File");
110 14 kreverch
                zPropertyFileConf.setType("noupdateable");
111 14 kreverch
                zPropertyFileConf.setValue("");
112 14 kreverch
                zPropertyFileConf.setPermitValue(null);
113 14 kreverch
                zPropertyFileConf.setMultivalues(null);
114 14 kreverch
                zSchedulerProperties.put("fileconf", zPropertyFileConf);
115 14 kreverch
116 14 kreverch
                Hashtable<Object, Object> permitValueType = new Hashtable<Object, Object>();
117 14 kreverch
                zProperties zPropertyType = new zProperties();
118 14 kreverch
                permitValueType.clear();
119 14 kreverch
                zPropertyType.setNameProperty("type");
120 14 kreverch
                zPropertyType.setLabelProperty("Snapshot Type");
121 14 kreverch
                zPropertyType.setType("noupdateable");
122 14 kreverch
                zPropertyType.setValue("");
123 14 kreverch
                zPropertyType.setPermitValue(null);
124 14 kreverch
                zPropertyType.setMultivalues(null);
125 14 kreverch
                zSchedulerProperties.put("type", zPropertyType);
126 14 kreverch
127 14 kreverch
                Hashtable<Object, Object> permitValueNbSnapshots = new Hashtable<Object, Object>();
128 14 kreverch
                zProperties zPropertyNbSnapshots = new zProperties();
129 14 kreverch
                permitValueNbSnapshots.clear();
130 14 kreverch
                zPropertyNbSnapshots.setNameProperty("nbsnapshots");
131 14 kreverch
                zPropertyNbSnapshots.setLabelProperty("Number Snapshots to keep");
132 14 kreverch
                zPropertyNbSnapshots.setType("freeentry");
133 14 kreverch
                zPropertyNbSnapshots.setValue("");
134 14 kreverch
                zPropertyNbSnapshots.setPermitValue(null);
135 14 kreverch
                zPropertyNbSnapshots.setMultivalues(null);
136 14 kreverch
                zSchedulerProperties.put("nbsnapshots", zPropertyNbSnapshots);
137 14 kreverch
138 14 kreverch
                Hashtable<Object, Object> permitValueMinutesOfSnapshots = new Hashtable<Object, Object>();
139 14 kreverch
                zProperties zPropertyMinutesOfSnapshots = new zProperties();
140 14 kreverch
                permitValueMinutesOfSnapshots.clear();
141 14 kreverch
                zPropertyMinutesOfSnapshots.setNameProperty("minutesofsnapshots");
142 14 kreverch
                zPropertyMinutesOfSnapshots.setLabelProperty("Minutes of snapshots [0-60]");
143 14 kreverch
                zPropertyMinutesOfSnapshots.setType("nofreeentry");
144 14 kreverch
                zPropertyMinutesOfSnapshots.setValue("");
145 14 kreverch
                zPropertyMinutesOfSnapshots.setPermitValue(cronMinute);
146 14 kreverch
                zPropertyMinutesOfSnapshots.setMultivalues(null);
147 14 kreverch
                zSchedulerProperties.put("minutesofsnapshots", zPropertyMinutesOfSnapshots);
148 14 kreverch
149 14 kreverch
                Hashtable<Object, Object> permitValueSnapshotsHours = new Hashtable<Object, Object>();
150 14 kreverch
                zProperties zPropertySnapshotsHours = new zProperties();
151 14 kreverch
                permitValueSnapshotsHours.clear();
152 14 kreverch
                zPropertySnapshotsHours.setNameProperty("hoursofsnapshots");
153 14 kreverch
                zPropertySnapshotsHours.setLabelProperty("Hour of snapshots [0-23]");
154 14 kreverch
                zPropertySnapshotsHours.setType("nofreeentry");
155 14 kreverch
                zPropertySnapshotsHours.setValue("");
156 14 kreverch
                zPropertySnapshotsHours.setPermitValue(cronHour);
157 14 kreverch
                zPropertySnapshotsHours.setMultivalues(null);
158 14 kreverch
                zSchedulerProperties.put("hoursofsnapshots", zPropertySnapshotsHours);
159 14 kreverch
160 14 kreverch
                Hashtable<Object, Object> permitValueDayOfWeekSnapshots = new Hashtable<Object, Object>();
161 14 kreverch
                zProperties zPropertyDayOfWeekSnapshots = new zProperties();
162 14 kreverch
                permitValueDayOfWeekSnapshots.clear();
163 14 kreverch
                zPropertyDayOfWeekSnapshots.setNameProperty("dayofweeksnapshots");
164 14 kreverch
                zPropertyDayOfWeekSnapshots.setLabelProperty("Day of week of Snapshots [0-6] 0 for Sunday");
165 14 kreverch
                zPropertyDayOfWeekSnapshots.setType("nofreeentry");
166 14 kreverch
                zPropertyDayOfWeekSnapshots.setValue("");
167 14 kreverch
                zPropertyDayOfWeekSnapshots.setPermitValue(cronDayOfWeek);
168 14 kreverch
                zPropertyDayOfWeekSnapshots.setMultivalues(null);
169 14 kreverch
                zSchedulerProperties.put("dayofweeksnapshots", zPropertyDayOfWeekSnapshots);
170 14 kreverch
171 14 kreverch
                Hashtable<Object, Object> permitValueDayOfMonthSnapshots = new Hashtable<Object, Object>();
172 14 kreverch
                zProperties zPropertyDayOfMonthSnapshots = new zProperties();
173 14 kreverch
                permitValueDayOfMonthSnapshots.clear();
174 14 kreverch
                zPropertyDayOfMonthSnapshots.setNameProperty("dayofmonthsnapshots");
175 14 kreverch
                zPropertyDayOfMonthSnapshots.setLabelProperty("Day of Month of Snapshots [1-30]");
176 14 kreverch
                zPropertyDayOfMonthSnapshots.setType("nofreeentry");
177 14 kreverch
                zPropertyDayOfMonthSnapshots.setValue("");
178 14 kreverch
                zPropertyDayOfMonthSnapshots.setPermitValue(cronDayOfMonth);
179 14 kreverch
                zPropertyDayOfMonthSnapshots.setMultivalues(null);
180 14 kreverch
                zSchedulerProperties.put("dayofmonthsnapshots", zPropertyDayOfMonthSnapshots);
181 14 kreverch
182 14 kreverch
                Hashtable<Object, Object> permitValueMonthSnapshots = new Hashtable<Object, Object>();
183 14 kreverch
                zProperties zPropertyMonthSnapshots = new zProperties();
184 14 kreverch
                permitValueMonthSnapshots.clear();
185 14 kreverch
                zPropertyMonthSnapshots.setNameProperty("monthsnapshots");
186 14 kreverch
                zPropertyMonthSnapshots.setLabelProperty("Month");
187 14 kreverch
                zPropertyMonthSnapshots.setType("nofreeentry");
188 14 kreverch
                zPropertyMonthSnapshots.setValue("");
189 14 kreverch
                zPropertyMonthSnapshots.setPermitValue(cronMonth);
190 14 kreverch
                zPropertyMonthSnapshots.setMultivalues(null);
191 14 kreverch
                zSchedulerProperties.put("monthsnapshots", zPropertyMonthSnapshots);
192 14 kreverch
193 14 kreverch
                /*Hashtable<Object, Object> permitValueFreqSnapshots = new Hashtable<Object, Object>();
194 14 kreverch
                zProperties zPropertyFreqSnapshots = new zProperties();
195 14 kreverch
                permitValueFreqSnapshots.clear();
196 14 kreverch
                zPropertyFreqSnapshots.setNameProperty("frequency");
197 14 kreverch
                zPropertyFreqSnapshots.setLabelProperty("Frequency");
198 14 kreverch
                zPropertyFreqSnapshots.setType("internaluse");
199 14 kreverch
                zPropertyFreqSnapshots.setValue("");
200 14 kreverch
                zPropertyFreqSnapshots.setPermitValue(null);
201 14 kreverch
                zSchedulerProperties.put("frequency", zPropertyFreqSnapshots);*/
202 14 kreverch
203 14 kreverch
204 14 kreverch
        }
205 14 kreverch
206 14 kreverch
        public void formatCronValue(String frequency, String DaySnapshot){
207 14 kreverch
                String cronValue ="";
208 14 kreverch
209 14 kreverch
                if (frequency.contains("Hours")){
210 14 kreverch
                        this.zSchedulerProperties.get("minutesofsnaphots").setValue("*");
211 14 kreverch
                        this.zSchedulerProperties.get("hoursofsnaphots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Hours", ""));
212 14 kreverch
                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*");
213 14 kreverch
                        this.zSchedulerProperties.get("monthsnapshots").setValue("*");
214 14 kreverch
                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
215 14 kreverch
216 14 kreverch
                }else{
217 14 kreverch
                        this.zSchedulerProperties.get("hour").setValue(this.zSchedulerProperties.get("time").getValue().split(":")[0]);
218 14 kreverch
                        this.zSchedulerProperties.get("minutes").setValue(this.zSchedulerProperties.get("time").getValue().split(":")[1]);
219 14 kreverch
                        if (frequency.contains("Days")){
220 14 kreverch
                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Days", ""));
221 14 kreverch
                                this.zSchedulerProperties.get("monthsnapshots").setValue("*");
222 14 kreverch
                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
223 14 kreverch
224 14 kreverch
                        }else{
225 14 kreverch
                                if (frequency.contains("Months")){
226 14 kreverch
                                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue(this.zSchedulerProperties.get("dayofmonthsnapshots").getValue());
227 14 kreverch
                                        this.zSchedulerProperties.get("monthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Months", ""));
228 14 kreverch
                                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
229 14 kreverch
230 14 kreverch
                                }else{
231 14 kreverch
                                        if (frequency.contains("Hour")){
232 14 kreverch
                                                this.zSchedulerProperties.get("minutes").setValue("*");
233 14 kreverch
                                                this.zSchedulerProperties.get("hours").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Hour", ""));
234 14 kreverch
                                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*");
235 14 kreverch
                                                this.zSchedulerProperties.get("monthsnapshots").setValue("*");
236 14 kreverch
                                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
237 14 kreverch
                                        }else{
238 14 kreverch
                                                if (frequency.contains("Day")){
239 14 kreverch
                                                        this.zSchedulerProperties.get("dayofmonthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Day", ""));
240 14 kreverch
                                                        this.zSchedulerProperties.get("monthsnapshots").setValue("*");
241 14 kreverch
                                                        this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
242 14 kreverch
                                                }else{
243 14 kreverch
                                                        if (frequency.contains("Month")){
244 14 kreverch
                                                                this.zSchedulerProperties.get("dayofmonthsnapshots").setValue(this.zSchedulerProperties.get("dayofmonthsnapshots").getValue());
245 14 kreverch
                                                                this.zSchedulerProperties.get("monthsnapshots").setValue("*/"+frequency.replaceAll("Every", "").replaceAll("Month", ""));
246 14 kreverch
                                                                this.zSchedulerProperties.get("dayofweeksnapshots").setValue("*");
247 14 kreverch
                                                        }
248 14 kreverch
                                                }
249 14 kreverch
                                        }
250 14 kreverch
                                }
251 14 kreverch
                        }
252 14 kreverch
                }
253 14 kreverch
        }
254 14 kreverch
255 14 kreverch
        public static int getIntDayOfWeek(String dayOfWeek)
256 14 kreverch
        {
257 14 kreverch
                try
258 14 kreverch
                {
259 14 kreverch
                        DateFormat formatter ;
260 14 kreverch
                        Date date ;
261 14 kreverch
                        formatter = new SimpleDateFormat("EEE");
262 14 kreverch
                        date = (Date)formatter.parse(dayOfWeek);
263 14 kreverch
                        GregorianCalendar g = new GregorianCalendar();
264 14 kreverch
                        g.setTime(date);
265 14 kreverch
                        return g.get(Calendar.DAY_OF_WEEK);
266 14 kreverch
                }
267 14 kreverch
                catch (ParseException e)
268 14 kreverch
                {
269 14 kreverch
                        System.out.println("Exception :"+e);
270 14 kreverch
                }
271 14 kreverch
                return 0;
272 14 kreverch
        }
273 14 kreverch
}