static void TestException( CIMHandler* handler, CIMInstance indicationHandlerInstance, CIMInstance indicationInstance, CIMStatusCode statusCode) { OperationContext context; CIMInstance indicationSubscriptionInstance; ContentLanguageList contentLanguages; Boolean exceptionCaught = false; CIMException testException; try { handler->handleIndication(context, NAMESPACE, indicationInstance, indicationHandlerInstance, indicationSubscriptionInstance, contentLanguages); } catch (CIMException& e) { exceptionCaught = true; testException = e; } PEGASUS_TEST_ASSERT(exceptionCaught && testException.getCode() == statusCode); }
// // Send notify config change message to provider manager service // This code was borrowed from the ConfigSettingProvider and should // be kept in sync. // The purpose is to ensure that OOP agents also get the update. // TBD, or is it for other reasons as well? // void ZOSConsoleManager::_sendNotifyConfigChangeMessage( const String& propertyName, const String& newPropertyValue, Boolean currentValueModified) { PEG_METHOD_ENTER(TRC_SERVER, "ZOSConsoleManager::_sendNotifyConfigChangeMessage"); ModuleController* controller = ModuleController::getModuleController(); MessageQueue * queue = MessageQueue::lookup( PEGASUS_QUEUENAME_PROVIDERMANAGER_CPP); MessageQueueService * service = dynamic_cast<MessageQueueService *>(queue); if (service != NULL) { // create CIMNotifyConfigChangeRequestMessage CIMNotifyConfigChangeRequestMessage * notify_req = new CIMNotifyConfigChangeRequestMessage ( XmlWriter::getNextMessageId (), propertyName, newPropertyValue, currentValueModified, QueueIdStack(service->getQueueId())); notify_req->operationContext.insert( IdentityContainer(System::getEffectiveUserName())); // create request envelope AsyncLegacyOperationStart asyncRequest( NULL, service->getQueueId(), notify_req); AutoPtr<AsyncReply> asyncReply( controller->ClientSendWait(service->getQueueId(), &asyncRequest)); AutoPtr<CIMNotifyConfigChangeResponseMessage> response( reinterpret_cast<CIMNotifyConfigChangeResponseMessage *>( (static_cast<AsyncLegacyOperationResult *> (asyncReply.get()))->get_result())); if (response->cimException.getCode() != CIM_ERR_SUCCESS) { CIMException e = response->cimException; const CString exMsg = e.getMessage().getCString(); PEG_TRACE((TRC_SERVER, Tracer::LEVEL1, "Notify config changed failed with rc=%d, message = %s", e.getCode(), (const char*)exMsg)); PEG_METHOD_EXIT(); } } PEG_METHOD_EXIT(); }
TraceableCIMException::TraceableCIMException(const CIMException & cimException) : CIMException(cimException.getCode(), cimException.getMessage()) { TraceableCIMException * t = (TraceableCIMException *)&cimException; CIMExceptionRep* left; CIMExceptionRep* right; left = reinterpret_cast<CIMExceptionRep*>(_rep); right = reinterpret_cast<CIMExceptionRep*>(t->_rep); left->file = right->file; left->line = right->line; // l10n left->contentLanguages = right->contentLanguages; left->cimMessage = right->cimMessage; }
void _checkExceptionCode (const CIMException & e, const CIMStatusCode expectedCode) { if (verbose) { if (e.getCode () != expectedCode) { cerr << "CIMException comparison failed. "; cerr << "Expected " << cimStatusCodeToString (expectedCode) << "; "; cerr << "Actual exception was " << e.getMessage () << "." << endl; } } PEGASUS_ASSERT (e.getCode () == expectedCode); }
void DefaultProviderManager::_shutdownAllProviders() { PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "DefaultProviderManager::_shutdownAllProviders"); AutoMutex lock(_providerTableMutex); PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL4, "providers in cache = %d", _providers.size())); //create an array of UnloadProviderRequest requests one per //provider to process shutdown of providers simultaneously. Array<AsyncRequestExecutor::AsyncRequestMsg*> ProviderRequests; for (ProviderTable::Iterator i = _providers.start(); i != 0; i++) { AutoMutex lock(i.value()->status.getStatusMutex()); if(i.value()->status.isInitialized()) { ProviderRequests.append( new UnloadProviderRequest(i.value())); } } //run the stop request on all providers on multiple threads using //the request executor. This will invoke _asyncRequestCallback() on a //seperate thread for each provider which in turn will unload that //provider. CIMException exception = AsyncRequestExecutor(&_asyncRequestCallback,this).executeRequests( ProviderRequests); if(exception.getCode() != CIM_ERR_SUCCESS) { PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2, "Unexpected Exception in _shutdownAllProviders()."); } PEG_METHOD_EXIT(); }
// Tests getting error Element and determing if data matches the predefined // error elemement xml. static void testGetErrorElement() { CIMException cimException; Buffer text; FileSystem::loadFileToMemory(text, "./getErrorElement.xml"); CIMStatusCode errorCode = CIM_ERR_NO_SUCH_PROPERTY; String errorDescription = " The specified Property does not exist."; XmlParser parser((char*)text.getData()); XmlReader::getErrorElement(parser, cimException); if (((unsigned)cimException.getCode() != (unsigned)errorCode) || (cimException.getMessage() == errorDescription) ) { throw cimException; } PEGASUS_TEST_ASSERT(cimException.getErrorCount() == 1); CIMInstance errorInstance = cimException.getError(0).clone(); // Convert it back to a CIM_Error for analysis CIMError err1; err1.setInstance(errorInstance); // Test for correct property data. CIMError::CIMStatusCodeEnum statusCodeRtn; PEGASUS_TEST_ASSERT(err1.getCIMStatusCode(statusCodeRtn)); PEGASUS_TEST_ASSERT( statusCodeRtn == CIMError::CIM_STATUS_CODE_CIM_ERR_INVALID_PARAMETER); String OwningEntity; PEGASUS_TEST_ASSERT(err1.getOwningEntity(OwningEntity)); PEGASUS_TEST_ASSERT(OwningEntity == "OpenPegasus"); String messageIDrtn; PEGASUS_TEST_ASSERT(err1.getMessageID(messageIDrtn)); PEGASUS_TEST_ASSERT(messageIDrtn == "2206"); }
// Test against the CIMException defined by the one // defined for the test. If not equal, generate error // and return false. If the message variable is set, // also test the message against the one defined. Boolean testEnumSequence::_testCIMException(CIMException& e) { _returnedCIMExceptionCode = e.getCode(); if (e.getCode() != _expectedCIMExceptionCode) { cerr << "CIMException Error: " << e.getCode() << " " << e.getMessage() << " Expected: " << _expectedCIMExceptionCode << " " << cimStatusCodeToString(_expectedCIMExceptionCode) << endl; return false; } else { VCOUT << "Correct Exception Code received." << _testName << " " << _operationName << " Exception " << e.getCode() << " " << e.getMessage() << endl; // test for correct message if required (i.e. test string not // empty if (_expectedCIMExceptionMessage != "") { if (_globMatch(_expectedCIMExceptionMessage, e.getMessage()) != 0 ) { cerr << "Received CIMException Message Error: |" << e.getMessage() << "| does not match expected CIMException |" << _expectedCIMExceptionMessage << "|" << endl; return false; } } } return true; }
CIMResponseMessage* DefaultProviderManager::_handleDisableModuleRequest( CIMRequestMessage* message) { PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "DefaultProviderManager::_handleDisableModuleRequest"); CIMDisableModuleRequestMessage* request = dynamic_cast<CIMDisableModuleRequestMessage*>(message); PEGASUS_ASSERT(request != 0); Array<Uint16> operationalStatus; CIMException cimException; try { // get provider module name String moduleName; CIMInstance mInstance = request->providerModule; Uint32 pos = mInstance.findProperty(PEGASUS_PROPERTYNAME_NAME); PEGASUS_ASSERT(pos != PEG_NOT_FOUND); mInstance.getProperty(pos).getValue().get(moduleName); // // Unload providers // Array<CIMInstance> providerInstances = request->providers; for (Uint32 i = 0, n = providerInstances.size(); i < n; i++) { String pName; providerInstances[i].getProperty( providerInstances[i].findProperty(PEGASUS_PROPERTYNAME_NAME)). getValue().get(pName); Sint16 ret_value = _disableProvider(moduleName, pName); if (ret_value == 0) { // disable failed since there are pending requests, // stop trying to disable other providers in this module. operationalStatus.append(CIM_MSE_OPSTATUS_VALUE_OK); break; } else if (ret_value != 1) // Not success { // disable failed for other reason, throw exception throw PEGASUS_CIM_EXCEPTION_L( CIM_ERR_FAILED, MessageLoaderParms( "ProviderManager.ProviderManagerService." "DISABLE_PROVIDER_FAILED", "Failed to disable the provider.")); } } } catch (CIMException& e) { PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL1,"CIMException: %s", (const char*)e.getMessage().getCString())); cimException = e; } catch (Exception& e) { PEG_TRACE((TRC_PROVIDERMANAGER, Tracer::LEVEL1,"Exception: %s", (const char*)e.getMessage().getCString())); cimException = CIMException(CIM_ERR_FAILED, e.getMessage()); } catch (...) { PEG_TRACE_CSTRING(TRC_PROVIDERMANAGER, Tracer::LEVEL1, "Exception: Unknown"); cimException = PEGASUS_CIM_EXCEPTION_L( CIM_ERR_FAILED, MessageLoaderParms( "ProviderManager.ProviderManagerService.UNKNOWN_ERROR", "Unknown Error")); } if (cimException.getCode() == CIM_ERR_SUCCESS) { // Status is set to OK if a provider was busy if (operationalStatus.size() == 0) { operationalStatus.append(CIM_MSE_OPSTATUS_VALUE_STOPPED); } } else { // If exception occurs, module is not stopped operationalStatus.append(CIM_MSE_OPSTATUS_VALUE_OK); } CIMDisableModuleResponseMessage* response = dynamic_cast<CIMDisableModuleResponseMessage*>( request->buildResponse()); PEGASUS_ASSERT(response != 0); response->operationalStatus = operationalStatus; PEG_METHOD_EXIT(); return response; }
void DefaultPropertyOwner::_requestIndicationServiceStateChange( const String& userName, Boolean enable, Uint32 timeoutSeconds) { MessageQueue *queue = MessageQueue::lookup( PEGASUS_QUEUENAME_INDICATIONSERVICE); // Return if indication service can not be found if (!queue) { return; } Uint32 queueId = queue->getQueueId(); const String METHOD_NAME = "RequestStateChange"; const String PARAMNAME_REQUESTEDSTATE = "RequestedState"; const String PARAMNAME_TIMEOUTPERIOD = "TimeoutPeriod"; const Uint16 STATE_ENABLED = 2; const Uint16 STATE_DISABLED = 3; String referenceStr("//", 2); referenceStr.append(System::getHostName()); referenceStr.append("/"); referenceStr.append(PEGASUS_NAMESPACENAME_INTEROP.getString()); referenceStr.append(":"); referenceStr.append( PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE.getString()); CIMObjectPath reference(referenceStr); Array<CIMParamValue> inParams; Array<CIMParamValue> outParams; inParams.append(CIMParamValue(PARAMNAME_REQUESTEDSTATE, CIMValue(enable ? STATE_ENABLED : STATE_DISABLED))); inParams.append(CIMParamValue(PARAMNAME_TIMEOUTPERIOD, CIMValue(CIMDateTime(timeoutSeconds * 1000000, true)))); MessageQueueService *controller = ModuleController::getModuleController(); try { CIMInvokeMethodRequestMessage* request = new CIMInvokeMethodRequestMessage( XmlWriter::getNextMessageId(), PEGASUS_NAMESPACENAME_INTEROP, referenceStr, CIMNameCast(METHOD_NAME), inParams, QueueIdStack(queueId)); request->operationContext.insert( IdentityContainer(userName)); AsyncLegacyOperationStart *asyncRequest = new AsyncLegacyOperationStart( 0, queueId, request); AsyncReply * asyncReply = controller->SendWait(asyncRequest); CIMInvokeMethodResponseMessage * response = reinterpret_cast<CIMInvokeMethodResponseMessage *>( (static_cast<AsyncLegacyOperationResult *>( asyncReply))->get_result()); CIMException e = response->cimException; delete response; delete asyncRequest; delete asyncReply; if (e.getCode() != CIM_ERR_SUCCESS) { throw e; } } catch(const Exception &e) { PEG_TRACE((TRC_CONFIG,Tracer::LEVEL1, "Exception caught while invoking CIM_IndicationService." "RequestStateChange() method: %s", (const char*)e.getMessage().getCString())); throw; } catch(...) { PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL1, "Unknown exception caught while invoking CIM_IndicationService." "RequestStateChange() method"); throw; } }
CIMHandleIndicationResponseMessage* IndicationHandlerService::_handleIndication( CIMHandleIndicationRequestMessage* request) { PEG_METHOD_ENTER(TRC_IND_HANDLER, "IndicationHandlerService::_handleIndication()"); Boolean handleIndicationSuccess = true; CIMException cimException = PEGASUS_CIM_EXCEPTION(CIM_ERR_SUCCESS, String::EMPTY); CIMName className = request->handlerInstance.getClassName(); CIMNamespaceName nameSpace = request->nameSpace; CIMInstance indication = request->indicationInstance; CIMInstance handler = request->handlerInstance; PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4, "Handler service received %s Indication %s for %s:%s.%s Handler", (const char*)(indication.getClassName().getString().getCString()), (const char*)(request->messageId.getCString()), (const char*)(request->nameSpace.getString().getCString()), (const char*)(handler.getClassName().getString().getCString()), (const char*)(handler.getProperty(handler.findProperty( PEGASUS_PROPERTYNAME_NAME)).getValue().toString().getCString()))); Uint32 pos = PEG_NOT_FOUND; if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_CIMXML) || className.equal (PEGASUS_CLASSNAME_LSTNRDST_CIMXML)) { pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_DESTINATION); if (pos == PEG_NOT_FOUND) { cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "HandlerService.IndicationHandlerService." "CIMXML_HANDLER_WITHOUT_DESTINATION", "CIMXml Handler missing Destination property")); handleIndicationSuccess = false; } else { CIMProperty prop = handler.getProperty(pos); String destination = prop.getValue().toString(); if (destination.size() == 0) { cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "HandlerService.IndicationHandlerService." "INVALID_DESTINATION", "invalid destination")); handleIndicationSuccess = false; } //compared index 10 is not : else if (destination.subString(0, 10) == String("localhost/")) { Uint32 exportServer = find_service_qid(PEGASUS_QUEUENAME_EXPORTREQDISPATCHER); // Listener is build with Cimom, so send message to ExportServer AutoPtr<CIMExportIndicationRequestMessage> exportmessage( new CIMExportIndicationRequestMessage( XmlWriter::getNextMessageId(), //taking localhost/CIMListener portion out from reg destination.subString(21), indication, QueueIdStack(exportServer, getQueueId()), String::EMPTY, String::EMPTY)); exportmessage->operationContext.insert( IdentityContainer(String::EMPTY)); exportmessage->operationContext.set( request->operationContext.get( ContentLanguageListContainer::NAME)); AutoPtr<AsyncOpNode> op( this->get_op()); AutoPtr<AsyncLegacyOperationStart> asyncRequest( new AsyncLegacyOperationStart( op.get(), exportServer, exportmessage.get())); exportmessage.release(); PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL4, "Indication handler forwarding message to %s", ((MessageQueue::lookup(exportServer)) ? ((MessageQueue::lookup(exportServer))-> getQueueName()): "BAD queue name"))); PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4, "Sending %s Indication %s to destination %s", (const char*) (indication.getClassName().getString(). getCString()), (const char*)(request->messageId.getCString()), (const char*) destination.getCString())); //SendAsync(op, // exportServer[0], // IndicationHandlerService::_handleIndicationCallBack, // this, // (void *)request->queueIds.top()); AutoPtr<AsyncReply> asyncReply(SendWait(asyncRequest.get())); asyncRequest.release(); // Return the ExportIndication results in HandleIndication //response AutoPtr<CIMExportIndicationResponseMessage> exportResponse( reinterpret_cast<CIMExportIndicationResponseMessage *>( (static_cast<AsyncLegacyOperationResult *>( asyncReply.get()))->get_result())); cimException = exportResponse->cimException; this->return_op(op.release()); } else { handleIndicationSuccess = _loadHandler(request, cimException); } } } else if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_SNMP)) { pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST); if (pos == PEG_NOT_FOUND) { cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "HandlerService.IndicationHandlerService." "SNMP_HANDLER_WITHOUT_TARGETHOST", "Snmp Handler missing Targethost property")); handleIndicationSuccess = false; } else { CIMProperty prop = handler.getProperty(pos); String destination = prop.getValue().toString(); if (destination.size() == 0) { cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "HandlerService.IndicationHandlerService." "INVALID_TARGETHOST", "invalid targethost")); handleIndicationSuccess = false; } else { handleIndicationSuccess = _loadHandler(request, cimException); } } } else if ((className.equal (PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG)) || (className.equal (PEGASUS_CLASSNAME_LSTNRDST_EMAIL))) { handleIndicationSuccess = _loadHandler(request, cimException); } // no success to handle indication // somewhere an exception message was build // time to write the error message to the log if (!handleIndicationSuccess) { Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING, MessageLoaderParms( "HandlerService.IndicationHandlerService." "INDICATION_DELIVERY_FAILED", "Failed to deliver an indication: $0", cimException.getMessage())); } CIMHandleIndicationResponseMessage* response = dynamic_cast<CIMHandleIndicationResponseMessage*>( request->buildResponse()); response->cimException = cimException; delete request; PEG_METHOD_EXIT(); return response; }