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 2001-2002 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 package com.sun.wbem.solarisprovider.srm; 27 28 import javax.wbem.cim.*; 29 import javax.wbem.client.*; 30 import javax.wbem.provider.*; 31 32 import java.util.Enumeration; 33 import java.util.Iterator; 34 import java.util.Vector; 35 36 37 /** 38 * Provider of the Solaris_ProcessStatistics class. This class represents 39 * an association linking a Solaris_Process and its 40 * Solaris_ProcessStatisticalInformation instance a raw resource utilization 41 * measurements for a process. 42 * @author Sun Microsystems, Inc. 43 */ 44 public class Solaris_ProcessStatistics extends SRMProvider { 45 46 /** 47 * The name of the provider implemented by this class 48 */ 49 String providerName = SOLARIS_PROCESSSTATISTICS; 50 51 private DataModel dm; 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 instance. 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 synchronized CIMInstance getInstance(CIMObjectPath op, 83 boolean localOnly, 84 boolean includeQualifiers, 85 boolean includeClassOrigin, 86 String[] propList, 87 CIMClass cc) 88 throws CIMException { 89 90 CIMObjectPath procstatCOP = null; 91 CIMObjectPath procCOP = null; 92 CIMInstance ci = null; 93 CIMProperty cp = null; 94 95 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 96 try { 97 Enumeration e = op.getKeys().elements(); 98 while (e.hasMoreElements()) { 99 cp = (CIMProperty) e.nextElement(); 100 if (cp.getName().equalsIgnoreCase(ELEMENT)) { 101 procCOP = (CIMObjectPath)((CIMValue)(cp.getValue())). 102 getValue(); 103 } 104 if (cp.getName().equalsIgnoreCase(STATS)) { 105 procstatCOP = (CIMObjectPath)((CIMValue)(cp.getValue())). 106 getValue(); 107 } 108 } 109 110 ci = cc.newInstance(); 111 ci.setProperty(ELEMENT, new CIMValue(procCOP)); 112 ci.setProperty(STATS, new CIMValue(procstatCOP)); 113 114 } catch (Exception e) { 115 String msg = writeLog(LOGERROR, "SRM_1001"); 116 writeLog(LOGERROR, e); 117 msg += " (" + e.getClass().toString() + ")"; 118 SRMDebug.trace1(providerName, e); 119 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 120 } 121 SRMDebug.trace(SRMDebug.METHOD_RETV, ci.toString()); 122 return ci; 123 124 } // end getInstance 125 126 127 /** 128 * Returns all instances of Solaris_ProcessStatistics. 129 * @param op - the object path specifies the class to be enumerated 130 * localOnly - if true, only the local properties of the class are returned, 131 * otherwise all properties are required 132 * @param includeQualifiers - if true, the qualifiers are returned as part 133 * of of the returned instancei, otherwise no qualifiers will be returned 134 * @param includeClassOrigin - if true, the class origin of each property 135 * will be returned 136 * @param String[] - if null, all properties are returned, otherwise only 137 * the properties specified will be 138 * returned. Any duplicate properties will be ignored. 139 * @param cc - the class reference 140 * @return An array of CIMInstance 141 * @exception CIMException - if the CIMObjectPath is incorrect or does not 142 * exist. 143 */ 144 public synchronized CIMInstance[] enumerateInstances(CIMObjectPath op, 145 boolean localOnly, 146 boolean includeQualifiers, 147 boolean includeClassOrigin, 148 String[] propList, 149 CIMClass cc) 150 throws CIMException { 151 152 Vector installedElements = new Vector(); 153 ProcessDataModel pdm; 154 CIMObjectPath procstatCOP; 155 CIMObjectPath procCOP; 156 CIMInstance ci; 157 DataModel dm = null; 158 159 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 160 try { 161 dm = resourceMonitor.getDataModel(false); 162 Iterator i = dm.getProcessIterator(); 163 while (i.hasNext()) { 164 pdm = (ProcessDataModel)i.next(); 165 procstatCOP = pdm.getCIMObjectPath( 166 SOLARIS_PROCESSSTATISTICALINFORMATION); 167 procCOP = pdm.getCIMObjectPathForProc(); 168 ci = cc.newInstance(); 169 ci.setProperty(ELEMENT, new CIMValue(procCOP)); 170 ci.setProperty(STATS, new CIMValue(procstatCOP)); 171 installedElements.addElement(ci); 172 } 173 dm = resourceMonitor.releaseDataModel(dm); 174 } catch (Exception e) { 175 dm = resourceMonitor.releaseDataModel(dm); 176 String msg = writeLog(LOGERROR, "SRM_1002"); 177 writeLog(LOGERROR, e); 178 msg += " (" + e.getClass().toString() + ")"; 179 SRMDebug.trace1(providerName, e); 180 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 181 } 182 183 CIMInstance[] ciArray = new CIMInstance[installedElements.size()]; 184 installedElements.toArray(ciArray); 185 SRMDebug.trace(SRMDebug.METHOD_RETV, "instance[0]: " 186 + (String)(ciArray.length > 0 ? ciArray[0].toString() : "null")); 187 return ciArray; 188 189 } // end enumerateInstances 190 191 192 /** 193 * Returns the names of all Solaris_ProcessUtilizationInformation instances. 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 synchronized CIMObjectPath[] 202 enumerateInstanceNames(CIMObjectPath op, CIMClass cc) 203 throws CIMException { 204 205 Vector installedElements = new Vector(); 206 ProcessDataModel pdm; 207 CIMObjectPath procstatCOP; 208 CIMObjectPath procCOP; 209 CIMObjectPath cop; 210 211 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 212 try { 213 dm = resourceMonitor.getDataModel(false); 214 Iterator i = dm.getProcessIterator(); 215 while (i.hasNext()) { 216 pdm = (ProcessDataModel) i.next(); 217 procstatCOP = pdm.getCIMObjectPath( 218 SOLARIS_PROCESSSTATISTICALINFORMATION); 219 procCOP = pdm.getCIMObjectPathForProc(); 220 cop = new CIMObjectPath(op.getObjectName(), 221 op.getNameSpace()); 222 cop.addKey(ELEMENT, new CIMValue(procCOP)); 223 cop.addKey(STATS, new CIMValue(procstatCOP)); 224 installedElements.add(cop); 225 } 226 dm = resourceMonitor.releaseDataModel(dm); 227 } catch (Exception e) { 228 dm = resourceMonitor.releaseDataModel(dm); 229 String msg = writeLog(LOGERROR, "SRM_1003"); 230 writeLog(LOGERROR, e); 231 msg += " (" + e.getClass().toString() + ")"; 232 SRMDebug.trace1(providerName, e); 233 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 234 } 235 236 CIMObjectPath[] copArray = new CIMObjectPath[installedElements.size()]; 237 installedElements.toArray(copArray); 238 SRMDebug.trace(SRMDebug.METHOD_RETV, "instanceName[0]: " 239 + (String)(copArray.length > 0 ? copArray[0].toString() : "null")); 240 return copArray; 241 242 } // end enumerateInstanceNames 243 244 } // end class Solaris_ProcessStatistics 245