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