Statistiques
| Révision :

root / src / gZFS / zfs.java @ 24

Historique | Voir | Annoter | Télécharger (54,99 ko)

1 14 kreverch
package gZFS;
2 14 kreverch
3 14 kreverch
import java.io.BufferedReader;
4 14 kreverch
import java.io.File;
5 14 kreverch
import java.io.FileInputStream;
6 14 kreverch
import java.io.FileNotFoundException;
7 14 kreverch
import java.io.IOException;
8 14 kreverch
import java.io.InputStream;
9 14 kreverch
import java.io.InputStreamReader;
10 14 kreverch
import java.io.OutputStream;
11 14 kreverch
import java.net.URL;
12 14 kreverch
import java.text.ParseException;
13 14 kreverch
import java.text.SimpleDateFormat;
14 14 kreverch
import java.util.ArrayList;
15 14 kreverch
import java.util.Arrays;
16 14 kreverch
import java.util.Hashtable;
17 14 kreverch
import java.util.List;
18 14 kreverch
import java.util.Properties;
19 14 kreverch
20 14 kreverch
import org.apache.log4j.Level;
21 14 kreverch
import org.apache.log4j.Logger;
22 14 kreverch
import org.jfree.util.Log;
23 14 kreverch
24 14 kreverch
import com.ibm.icu.math.BigDecimal;
25 14 kreverch
import com.jcraft.jsch.ChannelExec;
26 14 kreverch
import com.jcraft.jsch.JSch;
27 14 kreverch
import com.jcraft.jsch.JSchException;
28 14 kreverch
import com.jcraft.jsch.Session;
29 14 kreverch
30 14 kreverch
public class zfs {
31 14 kreverch
32 14 kreverch
33 14 kreverch
        private Logger log = Logger.getLogger(getClass().getPackage().getName()+" "+getClass().getCanonicalName());
34 14 kreverch
35 14 kreverch
        private String userLogin;
36 14 kreverch
        private String userPassword;
37 14 kreverch
        private String sshHost;
38 14 kreverch
        private int sshPort;
39 14 kreverch
        private Session session;
40 14 kreverch
        private Hashtable<String,Session> cacheSession = new Hashtable<String, Session>();
41 14 kreverch
        private JSch jsch = new JSch();
42 14 kreverch
        private String outCmd = null ;
43 14 kreverch
        private StringBuilder outErr ;
44 14 kreverch
        private List<Object> zpoolList = new ArrayList<Object>();
45 14 kreverch
        private List<Object> zfsList = new ArrayList<Object>();
46 14 kreverch
        private List<Object> zfsListSnapshots = new ArrayList<Object>();
47 14 kreverch
        private List<Object> zfsGetAllList = new ArrayList<Object>();
48 14 kreverch
        private List<Object> iscsiListConfigVol = new ArrayList<Object>();
49 14 kreverch
        private Hashtable<String,Object> modelZfsVolAndFS = new Hashtable<String, Object>();
50 14 kreverch
        private Hashtable<String,Object> error = new Hashtable<String, Object>();
51 14 kreverch
        private Hashtable<String,zdisk> hashDisks = new Hashtable<String, zdisk>();
52 14 kreverch
        private Hashtable<String,zraid> hashZRaid = new Hashtable<String, zraid>();
53 14 kreverch
54 14 kreverch
        private zpool zpool;
55 14 kreverch
        private zserver zserver;
56 14 kreverch
        private zvol zvol ;
57 14 kreverch
        private zsnapshots zsnapshots;
58 14 kreverch
        private zreplicas zreplicas;
59 14 kreverch
        private ziscsi ziscsi;
60 14 kreverch
        private zdisk zdisk;
61 14 kreverch
        private zraid zraid;
62 14 kreverch
        private List<Object> sidList;
63 14 kreverch
        private List<Object> ipList;
64 14 kreverch
        private Properties prop = new Properties();
65 14 kreverch
        zfs(){
66 14 kreverch
                this.loadConfig();
67 14 kreverch
                this.setZserver();
68 14 kreverch
                this.setZpool();
69 14 kreverch
                this.setZdisk();
70 14 kreverch
                this.setZvol();
71 14 kreverch
                this.setZsnapshots();
72 14 kreverch
                this.setZreplicas();
73 14 kreverch
                this.setZiscsi();
74 14 kreverch
                this.setZraid();
75 14 kreverch
                log.setLevel((Level) Level.DEBUG);
76 14 kreverch
        }
77 14 kreverch
78 14 kreverch
        public void setZvol(){
79 14 kreverch
                zvol= new zvol();
80 14 kreverch
        }
81 14 kreverch
82 14 kreverch
        public gZFS.zvol getZvol(){
83 14 kreverch
                return zvol;
84 14 kreverch
        }
85 14 kreverch
86 14 kreverch
        public boolean connectServer(String host, int port, String userLogin, String userPasswd){
87 14 kreverch
                try {
88 14 kreverch
                        setSession(jsch.getSession(userLogin, host, port));
89 14 kreverch
                        session.setPassword(userPasswd);
90 14 kreverch
                        Properties config = new Properties();
91 14 kreverch
                        config.put("StrictHostKeyChecking", "no");
92 14 kreverch
                        session.setConfig(config);
93 14 kreverch
                        session.connect();
94 14 kreverch
                        getCacheSession().put(host, session);
95 14 kreverch
                        if ( session.isConnected()){
96 14 kreverch
                                log.debug("Connected");
97 14 kreverch
                                return true;
98 14 kreverch
                        }else{
99 14 kreverch
                                log.debug("not Connected");
100 14 kreverch
                                return false;
101 14 kreverch
                        }
102 14 kreverch
103 14 kreverch
                } catch (JSchException e) {
104 14 kreverch
                        // TODO Auto-generated catch block
105 14 kreverch
                        e.printStackTrace();
106 14 kreverch
                        return false;
107 14 kreverch
                }
108 14 kreverch
        }
109 14 kreverch
110 14 kreverch
        public void disconnectServer(){
111 14 kreverch
                String[] keysProp = (String[]) this.getCacheSession().keySet().toArray(new String[0]);
112 14 kreverch
                Arrays.sort(keysProp);
113 14 kreverch
                for ( int i=0;i<keysProp.length;i++){
114 14 kreverch
                        String keyProp = keysProp[i];
115 14 kreverch
                        this.setSession(getCacheSession().get(keyProp));
116 14 kreverch
                        session.disconnect();
117 14 kreverch
                }
118 14 kreverch
        }
119 14 kreverch
120 14 kreverch
121 14 kreverch
        public Boolean executeCmd(String cmd) {
122 14 kreverch
                this.setOutCmd("");
123 14 kreverch
                try {
124 14 kreverch
125 14 kreverch
                        this.setSession(getCacheSession().get(this.getZserver().zProperties.get("serverIP").getValue()));
126 14 kreverch
                        log.debug("executeCMD : "+this.getZserver().zProperties.get("serverIP").getValue());
127 14 kreverch
                        ChannelExec channel = (ChannelExec) session.openChannel("exec");
128 14 kreverch
                        //((ChannelExec) channel).setCommand("lqs");
129 14 kreverch
                        ((ChannelExec) channel).setCommand(cmd);
130 14 kreverch
                        InputStream in = channel.getInputStream();
131 14 kreverch
                        OutputStream out = channel.getOutputStream();
132 14 kreverch
                        ((ChannelExec) channel).setErrStream(System.err);
133 14 kreverch
                        InputStream err = channel.getErrStream();
134 14 kreverch
                        channel.connect();
135 14 kreverch
                        log.debug("executeCmd "+cmd);
136 14 kreverch
                        BufferedReader reader = new BufferedReader(new InputStreamReader(err));
137 14 kreverch
                        outErr = new StringBuilder();
138 14 kreverch
                        String line;
139 14 kreverch
                        while ((line = reader.readLine()) != null) {
140 14 kreverch
                                outErr.append(line);
141 14 kreverch
                        }
142 24 kreverch
                        byte[] tmp = new byte[4096];
143 14 kreverch
144 14 kreverch
                        while (true) {
145 14 kreverch
146 14 kreverch
                                int ind = 0;
147 14 kreverch
                                while (in.available() > 0) {
148 24 kreverch
                                        int i = in.read(tmp, 0, 4096);
149 14 kreverch
                                        if (i < 0)
150 14 kreverch
                                                break;
151 14 kreverch
152 14 kreverch
                                        this.setOutCmd(this.getOutCmd()+new String(tmp, 0, i));
153 14 kreverch
                                }
154 14 kreverch
                                if (channel.isClosed()) {
155 14 kreverch
                                        break;
156 14 kreverch
                                }
157 14 kreverch
                                try {
158 14 kreverch
                                        Thread.sleep(900);
159 14 kreverch
                                } catch (Exception ee) {
160 14 kreverch
                                        log.debug(ee);
161 14 kreverch
                                }
162 14 kreverch
                        }
163 14 kreverch
                        channel.disconnect();
164 14 kreverch
165 14 kreverch
                } catch (JSchException e) {
166 14 kreverch
                        // TODO Auto-generated catch block
167 14 kreverch
                        log.debug("executeCMD "+e.getMessage());
168 14 kreverch
                        e.printStackTrace();
169 14 kreverch
                        return false;
170 14 kreverch
                } catch (IOException e) {
171 14 kreverch
                        // TODO Auto-generated catch block
172 14 kreverch
                        log.debug("executeCmd "+e.getMessage());
173 14 kreverch
                        e.printStackTrace();
174 14 kreverch
                        return false;
175 14 kreverch
                }
176 14 kreverch
                /*for (int cpt=0;cpt < outCmd.length;cpt++ ) {
177 14 kreverch
                        log.debug(outCmd[cpt]);
178 14 kreverch
                }*/
179 14 kreverch
                //log.debug(this.getOutCmd());
180 14 kreverch
                return true;
181 14 kreverch
        }
182 14 kreverch
183 14 kreverch
        public Boolean zfsGetAllVolume(String volName){
184 14 kreverch
                zfsGetAllList.clear();
185 14 kreverch
                //clear this.getZvol properties
186 14 kreverch
                String[] keysProp = (String[]) this.getZvol().zProperties.keySet().toArray(new String[0]);
187 14 kreverch
                Arrays.sort(keysProp);
188 14 kreverch
                for ( int i=0;i<keysProp.length;i++){
189 14 kreverch
                        String keyProp = keysProp[i];
190 14 kreverch
                        this.getZvol().zProperties.get(keyProp).setMultivalues(null);
191 14 kreverch
                        this.getZvol().zProperties.get(keyProp).setValue("");;
192 14 kreverch
193 14 kreverch
                }
194 14 kreverch
                if (  this.executeCmd("/sbin/zfs get all "+volName) ){
195 14 kreverch
                        log.debug(this.getOutCmd());
196 14 kreverch
                        String[] Tsplit = this.getOutCmd().split("\n");
197 14 kreverch
                        for (int cpt=1;cpt<Tsplit.length;cpt++){
198 14 kreverch
199 14 kreverch
                                log.debug(Tsplit[cpt].replaceAll(volName+"\\s+","").replaceAll("\n", "").replaceAll("\\s+", " "));
200 14 kreverch
                                String[] TsplitLine = Tsplit[cpt].replaceAll(volName+"\\s+","").replaceAll("\n", "").replaceAll("\\s+", " ").split(" ");
201 14 kreverch
                                log.debug(TsplitLine[0]);
202 14 kreverch
                                if ( "creation".equalsIgnoreCase(TsplitLine[0])){
203 14 kreverch
                                        this.getZvol().zProperties.get("creation").setValue(TsplitLine[1]+" "+TsplitLine[2]+" "+TsplitLine[3]+" "+TsplitLine[4]+" "+TsplitLine[5]);;
204 14 kreverch
                                }else{
205 14 kreverch
                                        //this.getZvol().zProperties.containsKey(TsplitLine[0]);
206 14 kreverch
                                        if (this.getZvol().zProperties.containsKey(TsplitLine[0])){
207 14 kreverch
                                                this.getZvol().zProperties.get(TsplitLine[0]).setValue(TsplitLine[1]);
208 14 kreverch
                                                log.debug("ZFS DEBUG "+this.getZvol().zProperties.get(TsplitLine[0]).getNameProperty()+" "+ this.getZvol().zProperties.get(TsplitLine[0]).getValue());
209 14 kreverch
                                        }
210 14 kreverch
                                }
211 14 kreverch
                        }
212 14 kreverch
                        this.getZvol().zProperties.get("name").setValue(volName);
213 14 kreverch
                        //this.getZvol().zProperties.get("name").setValue(volName);
214 14 kreverch
                }
215 14 kreverch
216 14 kreverch
217 14 kreverch
                return true;
218 14 kreverch
        }
219 14 kreverch
        public void zfsGetInfoByProperty(String volName, String propertyName){
220 14 kreverch
                zfsGetAllList.clear();
221 14 kreverch
                if (  this.executeCmd("/sbin/zfs get "+propertyName+" -H "+volName) ){
222 14 kreverch
                        log.debug(this.getOutCmd());
223 14 kreverch
                        String[] Tsplit = this.getOutCmd().split("\n");
224 14 kreverch
                        for (int cpt=0;cpt<Tsplit.length;cpt++){
225 14 kreverch
226 14 kreverch
                                log.debug(Tsplit[cpt].replaceAll(volName+"\\s+","").replaceAll("\n", "").replaceAll("\\s+", " "));
227 14 kreverch
                                String[] TsplitLine = Tsplit[cpt].replaceAll(volName+"\\s+","").replaceAll("\n", "").replaceAll("\\s+", " ").split(" ");
228 14 kreverch
                                log.debug(TsplitLine[0]);
229 14 kreverch
                                if ( "creation".equalsIgnoreCase(TsplitLine[0])){
230 14 kreverch
                                        this.getZvol().zProperties.get("creation").setValue(TsplitLine[1]+" "+TsplitLine[2]+" "+TsplitLine[3]+" "+TsplitLine[4]+" "+TsplitLine[5]);;
231 14 kreverch
                                }else{
232 14 kreverch
                                        //this.getZvol().zProperties.containsKey(TsplitLine[0]);
233 14 kreverch
                                        if (this.getZvol().zProperties.containsKey(TsplitLine[0])){
234 14 kreverch
                                                this.getZvol().zProperties.get(TsplitLine[0]).setValue(TsplitLine[1]);
235 14 kreverch
                                                log.debug("ZFS DEBUG "+this.getZvol().zProperties.get(TsplitLine[0]).getNameProperty()+" "+ this.getZvol().zProperties.get(TsplitLine[0]).getValue());
236 14 kreverch
                                        }
237 14 kreverch
                                }
238 14 kreverch
                        }
239 14 kreverch
                        this.getZvol().zProperties.get("name").setValue(volName);
240 14 kreverch
                        //this.getZvol().zProperties.get("name").setValue(volName);
241 14 kreverch
                }
242 14 kreverch
243 14 kreverch
        }
244 14 kreverch
245 14 kreverch
246 14 kreverch
        public Boolean zpoolGetAll(String zpoolName){
247 14 kreverch
                zfsGetAllList.clear();
248 14 kreverch
                //clear this.getZvol properties
249 14 kreverch
                String[] keysProp = (String[]) this.getZpool().zProperties.keySet().toArray(new String[0]);
250 14 kreverch
                Arrays.sort(keysProp);
251 14 kreverch
                for ( int i=0;i<keysProp.length;i++){
252 14 kreverch
                        String keyProp = keysProp[i];
253 14 kreverch
                        this.getZpool().zProperties.get(keyProp).setMultivalues(null);
254 14 kreverch
                        this.getZpool().zProperties.get(keyProp).setValue("");;
255 14 kreverch
256 14 kreverch
                }
257 14 kreverch
                if (  this.executeCmd("/sbin/zpool get all "+zpoolName) ){
258 14 kreverch
                        log.debug(this.getOutCmd());
259 14 kreverch
                        String[] Tsplit = this.getOutCmd().split("\n");
260 14 kreverch
                        for (int cpt=1;cpt<Tsplit.length;cpt++){
261 14 kreverch
262 14 kreverch
                                log.debug(Tsplit[cpt].replaceAll(zpoolName+"\\s+","").replaceAll("\n", "").replaceAll("\\s+", " "));
263 14 kreverch
                                String[] TsplitLine = Tsplit[cpt].replaceAll(zpoolName+"\\s+","").replaceAll("\n", "").replaceAll("\\s+", " ").split(" ");
264 14 kreverch
                                log.debug(TsplitLine[0]);
265 14 kreverch
                                if ( "creation".equalsIgnoreCase(TsplitLine[0])){
266 14 kreverch
                                        this.getZpool().zProperties.get("creation").setValue(TsplitLine[1]+" "+TsplitLine[2]+" "+TsplitLine[3]+" "+TsplitLine[4]+" "+TsplitLine[5]);;
267 14 kreverch
                                }else{
268 14 kreverch
                                        //this.getZpool().zProperties.containsKey(TsplitLine[0]);
269 14 kreverch
                                        if (this.getZpool().zProperties.containsKey(TsplitLine[0])){
270 14 kreverch
                                                this.getZpool().zProperties.get(TsplitLine[0]).setValue(TsplitLine[1]);
271 14 kreverch
                                                log.debug("ZFS DEBUG "+this.getZpool().zProperties.get(TsplitLine[0]).getNameProperty()+" "+ this.getZpool().zProperties.get(TsplitLine[0]).getValue());
272 14 kreverch
                                        }
273 14 kreverch
                                }
274 14 kreverch
                        }
275 14 kreverch
                        this.getZpool().zProperties.get("name").setValue(zpoolName);
276 14 kreverch
                        //this.getZvol().zProperties.get("name").setValue(volName);
277 14 kreverch
278 14 kreverch
                        this.getZpoolRealUseableSpace(zpoolName);
279 14 kreverch
                        log.debug("zpoolGetAll "+this.getZpool().zProperties.get("realuseablespace").getValue());
280 14 kreverch
                        this.getZpoolProvisionedSpace(zpoolName);
281 14 kreverch
                        if (  this.executeCmd(this.getZserver().zProperties.get("binzpoolgetstate").getValue()+" -n "+this.getZpool().zProperties.get("name").getValue()) ){
282 14 kreverch
                                log.debug(this.getOutCmd());
283 14 kreverch
                                String[] TsplitOut = this.getOutCmd().split("\n");
284 14 kreverch
                                for (int cpt=1;cpt<TsplitOut.length;cpt++){
285 14 kreverch
286 14 kreverch
                                        String[] TsplitLineState= TsplitOut[cpt].replaceAll("\n","").split(":");
287 14 kreverch
                                        log.debug(TsplitLineState[0]);
288 14 kreverch
                                        //this.getZpool().zProperties.containsKey(TsplitLine[0]);
289 14 kreverch
                                        if (this.getZpool().zProperties.containsKey(TsplitLineState[0])){
290 14 kreverch
                                                this.getZpool().zProperties.get(TsplitLineState[0]).setValue(TsplitLineState[1]);
291 14 kreverch
                                                log.debug("ZFS DEBUG "+this.getZpool().zProperties.get(TsplitLineState[0]).getNameProperty()+" "+ this.getZpool().zProperties.get(TsplitLineState[0]).getValue());
292 14 kreverch
                                        }
293 14 kreverch
                                }
294 14 kreverch
                                this.getZpool().zProperties.get("name").setValue(zpoolName);
295 14 kreverch
                        }
296 14 kreverch
297 14 kreverch
                }
298 14 kreverch
299 14 kreverch
300 14 kreverch
                return true;
301 14 kreverch
        }
302 14 kreverch
303 14 kreverch
304 14 kreverch
        public List<Object> zpoolList(){
305 14 kreverch
                zpoolList.clear();
306 14 kreverch
307 14 kreverch
                if (  this.executeCmd("/sbin/zpool list -H") ){
308 14 kreverch
                        String[] Tsplit = this.getOutCmd().split("\n");
309 14 kreverch
                        for (int cpt=0;cpt<Tsplit.length;cpt++){
310 14 kreverch
                                log.debug(Tsplit[cpt].split("\\s+")[0] );
311 14 kreverch
                                zpoolList.add(Tsplit[cpt].split("\\s+")[0]);
312 14 kreverch
                                //zpoolNames[ind] = Tsplit[cpt].split("\\s+")[0];
313 14 kreverch
                        }
314 14 kreverch
                }
315 14 kreverch
                return zpoolList;
316 14 kreverch
        }
317 14 kreverch
318 14 kreverch
        public List<Object> zfsListSnapshotsByVolFS(String nameVolFS){
319 14 kreverch
                zfsListSnapshots.clear();
320 14 kreverch
321 14 kreverch
                log.debug("zfs list -H -r -t snapshot -oname,used,referenced "+nameVolFS);
322 14 kreverch
                if (  this.executeCmd("/sbin/zfs list -H -r -t snapshot "+nameVolFS) ){
323 14 kreverch
                        if ( this.getOutCmd().length() >0){
324 14 kreverch
                                String[] Tsplit = this.getOutCmd().split("\n");
325 14 kreverch
                                for (int cpt=0;cpt<Tsplit.length;cpt++){
326 14 kreverch
                                        log.debug(Tsplit[cpt].split("\\s+")[0] );
327 14 kreverch
                                        zfsListSnapshots.add(Tsplit[cpt].split("\\s+")[0]);
328 14 kreverch
                                        //zpoolNames[ind] = Tsplit[cpt].split("\\s+")[0];
329 14 kreverch
                                }
330 14 kreverch
                        }
331 14 kreverch
332 14 kreverch
                }
333 14 kreverch
                return zfsListSnapshots;
334 14 kreverch
        }
335 14 kreverch
336 14 kreverch
        public Boolean getIscsiListConfigVol(String nameVolFS){
337 14 kreverch
                sidList = new ArrayList<Object>();
338 14 kreverch
                ipList = new ArrayList<Object>();
339 14 kreverch
                //sidList=null;
340 14 kreverch
                //ipList=null;
341 14 kreverch
                log.debug("get-conf-iscsi-volume nameVolFS");
342 14 kreverch
                //Reset ziscsi object
343 14 kreverch
                this.setZiscsi();
344 14 kreverch
                if (  this.executeCmd("/sbin/get-conf-iscsi-volume "+nameVolFS) ){
345 14 kreverch
                        String[] Tsplit = this.getOutCmd().split("\n");
346 14 kreverch
                        for (int cpt=0;cpt<Tsplit.length;cpt++){
347 14 kreverch
348 14 kreverch
                                String[] TsplitLine = Tsplit[cpt].replaceAll("\n", "").replaceAll("\\s+", " ").split(" ");
349 14 kreverch
                                if ( "sid".equalsIgnoreCase(TsplitLine[0])){
350 14 kreverch
                                        sidList.add(TsplitLine[1]);
351 14 kreverch
                                }else{
352 14 kreverch
                                        if ("sessionIP".equalsIgnoreCase(TsplitLine[0])){
353 14 kreverch
                                                ipList.add(TsplitLine[1]);
354 14 kreverch
                                                log.debug("sessionIP "+TsplitLine[1]);
355 14 kreverch
                                        }else{
356 14 kreverch
                                                //this.getZvol().zProperties.containsKey(TsplitLine[0]);
357 21 kreverch
                                                if (this.getZiscsi().zProperties.containsKey(TsplitLine[0])&& TsplitLine.length ==2){
358 14 kreverch
                                                        this.getZiscsi().zProperties.get(TsplitLine[0]).setValue(TsplitLine[1]);
359 14 kreverch
                                                }
360 14 kreverch
                                        }
361 14 kreverch
                                }
362 14 kreverch
                        }
363 14 kreverch
                        this.getZiscsi().zProperties.get("name").setValue(this.getZvol().zProperties.get("name").getValue());
364 14 kreverch
                        this.getZiscsi().zProperties.get("sid").setMultivalues(sidList);
365 14 kreverch
                        this.getZiscsi().zProperties.get("sessionIP").setMultivalues(ipList);
366 14 kreverch
                        return true;
367 14 kreverch
                }else{
368 14 kreverch
                        return false;
369 14 kreverch
                }
370 14 kreverch
        }
371 14 kreverch
372 14 kreverch
373 14 kreverch
        public void getZpoolProvisionedSpace(String zpoolName){
374 14 kreverch
                log.debug("getZpoolProvisionedSpace "+this.getZpool().zProperties.get("realuseablespace").getValue());
375 14 kreverch
                if (  this.executeCmd("/sbin/get-provisioned-space "+zpoolName) ){
376 14 kreverch
                        log.debug(this.getOutCmd());
377 14 kreverch
                        String[] Tsplit = this.getOutCmd().split("\n");
378 14 kreverch
                        log.debug("getZpoolProvisionedSpace "+this.getZpool().zProperties.get("realuseablespace").getValue().substring((this.getZpool().zProperties.get("realuseablespace").getValue().length())));
379 14 kreverch
380 14 kreverch
                        String refUnit = this.getZpool().zProperties.get("realuseablespace").getValue().substring((this.getZpool().zProperties.get("realuseablespace").getValue().length()-1), (this.getZpool().zProperties.get("realuseablespace").getValue().length()));
381 14 kreverch
382 14 kreverch
383 14 kreverch
                        float totalProvisioned=0;
384 14 kreverch
                        log.debug(String.valueOf(totalProvisioned)+refUnit);
385 14 kreverch
                        for (int cpt=0;cpt<Tsplit.length;cpt++){
386 14 kreverch
387 14 kreverch
                                log.debug(Tsplit[cpt].replaceAll(zpoolName+"\\s+","").replaceAll("\n", "").replaceAll("\\s+", " "));
388 14 kreverch
                                String[] TsplitLine = Tsplit[cpt].replaceAll("\n", "").replaceAll("\\s+", " ").split(" ");
389 14 kreverch
                                log.debug(TsplitLine[0]);
390 14 kreverch
                                totalProvisioned=totalProvisioned+this.convertInReferenceUnit(TsplitLine[2], refUnit);
391 14 kreverch
392 14 kreverch
                        }
393 14 kreverch
                        log.debug("getZpoolProvisionedSpace "+String.valueOf(totalProvisioned)+refUnit);
394 14 kreverch
                        this.getZpool().zProperties.get("provisionspace").setValue(String.valueOf(BigDecimal.valueOf(totalProvisioned).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())+refUnit);
395 14 kreverch
                        //this.getZvol().zProperties.get("name").setValue(volName);
396 14 kreverch
                        log.debug(String.valueOf(totalProvisioned)+refUnit);
397 14 kreverch
398 14 kreverch
399 14 kreverch
                }
400 14 kreverch
        }
401 14 kreverch
402 14 kreverch
        public void getZpoolRealUseableSpace(String zpoolName){
403 14 kreverch
404 14 kreverch
                this.zfsGetInfoByProperty(zpoolName, "used");
405 14 kreverch
                this.zfsGetInfoByProperty(zpoolName, "available");
406 14 kreverch
                log.debug("getZpoolRealUseableSpace "+this.getZvol().zProperties.get("used").getValue());
407 14 kreverch
                String refUnit = this.getZvol().zProperties.get("used").getValue().substring(this.getZvol().zProperties.get("used").getValue().length()-1, this.getZvol().zProperties.get("used").getValue().length());
408 14 kreverch
                if (!refUnit.equalsIgnoreCase("T")&&!refUnit.equalsIgnoreCase("G")){
409 14 kreverch
                        refUnit = this.getZvol().zProperties.get("available").getValue().substring(this.getZvol().zProperties.get("available").getValue().length()-1, this.getZvol().zProperties.get("available").getValue().length());
410 14 kreverch
                }
411 14 kreverch
                log.debug("getZpoolRealUseableSpace "+refUnit);
412 14 kreverch
                float usedSize = this.convertInReferenceUnit(this.getZvol().zProperties.get("used").getValue(), refUnit);
413 14 kreverch
                float availableSize = this.convertInReferenceUnit(this.getZvol().zProperties.get("available").getValue(), refUnit);
414 14 kreverch
                log.debug("getZpoolRealUseableSpace "+String.valueOf(usedSize+availableSize)+refUnit);
415 14 kreverch
                this.getZpool().zProperties.get("realuseablespace").setValue(String.valueOf(BigDecimal.valueOf(usedSize+availableSize).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())+refUnit);
416 14 kreverch
417 14 kreverch
        }
418 14 kreverch
419 14 kreverch
        public void getZpoolStatus(){
420 14 kreverch
                error.clear();
421 14 kreverch
                if ( !"".equalsIgnoreCase(getZpool().zProperties.get("name").getValue())){
422 14 kreverch
423 14 kreverch
                        log.debug("getZpoolStatus");
424 14 kreverch
                        hashDisks.clear();
425 14 kreverch
                        hashZRaid.clear();
426 14 kreverch
                        this.setZraid();
427 14 kreverch
                        if ( this.executeCmd("/sbin/show-infodisk-cache")){
428 14 kreverch
                                log.debug("getZpoolStatus");
429 14 kreverch
                                this.setZdisk();
430 14 kreverch
                                if ( outErr.length() ==0){
431 14 kreverch
                                        //log.debug(this.getOutCmd());
432 14 kreverch
                                        String namePool="";
433 14 kreverch
                                        if (this.getOutCmd().length()>0) {
434 14 kreverch
435 14 kreverch
                                                String[] Tsplit = this.getOutCmd().split("\n");
436 14 kreverch
                                                for (int cpt=0;cpt<Tsplit.length;cpt++){
437 14 kreverch
                                                        String[] TsplitLine = Tsplit[cpt].replaceAll("\n", "").replaceAll("\\s+", "").replaceAll("'", "").split(":");
438 14 kreverch
                                                        String propertyDisk=TsplitLine[0].toLowerCase();
439 14 kreverch
                                                        String valuePropertyDisk="";
440 14 kreverch
441 14 kreverch
                                                        if (TsplitLine.length==2){
442 14 kreverch
                                                                valuePropertyDisk=TsplitLine[1];
443 14 kreverch
                                                        }
444 14 kreverch
445 14 kreverch
                                                        if (Tsplit[cpt].equalsIgnoreCase("#infoDisk#")){
446 14 kreverch
                                                                if (!this.getZdisk().zProperties.get("path").getValue().equalsIgnoreCase("") ){
447 14 kreverch
                                                                        hashDisks.put("disk"+cpt, this.getZdisk());
448 14 kreverch
                                                                        log.debug(this.getZraid().zProperties.get("poolname").getValue()+"-"+this.getZraid().zProperties.get("raidtype").getValue()+"-"+this.getZraid().zProperties.get("raidid").getValue());
449 14 kreverch
                                                                        if (!hashZRaid.containsKey(this.getZraid().zProperties.get("poolname").getValue()+"-"+this.getZraid().zProperties.get("raidtype").getValue()+"-"+this.getZraid().zProperties.get("raidid").getValue())){
450 14 kreverch
                                                                                this.getZraid().zProperties.get("name").setValue(this.getZraid().zProperties.get("poolname").getValue()+"-"+this.getZraid().zProperties.get("raidtype").getValue()+"-"+this.getZraid().zProperties.get("raidid").getValue());
451 14 kreverch
                                                                                hashZRaid.put(this.getZraid().zProperties.get("poolname").getValue()+"-"+this.getZraid().zProperties.get("raidtype").getValue()+"-"+this.getZraid().zProperties.get("raidid").getValue(), this.getZraid());
452 14 kreverch
                                                                                this.setZraid();
453 14 kreverch
                                                                        }
454 14 kreverch
                                                                }
455 14 kreverch
                                                                this.setZdisk();
456 14 kreverch
                                                        }else{
457 14 kreverch
                                                                if (TsplitLine.length==2){
458 14 kreverch
                                                                        valuePropertyDisk=TsplitLine[1];
459 14 kreverch
460 14 kreverch
                                                                        if (this.getZdisk().zProperties.containsKey(propertyDisk)){
461 14 kreverch
                                                                                this.getZdisk().zProperties.get(propertyDisk).setValue(valuePropertyDisk);
462 14 kreverch
                                                                                //log.debug(propertyDisk+" : "+valuePropertyDisk);
463 14 kreverch
                                                                        }
464 14 kreverch
465 14 kreverch
                                                                        if (this.getZraid().zProperties.containsKey(propertyDisk)){
466 14 kreverch
                                                                                this.getZraid().zProperties.get(propertyDisk).setValue(valuePropertyDisk);
467 14 kreverch
468 14 kreverch
                                                                                log.debug(propertyDisk+" : "+valuePropertyDisk);
469 14 kreverch
                                                                        }
470 14 kreverch
                                                                }
471 14 kreverch
                                                        }
472 14 kreverch
473 14 kreverch
                                                }
474 14 kreverch
                                        }
475 14 kreverch
                                }
476 14 kreverch
                        }
477 14 kreverch
                        log.debug("getZpoolStatus : "+hashDisks.size());
478 14 kreverch
                        log.debug("getZpoolStatus : "+hashZRaid.size());
479 14 kreverch
                        this.setHashDisks(hashDisks);
480 14 kreverch
                        this.setHashZRaid(hashZRaid);
481 14 kreverch
482 14 kreverch
                }
483 14 kreverch
484 14 kreverch
        }
485 14 kreverch
486 14 kreverch
487 14 kreverch
        public void getInfoDisk(){
488 14 kreverch
                if ( this.executeCmd(this.getZserver().zProperties.get("bingetdiskinfo").getValue() +" "+this.getZdisk().zProperties.get("path").getValue())){
489 14 kreverch
                        log.debug("getZpoolStatus");
490 14 kreverch
                        if ( outErr.length() ==0){
491 14 kreverch
                                log.debug(this.getOutCmd());
492 14 kreverch
                                if (this.getOutCmd().length()>0) {
493 14 kreverch
                                        String dataType="";
494 14 kreverch
                                        String[] Tsplit = this.getOutCmd().split("\n");
495 14 kreverch
496 14 kreverch
497 14 kreverch
                                        for (int cpt=0;cpt<Tsplit.length;cpt++){
498 14 kreverch
499 14 kreverch
                                                String[] TsplitLine = Tsplit[cpt].replaceAll("\n", "").replaceAll("\\s+", "").replaceAll("'", "").split(":");
500 14 kreverch
                                                String propertyDisk=TsplitLine[0];
501 14 kreverch
                                                String valuePropertyDisk="";
502 14 kreverch
503 14 kreverch
504 14 kreverch
                                        }
505 14 kreverch
                                }
506 14 kreverch
                        }
507 14 kreverch
                }
508 14 kreverch
        }
509 14 kreverch
510 14 kreverch
511 14 kreverch
        public void getZsnapshotConfig(){
512 14 kreverch
                log.debug("getZsnapshotConfig");
513 14 kreverch
                this.setZsnapshots();
514 14 kreverch
                if (  this.executeCmd(this.getZserver().zProperties.get("bingetconfsnapshot").getValue()+" "+this.getZvol().zProperties.get("name").getValue()) ){
515 14 kreverch
                        if ( outErr.length() ==0){
516 14 kreverch
                                log.debug(this.getOutCmd());
517 14 kreverch
                                if (this.getOutCmd().length()>0) {
518 14 kreverch
                                        String[] Tsplit = this.getOutCmd().split("\n");
519 14 kreverch
                                        for (int cpt=0;cpt<Tsplit.length;cpt++){
520 14 kreverch
                                                String[] TsplitLine = Tsplit[cpt].replaceAll("\n", "").replaceAll("\\s+", " ").split("=");
521 14 kreverch
                                                log.debug(TsplitLine.length);
522 14 kreverch
                                                log.debug(TsplitLine[0]+" "+TsplitLine[1]);
523 14 kreverch
524 14 kreverch
                                                this.zsnapshots.zSchedulerProperties.get(TsplitLine[0]).setValue(TsplitLine[1]);
525 14 kreverch
                                        }
526 14 kreverch
                                }
527 14 kreverch
528 14 kreverch
                        }else{
529 14 kreverch
                                log.debug(this.getOutCmd());
530 14 kreverch
                                this.setZsnapshots();
531 14 kreverch
                                this.getZsnapshots().zSchedulerProperties.get("name").setValue(this.getZvol().zProperties.get("name").getValue());
532 14 kreverch
                                this.getZsnapshots().zSchedulerProperties.get("type").setValue(this.getZvol().zProperties.get("type").getValue());
533 14 kreverch
                        }
534 14 kreverch
                }
535 14 kreverch
                this.getZsnapshots().zSchedulerProperties.get("name").setValue(this.getZvol().zProperties.get("name").getValue());
536 14 kreverch
                this.getZsnapshots().zSchedulerProperties.get("type").setValue(this.getZvol().zProperties.get("type").getValue());
537 14 kreverch
        }
538 14 kreverch
539 14 kreverch
        public void getZreplicaConfig(){
540 14 kreverch
                log.debug("getZreplicaConfig");
541 14 kreverch
                this.setZreplicas();
542 14 kreverch
                log.debug(this.getZserver().zProperties.get("bingetconfreplica").getValue()+" "+this.getZvol().zProperties.get("name").getValue());
543 14 kreverch
                if (  this.executeCmd(this.getZserver().zProperties.get("bingetconfreplica").getValue()+" "+this.getZvol().zProperties.get("name").getValue()) ){
544 14 kreverch
                        if ( outErr.length() ==0){
545 14 kreverch
                                log.debug(this.getOutCmd());
546 14 kreverch
                                if (this.getOutCmd().length()>0) {
547 14 kreverch
                                        String[] Tsplit = this.getOutCmd().split("\n");
548 14 kreverch
                                        for (int cpt=0;cpt<Tsplit.length;cpt++){
549 14 kreverch
                                                String[] TsplitLine = Tsplit[cpt].replaceAll("\n", "").replaceAll("\\s+", " ").split("=");
550 14 kreverch
                                                log.debug(TsplitLine.length);
551 14 kreverch
                                                if (TsplitLine.length>1){
552 14 kreverch
                                                        log.debug(TsplitLine[0]+" "+TsplitLine[1]);
553 14 kreverch
                                                        this.zreplicas.zSchedulerProperties.get(TsplitLine[0]).setValue(TsplitLine[1]);
554 14 kreverch
                                                }
555 14 kreverch
                                        }
556 14 kreverch
                                }
557 14 kreverch
558 14 kreverch
                        }else{
559 14 kreverch
                                log.debug(this.getOutCmd());
560 14 kreverch
                                this.setZreplicas();
561 14 kreverch
                                this.getZreplicas().zSchedulerProperties.get("name").setValue(this.getZvol().zProperties.get("name").getValue());
562 14 kreverch
                                //this.getZreplicas().zSchedulerProperties.get("type").setValue(this.getZvol().zProperties.get("type").getValue());
563 14 kreverch
                        }
564 14 kreverch
                }
565 14 kreverch
566 14 kreverch
567 14 kreverch
                //this.getZsnapshots().zSchedulerProperties.get("name").setValue(this.getZvol().zProperties.get("name").getValue());
568 14 kreverch
                //this.getZreplicas().zSchedulerProperties.get("type").setValue(this.getZvol().zProperties.get("type").getValue());
569 14 kreverch
        }
570 14 kreverch
571 14 kreverch
        public void zfsEnableSnapshots(){
572 14 kreverch
573 14 kreverch
                String[] keysProp = (String[]) this.getZsnapshots().zSchedulerProperties.keySet().toArray(new String[0]);
574 14 kreverch
                Arrays.sort(keysProp);
575 14 kreverch
                error.clear();
576 14 kreverch
577 14 kreverch
                for ( int i=0;i<keysProp.length;i++){
578 14 kreverch
                        String keyProp = keysProp[i];
579 14 kreverch
                        if ( !this.getZsnapshots().zSchedulerProperties.get(keyProp).getType().equals("nofreeentry") && this.getZsnapshots().zSchedulerProperties.get(keyProp).getValue().equals("") && !"fileconf".equalsIgnoreCase(keyProp)){
580 14 kreverch
                                error.put(keyProp, keyProp+" cannot be empty");
581 14 kreverch
                        }else{
582 14 kreverch
                                if ( this.getZsnapshots().zSchedulerProperties.get(keyProp).getType().equals("nofreeentry") && this.getZsnapshots().zSchedulerProperties.get(keyProp).getMultivalues().isEmpty()){
583 14 kreverch
                                        error.put(keyProp, keyProp+" cannot be empty");
584 14 kreverch
                                }else{
585 14 kreverch
                                        if (this.getZsnapshots().zSchedulerProperties.get(keyProp).getType().equals("nofreeentry") && this.getZsnapshots().zSchedulerProperties.get(keyProp).getMultivalues().contains("*") && this.getZsnapshots().zSchedulerProperties.get(keyProp).getMultivalues().size()>1){
586 14 kreverch
                                                error.put(keyProp, keyProp+ " All is not compatible with others selections");
587 14 kreverch
                                        }
588 14 kreverch
                                }
589 14 kreverch
590 14 kreverch
                        }
591 14 kreverch
                        log.debug(this.getZsnapshots().zSchedulerProperties.get(keyProp).getType()+" "+this.getZsnapshots().zSchedulerProperties.get(keyProp).getValue()+" "+this.getZsnapshots().zSchedulerProperties.get(keyProp).getMultivalues());
592 14 kreverch
                }
593 14 kreverch
594 14 kreverch
                log.debug("ERROR SIZE : "+error.size());
595 14 kreverch
                if ( error.size() ==0){
596 14 kreverch
                        //String contentFileCronSnapshot = this.getZsnapshots().formatCronValue(this.getZsnapshots().zSchedulerProperties.get("frequency").getValue(), this.getZsnapshots().zSchedulerProperties.get("dayofweeksnapshots").getValue());
597 14 kreverch
                        for ( int i=0;i<keysProp.length;i++){
598 14 kreverch
                                String keyProp = keysProp[i];
599 14 kreverch
                                log.debug("zfsEnable "+keyProp);
600 14 kreverch
                                if ( this.getZsnapshots().zSchedulerProperties.get(keyProp).getMultivalues() != null){
601 14 kreverch
                                        if ( this.getZsnapshots().zSchedulerProperties.get(keyProp).getMultivalues().size() ==1){
602 14 kreverch
                                                this.getZsnapshots().zSchedulerProperties.get(keyProp).setValue(this.getZsnapshots().zSchedulerProperties.get(keyProp).getMultivalues().get(0).toString());
603 14 kreverch
                                        }else{
604 14 kreverch
                                                this.getZsnapshots().zSchedulerProperties.get(keyProp).setValue("");
605 14 kreverch
                                                for ( int cpt=0;cpt<this.getZsnapshots().zSchedulerProperties.get(keyProp).getMultivalues().size();cpt++){
606 14 kreverch
                                                        this.getZsnapshots().zSchedulerProperties.get(keyProp).setValue(this.getZsnapshots().zSchedulerProperties.get(keyProp).getValue()+this.getZsnapshots().zSchedulerProperties.get(keyProp).getMultivalues().get(cpt)+",");
607 14 kreverch
                                                }
608 14 kreverch
                                                this.getZsnapshots().zSchedulerProperties.get(keyProp).setValue(this.getZsnapshots().zSchedulerProperties.get(keyProp).getValue().substring(0, this.getZsnapshots().zSchedulerProperties.get(keyProp).getValue().length()-1));
609 14 kreverch
                                        }
610 14 kreverch
                                }
611 14 kreverch
                        }
612 14 kreverch
                        String cronMin = this.getZsnapshots().zSchedulerProperties.get("minutesofsnapshots").getValue();
613 14 kreverch
                        String cronHour = this.getZsnapshots().zSchedulerProperties.get("hoursofsnapshots").getValue();
614 14 kreverch
                        String cronMonth = this.getZsnapshots().zSchedulerProperties.get("monthsnapshots").getValue();
615 14 kreverch
                        String cronDayofMonth = this.getZsnapshots().zSchedulerProperties.get("dayofmonthsnapshots").getValue();
616 14 kreverch
                        String cronDayofWeek = this.getZsnapshots().zSchedulerProperties.get("dayofweeksnapshots").getValue();
617 14 kreverch
                        String nameVolFS=this.getZsnapshots().zSchedulerProperties.get("name").getValue();
618 14 kreverch
                        String typeZFS=this.getZsnapshots().zSchedulerProperties.get("type").getValue();
619 14 kreverch
                        String nbsnapshots=this.getZsnapshots().zSchedulerProperties.get("nbsnapshots").getValue();
620 14 kreverch
                        if (  this.executeCmd(this.getZserver().zProperties.get("binzfsenablesnapshots").getValue()+" -m "+"\""+cronMin+"\""+
621 14 kreverch
                                        " -H "+"\""+cronHour+"\""+
622 14 kreverch
                                        " -M "+"\""+cronMonth+"\""+
623 14 kreverch
                                        " -D "+"\""+cronDayofMonth+"\""+
624 14 kreverch
                                        " -d "+"\""+cronDayofWeek+"\""+
625 14 kreverch
                                        " -N "+"\""+nameVolFS+"\""+
626 14 kreverch
                                        " -t "+"\""+typeZFS+"\""+
627 14 kreverch
                                        " -k "+"\""+nbsnapshots+"\"")){
628 14 kreverch
                                if ( outErr.length() ==0){
629 14 kreverch
                                        log.debug(this.getOutCmd());
630 14 kreverch
                                        String[] Tsplit = this.getOutCmd().split("\n");
631 14 kreverch
                                        for (int cpt=0;cpt<Tsplit.length;cpt++){
632 14 kreverch
                                                /*String[] TsplitLine = Tsplit[cpt].replaceAll("\n", "").replaceAll("\\s+", " ").split("=");
633 14 kreverch
                                                log.debug(TsplitLine.length);
634 14 kreverch
                                                log.debug(TsplitLine[0]+" "+TsplitLine[1]);
635 14 kreverch
                                                this.zsnapshots.zSchedulerProperties.get(TsplitLine[0]).setValue(TsplitLine[1]);*/
636 14 kreverch
                                        }
637 14 kreverch
                                }else{
638 14 kreverch
                                        log.debug(this.getOutCmd());
639 14 kreverch
                                        this.setZsnapshots();
640 14 kreverch
                                        this.getZsnapshots().zSchedulerProperties.get("name").setValue(this.getZvol().zProperties.get("name").getValue());
641 14 kreverch
                                        this.getZsnapshots().zSchedulerProperties.get("type").setValue(this.getZvol().zProperties.get("type").getValue());
642 14 kreverch
                                }
643 14 kreverch
                        }
644 14 kreverch
                }
645 14 kreverch
        }
646 14 kreverch
647 14 kreverch
648 14 kreverch
        public void zfsDisableSnapshots(){
649 14 kreverch
                error.clear();
650 14 kreverch
                if (  this.executeCmd(this.getZserver().zProperties.get("binzfsdisablesnapshots").getValue()+" -N "+"\""+this.getZsnapshots().zSchedulerProperties.get("name").getValue()+"\"" )){
651 14 kreverch
                        if ( outErr.length() ==0){
652 14 kreverch
                                log.debug(this.getOutCmd());
653 14 kreverch
                        }else{
654 14 kreverch
                                log.debug(this.getOutCmd());
655 14 kreverch
                                if (outErr.length()>0){
656 14 kreverch
                                        error.put("binzfsdisablesnapshots", outErr+"\n" );
657 14 kreverch
                                }
658 14 kreverch
                        }
659 14 kreverch
                }
660 14 kreverch
        }
661 14 kreverch
662 14 kreverch
        public void zfsSnapshots(){
663 14 kreverch
                error.clear();
664 14 kreverch
                if ( this.getZsnapshots().zSchedulerProperties.get("fileconf").getValue().isEmpty()){
665 14 kreverch
                        error.put("fileconf ", "Please configure the Snapshots");
666 14 kreverch
                }
667 14 kreverch
                if ( error.size() < 1){
668 14 kreverch
                        if (  this.executeCmd(this.getZserver().zProperties.get("binzfssnapshots").getValue()+" "+"\""+this.getZsnapshots().zSchedulerProperties.get("fileconf").getValue()+"\"" )){
669 14 kreverch
                                if ( outErr.length() ==0){
670 14 kreverch
                                        log.debug(this.getOutCmd());
671 14 kreverch
                                }else{
672 14 kreverch
                                        log.debug(this.getOutCmd());
673 14 kreverch
                                        if (outErr.length()>0){
674 14 kreverch
                                                error.put("binzfssnapshots", outErr+"\n" );
675 14 kreverch
                                        }
676 14 kreverch
                                }
677 14 kreverch
                        }
678 14 kreverch
                }
679 14 kreverch
        }
680 14 kreverch
681 14 kreverch
682 14 kreverch
        public void zfsEnableReplicas(){
683 14 kreverch
684 14 kreverch
                String[] keysProp = (String[]) this.getZreplicas().zSchedulerProperties.keySet().toArray(new String[0]);
685 14 kreverch
                Arrays.sort(keysProp);
686 14 kreverch
                error.clear();
687 14 kreverch
688 14 kreverch
                for ( int i=0;i<keysProp.length;i++){
689 14 kreverch
                        String keyProp = keysProp[i];
690 14 kreverch
                        log.debug("zfsEnableReplicas "+keyProp);
691 14 kreverch
                        if ( !this.getZreplicas().zSchedulerProperties.get(keyProp).getType().equals("nofreeentry") && !this.getZreplicas().zSchedulerProperties.get(keyProp).getType().equals("noupdateable") && this.getZreplicas().zSchedulerProperties.get(keyProp).getValue().equals("")){
692 14 kreverch
                                error.put(keyProp, keyProp+" cannot be empty");
693 14 kreverch
                        }else{
694 14 kreverch
                                if ( "nofreeentry".equalsIgnoreCase(this.getZreplicas().zSchedulerProperties.get(keyProp).getType()) && (this.getZreplicas().zSchedulerProperties.get(keyProp).getPermitValue() !=null)){
695 14 kreverch
                                        if ( this.getZreplicas().zSchedulerProperties.get(keyProp).getType().equals("nofreeentry") && this.getZreplicas().zSchedulerProperties.get(keyProp).getMultivalues().isEmpty()){
696 14 kreverch
                                                error.put(keyProp, keyProp+" cannot be empty");
697 14 kreverch
                                        }else{
698 14 kreverch
                                                if (this.getZreplicas().zSchedulerProperties.get(keyProp).getType().equals("nofreeentry") && this.getZreplicas().zSchedulerProperties.get(keyProp).getMultivalues().contains("*") && this.getZreplicas().zSchedulerProperties.get(keyProp).getMultivalues().size()>1){
699 14 kreverch
                                                        error.put(keyProp, keyProp+ " All is not compatible with others selections");
700 14 kreverch
                                                }
701 14 kreverch
                                        }
702 14 kreverch
                                }
703 14 kreverch
                        }
704 14 kreverch
                        log.debug(this.getZreplicas().zSchedulerProperties.get(keyProp).getType()+" "+this.getZreplicas().zSchedulerProperties.get(keyProp).getValue()+" "+this.getZreplicas().zSchedulerProperties.get(keyProp).getMultivalues());
705 14 kreverch
                }
706 14 kreverch
                if ("".equalsIgnoreCase(this.getZreplicas().zSchedulerProperties.get("replicapool").getValue())){
707 14 kreverch
                        error.put("replicaPool", "replicapool cannot be empty");
708 14 kreverch
                }
709 14 kreverch
710 14 kreverch
                log.debug("ERROR SIZE : "+error.size());
711 14 kreverch
                if ( error.size() ==0){
712 14 kreverch
                        //String contentFileCronSnapshot = this.getZsnapshots().formatCronValue(this.getZsnapshots().zSchedulerProperties.get("frequency").getValue(), this.getZsnapshots().zSchedulerProperties.get("dayofweeksnapshots").getValue());
713 14 kreverch
                        for ( int i=0;i<keysProp.length;i++){
714 14 kreverch
                                String keyProp = keysProp[i];
715 14 kreverch
                                log.debug("zfsEnable Replica"+keyProp);
716 14 kreverch
                                if ( this.getZreplicas().zSchedulerProperties.get(keyProp).getMultivalues() != null){
717 14 kreverch
                                        if ( this.getZreplicas().zSchedulerProperties.get(keyProp).getMultivalues().size() ==1){
718 14 kreverch
                                                this.getZreplicas().zSchedulerProperties.get(keyProp).setValue(this.getZreplicas().zSchedulerProperties.get(keyProp).getMultivalues().get(0).toString());
719 14 kreverch
                                        }else{
720 14 kreverch
                                                this.getZreplicas().zSchedulerProperties.get(keyProp).setValue("");
721 14 kreverch
                                                for ( int cpt=0;cpt<this.getZreplicas().zSchedulerProperties.get(keyProp).getMultivalues().size();cpt++){
722 14 kreverch
                                                        this.getZreplicas().zSchedulerProperties.get(keyProp).setValue(this.getZreplicas().zSchedulerProperties.get(keyProp).getValue()+this.getZreplicas().zSchedulerProperties.get(keyProp).getMultivalues().get(cpt)+",");
723 14 kreverch
                                                }
724 14 kreverch
                                                this.getZreplicas().zSchedulerProperties.get(keyProp).setValue(this.getZreplicas().zSchedulerProperties.get(keyProp).getValue().substring(0, this.getZreplicas().zSchedulerProperties.get(keyProp).getValue().length()-1));
725 14 kreverch
                                        }
726 14 kreverch
                                }
727 14 kreverch
                        }
728 14 kreverch
                        String cronMin = this.getZreplicas().zSchedulerProperties.get("minutesofreplicas").getValue();
729 14 kreverch
                        String cronHour = this.getZreplicas().zSchedulerProperties.get("hoursofreplicas").getValue();
730 14 kreverch
                        String cronMonth = this.getZreplicas().zSchedulerProperties.get("monthreplicas").getValue();
731 14 kreverch
                        String cronDayofMonth = this.getZreplicas().zSchedulerProperties.get("dayofmonthreplicas").getValue();
732 14 kreverch
                        String cronDayofWeek = this.getZreplicas().zSchedulerProperties.get("dayofweekreplicas").getValue();
733 14 kreverch
                        String nameVolFS=this.getZreplicas().zSchedulerProperties.get("name").getValue();
734 14 kreverch
                        String nameReplica=this.getZreplicas().zSchedulerProperties.get("replicapool").getValue()+"/"+this.getZvol().zProperties.get("name").getValue().split("/")[1];
735 14 kreverch
                        String lastSnapshotsReplicated=this.getZreplicas().zSchedulerProperties.get("lastsnapshotreplicated").getValue();
736 14 kreverch
                        String nbReplica=this.getZreplicas().zSchedulerProperties.get("nbreplica").getValue();
737 14 kreverch
                        String cmd2exec = this.getZserver().zProperties.get("binzfsenablereplicas").getValue()+" -m "+"\""+cronMin+"\""+
738 14 kreverch
                                        " -H "+"\""+cronHour+"\""+
739 14 kreverch
                                        " -M "+"\""+cronMonth+"\""+
740 14 kreverch
                                        " -D "+"\""+cronDayofMonth+"\""+
741 14 kreverch
                                        " -d "+"\""+cronDayofWeek+"\""+
742 14 kreverch
                                        " -o "+"\""+nameVolFS+"\""+
743 14 kreverch
                                        " -r "+"\""+nameReplica+"\""+
744 14 kreverch
                                        " -n "+"\""+nbReplica+"\"";
745 14 kreverch
746 14 kreverch
                        if (!"".equalsIgnoreCase(this.getZreplicas().zSchedulerProperties.get("server").getValue()) && (!this.getZserver().zProperties.get("serverIP").getValue().equalsIgnoreCase(this.getZreplicas().zSchedulerProperties.get("server").getValue())) ){
747 14 kreverch
                                cmd2exec = cmd2exec +" -s "+this.getZreplicas().zSchedulerProperties.get("server").getValue();
748 14 kreverch
                        }
749 14 kreverch
                        log.debug(cmd2exec+" "+this.getZreplicas().zSchedulerProperties.get("server").getValue()+" "+this.getZserver().zProperties.get("serverIP").getValue());
750 14 kreverch
                        if (  this.executeCmd(cmd2exec)){
751 14 kreverch
                                if ( outErr.length() ==0){
752 14 kreverch
                                        log.debug(this.getOutCmd());
753 14 kreverch
                                        String[] Tsplit = this.getOutCmd().split("\n");
754 14 kreverch
                                        for (int cpt=0;cpt<Tsplit.length;cpt++){
755 14 kreverch
                                                /*String[] TsplitLine = Tsplit[cpt].replaceAll("\n", "").replaceAll("\\s+", " ").split("=");
756 14 kreverch
                                                log.debug(TsplitLine.length);
757 14 kreverch
                                                log.debug(TsplitLine[0]+" "+TsplitLine[1]);
758 14 kreverch
                                                this.zsnapshots.zSchedulerProperties.get(TsplitLine[0]).setValue(TsplitLine[1]);*/
759 14 kreverch
                                        }
760 14 kreverch
                                }else{
761 14 kreverch
                                        log.debug(this.getOutCmd());
762 14 kreverch
                                        this.setZreplicas();
763 14 kreverch
                                        this.getZreplicas().zSchedulerProperties.get("name").setValue(this.getZvol().zProperties.get("name").getValue());
764 14 kreverch
                                        //this.getZreplicas().zSchedulerProperties.get("type").setValue(this.getZvol().zProperties.get("type").getValue());
765 14 kreverch
                                }
766 14 kreverch
                        }
767 14 kreverch
                }
768 14 kreverch
        }
769 14 kreverch
770 14 kreverch
771 14 kreverch
        public void zfsDisableReplicas(){
772 14 kreverch
                error.clear();
773 14 kreverch
                if (  this.executeCmd(this.getZserver().zProperties.get("binzfsdisablereplicas").getValue()+" -N "+"\""+this.getZreplicas().zSchedulerProperties.get("name").getValue()+"\"" )){
774 14 kreverch
                        if ( outErr.length() ==0){
775 14 kreverch
                                log.debug(this.getOutCmd());
776 14 kreverch
                        }else{
777 14 kreverch
                                log.debug(this.getOutCmd());
778 14 kreverch
                                if (outErr.length()>0){
779 14 kreverch
                                        error.put("binzfsdisablereplicas", outErr+"\n" );
780 14 kreverch
                                }
781 14 kreverch
                        }
782 14 kreverch
                }
783 14 kreverch
        }
784 14 kreverch
785 14 kreverch
        public void zfsReplicas(){
786 14 kreverch
                error.clear();
787 14 kreverch
                if ( this.getZreplicas().zSchedulerProperties.get("fileconf").getValue().isEmpty()){
788 14 kreverch
                        error.put("fileconf ", "Please configure the replication");
789 14 kreverch
                }
790 14 kreverch
                if ( error.size() < 1){
791 14 kreverch
                        if (  this.executeCmd(this.getZserver().zProperties.get("binzfsreplica").getValue()+" "+"\""+this.getZreplicas().zSchedulerProperties.get("fileconf").getValue()+"\" &" )){
792 14 kreverch
                                if ( outErr.length() ==0){
793 14 kreverch
                                        log.debug(this.getOutCmd());
794 14 kreverch
                                }else{
795 14 kreverch
                                        log.debug(this.getOutCmd());
796 14 kreverch
                                        if (outErr.length()>0){
797 14 kreverch
                                                error.put("binzfsreplica", outErr+"\n" );
798 14 kreverch
                                        }
799 14 kreverch
                                }
800 14 kreverch
                        }
801 14 kreverch
                }
802 14 kreverch
        }
803 14 kreverch
804 14 kreverch
805 14 kreverch
        public void zfsCreateVolFS(){
806 14 kreverch
                error.clear();
807 14 kreverch
                if (this.getZpool().zProperties.get("name").getValue().equals("")){
808 14 kreverch
                        error.put("pool", "Please select a pool");
809 14 kreverch
                }
810 14 kreverch
                String[] keysProp = (String[]) this.getZvol().zProperties.keySet().toArray(new String[0]);
811 14 kreverch
                Arrays.sort(keysProp);
812 14 kreverch
                String optionsList="";
813 14 kreverch
                for (int i = 0; i < keysProp.length; i++) {
814 14 kreverch
                        String keyProp = keysProp[i];
815 14 kreverch
                        log.debug(keyProp);
816 14 kreverch
                        if ( ("volume".equalsIgnoreCase(this.getZvol().zProperties.get("type").getValue()) &&
817 14 kreverch
                                        ("volume".equalsIgnoreCase(this.getZvol().zProperties.get(keyProp).getPropertyOf()) ||
818 14 kreverch
                                                        "volandfs".equalsIgnoreCase(this.getZvol().zProperties.get(keyProp).getPropertyOf())))) {
819 14 kreverch
                                if (this.getZvol().zProperties.get(keyProp).getValue().equals("")&&!this.getZvol().zProperties.get(keyProp).getType().equals("noupdateable")){
820 14 kreverch
                                        error.put(keyProp, keyProp+" cannot be empty");
821 14 kreverch
                                }
822 14 kreverch
                                if ( keyProp.equals("volblocksize")&& "".equals(this.getZvol().zProperties.get(keyProp).getValue())){
823 14 kreverch
                                        error.put(keyProp, keyProp+" cannot be empty");
824 14 kreverch
                                }
825 14 kreverch
826 14 kreverch
                                String nameVolFS = this.getZvol().zProperties.get("name").getValue();
827 14 kreverch
                                //Available space
828 14 kreverch
                                if (keyProp.equals("volsize")&& !"".equals(this.getZvol().zProperties.get(keyProp).getValue())){
829 14 kreverch
                                        String unit = this.getZvol().zProperties.get("volsize").getValue().substring(this.getZvol().zProperties.get("volsize").getValue().length()-1, this.getZvol().zProperties.get("volsize").getValue().length());
830 14 kreverch
831 14 kreverch
                                        if ( !unit.equalsIgnoreCase("T") && !unit.equalsIgnoreCase("G") && !unit.equalsIgnoreCase("M")){
832 14 kreverch
                                                error.put("volsize", "Field size : Unit valid est T,G or M");
833 14 kreverch
                                        }else{
834 14 kreverch
                                                Float realUseableSpace = this.convertInReferenceUnit(this.getZpool().zProperties.get("realuseablespace").getValue(), unit);
835 14 kreverch
                                                Float sizeVolFS = this.convertInReferenceUnit(this.getZvol().zProperties.get("volsize").getValue(), unit);
836 14 kreverch
                                                this.zfsGetInfoByProperty(this.getZpool().zProperties.get("name").getValue(), "used");
837 14 kreverch
                                                Float usedSpace = this.convertInReferenceUnit(this.getZvol().zProperties.get("used").getValue(), unit);
838 14 kreverch
                                                this.getZvol().zProperties.get("name").setValue(nameVolFS);
839 14 kreverch
                                                Float freeSpace = realUseableSpace - usedSpace;
840 14 kreverch
                                                if ( sizeVolFS > freeSpace){
841 14 kreverch
                                                        error.put("freespace", "No space available. Free Pool Space : "+String.valueOf(freeSpace)+unit);
842 14 kreverch
                                                }
843 14 kreverch
                                        }
844 14 kreverch
                                }
845 14 kreverch
                                log.debug("zfsCreateVolFS : "+keyProp+" "+this.getZvol().zProperties.get(keyProp).getType());
846 14 kreverch
                                if (!keyProp.equals("name") &&  !this.getZvol().zProperties.get(keyProp).getType().equals("noupdateable")){
847 14 kreverch
                                        log.debug("zfsCreateVolFS :"+keyProp);
848 14 kreverch
                                        optionsList = optionsList+keyProp+"="+this.getZvol().zProperties.get(keyProp).getValue()+",";
849 14 kreverch
                                }
850 14 kreverch
                        }else{
851 14 kreverch
                                if (("filesystem".equalsIgnoreCase(this.getZvol().zProperties.get("type").getValue()) &&
852 14 kreverch
                                                "fs".equalsIgnoreCase(this.getZvol().zProperties.get(keyProp).getPropertyOf())||"volandfs".equalsIgnoreCase(this.getZvol().zProperties.get(keyProp).getPropertyOf()))        ){
853 14 kreverch
                                        if (this.getZvol().zProperties.get(keyProp).getValue().equals("")&&!this.getZvol().zProperties.get(keyProp).getType().equals("noupdateable")&&!"quota".equals(keyProp)&&!"reservation".equals(keyProp) ){
854 14 kreverch
                                                error.put(keyProp, keyProp+" cannot be empty");
855 14 kreverch
                                        }
856 14 kreverch
                                        if (("quota".equals(keyProp)||"reservation".equals(keyProp))&&"".equals(this.getZvol().zProperties.get(keyProp).getValue())){
857 14 kreverch
                                                this.getZvol().zProperties.get(keyProp).setValue("none");
858 14 kreverch
                                        }
859 14 kreverch
                                        if (("quota".equals(keyProp)||"reservation".equals(keyProp))&& !"none".equals(this.getZvol().zProperties.get(keyProp).getValue()) &&!"".equals(this.getZvol().zProperties.get(keyProp).getValue())){
860 14 kreverch
                                                String nameVolFS = this.getZvol().zProperties.get("name").getValue();
861 14 kreverch
                                                String unit = this.getZvol().zProperties.get(keyProp).getValue().substring(this.getZvol().zProperties.get(keyProp).getValue().length()-1, this.getZvol().zProperties.get(keyProp).getValue().length());
862 14 kreverch
                                                if ( !unit.equalsIgnoreCase("T") && !unit.equalsIgnoreCase("G") && !unit.equalsIgnoreCase("M")){
863 14 kreverch
                                                        error.put(keyProp, "Field "+keyProp+" : Unit valid est T,G or M");
864 14 kreverch
                                                }else{
865 14 kreverch
                                                        Float realUseableSpace = this.convertInReferenceUnit(this.getZpool().zProperties.get("realuseablespace").getValue(), unit);
866 14 kreverch
                                                        Float valueKeyProp = this.convertInReferenceUnit(this.getZvol().zProperties.get(keyProp).getValue(), unit);
867 14 kreverch
                                                        this.zfsGetInfoByProperty(this.getZpool().zProperties.get("name").getValue(), "used");
868 14 kreverch
                                                        Float usedSpace = this.convertInReferenceUnit(this.getZvol().zProperties.get("used").getValue(), unit);
869 14 kreverch
                                                        this.getZvol().zProperties.get("name").setValue(nameVolFS);
870 14 kreverch
                                                        Float freeSpace = realUseableSpace - usedSpace;
871 14 kreverch
                                                        if ( valueKeyProp > freeSpace){
872 14 kreverch
                                                                error.put(keyProp, "Error value for "+keyProp+" : No space available. Free Pool Space : "+String.valueOf(freeSpace)+unit);
873 14 kreverch
                                                        }
874 14 kreverch
                                                }
875 14 kreverch
                                        }
876 14 kreverch
                                        log.debug("zfsCreateVolFS : "+keyProp+" "+this.getZvol().zProperties.get(keyProp).getType());
877 14 kreverch
                                        if (!keyProp.equals("name") &&  !this.getZvol().zProperties.get(keyProp).getType().equals("noupdateable")){
878 14 kreverch
                                                log.debug("zfsCreateVolFS :"+keyProp);
879 14 kreverch
                                                optionsList = optionsList+keyProp+"="+this.getZvol().zProperties.get(keyProp).getValue()+",";
880 14 kreverch
                                        }
881 14 kreverch
                                }
882 14 kreverch
883 14 kreverch
                        }
884 14 kreverch
                }
885 14 kreverch
                if (error.size()==0){
886 14 kreverch
                        log.debug(optionsList);
887 14 kreverch
                        if ( optionsList.length()>0){
888 14 kreverch
                                optionsList=optionsList.substring(0, optionsList.length()-1);
889 14 kreverch
                        }
890 14 kreverch
891 14 kreverch
                        if ( "volume".equals(this.getZvol().zProperties.get("type").getValue())&& this.executeCmd(this.getZserver().zProperties.get("binzfscreatevolume").getValue()+" -n "+this.getZvol().zProperties.get("name").getValue()+
892 14 kreverch
                                        " -p "+this.getZpool().zProperties.get("name").getValue()+
893 14 kreverch
                                        " -b "+this.getZvol().zProperties.get("volblocksize").getValue()+
894 14 kreverch
                                        " -s "+this.getZvol().zProperties.get("volsize").getValue()+
895 14 kreverch
                                        " -o "+optionsList)){
896 14 kreverch
                                if ( outErr.length() ==0){
897 14 kreverch
                                        log.debug(this.getOutCmd());
898 14 kreverch
                                }else{
899 14 kreverch
                                        log.debug(this.getOutCmd());
900 14 kreverch
                                        error.put("binzfscreatevolume", "Incoherence : Please connect you to server and launch manualy "+this.getZserver().zProperties.get("binzfscreatevolume").getValue() );
901 14 kreverch
                                }
902 14 kreverch
                        }else{
903 14 kreverch
                                if ("filesystem".equals(this.getZvol().zProperties.get("type").getValue())&& this.executeCmd(this.getZserver().zProperties.get("binzfscreatefilesystem").getValue()+" -n "+this.getZvol().zProperties.get("name").getValue()+
904 14 kreverch
                                                " -p "+this.getZpool().zProperties.get("name").getValue()+
905 14 kreverch
                                                " -o "+optionsList)){
906 14 kreverch
                                        if ( outErr.length() ==0){
907 14 kreverch
                                                log.debug(this.getOutCmd());
908 14 kreverch
                                        }else{
909 14 kreverch
                                                log.debug(this.getOutCmd());
910 14 kreverch
                                                error.put("binzfscreatefilesystem", "Incoherence : Please connect you to server and launch manualy "+this.getZserver().zProperties.get("binzfscreatefilesystem").getValue() );
911 14 kreverch
                                        }
912 14 kreverch
                                }
913 14 kreverch
                        }
914 14 kreverch
                }else{
915 14 kreverch
                        log.debug("Error : "+error.size());
916 14 kreverch
                }
917 14 kreverch
        }
918 14 kreverch
919 14 kreverch
        public void zfsUmountFS(){
920 14 kreverch
                error.clear();
921 14 kreverch
                if ("".equals(this.getZvol().zProperties.get("name").getValue())){
922 14 kreverch
                        error.put("name", "Please select a ZFS FileSystem");
923 14 kreverch
                }
924 14 kreverch
                if (error.size()==0){
925 14 kreverch
                        if (this.executeCmd(this.getZserver().zProperties.get("binzfs").getValue()+" umount "+this.getZvol().zProperties.get("name").getValue())){
926 14 kreverch
                                if ( outErr.length() ==0){
927 14 kreverch
                                        log.debug(this.getOutCmd());
928 14 kreverch
                                }else{
929 14 kreverch
                                        log.debug(this.getOutCmd());
930 14 kreverch
                                        if (outErr.toString().contains("Error")){
931 14 kreverch
                                                error.put("binzfs", "Incoherence : Please connect you to server and launch manualy "+this.getZserver().zProperties.get("binzfs").getValue() );
932 14 kreverch
                                        }
933 14 kreverch
                                }
934 14 kreverch
                        }else{
935 14 kreverch
                                error.put("executeCmd", "Problem with the command : "+this.getZserver().zProperties.get("binzfs").getValue()+" umount "+this.getZvol().zProperties.get("name").getValue());
936 14 kreverch
                        }
937 14 kreverch
                }
938 14 kreverch
939 14 kreverch
        }
940 14 kreverch
941 14 kreverch
        public void zfsDestroyVolFS(){
942 14 kreverch
                error.clear();
943 14 kreverch
                if ("".equals(this.getZvol().zProperties.get("name").getValue())){
944 14 kreverch
                        error.put("name", "Please select a ZFS FileSystem");
945 14 kreverch
                }
946 14 kreverch
                if ( error.size()==0){
947 14 kreverch
                        if ( "filesystem".equals(this.getZvol().zProperties.get("type").getValue())){
948 14 kreverch
                                if ( this.executeCmd(this.getZserver().zProperties.get("binzfsdelfilesystem").getValue()+" -n "+this.getZvol().zProperties.get("name").getValue() )) {
949 14 kreverch
                                        if ( outErr.length() ==0){
950 14 kreverch
                                                log.debug(this.getOutCmd());
951 14 kreverch
                                        }else{
952 14 kreverch
                                                log.debug(this.getOutCmd());
953 14 kreverch
                                                if (outErr.length()>0){
954 14 kreverch
                                                        error.put("binzfsdelvolume", outErr+"\n" );
955 14 kreverch
                                                }
956 14 kreverch
                                        }
957 14 kreverch
                                }else{
958 14 kreverch
                                        error.put("executeCmd", "Problem with the command : "+this.getZserver().zProperties.get("binzfsdelfilesystem").getValue()+" -n "+this.getZvol().zProperties.get("name").getValue());
959 14 kreverch
                                }
960 14 kreverch
                        }else{
961 14 kreverch
                                if ( "volume".equals(this.getZvol().zProperties.get("type").getValue())){
962 14 kreverch
                                        if ( this.executeCmd(this.getZserver().zProperties.get("binzfsdelvolume").getValue()+" -n "+this.getZvol().zProperties.get("name").getValue() )) {
963 14 kreverch
                                                if ( outErr.length() ==0){
964 14 kreverch
                                                        log.debug(this.getOutCmd());
965 14 kreverch
                                                }else{
966 14 kreverch
                                                        log.debug(this.getOutCmd());
967 14 kreverch
                                                        if (outErr.length()>0){
968 14 kreverch
                                                                error.put("binzfsdelvolume", outErr+"\n" );
969 14 kreverch
                                                        }
970 14 kreverch
                                                }
971 14 kreverch
                                        }else{
972 14 kreverch
                                                error.put("executeCmd", "Problem with the command : "+this.getZserver().zProperties.get("binzfsdelvolume").getValue()+" -n "+this.getZvol().zProperties.get("name").getValue());
973 14 kreverch
                                        }
974 14 kreverch
                                }else{
975 14 kreverch
                                        if ( "snapshot".equals(this.getZvol().zProperties.get("type").getValue())){
976 14 kreverch
                                                if ( this.executeCmd(this.getZserver().zProperties.get("binzfsdelvolume").getValue()+" -n "+this.getZvol().zProperties.get("name").getValue() )) {
977 14 kreverch
                                                        if ( outErr.length() ==0){
978 14 kreverch
                                                                log.debug(this.getOutCmd());
979 14 kreverch
                                                        }else{
980 14 kreverch
                                                                log.debug(this.getOutCmd());
981 14 kreverch
                                                                if (outErr.length()>0){
982 14 kreverch
                                                                        error.put("binzfsdelvolume", outErr+"\n" );
983 14 kreverch
                                                                }
984 14 kreverch
                                                        }
985 14 kreverch
                                                }else{
986 14 kreverch
                                                        error.put("executeCmd", "Problem with the command : "+this.getZserver().zProperties.get("binzfsdelvolume").getValue()+" -n "+this.getZvol().zProperties.get("name").getValue());
987 14 kreverch
                                                }
988 14 kreverch
                                        }
989 14 kreverch
                                }
990 14 kreverch
                        }
991 14 kreverch
992 14 kreverch
                }
993 14 kreverch
        }
994 14 kreverch
995 14 kreverch
        public void zfsCreateIscsi(){
996 14 kreverch
                String[] keysProp = (String[]) this.getZiscsi().zProperties.keySet().toArray(new String[0]);
997 14 kreverch
                Arrays.sort(keysProp);
998 14 kreverch
                error.clear();
999 14 kreverch
                if ("filesystem".equals(this.getZvol().zProperties.get("type").getValue())){
1000 14 kreverch
                        error.put("type", "You cannot add a iscsi configuration for a zfs filesystem");
1001 14 kreverch
                }
1002 14 kreverch
1003 14 kreverch
                for ( int i=0;i<keysProp.length;i++){
1004 14 kreverch
                        String keyProp = keysProp[i];
1005 14 kreverch
                        if (!this.getZiscsi().zProperties.get(keyProp).getType().contains("noupdateable") && !keyProp.equalsIgnoreCase("allowIP")){
1006 14 kreverch
                                if ( "".equals(this.getZiscsi().zProperties.get(keyProp).getValue())) {
1007 14 kreverch
                                        error.put(keyProp, this.getZiscsi().zProperties.get(keyProp).getLabelProperty()+" cannot be empty" );
1008 14 kreverch
                                }
1009 14 kreverch
                        }
1010 14 kreverch
                }
1011 14 kreverch
                if (!"".equals(this.getZiscsi().zProperties.get("tid").getValue())){
1012 14 kreverch
                        error.put("tid", "Iscsi is already configured for this volume" );
1013 14 kreverch
                }
1014 14 kreverch
1015 14 kreverch
                if ( error.size() ==0){
1016 14 kreverch
                        String cmd = this.getZserver().zProperties.get("binzfsaddiscsi").getValue()+" -d "+this.getZserver().zProperties.get("pathzfsvoldevice").getValue()+this.getZiscsi().zProperties.get("name").getValue()
1017 14 kreverch
                                        +" -T "+this.getZiscsi().zProperties.get("exportType").getValue()+
1018 14 kreverch
                                        " -L 0"+
1019 14 kreverch
                                        " -o "+this.getZiscsi().zProperties.get("iomode").getValue()+
1020 14 kreverch
                                        " -l "+this.getZiscsi().zProperties.get("login").getValue()+
1021 14 kreverch
                                        " -p "+this.getZiscsi().zProperties.get("passwd").getValue()+
1022 14 kreverch
                                        " -t "+this.getZiscsi().zProperties.get("name").getValue();
1023 14 kreverch
                        if (!this.getZiscsi().zProperties.get("allowIP").getValue().isEmpty()){
1024 14 kreverch
                                cmd = cmd +" -R "+"\""+this.getZiscsi().zProperties.get("allowIP").getValue()+"\"";
1025 14 kreverch
                        }
1026 14 kreverch
                        if (  this.executeCmd(cmd)){
1027 14 kreverch
                                if ( outErr.length() ==0){
1028 14 kreverch
                                        //log.debug(this.getOutCmd());
1029 14 kreverch
                                }else{
1030 14 kreverch
                                        if (outErr.toString().contains("Error")){
1031 14 kreverch
                                                error.put("pathzfsvoldevice", "Incoherence : Please connect you to server and launch manualy "+this.getZserver().zProperties.get("binzfsaddiscsi").getValue() );
1032 14 kreverch
                                        }
1033 14 kreverch
                                }
1034 14 kreverch
                        }
1035 14 kreverch
                }
1036 14 kreverch
        }
1037 14 kreverch
1038 14 kreverch
        public void zfsDelIscsi(){
1039 14 kreverch
                error.clear();
1040 14 kreverch
                if (!"".equals(this.getZiscsi().zProperties.get("tid").getValue())){
1041 14 kreverch
                        if (  this.executeCmd(this.getZserver().zProperties.get("binzfsdeliscsi").getValue()+" -T "+"\""+this.getZiscsi().zProperties.get("tid").getValue()+"\"" )){
1042 14 kreverch
                                if ( outErr.length() ==0){
1043 14 kreverch
                                        log.debug(this.getOutCmd());
1044 14 kreverch
                                }else{
1045 14 kreverch
                                        log.debug("zdsdelIscsi Error : " +outErr);
1046 14 kreverch
                                        if ( outErr.toString().contains("in use")){
1047 14 kreverch
                                                error.put("binzfsdeliscsi", outErr.toString() );
1048 14 kreverch
                                        }else{
1049 14 kreverch
                                                error.put("binzfsdeliscsi", outErr+"\n"+"Incoherence : Please connect you to server and launch manualy "+this.getZserver().zProperties.get("binzfsdeliscsi").getValue() );
1050 14 kreverch
                                        }
1051 14 kreverch
                                }
1052 14 kreverch
                        }
1053 14 kreverch
                }
1054 14 kreverch
1055 14 kreverch
        }
1056 14 kreverch
1057 14 kreverch
1058 14 kreverch
        public void zfsClone(){
1059 14 kreverch
                error.clear();
1060 14 kreverch
                if ("".equals(this.getZvol().zProperties.get("name").getValue())){
1061 14 kreverch
                        error.put("name", "Please, select a volume or filesystem to clone" );
1062 14 kreverch
                }
1063 14 kreverch
1064 14 kreverch
                if ( error.size() ==0){
1065 14 kreverch
                        String cmd = this.getZserver().zProperties.get("binzfsclone").getValue()+" -n "+this.getZvol().zProperties.get("name").getValue();
1066 14 kreverch
                        if (  this.executeCmd(cmd)){
1067 14 kreverch
                                if ( outErr.length() ==0){
1068 14 kreverch
                                        log.debug(this.getOutCmd());
1069 14 kreverch
                                        String[] TsplitOut = this.getOutCmd().split("\n");
1070 14 kreverch
                                        if (TsplitOut.length>0){
1071 14 kreverch
                                                String[] TsplitLine = TsplitOut[0].split("name:");
1072 14 kreverch
                                                if (TsplitLine.length>0){
1073 14 kreverch
                                                        this.zfsGetAllVolume(TsplitLine[1]);
1074 14 kreverch
                                                        if ("".equalsIgnoreCase(this.getZvol().zProperties.get("name").getValue())){
1075 14 kreverch
                                                                error.put("zfsclone", "Clone Creation failed");
1076 14 kreverch
                                                        }
1077 14 kreverch
                                                }
1078 14 kreverch
                                        }
1079 14 kreverch
                                }else{
1080 14 kreverch
                                        if (outErr.length()>0){
1081 14 kreverch
                                                error.put("zfsclone", outErr);
1082 14 kreverch
                                        }
1083 14 kreverch
                                }
1084 14 kreverch
                        }
1085 14 kreverch
                }
1086 14 kreverch
        }
1087 14 kreverch
1088 14 kreverch
1089 14 kreverch
        public float convertInReferenceUnit(String value2Convert, String refUnit){
1090 14 kreverch
1091 14 kreverch
                float convertedValue=0;
1092 21 kreverch
                value2Convert = value2Convert.replace(",", ".");
1093 14 kreverch
                log.debug("convertInReferenceUnit "+value2Convert+" "+refUnit);
1094 14 kreverch
                if ( refUnit.equalsIgnoreCase("T")){
1095 14 kreverch
                        if (value2Convert.contains("T")){
1096 14 kreverch
                                convertedValue=Float.valueOf(value2Convert.substring(0, (value2Convert.length()-1)));
1097 14 kreverch
                        }else{
1098 14 kreverch
                                if (value2Convert.contains("G")){
1099 14 kreverch
                                        convertedValue=(Float.valueOf(value2Convert.substring(0, (value2Convert.length()-1)))/1024);
1100 14 kreverch
                                }else{
1101 14 kreverch
                                        if (value2Convert.contains("M")){
1102 14 kreverch
                                                convertedValue=(Float.valueOf(value2Convert.substring(0, (value2Convert.length()-1)))/1048576);
1103 14 kreverch
                                        }else{
1104 14 kreverch
                                                if (value2Convert.contains("K")){
1105 14 kreverch
                                                        convertedValue=(Float.valueOf(value2Convert.substring(0, (value2Convert.length()-1)))/1073741824);
1106 14 kreverch
                                                }
1107 14 kreverch
                                        }
1108 14 kreverch
                                }
1109 14 kreverch
                        }
1110 14 kreverch
1111 14 kreverch
                }
1112 14 kreverch
1113 14 kreverch
                if ( refUnit.equalsIgnoreCase("G")){
1114 14 kreverch
                        if (value2Convert.contains("G")){
1115 14 kreverch
                                convertedValue=(Float.valueOf(value2Convert.substring(0, (value2Convert.length()-1))));
1116 14 kreverch
                        }else{
1117 14 kreverch
                                if (value2Convert.contains("T")){
1118 14 kreverch
                                        convertedValue=(Float.valueOf(value2Convert.substring(0, (value2Convert.length()-1)))*1024);
1119 14 kreverch
                                }else{
1120 14 kreverch
                                        if (value2Convert.contains("M")){
1121 14 kreverch
                                                convertedValue=(Float.valueOf(value2Convert.substring(0, (value2Convert.length()-1)))/1024);
1122 14 kreverch
                                        }else{
1123 14 kreverch
                                                if (value2Convert.contains("K")){
1124 14 kreverch
                                                        convertedValue=(Float.valueOf(value2Convert.substring(0, (value2Convert.length()-1)))/1048576);
1125 14 kreverch
                                                }
1126 14 kreverch
                                        }
1127 14 kreverch
                                }
1128 14 kreverch
                        }
1129 14 kreverch
                }
1130 14 kreverch
                log.debug("getZpoolProvisionedSpace "+convertedValue);
1131 14 kreverch
                return convertedValue;
1132 14 kreverch
        }
1133 14 kreverch
1134 14 kreverch
        public List<Object> zfsList(){
1135 14 kreverch
                zfsList.clear();
1136 14 kreverch
1137 14 kreverch
1138 14 kreverch
                if (  this.executeCmd("/sbin/zfs list -H") ){
1139 14 kreverch
                        String[] Tsplit = this.getOutCmd().split("\n");
1140 14 kreverch
                        for (int cpt=0;cpt<Tsplit.length;cpt++){
1141 14 kreverch
                                log.debug(Tsplit[cpt].split("\\s+")[0] );
1142 14 kreverch
                                zfsList.add(Tsplit[cpt].split("\\s+")[0]);
1143 14 kreverch
                                //zpoolNames[ind] = Tsplit[cpt].split("\\s+")[0];
1144 14 kreverch
                        }
1145 14 kreverch
                }
1146 14 kreverch
                return zfsList;
1147 14 kreverch
        }
1148 14 kreverch
1149 14 kreverch
1150 14 kreverch
        public boolean addServer(){
1151 14 kreverch
1152 14 kreverch
                if (!"".equalsIgnoreCase(this.getZserver().zProperties.get("serverIP").getValue())) {
1153 14 kreverch
                        this.getZserver().add(System.getProperty("user.home")+prop.getProperty("serverConfDir")+this.getZserver().zProperties.get("serverIP").getValue()+".properties");
1154 14 kreverch
1155 14 kreverch
                }else{
1156 14 kreverch
                        return false;
1157 14 kreverch
                }
1158 14 kreverch
                return true;
1159 14 kreverch
        }
1160 14 kreverch
1161 14 kreverch
        public boolean removeServer(){
1162 14 kreverch
                if (!"".equalsIgnoreCase(this.getZserver().zProperties.get("serverIP").getValue())) {
1163 14 kreverch
                        this.getZserver().remove(System.getProperty("user.home")+prop.getProperty("serverConfDir")+this.getZserver().zProperties.get("serverIP").getValue()+".properties");
1164 14 kreverch
                        this.getCacheSession().remove(this.getZserver().zProperties.get("serverIP").getValue());
1165 14 kreverch
                }
1166 14 kreverch
                return false;
1167 14 kreverch
        }
1168 14 kreverch
1169 14 kreverch
        public List<Object> getListServer(){
1170 14 kreverch
                String dirName = System.getProperty("user.home")+prop.getProperty("serverConfDir");
1171 14 kreverch
                log.debug(System.getProperty("user.home")+prop.getProperty("serverConfDir"));
1172 14 kreverch
                File dir = new File(dirName);
1173 14 kreverch
                if ( !dir.exists()){
1174 14 kreverch
                        dir.mkdir();
1175 14 kreverch
                        log.debug((System.getProperty("user.home")+prop.getProperty("serverConfDir")));
1176 14 kreverch
                }
1177 14 kreverch
                log.debug((System.getProperty("user.home")+prop.getProperty("serverConfDir")));
1178 14 kreverch
                File f = new File(System.getProperty("user.home")+prop.getProperty("serverConfDir"));
1179 14 kreverch
                log.debug((System.getProperty("user.home")+prop.getProperty("serverConfDir")));
1180 14 kreverch
                File[] list = f.listFiles();
1181 14 kreverch
                List<Object> listServer = new ArrayList<Object>();
1182 14 kreverch
                for (int i=0;i<list.length;i++){
1183 14 kreverch
                        listServer.add(list[i].getName().split(".properties")[0]);
1184 14 kreverch
                }
1185 14 kreverch
                return listServer;
1186 14 kreverch
        }
1187 14 kreverch
1188 14 kreverch
        public void getServer(String serverName){
1189 14 kreverch
                this.getZserver().load(System.getProperty("user.home")+prop.getProperty("serverConfDir")+serverName+".properties");
1190 14 kreverch
                String[] keysProp = (String[]) this.getZserver().zProperties.keySet().toArray(new String[0]);
1191 14 kreverch
                Arrays.sort(keysProp);
1192 14 kreverch
                error.clear();
1193 14 kreverch
                for ( int i=0;i<keysProp.length;i++){
1194 14 kreverch
                        String keyProp = keysProp[i];
1195 14 kreverch
                        if (prop.containsKey(keyProp)){
1196 14 kreverch
                                this.getZserver().zProperties.get(keyProp).setValue(prop.getProperty(keyProp));
1197 14 kreverch
                        }
1198 14 kreverch
1199 14 kreverch
                }
1200 14 kreverch
        }
1201 14 kreverch
1202 14 kreverch
        public void checkBinEnv(){
1203 14 kreverch
                String[] keysProp = (String[]) this.getZserver().zProperties.keySet().toArray(new String[0]);
1204 14 kreverch
                Arrays.sort(keysProp);
1205 14 kreverch
                error.clear();
1206 14 kreverch
                for ( int i=0;i<keysProp.length;i++){
1207 14 kreverch
                        String keyProp = keysProp[i];
1208 14 kreverch
                        if ( !keyProp.equalsIgnoreCase("serverIP") && !keyProp.equalsIgnoreCase("userLogin") && !keyProp.equalsIgnoreCase("userPasswd")&&!keyProp.equalsIgnoreCase("pathzfsvoldevice")){
1209 14 kreverch
                                if (  this.executeCmd(prop.getProperty(keyProp)) && ! outErr.toString().contains("No such file or directory")){
1210 14 kreverch
                                        log.debug(prop.getProperty(keyProp));
1211 14 kreverch
                                        log.debug("checkBinEnv "+outErr.toString().contains("No such file or directory"));
1212 14 kreverch
                                }else{
1213 14 kreverch
                                        error.put(keyProp, outErr.toString());
1214 14 kreverch
                                }
1215 14 kreverch
                        }
1216 14 kreverch
                }
1217 14 kreverch
        }
1218 14 kreverch
1219 14 kreverch
        public void loadConfig(){
1220 14 kreverch
1221 14 kreverch
                try {
1222 14 kreverch
                        InputStream resource = getClass().getResourceAsStream("config.properties");
1223 14 kreverch
1224 14 kreverch
                        prop.load(resource);
1225 14 kreverch
                        log.debug(prop);
1226 14 kreverch
                } catch (FileNotFoundException e) {
1227 14 kreverch
                        // TODO Auto-generated catch block
1228 14 kreverch
                        e.printStackTrace();
1229 14 kreverch
                } catch (IOException e) {
1230 14 kreverch
                        // TODO Auto-generated catch block
1231 14 kreverch
                        e.printStackTrace();
1232 14 kreverch
                }
1233 14 kreverch
        }
1234 14 kreverch
        public String getUserPassword() {
1235 14 kreverch
                return userPassword;
1236 14 kreverch
        }
1237 14 kreverch
1238 14 kreverch
1239 14 kreverch
1240 14 kreverch
        public void setUserPassword(String userPassword) {
1241 14 kreverch
                this.userPassword = userPassword;
1242 14 kreverch
        }
1243 14 kreverch
1244 14 kreverch
1245 14 kreverch
1246 14 kreverch
        public String getUserLogin() {
1247 14 kreverch
                return userLogin;
1248 14 kreverch
        }
1249 14 kreverch
1250 14 kreverch
1251 14 kreverch
1252 14 kreverch
        public void setUserLogin(String userLogin) {
1253 14 kreverch
                this.userLogin = userLogin;
1254 14 kreverch
        }
1255 14 kreverch
1256 14 kreverch
1257 14 kreverch
1258 14 kreverch
        public String getSshHost() {
1259 14 kreverch
                return sshHost;
1260 14 kreverch
        }
1261 14 kreverch
1262 14 kreverch
1263 14 kreverch
1264 14 kreverch
        public void setSshHost(String sshHost) {
1265 14 kreverch
                this.sshHost = sshHost;
1266 14 kreverch
        }
1267 14 kreverch
1268 14 kreverch
1269 14 kreverch
1270 14 kreverch
        public int getSshPort() {
1271 14 kreverch
                return sshPort;
1272 14 kreverch
        }
1273 14 kreverch
1274 14 kreverch
1275 14 kreverch
1276 14 kreverch
        public void setSshPort(int sshPort) {
1277 14 kreverch
                this.sshPort = sshPort;
1278 14 kreverch
        }
1279 14 kreverch
1280 14 kreverch
        public String getOutCmd() {
1281 14 kreverch
                return outCmd;
1282 14 kreverch
        }
1283 14 kreverch
1284 14 kreverch
        public void setOutCmd(String out) {
1285 14 kreverch
                this.outCmd=out;
1286 14 kreverch
        }
1287 14 kreverch
1288 14 kreverch
        public Session getSession() {
1289 14 kreverch
                return session;
1290 14 kreverch
        }
1291 14 kreverch
1292 14 kreverch
        public void setSession(Session session) {
1293 14 kreverch
                this.session = session;
1294 14 kreverch
        }
1295 14 kreverch
1296 14 kreverch
        /**
1297 14 kreverch
         * @return the zSnapshot
1298 14 kreverch
         */
1299 14 kreverch
        public zsnapshots getZsnapshots() {
1300 14 kreverch
                return zsnapshots;
1301 14 kreverch
        }
1302 14 kreverch
1303 14 kreverch
        /**
1304 14 kreverch
         * @param zSnapshot the zSnapshot to set
1305 14 kreverch
         */
1306 14 kreverch
        public void setZsnapshots() {
1307 14 kreverch
                this.zsnapshots = new zsnapshots();
1308 14 kreverch
        }
1309 14 kreverch
1310 14 kreverch
        public zreplicas getZreplicas() {
1311 14 kreverch
                return zreplicas;
1312 14 kreverch
        }
1313 14 kreverch
1314 14 kreverch
        public void setZreplicas() {
1315 14 kreverch
                this.zreplicas = new zreplicas();
1316 14 kreverch
        }
1317 14 kreverch
1318 14 kreverch
        /**
1319 14 kreverch
         * @return the ziscsi
1320 14 kreverch
         */
1321 14 kreverch
        public ziscsi getZiscsi() {
1322 14 kreverch
                return ziscsi;
1323 14 kreverch
        }
1324 14 kreverch
1325 14 kreverch
        /**
1326 14 kreverch
         * @param ziscsi the ziscsi to set
1327 14 kreverch
         */
1328 14 kreverch
        public void setZiscsi() {
1329 14 kreverch
                this.ziscsi = new ziscsi();
1330 14 kreverch
        }
1331 14 kreverch
1332 14 kreverch
        /**
1333 14 kreverch
         * @return the zserver
1334 14 kreverch
         */
1335 14 kreverch
        public zserver getZserver() {
1336 14 kreverch
                return zserver;
1337 14 kreverch
        }
1338 14 kreverch
1339 14 kreverch
        /**
1340 14 kreverch
         * @param zserver the zserver to set
1341 14 kreverch
         */
1342 14 kreverch
        public void setZserver() {
1343 14 kreverch
                this.zserver = new zserver();
1344 14 kreverch
        }
1345 14 kreverch
1346 14 kreverch
        /**
1347 14 kreverch
         * @return the cacheSession
1348 14 kreverch
         */
1349 14 kreverch
        public Hashtable<String,Session> getCacheSession() {
1350 14 kreverch
                return cacheSession;
1351 14 kreverch
        }
1352 14 kreverch
1353 14 kreverch
        /**
1354 14 kreverch
         * @param cacheSession the cacheSession to set
1355 14 kreverch
         */
1356 14 kreverch
        public void setCacheSession(Hashtable<String,Session> cacheSession) {
1357 14 kreverch
                this.cacheSession = cacheSession;
1358 14 kreverch
        }
1359 14 kreverch
1360 14 kreverch
        /**
1361 14 kreverch
         * @return the zpool
1362 14 kreverch
         */
1363 14 kreverch
        public zpool getZpool() {
1364 14 kreverch
                return zpool;
1365 14 kreverch
        }
1366 14 kreverch
1367 14 kreverch
        /**
1368 14 kreverch
         * @param zpool the zpool to set
1369 14 kreverch
         */
1370 14 kreverch
        public void setZpool() {
1371 14 kreverch
                this.zpool = new zpool();
1372 14 kreverch
        }
1373 14 kreverch
1374 14 kreverch
1375 14 kreverch
        public zdisk getZdisk() {
1376 14 kreverch
                return zdisk;
1377 14 kreverch
        }
1378 14 kreverch
1379 14 kreverch
        public void setZdisk() {
1380 14 kreverch
                this.zdisk = new zdisk();
1381 14 kreverch
        }
1382 14 kreverch
1383 14 kreverch
        /**
1384 14 kreverch
         * @return the error
1385 14 kreverch
         */
1386 14 kreverch
        public Hashtable<String,Object> getError() {
1387 14 kreverch
                return error;
1388 14 kreverch
        }
1389 14 kreverch
1390 14 kreverch
        /**
1391 14 kreverch
         * @param error the error to set
1392 14 kreverch
         */
1393 14 kreverch
        public void setError(Hashtable<String,Object> error) {
1394 14 kreverch
                this.error = error;
1395 14 kreverch
        }
1396 14 kreverch
1397 14 kreverch
        public Hashtable<String, zdisk> getHashDisks() {
1398 14 kreverch
                return hashDisks;
1399 14 kreverch
        }
1400 14 kreverch
1401 14 kreverch
        public void setHashDisks(Hashtable<String, zdisk> hashDisks) {
1402 14 kreverch
                this.hashDisks = hashDisks;
1403 14 kreverch
        }
1404 14 kreverch
1405 14 kreverch
        public zraid getZraid() {
1406 14 kreverch
                return zraid;
1407 14 kreverch
        }
1408 14 kreverch
1409 14 kreverch
        public void setZraid() {
1410 14 kreverch
                this.zraid = new zraid();
1411 14 kreverch
        }
1412 14 kreverch
1413 14 kreverch
1414 14 kreverch
1415 14 kreverch
        public Hashtable<String, zraid> getHashZRaid() {
1416 14 kreverch
                return hashZRaid;
1417 14 kreverch
        }
1418 14 kreverch
1419 14 kreverch
        public void setHashZRaid(Hashtable<String, zraid> hashZRaid) {
1420 14 kreverch
                this.hashZRaid = hashZRaid;
1421 14 kreverch
        }
1422 14 kreverch
1423 14 kreverch
}