void IndicationFormatter::validateTextFormatParameters ( const CIMPropertyList & propertyList, const CIMClass & indicationClass, const Array<String> & textFormatParams) { PEG_METHOD_ENTER (TRC_IND_FORMATTER, "IndicationFormatter::validateTextFormatParameters"); Array <String> indicationClassProperties; String exceptionStr; // All the properties are selected if (propertyList.isNull ()) { for (Uint32 i = 0; i < indicationClass.getPropertyCount (); i++) { indicationClassProperties.append( indicationClass.getProperty (i).getName ().getString()); } } // partial properties are selected else { Array<CIMName> propertyNames = propertyList.getPropertyNameArray(); for (Uint32 j = 0; j < propertyNames.size(); j++) { indicationClassProperties.append(propertyNames[j].getString()); } } // check if the textFormatParams is contained in the // indicationClassProperties for (Uint32 k = 0; k < textFormatParams.size(); k++) { if (!Contains(indicationClassProperties, textFormatParams[k])) { // The property name in TextFormatParameters is not // included in the select clause of the associated filter query MessageLoaderParms parms( "IndicationFormatter.IndicationFormatter._MSG_MISS_MATCHED_PROPERTY_NAME", "The property name $0 in $1 does not match the properties in the select clause", textFormatParams[k], _PROPERTY_TEXTFORMATPARAMETERS.getString()); exceptionStr.append(MessageLoader::getMessage(parms)); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION ( CIM_ERR_INVALID_PARAMETER, exceptionStr); } } PEG_METHOD_EXIT(); }
static CIMPropertyList getList(const char** l) { CIMPropertyList pl; if (l) { Array<CIMName> n; while (*l) { n.append(*l++); } pl.set(n); } return pl; }
void test03() { // // Define query: // const char TEXT[] = "SELECT *\n" "FROM AnotherClass\n"; // // Will test WQLParser::parse(const String&, WQLSelectStatement&) // and WQLParser::parse(const char*, WQLSelectStatement&) forms // String text (TEXT); if (verbose) { cout << text << endl; } // // Parse the text: // WQLSelectStatement statement; try { WQLParser::parse(text, statement); if (verbose) { statement.print(); } // // Test WQLSelectStatement functions // assert (statement.getClassName().equal ("AnotherClass")); assert (statement.getAllProperties()); CIMPropertyList propList = statement.getSelectPropertyList(); assert (propList.isNull()); assert (!statement.hasWhereClause()); assert (statement.getWherePropertyNameCount() == 0); CIMPropertyList wherePropList = statement.getWherePropertyList(); assert (!wherePropList.isNull()); assert (wherePropList.size() == 0); } catch (Exception& e) { cerr << "Exception: " << e.getMessage() << endl; exit(1); } }
CIMPropertyList WQLSelectStatementRep::getPropertyList( const CIMObjectPath& inClassName) { if(_ctx == NULL){ MessageLoaderParms parms( "WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL", "Trying to process a query with a NULL Query Context."); throw QueryRuntimeException(parms); } if(_allProperties) return CIMPropertyList(); CIMName className = inClassName.getClassName(); if (className.isNull()) { // If the caller passed in an empty className, then the // FROM class is to be used. className = _className; } // check if inClassName is the From class if(!(className == _className)){ // check if inClassName is a subclass of the From class if(!_ctx->isSubClass(_className,className)){ MessageLoaderParms parms( "WQL.WQLSelectStatementRep.CLASS_NOT_FROM_LIST_CLASS", "Class $0 does not match the FROM class or any of its" " subclasses.", className.getString()); throw QueryRuntimeException(parms); } } Array<CIMName> names = getWherePropertyList(inClassName).getPropertyNameArray(); Array<CIMName> selectList = getSelectPropertyList(inClassName).getPropertyNameArray(); // check for duplicates and remove them for(Uint32 i = 0; i < names.size(); i++){ for(Uint32 j = 0; j < selectList.size(); j++){ if(names[i] == selectList[j]) selectList.remove(j); } } names.appendArray(selectList); CIMPropertyList list = CIMPropertyList(); list.set(names); return list; }
void PG_TestPropertyTypes::modifyInstance( const OperationContext& context, const CIMObjectPath& instanceReference, const CIMInstance& instanceObject, const Boolean includeQualifiers, const CIMPropertyList& propertyList, ResponseHandler& handler) { // This provider only allows partial instance modification for the // PropertyUint8 property. if (!(propertyList.isNull() || ((propertyList.size() == 1) && (propertyList[0].equal("PropertyUint8"))))) { throw CIMException(CIM_ERR_NOT_SUPPORTED); } // synchronously get references Array<CIMObjectPath> references = _enumerateInstanceNames(context, instanceReference); // ensure the Namespace is valid if (!instanceReference.getNameSpace().equal("test/static")) { throw CIMException(CIM_ERR_INVALID_NAMESPACE); } // ensure the class existing in the specified namespace if (!instanceReference.getClassName().equal("PG_TestPropertyTypes")) { throw CIMException(CIM_ERR_INVALID_CLASS); } // ensure the property values are valid _testPropertyTypesValue(instanceObject); // ensure the request object exists Uint32 index = findObjectPath(references, instanceReference); if (index == PEG_NOT_FOUND) { throw CIMException(CIM_ERR_NOT_FOUND); } // begin processing the request handler.processing(); // We do nothing here since we like to have static result // complete processing the request handler.complete(); }
void _printPropertyList(CIMPropertyList& propList) { if (propList.isNull()) { cout << "-----all properties required" << endl; } else if (propList.size() == 0) { cout << "-----no properties required" << endl; } else { for (Uint32 n = 0; n < propList.size(); n++) { cout << "-----Required property " << propList[n].getString() << endl; } } }
// KS Mar 05 - The following removal functions are very inefficient and should // be optimized to avoid the multiple memory moves. Actually, the remove // qualifiers should be added as a function and optimized that once. void CIMInstanceRep::filter( Boolean includeQualifiers, Boolean includeClassOrigin, const CIMPropertyList& propertyList) { // Filter any qualifiers from this instance. if (!includeQualifiers && _qualifiers.getCount() > 0) { while (_qualifiers.getCount()) { _qualifiers.removeQualifier(0); } } // For each property, remove if not in propertylist for (Uint32 i = 0 ; i < _properties.size(); i++) { CIMConstProperty p = getProperty(i); CIMName name = p.getName(); Array<CIMName> pl = propertyList.getPropertyNameArray(); if (propertyList.isNull() || Contains(pl, name)) { // test ClassOrigin and possibly remove if (!includeClassOrigin) { _properties[i].setClassOrigin(CIMName()); } // remove qualifiers if required. if (!includeQualifiers && _properties[i].getQualifierCount() > 0) { while (_properties[i].getQualifierCount() > 0) { _properties[i].removeQualifier(0); } } } else { _properties.remove(i--); } } return; }
// =========================================================================== // Main // Options: // Test or show - TBD // =========================================================================== int main() { //verbose = getenv("PEGASUS_TEST_VERBOSE"); verbose = "test"; cout << "+++++ Testing AssociationTest Provider" << endl; // Build array of classes Array<CIMName> Classes; Classes.append("TST_ClassA"); Classes.append("TST_ClassB"); Classes.append("TST_ClassC"); Classes.append("TST_ClassD"); Classes.append("TSTDY_ClassA"); Classes.append("TSTDY_ClassB"); Classes.append("TSTDY_ClassC"); Classes.append("TSTDY_ClassD"); Array<CIMName> AssocClasses; AssocClasses.append("TST_AssocI1"); AssocClasses.append("TST_AssocI2"); AssocClasses.append("TST_AssocI3"); AssocClasses.append("TST_AssocI4"); AssocClasses.append("TST_AssocI5"); AssocClasses.append("TST_AssocI6"); AssocClasses.append("TST_AssocNI1"); AssocClasses.append("TST_AssocNI2"); AssocClasses.append("TST_AssocNI3"); AssocClasses.append("TST_AssocNI4"); AssocClasses.append("TST_AssocNI5"); AssocClasses.append("TST_AssocNI6"); // Connect try { c.connect (HOST, PORTNUMBER, String::EMPTY, String::EMPTY); } catch (Exception& e) { errorExit(e); } int rc; // Start by confirming the existence of the classes, etc. if ((rc = testClassList(Classes)) != 0) return rc; if ((rc = testClassList(AssocClasses)) != 0) return rc; // Now start the association tests. // Reference Names Test // Class A Refrence Names Test ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"), CIMName(), "", 2)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"), CIMName(), "to", 2)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"), CIMName(), "from", 2)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI1"), "", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI1"), "to", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI1"), "from", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI3"), "", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI3"), "to", 0)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI3"), "from", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI5"), "", 0)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI5"), "to", 0)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI5"), "from", 0)); // Class B Refrence Names Test ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"), CIMName(), "", 4)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"), CIMName(), "to", 2)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"), CIMName(), "from", 4)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "to", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "from", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "to", 0)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "from", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI5"), "", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI5"), "to", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI5"), "from", 1)); // TODO TestReferences for class c and class d // testRefernceName Instances from static store ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName(), "", 2)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName(), "to", 2)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName(), "from", 2)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName("TST_AssocI1"), "", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName("TST_AssocI1"), "to", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName("TST_AssocI1"), "from", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName("TST_AssocI3"), "", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName("TST_AssocI3"), "to", 0)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName("TST_AssocI3"), "from", 1)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName("TST_AssocI5"), "", 0)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName("TST_AssocI5"), "to", 0)); ASRT(testReferenceNames( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName("TST_AssocI5"), "from", 0)); // Lets make the previous a common test between ref and ref names. // References // Limited test since we learned most in the previous test of reference // names CIMPropertyList NullPL; CIMPropertyList emptyPL; CIMPropertyList fullPL; Array<CIMName> fullPLinput; fullPLinput.append("name"); fullPL.set(fullPLinput); CIMPropertyList errorPL; Array<CIMName> errorPLinput; errorPLinput.append("junk"); errorPL.set(errorPLinput); ASRT(testReferences(CIMObjectPath("TST_ClassA"), CIMName(), "", emptyPL,2)); ASRT(testReferences( CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName(), "", fullPL,2)); // Testing associators and and associator names functions. ASRT(testAssocNames( CIMObjectPath("TST_ClassA"), CIMName(), CIMName(), "", "", 3)); cout << "+++++ passed all tests" << endl; return 0; }
Boolean _getPropertyList(QueryExpression& qe, Array<CIMInstance>& _instances, CIMNamespaceName ns, String testOption, String lang) { if(testOption == String::EMPTY || testOption == "3") { for(Uint32 j = 0; j < _instances.size(); j++) { cout << endl << lang << " ========Get Property List Results=======" << endl; cout << qe.getQuery() << endl; try { cout << endl << "Get Class Path List" << endl; Array<CIMObjectPath> fromPaths = qe.getClassPathList(); for (Uint32 k = 0; k < fromPaths.size(); k++) { cout << "-----" << fromPaths[k].toString() << endl; } } catch(Exception& e) { cout << "-----" << e.getMessage() << endl; } catch(...) { cout << "Unknown Exception" << endl; } CIMName className = _instances[j].getClassName(); CIMObjectPath classPath (String::EMPTY, ns, className); CIMPropertyList propList; try { cout << "Property List for the FROM class" << endl; propList = qe.getPropertyList(); _printPropertyList(propList); } catch(Exception& e) { cout << "-----" << e.getMessage() << endl; } catch(...) { cout << "Unknown Exception" << endl; } try { cout << "Property List for " << className.getString() << endl; propList = qe.getPropertyList(classPath); _printPropertyList(propList); } catch(Exception& e) { cout << "-----" << e.getMessage() << endl; } catch(...) { cout << "Unknown Exception" << endl; } try { propList.clear(); cout << "SELECT Property List for the FROM class" << endl; propList = qe.getSelectPropertyList(); _printPropertyList(propList); } catch(Exception& e) { cout << "-----" << e.getMessage() << endl; } catch(...) { cout << "Unknown Exception" << endl; } try { propList.clear(); cout << "SELECT Property List for " << className.getString() << endl; propList = qe.getSelectPropertyList(classPath); _printPropertyList(propList); } catch(Exception& e) { cout << "-----" << e.getMessage() << endl; } catch(...) { cout << "Unknown Exception" << endl; } try { propList.clear(); cout << "WHERE Property List for the FROM class" << endl; propList = qe.getWherePropertyList(); _printPropertyList(propList); } catch(Exception& e) { cout << "-----" << e.getMessage() << endl; } catch(...) { cout << "Unknown Exception" << endl; } try { propList.clear(); cout << "WHERE Property List for " << className.getString() << endl; propList = qe.getWherePropertyList(classPath); _printPropertyList(propList); } catch(Exception& e) { cout << "-----" << e.getMessage() << endl; } catch(...) { cout << "Unknown Exception" << endl; } } } return true; }
PEGASUS_NAMESPACE_BEGIN void SCMOInternalXmlEncoder::_putXMLInstance( CIMBuffer& out, const SCMOInstance& ci, const CIMPropertyList& propertyList ) { if (ci.isUninitialized()) { out.putUint32(0); out.putUint32(0); out.putString(String()); out.putNamespaceName(CIMNamespaceName()); } else { Buffer buf(4096); // Serialize instance as XML. if (propertyList.isNull()) { Array<Uint32> emptyNodes; SCMOXmlWriter::appendInstanceElement( buf, ci, false, emptyNodes); } else { Array<propertyFilterNodesArray_t> propFilterNodesArrays; // This searches for an already created array of nodes, // if not found, creates it inside propFilterNodesArrays const Array<Uint32> & nodes= SCMOXmlWriter::getFilteredNodesArray( propFilterNodesArrays, ci, propertyList); SCMOXmlWriter::appendInstanceElement( buf, ci, true, nodes); } buf.append('\0'); out.putUint32(buf.size()); out.putBytes(buf.getData(), buf.size()); buf.clear(); if (0 == ci.getClassName()) { out.putUint32(0); out.putString(String()); out.putNamespaceName(CIMNamespaceName()); } else { // Serialize object path as XML. SCMOXmlWriter::appendValueReferenceElement(buf, ci); buf.append('\0'); out.putUint32(buf.size()); out.putBytes(buf.getData(), buf.size()); // Write hostname and namespace in UTF-16 format Uint32 len=0; const char* hn = ci.getHostName_l(len); out.putUTF8AsString(hn, len); const char * ns = ci.getNameSpace_l(len); out.putUTF8AsString(ns, len); } } }
// // Local version of enumerateInstances to be used by other functions in the // provider. Note that this delivers instances as a group rather than one // at a time. This design point may need to be revisited if this provider // is used in environments such that returning segmented responses would have // significant performance advantages. For now, that doesn't seem to be the // case. // Array<CIMInstance> InteropProvider::localEnumerateInstances( const OperationContext & context, const CIMObjectPath & ref, const CIMPropertyList& propertyList) { PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::localEnumerateInstances()"); const CIMName & className = ref.getClassName(); PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4, "%s enumerateInstances. referenc= %s , PropertyList= %s", thisProvider, (const char *)className.getString().getCString(), (const char *)propertyList.toString().getCString())); // Verify that ClassName is correct and get its enum value TARGET_CLASS classEnum = translateClassInput(className); Array<CIMInstance> instances; switch(classEnum) { case PG_OBJECTMANAGER: { instances.append(getObjectManagerInstance()); break; } case PG_CIMXMLCOMMUNICATIONMECHANISM: { instances = enumCIMXMLCommunicationMechanismInstances(); break; } case PG_NAMESPACEINMANAGER: { instances = enumNamespaceInManagerInstances(); break; } case PG_COMMMECHANISMFORMANAGER: { instances = enumCommMechanismForManagerInstances(); break; } case PG_NAMESPACE: { instances = enumNamespaceInstances(); break; } case PG_REGISTEREDPROFILE: { instances = enumRegisteredProfileInstances(); break; } case PG_REGISTEREDSUBPROFILE: { instances = enumRegisteredSubProfileInstances(); break; } case PG_REFERENCEDPROFILE: { instances = enumReferencedProfileInstances(); break; } case PG_ELEMENTCONFORMSTOPROFILE: { instances = enumElementConformsToProfileInstances(context, ref.getNameSpace()); break; } case PG_ELEMENTCONFORMSTOPROFILE_RP_RP: { instances = enumElementConformsToProfileRPRPInstances( context, ref.getNameSpace()); break; } case PG_SUBPROFILEREQUIRESPROFILE: { instances = enumSubProfileRequiresProfileInstances(); break; } case PG_SOFTWAREIDENTITY: { instances = enumSoftwareIdentityInstances(); break; } case PG_ELEMENTSOFTWAREIDENTITY: { instances = enumElementSoftwareIdentityInstances(); break; } case PG_INSTALLEDSOFTWAREIDENTITY: { instances = enumInstalledSoftwareIdentityInstances(context); break; } case PG_COMPUTERSYSTEM: { instances.append(getComputerSystemInstance(context)); break; } case PG_HOSTEDOBJECTMANAGER: { instances.append(getHostedObjectManagerInstance(context)); break; } case PG_HOSTEDACCESSPOINT: { instances = enumHostedAccessPointInstances(context); break; } //We don't support enumerate CIM_Namespace instances. PG_Namespace is //supported. case CIM_NAMESPACE: { break; } case PG_PROVIDERPROFILECAPABILITIES: { instances = enumProviderProfileCapabilityInstances(false); break; } #ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT case PG_ELEMENTCAPABILITIES: { instances = enumElementCapabilityInstances(context); break; } case PG_HOSTEDINDICATIONSERVICE: { instances = enumHostedIndicationServiceInstances(context); break; } case PG_SERVICEAFFECTSELEMENT: { instances = enumServiceAffectsElementInstances(context); break; } case CIM_INDICATIONSERVICE: { instances = enumIndicationServiceInstances(context); break; } #endif default: PEG_METHOD_EXIT(); throw CIMNotSupportedException(className.getString() + " not supported by Interop Provider enumerate"); } // Filter and deliver the resulting instances for (Uint32 i = 0 ; i < instances.size() ; i++) { normalizeInstance(instances[i], ref, false, false, propertyList); } PEG_METHOD_EXIT(); return instances; }
// // Local version of getInstance to be used by other functions in the the // provider. Returns a single instance. Note that it always returns an // instance. If none was found, it is uninialitized. // CIMInstance InteropProvider::localGetInstance( const OperationContext & context, const CIMObjectPath & instanceName, const CIMPropertyList & propertyList) { PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::localGetInstance"); PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4, "%s getInstance. instanceName= %s , PropertyList= %s", thisProvider, (const char *)instanceName.toString().getCString(), (const char *)propertyList.toString().getCString())); // Test if we're looking for something outside of our namespace. This will // happen during associators calls from PG_RegisteredProfile instances // through the PG_ElementConformsToProfile association CIMNamespaceName opNamespace = instanceName.getNameSpace(); CIMName opClass = instanceName.getClassName(); if((opNamespace != PEGASUS_NAMESPACENAME_INTEROP && opClass != PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE) // Get CIM_IndicationService instance from IndicationService. #ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT || opClass == PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE #endif ) { AutoMutex mut(interopMut); CIMInstance gotInstance = cimomHandle.getInstance( context, opNamespace, instanceName, false, false, false, propertyList); PEG_METHOD_EXIT(); return gotInstance; } TARGET_CLASS classEnum = translateClassInput(opClass); CIMInstance retInstance; switch(classEnum) { case PG_SOFTWAREIDENTITY: { retInstance = getSoftwareIdentityInstance(instanceName); normalizeInstance( retInstance, instanceName, false, false, propertyList); } break; case PG_NAMESPACE: { retInstance = getNameSpaceInstance(instanceName); normalizeInstance( retInstance, instanceName, false, false, propertyList); } break; // ATTN: Implement getIntstance for all other classes. Currently // this method calls localEnumerateInstances() to select instance // which is too expensive. default: { // Create reference from host, namespace, class components of // instance name CIMObjectPath ref; ref.setHost(instanceName.getHost()); ref.setClassName(opClass); ref.setNameSpace(opNamespace); // Enumerate instances for this class. Returns all instances // Note that this returns paths setup and instances already // filtered per the input criteria. Array<CIMInstance> instances = localEnumerateInstances( context, ref, propertyList); ConstArrayIterator<CIMInstance> instancesIter(instances); // deliver a single instance if found. bool found = false; for(Uint32 i = 0; i < instancesIter.size(); i++) { CIMObjectPath currentInstRef = instancesIter[i].getPath(); currentInstRef.setHost(instanceName.getHost()); currentInstRef.setNameSpace(instanceName.getNameSpace()); if(instanceName == currentInstRef) { retInstance = instancesIter[i]; found = true; break; } } if (!found) { PEG_METHOD_EXIT(); throw CIMObjectNotFoundException(instanceName.toString()); } } } PEG_METHOD_EXIT(); return retInstance; }
void test01() { // // Create a property source (a place for the evaluate to get the // values of properties from): // WQLSimplePropertySource source; assert(source.addValue("x", WQLOperand(10, WQL_INTEGER_VALUE_TAG))); assert(source.addValue("y", WQLOperand(20, WQL_INTEGER_VALUE_TAG))); assert(source.addValue("z", WQLOperand(1.5, WQL_DOUBLE_VALUE_TAG))); // // Define query: // const char TEXT[] = "SELECT x,y,z\n" "FROM MyClass\n" "WHERE x > 5 AND y < 25 AND z > 1.2"; // // Will test WQLParser::parse(const Array<Sint8>&, WQLSelectStatement&) // and WQLParser::parse(const char*, WQLSelectStatement&) forms // Array<char> text; text.append(TEXT, sizeof(TEXT)); if (verbose) { cout << text.getData() << endl; } // // Parse the text: // WQLSelectStatement statement; try { WQLParser::parse(text, statement); if (verbose) { statement.print(); } // // Test WQLSelectStatement functions // assert (statement.getClassName().equal ("MyClass")); assert (!statement.getAllProperties()); assert (statement.getSelectPropertyNameCount() == 3); CIMName propName = statement.getSelectPropertyName (0); assert ((propName.equal ("x")) || (propName.equal ("y")) || (propName.equal ("z"))); CIMPropertyList propList = statement.getSelectPropertyList(); assert (!propList.isNull()); assert (propList.size() == 3); assert ((propList[0].equal ("x")) || (propList[0].equal ("y")) || (propList[0].equal ("z"))); assert (statement.hasWhereClause()); assert (statement.getWherePropertyNameCount() == 3); CIMName wherePropName = statement.getWherePropertyName (0); assert ((wherePropName.equal ("x")) || (wherePropName.equal ("y")) || (wherePropName.equal ("z"))); CIMPropertyList wherePropList = statement.getWherePropertyList(); assert (!wherePropList.isNull()); assert (wherePropList.size() == 3); assert ((wherePropList[0].equal ("x")) || (wherePropList[0].equal ("y")) || (wherePropList[0].equal ("z"))); assert (statement.evaluateWhereClause(&source)); } catch (Exception& e) { cerr << "Exception: " << e.getMessage() << endl; exit(1); } }
void test02() { // // Create a property source (a place for the evaluate to get the // values of properties from): // WQLSimplePropertySource source; assert(source.addValue("a", WQLOperand(5, WQL_INTEGER_VALUE_TAG))); assert(source.addValue("b", WQLOperand(25, WQL_INTEGER_VALUE_TAG))); assert(source.addValue("c", WQLOperand(0.9, WQL_DOUBLE_VALUE_TAG))); assert(source.addValue("d", WQLOperand("Test", WQL_STRING_VALUE_TAG))); // // Define query: // const char TEXT[] = "SELECT a,c,d\n" "FROM YourClass\n" "WHERE a > 5 AND b < 25 AND c > 1.2 AND d = \"Pass\""; // // Will test WQLParser::parse(const String&, WQLSelectStatement&) // and WQLParser::parse(const char*, WQLSelectStatement&) forms // String text (TEXT); if (verbose) { cout << text << endl; } // // Parse the text: // WQLSelectStatement statement; try { WQLParser::parse(text, statement); if (verbose) { statement.print(); } // // Test WQLSelectStatement functions // assert (statement.getClassName().equal ("YourClass")); assert (!statement.getAllProperties()); assert (statement.getSelectPropertyNameCount() == 3); CIMName propName = statement.getSelectPropertyName (2); assert ((propName.equal ("a")) || (propName.equal ("c")) || (propName.equal ("d"))); CIMPropertyList propList = statement.getSelectPropertyList(); assert (!propList.isNull()); assert (propList.size() == 3); assert ((propList[2].equal ("a")) || (propList[2].equal ("c")) || (propList[2].equal ("d"))); assert (statement.hasWhereClause()); assert (statement.getWherePropertyNameCount() == 4); CIMName wherePropName = statement.getWherePropertyName (3); assert ((wherePropName.equal ("a")) || (wherePropName.equal ("b")) || (wherePropName.equal ("c")) || (wherePropName.equal ("d"))); CIMPropertyList wherePropList = statement.getWherePropertyList(); assert (!wherePropList.isNull()); assert (wherePropList.size() == 4); assert ((wherePropList[3].equal ("a")) || (wherePropList[3].equal ("b")) || (wherePropList[3].equal ("c")) || (wherePropList[3].equal ("d"))); assert (!statement.evaluateWhereClause(&source)); } catch (Exception& e) { cerr << "Exception: " << e.getMessage() << endl; exit(1); } }
void ConfigSettingProvider::_modifyInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance& modifiedIns, const CIMPropertyList& propertyList, Uint32 timeoutSeconds) { PEG_METHOD_ENTER(TRC_CONFIG, "ConfigSettingProvider::_modifyInstance()"); // // get userName // String userName; try { IdentityContainer container = context.get(IdentityContainer::NAME); userName = container.getUserName(); } catch (...) { userName = String::EMPTY; } // // verify user authorizations // z/OS: authorization check is done in CIMOpReqAuth already // #ifndef PEGASUS_OS_ZOS if (userName != String::EMPTY) { _verifyAuthorization(userName); } #endif // NOTE: Qualifiers are not processed by this provider, so the // IncludeQualifiers flag is ignored. // // check if the class name requested is PG_ConfigSetting // if (!instanceReference.getClassName().equal (PG_CONFIG_SETTING)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, instanceReference.getClassName().getString()); } // // validate key bindings // Array<CIMKeyBinding> kbArray = instanceReference.getKeyBindings(); if ( (kbArray.size() != 1) || (!kbArray[0].getName().equal (PROPERTY_NAME))) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L( CIM_ERR_INVALID_PARAMETER, MessageLoaderParms( "ControlProviders.ConfigSettingProvider." "ConfigSettingProvider." "INVALID_INSTANCE_NAME", "Invalid instance name")); } String configPropertyName = kbArray[0].getValue(); // Modification of the entire instance is not supported by this provider if (propertyList.isNull()) { PEG_METHOD_EXIT(); //l10n //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, //"Modification of entire instance"); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED, MessageLoaderParms( "ControlProviders.ConfigSettingProvider." "ConfigSettingProvider." "MODIFICATION_OF_ENTIRE_INSTANCE", "Modification of entire instance")); } Boolean currentValueModified = false; Boolean plannedValueModified = false; for (Uint32 i = 0; i < propertyList.size(); ++i) { CIMName propertyName = propertyList[i]; if (propertyName.equal (CURRENT_VALUE)) { currentValueModified = true; } else if (propertyName.equal (PLANNED_VALUE)) { plannedValueModified = true; } else { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED, MessageLoaderParms( "ControlProviders.ConfigSettingProvider." "ConfigSettingProvider." "MODIFICATION_NOT_SUPPORTED", "Modification of property \"$0\"", propertyName.getString())); } } String preValue; String currentValue; String plannedValue; Boolean currentValueIsNull = false; Boolean plannedValueIsNull = false; // // Get the current value from the instance // Uint32 pos = modifiedIns.findProperty(CURRENT_VALUE); if (pos == PEG_NOT_FOUND) { currentValueIsNull = true; } else { CIMConstProperty prop = modifiedIns.getProperty(pos); try { prop.getValue().get(currentValue); } catch (Exception& e) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage()); } } // // Get the planned value from the instance // pos = modifiedIns.findProperty(PLANNED_VALUE); if (pos == PEG_NOT_FOUND) { plannedValueIsNull = true; } else { CIMConstProperty prop = modifiedIns.getProperty(pos); try { prop.getValue().get(plannedValue); } catch (Exception& e) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage()); } } try { // // Update the current value, if requested // if (currentValueModified) { preValue = _configManager->getCurrentValue(configPropertyName); if ( !_configManager->updateCurrentValue( configPropertyName, currentValue, userName, timeoutSeconds, currentValueIsNull)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L( CIM_ERR_FAILED, MessageLoaderParms( "ControlProviders.ConfigSettingProvider." "ConfigSettingProvider." "UPDATE_CURRENT_VALUE_FAILED", "Failed to update the current value.")); } // It is unset, get current value which is default if (currentValueIsNull) { currentValue = _configManager->getCurrentValue( configPropertyName); } // send notify config change message to Handler Service if(String::equal(configPropertyName, "maxIndicationDeliveryRetryAttempts")|| String::equal(configPropertyName, "minIndicationDeliveryRetryInterval")) { _sendNotifyConfigChangeMessage( configPropertyName, currentValue, userName, PEGASUS_QUEUENAME_INDHANDLERMANAGER, true); } // send notify config change message to ProviderManager Service _sendNotifyConfigChangeMessage( configPropertyName, currentValue, userName, PEGASUS_QUEUENAME_PROVIDERMANAGER_CPP, true); PEG_AUDIT_LOG(logSetConfigProperty(userName, configPropertyName, preValue, currentValue, false)); } // // Update the planned value, if requested // if (plannedValueModified) { preValue = _configManager->getPlannedValue(configPropertyName); if ( !_configManager->updatePlannedValue( configPropertyName, plannedValue, plannedValueIsNull) ) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L( CIM_ERR_FAILED, MessageLoaderParms( "ControlProviders.ConfigSettingProvider." "ConfigSettingProvider." "UPDATE_PLANNED_VALUE_FAILED", "Failed to update the planned value.")); } // It is unset, get planned value which is default if (plannedValueIsNull) { plannedValue = _configManager->getPlannedValue( configPropertyName); if (String::equal(configPropertyName, "maxIndicationDeliveryRetryAttempts") || String::equal(configPropertyName, "minIndicationDeliveryRetryInterval")) { _sendNotifyConfigChangeMessage( configPropertyName, plannedValue, userName, PEGASUS_QUEUENAME_INDHANDLERMANAGER, false); } } // send notify config change message to ProviderManager Service _sendNotifyConfigChangeMessage( configPropertyName, plannedValue, userName, PEGASUS_QUEUENAME_PROVIDERMANAGER_CPP, false); PEG_AUDIT_LOG(logSetConfigProperty(userName, configPropertyName, preValue, plannedValue, true)); } } catch (const NonDynamicConfigProperty& ndcp) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION( CIM_ERR_NOT_SUPPORTED, ndcp.getMessage()); } catch (const InvalidPropertyValue& ipv) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION( CIM_ERR_FAILED, ipv.getMessage()); } catch (const UnrecognizedConfigProperty&) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L( CIM_ERR_NOT_FOUND, MessageLoaderParms( "ControlProviders.ConfigSettingProvider." "ConfigSettingProvider." "CONFIG_PROPERTY_NOT_FOUND", "Configuration property \"$0\"", configPropertyName)); } PEG_METHOD_EXIT(); return; }
///////////////////////////////////////////////////////////////////////////// // WMIInstanceProvider::modifyInstance // // /////////////////////////////////////////////////////////////////////////// void WMIInstanceProvider::modifyInstance( const String& nameSpace, const String& userName, const String& password, const CIMInstance& modifiedInstance, Boolean includeQualifiers, const CIMPropertyList& propertylist) { PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMIClassProvider::modifyInstance()"); HRESULT hr; CComPtr<IWbemClassObject> pClass; CComPtr<IWbemClassObject> pInstance; setup(nameSpace, userName, password); PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3, "ModifyInstance() - nameSpace %s, userName %s", nameSpace.getCString(), userName.getCString())); if (!m_bInitialized) { PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL1, "WMIInstanceProvider::ModifyInstance - m_bInitilized= %x, " "throw CIM_ERR_FAILED exception", m_bInitialized)); throw CIMException(CIM_ERR_FAILED); } // Check if the instance's class is valid. String className = modifiedInstance.getClassName().getString(); if (!(_collector->getObject(&pClass, className))) { if (pClass) pClass.Release(); throw CIMException(CIM_ERR_INVALID_CLASS); } else if (_collector->isInstance(pClass)) { if (pClass) pClass.Release(); throw CIMException(CIM_ERR_INVALID_PARAMETER); } if (pClass) pClass.Release(); // Get the instance path CIMObjectPath objPath = modifiedInstance.getPath(); // Get the name of the instance String instanceName = getObjectName(objPath); // Check if the instance exists if (!(_collector->getObject(&pInstance, instanceName))) { if (pInstance) pInstance.Release(); throw CIMException(CIM_ERR_NOT_FOUND); } else if (!(_collector->isInstance(pInstance))) { if (pInstance) pInstance.Release(); throw CIMException(CIM_ERR_INVALID_PARAMETER); } // Set the properties that are into propertylist Array<CIMName> listNames; listNames = propertylist.getPropertyNameArray(); bool foundInArray; bool bPropertySet = false; for(Uint32 i = 0; i < modifiedInstance.getPropertyCount(); i++) { CComVariant v; CIMProperty property = modifiedInstance.getProperty(i).clone(); String sPropName = property.getName().getString(); // change only the properties defined into the array // if the array is null, change all properties if (propertylist.isNull()) { foundInArray = true; } else { foundInArray = false; for (Uint32 j = 0; (j < listNames.size()) && !foundInArray; j++) //if (listNames[j].getString() == str) if (String::equalNoCase(listNames[j].getString(), sPropName)) foundInArray = true; } if (foundInArray) { WMIValue propertyValue = property.getValue(); try { propertyValue.getAsVariant(&v,nameSpace, userName, password); } catch (CIMException&) { if (pInstance) pInstance.Release(); v.Clear(); throw; } CComBSTR bs = sPropName.getCString(); hr = pInstance->Put(bs, 0, &v, 0); v.Clear(); // If we fail to set one property, we must assure // that the others will be processed if(SUCCEEDED(hr)) { // Mark that at least one property was set bPropertySet = true; } } } // Check if at least one property was set // otherwise throw invalid parameter error if(!bPropertySet) { PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL1, "modifyInstance() - Put Failed hr=0x%x.", hr)); throw CIMException(CIM_ERR_FAILED); } // Connect to the server CComPtr<IWbemServices> pServices; bool bConnected = _collector->Connect(&pServices); if (!bConnected) { throw CIMException(CIM_ERR_ACCESS_DENIED); } // Write the instance to WMI. hr = pServices->PutInstance(pInstance, WBEM_FLAG_UPDATE_ONLY, NULL, NULL); if (pInstance) pInstance.Release(); if (pServices) pServices.Release(); if(FAILED(hr)) { switch(hr) { case E_ACCESSDENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break; case WBEM_E_ACCESS_DENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break; case WBEM_E_NOT_FOUND: throw CIMException(CIM_ERR_NOT_FOUND); break; case WBEM_E_INVALID_CLASS: throw CIMException(CIM_ERR_INVALID_CLASS); break; case WBEM_E_INVALID_OBJECT: throw CIMException(CIM_ERR_INVALID_PARAMETER); break; default: throw CIMException(CIM_ERR_FAILED); } } PEG_METHOD_EXIT(); return; }