computing.install in Drupal Computing 7
Same filename and directory in other branches
Drupal Computing installation file.
File
computing.installView source
<?php
/**
* @file
* Drupal Computing installation file.
*/
/**
* Implements hook_schema().
* @see [#1744340] for information about large input/output causes PHP out of memory.
*/
function computing_schema() {
$schema = array();
$schema['computing_record'] = array(
'description' => 'Stores computing command record.',
'fields' => array(
// core fields
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Unique auto increment computing record id',
),
'app' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 50,
'description' => 'Application that generates/executes a set of commands',
),
'command' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 50,
'description' => 'Command to be executed, no parameters',
),
'description' => array(
'type' => 'varchar',
'not null' => FALSE,
'length' => 200,
'description' => 'Human readable text to explain the command to users',
),
'uid' => array(
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
'description' => "FK User's {users}.uid, if any. If no uid, set to null",
),
'nid' => array(
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
'description' => "Related node if for this command, if any. If no nid, set it to null",
),
'created' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Unix timestamp this command is created',
),
// parameters and results
'input' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Input parameters for this command. Serialized PHP object.',
),
'output' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Return results for this command. Serialized PHP object.',
),
// the json input/output is useful because then we know it's json and can display them in readable format.
// use the name inputjson rather than input_json in order to facilitate Gson in Java.
// attention: both inputjson/outputjson could be too big to handle in PHP due to PHP memory_limit.
// if that happens, you should save extra data to your own db tables, rather than dump them into input/output json.
'inputjson' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'description' => 'JSON input parameters for this command.',
),
'outputjson' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'description' => 'JSON output parameters for this command.',
),
'id1' => array(
'type' => 'int',
'not null' => FALSE,
'description' => "Optional ID, suggested for input",
),
'id2' => array(
'type' => 'int',
'not null' => FALSE,
'description' => "Optional ID, suggested for output",
),
'id3' => array(
'type' => 'int',
'not null' => FALSE,
'description' => "Optional ID, suggested for input",
),
'id4' => array(
'type' => 'int',
'not null' => FALSE,
'description' => "Optional ID, suggested for output",
),
'ids1' => array(
'type' => 'varchar',
'length' => 20,
'not null' => FALSE,
'description' => "Optional string ID, suggested for input",
),
'ids2' => array(
'type' => 'varchar',
'length' => 20,
'not null' => FALSE,
'description' => "Optional string ID, suggested for output",
),
'ids3' => array(
'type' => 'varchar',
'length' => 20,
'not null' => FALSE,
'description' => "Optional string ID, suggested for input",
),
'ids4' => array(
'type' => 'varchar',
'length' => 20,
'not null' => FALSE,
'description' => "Optional string ID, suggested for output",
),
'number1' => array(
'type' => 'float',
'not null' => FALSE,
'description' => "Optional number, suggested for input",
),
'number2' => array(
'type' => 'float',
'not null' => FALSE,
'description' => "Optional number, suggested for output",
),
'number3' => array(
'type' => 'float',
'not null' => FALSE,
'description' => "Optional number, suggested for input",
),
'number4' => array(
'type' => 'float',
'not null' => FALSE,
'description' => "Optional number, suggested for output",
),
'string1' => array(
'type' => 'varchar',
'length' => 2000,
'not null' => FALSE,
'description' => "Optional string, suggested for input",
),
'string2' => array(
'type' => 'varchar',
'length' => 2000,
'not null' => FALSE,
'description' => "Optional string, suggested for output",
),
'string3' => array(
'type' => 'varchar',
'length' => 2000,
'not null' => FALSE,
'description' => "Optional string, suggested for input",
),
'string4' => array(
'type' => 'varchar',
'length' => 2000,
'not null' => FALSE,
'description' => "Optional string, suggested for output",
),
// currently not used.
// 'dependency' => array('type' => 'int', 'not null' => FALSE, 'unsigned' => TRUE, 'description' => 'For serialized execution sequence, this links to the id of dependent command',),
// 'session' => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE, 'description' => "Optional session id to identify the session of a command",), // session id, not implemented yet.
// running status, message, control, misc
'status' => array(
'type' => 'char',
'length' => 4,
'not null' => FALSE,
'description' => 'Status code of the command, see code in Java',
),
'control' => array(
'type' => 'char',
'length' => 4,
'not null' => FALSE,
'description' => 'Control signal to send to the running command, see code in Java',
),
'message' => array(
'type' => 'text',
'not null' => FALSE,
'description' => 'Human readable message for users about the execution results',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => FALSE,
'description' => 'Similar to the module weight, 0 is normal, small number has higher priority',
),
'agent' => array(
'type' => 'varchar',
'length' => 20,
'not null' => FALSE,
'description' => "The agent that execute the command, usually is the machine id",
),
'start' => array(
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
'description' => 'Timestamp when the command is executed, perhaps has timezone difference from created',
),
'end' => array(
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
'description' => 'Timestamp when the command is done',
),
'updated' => array(
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
'description' => 'Signal timestamp, used to show how much time is spent running up to the checkpoint',
),
'progress' => array(
'type' => 'float',
'not null' => FALSE,
'unsigned' => TRUE,
'description' => '(0,1) float number to show the progress of the command',
),
),
'primary key' => array(
'id',
),
'indexes' => array(
'app_index' => array(
'app',
),
'priority_index' => array(
'weight',
'created',
),
),
'foreign keys' => array(
'user_uid' => array(
'table' => 'users',
'columns' => array(
'uid' => 'uid',
),
),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function computing_install() {
variable_set('computing_drupal_version', VERSION);
}
/**
* Implements hook_uninstall().
*/
function computing_uninstall() {
variable_del('computing_drupal_version');
}
function computing_update_7004() {
$schema = computing_schema();
$fields = $schema['computing_record']['fields'];
db_drop_field('computing_record', 'input_json');
db_drop_field('computing_record', 'output_json');
db_add_field('computing_record', 'inputjson', $fields['inputjson']);
db_add_field('computing_record', 'outputjson', $fields['outputjson']);
}
function computing_update_7005() {
$schema = computing_schema();
$fields = $schema['computing_record']['fields'];
db_drop_field('computing_record', 'eid');
db_add_field('computing_record', 'nid', $fields['nid']);
}
function computing_update_7006() {
$schema = drupal_get_schema_unprocessed('computing', 'computing_record');
db_change_field('computing_record', 'inputjson', 'inputjson', $schema['fields']['inputjson']);
db_change_field('computing_record', 'outputjson', 'outputjson', $schema['fields']['outputjson']);
}
/**
* increase string1-4 to length=2000 (originally was 1000).
*/
function computing_update_7008() {
$schema = drupal_get_schema_unprocessed('computing', 'computing_record');
db_change_field('computing_record', 'string1', 'string1', $schema['fields']['string1']);
db_change_field('computing_record', 'string2', 'string2', $schema['fields']['string2']);
db_change_field('computing_record', 'string3', 'string3', $schema['fields']['string3']);
db_change_field('computing_record', 'string4', 'string4', $schema['fields']['string4']);
}
/**
* Create 'computing_drupal_version' variable in order to query Drupal version.
*/
function computing_update_7009() {
variable_set('computing_drupal_version', VERSION);
}
/**
* Add the 'agent' field.
*/
function computing_update_7010() {
$schema = drupal_get_schema_unprocessed('computing', 'computing_record');
db_add_field('computing_record', 'agent', $schema['fields']['agent']);
}
/**
* Add ids1-4.
*/
function computing_update_7011() {
$schema = drupal_get_schema_unprocessed('computing', 'computing_record');
db_add_field('computing_record', 'ids1', $schema['fields']['ids1']);
db_add_field('computing_record', 'ids2', $schema['fields']['ids2']);
db_add_field('computing_record', 'ids3', $schema['fields']['ids3']);
db_add_field('computing_record', 'ids4', $schema['fields']['ids4']);
}
Functions
Name | Description |
---|---|
computing_install | Implements hook_install(). |
computing_schema | Implements hook_schema(). |
computing_uninstall | Implements hook_uninstall(). |
computing_update_7004 | |
computing_update_7005 | |
computing_update_7006 | |
computing_update_7008 | increase string1-4 to length=2000 (originally was 1000). |
computing_update_7009 | Create 'computing_drupal_version' variable in order to query Drupal version. |
computing_update_7010 | Add the 'agent' field. |
computing_update_7011 | Add ids1-4. |