Merge branch 'cc-5709-airtime-analyzer' into cc-5709-airtime-analyzer-saas
This commit is contained in:
commit
a6e80e2789
|
@ -44,7 +44,7 @@ class CcFilesTableMap extends TableMap {
|
||||||
$this->addColumn('FTYPE', 'DbFtype', 'VARCHAR', true, 128, '');
|
$this->addColumn('FTYPE', 'DbFtype', 'VARCHAR', true, 128, '');
|
||||||
$this->addForeignKey('DIRECTORY', 'DbDirectory', 'INTEGER', 'cc_music_dirs', 'ID', false, null, null);
|
$this->addForeignKey('DIRECTORY', 'DbDirectory', 'INTEGER', 'cc_music_dirs', 'ID', false, null, null);
|
||||||
$this->addColumn('FILEPATH', 'DbFilepath', 'LONGVARCHAR', false, null, '');
|
$this->addColumn('FILEPATH', 'DbFilepath', 'LONGVARCHAR', false, null, '');
|
||||||
$this->addColumn('IMPORT_STATUS', 'DbImportStatus', 'INTEGER', true, null, 0);
|
$this->addColumn('IMPORT_STATUS', 'DbImportStatus', 'INTEGER', true, null, 1);
|
||||||
$this->addColumn('CURRENTLYACCESSING', 'DbCurrentlyaccessing', 'INTEGER', true, null, 0);
|
$this->addColumn('CURRENTLYACCESSING', 'DbCurrentlyaccessing', 'INTEGER', true, null, 0);
|
||||||
$this->addForeignKey('EDITEDBY', 'DbEditedby', 'INTEGER', 'cc_subjs', 'ID', false, null, null);
|
$this->addForeignKey('EDITEDBY', 'DbEditedby', 'INTEGER', 'cc_subjs', 'ID', false, null, null);
|
||||||
$this->addColumn('MTIME', 'DbMtime', 'TIMESTAMP', false, 6, null);
|
$this->addColumn('MTIME', 'DbMtime', 'TIMESTAMP', false, 6, null);
|
||||||
|
|
|
@ -66,7 +66,7 @@ abstract class BaseCcFiles extends BaseObject implements Persistent
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value for the import_status field.
|
* The value for the import_status field.
|
||||||
* Note: this column has a database default value of: 0
|
* Note: this column has a database default value of: 1
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $import_status;
|
protected $import_status;
|
||||||
|
@ -524,7 +524,7 @@ abstract class BaseCcFiles extends BaseObject implements Persistent
|
||||||
$this->mime = '';
|
$this->mime = '';
|
||||||
$this->ftype = '';
|
$this->ftype = '';
|
||||||
$this->filepath = '';
|
$this->filepath = '';
|
||||||
$this->import_status = 0;
|
$this->import_status = 1;
|
||||||
$this->currentlyaccessing = 0;
|
$this->currentlyaccessing = 0;
|
||||||
$this->length = '00:00:00';
|
$this->length = '00:00:00';
|
||||||
$this->file_exists = true;
|
$this->file_exists = true;
|
||||||
|
@ -2892,7 +2892,7 @@ abstract class BaseCcFiles extends BaseObject implements Persistent
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->import_status !== 0) {
|
if ($this->import_status !== 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,13 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
//fields that are not modifiable via our RESTful API
|
//fields that are not modifiable via our RESTful API
|
||||||
private $blackList = array(
|
private $blackList = array(
|
||||||
'id',
|
'id',
|
||||||
|
'directory',
|
||||||
|
'filepath',
|
||||||
'file_exists',
|
'file_exists',
|
||||||
|
'hidden',
|
||||||
|
'mtime',
|
||||||
|
'utime',
|
||||||
|
'lptime',
|
||||||
'silan_check',
|
'silan_check',
|
||||||
'soundcloud_id',
|
'soundcloud_id',
|
||||||
'is_scheduled',
|
'is_scheduled',
|
||||||
|
@ -147,9 +153,18 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = CcFilesQuery::create()->findPk($id);
|
$file = CcFilesQuery::create()->findPk($id);
|
||||||
if ($file)
|
//validate fields
|
||||||
|
$requestData = json_decode($this->getRequest()->getRawBody(), true);
|
||||||
|
//TODO: rename EditAudioMD form?
|
||||||
|
$fileForm = new Application_Form_EditAudioMD();
|
||||||
|
$fileForm->startForm($file->getDbId());
|
||||||
|
$fileForm->populate($requestData);
|
||||||
|
|
||||||
|
if (!$fileForm->isValidPartial($requestData)) {
|
||||||
|
$file->setDbImportStatus(2)->save();
|
||||||
|
$this->invalidDataResponse();
|
||||||
|
} else if ($file)
|
||||||
{
|
{
|
||||||
$requestData = json_decode($this->getRequest()->getRawBody(), true);
|
|
||||||
$file->fromArray($this->validateRequestData($requestData), BasePeer::TYPE_FIELDNAME);
|
$file->fromArray($this->validateRequestData($requestData), BasePeer::TYPE_FIELDNAME);
|
||||||
|
|
||||||
//Our RESTful API takes "full_path" as a field, which we then split and translate to match
|
//Our RESTful API takes "full_path" as a field, which we then split and translate to match
|
||||||
|
@ -179,6 +194,7 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
->setHttpResponseCode(200)
|
->setHttpResponseCode(200)
|
||||||
->appendBody(json_encode($this->sanitizeResponse($file)));
|
->appendBody(json_encode($this->sanitizeResponse($file)));
|
||||||
} else {
|
} else {
|
||||||
|
$file->setDbImportStatus(2)->save();
|
||||||
$this->fileNotFoundResponse();
|
$this->fileNotFoundResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -284,6 +300,13 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
$resp->setHttpResponseCode(404);
|
$resp->setHttpResponseCode(404);
|
||||||
$resp->appendBody("ERROR: Media not found.");
|
$resp->appendBody("ERROR: Media not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function invalidDataResponse()
|
||||||
|
{
|
||||||
|
$resp = $this->getResponse();
|
||||||
|
$resp->setHttpResponseCode(400);
|
||||||
|
$resp->appendBody("ERROR: Invalid data");
|
||||||
|
}
|
||||||
|
|
||||||
private function processUploadedFile($callbackUrl, $originalFilename, $ownerId)
|
private function processUploadedFile($callbackUrl, $originalFilename, $ownerId)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<column name="ftype" phpName="DbFtype" type="VARCHAR" size="128" required="true" defaultValue=""/>
|
<column name="ftype" phpName="DbFtype" type="VARCHAR" size="128" required="true" defaultValue=""/>
|
||||||
<column name="directory" phpName="DbDirectory" type="INTEGER" required="false"/>
|
<column name="directory" phpName="DbDirectory" type="INTEGER" required="false"/>
|
||||||
<column name="filepath" phpName="DbFilepath" type="LONGVARCHAR" required="false" defaultValue=""/>
|
<column name="filepath" phpName="DbFilepath" type="LONGVARCHAR" required="false" defaultValue=""/>
|
||||||
<column name="import_status" phpName="DbImportStatus" type="INTEGER" required="true" defaultValue="0"/>
|
<column name="import_status" phpName="DbImportStatus" type="INTEGER" required="true" defaultValue="1"/>
|
||||||
<column name="currentlyaccessing" phpName="DbCurrentlyaccessing" type="INTEGER" required="true" defaultValue="0"/>
|
<column name="currentlyaccessing" phpName="DbCurrentlyaccessing" type="INTEGER" required="true" defaultValue="0"/>
|
||||||
<column name="editedby" phpName="DbEditedby" type="INTEGER" required="false"/>
|
<column name="editedby" phpName="DbEditedby" type="INTEGER" required="false"/>
|
||||||
<column name="mtime" phpName="DbMtime" type="TIMESTAMP" size="6" required="false"/>
|
<column name="mtime" phpName="DbMtime" type="TIMESTAMP" size="6" required="false"/>
|
||||||
|
|
|
@ -36,7 +36,7 @@ CREATE TABLE "cc_files"
|
||||||
"ftype" VARCHAR(128) default '' NOT NULL,
|
"ftype" VARCHAR(128) default '' NOT NULL,
|
||||||
"directory" INTEGER,
|
"directory" INTEGER,
|
||||||
"filepath" TEXT default '',
|
"filepath" TEXT default '',
|
||||||
"import_status" INTEGER default 0 NOT NULL,
|
"import_status" INTEGER default 1 NOT NULL,
|
||||||
"currentlyaccessing" INTEGER default 0 NOT NULL,
|
"currentlyaccessing" INTEGER default 0 NOT NULL,
|
||||||
"editedby" INTEGER,
|
"editedby" INTEGER,
|
||||||
"mtime" TIMESTAMP(6),
|
"mtime" TIMESTAMP(6),
|
||||||
|
|
|
@ -10,19 +10,18 @@ from message_listener import MessageListener
|
||||||
class AirtimeAnalyzerServer:
|
class AirtimeAnalyzerServer:
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
_CONFIG_PATH = '/etc/airtime/airtime.conf'
|
|
||||||
_LOG_PATH = "/var/log/airtime/airtime_analyzer.log"
|
_LOG_PATH = "/var/log/airtime/airtime_analyzer.log"
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
_log_level = logging.INFO
|
_log_level = logging.INFO
|
||||||
|
|
||||||
def __init__(self, debug=False):
|
def __init__(self, config_path, debug=False):
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
self.setup_logging(debug)
|
self.setup_logging(debug)
|
||||||
|
|
||||||
# Read our config file
|
# Read our config file
|
||||||
rabbitmq_config = self.read_config_file()
|
rabbitmq_config = self.read_config_file(config_path)
|
||||||
|
|
||||||
# Start listening for RabbitMQ messages telling us about newly
|
# Start listening for RabbitMQ messages telling us about newly
|
||||||
# uploaded files.
|
# uploaded files.
|
||||||
|
@ -55,9 +54,8 @@ class AirtimeAnalyzerServer:
|
||||||
rootLogger.addHandler(consoleHandler)
|
rootLogger.addHandler(consoleHandler)
|
||||||
|
|
||||||
|
|
||||||
def read_config_file(self):
|
def read_config_file(self, config_path):
|
||||||
config = ConfigParser.SafeConfigParser()
|
config = ConfigParser.SafeConfigParser()
|
||||||
config_path = AirtimeAnalyzerServer._CONFIG_PATH
|
|
||||||
try:
|
try:
|
||||||
config.readfp(open(config_path))
|
config.readfp(open(config_path))
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
|
|
|
@ -6,12 +6,14 @@ import os
|
||||||
import airtime_analyzer.airtime_analyzer as aa
|
import airtime_analyzer.airtime_analyzer as aa
|
||||||
|
|
||||||
VERSION = "1.0"
|
VERSION = "1.0"
|
||||||
|
DEFAULT_CONFIG_PATH = '/etc/airtime/airtime.conf'
|
||||||
|
|
||||||
print "Airtime Analyzer " + VERSION
|
print "Airtime Analyzer " + VERSION
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-d", "--daemon", help="run as a daemon", action="store_true")
|
parser.add_argument("-d", "--daemon", help="run as a daemon", action="store_true")
|
||||||
parser.add_argument("--debug", help="log full debugging output", action="store_true")
|
parser.add_argument("--debug", help="log full debugging output", action="store_true")
|
||||||
|
parser.add_argument("--rmq-config-file", help="specify a configuration file with RabbitMQ settings (default is /etc/airtime/airtime.conf)")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
'''Ensure media_monitor isn't running before we start, because it'll move newly uploaded
|
'''Ensure media_monitor isn't running before we start, because it'll move newly uploaded
|
||||||
|
@ -33,10 +35,15 @@ def check_if_media_monitor_is_running():
|
||||||
|
|
||||||
check_if_media_monitor_is_running()
|
check_if_media_monitor_is_running()
|
||||||
|
|
||||||
|
#Default config file path
|
||||||
|
config_path = DEFAULT_CONFIG_PATH
|
||||||
|
if args.rmq_config_file:
|
||||||
|
config_path = args.rmq_config_file
|
||||||
|
|
||||||
if args.daemon:
|
if args.daemon:
|
||||||
with daemon.DaemonContext():
|
with daemon.DaemonContext():
|
||||||
analyzer = aa.AirtimeAnalyzerServer(debug=args.debug)
|
analyzer = aa.AirtimeAnalyzerServer(config_path=config_path, debug=args.debug)
|
||||||
else:
|
else:
|
||||||
# Run without daemonizing
|
# Run without daemonizing
|
||||||
analyzer = aa.AirtimeAnalyzerServer(debug=args.debug)
|
analyzer = aa.AirtimeAnalyzerServer(config_path=config_path, debug=args.debug)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,41 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
path=$1
|
post_file() {
|
||||||
filename="${path##*/}"
|
#kill process after 30 minutes (360*5=30 minutes)
|
||||||
curl http://localhost/rest/media -u 3188BDIMPJROQP89Z0OX: -X POST -F "file=@$path" -F "name=$filename"
|
max_retry=360
|
||||||
|
retry_count=0
|
||||||
|
|
||||||
|
file_path=${1}
|
||||||
|
filename="${file_path##*/}"
|
||||||
|
|
||||||
|
#base_instance_path and airtime_conf_path are common to all saas instances
|
||||||
|
base_instance_path=/mnt/airtimepro/instances/
|
||||||
|
airtime_conf_path=/etc/airtime/airtime.conf
|
||||||
|
|
||||||
|
#maps the instance_path to the url
|
||||||
|
vhost_file=/mnt/airtimepro/system/vhost.map
|
||||||
|
|
||||||
|
#instance_path will look like 1/1384, for example
|
||||||
|
instance_path=$(echo ${file_path} | grep -Po "(?<=($base_instance_path)).*?(?=/srv)")
|
||||||
|
|
||||||
|
#post request url - http://bananas.airtime.pro/rest/media, for example
|
||||||
|
url=http://
|
||||||
|
url+=$(grep -E $instance_path $vhost_file | awk '{print $1;}')
|
||||||
|
url+=/rest/media
|
||||||
|
|
||||||
|
#path to specific instance's airtime.conf
|
||||||
|
instance_conf_path=$base_instance_path$instance_path$airtime_conf_path
|
||||||
|
|
||||||
|
api_key=$(sudo awk -F "=" '/api_key/ {print $2}' $instance_conf_path)
|
||||||
|
|
||||||
|
until curl --max-time 30 $url -u $api_key":" -X POST -F "file=@${file_path}" -F "name=${filename}"
|
||||||
|
do
|
||||||
|
retry_count=$[$retry_count+1]
|
||||||
|
if [ $retry_count -ge $max_retry ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
post_file "${1}" &
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
post_file() {
|
||||||
|
file_path=${1}
|
||||||
|
filename="${file_path##*/}"
|
||||||
|
|
||||||
|
#kill process after 30 minutes (360*5=30 minutes)
|
||||||
|
max_retry=10
|
||||||
|
retry_count=0
|
||||||
|
|
||||||
|
until curl --max-time 30 http://localhost/rest/media -u 3188BDIMPJROQP89Z0OX: -X POST -F "file=@${file_path}" -F "name=${filename}"
|
||||||
|
do
|
||||||
|
retry_count=$[$retry_count+1]
|
||||||
|
if [ $retry_count -ge $max_retry ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
post_file "${1}" &
|
Loading…
Reference in New Issue