田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.vci.client.volumn;
 
import com.vci.client.common.providers.ServiceProvider;
import com.vci.corba.common.VCIError;
//import com.vci.corba.framework.method.VolumeManagerPrx;
import com.vci.corba.volume.VolumeServicePrx;
import com.vci.corba.framework.data.PvolumeInfo;
 
/**
 * <p>Title: 卷服务Session</p>
 * <p>Description: 获取卷服务的工厂,并通过工厂获取系统提供的卷服务</p>
 * <p>Copyright: Copyright (c) 2011</p>
 * <p>Company: VCI</p>
 * @author Administrator
 * @time 2011-7-3
 * @version 1.0
 */
public class VolumnSession {
 
//    private static VolumeManagerPrx VF = null;
//    private static VolumeServicePrx volumeService = null;
    
//    static
//    {
//        try
//        { 
//            VF = ServiceProvider.getVolumeManager();
//        }
//        catch(Exception e)
//        {
//            e.printStackTrace();
//        }
//    }
    
 
    public static PvolumeInfo getVolumnInfo(String volName)
            throws Exception {
        try {
            PvolumeInfo[] vols = ServiceProvider.getFrameService().getAllPvolumes();
            for (PvolumeInfo vol : vols) {
                if (volName.equalsIgnoreCase(vol.name))
                    return vol;
            }
 
            return new PvolumeInfo();
        } catch (VCIError ve) {
            ve.printStackTrace();
            throw ve;
        }
    }
    
//    public static VolumnService getVolumnService() throws VCIError{
//        try {
//            if (volumnService == null) {
//                volumnService = VF.getVolumnService();
//            } 
//            return volumnService; 
//        } catch (VCIError ve) {
//            throw ve;
//        }
//    }
    
    public static VolumeServicePrx getVolumnService(String serviceName) throws VCIError{
        try {
            VolumeServicePrx vs = ServiceProvider.getVolumeService(serviceName);
            
            return vs; 
        } catch (Exception e) {
            // TODO Auto-generated catch block
            throw new VCIError("VolumnSession-001", new String[] {e.getMessage()});
        }
    }
    
    public static VolumeServicePrx getVolumnServiceByVolumn(String volName) throws VCIError{
        try {
            PvolumeInfo[] vols = ServiceProvider.getFrameService().getAllPvolumes();
            
            String serviceName = "";
            for (PvolumeInfo vol : vols) {
                if (vol.name.equalsIgnoreCase(volName)){
                    serviceName = vol.service;
                    break;
                }
            }
            
            if (serviceName.isEmpty())
                throw new VCIError("VolumnSession-002", new String[] {"卷对应的卷服务为空,请修改卷配置!"});
            
            return getVolumnService(serviceName);
 
            //return vm; 
        } catch (VCIError ve) {
            throw ve;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            throw new VCIError("VolumnSession-003", new String[] {e.getMessage()});
        }
    }
 
}