~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/juti/test/com/sun/grid/TestConfiguration.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 *
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 *
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 *
 
9
 *
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 *
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 *
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 *
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 *
 
28
 *   All Rights Reserved.
 
29
 *
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
package com.sun.grid;
 
33
 
 
34
import java.io.File;
 
35
import java.io.FileInputStream;
 
36
import java.io.IOException;
 
37
import java.util.Iterator;
 
38
import java.util.Properties;
 
39
 
 
40
/**
 
41
 *
 
42
 */
 
43
public class TestConfiguration {
 
44
    
 
45
    private File catop;
 
46
    private File calocaltop;
 
47
    private File cascript;
 
48
    private String adminUser;
 
49
    private Properties props = new Properties();
 
50
    
 
51
    private static TestConfiguration theInstance;
 
52
    public synchronized static TestConfiguration getInstance() throws IOException {
 
53
        if(theInstance == null) {
 
54
            theInstance = new TestConfiguration();
 
55
        }
 
56
        return theInstance;
 
57
    }
 
58
    
 
59
    protected TestConfiguration() throws IOException {
 
60
        
 
61
        File file = new File("test/TestConfiguration.properties".replace('/', File.separatorChar));
 
62
        props.load(new FileInputStream(file));
 
63
        
 
64
        File privFile = new File("test/TestConfiguration_private.properties".replace('/', File.separatorChar));
 
65
        
 
66
        if(privFile.exists()) {
 
67
            
 
68
            Properties privProps = new Properties();
 
69
            privProps.load(new FileInputStream(privFile));
 
70
            
 
71
            Iterator iter = privProps.keySet().iterator();
 
72
            while(iter.hasNext()) {
 
73
                Object prop = iter.next();
 
74
                props.put(prop, privProps.get(prop));
 
75
            }
 
76
        }  
 
77
        
 
78
        String fileProp = System.getProperty(getClass().getName() + ".file");
 
79
        if(fileProp != null) {
 
80
            Properties fileProps = new Properties();
 
81
            fileProps.load(new FileInputStream(fileProp));
 
82
            
 
83
            Iterator iter = fileProps.keySet().iterator();
 
84
            while(iter.hasNext()) {
 
85
                Object prop = iter.next();
 
86
                props.put(prop, fileProps.get(prop));
 
87
            }
 
88
        }
 
89
        
 
90
    }
 
91
    
 
92
    private File getFileFromConfig(String key) {
 
93
        String str = props.getProperty(key);
 
94
        if(str == null) {
 
95
            throw new IllegalArgumentException(key + " is not defined in test configuration");
 
96
        }
 
97
        return new File(str);
 
98
    }
 
99
    
 
100
    public File getCatop() {
 
101
        if(catop == null) {
 
102
            String str = getCell() + "common/sgeCA";
 
103
            catop = new File(getSgeRoot(), str.replace('/', File.separatorChar) );
 
104
        }
 
105
        return catop;
 
106
    }
 
107
    
 
108
    public File getCaLocalTop() {
 
109
        if(calocaltop == null) {
 
110
            String str = "/var/sgeCA/port" + getQMasterPort() + "/" + getCell();
 
111
            calocaltop = new File(str.replace('/', File.pathSeparatorChar));
 
112
        }
 
113
        return calocaltop;
 
114
    }
 
115
    
 
116
    public File getCaScript() {
 
117
        if(cascript == null) {
 
118
            cascript = new File(getSgeRoot(), "util/sgeCA/sge_ca".replace('/', File.separatorChar));
 
119
        }
 
120
        return cascript;
 
121
    }
 
122
    
 
123
    
 
124
    private int qmasterPort = -1;
 
125
    public int getQMasterPort() {
 
126
        if(qmasterPort < 0) {
 
127
            qmasterPort = Integer.parseInt(props.getProperty("sge_qmaster_port"));
 
128
        }
 
129
        return qmasterPort;
 
130
    }
 
131
    
 
132
    public String getAdminUser() {
 
133
        if(adminUser == null) {
 
134
            adminUser = props.getProperty("adminuser");
 
135
        }
 
136
        return adminUser;
 
137
    }
 
138
    
 
139
    public String getTestUser() {
 
140
        return props.getProperty("testuser");
 
141
    }
 
142
    
 
143
    public char [] getTestUserPassword() {
 
144
        String pw = props.getProperty("testuser_pw");
 
145
        if(pw != null) {
 
146
            return pw.toCharArray();
 
147
        }
 
148
        return null;
 
149
    }
 
150
    
 
151
    public String getUserVerifier() {
 
152
        return props.getProperty("userverifier");
 
153
    }
 
154
    
 
155
    public String getPamService() {
 
156
        return props.getProperty("pam_service");
 
157
    }
 
158
    
 
159
    private File sgeRoot;
 
160
    
 
161
    public File getSgeRoot() {
 
162
        if(sgeRoot == null) {
 
163
            sgeRoot = new File(props.getProperty("sge_root"));
 
164
        }
 
165
        return sgeRoot;
 
166
    }
 
167
    
 
168
    private String cell;
 
169
    
 
170
    public String getCell() {
 
171
        if(cell == null) {
 
172
            cell = props.getProperty("sge_cell");
 
173
        }
 
174
        return cell;
 
175
    }
 
176
}