예제 #1
0
void JobAf::construct()
{
	AF_DEBUG << '"' << m_name << "\": from store: " << isFromStore();

	if( NULL != m_blocks )
	{
		AF_ERR << "Already constructed.";
		return;
	}

	if( m_blocks_num < 1 )
	{
		AF_ERR << "invalid number of blocks = " << m_blocks_num;
		return;
	}

	m_blocks = new Block*[m_blocks_num];
	if( NULL == m_blocks )
	{
		AF_ERR << "Can't allocate memory for blocks.";
		return;
	}
	for( int b = 0; b < m_blocks_num; b++) m_blocks[b] = NULL;
	for( int b = 0; b < m_blocks_num; b++)
	{
		m_blocks[b] = v_newBlock(b);
		if( m_blocks[b] == NULL )
		{
			AF_ERR << "Can't create block " << b << " of " << m_blocks_num;
			return;
		}
	}
}
예제 #2
0
파일: renderaf.cpp 프로젝트: RISEFX/cgru
void RenderAf::setRegistered()
{
	getFarmHost();

	if( isFromStore())
	{
		appendLog("Initialized from store.");
	}
	else
	{
		m_time_register = time( NULL);
		setStoreDir( AFCommon::getStoreDirRender( *this));
		store();
		appendLog("Registered.");
	}

	af::Client::setRegisterTime();

	m_task_start_finish_time = 0;
	m_wol_operation_time = 0;
	m_idle_time = time(NULL);
	m_busy_time = m_idle_time;

	if( isOnline()) appendLog("Registered online.");
	else appendLog("Registered offline.");
}
예제 #3
0
bool JobAf::isValidConstructed() const
{
	std::string err;

	if( isValid( &err))
	{
		if( NULL == m_blocks )
			err += "Job '" + m_name + "' is not constructed.";
	}

	if( err.size())
	{
		err = std::string("Invalid job '") + m_name + "': " + err;
		if( isFromStore())
			AF_ERR << err;
		else
			AFCommon::QueueLogError( err);
		return false;
	}

	AF_DEBUG << '"' << m_name << "\": TRUE; from store: " << isFromStore();

	return true;
}
예제 #4
0
파일: branchsrv.cpp 프로젝트: CGRU/cgru
bool BranchSrv::initialize()
{
	// Non root branch should have a parent
	if ((m_name != "/") && (NULL == m_parent))
	{
		AF_ERR << "BranchSrv::initialize: Branch['" << m_name << "'] has NULL parent.";
		return false;
	}

	if (NULL != m_parent)
	{
		m_parent_path = m_parent->getName();
		m_parent->addBranch(this);
	}

	if (isFromStore())
	{
		if (m_time_creation == 0)
		{
			m_time_creation = time(NULL);
			store();
		}
		appendLog("Initialized from store.");
	}
	else
	{
		if (NULL == m_parent)
		{
			// The root branch is just created for the first time (not from store)
			setCreateChilds(true);
			setSolveJobs(true);
			m_max_tasks_per_second = AFBRANCH::TASKSPERSECOND_ROOT;
		}

		m_time_creation = time(NULL);

		setStoreDir(AFCommon::getStoreDirBranch(*this));
		store();
		appendLog("Initialized.");
	}

	return true;
}
예제 #5
0
파일: useraf.cpp 프로젝트: g-LuL/cgru
bool UserAf::initialize()
{
	if( isFromStore())
	{
		if(( getTimeRegister() == 0 ) || ( getTimeActivity() == 0 ))
		{
			if( getTimeRegister() == 0 ) setTimeRegister();
			if( getTimeActivity() == 0 ) updateTimeActivity();
			store();
		}
		appendLog("Initialized from store.");
	}
	else
	{
		setTimeRegister();
		updateTimeActivity();
		setStoreDir( AFCommon::getStoreDirUser( *this));
		store();
		appendLog("Registered.");
	}

	return true;
}
예제 #6
0
bool JobAf::initialize()
{
	AF_DEBUG << "'" << m_name << "'[" << m_id << "]:";
	
	//
	//	Set job ID to blocks and progress classes:
	m_progress->setJobId( m_id);
	for( int b = 0; b < m_blocks_num; b++)
	{
		m_blocks_data[b]->setJobId( m_id);
	}

	//
	// Store job ( if not stored )
	if( isFromStore() == false )
	{
		setStoreDir( AFCommon::getStoreDirJob( *this));

		initStoreDirs();

		// Write blocks tasks data:
		for( int b = 0; b < m_blocks_num; b++)
			m_blocks[b]->storeTasks();

		std::ostringstream ostr;
		v_jsonWrite( ostr, 0);
		std::string str = ostr.str();
		AFCommon::writeFile( str.c_str(), str.size(), getStoreFile());
	}

	// Create tasks store folder (if does not exists any)
	if(( af::pathIsFolder( m_store_dir_tasks) == false ) && ( af::pathMakePath( m_store_dir_tasks) == false ))
	{
		AFCommon::QueueLogError( std::string("Unable to create tasks store folder:\n") + m_store_dir_tasks);
		return false;
	}

	//
	// Executing pre commands ( if not from database )
	if( isFromStore() == false )
	{
		if( false == m_command_pre.empty())
		{
			AFCommon::executeCmd( m_command_pre);
			appendLog( std::string("Job pre command executed:\n") + m_command_pre);
		}
		for( int b = 0; b < m_blocks_num; b++)
		{
			if( m_blocks_data[b]->hasCmdPre() )
			{
				AFCommon::executeCmd( m_blocks_data[b]->getCmdPre());
				appendLog( std::string("Block[") + m_blocks_data[b]->getName() + "] pre command executed:\n" + m_blocks_data[b]->getCmdPre());
			}
		}
		appendLog("Initialized.");
	}
	else
	{
		appendLog("Initialized from database.");
	}

	//
	// Checking states
	for( int b = 0; b < m_blocks_num; b++)
	{
		int numtasks = m_blocks_data[b]->getTasksNum();
		for( int t = 0; t < numtasks; t++)
		{
			uint32_t taskstate = m_progress->tp[b][t]->state;

			if( taskstate == 0 )
			{
				taskstate = AFJOB::STATE_READY_MASK;
			}
			else if( taskstate & AFJOB::STATE_RUNNING_MASK && ( false == m_blocks_data[b]->isMultiHost()))
			{
				taskstate = taskstate | AFJOB::STATE_WAITRECONNECT_MASK;
				taskstate = taskstate & (~AFJOB::STATE_RUNNING_MASK );
				m_progress->tp[b][t]->time_done = time(NULL);
				m_blocks[b]->m_tasks[t]->v_appendLog(
						"Task was running at server start. Waiting for render reconnect...");
			}

			m_progress->tp[b][t]->state = taskstate;
		}
	}
	
	if(( m_state & AFJOB::STATE_DONE_MASK) == false ) m_state = m_state | AFJOB::STATE_WAITDEP_MASK;
	
	v_refresh( time(NULL), NULL, NULL);
	
	return true;
}
예제 #7
0
    m_user             = NULL;
    m_blocks           = NULL;
	m_progress         = NULL;
    m_deletion         = false;
    m_logsWeight       = 0;
    m_blackListsWeight = 0;
}

void JobAf::initStoreDirs()
{
	m_store_dir_tasks = getStoreDir() + AFGENERAL::PATH_SEPARATOR + "tasks";
}

void JobAf::construct()
{
	AFINFA("JobAf::construct: \"%s\": from store: %d", m_name.c_str(), isFromStore())

	if( m_blocks != NULL )
	{
		AFERROR("JobAf::construct: Already constructed.")
		return;
	}

	if( m_blocks_num < 1 )
	{
		AFERRAR("JobAf::construct: invalid number of blocks = %d", m_blocks_num)
		return;
	}

	m_blocks = new Block*[m_blocks_num];
	if( m_blocks == NULL )