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

« back to all changes in this revision

Viewing changes to source/libs/jgdi/test/com/sun/grid/jgdi/monitoring/TestClusterQueueSummary.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.jgdi.monitoring;
 
33
 
 
34
import com.sun.grid.jgdi.monitoring.filter.QueueStateFilter;
 
35
import com.sun.grid.jgdi.monitoring.filter.ResourceFilter;
 
36
import java.util.List;
 
37
import junit.framework.Test;
 
38
import junit.framework.TestSuite;
 
39
import com.sun.grid.jgdi.JGDI;
 
40
import com.sun.grid.jgdi.monitoring.filter.UserFilter;
 
41
import com.sun.grid.jgdi.configuration.ClusterQueue;
 
42
import com.sun.grid.jgdi.configuration.ConfigurationFactory;
 
43
import com.sun.grid.jgdi.configuration.UserSet;
 
44
 
 
45
 
 
46
/**
 
47
 *
 
48
 */
 
49
public class TestClusterQueueSummary extends com.sun.grid.jgdi.BaseTestCase {
 
50
    
 
51
    /** Creates a new instance of TestQHost */
 
52
    public TestClusterQueueSummary(String testName) {
 
53
        super(testName);
 
54
    }
 
55
    
 
56
    public static Test suite() {
 
57
        TestSuite suite = new TestSuite(TestClusterQueueSummary.class);
 
58
        return suite;
 
59
    }
 
60
    
 
61
    private void printResult(List<ClusterQueueSummary> result) {
 
62
        
 
63
        logger.fine("CLUSTER QUEUE CQLOAD   USED  AVAIL  TOTAL");
 
64
        StringBuilder buf = new StringBuilder();
 
65
        for (ClusterQueueSummary cqs : result) {
 
66
            buf.setLength(0);
 
67
            buf.append(cqs.getName());
 
68
            buf.append(" ");
 
69
            buf.append(cqs.isLoadSet() ? Double.toString(cqs.getLoad()) : "-NA-");
 
70
            buf.append(" ");
 
71
            buf.append(cqs.getUsedSlots());
 
72
            buf.append(" ");
 
73
            buf.append(cqs.getAvailableSlots());
 
74
            buf.append(" ");
 
75
            buf.append(cqs.getTotalSlots());
 
76
            logger.fine(buf.toString());
 
77
        }
 
78
    }
 
79
    
 
80
    public void testSimple() throws Exception {
 
81
        
 
82
        JGDI jgdi = createJGDI();
 
83
        try {
 
84
            ClusterQueueSummaryOptions options = new ClusterQueueSummaryOptions();
 
85
            List<ClusterQueueSummary> result = jgdi.getClusterQueueSummary(options);
 
86
            printResult(result);
 
87
        } finally {
 
88
            jgdi.close();
 
89
        }
 
90
    }
 
91
    
 
92
    public void testResourceFilter() throws Exception {
 
93
        
 
94
        JGDI jgdi = createJGDI();
 
95
        try {
 
96
            ClusterQueueSummaryOptions options = new ClusterQueueSummaryOptions();
 
97
            ResourceFilter rsf = new ResourceFilter();
 
98
            rsf.addResource("NoAccessUsers", "lx26-x86");
 
99
            options.setResourceFilter(rsf);
 
100
            List<ClusterQueueSummary> result = jgdi.getClusterQueueSummary(options);
 
101
            printResult(result);
 
102
        } finally {
 
103
            jgdi.close();
 
104
        }
 
105
    }
 
106
    
 
107
    public void testQueueStateFilter() throws Exception {
 
108
        
 
109
        JGDI jgdi = createJGDI();
 
110
        try {
 
111
            ClusterQueueSummaryOptions options = new ClusterQueueSummaryOptions();
 
112
            QueueStateFilter qsf = new QueueStateFilter();
 
113
            qsf.setAlarm(true);
 
114
            options.setQueueStateFilter(qsf);
 
115
            logger.fine("queueStateFiter: " + qsf);
 
116
            List<ClusterQueueSummary> result = jgdi.getClusterQueueSummary(options);
 
117
            printResult(result);
 
118
        } finally {
 
119
            jgdi.close();
 
120
        }
 
121
    }
 
122
    
 
123
    public void testQueueUserFilter() throws Exception {
 
124
        
 
125
        JGDI jgdi = createJGDI();
 
126
        try {
 
127
            ClusterQueueSummaryOptions options = new ClusterQueueSummaryOptions();
 
128
            UserSet userSet = ConfigurationFactory.createUserSet();
 
129
            userSet.setName("NoAccessUsers");
 
130
            userSet.addEntries("noaccess");
 
131
            jgdi.addUserSet(userSet);
 
132
            try {
 
133
                ClusterQueue cq = ConfigurationFactory.createClusterQueueWithDefaults();
 
134
                cq.setName("testQueueUserFilter");
 
135
                UserFilter uf = new UserFilter();
 
136
                uf.addUser("noaccess");
 
137
                jgdi.addClusterQueue(cq);
 
138
                
 
139
                try {
 
140
                    options.setQueueUserFilter(uf);
 
141
                    logger.fine("testQueueUserFilter for queue " + cq.getName());
 
142
                    List<ClusterQueueSummary> result = jgdi.getClusterQueueSummary(options);
 
143
                    printResult(result);
 
144
                } finally {
 
145
                    jgdi.deleteClusterQueue(cq);
 
146
                }
 
147
            } finally {
 
148
                jgdi.deleteUserSet(userSet);
 
149
            }
 
150
        } finally {
 
151
            jgdi.close();
 
152
        }
 
153
    }
 
154
}