Statistiques
| Révision :

root / src / gZFS / zsnapshots.java @ 60

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

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