//============================================================================= // METHOD: SPELLclientIPC:: //============================================================================= SPELLipcMessage SPELLclientIPC::processRequest( const SPELLipcMessage& msg ) { int clientKey = msg.getKey(); DEBUG("[CLTRCV] Received request from client: " + msg.getId()); SPELLipcMessage resp = VOID_MESSAGE; SPELLclientInterestList* list = getClientInterestList(clientKey); // If the message is a login message, redirect it to the client manager if (msg.getId() == ContextMessages::REQ_GUI_LOGIN) { SPELLclientManager::instance().clientLogin(clientKey, msg.get( MessageField::FIELD_HOST )); resp = SPELLipcHelper::createResponse(ContextMessages::RSP_GUI_LOGIN, msg); } // If the message is a logout message, redirect it to the client manager else if (msg.getId() == ContextMessages::REQ_GUI_LOGOUT ) { // No need to close IPC here. When the GUI receives the response, // it will close the channel by sending EOC. There, IPC layer will // automatically close the corresponding channel. SPELLclientManager::instance().clientLogout(clientKey); resp = SPELLipcHelper::createResponse(ContextMessages::RSP_GUI_LOGOUT, msg); } else if (list != NULL) { //DEBUG("[CLTRCV] Distribute client request: " + msg.getId()); resp = list->distributeRequest(msg); //DEBUG("[CLTRCV] Got response for client request: " + msg.getId()); // Executor request additional processing (request attended by executor that need to be processed in context also) // But only if the response is not an error if (resp.getType() != MSG_TYPE_ERROR) { if (msg.getId() == ExecutorMessages::REQ_SET_CONFIG) { SPELLipcMessage cfgChange( msg ); cfgChange.setId( ContextMessages::MSG_EXEC_CONFIG ); cfgChange.setType( MSG_TYPE_ONEWAY ); SPELLclientManager::instance().notifyMonitoringClients(&cfgChange); } } if (resp.isVoid()) { LOG_ERROR("Unable to get response for client request " + msg.getId()); } } else { LOG_ERROR("No listeners for client " + ISTR(clientKey) + " to distribute request: " + msg.getId()); } return resp; }
//============================================================================= // METHOD: SPELLclient:: //============================================================================= SPELLipcMessage SPELLclient::processRequestFromClient( const SPELLipcMessage& msg ) { //DEBUG(" Client request start"); // Create the login message std::string requestId = msg.getId(); SPELLipcMessage resp = VOID_MESSAGE; try { if ( requestId == ContextMessages::REQ_INSTANCE_ID ) { resp = SPELLcontext::instance().getInstanceId( msg ); } else if ( requestId == ContextMessages::REQ_OPEN_EXEC ) { resp = SPELLcontext::instance().openExecutor( msg, this ); } else if ( requestId == ContextMessages::REQ_CLOSE_EXEC ) { resp = SPELLcontext::instance().closeExecutor( msg ); } else if ( requestId == ContextMessages::REQ_KILL_EXEC ) { resp = SPELLcontext::instance().killExecutor( msg ); } else if ( requestId == ContextMessages::REQ_ATTACH_EXEC ) { resp = SPELLcontext::instance().attachExecutor( msg, this ); } else if ( requestId == ContextMessages::REQ_DETACH_EXEC ) { resp = SPELLcontext::instance().detachExecutor( msg, this ); } else if (msg.getId() == ContextMessages::REQ_RECOVER_EXEC) { resp = SPELLcontext::instance().recoverExecutor( msg, this ); } else if (msg.getId() == ContextMessages::REQ_PROC_LIST) { resp = SPELLcontext::instance().getProcedureList( msg ); } else if (msg.getId() == ContextMessages::REQ_EXEC_LIST) { resp = SPELLcontext::instance().getExecutorList( msg ); } else if (msg.getId() == ContextMessages::REQ_PROC_PROP) { resp = SPELLcontext::instance().getProcedureProperties( msg ); } else if (msg.getId() == ContextMessages::REQ_PROC_CODE) { resp = SPELLcontext::instance().getProcedureCode( msg ); } else if (msg.getId() == ContextMessages::REQ_EXEC_INFO) { resp = SPELLcontext::instance().getExecutorInfo( msg ); } else if (msg.getId() == ContextMessages::REQ_CLIENT_INFO) { resp = SPELLcontext::instance().getClientInfo( msg ); } else if (msg.getId() == ContextMessages::REQ_SERVER_FILE_PATH) { resp = SPELLcontext::instance().getServerFilePath( msg ); } else if (msg.getId() == ContextMessages::REQ_RECOVERY_LIST) { resp = SPELLcontext::instance().getProcedureRecoveryList( msg ); } else if (msg.getId() == ContextMessages::REQ_ASRUN_LIST) { resp = SPELLcontext::instance().getProcedureAsRunList( msg ); } else if (msg.getId() == ContextMessages::REQ_DELETE_RECOVERY ) { resp = SPELLcontext::instance().deleteRecoveryFiles(msg); } else if (msg.getId() == ContextMessages::REQ_REMOVE_CONTROL ) { resp = SPELLcontext::instance().removeControl(msg); } else if (msg.getId() == ContextMessages::REQ_SET_BACKGROUND ) { resp = SPELLcontext::instance().setExecutorInBackground(msg); } else if (msg.getId() == ContextMessages::REQ_LIST_FILES ) { resp = SPELLcontext::instance().listFiles(msg); } else if (msg.getId() == ContextMessages::REQ_LIST_DATADIRS ) { resp = SPELLcontext::instance().listDataDirectories(msg); } else if (msg.getId() == ContextMessages::REQ_INPUT_FILE ) { resp = SPELLcontext::instance().getInputFile(msg); } else if (msg.getId() == ContextMessages::REQ_CURRENT_TIME ) { resp = SPELLcontext::instance().getCurrentTime(msg); } else if ( requestId == ContextMessages::REQ_DEL_SHARED_DATA ) { resp = SPELLcontext::instance().clearSharedData(msg); } else if ( requestId == ContextMessages::REQ_SET_SHARED_DATA ) { resp = SPELLcontext::instance().setSharedData(msg); } else if ( requestId == ContextMessages::REQ_GET_SHARED_DATA ) { resp = SPELLcontext::instance().getSharedData(msg); } else if ( requestId == ContextMessages::REQ_GET_SHARED_DATA_KEYS ) { resp = SPELLcontext::instance().getSharedDataKeys(msg); } else if ( requestId == ContextMessages::REQ_GET_SHARED_DATA_SCOPES ) { resp = SPELLcontext::instance().getSharedDataScopes(msg); } else if ( requestId == ContextMessages::REQ_DEL_SHARED_DATA_SCOPE ) { resp = SPELLcontext::instance().removeSharedDataScope(msg); } else if ( requestId == ContextMessages::REQ_ADD_SHARED_DATA_SCOPE ) { resp = SPELLcontext::instance().addSharedDataScope(msg); } else if ( requestId == ContextMessages::REQ_GET_CTX_EXEC_DFLT ) { resp = SPELLcontext::instance().getExecutorDefaults(msg); } else if ( requestId == ContextMessages::REQ_SET_CTX_EXEC_DFLT ) { resp = SPELLcontext::instance().setExecutorDefaults(msg); } else { // Forward the request to the executor std::string procId = msg.get( MessageField::FIELD_PROC_ID ); try { DEBUG( NAME + "Forward request to executor " + procId +": " + msg.getId()); SPELLexecutor* exec = SPELLexecutorManager::instance().getExecutor(procId); resp = exec->sendRequestToExecutor(msg); if (resp.isVoid()) { LOG_ERROR("Unable to obtain response for client request " + msg.getId() + " from executor "); } } catch( SPELLcoreException& ex ) { LOG_ERROR( NAME + "Unable to send request to executor '" + procId + "', unable to find"); std::string id = msg.getId(); SPELLutils::replace(id, "REQ", "RSP"); resp = SPELLipcHelper::createErrorResponse(id,msg); resp.set(MessageField::FIELD_ERROR, "Unable to send request to executor " + procId); resp.set(MessageField::FIELD_REASON, "Cannot find the executor"); resp.set(MessageField::FIELD_FATAL, PythonConstants::True ); } } } catch(SPELLexecutorManager::OperationError& err) { LOG_ERROR( NAME + "Error in client request processing " + ISTR(err.errorCode)); std::string id = msg.getId(); SPELLutils::replace(id, "REQ", "RSP"); resp = SPELLipcHelper::createErrorResponse(id,msg); resp.set(MessageField::FIELD_ERROR, "Error in client processing"); resp.set(MessageField::FIELD_REASON, err.message); resp.set(MessageField::FIELD_FATAL, PythonConstants::True); } catch(...) { LOG_ERROR( NAME + "Unknown error in client request processing"); std::string id = msg.getId(); SPELLutils::replace(id, "REQ", "RSP"); resp = SPELLipcHelper::createErrorResponse(id,msg); resp.set(MessageField::FIELD_ERROR, "Error in client processing"); resp.set(MessageField::FIELD_REASON, "Unknown reason"); resp.set(MessageField::FIELD_FATAL, PythonConstants::True); } //DEBUG(" Client request end"); return resp; }