Skip to content
Snippets Groups Projects
Commit 7c12b814 authored by baldwinlouie's avatar baldwinlouie
Browse files

Issue #1911170, Issue #1911286 by baldwinlouie: Fixed data type error for...

Issue #1911170, Issue #1911286 by baldwinlouie: Fixed data type error for created/updated database column in cloud_metering_queue, and fixed serialization error when a snapshot id is returned from the API
parent 18467c09
No related branches found
No related tags found
No related merge requests found
...@@ -11,23 +11,9 @@ ...@@ -11,23 +11,9 @@
module_load_include('inc', 'cloud_metering', 'cloud_metering_constants'); module_load_include('inc', 'cloud_metering', 'cloud_metering_constants');
/**
* Implementation of hook_install().
*/
function cloud_metering_install() {
// Create tables.
}
/**
* Implementation of hook_uninstall().
*/
function cloud_metering_uninstall() {
// Remove tables.
}
/** /**
* Implementation of hook_schema(). * Implementation of hook_schema().
*/ */
function cloud_metering_schema() { function cloud_metering_schema() {
$schema = array(); $schema = array();
...@@ -208,11 +194,13 @@ function cloud_metering_schema() { ...@@ -208,11 +194,13 @@ function cloud_metering_schema() {
'not null' => TRUE, 'not null' => TRUE,
), ),
'created' => array( 'created' => array(
'type' => 'text', 'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE, 'not null' => TRUE,
), ),
'updated' => array( 'updated' => array(
'type' => 'text', 'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE, 'not null' => TRUE,
), ),
'status' => array( 'status' => array(
...@@ -239,3 +227,10 @@ function cloud_metering_update_7100() { ...@@ -239,3 +227,10 @@ function cloud_metering_update_7100() {
db_change_field(CLOUD_METERING_MAILS_TABLE, 'token', 'token', array('type' => 'varchar', 'not null' => TRUE, 'length' => 64)); db_change_field(CLOUD_METERING_MAILS_TABLE, 'token', 'token', array('type' => 'varchar', 'not null' => TRUE, 'length' => 64));
} }
/**
* Update created and updated columns in cloud_metering_queue_table. Change from text to int.
*/
function cloud_metering_update_7101() {
db_change_field(CLOUD_METERING_QUEUE_TABLE, 'created', 'created', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
db_change_field(CLOUD_METERING_QUEUE_TABLE, 'updated', 'updated', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
}
...@@ -142,8 +142,6 @@ function cloud_metering_form_aws_cloud_server_templates_new_alter(&$form, &$form ...@@ -142,8 +142,6 @@ function cloud_metering_form_aws_cloud_server_templates_new_alter(&$form, &$form
'#validate' => array('_cloud_metering_validate_template_budget'), '#validate' => array('_cloud_metering_validate_template_budget'),
); );
} }
} }
/** /**
......
...@@ -25,77 +25,42 @@ function cloud_metering_cron_queue_info() { ...@@ -25,77 +25,42 @@ function cloud_metering_cron_queue_info() {
* Queue worker callback * Queue worker callback
*/ */
function _cloud_metering_process_queue() { function _cloud_metering_process_queue() {
$next_task = _cloud_metering_next_task_to_execute();
while ( TRUE ) { if (count($next_task)) {
if ($next_task['task'] == CLOUD_METERING_BACKUP) {
$next_task = _cloud_metering_next_task_to_execute(); _cloud_metering_backup($next_task);
if (is_array($next_task) && sizeof($next_task) > 0) {
if ($next_task['task'] == CLOUD_METERING_BACKUP) {
_cloud_metering_backup($next_task);
continue;
}
elseif ($next_task['task'] == CLOUD_METERING_DETACH) {
_cloud_metering_detach_volumes($next_task);
continue;
}
elseif ($next_task['task'] == CLOUD_METERING_TERMINATE) {
_cloud_metering_terminate($next_task);
continue;
}
elseif ($next_task['task'] == CLOUD_METERING_BACKUP_CHECK) {
_cloud_metering_check_backup($next_task);
continue;
}
elseif ($next_task['task'] == CLOUD_METERING_DETACH_CHECK) {
_cloud_metering_check_detach($next_task);
continue;
}
elseif ($next_task['task'] == CLOUD_METERING_TERMINATE_CHECK) {
_cloud_metering_check_terminate($next_task);
continue;
}
} }
else { elseif ($next_task['task'] == CLOUD_METERING_DETACH) {
_cloud_metering_detach_volumes($next_task);
return; }
elseif ($next_task['task'] == CLOUD_METERING_TERMINATE) {
_cloud_metering_terminate($next_task);
}
elseif ($next_task['task'] == CLOUD_METERING_BACKUP_CHECK) {
_cloud_metering_check_backup($next_task);
}
elseif ($next_task['task'] == CLOUD_METERING_DETACH_CHECK) {
_cloud_metering_check_detach($next_task);
}
elseif ($next_task['task'] == CLOUD_METERING_TERMINATE_CHECK) {
_cloud_metering_check_terminate($next_task);
} }
} }
} }
/** /**
* Add item to Drupal queue * Add item to Drupal queue
*/ */
function _cloud_metering_add_queue_item($item) { function _cloud_metering_add_queue_item($item) {
$queue = DrupalQueue::get(CLOUD_METERING_QUEUE); $queue = DrupalQueue::get(CLOUD_METERING_QUEUE);
$queue->createItem($item); $queue->createItem($item);
} }
/** /**
* Get the uuid * Get the uuid
*/ */
function _cloud_metering_get_uuid($cloud_context, $instance_id) { function _cloud_metering_get_uuid($cloud_context, $instance_id) {
return $cloud_context . '-' . $instance_id; return $cloud_context . '-' . $instance_id;
} }
/** /**
...@@ -227,7 +192,7 @@ function _cloud_metering_backup($task) { ...@@ -227,7 +192,7 @@ function _cloud_metering_backup($task) {
$snapshot_id = cloud_perform_action('', 'backup', $cloud_context, $params); $snapshot_id = cloud_perform_action('', 'backup', $cloud_context, $params);
if ($snapshot_id) { if ($snapshot_id) {
$volumes[$volume_id]['snapshot_id'] = $snapshot_id; $volumes[$volume_id]['snapshot_id'] = (string)$snapshot_id;
} }
else { else {
// TODO -- Decide on steps to be taken in case snapshot creation fails // TODO -- Decide on steps to be taken in case snapshot creation fails
......
...@@ -26,8 +26,8 @@ function _cloud_metering_add_task($cloud_context, $instance_id, $task, $data = a ...@@ -26,8 +26,8 @@ function _cloud_metering_add_task($cloud_context, $instance_id, $task, $data = a
->fields(array( ->fields(array(
'task' => $task, 'task' => $task,
'uuid' => $uuid, 'uuid' => $uuid,
'created' => 'now', 'created' => time(),
'updated' => 'now', 'updated' => time(),
'status' => CLOUD_METERING_QUEUE_STATUS_INITIATED, 'status' => CLOUD_METERING_QUEUE_STATUS_INITIATED,
'uid' => 1, 'uid' => 1,
'data' => serialize($data), 'data' => serialize($data),
...@@ -103,16 +103,13 @@ function _cloud_metering_update_task_status($qid, $status, $data = NULL) { ...@@ -103,16 +103,13 @@ function _cloud_metering_update_task_status($qid, $status, $data = NULL) {
$query_update = db_update(CLOUD_METERING_QUEUE_TABLE); $query_update = db_update(CLOUD_METERING_QUEUE_TABLE);
$fields = array(); $fields = array();
if ( is_array($data) ) { $fields['status'] = $status;
$fields['updated'] = time();
if (is_array($data)) {
$data = (sizeof($data) > 0) ? serialize($data) : ''; $data = (sizeof($data) > 0) ? serialize($data) : '';
$fields['status'] = $status; $fields['data'] = $data;
$fields['updated'] = 'now';
$fields['data'] = $data;
}
else {
$fields['status'] = $status;
$fields['updated'] = 'now';
} }
$query_update->fields($fields); $query_update->fields($fields);
...@@ -128,7 +125,7 @@ function _cloud_metering_update_task_status($qid, $status, $data = NULL) { ...@@ -128,7 +125,7 @@ function _cloud_metering_update_task_status($qid, $status, $data = NULL) {
*/ */
function _cloud_metering_next_task_in_progress() { function _cloud_metering_next_task_in_progress() {
$query = 'SELECT * , TIMESTAMPDIFF(MINUTE, updated, CURRENT_TIMESTAMP) time_running FROM {' . CLOUD_METERING_QUEUE_TABLE . "} WHERE status = :status ORDER BY created ASC LIMIT 0, 1"; $query = 'SELECT * , TIMESTAMPDIFF(MINUTE, FROM_UNIXTIME(updated), CURRENT_TIMESTAMP) time_running FROM {' . CLOUD_METERING_QUEUE_TABLE . "} WHERE status = :status ORDER BY created ASC LIMIT 0, 1";
$db_result = db_query($query, array(':status' => CLOUD_METERING_QUEUE_STATUS_IN_PROGRESS) ); $db_result = db_query($query, array(':status' => CLOUD_METERING_QUEUE_STATUS_IN_PROGRESS) );
$task = array(); $task = array();
...@@ -205,15 +202,12 @@ function _cloud_metering_next_task_to_execute() { ...@@ -205,15 +202,12 @@ function _cloud_metering_next_task_to_execute() {
* Get a task from queue database table * Get a task from queue database table
*/ */
function _cloud_metering_get_task($qid) { function _cloud_metering_get_task($qid) {
$query = 'SELECT *, TIMESTAMPDIFF(MINUTE, FROM_UNIXTIME(updated), CURRENT_TIMESTAMP) time_running FROM {' . CLOUD_METERING_QUEUE_TABLE . '} WHERE qid = :qid ';
$query = 'SELECT *, TIMESTAMPDIFF(MINUTE, updated, CURRENT_TIMESTAMP) time_running FROM {' . CLOUD_METERING_QUEUE_TABLE . '} WHERE qid = :qid ';
$db_result = db_query($query, array(':qid' => $qid) ); $db_result = db_query($query, array(':qid' => $qid) );
$task = array(); $task = array();
foreach ($db_result as $o) { foreach ($db_result as $o) {
$task['qid'] = $o->qid; $task['qid'] = $o->qid;
$task['task'] = $o->task; $task['task'] = $o->task;
$task['uuid'] = $o->uuid; $task['uuid'] = $o->uuid;
...@@ -224,9 +218,7 @@ function _cloud_metering_get_task($qid) { ...@@ -224,9 +218,7 @@ function _cloud_metering_get_task($qid) {
$task['data'] = unserialize($o->data); $task['data'] = unserialize($o->data);
$task['time_running'] = $o->time_running; $task['time_running'] = $o->time_running;
} }
return $task; return $task;
} }
/** /**
...@@ -240,16 +232,11 @@ function _cloud_metering_get_in_progress_tasks($type = 'base') { ...@@ -240,16 +232,11 @@ function _cloud_metering_get_in_progress_tasks($type = 'base') {
->fields('c') ->fields('c')
->condition('c.status', CLOUD_METERING_QUEUE_STATUS_IN_PROGRESS) ->condition('c.status', CLOUD_METERING_QUEUE_STATUS_IN_PROGRESS)
->condition('c.task', $task_types, 'IN') ->condition('c.task', $task_types, 'IN')
->where('TIMESTAMPDIFF(MINUTE, c.updated, CURRENT_TIMESTAMP) >= 1') ->where('TIMESTAMPDIFF(MINUTE, FROM_UNIXTIME(c.updated), CURRENT_TIMESTAMP) >= 1')
->orderBy('c.created', 'ASC'); ->orderBy('c.created', 'ASC');
$result = $query->execute(); $result = $query->execute();
foreach ($result as $row) {
$tasks[] = $row;
}
return $tasks;
return $result->fetchAllAssoc('qid', PDO::FETCH_ASSOC);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment