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_ProjectProcessAggregateStatisticalInformation.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 com.sun.wbem.solarisprovider.common.ProviderUtility; 37 import java.util.Enumeration; 38 import java.util.Iterator; 39 import java.util.Vector; 40 41 42 /** 43 * Provider of the Solaris_ProjectProcessAggregateStatisticalInformation class. 44 * This class provides accumulated resource utilization measurements for 45 * an aggregation of processes sharing a common Project. The (inherited) 46 * ProcessStatisticalInformation properties are populated by summing the 47 * underlying process's usage. 48 * @author Sun Microsystems 49 */ 50 public class Solaris_ProjectProcessAggregateStatisticalInformation 51 extends SRMProvider 52 implements Authorizable, 53 Solaris_ProcessStatisticalInformationProperties { 54 55 /** 56 * The name of the provider implemented by this class 57 */ 58 String providerName = 59 SOLARIS_PROJECTPROCESSAGGREGATESTATISTICALINFORMATION; 60 61 /** 62 * Get the name of the provider implemented by this class. 63 * @returns String provider name 64 */ 65 protected String getProviderName() { 66 return providerName; 67 } 68 69 70 /** 71 * Returns an instance specified by the Name key. 72 * @param op - the name of the instance to be retrieved. This must include 73 * all of the keys and values for the instance. 74 * @param localOnly - if true, only the local properties of the class are 75 * returned, otherwise all properties are required 76 * @param includeQualifiers - if true, the qualifiers are returned as part 77 * of of the returned instancei, otherwise no qualifiers will be returned 78 * @param includeClassOrigin - if true, the class origin of each property 79 * will be returned 80 * @param String[] - if null, all properties are returned, otherwise only 81 * the properties specified will be returned. Any duplicate properties will 82 * be ignored. 83 * @param cc - the class reference 84 * 85 * @return CIMInstance the retrieved instance. 86 * @exception CIMException - the method getInstance throws a CIMException 87 * if the CIMObjectPath is incorrect or does not exist. 88 */ 89 public synchronized CIMInstance getInstance(CIMObjectPath op, 90 boolean localOnly, 91 boolean includeQualifiers, 92 boolean includeClassOrigin, 93 String[] propList, 94 CIMClass cc) 95 throws CIMException { 96 97 String name = null; 98 CIMProperty cp; 99 CIMInstance ci = null; 100 DataModel dm = null; 101 ProcessAggregateDataModel padm; 102 103 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 104 try { 105 Enumeration e = op.getKeys().elements(); 106 while (e.hasMoreElements()) { 107 cp = (CIMProperty) e.nextElement(); 108 if (cp.getName().equalsIgnoreCase(NAME)) { 109 name = (String)((CIMValue)(cp.getValue())).getValue(); 110 } 111 } 112 dm = resourceMonitor.getDataModel(false); 113 if ((padm = dm.getProjprocs(name)) == null) { 114 dm = resourceMonitor.releaseDataModel(dm); 115 throw notFoundEx; 116 } 117 ci = padm.getCIMInstance(cc); 118 dm = resourceMonitor.releaseDataModel(dm); 119 } catch (Exception e) { 120 dm = resourceMonitor.releaseDataModel(dm); 121 String msg = writeLog(LOGERROR, "SRM_1001"); 122 writeLog(LOGERROR, e); 123 msg += " (" + e.getClass().toString() + ")"; 124 SRMDebug.trace1(providerName, e); 125 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 126 } 127 SRMDebug.trace(SRMDebug.METHOD_RETV, ci.toString()); 128 return ci; 129 130 } // end getInstance 131 132 133 /** 134 * Returns all instances of 135 * Solaris_ProjectProcessAggregateUtilizationInformation. 136 * @param op - the object path specifies the class to be enumerated 137 * localOnly - if true, only the local properties of the class are returned, 138 * otherwise all properties are required 139 * @param includeQualifiers - if true, the qualifiers are returned as part 140 * of of the returned instancei, otherwise no qualifiers will be returned 141 * @param includeClassOrigin - if true, the class origin of each property 142 * will be returned 143 * @param String[] - if null, all properties are returned, otherwise only 144 * the properties specified will be 145 * returned. Any duplicate properties will be ignored. 146 * @param cc - the class reference 147 * @return An array of CIMInstance 148 * @exception CIMException - if the CIMObjectPath is incorrect or does not 149 * exist. 150 */ 151 public synchronized CIMInstance[] enumerateInstances(CIMObjectPath op, 152 boolean localOnly, 153 boolean includeQualifiers, 154 boolean includeClassOrigin, 155 String[] propList, 156 CIMClass cc) 157 throws CIMException { 158 DataModel dm = null; 159 160 long t0 = System.currentTimeMillis(); 161 162 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 163 try { 164 Vector procAggrInstances = new Vector(); 165 CIMInstance ci; 166 dm = resourceMonitor.getDataModel(false); 167 Iterator i = dm.getProjprocsIterator(); 168 while (i.hasNext()) { 169 ci = ((ProcessAggregateDataModel) i.next()).getCIMInstance(cc); 170 procAggrInstances.addElement(ci); 171 } 172 dm = resourceMonitor.releaseDataModel(dm); 173 CIMInstance[] ciArray = new CIMInstance[procAggrInstances.size()]; 174 procAggrInstances.toArray(ciArray); 175 SRMDebug.trace(SRMDebug.METHOD_RETV, "instance[0]: " + 176 ciArray[0].toString()); 177 return ciArray; 178 } catch (Exception e) { 179 dm = resourceMonitor.releaseDataModel(dm); 180 String msg = writeLog(LOGERROR, "SRM_1002"); 181 writeLog(LOGERROR, e); 182 msg += " (" + e.getClass().toString() + ")"; 183 SRMDebug.trace1(providerName, e); 184 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 185 } 186 187 } // end enumerateInstances 188 189 190 /** 191 * Returns the names of all Solaris_ProjectProcessUtilizationInformation 192 * instances. 193 * 194 * @param op - the class name to enumerate the instances 195 * @param cc - the class reference passed to the provider 196 * @return an array of CIMObjectPath containing names of the enumerated 197 * instances. 198 * @exception CIMException - if the classname is null or does not exist. 199 */ 200 public synchronized CIMObjectPath[] enumerateInstanceNames(CIMObjectPath op, 201 CIMClass cc) throws CIMException { 202 DataModel dm = null; 203 204 SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString()); 205 try { 206 ProcessAggregateDataModel padm; 207 Vector procAggrInstances = new Vector(); 208 int pid; 209 CIMObjectPath cop; 210 211 dm = resourceMonitor.getDataModel(false); 212 Iterator i = dm.getProjprocsIterator(); 213 214 while (i.hasNext()) { 215 padm = (ProcessAggregateDataModel) i.next(); 216 cop = new CIMObjectPath(op.getObjectName(), op.getNameSpace()); 217 cop.addKey(NAME, new CIMValue(padm.name)); 218 procAggrInstances.addElement(cop); 219 } 220 dm = resourceMonitor.releaseDataModel(dm); 221 CIMObjectPath[] copArray = 222 new CIMObjectPath[procAggrInstances.size()]; 223 procAggrInstances.toArray(copArray); 224 SRMDebug.trace(SRMDebug.METHOD_RETV, "instanceName[0]: " + 225 copArray[0].toString()); 226 return copArray; 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 } // end enumerateInstanceNames 237 238 protected synchronized CIMValue getBulkData(Vector outParams) 239 throws CIMException { 240 DataModel dm = null; 241 242 try { 243 dm = resourceMonitor.getDataModel(false); 244 Iterator i = dm.getProjprocsIterator(); 245 Vector vOutParam = new Vector(); 246 while (i.hasNext()) { 247 vOutParam.addElement(((ProcessAggregateDataModel) i.next()). 248 toBulkData()); 249 } 250 // rem: we can only return CIMValues in our outParams 251 CIMDataType dtype = new CIMDataType(CIMDataType.STRING_ARRAY); 252 CIMValue outVal = new CIMValue(vOutParam, dtype); 253 outParams.addElement(outVal); 254 dm = resourceMonitor.releaseDataModel(dm); 255 256 } catch (Exception e) { 257 dm = resourceMonitor.releaseDataModel(dm); 258 String msg = writeLog(LOGERROR, "SRM_1002"); 259 writeLog(LOGERROR, e); 260 msg += " (" + e.getClass().toString() + ")"; 261 SRMDebug.trace1(providerName, e); 262 throw new CIMException(CIMException.CIM_ERR_FAILED, msg); 263 } 264 265 CIMValue rv = new CIMValue(new Integer(0)); 266 return (rv); 267 } // end getBulkData 268 269 } // end class Solaris_ProjectProcessAggregateStatisticalInformation 270