bool AsyncThriftForwarder::init()
{
	TLogger::configure();
	this->setApplicationName("asyncthrift-forwarder");

	try {
		QtArgCmdLine cmdline;

		QtArg config('c', "config", "Configuration directory override", false, true);
		QtArg daemonize('d', "daemonize", "Daemonize on start", false, false);
		QtArg user('u', "user", "Run as the given user", false, true);

		QtArgHelp help(&cmdline);
		help.printer()->setProgramDescription("Thrift asynchronous server forwarder.");
		help.printer()->setExecutableName(this->applicationName());

		cmdline.addArg(&config);
		cmdline.addArg(&daemonize);
		cmdline.addArg(&user);
		cmdline.addArg(help);
		cmdline.parse();

		if (config.isPresent())
			config_dir = QDir(config.value().toString());

		if (!config_dir.exists()) {
			TERROR("Invalid configuration directory: '%s'", qPrintable(config_dir.path()));
			return false;
		}

		config_dir.makeAbsolute();

		if (!TApplication::init(QList<int>() << SIGINT << SIGTERM << SIGHUP, daemonize.isPresent(), user.value().toString(), "asyncthrift/forwarder"))
			return false;
	} catch (const QtArgHelpHasPrintedEx& ex) {
		return false;
	} catch (const QtArgBaseException& ex) {
		TERROR("%s", ex.what());
		return false;
	}

	if (!reloadConfig())
		return false;

	return true;
}
Esempio n. 2
0
/**
 * after ending experiment, host must
 * send your counters to controller
 */
static void tikle_send_log(void)
{
	int tikle_err;

	if ((tikle_err = sock_create(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &tikle_comm->sock_log)) < 0) {
		TERROR("error %d while creating sockudp\n", -ENXIO);
	}

	memset(&tikle_comm->addr_log, 0, sizeof(struct sockaddr));
	tikle_comm->addr_log.sin_family = AF_INET;
	tikle_comm->addr_log.sin_addr.s_addr = tikle_comm->addr_recv.sin_addr.s_addr;
	tikle_comm->addr_log.sin_port = htons(PORT_LOGGING);

	if ((tikle_err = tikle_comm->sock_send->ops->connect(tikle_comm->sock_send,(struct sockaddr *)&tikle_comm->addr_send, sizeof(struct sockaddr), 0)) < 0) {
		TERROR("error %d while connecting to socket\n", -tikle_err);
		sock_release(tikle_comm->sock_send);
		tikle_comm->sock_log = NULL; 
	}

	tikle_sockudp_send(tikle_comm->sock_log, &tikle_comm->addr_log, tikle_log_counters, sizeof(unsigned long) * log_size);
}
Esempio n. 3
0
// ==================================================================
action_result_t TActionRegExp::exec(Tractor *tractor) const
// ==================================================================
{
	T_ASSERT(tractor);
	T_ASSERT(m_data.size());
	T_ASSERT(m_regexp.size());

	QString text(tractor->substituteValues(m_data));
	QStringList assign(m_assignto.split(",", QString::SkipEmptyParts));
	QStringList::const_iterator iter(assign.constBegin());

	QRegExp regexp(m_regexp);
	if (m_case_sensitive)
	{
		regexp.setCaseSensitivity(Qt::CaseSensitive);
	}
	else
	{
		regexp.setCaseSensitivity(Qt::CaseInsensitive);
	}

	if (m_minimal)
	{
		regexp.setMinimal(true);
	}

	int pos(text.indexOf(regexp));

	if (m_strict && pos < 0)
	{
		TERROR(("strict RegExp did not match"));
		return failure(tractor);
	}

	while (pos >= 0 && iter != assign.constEnd())
	{
		tractor->setValue(*iter, regexp.cap(1), m_global);
		pos += regexp.matchedLength();
		pos = text.indexOf(regexp, pos);
		++iter;
	}

	return action_result_normal;
}
Esempio n. 4
0
// ==================================================================
action_result_t TActionFailure::failure(Tractor * tractor) const
// ==================================================================
{
	T_ASSERT(tractor);

	TERROR(("Failure: Action %s, mark error %d",
	        getFailureStr(m_failure_type), m_error_mark));

	if (m_error_mark)
	{
		tractor->setError(true);
	}

	switch (m_failure_type)
	{
		case action_failure_type_none:
		{
			FATAL(("Failure type not set"));
			T_ASSERT(false);
			return action_result_abort;
		}

		case action_failure_type_continue:
		{
			return action_result_normal;
		}

		case action_failure_type_return:
		{
			// same as TActionReturn
			tractor->popStation();
			return action_result_station_update;
		}

		case action_failure_type_station:
		{
			const TStation *station(tractor->getFarm()->getMap()
			                        ->getStation(m_station));
			if (station)
			{
				tractor->popStation();
				tractor->pushStation(station, &m_station_args);
				return action_result_station_update;
			}

			/// fall trough!
		}

		case action_failure_type_exit:
		{
			tractor->setState(tractor_state_stop);
			/// fall trough!
		}

		case action_failure_type_stop:
		{
			// clear station stack
			// same as TActionStop
			while (tractor->topStation())
			{
				tractor->popStation();
			}

			return action_result_station_update;
		}

		default:
		{
			ERROR(("Unhandled failure type"));
			break;
		}
	}

	return action_result_abort;
}