1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2001 by Sun Microsystems, Inc. 23 * All rights reserved. 24 * 25 * Solaris_ActiveUserProcessAggregateStatistics.java 26 */ 27 28 29 package com.sun.wbem.solarisprovider.srm; 30 31 import javax.wbem.cim.*; 32 import javax.wbem.provider.*; 33 34 import java.util.Enumeration; 35 import java.util.Iterator; 36 import java.util.Vector; 37 38 39 /** 40 * Provider of the Solaris_ProjectProcessAggregateStatisticalInformation class. 41 * This class represents a link between an User active on a system and the 42 * aggregated resource usage of its Process(es). 43 * @author Sun Microsystems 44 */ 45 public class Solaris_ActiveUserProcessAggregateStatistics extends SRMProvider { 46 47 /** 48 * The name of the provider implemented by this class 49 */ 50 protected String providerName = 51 SOLARIS_ACTIVEUSERPROCESSAGGREGATESTATISTICS; 52 53 54 /** 55 * Get the name of the provider implemented by this class. 56 * @returns String provider name 57 */ 58 protected String getProviderName() { 59 return providerName; 60 } 61 62 63 /** 64 * Returns a specific CIMInstance 65 * @param op - the name of the instance to be retrieved. This must include 66 * all of the keys and values for the instance. 67 * @param localOnly - if true, only the local properties of the class are 68 * returned, otherwise all properties are required 69 * @param includeQualifiers - if true, the qualifiers are returned as part 70 * of of the returned instancei, otherwise no qualifiers will be returned 71 * @param includeClassOrigin - if true, the class origin of each property 72 * will be returned 73 * @param String[] - if null, all properties are returned, otherwise only 74 * the properties specified will be returned. Any duplicate properties will 75 * be ignored. 76 * @param cc - the class reference 77 * 78 * @return CIMInstance the retrieved instance. 79 * @exception CIMException - the method getInstance throws a CIMException 80 * if the CIMObjectPath is incorrect or does not exist. 81 */ 82 public CIMInstance getInstance(CIMObjectPath op, 83 boolean localOnly, 84 boolean includeQualifiers, 85 boolean includeClassOrigin, 86 String[] propList, 87 CIMClass cc) 88 throws CIMException { 89 90 91 CIMObjectPath procaggreCOP = null; 92 CIMObjectPath activeusrCOP = null; 93 CIMInstance ci = null; 94 CIMProperty cp; 95 96 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 97 try { 98 Enumeration e = op.getKeys().elements(); 99 while (e.hasMoreElements()) { 100 cp = (CIMProperty)e.nextElement(); 101 if (cp.getName().equalsIgnoreCase(ELEMENT)) { 102 activeusrCOP = (CIMObjectPath)((CIMValue)(cp.getValue())). 103 getValue(); 104 } 105 if (cp.getName().equalsIgnoreCase(STATS)) { 106 procaggreCOP = (CIMObjectPath)((CIMValue)(cp.getValue())). 107 getValue(); 108 } 109 } 110 111 ci = cc.newInstance(); 112 ci.setProperty(ELEMENT, new CIMValue(activeusrCOP)); 113 ci.setProperty(STATS, new CIMValue(procaggreCOP)); 114 115 } catch (Exception e) { 116 String msg = writeLog(LOGERROR, "SRM_1001"); 117 writeLog(LOGERROR, e); 118 msg += " (" + e.getClass().toString() + ")"; 119 SRMDebug.trace1(providerName, e); 120 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 121 } 122 SRMDebug.trace(SRMDebug.METHOD_RETV, ci.toString()); 123 return ci; 124 125 } // end getInstance 126 127 128 /** 129 * Enumerates all instances of Solaris_ActiveUserAggregateStatistics. 130 * @param op - the object path specifies the class to be enumerated 131 * localOnly - if true, only the local properties of the class are returned, 132 * otherwise all properties are required 133 * @param includeQualifiers - if true, the qualifiers are returned as part 134 * of of the returned instancei, otherwise no qualifiers will be returned 135 * @param includeClassOrigin - if true, the class origin of each property 136 * will be returned 137 * @param String[] - if null, all properties are returned, otherwise only 138 * the properties specified will be 139 * returned. Any duplicate properties will be ignored. 140 * @param cc - the class reference 141 * @return An array of CIMInstance 142 * @exception CIMException - if the CIMObjectPath is incorrect or does not 143 * exist. 144 */ 145 public CIMInstance[] enumerateInstances(CIMObjectPath op, 146 boolean localOnly, 147 boolean includeQualifiers, 148 boolean includeClassOrigin, 149 String[] propList, 150 CIMClass cc) 151 throws CIMException { 152 153 Vector installedElements = new Vector(); 154 DataModel dm = null; 155 ActiveUserModel aum; 156 CIMObjectPath procaggreCOP; 157 CIMObjectPath activeusrCOP; 158 CIMInstance ci; 159 160 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 161 try { 162 dm = resourceMonitor.getDataModel(false); 163 Iterator i = dm.getUserIterator(); 164 while (i.hasNext()) { 165 aum = (ActiveUserModel) i.next(); 166 activeusrCOP = aum.getCIMObjectPath(SOLARIS_ACTIVEUSER); 167 procaggreCOP = dm.getUserprocs(aum.name).getCIMObjectPath( 168 SOLARIS_USERPROCESSAGGREGATESTATISTICALINFORMATION); 169 ci = cc.newInstance(); 170 ci.setProperty(ELEMENT, new CIMValue(activeusrCOP)); 171 ci.setProperty(STATS, new CIMValue(procaggreCOP)); 172 installedElements.addElement(ci); 173 } 174 dm = resourceMonitor.releaseDataModel(dm); 175 } catch (Exception e) { 176 dm = resourceMonitor.releaseDataModel(dm); 177 String msg = writeLog(LOGERROR, "SRM_1002"); 178 writeLog(LOGERROR, e); 179 msg += " (" + e.getClass().toString() + ")"; 180 SRMDebug.trace1(providerName, e); 181 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 182 } 183 CIMInstance[] ciArray = new CIMInstance[installedElements.size()]; 184 installedElements.toArray(ciArray); 185 SRMDebug.trace(SRMDebug.METHOD_RETV, "instance[0]: " 186 + ciArray[0].toString()); 187 return ciArray; 188 189 } // end enumerateInstances 190 191 192 /** 193 * Returns all object paths 194 * 195 * @param op - the class name to enumerate the instances 196 * @param cc - the class reference passed to the provider 197 * @return an array of CIMObjectPath containing names of the enumerated 198 * instances. 199 * @exception CIMException - if the classname is null or does not exist. 200 */ 201 public CIMObjectPath[] enumerateInstanceNames(CIMObjectPath op, 202 CIMClass cc) 203 throws CIMException { 204 205 Vector installedElements = new Vector(); 206 DataModel dm = null; 207 ActiveUserModel aum; 208 CIMObjectPath procaggreCOP; 209 CIMObjectPath activeusrCOP; 210 CIMObjectPath cop; 211 212 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 213 try { 214 dm = resourceMonitor.getDataModel(false); 215 Iterator i = dm.getUserIterator(); 216 while (i.hasNext()) { 217 aum = (ActiveUserModel) i.next(); 218 activeusrCOP = aum.getCIMObjectPath(SOLARIS_ACTIVEUSER); 219 procaggreCOP = dm.getUserprocs(aum.name).getCIMObjectPath( 220 SOLARIS_USERPROCESSAGGREGATESTATISTICALINFORMATION); 221 cop = new CIMObjectPath(op.getObjectName(), 222 op.getNameSpace()); 223 cop.addKey(ELEMENT, new CIMValue(activeusrCOP)); 224 cop.addKey(STATS, new CIMValue(procaggreCOP)); 225 installedElements.add(cop); 226 } 227 dm = resourceMonitor.releaseDataModel(dm); 228 } catch (Exception e) { 229 dm = resourceMonitor.releaseDataModel(dm); 230 String msg = writeLog(LOGERROR, "SRM_1003"); 231 writeLog(LOGERROR, e); 232 msg += " (" + e.getClass().toString() + ")"; 233 SRMDebug.trace1(providerName, e); 234 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 235 } 236 237 CIMObjectPath[] copArray = new CIMObjectPath[installedElements.size()]; 238 installedElements.toArray(copArray); 239 SRMDebug.trace(SRMDebug.METHOD_RETV, "instanceName[0]: " 240 + copArray[0].toString()); 241 return copArray; 242 243 } // end enumerateInstanceNames 244 245 } // end class Solaris_ActiveUserProcessAggregateStatistics 246