Merge pull request #253 from radiorabe/feature/refactor-config-structure
Simplify configuration file structure
This commit is contained in:
commit
bd845a016d
14 changed files with 47 additions and 107 deletions
|
@ -55,7 +55,7 @@ class CeleryManager {
|
|||
* results asynchronously later
|
||||
*/
|
||||
public static function sendCeleryMessage($task, $exchange, $data) {
|
||||
$config = parse_ini_file(Application_Model_RabbitMq::getRmqConfigPath(), true);
|
||||
$config = Config::getConfig();
|
||||
$queue = $routingKey = $exchange;
|
||||
$c = self::_setupCeleryExchange($config, $exchange, $queue); // Use the exchange name for the queue
|
||||
$result = $c->PostTask($task, $data, true, $routingKey); // and routing key
|
||||
|
@ -75,7 +75,7 @@ class CeleryManager {
|
|||
* $_CELERY_MESSAGE_TIMEOUT milliseconds have passed
|
||||
*/
|
||||
private static function getAsyncResultMessage($task) {
|
||||
$config = parse_ini_file(Application_Model_RabbitMq::getRmqConfigPath(), true);
|
||||
$config = Config::getConfig();
|
||||
$queue = self::$_CELERY_RESULTS_EXCHANGE . "." . $task;
|
||||
$c = self::_setupCeleryExchange($config, self::$_CELERY_RESULTS_EXCHANGE, $queue);
|
||||
$message = $c->getAsyncResultMessage($task->getDbName(), $task->getDbTaskId());
|
||||
|
|
|
@ -49,23 +49,16 @@ class Config {
|
|||
$CC_CONFIG['staticBaseDir'] = '/';
|
||||
}
|
||||
|
||||
// Parse separate conf file for cloud storage values
|
||||
$cloudStorageConfig = LIBRETIME_CONF_DIR . '/' . $CC_CONFIG['dev_env']."/cloud_storage.conf";
|
||||
if (!file_exists($cloudStorageConfig)) {
|
||||
// If the dev env specific cloud_storage.conf doesn't exist default
|
||||
// to the production cloud_storage.conf
|
||||
$cloudStorageConfig = LIBRETIME_CONF_DIR . "/production/cloud_storage.conf";
|
||||
}
|
||||
$cloudStorageValues = parse_ini_file($cloudStorageConfig, true);
|
||||
|
||||
$CC_CONFIG["supportedStorageBackends"] = array('amazon_S3');
|
||||
foreach ($CC_CONFIG["supportedStorageBackends"] as $backend) {
|
||||
$CC_CONFIG[$backend] = $cloudStorageValues[$backend];
|
||||
}
|
||||
$CC_CONFIG['amazon_S3'] = array(
|
||||
'provider' => $values['amazon_S3']['provider'],
|
||||
'bucket' => $values['amazon_S3']['bucket'],
|
||||
'api_key' => $values['amazon_S3']['api_key'],
|
||||
'api_key_secret' => $values['amazon_S3']['api_key_secret']
|
||||
);
|
||||
|
||||
// Tells us where file uploads will be uploaded to.
|
||||
// It will either be set to a cloud storage backend or local file storage.
|
||||
$CC_CONFIG["current_backend"] = $cloudStorageValues["current_backend"]["storage_backend"];
|
||||
$CC_CONFIG["current_backend"] = $values["current_backend"]["storage_backend"];
|
||||
|
||||
$CC_CONFIG['cache_ahead_hours'] = $values['general']['cache_ahead_hours'];
|
||||
|
||||
|
@ -81,20 +74,13 @@ class Config {
|
|||
$CC_CONFIG['soundcloud-connection-retries'] = $values['soundcloud']['connection_retries'];
|
||||
$CC_CONFIG['soundcloud-connection-wait'] = $values['soundcloud']['time_between_retries'];
|
||||
|
||||
$globalAirtimeConfig = LIBRETIME_CONF_DIR . '/' . $CC_CONFIG['dev_env']."/airtime.conf";
|
||||
if (!file_exists($globalAirtimeConfig)) {
|
||||
// If the dev env specific airtime.conf doesn't exist default
|
||||
// to the production airtime.conf
|
||||
$globalAirtimeConfig = LIBRETIME_CONF_DIR . "/production/airtime.conf";
|
||||
}
|
||||
$globalAirtimeConfigValues = parse_ini_file($globalAirtimeConfig, true);
|
||||
$CC_CONFIG['soundcloud-client-id'] = $globalAirtimeConfigValues['soundcloud']['soundcloud_client_id'];
|
||||
$CC_CONFIG['soundcloud-client-secret'] = $globalAirtimeConfigValues['soundcloud']['soundcloud_client_secret'];
|
||||
$CC_CONFIG['soundcloud-redirect-uri'] = $globalAirtimeConfigValues['soundcloud']['soundcloud_redirect_uri'];
|
||||
if (isset($globalAirtimeConfigValues['facebook']['facebook_app_id'])) {
|
||||
$CC_CONFIG['facebook-app-id'] = $globalAirtimeConfigValues['facebook']['facebook_app_id'];
|
||||
$CC_CONFIG['facebook-app-url'] = $globalAirtimeConfigValues['facebook']['facebook_app_url'];
|
||||
$CC_CONFIG['facebook-app-api-key'] = $globalAirtimeConfigValues['facebook']['facebook_app_api_key'];
|
||||
$CC_CONFIG['soundcloud-client-id'] = $values['soundcloud']['soundcloud_client_id'];
|
||||
$CC_CONFIG['soundcloud-client-secret'] = $values['soundcloud']['soundcloud_client_secret'];
|
||||
$CC_CONFIG['soundcloud-redirect-uri'] = $values['soundcloud']['soundcloud_redirect_uri'];
|
||||
if (isset($values['facebook']['facebook_app_id'])) {
|
||||
$CC_CONFIG['facebook-app-id'] = $values['facebook']['facebook_app_id'];
|
||||
$CC_CONFIG['facebook-app-url'] = $values['facebook']['facebook_app_url'];
|
||||
$CC_CONFIG['facebook-app-api-key'] = $values['facebook']['facebook_app_api_key'];
|
||||
}
|
||||
|
||||
// ldap config
|
||||
|
|
|
@ -78,29 +78,11 @@ class Application_Model_RabbitMq
|
|||
self::sendMessage($exchange, 'direct', true, $data);
|
||||
}
|
||||
|
||||
public static function getRmqConfigPath() {
|
||||
//Hack for Airtime Pro. The RabbitMQ settings for communicating with airtime_analyzer are global
|
||||
//and shared between all instances on Airtime Pro.
|
||||
//
|
||||
// todo: rewrite me to only use the config class and not access /etc/airtime directly
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$devEnv = "production"; //Default
|
||||
if (array_key_exists("dev_env", $CC_CONFIG)) {
|
||||
$devEnv = $CC_CONFIG["dev_env"];
|
||||
}
|
||||
$rmq_config_path = LIBRETIME_CONF_DIR . '/' . $devEnv."/rabbitmq-analyzer.ini";
|
||||
if (!file_exists($rmq_config_path)) {
|
||||
// If the dev env specific rabbitmq-analyzer.ini doesn't exist default
|
||||
// to the production rabbitmq-analyzer.ini
|
||||
$rmq_config_path = LIBRETIME_CONF_PATH . "/production/rabbitmq-analyzer.ini";
|
||||
}
|
||||
return $rmq_config_path;
|
||||
}
|
||||
|
||||
public static function SendMessageToAnalyzer($tmpFilePath, $importedStorageDirectory, $originalFilename,
|
||||
$callbackUrl, $apiKey, $storageBackend, $filePrefix)
|
||||
{
|
||||
$config = parse_ini_file(self::getRmqConfigPath(), true);
|
||||
$config = Config::getConfig();
|
||||
|
||||
$conn = new \PhpAmqpLib\Connection\AMQPConnection($config["rabbitmq"]["host"],
|
||||
$config["rabbitmq"]["port"],
|
||||
$config["rabbitmq"]["user"],
|
||||
|
|
|
@ -120,6 +120,19 @@ vhost = /airtime
|
|||
# ----------------------------------------------------------------------
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# S T O R A G E
|
||||
# ----------------------------------------------------------------------
|
||||
#
|
||||
[current_backend]
|
||||
storage_backend=file
|
||||
|
||||
[amazon_S3]
|
||||
provider=amazon_S3
|
||||
bucket=0
|
||||
api_key=0
|
||||
api_key_secret=0
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# M O N I T
|
||||
# ----------------------------------------------------------------------
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
[current_backend]
|
||||
storage_backend=file
|
||||
|
||||
[amazon_S3]
|
||||
provider=amazon_S3
|
||||
bucket=0
|
||||
api_key=0
|
||||
api_key_secret=0
|
|
@ -1,7 +0,0 @@
|
|||
[rabbitmq]
|
||||
host = 127.0.0.1
|
||||
port = 5672
|
||||
user = airtime
|
||||
password = airtime
|
||||
vhost = /airtime
|
||||
|
|
@ -26,7 +26,6 @@ class MediaSetup extends Setup {
|
|||
|
||||
const MEDIA_FOLDER = "mediaFolder";
|
||||
const LIBRETIME_CONF_FILE_NAME = "airtime.conf";
|
||||
const RMQ_INI_FILE_NAME = "rabbitmq-analyzer.ini";
|
||||
|
||||
static $path;
|
||||
static $message = null;
|
||||
|
@ -66,10 +65,6 @@ class MediaSetup extends Setup {
|
|||
self::$message = "Error moving airtime.conf or deleting /tmp/airtime.conf.temp!";
|
||||
self::$errors[] = "ERR";
|
||||
}
|
||||
if (!$this->moveRmqConfig()) {
|
||||
self::$message = "Error moving rabbitmq-analyzer.ini or deleting /tmp/rabbitmq.ini.tmp!";
|
||||
self::$errors[] = "ERR";
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're upgrading from an old Airtime instance (pre-2.5.2) we rename their old
|
||||
|
@ -102,16 +97,6 @@ class MediaSetup extends Setup {
|
|||
&& unlink(AIRTIME_CONF_TEMP_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves /tmp/airtime.conf.temp to /etc/airtime.conf and then removes it to complete setup
|
||||
* @return boolean false if either of the copy or removal operations fail
|
||||
*/
|
||||
function moveRmqConfig() {
|
||||
return copy(RMQ_INI_TEMP_PATH, LIBRETIME_CONF_DIR . '/' . self::RMQ_INI_FILE_NAME)
|
||||
&& copy(RMQ_INI_TEMP_PATH, LIBRETIME_CONF_DIR . '/production/' . self::RMQ_INI_FILE_NAME)
|
||||
&& unlink(RMQ_INI_TEMP_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given directory to cc_music_dirs
|
||||
* TODO Should we check for an existing entry in cc_music_dirs?
|
||||
|
|
|
@ -51,10 +51,6 @@ class RabbitMQSetup extends Setup {
|
|||
$this->identifyRMQConnectionError();
|
||||
}
|
||||
|
||||
if (count(self::$errors) <= 0) {
|
||||
$this->writeToTemp();
|
||||
}
|
||||
|
||||
return array(
|
||||
"message" => self::$message,
|
||||
"errors" => self::$errors
|
||||
|
@ -81,13 +77,4 @@ class RabbitMQSetup extends Setup {
|
|||
self::$errors[] = self::RMQ_PORT;
|
||||
self::$errors[] = self::RMQ_VHOST;
|
||||
}
|
||||
|
||||
protected function writeToTemp() {
|
||||
if (!file_exists(RMQ_INI_TEMP_PATH)) {
|
||||
copy(BUILD_PATH . "rabbitmq-analyzer.ini", RMQ_INI_TEMP_PATH);
|
||||
}
|
||||
$this->_write(RMQ_INI_TEMP_PATH);
|
||||
parent::writeToTemp();
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,15 @@ base_dir = /
|
|||
cache_ahead_hours = 1
|
||||
station_id = teststation
|
||||
|
||||
[current_backend]
|
||||
storage_backend=file
|
||||
|
||||
[amazon_S3]
|
||||
provider=amazon_S3
|
||||
bucket=0
|
||||
api_key=0
|
||||
api_key_secret=0
|
||||
|
||||
[monit]
|
||||
monit_user = guest
|
||||
monit_password = airtime
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[amazon_S3]
|
||||
[current_backend]
|
||||
storage_backend=file
|
4
install
4
install
|
@ -1032,10 +1032,6 @@ if [ ! -d "/etc/airtime" ]; then
|
|||
|
||||
verbose "\n * Creating /etc/airtime/ directory..."
|
||||
mkdir /etc/airtime
|
||||
# workaround for reintegrated airtime-saas dir, will get removed after we refactored config loading
|
||||
ln -s /etc/airtime/ /etc/airtime/production
|
||||
# put the default cloud_storage.conf using local file storage into directory
|
||||
cp ${AIRTIMEROOT}/airtime_mvc/build/cloud_storage.conf /etc/airtime/cloud_storage.conf
|
||||
fi
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ from boto.s3.key import Key
|
|||
# https://github.com/docker/docker-registry/issues/400
|
||||
u'fix getaddrinfo deadlock'.encode('idna')
|
||||
|
||||
CLOUD_CONFIG_PATH = os.path.join(os.getenv('LIBRETIME_CONF_DIR', '/etc/airtime'), 'cloud_storage.conf')
|
||||
CLOUD_CONFIG_PATH = os.path.join(os.getenv('LIBRETIME_CONF_DIR', '/etc/airtime'), 'airtime.conf')
|
||||
STORAGE_BACKEND_FILE = "file"
|
||||
SOCKET_TIMEOUT = 240
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from libcloud.storage.providers import get_driver
|
|||
from libcloud.storage.types import Provider, ContainerDoesNotExistError, ObjectDoesNotExistError
|
||||
|
||||
|
||||
CLOUD_CONFIG_PATH = os.path.join(os.getenv('LIBRETIME_CONF_DIR', '/etc/airtime'), 'cloud_storage.conf')
|
||||
CLOUD_CONFIG_PATH = os.path.join(os.getenv('LIBRETIME_CONF_DIR', '/etc/airtime'), 'airtime.conf')
|
||||
STORAGE_BACKEND_FILE = "file"
|
||||
|
||||
class CloudStorageUploader:
|
||||
|
|
|
@ -10,7 +10,7 @@ import airtime_analyzer.airtime_analyzer as aa
|
|||
VERSION = "1.0"
|
||||
LIBRETIME_CONF_DIR = os.getenv('LIBRETIME_CONF_DIR', '/etc/airtime')
|
||||
DEFAULT_RMQ_CONFIG_PATH = os.path.join(LIBRETIME_CONF_DIR, 'airtime.conf')
|
||||
DEFAULT_CLOUD_STORAGE_CONFIG_PATH = os.path.join(LIBRETIME_CONF_DIR, os.getenv('ENVIRONMENT', 'production'), 'airtime.conf')
|
||||
DEFAULT_CLOUD_STORAGE_CONFIG_PATH = os.path.join(LIBRETIME_CONF_DIR, 'airtime.conf')
|
||||
DEFAULT_HTTP_RETRY_PATH = '/tmp/airtime_analyzer_http_retries'
|
||||
|
||||
def run():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue