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_ProcessStatisticalInformation.java 26 */ 27 28 29 package com.sun.wbem.solarisprovider.srm; 30 31 import javax.wbem.cim.*; 32 import javax.wbem.client.*; 33 import javax.wbem.provider.*; 34 import javax.wbem.query.*; 35 36 import java.util.Enumeration; 37 import java.util.Iterator; 38 import java.util.Vector; 39 40 41 /** 42 * Provider of the Solaris_ProcessStatisticalInformation class. 43 * This class provides raw resource utilization measurements for a process. 44 * @author Sun Microsystems 45 */ 46 public class Solaris_ProcessStatisticalInformation extends SRMProvider 47 implements Solaris_ProcessStatisticalInformationProperties { 48 49 50 /** 51 * The name of the provider implemented by this class 52 */ 53 protected String providerName = SOLARIS_PROCESSSTATISTICALINFORMATION; 54 55 56 /** 57 * Get the name of the provider implemented by this class. 58 * @returns String provider name 59 */ 60 protected String getProviderName() { 61 return providerName; 62 } 63 64 65 /** 66 * Returns an instance specified by the PID key. 67 * @param op - the name of the instance to be retrieved. This must include 68 * all of the keys and values for the instance. 69 * @param localOnly - if true, only the local properties of the class are 70 * returned, otherwise all properties are required 71 * @param includeQualifiers - if true, the qualifiers are returned as part 72 * of of the returned instancei, otherwise no qualifiers will be returned 73 * @param includeClassOrigin - if true, the class origin of each property 74 * will be returned 75 * @param String[] - if null, all properties are returned, otherwise only 76 * the properties specified will be returned. Any duplicate properties will 77 * be ignored. 78 * @param cc - the class reference 79 * 80 * @return CIMInstance the retrieved instance. 81 * @exception CIMException - the method getInstance throws a CIMException 82 * if the CIMObjectPath is incorrect or does not exist. 83 */ 84 public synchronized CIMInstance getInstance(CIMObjectPath op, 85 boolean localOnly, 86 boolean includeQualifiers, 87 boolean includeClassOrigin, 88 String[] propList, 89 CIMClass cc) 90 throws CIMException { 91 92 String pid = null; 93 CIMInstance ci = null; 94 CIMProperty cp = null; 95 DataModel dm = null; 96 ProcessDataModel pdm; 97 98 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 99 try { 100 Enumeration e = op.getKeys().elements(); 101 while (e.hasMoreElements()) { 102 cp = (CIMProperty) e.nextElement(); 103 if (cp.getName().equalsIgnoreCase(NAME)) { 104 pid = (String)((CIMValue)(cp.getValue())).getValue(); 105 } 106 } 107 dm = resourceMonitor.getDataModel(false); 108 if ((pdm = dm.getProcess(Integer.parseInt(pid))) == null) { 109 resourceMonitor.releaseDataModel(dm); 110 throw notFoundEx; 111 } 112 ci = pdm.getCIMInstance(cc); 113 dm = resourceMonitor.releaseDataModel(dm); 114 } catch (Exception e) { 115 dm = resourceMonitor.releaseDataModel(dm); 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 * Returns all instances of Solaris_ProcessUtilizationInformation. 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 synchronized CIMInstance[] enumerateInstances(CIMObjectPath op, 146 boolean localOnly, 147 boolean includeQualifiers, 148 boolean includeClassOrigin, 149 String[] propList, 150 CIMClass cc) 151 throws CIMException { 152 153 DataModel dm = null; 154 155 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 156 try { 157 Vector procInstances = new Vector(); 158 CIMInstance ci; 159 dm = resourceMonitor.getDataModel(false); 160 Iterator i = dm.getProcessIterator(); 161 while (i.hasNext()) { 162 ci = ((ProcessDataModel) i.next()).getCIMInstance(cc); 163 procInstances.addElement(ci); 164 } 165 dm = resourceMonitor.releaseDataModel(dm); 166 CIMInstance[] ciArray = new CIMInstance[procInstances.size()]; 167 procInstances.toArray(ciArray); 168 SRMDebug.trace(SRMDebug.METHOD_RETV, "instance[0]: " + 169 ciArray[0].toString()); 170 return ciArray; 171 } catch (Exception e) { 172 dm = resourceMonitor.releaseDataModel(dm); 173 String msg = writeLog(LOGERROR, "SRM_1002"); 174 writeLog(LOGERROR, e); 175 msg += " (" + e.getClass().toString() + ")"; 176 SRMDebug.trace1(providerName, e); 177 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 178 } 179 180 } // end enumerateInstances 181 182 183 /** 184 * Returns the names of all Solaris_ProcessUtilizationInformation instances. 185 * 186 * @param op - the class name to enumerate the instances 187 * @param cc - the class reference passed to the provider 188 * @return an array of CIMObjectPath containing names of the enumerated 189 * instances. 190 * @exception CIMException - if the classname is null or does not exist. 191 */ 192 public synchronized CIMObjectPath[] 193 enumerateInstanceNames(CIMObjectPath op, CIMClass cc) 194 throws CIMException { 195 196 DataModel dm = null; 197 198 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 199 try { 200 ProcessDataModel pdm; 201 Vector procInstances = new Vector(); 202 int pid; 203 CIMObjectPath cop; 204 dm = resourceMonitor.getDataModel(false); 205 Iterator i = dm.getProcessIterator(); 206 while (i.hasNext()) { 207 pdm = (ProcessDataModel)i.next(); 208 cop = new CIMObjectPath(op.getObjectName(), op.getNameSpace()); 209 cop.addKey(NAME, new CIMValue(Long.toString(pdm.pid))); 210 procInstances.addElement(cop); 211 } 212 dm = resourceMonitor.releaseDataModel(dm); 213 CIMObjectPath[] copArray = new CIMObjectPath[procInstances.size()]; 214 procInstances.toArray(copArray); 215 SRMDebug.trace(SRMDebug.METHOD_RETV, "instanceName[0]: " 216 + copArray[0].toString()); 217 return copArray; 218 } catch (Exception e) { 219 dm = resourceMonitor.releaseDataModel(dm); 220 String msg = writeLog(LOGERROR, "SRM_1003"); 221 writeLog(LOGERROR, e); 222 msg += " (" + e.getClass().toString() + ")"; 223 SRMDebug.trace1(providerName, e); 224 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 225 } 226 227 } // end enumerateInstanceNames 228 229 } // end class Solaris_ProcessStatisticalInformation 230