Ejemplo n.º 1
0
//=============================================================================
// METHOD: SPELLlistenerContext::startContext
//=============================================================================
SPELLipcMessage SPELLlistenerContext::startContext( const SPELLipcMessage& msg )
{
    std::string cmd;
    std::string name;

    name = msg.get(MessageField::FIELD_CTX_NAME);

    cmd = SPELLutils::getSPELL_HOME() + PATH_SEPARATOR + "bin" + PATH_SEPARATOR 
        + "SPELL-Context -n " + name + " -s " + ISTR(m_port)
        + " -c " + m_configFile;

    DEBUG("Opening context using command: " + cmd);

    std::string identifier = "CTX_" + name;

    // Will have no effect if the listener is there already
    SPELLprocessManager::instance().addListener("CTX_" + name, this);

    // Clear process information, in case it is there already
    SPELLprocessManager::instance().clearProcess(identifier);
    // Register and start the process
    SPELLprocessManager::instance().startProcess("CTX_" + name, cmd);

    // Notify to other clients
    SPELLipcMessage notify( msg );
    notify.setId( ListenerMessages::MSG_CONTEXT_OP );
    notify.setType( MSG_TYPE_ONEWAY );
    notify.set( MessageField::FIELD_CTX_STATUS, MessageValue::DATA_CTX_STARTING );
    notify.setSender("LST");
    notify.setReceiver("GUI");
    m_gui->displace(&notify);

    DEBUG("Wait context " + name + " login");
    m_waitForContextStart.clear();
    bool timeout = m_waitForContextStart.wait(15*1000);
    DEBUG("Wait context " + name + " login done: timeout " + BSTR(timeout));

    if (timeout)
    {
    	SPELLipcMessage resp = SPELLipcHelper::createErrorResponse(ContextMessages::RSP_OPEN_CTX, msg);
    	resp.set( MessageField::FIELD_FATAL, PythonConstants::True);
    	resp.set( MessageField::FIELD_ERROR, "Cannot open context " + name);
    	resp.set( MessageField::FIELD_REASON, "Context did not log in in time");
    	return resp;
    }
    else
    {
    	LOG_INFO("Context running");
    	return SPELLipcHelper::createResponse(ContextMessages::RSP_OPEN_CTX, msg);
    }
}
Ejemplo n.º 2
0
//=============================================================================
// METHOD: SPELLexecutorIPC::
//=============================================================================
SPELLipcMessage SPELLexecutorIPC::sendRequest( const std::string& executorId, const SPELLipcMessage& msg, unsigned long timeoutMsec )
{
	if (m_connected)
	{
		SPELLipcMessage toSend(msg);
		return m_ipc.sendRequest(toSend,timeoutMsec);
	}
	else
	{
		SPELLipcMessage resp = SPELLipcHelper::createErrorResponse("IpcErrorResponse", msg);
		resp.set( MessageField::FIELD_ERROR, "Cannot send request" );
		resp.set( MessageField::FIELD_REASON, "IPC not connected");
		resp.set( MessageField::FIELD_FATAL, PythonConstants::True );
		return resp;
	}
}
Ejemplo n.º 3
0
//=============================================================================
// METHOD: SPELLclientManager::
//=============================================================================
void SPELLclientManager::completeMonitoringInfo( const std::string& procId, SPELLipcMessage& msg )
{
	std::list<std::string> monitoring = getMonitoringClients(procId);
	std::list<std::string>::iterator it;
	std::string monitoringList = "";
	for( it = monitoring.begin(); it != monitoring.end(); it++)
	{
		if (monitoringList != "") monitoringList += ",";
		monitoringList += (*it);
	}
	msg.set( MessageField::FIELD_GUI_LIST, monitoringList );
}
Ejemplo n.º 4
0
 SPELLipcMessage* processRequest( SPELLipcMessage* msg )
 {
     SPELLipcMessage* resp = SPELLipcHelper::createResponse("dummy", msg);
     try
     {
         std::cout << "request received from " << msg->getKey() << ": " << msg->get("NUM") << std::endl;
         resp->setId("resp");
         resp->setType(MSG_TYPE_RESPONSE);
         resp->set("NUM", msg->get("NUM"));
         usleep(200000);
     }
     catch(SPELLcoreException& ex)
     {
         std::cerr << "PROCESS ERROR: " << ex.what() << std::endl;
     }
     return resp;
 };
Ejemplo n.º 5
0
//=============================================================================
// METHOD: SPELLlistenerContext::fillContextInfo
//=============================================================================
void SPELLlistenerContext::fillContextInfo(const std::string ctxName, SPELLipcMessage& msg )
{
    std::string driverName;
    SPELLcontextConfig* ctxConfig;
    SPELLdriverConfig* drvConfig;
    ContextInfo* ctxInfo;

	ctxInfo = &m_openContexts[ctxName];
	ctxConfig = ctxInfo->m_ctxConfig;
	drvConfig = ctxInfo->m_drvConfig;

	msg.set(MessageField::FIELD_CTX_NAME, ctxName);
	msg.set( MessageField::FIELD_CTX_PORT, ISTR(ctxInfo->m_port) );

	if (ctxConfig != NULL)
	{
		msg.set(MessageField::FIELD_CTX_DRV, ctxConfig->getDriverName());
		msg.set(MessageField::FIELD_CTX_SC, ctxConfig->getSC());
		msg.set(MessageField::FIELD_CTX_FAM, ctxConfig->getFamily());
		msg.set(MessageField::FIELD_CTX_GCS, ctxConfig->getGCS());
		msg.set(MessageField::FIELD_CTX_DESC, ctxConfig->getDescription());
		msg.set(MessageField::FIELD_CTX_STATUS, ctxInfo->m_status);
	}
	else
	{
		msg.set(MessageField::FIELD_CTX_DRV, "Unknown");
		msg.set(MessageField::FIELD_CTX_SC, "Unknown");
		msg.set(MessageField::FIELD_CTX_FAM, "Unknown");
		msg.set(MessageField::FIELD_CTX_GCS, "Unknown");
		msg.set(MessageField::FIELD_CTX_DESC, "Unknown");
		msg.set(MessageField::FIELD_CTX_STATUS, "ERROR");
	}

	if (drvConfig != NULL)
	{
		msg.set(MessageField::FIELD_CTX_MAXPROC, ISTR(drvConfig->getMaxProcs()));
	}
	else
	{
		msg.set(MessageField::FIELD_CTX_MAXPROC, "0" );
	}
}
Ejemplo n.º 6
0
//=============================================================================
// 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;
}