diff --git a/modules/cloud_alert/README.txt b/modules/cloud_alert/README.txt deleted file mode 100644 index 0eb1d22..0000000 --- a/modules/cloud_alert/README.txt +++ /dev/null @@ -1,54 +0,0 @@ -BASIC INFO -========== -- THIS MODULES DOES NOT DO ANYTHING AT THIS TIME. -- Provides a set of trigger and action for cloud management -- Works with Cloud. Failover and auto-scaling module. - -* This module will do nothing; not implemented for sending e-mail, etc. -* This module should be implemented as based on trigger/action on Drupal. - -HOW TO USE -========== - -1) Enable Alert module -2) Go to the menu: Design | Alerts | New Alert Button -3) Create a server template -4) Select alert(s) in a server template - - -TODO -==== - -- This module started with D5, so it needs to match D6's trigger and action APIs. - - -DIRECTORY STRUCTURE -=================== - -cloud - +-modules (depends on Cloud module) (Cloud is a core module for Cloud package) - +-cloud_activity_audit - o-cloud_alert - x-cloud_auto_scaling - x-cloud_billing - x-cloud_cluster - x-cloud_dashboard - x-cloud_failover - +-cloud_inputs - x-cloud_metering - +-cloud_pricing - x-cloud_resource_allocator - x-cloud_scaling_manager - +-cloud_script - +-cloud_server_templates - - - x... Not released yet. - - -CHANGE HISTORY -============== -2011/12/21 7.x-1.x-dev released - - -End of README.txt \ No newline at end of file diff --git a/modules/cloud_alert/cloud_alert.constants.inc b/modules/cloud_alert/cloud_alert.constants.inc deleted file mode 100644 index 2bb7712..0000000 --- a/modules/cloud_alert/cloud_alert.constants.inc +++ /dev/null @@ -1,13 +0,0 @@ -fields('a'); - - return $query; -} - - -function _cloud_alert_get_count_db() { - - $alerts_count = 0; - $query = db_select(CLOUD_ALERTS_TABLE, 'a'); - $query->addExpression('COUNT(*)', 'alerts_count'); - - $result = $query->execute(); - foreach ($result as $alerts) { - $alerts_count = $alerts->alerts_count; - } - - return $alerts_count; -} - - -function _cloud_alert_delete($id) { - - //// add watchdog log - $query = _cloud_alert_get(); - $query - ->condition('alert_id', $id); - $result = $query->execute(); - - - $count = 0; - $alert_obj = $result->fetchObject(); - - - $query = db_delete( CLOUD_ALERTS_TABLE ) - ->condition('alert_id', $id) - ->execute(); - - // User Activity Log - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => t('Alert has been deleted: @alert_name', array('@alert_name' => $alert_obj->name)), - 'link' => '', - ) - ); - - $alert_deleted = db_delete( CLOUD_ALERTS_TABLE ) - ->condition('alert_id', $id) - ->execute(); - - - $alert_deleted = db_delete(CLOUD_SERVER_TEMPLATES_ALERTS_TABLE) - ->condition('alert_id', $id) - ->execute(); - - //// - return; -} - -/** - * Insert a alert in database - * This function insert entry in database and audit logs as well. - * - * @param $form_values - * This is the form-values submitted by new alert form - * @return return a last inserted alert-id - */ -function _cloud_alert_insert($form_values) { - - $insert_query = db_insert( CLOUD_ALERTS_TABLE ) - ->fields(array( - 'name' => $form_values['name_text' ], - 'description' => $form_values['description_text' ], - 'metric' => $form_values['metric_select' ], - 'variable' => $form_values['variable_select' ], - '`condition`' => $form_values['condition_select' ], - 'threshold' => $form_values['threshold_text' ], - 'duration_in_minutes' => $form_values['duration_in_minutes_select' ], - 'escalate' => $form_values['escalate_select' ], - 'created' => date('c'), - 'updated' => date('c'), - )) - ->execute(); - - - // User Activity Log - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => t('New Alert has been added: @alert_name', array('@alert_name' => $form_values['name_text'])), - 'link' => '', - ) - ); - - return; - //watchdog('user_activity', 'New Alert"' . $form_values['name_text'] . '") has been added.', WATCHDOG_WARNING, 'design/alerts/create&id=' . $id); -} - -function _cloud_alert_update($form_values, $alert_id = '') { - - $update_query = db_update( CLOUD_ALERTS_TABLE ) - ->fields(array( - 'name' => $form_values['name_text' ], - 'description' => $form_values['description_text' ], - 'metric' => $form_values['metric_select' ], - 'variable' => $form_values['variable_select' ], - '`condition`' => $form_values['condition_select' ], - 'threshold' => $form_values['threshold_text' ], - 'duration_in_minutes' => $form_values['duration_in_minutes_select' ], - 'escalate' => $form_values['escalate_select' ], - 'updated' => date('c'), - )) - ->condition('alert_id', (!empty($form_values['alert_id']) ? $form_values['alert_id'] : $alert_id)) - ->execute(); - - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => t('Alert has been modified: @alert_name', array('@alert_name' => $form_values['name_text'])), - 'link' => '', // 'design/alerts/create&id=' . $alert_id - ) - ); - - return; -} - - -function _cloud_alert_get_all() { - - $query = _cloud_alert_get(); - $result = $query->execute(); - - $alert_options = array(); - foreach ($result as $alert) { - - $alert_options[$alert->alert_id] = $alert->name; - } - - //asort($alert_options); - return $alert_options; -} - -//end diff --git a/modules/cloud_alert/cloud_alert.inc b/modules/cloud_alert/cloud_alert.inc deleted file mode 100644 index 748847b..0000000 --- a/modules/cloud_alert/cloud_alert.inc +++ /dev/null @@ -1,869 +0,0 @@ -hasPermission('list alerts') === FALSE ) { - - drupal_set_message(t('You are not authorized to access this page.')); - return array(); - } - - $user = \Drupal::currentUser(); - - // @FIXME -// The Assets API has totally changed. CSS, JavaScript, and libraries are now -// attached directly to render arrays using the #attached property. -// -// -// @see https://www.drupal.org/node/2169605 -// @see https://www.drupal.org/node/2408597 -// drupal_add_js(cloud_get_module_base() . 'js/cloud.js'); - - - $options = array( - t('Nickname' ), - t('Metric' ), - t('Variable' ), - ); - - $filter = cloud_get_filter_value( $form_submit, 'filter' ); - $filter = trim($filter); - - $filter_col = cloud_get_filter_value( $form_submit, 'operation'); - $filter_col = isset($filter_col) && $filter_col ? $filter_col : 0; // Default: Alert Name - - if ( $filter_col == 0 ) { - $column = 'Alert Name'; - $sql_col = 'name' ; - } - elseif ($filter_col == 1 ) { - $column = 'Metric' ; - $sql_col = 'metric' ; - } - elseif ($filter_col == 2 ) { - $column = 'Variable' ; - $sql_col = 'variable' ; - } - - if ( isset($filter) ) { - - $query_args[] = $sql_col; - $query_args[] = $filter ; - } - else { - $filter = ' 1 '; - $query_args[] = ' ' ; - } - - //asort($options); - - $alerts_count = _cloud_alert_get_count_db(); - $filter_disabled = ''; - if ( $alerts_count < 2 ) { - - $filter_disabled = TRUE; - } - - $form['options'] = array( - '#prefix' => '
', - '#type' => 'fieldset', - '#suffix' => '
', - // '#title' => t('Operations'), - ); - - $form['options']['label' ] = array( - '#type' => 'item' , - '#title' => t('Filter'), - ); - $form['options']['operation'] = array( - '#type' => 'select' , - '#options' => $options, - '#default_value' => $filter_col, - '#disabled' => $filter_disabled, - ); - $form['options']['filter' ] = array( - '#type' => 'textfield', - '#size' => 40, - '#default_value' => $filter, - '#disabled' => $filter_disabled, - ); - $form['options']['submit' ] = array( - '#type' => 'submit' , - '#value' => t('Apply'), - '#disabled' => $filter_disabled, - ); - - if (\Drupal::currentUser()->hasPermission('create alert') ) { - - $form['options']['alert'] = array( - '#type' => 'submit', - '#value' => t('Create'), - ); - } - - $form['header'] = array( - '#type' => 'value', - '#value' => array( - array( - 'data' => t('Nickname'), - 'field' => 'name', - 'sort' => 'asc', - 'class' => array('nickname-column'), - ), - array( - 'data' => t('Description' ), - 'field' => 'description', - ), - array( - 'data' => t('Trigger on' ), - 'field' => 'metric', - ), - array( - 'data' => t('Duration (min)'), - 'field' => 'duration_in_minutes', - ), - array( - 'data' => t('Created' ), - 'field' => 'created', - ), - array( - 'data' => t('Updated' ), - 'field' => 'updated', - ), - array( - 'data' => t('Action' ), - 'class' => 'action-column', - ), - ), - ); - - $query = _cloud_alert_get(); - $query = $query - ->extend('PagerDefault') - ->extend('TableSort') - ->orderByHeader($form['header']['#value']); - - $query - ->condition($query_args[0], '%%' . $query_args[1] . '%%', 'like') - ->fields('a') - ->limit(CLOUD_ALERTS_PAGER_LIMIT); - - $result = $query->execute(); - - - $destination = drupal_get_destination(); - foreach ($result as $alert_obj) { - - // @FIXME -// l() expects a Url object, created from a route name or external URI. -// $form['Name' ][$alert_obj->alert_id] = array( -// array('#markup' => l( $alert_obj->name, CLOUD_ALERTS_PATH . '/' . $alert_obj->alert_id . '/view', array('query' => array('id' => $alert_obj->alert_id)))), -// ); - - - $form['Trigger'][$alert_obj->alert_id] = array( - array('#markup' => t('@metric.@variable @condition @threshold', array( - '@metric' => $alert_obj->metric , - '@variable' => $alert_obj->variable , - '@condition' => $alert_obj->condition, - '@threshold' => $alert_obj->threshold, - ))), - ); - - $form['hdnName' ][$alert_obj->alert_id] = array( - '#type' => 'hidden', - '#value' => addslashes($alert_obj->name), - ); - $form['Description' ][$alert_obj->alert_id] = array('#markup' => \Drupal\Component\Utility\SafeMarkup::checkPlain( $alert_obj->description)); - $form['Created' ][$alert_obj->alert_id] = array('#markup' => format_date(strtotime($alert_obj->created), 'short')); - $form['Updated' ][$alert_obj->alert_id] = array('#markup' => format_date(strtotime($alert_obj->updated), 'short')); - $form['duration_in_minutes'][$alert_obj->alert_id] = array('#markup' => t( $alert_obj->duration_in_minutes)); - } - - $form_state['#redirect'] = FALSE; - - return $form; -} - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function theme_cloud_alert_list($variables) { - $form = $variables['form']; - - if ( \Drupal::currentUser()->hasPermission('list alerts') === FALSE ) { - - $output = \Drupal::service("renderer")->render($form); - return $output; - } - - $rows = array(); - if ( !empty($form['Name']) ) { - foreach (\Drupal\Core\Render\Element::children($form['Name']) as $key) { - - $row = array(); - $row[] = array( - 'data' => \Drupal::service("renderer")->render($form['Name'][$key]), - 'class' => array('nickname-column'), - ); - $row[] = \Drupal::service("renderer")->render($form['Description' ][$key]); - $row[] = \Drupal::service("renderer")->render($form['Trigger' ][$key]); - $row[] = \Drupal::service("renderer")->render($form['duration_in_minutes'][$key]); - $row[] = \Drupal::service("renderer")->render($form['Created' ][$key]); - $row[] = \Drupal::service("renderer")->render($form['Updated' ][$key]); - - $form['hdnName'][$key]['#value'] = !empty($form['hdnName'][$key]['#value']) ? $form['hdnName'][$key]['#value'] : ''; - $action_data = ''; - if (\Drupal::currentUser()->hasPermission('delete alert')) { - $prop['onclick'] = cloud_get_messagebox('Are you sure you want to delete the alert "' . trim($form['hdnName'][$key]['#value']) . '" ?'); - - $action_data .= cloud_display_action( 'images/icon_delete', t('Delete'), CLOUD_ALERTS_PATH . '/' . urlencode($key) . '/delete/' , array('query' => array('id' => urlencode($key)), 'html' => TRUE), $prop['onclick']); - } - - if (\Drupal::currentUser()->hasPermission('edit alert')) { - - $action_data .= cloud_display_action( 'images/icon_edit', t('Edit'), CLOUD_ALERTS_PATH . '/' . urlencode($key) . '/edit', array('query' => array('id' => urlencode($key)), 'html' => TRUE)); - } - - $row[] = array( - 'data' => $action_data, - 'class' => 'action-column', - ); - $rows[] = $row; - } - } - - while (0) { - if ($form['pager']['#markup']) { - - } - // @FIXME -// l() expects a Url object, created from a route name or external URI. -// $reload_link = l(t('- Refresh Page -'), -// CLOUD_ALERTS_PATH . '/getdata', -// array('query' => array('src' => CLOUD_ALERTS_PATH . '/list')) -// ); - - $ref_link = array( - '#type' => 'item', - '#prefix' => '', - '#markup' => $reload_link, - ); - } - - $output = \Drupal::service("renderer")->render($form['options']); - // @FIXME -// theme() has been renamed to _theme() and should NEVER be called directly. -// Calling _theme() directly can alter the expected output and potentially -// introduce security issues (see https://www.drupal.org/node/2195739). You -// should use renderable arrays instead. -// -// -// @see https://www.drupal.org/node/2195739 -// $output .= theme('table', array('header' => $form['header']['#value'], 'rows' => $rows)); - - // @FIXME -// theme() has been renamed to _theme() and should NEVER be called directly. -// Calling _theme() directly can alter the expected output and potentially -// introduce security issues (see https://www.drupal.org/node/2195739). You -// should use renderable arrays instead. -// -// -// @see https://www.drupal.org/node/2195739 -// $output .= theme('pager'); - - $output .= drupal_render_children($form); - - return $output; -} - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function cloud_alert_list_submit($form_id, &$form_values) { - - $form_values = $form_values['values']; - - if ( $form_values['op'] == t('Create')) { - - return drupal_goto( CLOUD_ALERTS_PATH . '/create'); - - } - elseif ( $form_values['op'] == t('Apply') ) { - - $param_arr = array( - 'filter' => $form_values['filter'], - 'operation' => $form_values['operation'], - ); - - $destination = drupal_get_destination(); - $form_values['redirect'] = array($destination['destination'], array('query' => $param_arr)); - } - - return; -} - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function cloud_alert_delete($alert_id = '') { - - _cloud_alert_delete($alert_id); - - drupal_set_message(t('Alert been deleted successfully.')); - drupal_goto(CLOUD_ALERTS_PATH . '/list'); - - return; -} - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function cloud_alert_view($form, $form_submit, $alert_id = '') { - - if ( \Drupal::currentUser()->hasPermission('view alerts') === FALSE ) { - - drupal_set_message(t('You are not authorized to access this page.')); - drupal_goto(CLOUD_ALERTS_PATH . '/list'); - return; - } - - $action = 'Add'; - $alerts_options = cloud_alert_get_options(); - - $form['fieldset_alert_info' ] = array( - '#type' => 'fieldset', - '#title' => t('Details'), - ); - $form['name' ]['name_label' ] = array( - '#type' => 'item', - '#title' => t('Name'), - ); - - $form['description']['description_label'] = array( - '#type' => 'item', - '#title' => t('Description'), - ); - $form['condition' ]['condition_label' ] = array( - '#type' => 'item', - '#title' => t('Condition'), - ); - - $condition_elem = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - - $condition_elem['metric_Info' ] = array( - '#value' => 'If ' , - '#size' => 20, - ); - $condition_elem['metric_select' ] = array( - '#type' => 'select' , - '#options' => $alerts_options['ALERTS_METRIC_OPTIONS'], - ); - $condition_elem['variable_Info' ] = array('#value' => ' . '); - $condition_elem['variable_select'] = array( - '#type' => 'select' , - '#options' => $alerts_options['ALERTS_VARIABLE_OPTIONS'], - ); - $condition_elem['condition_Info' ] = array('#value' => ' is '); - $condition_elem['condition_select'] = array( - '#type' => 'select' , - '#options' => $alerts_options['ALERTS_CONDITION_OPTIONS'], - ); - $condition_elem['threshold_text' ] = array( - '#type' => 'textfield', - '#size' => 10, - '#maxlength' => 3, - '#title' => t('Threshold'), - ); - $condition_elem['threshold_unit' ] = array('#value' => ''); - - //duration in minutes - $duration_options = range(0, 60); - $form['duration_in_minutes']['duration_in_minutes_label'] = array( - '#type' => 'item', - '#title' => t('Duration'), - ); - $duration_elem = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - $duration_elem['duration_in_minutes_Info' ] = array('#value' => 'For '); - $duration_elem['duration_in_minutes_select'] = array( - '#type' => 'select' , - '#options' => $duration_options, - ); - $duration_elem['duration_in_minutes_Info1'] = array('#value' => ' minutes , then escalate to '); - $duration_elem['escalate_select' ] = array( - '#type' => 'select' , - '#options' => $alerts_options['ALERTS_ESCALATIONS'], - ); - - if ($alert_id) { - - $query = _cloud_alert_get(); - $query - ->condition('alert_id', $alert_id) - ->fields('a'); - - $result = $query->execute(); - - $count = 0; - $alert_object = $result->fetchObject(); - - $action = t('Edit'); - $form['alert_id' ] = array( - '#type' => 'hidden', - '#value' => $alert_id, - ); - $form['name' ]['name_text' ] = array('#markup' => \Drupal\Component\Utility\SafeMarkup::checkPlain( isset_variable($alert_object->name))); //array('#type' => 'textfield', '#size' => 100 ); - $form['description']['description_text'] = array('#markup' => \Drupal\Component\Utility\SafeMarkup::checkPlain( isset_variable($alert_object->description) )); - $condition_elem['metric_select' ] = array('#markup' => t( isset_variable($alert_object->metric ) )); - $condition_elem['variable_select'] = array('#markup' => t( isset_variable($alert_object->variable ) )); - $condition_elem['condition_select'] = array('#markup' => t( isset_variable($alert_object->condition) )); - $condition_elem['threshold_text' ] = array('#markup' => t( isset_variable($alert_object->threshold) )); - - $duration_elem['escalate_select' ] = array('#markup' => t( isset_variable(($alert_object->escalate ) - ? $alert_object->escalate - : 'critical') )); - $duration_elem['duration_in_minutes_select'] = array('#markup' => t( isset_variable($alert_object->duration_in_minutes) )); - } - $form['condition' ]['condition_content'] = $condition_elem; - $form['duration_in_minutes']['duration_content'] = $duration_elem; - - - $form['submit_buttons'] = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - - if (\Drupal::currentUser()->hasPermission('edit alert')) { - - // Edit Button - // @FIXME -// url() expects a route name or an external URI. -// $location = check_url(url(CLOUD_ALERTS_PATH . '/' . $alert_id . '/edit')) . '&id=' . $alert_id; - - $action = "document.forms[0].action='" . $location . "';"; - $onclick = $action; - $form['submit_buttons']['Edit'] = array( - '#type' => 'submit', - '#value' => t('Edit'), - '#attributes' => array('onclick' => $onclick), - ); - } - - if (\Drupal::currentUser()->hasPermission('delete alert')) { - - // Delete Button - $confirm_msg = cloud_get_messagebox(t('Are you sure you want to delete the Alert "@alert_name" ?', array('@alert_name' => $alert_object->name))); - // @FIXME -// url() expects a route name or an external URI. -// $location = check_url(url(CLOUD_ALERTS_PATH . '/' . $alert_id . '/delete')) . '&id=' . $alert_id; - - $action = "document.forms[0].action='" . $location . "';"; - $onclick = $action . $confirm_msg; - $form['submit_buttons']['Delete'] = array( - '#type' => 'submit', - '#value' => t('Delete'), - '#attributes' => array('onclick' => $onclick), - ); - } - - $form['submit_buttons']['Cancel'] = array( - '#type' => 'submit', - '#value' => t('List Alerts'), - ); - - return $form; -} - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function theme_cloud_alert_view($variables) { - $form = $variables['form']; - - if ( \Drupal::currentUser()->hasPermission('view alerts') === FALSE ) { - - return; - } - - $rows = array( - array( - \Drupal::service("renderer")->render($form['name']['name_label'] ), - \Drupal::service("renderer")->render($form['name']['name_text'] ), - ), - array( - \Drupal::service("renderer")->render($form['description']['description_label'] ), - \Drupal::service("renderer")->render($form['description']['description_text'] ), - ), - array( - \Drupal::service("renderer")->render($form['condition']['condition_label' ] ), - \Drupal::service("renderer")->render($form['condition']['condition_content'] ), - ), - //duration_in_minutes_Info - array( - \Drupal::service("renderer")->render($form['duration_in_minutes']['duration_in_minutes_label'] ), - \Drupal::service("renderer")->render($form['duration_in_minutes']['duration_content' ] ), - ), - ); - - // @FIXME -// theme() has been renamed to _theme() and should NEVER be called directly. -// Calling _theme() directly can alter the expected output and potentially -// introduce security issues (see https://www.drupal.org/node/2195739). You -// should use renderable arrays instead. -// -// -// @see https://www.drupal.org/node/2195739 -// $table = theme('table', array('header' => NULL, 'rows' => $rows)); - - $form['fieldset_alert_info']['#children'] = $table; - - //cf. Waning by Coder module: Potential problem: when FAPI element '#type' is set to 'markup' (default), '#value' only accepts filtered text, be sure to use check_plain(), filter_xss() or similar to ensure your $variable is fully sanitized. - //$form['fieldset_alert_info']['list'] = array('#type' => 'markup', '#value' => $table); - - $output = \Drupal::service("renderer")->render($form['submit_buttons']); - $output .= \Drupal::service("renderer")->render($form['fieldset_alert_info']); - $output .= drupal_render_children($form); - - return $output; -} - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function cloud_alert_create($form, $form_submit = '', $alert_id = '') { - - $action = t('Add'); - $alerts_options = cloud_alert_get_options(); - - $form['fieldset_alert_info'] = array('#type' => 'fieldset' /* '#title' => t('Alert Info') */); - $form['name']['name_label'] = array( - '#type' => 'item' , - '#title' => t('Name'), - '#required' => TRUE, - ); - $form['name']['name_text' ] = array( - '#type' => 'textfield', - '#size' => 100, - ); - - $form['description']['description_label'] = array( - '#type' => 'item', - '#title' => t('Description'), - ); - $form['description']['description_text'] = array('#type' => 'textarea'); - - $form['condition']['condition_label'] = array( - '#type' => 'item', - '#title' => t('Condition'), - '#required' => TRUE, - ); - - $condition_elem = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - - $condition_elem['metric_Info' ] = array( - '#value' => 'If ' , - '#size' => 20, - ); - $condition_elem['metric_select' ] = array( - '#type' => 'select' , - '#options' => $alerts_options['ALERTS_METRIC_OPTIONS'], - ); - //$form['metric' ]['metric_IPs' ] = array( '#type' => 'textfield', '#size' => '14' , '#title' => t('IPs') , '#default_value' => '0.0.0.0/32' ); - $condition_elem['variable_Info' ] = array('#value' => ' . '); - $condition_elem['variable_select'] = array( - '#type' => 'select' , - '#options' => $alerts_options['ALERTS_VARIABLE_OPTIONS'], - ); - $condition_elem['condition_Info' ] = array('#value' => ' is '); - $condition_elem['condition_select'] = array( - '#type' => 'select' , - '#options' => $alerts_options['ALERTS_CONDITION_OPTIONS'], - ); - $condition_elem['threshold_text' ] = array( - '#type' => 'textfield', - '#size' => 10, - '#maxlength' => 10, - '#title' => t('Threshold'), - ); - $condition_elem['threshold_unit' ] = array('#value' => ''); - - //duration in minutes - $duration_options = range(0, 60); - unset($duration_options[0]); - $form['duration_in_minutes']['duration_in_minutes_label'] = array( - '#type' => 'item', - '#title' => t('Duration'), - ); - $duration_elem = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - $duration_elem['duration_in_minutes_Info' ] = array('#value' => 'For '); - $duration_elem['duration_in_minutes_select'] = array( - '#type' => 'select' , - '#options' => $duration_options, - ); - $duration_elem['duration_in_minutes_Info1'] = array('#value' => ' minutes , then escalate to '); - $duration_elem['escalate_select' ] = array( - '#type' => 'select' , - '#options' => $alerts_options['ALERTS_ESCALATIONS'], - ); - - if ($alert_id) { - - $query = _cloud_alert_get(); - $query - ->condition('alert_id', $alert_id) - ->fields('a'); - - $result = $query->execute(); - - $count = 0; - - $alert_object = $result->fetchObject(); - - - $action = t('Edit'); - $form['alert_id'] = array( - '#type' => 'hidden', - '#value' => $alert_id, - ); - $form['name']['name_text']['#default_value'] = isset_variable($alert_object->name); - $form['description']['description_text']['#default_value'] = isset_variable($alert_object->description ); - - $condition_elem['metric_select' ]['#default_value'] = isset_variable($alert_object->metric ); - $condition_elem['variable_select']['#default_value'] = isset_variable($alert_object->variable ); - $condition_elem['condition_select']['#default_value'] = isset_variable($alert_object->condition ); - $condition_elem['threshold_text' ]['#default_value'] = isset_variable($alert_object->threshold ); - - $duration_elem['escalate_select']['#default_value'] = isset_variable($alert_object->escalate ); - $duration_elem['duration_in_minutes_select']['#default_value'] = isset_variable($alert_object->duration_in_minutes ); - } - - $form['condition' ]['condition_content'] = $condition_elem; - $form['duration_in_minutes']['duration_content'] = $duration_elem; - - - $form['submit_buttons'] = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - - $form['submit_buttons'][$action] = array( - '#type' => 'submit', - '#value' => t($action), - ); - $form['submit_buttons']['Cancel'] = array( - '#type' => 'submit', - '#value' => t('Cancel'), - ); - - return $form; -} - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function theme_cloud_alert_create($variables) { - $form = $variables['form']; - - - $output = ''; - $rows = array( - array( - \Drupal::service("renderer")->render($form['name']['name_label'] ), - \Drupal::service("renderer")->render($form['name']['name_text'] ), - ), - array( - \Drupal::service("renderer")->render($form['description']['description_label'] ), - \Drupal::service("renderer")->render($form['description']['description_text'] ), - ), - array( - \Drupal::service("renderer")->render($form['condition']['condition_label' ] ), - \Drupal::service("renderer")->render($form['condition']['condition_content'] ), - ), - //duration_in_minutes_Info - array( - \Drupal::service("renderer")->render($form['duration_in_minutes']['duration_in_minutes_label'] ), - \Drupal::service("renderer")->render($form['duration_in_minutes']['duration_content' ] ), - ), - ); - - - // @FIXME -// theme() has been renamed to _theme() and should NEVER be called directly. -// Calling _theme() directly can alter the expected output and potentially -// introduce security issues (see https://www.drupal.org/node/2195739). You -// should use renderable arrays instead. -// -// -// @see https://www.drupal.org/node/2195739 -// $table = theme('table', array('header' => NULL, 'rows' => $rows)); - - $form['fieldset_alert_info']['#children'] = $table; - - //cf. Waning by Coder module: Potential problem: when FAPI element '#type' is set to 'markup' (default), '#value' only accepts filtered text, be sure to use check_plain(), filter_xss() or similar to ensure your $variable is fully sanitized. - //$form['fieldset_alert_info']['list'] = array('#type' => 'markup', '#value' => $table); - - $output .= \Drupal::service("renderer")->render($form['fieldset_alert_info']); - $output .= \Drupal::service("renderer")->render($form['submit_buttons']); - $output .= drupal_render_children($form); - - return $output; -} - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function cloud_alert_create_validate($form_id, $form_values) { - - $form_values = $form_values['values']; - - if ( $form_values['op'] == t('Add') - || $form_values['op'] == t('Edit') ) { - - //print_r($form_values['name_text']); die; - if ( empty($form_values['name_text']) ) { - - form_set_error('', t('You must enter valid Alert Name') ); - } - else { - - - $query = _cloud_alert_get(); - $query - ->condition('name', $form_values['name_text'], 'like') - ->fields('a'); - - $result = $query->execute()->fetchObject(); - - if ($result) { - - $alert_id = $result->alert_id; - if ($alert_id != $form_values['alert_id']) { - - form_set_error('', t('Name is already used by a Alert.')); - } - } - } - - if ( !preg_match(CLOUD_ALERTS_VALID_NUMBER, $form_values['threshold_text']) ) { - - form_set_error('', t('You must enter valid threshold value')); - } - elseif ( empty($form_values['duration_in_minutes_select']) ) { - - form_set_error('', t('You must enter valid duration time in minutes')); - } - } - - return; -} - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function cloud_alert_create_submit($form_id, $form_values) { - - $form_values = $form_values['values']; - if ( $form_values['op'] == t('Cancel')) { - - drupal_goto( CLOUD_ALERTS_PATH . '/list'); - - return; - - } - elseif ($form_values['op'] == t('Add')) { - - _cloud_alert_insert($form_values); - - drupal_set_message(t('Alert has been saved.')); - drupal_goto(CLOUD_ALERTS_PATH . '/list'); - - } - elseif ($form_values['op'] == t('Edit')) { - - $alert_id = $form_values['alert_id']; - _cloud_alert_update($form_values, $alert_id ); - drupal_set_message(t('Alert has been saved.')); - drupal_goto(CLOUD_ALERTS_PATH . '/list'); - } - - return; -} - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function cloud_alert_view_submit($form_id, $form_values) { - - $form_values = $form_values['values']; - - if ( $form_values['op'] == t('List Alerts')) { - drupal_goto( CLOUD_ALERTS_PATH . '/list'); - - return; - } -} - - -function _cloud_alert_getdata($src = '') { - - if ( $src == NULL - || empty($src) ) { - drupal_goto( CLOUD_ALERTS_PATH . '/list' ); - } - else { - - drupal_goto( $src); - } -} diff --git a/modules/cloud_alert/cloud_alert.info.yml b/modules/cloud_alert/cloud_alert.info.yml deleted file mode 100644 index 1b65c13..0000000 --- a/modules/cloud_alert/cloud_alert.info.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: Cloud Alerts -description: 'Get a quick synopsis of Alert Specifications .' -package: Cloud -core: 8.x -version: 8.x-1.x -project: cloud -type: module diff --git a/modules/cloud_alert/cloud_alert.install b/modules/cloud_alert/cloud_alert.install deleted file mode 100644 index 8ccea0b..0000000 --- a/modules/cloud_alert/cloud_alert.install +++ /dev/null @@ -1,127 +0,0 @@ - 'Alerts Configuration', - 'fields' => array( - 'alert_id' => array( - 'type' => 'serial' , - 'length' => 11, - 'not null' => TRUE, - ), - 'name' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => '', - ), - 'description' => array( - 'type' => 'text' , - 'not null' => FALSE, - 'description' => '', - ), - 'metric' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'default' => '', - 'description' => '', - ), - 'variable' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'default' => '', - 'description' => '', - ), - 'condition' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'default' => '', - 'description' => '', - ), - 'threshold' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'default' => '', - 'description' => '', - ), - 'duration_in_minutes' => array( - 'type' => 'int' , - 'length' => 11, - 'not null' => FALSE , - 'description' => '', - ), - 'escalate' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'default' => '', - 'description' => '', - ), - 'status' => array( - 'type' => 'int' , - 'length' => 3, - 'not null' => FALSE, - 'default' => 1, - 'description' => '', - ), - 'created' => array( - 'type' => 'text' , - 'not null' => FALSE, - 'description' => '', - ), - 'updated' => array( - 'type' => 'text' , - 'not null' => FALSE, - 'description' => '', - ), - ), - 'primary key' => array('alert_id'), - ); - - ///To add more schema just add one more $schema['newtable'] array . - - return $schema; -} \ No newline at end of file diff --git a/modules/cloud_alert/cloud_alert.links.action.yml b/modules/cloud_alert/cloud_alert.links.action.yml deleted file mode 100644 index 98c3eda..0000000 --- a/modules/cloud_alert/cloud_alert.links.action.yml +++ /dev/null @@ -1,14 +0,0 @@ -entity.cloud_alert.add_form: - route_name: entity.cloud_alert.add_form - title: 'Add Cloud Alert' - appears_on: - - entity.cloud_alert.collection - - entity.cloud_alert.canonical - -entity.cloud_alert.collection: - route_name: entity.cloud_alert.collection - title: 'List Cloud Alert' - appears_on: - - entity.cloud_alert.add_form - - entity.cloud_alert.edit_form - - entity.cloud_alert.delete_form \ No newline at end of file diff --git a/modules/cloud_alert/cloud_alert.links.menu.yml b/modules/cloud_alert/cloud_alert.links.menu.yml deleted file mode 100644 index e1f7fe4..0000000 --- a/modules/cloud_alert/cloud_alert.links.menu.yml +++ /dev/null @@ -1,12 +0,0 @@ -# # CloudAlert menu items definition -# entity.cloud_alert.collection: -# title: 'CloudAlert: Listing' -# route_name: entity.cloud_alert.collection -# description: 'List CloudAlert' -# -# cloud_alert.admin.structure.settings: -# title: CloudAlert Settings -# description: 'Configure CloudAlert entity' -# route_name: cloud_alert.settings -# parent: system.admin_structure -# diff --git a/modules/cloud_alert/cloud_alert.links.task.yml b/modules/cloud_alert/cloud_alert.links.task.yml deleted file mode 100644 index cdd7abd..0000000 --- a/modules/cloud_alert/cloud_alert.links.task.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Cloud Alert routing definition - -cloud_alert.settings_tab: - route_name: cloud_alert.settings - title: 'Settings' - base_route: cloud_alert.settings - -entity.cloud_alert.canonical: - route_name: entity.cloud_alert.canonical - base_route: entity.cloud_alert.canonical - title: 'View' - -entity.cloud_alert.edit_form: - route_name: entity.cloud_alert.edit_form - base_route: entity.cloud_alert.canonical - title: Edit - -entity.cloud_alert.delete_form: - route_name: entity.cloud_alert.delete_form - base_route: entity.cloud_alert.canonical - title: Delete - diff --git a/modules/cloud_alert/cloud_alert.module b/modules/cloud_alert/cloud_alert.module deleted file mode 100644 index b08d598..0000000 --- a/modules/cloud_alert/cloud_alert.module +++ /dev/null @@ -1,212 +0,0 @@ -loadInclude('cloud' , 'inc', 'cloud.constants' ); -\Drupal::moduleHandler()->loadInclude('cloud_alert', 'inc', 'cloud_alert.constants'); -\Drupal::moduleHandler()->loadInclude('cloud_alert', 'inc', 'cloud_alert' ); -\Drupal::moduleHandler()->loadInclude('cloud_alert', 'inc', 'cloud_alert.db' ); - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function cloud_alert_get_options() { - - $alerts_escalations = array( - 'critical' => t('critical'), - 'default' => t('default'), - 'scale in' => t('scale in'), - 'scale out' => t('scale out'), - 'send e-mail' => t('send e-mail'), - 'warning' => t('warning'), - ); - $alerts_metric_options = array( - 'cpu' => t('CPU'), - 'memory' => t('Memory/RAM'), - 'traffic' => t('Traffic'), - 'disk' => t('Disk'), - 'users' => t('Users/Users'), - ); - $alerts_variable_options = array( - 'value' => t('value'), - 'state' => t('state'), - 'count' => t('count'), - 'status' => t('status'), - 'ping' => t('ping'), - ); - $alerts_condition_options = array( - '<' => '<', - '>' => '>', - '=' => '=', - '!=' => '!=', - ); - - asort($alerts_escalations ); - asort($alerts_metric_options ); - asort($alerts_variable_options ); - asort($alerts_condition_options ); - - $alerts_options = array( - 'ALERTS_ESCALATIONS' => $alerts_escalations , - 'ALERTS_METRIC_OPTIONS' => $alerts_metric_options , - 'ALERTS_VARIABLE_OPTIONS' => $alerts_variable_options , - 'ALERTS_CONDITION_OPTIONS' => $alerts_condition_options, - ); - - return $alerts_options; -} - -/** - * Implements hook_help(). - */ -function cloud_alert_help($section) { - - switch ($section) { - - case 'admin/help#': - $output = '

' . t('The cloud module creates a user interface for users to manage clouds. Users can Create Instances, Describe Instances etc..') . '

'; - return $output; - } -} - -/** - * Implements hook_menu(). - */ -function cloud_alert_menu() { - - $items = array(); - - $access = \Drupal::currentUser()->hasPermission('access design'); - - // alerts Menu - - $items['design/alerts'] = array( - 'title' => 'Alerts', - 'description' => 'Get a quick synopsis of Alert Specifications.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_alert_list'), - 'weight' => 15, - 'access arguments' => array('list server templates'), - 'file' => '', - ); - - $items['design/alerts/getdata'] = array( - 'path' => 'design/alerts/getdata', - 'title' => 'alerts Get data', - 'page callback' => '_cloud_alert_getdata', - 'page arguments' => array('cloud_alert'), - 'access arguments' => array('list alerts'), - 'type' => MENU_CALLBACK, - 'file' => '', - ); - - $items['design/alerts/%/view'] = array( - //'path' => '', - 'title' => 'Alert Info', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_alert_view', 2), - //'weight' => -1, - 'access arguments' => array('list alerts'), - 'type' => MENU_CALLBACK, - 'file' => '', - ); - - $items['design/alerts/create'] = array( - //'path' => '', - 'title' => 'Add/Edit Alert', - 'description' => 'Get a quick synopsis of Alert Specifications.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_alert'), - //'weight' => -1, - 'access arguments' => array('create alert'), - 'type' => MENU_CALLBACK, - 'file' => '', - ); - - $items['design/alerts/%/edit'] = array( - //'path' => '', - 'title' => 'Add/Edit Alert', - 'description' => 'Get a quick synopsis of Alert Specifications.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_alert', 2), - //'weight' => -1, - 'access arguments' => array('create alert'), - 'type' => MENU_CALLBACK, - 'file' => '', - ); - - - $items['design/alerts/%/delete'] = array( - //'path' => '', - 'title' => 'Delete', - 'page callback' => 'cloud_alert_delete', - 'page arguments' => array(2), - 'access arguments' => array('delete alert'), - 'type' => MENU_CALLBACK, - 'file' => '', - ); - - // End of alerts Menu - - return $items; -} - - -/** - * Implements hook_permission(). - */ -function cloud_alert_permission() { - - return array( - 'list alerts' => array( - 'title' => t('list alerts' ), - 'description' => t('TODO Add a description for \'list alerts\''), - ), - 'create alert' => array( - 'title' => t('create alert'), - 'description' => t('TODO Add a description for \'create alert\''), - ), - 'view alerts' => array( - 'title' => t('view alerts' ), - 'description' => t('TODO Add a description for \'view alerts\''), - ), - 'edit alert' => array( - 'title' => t('edit alert'), - 'description' => t('TODO Add a description for \'edit alert\''), - ), - 'delete alert' => array( - 'title' => t('delete alert'), - 'description' => t('TODO Add a description for \'delete alert\''), - ), - ); -} - - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function cloud_alert_theme() { - - return array( - 'cloud_alert_list' => array( - 'render element' => 'form', - 'file' => 'cloud_alert.inc', - ), - 'cloud_alert_view' => array( - 'render element' => 'form', - 'file' => 'cloud_alert.inc', - ), - 'cloud_alert' => array( - 'render element' => 'form', - 'file' => 'cloud_alert.inc', - ), - ); -} diff --git a/modules/cloud_alert/cloud_alert.page.inc b/modules/cloud_alert/cloud_alert.page.inc deleted file mode 100644 index 55badf6..0000000 --- a/modules/cloud_alert/cloud_alert.page.inc +++ /dev/null @@ -1,30 +0,0 @@ - 'Alerts' , - 'description' => 'Alerts Test Case', - 'group' => 'Cloud' , - ); - } - - public function testAlerts() { - - // AmazonEC2TestCase::refreshPage() ; - // AmazonEC2TestCase::refreshPageImage(); - - // Access to Alerts Menu - $this->drupalGet('design/alerts'); - $this->assertResponse(200, t('HTTP 200: Design Menu' )); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - // List Alerts for Amazon EC2 - $this->drupalGet('design/alerts/list'); - $this->assertResponse(200, t('HTTP 200: Design | Alerts' )); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - $this->drupalPost('design/alerts/list', '', t('Create')); - - // Input Fields - $alertName = array(); - $alertDesc = array(); - - // Create a new alert - for ($i = 0; $i < CLOUD_ALERTS_REPEAT_COUNT; $i++) { // 3 times - - // Input Fields - $alertName[] = '#' . ($i + 1) . ': ' . date('D M j G:i:s T Y') - . ' - SimpleTest Alerts Name' ; - $alertDesc[] = '#' . ($i + 1) . ': ' . date('D M j G:i:s T Y') - . ' - SimpleTest Alerts Description' ; - $id = $i+1; - $add = array( - 'name_text' => $alertName[$i], - 'description_text' => $alertDesc[$i], - 'metric_select' => 'memory' , - 'variable_select' => 'count' , - 'threshold_text' => '5' , - 'duration_in_minutes_select' => '10', - ); - - $this->drupalPost('design/alerts/create', $add, t('Add')); - $this->assertResponse(200, t('HTTP 200: New Alert Form | Add')); - $this->assertText(t('Alert has been saved.'), - t('Confirm Message:') . t('Alert has been saved.')); - $this->assertText($alertName[$i], t('Confirm Item:') . $alertName[$i]); - $this->assertText($alertDesc[$i], t('Confirm Item:') . $alertDesc[$i]); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - $this->drupalGet('design/alerts/list'); - $this->assertResponse(200, t('HTTP 200: Design | Alerts')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - /// modify case - $edit = array( - 'alert_id' => $id, - 'name_text' => $alertName[$i], - 'description_text' => $alertDesc[$i], - 'metric_select' => 'memory' , - 'variable_select' => 'count' , - 'threshold_text' => '5' , - 'duration_in_minutes_select' => '10', - ); - - $this->drupalPost('design/alerts/' . $id . '/edit', $edit, t('Edit'), array( 'query' => $edit , )); - $this->assertResponse(200, t('HTTP 200: New Alert Form | Edit')); - $this->assertText(t('Alert has been saved.'), - t('Confirm Message:') . t('Alert has been saved.')); - $this->assertText($alertName[$i], t('Confirm Item:') . $alertName[$i] . '_modified'); - $this->assertText($alertDesc[$i], t('Confirm Item:') . $alertDesc[$i]); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - $this->drupalGet('design/alerts/list'); - $this->assertResponse(200, t('HTTP 200: Design | Alerts')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - } - - // Delete a Alerts Item - $this->drupalGet('design/alerts/1/delete', array( - 'id' => 1, - )); - $this->assertResponse(200, t('HTTP 200: Design | Alerts | Delete')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - //$this->assertText($alertName, 'Deleted Item: ' . $alertName); - - //filtering alert item - $filter = array( - 'filter' => 'Test', - 'operation' => 0, - ); - - $this->drupalPost('design/alerts', $filter, t('Apply')); - $this->assertResponse(200, t('HTTP 200: Search Listings | Filter')); - $alert_id = CLOUD_ALERTS_REPEAT_COUNT - 1 ; - $this->assertText($alertName[$alert_id], t('Confirm Item:') . $alertName[$alert_id ]); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - ///////end - } -} diff --git a/modules/cloud_alert/src/CloudAlertInterface.php b/modules/cloud_alert/src/CloudAlertInterface.php deleted file mode 100644 index 8fcf453..0000000 --- a/modules/cloud_alert/src/CloudAlertInterface.php +++ /dev/null @@ -1,36 +0,0 @@ - t('Name'), 'specifier' => 'name', 'sort' => 'ASC'], - ['data' => t('Description'), 'specifier' => 'description'], - ]; - - return $header + parent::buildHeader(); - } - - /** - * {@inheritdoc} - */ - public function buildRow(EntityInterface $entity) { - - // For debug - // $row['id'] = $entity->id(); - // $row['uuid'] = $entity->uuid(); - $row['name'] = \Drupal::l( - $this->getLabel($entity), - new Url( - 'entity.cloud_alert.canonical', [ - 'cloud_alert' => $entity->id(), - ] - ) - ); - $row['description'] = $entity->description(); - - return $row + parent::buildRow($entity); - - } - -} diff --git a/modules/cloud_alert/src/Controller/CloudAlertsController.php b/modules/cloud_alert/src/Controller/CloudAlertsController.php deleted file mode 100644 index 5225789..0000000 --- a/modules/cloud_alert/src/Controller/CloudAlertsController.php +++ /dev/null @@ -1,11 +0,0 @@ -loadInclude('cloud', 'inc', 'cloud.constants'); -/** - * - */ -class CloudAlertsController { - -} diff --git a/modules/cloud_alert/src/Entity/CloudAlert.php b/modules/cloud_alert/src/Entity/CloudAlert.php deleted file mode 100644 index 6db02e7..0000000 --- a/modules/cloud_alert/src/Entity/CloudAlert.php +++ /dev/null @@ -1,204 +0,0 @@ - \Drupal::currentUser()->id(), - ]; - } - - /** - * {@inheritdoc} - */ - public function description() { - return $this->get('description')->value; - } - - /** - * {@inheritdoc} - */ - public function created() { - return $this->get('created')->value; - } - - /** - * {@inheritdoc} - */ - public function changed() { - return $this->get('changed')->value; - } - - /** - * {@inheritdoc} - */ - public function getOwner() { - return $this->get('user_id')->entity; - } - - /** - * {@inheritdoc} - */ - public function getOwnerId() { - return $this->get('user_id')->target_id; - } - - /** - * {@inheritdoc} - */ - public function setOwnerId($uid) { - $this->set('user_id', $uid); - return $this; - } - - /** - * {@inheritdoc} - */ - public function setOwner(UserInterface $account) { - $this->set('user_id', $account->id()); - return $this; - } - - /** - * The comment language code. - */ - public function langcode() { - return $this->get('langcode'); - } - - /** - * {@inheritdoc} - */ - public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - - $fields['id'] = BaseFieldDefinition::create('integer') - ->setLabel(t('ID')) - ->setDescription(t('The ID of the Cloud Alert entity.')) - ->setReadOnly(TRUE); - - $fields['uuid'] = BaseFieldDefinition::create('uuid') - ->setLabel(t('UUID')) - ->setDescription(t('The UUID of the Cloud Alert entity.')) - ->setReadOnly(TRUE); - - $fields['user_id'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Authored by')) - ->setDescription(t('The user ID of the CloudAlert entity author.')) - ->setRevisionable(TRUE) - ->setSetting('target_type', 'user') - ->setSetting('handler', 'default') - ->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId') - ->setTranslatable(TRUE) - ->setDisplayOptions('view', [ - 'label' => 'hidden', - 'type' => 'author', - 'weight' => 0, - ]) - ->setDisplayOptions('form', [ - 'type' => 'entity_reference_autocomplete', - 'weight' => 5, - 'settings' => [ - 'match_operator' => 'CONTAINS', - 'size' => '60', - 'autocomplete_type' => 'tags', - 'placeholder' => '', - ], - ]) - ->setDisplayConfigurable('form', TRUE) - ->setDisplayConfigurable('view', TRUE); - - $fields['name'] = BaseFieldDefinition::create('string') - ->setLabel(t('Name')) - ->setDescription(t('The name of the cloud alert entity.')) - ->setSettings([ - 'default_value' => '', - 'max_length' => 255, - 'text_processing' => 0, - ]) - ->setDisplayOptions('view', [ - 'label' => 'above', - 'type' => 'string', - 'weight' => -5, - ]) - /* - ->setDisplayOptions('form', array( - 'type' => 'string_textfield', - 'weight' => -6, - )) - */ - ->setDisplayConfigurable('form', TRUE) - ->setDisplayConfigurable('view', TRUE) - ->setRequired(TRUE); - - $fields['description'] = BaseFieldDefinition::create('string') - ->setLabel(t('Description')) - ->setDescription(t('Script Description.')); - - $fields['langcode'] = BaseFieldDefinition::create('language') - ->setLabel(t('Language code')) - ->setDescription(t('The language code of CloudAlert entity.')); - - $fields['created'] = BaseFieldDefinition::create('created') - ->setLabel(t('Created')) - ->setDescription(t('The time that the entity was created.')); - - $fields['changed'] = BaseFieldDefinition::create('changed') - ->setLabel(t('Changed')) - ->setDescription(t('The time that the entity was last edited.')); - - return $fields; - } - -} diff --git a/modules/cloud_alert/src/Entity/CloudAlertViewsData.php b/modules/cloud_alert/src/Entity/CloudAlertViewsData.php deleted file mode 100644 index 4ee18f0..0000000 --- a/modules/cloud_alert/src/Entity/CloudAlertViewsData.php +++ /dev/null @@ -1,28 +0,0 @@ - 'id', - 'title' => t('Cloud Alert'), - 'help' => t('The cloud_alert entity ID.'), - ]; - - return $data; - } - -} diff --git a/modules/cloud_alert/src/Form/CloudAlertDeleteForm.php b/modules/cloud_alert/src/Form/CloudAlertDeleteForm.php deleted file mode 100644 index dc08d9c..0000000 --- a/modules/cloud_alert/src/Form/CloudAlertDeleteForm.php +++ /dev/null @@ -1,15 +0,0 @@ -entity; - - $form['name'] = [ - '#type' => 'textfield', - '#title' => $this->t('Name'), - '#maxlength' => 255, - '#size' => 60, - '#default_value' => $entity->label(), - '#required' => TRUE, - '#weight' => -5, - ]; - - $form['description'] = [ - '#type' => 'textarea', - '#title' => $this->t('Description'), - '#cols' => 60, - '#rows' => 3, - '#default_value' => $entity->description(), - '#weight' => -5, - '#required' => FALSE, - ]; - - $form['langcode'] = [ - '#title' => t('Language'), - '#type' => 'language_select', - '#default_value' => $entity->getUntranslated()->language()->getId(), - '#languages' => Language::STATE_ALL, - ]; - - $form['actions'] = $this->actions($form, $form_state); - - return $form; - } - -} diff --git a/modules/cloud_alert/src/Form/CloudAlertSettingsForm.php b/modules/cloud_alert/src/Form/CloudAlertSettingsForm.php deleted file mode 100644 index 3f3f5a0..0000000 --- a/modules/cloud_alert/src/Form/CloudAlertSettingsForm.php +++ /dev/null @@ -1,55 +0,0 @@ -drupalCreateUser([ - 'add cloud alert', - 'list cloud alert', - 'view cloud alert', - 'edit cloud alert', - 'delete cloud alert', - ]); - $this->drupalLogin($web_user); - } - - /** - * Tests CRUD for cloud_alert information. - */ - public function testCloudAlert() { - - // Access to Cloud Alert Menu - // $clouds = $this->getClouds(); - // foreach ($clouds as $cloud) {. - $cloud_context = 'default_cloud_context'; - - // List Cloud Alert for AWS. - $this->drupalGet("/clouds/design/cloud_alert"); - $this->assertResponse(200, t('HTTP 200: List | Cloud Alert')); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - - // Add a new cloud_alert information. - $add = $this->createCloudAlertTestData(); - for ($i = 0; $i < CLOUD_ALERT_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $this->drupalPostForm("/clouds/design/cloud_alert/add", - $add[$i], - t('Save')); - $this->assertResponse(200, t('HTTP 200: Add | A New Cloud Alert Form #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - $this->assertText(t('The Cloud Alert entity "@name" has been saved.', [ - '@name' => $add[$i]['name'], - ]), - t('Confirm Message') . ': ' - . t('The Cloud Alert entity "@name" has been saved.', [ - '@name' => $add[$i]['name'], - ]) - ); - $this->assertText($add[$i]['name'], - t('Name: @name ', [ - '@name' => $add[$i]['name'], - ])); - - // Make sure listing. - $this->drupalGet("/clouds/design/cloud_alert"); - $this->assertResponse(200, t('HTTP 200: List | Cloud Alert #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertText($add[$j]['name'], - t("Make sure w/ Listing @num: @name", [ - '@num' => $j + 1, - '@name' => $add[$j]['name'], - ])); - } - } - - // Edit case. - $edit = $this->createCloudAlertTestData(); - // 3 times. - for ($i = 0; $i < CLOUD_ALERT_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $this->drupalPostForm("/clouds/design/cloud_alert/$num/edit", - $edit[$i], - t('Save')); - $this->assertResponse(200, t('HTTP 200: Edit | A New Cloud Alert Form #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - $this->assertText(t('The Cloud Alert entity "@name" has been saved.', [ - '@name' => $edit[$i]['name'], - ]), - t('Confirm Message') . ': ' - . t('The Cloud Alert entity "@name" has been saved.', [ - '@name' => $edit[$i]['name'], - ]) - ); - $this->assertText($edit[$i]['name'], t('Name: @name ', [ - '@name' => $edit[$i]['name'], - ])); - - // Make sure listing. - $this->drupalGet("/clouds/design/cloud_alert"); - $this->assertResponse(200, t('HTTP 200: List | Cloud Alert #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertText($edit[$j]['name'], - t("Make sure w/ Listing @num: @name", [ - '@num' => $j + 1, - '@name' => $edit[$j]['name'], - ])); - } - } - - // Delete cloud_alert Items. - for ($i = 0; $i < CLOUD_ALERT_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $this->drupalGet("/clouds/design/cloud_alert/$num/delete"); - $this->drupalPostForm("/clouds/design/cloud_alert/$num/delete", - [], - t('Delete')); - $this->assertResponse(200, t('HTTP 200: Delete | Cloud Alert #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - // Make sure listing. - $this->drupalGet("/clouds/design/cloud_alert"); - $this->assertResponse(200, t('HTTP 200: Delete | Cloud Alert #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertNoText($edit[$j]['name'], - t("Make sure w/ Listing @num: @name", [ - '@num' => $j + 1, - '@name' => $edit[$j]['name'], - ])); - } - } - - // Filtering cloud_alert information item - /* - $filter = array( - 'filter' => 't1', - 'operation' => 0, - ); - - $this->drupalPost("/clouds/design/cloud_alert", $filter, t('Apply')); - $this->assertResponse(200, t('HTTP 200: Search Listings | Filter')); - $cloud_alert_id = CLOUD_ALERT_REPEAT_COUNT - 1 ; - $this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large'); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - */ - // end - // } // End of foreach. - } - - /** - * - */ - private function createCloudAlertTestData() { - - static $random; - if (!$random) { - $random = new Random(); - } - - // 3 times. - for ($i = 0; $i < CLOUD_ALERT_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - // Input Fields. - $data[] = [ - // 'cloud_context' => $cloud_context ,. - 'name' => "Cloud Alert #$num - " . date('Y/m/d - ') . $random->name(16, TRUE), - 'description' => "#$num: " . date('Y/m/d H:i:s - D M j G:i:s T Y') - . ' - SimpleTest Cloud Alert Description - ' - . $random->string(32, TRUE), - ]; - } - - return $data; - } - -} diff --git a/modules/cloud_alert/templates/cloud_alert.html.twig b/modules/cloud_alert/templates/cloud_alert.html.twig deleted file mode 100644 index 90a7c7e..0000000 --- a/modules/cloud_alert/templates/cloud_alert.html.twig +++ /dev/null @@ -1,22 +0,0 @@ -{# -/** - * @file cloud_alert.html.twig - * Default theme implementation to present CloudAlert data. - * - * This template is used when viewing a cloud_alert entity's page, - * - * - * Available variables: - * - content: A list of content items. Use 'content' to print all content, or - * - attributes: HTML attributes for the container element. - * - * @see template_preprocess_cloud_alert() - * - * @ingroup themeable - */ -#} - - {% if content %} - {{- content -}} - {% endif %} - diff --git a/modules/cloud_cluster/README.txt b/modules/cloud_cluster/README.txt deleted file mode 100644 index 088c67f..0000000 --- a/modules/cloud_cluster/README.txt +++ /dev/null @@ -1,65 +0,0 @@ -BASIC INFO -========== - -- Provides cluster feature which enables to bundle server templates. -- Works with Cloud and Server Templates module. - - -HOW TO USE -========== - -1) Enable Cluster module -2) Create server template(s) -3) Go to the menu: Design | Cluster | Create -4) Input Nickname and Description (and click 'Save' button) -5) Select a cluster item -6) Click 'Add Server' button -7) Select a server template -8) Enter nickname, select SSH Key, Security Group and Availability Zone -9) Click 'Add' button - - -DIRECTORY STRUCTURE -=================== - -cloud - +-modules (depends on Cloud module) (Cloud is a core module for Cloud package) - +-cloud_activity_audit - +-cloud_cluster - x-cloud_auto_scaling - +-cloud_billing - o-cloud_cluster - +-cloud_dashboard - +-cloud_failover - +-cloud_inputs - +-cloud_metering - +-cloud_monitoring - +-cloud_pricing - +-cloud_resource_allocator - x-cloud_scaling_manager - +-cloud_scripting - +-cloud_server_templates - - x... Not released yet. - - -CHANGE HISTORY -============== -2011/12/21 ver.1.2 released 6.x-1.2 -2011/07/02 ver.1.1 released 6.x-1.1 -2011/06/13 ver.1.01 released 6.x-1.01 -2011/06/10 ver.1.0 released 6.x-1.0 -2011/06/02 ver.0.92 released 6.x-1.x-dev -2011/04/05 ver.0.91 released to reviewing process of drupal.org -2011/03/24 ver.0.9 released to reviewing process of drupal.org -2011/01/29 ver.0.82 released to reviewing process of drupal.org -2010/12/26 ver.0.81 released to reviewing process of drupal.org -2010/12/15 ver.0.8 released to reviewing process of drupal.org - - -Copyright -========= - -Copyright (c) 2010-2012 DOCOMO Innovations, Inc. - -End of README.txt \ No newline at end of file diff --git a/modules/cloud_cluster/cloud_cluster.inc b/modules/cloud_cluster/cloud_cluster.inc deleted file mode 100644 index 04c9e77..0000000 --- a/modules/cloud_cluster/cloud_cluster.inc +++ /dev/null @@ -1,1930 +0,0 @@ - '
', - '#type' => 'fieldset', - '#suffix' => '
', - ); - - $form['operations']['label' ] = array( - '#type' => 'item' , - '#title' => t('Filter'), - ); - $form['operations']['operation'] = array( - '#type' => 'select' , - '#options' => $options , - '#disabled' => $filter_disabled, - '#default_value' => $filter_col, - ); - $form['operations']['filter' ] = array( - '#type' => 'textfield', - '#size' => 40 , - '#default_value' => $filter , - '#disabled' => $filter_disabled, - ); - $form['operations']['submit' ] = array( - '#type' => 'submit' , - '#value' => t('Apply'), - '#disabled' => $filter_disabled, - ); - - if (user_access('create cluster') ) { - - $tmpl_active_count = _cloud_server_templates_get_active_template_count_by_cloud(); - - if (isset($tmpl_active_count) && count($tmpl_active_count) > 0 ) { - - $form['operations']['cloud_cluster'] = array( - '#type' => 'submit', - '#value' => t('Create'), - ); - } - else { - - $form['operations']['cloud_cluster'] = array( - '#type' => 'submit', - '#value' => t('Create'), - '#disabled' => TRUE, - ); - $template_url = filter_xss( l( t('Design - Template'), 'design/server_templates' ) ); - drupal_set_message(check_plain(t('There are no Templates > ', array())) . $template_url ); - } - } - - $form['header'] = array( - '#type' => 'value', - '#value' => array( - array( - 'data' => t('Nickname'), - 'field' => 'cluster_nickname', - 'sort' => 'asc', - 'class' => array('nickname-column'), - ), - array( - 'data' => t('Description'), - 'field' => 'description', - ), - array( - 'data' => t('Creator' ), - 'field' => 'creator', - ), - array('data' => t('Servers' )), - array('data' => t('Running' )), - array('data' => t('Action'), 'class' => 'action-column'), - ), - ); - - $query = _cloud_cluster_get_clusters_query(); - $query = $query - ->extend('PagerDefault') - ->extend('TableSort') - ->orderByHeader($form['header']['#value']); - - $query - ->condition($query_args[0], '%%' . $query_args[1] . '%%', 'like') - ->fields('a') - ->limit(CLOUD_CLUSTER_PAGER_LIMIT); - - $result = $query->execute(); - - $destination = drupal_get_destination(); - - $filter_params = array(); - $filter_params['filter_state'] = 'all'; - $all_instances_list = cloud_get_all_instances_list($filter_params); - foreach ($result as $cluster) { - $run_count = _cloud_cluster_get_running_instance_count($cluster->cluster_id, '', $all_instances_list); - if ($run_count > 0) { - $form['Nickname'][$cluster->cluster_id] = array('#markup' => l( $cluster->cluster_nickname, CLOUD_CLUSTER_PATH . '/describe/servers/' . $cluster->cluster_id, array())); - } - else { - $form['Nickname'][$cluster->cluster_id] = array('#markup' => l( $cluster->cluster_nickname, CLOUD_CLUSTER_PATH . '/describe/cluster_templates/' . $cluster->cluster_id, array())); - } - - $form['Description'][$cluster->cluster_id] = array('#markup' => check_plain( $cluster->description)); - $form['Creator'][$cluster->cluster_id] = array('#markup' => t( $cluster->creator)); - - $servers_count = _cloud_cluster_get_servers_count($cluster->cluster_id, $all_instances_list); - $form['Servers'][$cluster->cluster_id] = array('#markup' => t( $servers_count)); - - $form['Running'][$cluster->cluster_id] = array('#markup' => t( $run_count)); - $form['Actions'][$cluster->cluster_id] = array('#markup' => cloud_cluster_action(array('cluster_name' => $cluster->cluster_nickname, 'cluster_id' => $cluster->cluster_id))); - } - $form['#redirect'] = FALSE; - - return $form; -} - -/** - * Theme function for cluster listing page - */ -function theme_cloud_cluster_display_list($form) { - $form = $form['form']; - $rows = array(); - - if (isset($form['Nickname'])) { - foreach (element_children($form['Nickname']) as $key) { - $rows[] = array( - array( - 'data' => drupal_render($form['Nickname' ][$key]), - 'class' => array('nickname-column'), - ), - drupal_render($form['Description'][$key]), - drupal_render($form['Creator' ][$key]), - drupal_render($form['Servers' ][$key]), - drupal_render($form['Running' ][$key]), - array( - 'data' => drupal_render($form['Actions'][$key]), - 'class' => 'action-column', - ), - ); - } - } - $output = drupal_render($form['operations']); - $output .= theme('table', array('header' => $form['header']['#value'], 'rows' => $rows, 'attributes' => array())); - $output .= theme('pager', array('tags' => array())); - $output .= drupal_render_children($form); - return $output; -} - -/** - * Function to render the actions for a cluster - */ -function cloud_cluster_action($cluster_info) { - $action_data = array(); - - if (user_access('delete cluster')) { - $prop['onclick'] = cloud_get_messagebox(t('Are you sure you want to delete the cluster "@cluster_name" ?', array('@cluster_name' => $cluster_info['cluster_name']))); - $action_data[] = cloud_display_action('images/icon_delete.png', t('Delete'), CLOUD_CLUSTER_PATH . '/delete/' . $cluster_info['cluster_id'], array('html' => TRUE), $prop['onclick']); - } - - if (user_access('update cluster')) { - $action_data[] = cloud_display_action('images/icon_edit.png', t('Edit'), CLOUD_CLUSTER_PATH . '/describe/info/' . $cluster_info['cluster_id'], array('html' => TRUE)); - } - - if (module_exists('cloud_inputs')) { // Check if inputs exists - if (user_access('update cluster')) { - $action_data[] = cloud_display_action('images/icon_table_inputs.png', 'Inputs', 'design/cloud_cluster/' . $cluster_info['cluster_id'] . '/inputs', array('query' => array('cluster_id' => $cluster_info['cluster_id'], 'module' => 'cluster'), 'html' => TRUE)); - } - } - - // allow other modules to add action icons - $user_actions = module_invoke_all('cloud_cluster_action_data', $cluster_info); - $action_data = array_merge($action_data, $user_actions); - return implode($action_data); -} - -/** - * Function that submits the cluster display listing form - */ -function cloud_cluster_display_list_submit($form_id, &$form_state) { - - $form_values =& $form_state['values']; - - if ($form_values['op'] == t('Create')) { - $form_state['redirect'] = CLOUD_CLUSTER_PATH . '/create'; - } - elseif ($form_values['op'] == t('Apply')) { - $param_arr = array( - 'filter' => $form_values['filter'], - 'operation' => $form_values['operation'], - ); - $form_state['redirect'] = array(current_path(), array('query' => $param_arr)); - } -} - -/** - * Create a new Cluster - * - * @param $page_submit - * @return - */ -function cloud_cluster_create_new_cluster($form, $page_submit = '') { - - $form = array(); - - $form['fieldset_cluster_info' ] = array('#type' => 'fieldset' /* '#title' => t('Cluster Info') */); - $form['nickname_details']['nickname_label'] = array( - '#type' => 'item', - '#title' => t('Nickname'), - '#required' => TRUE, - ); - $form['nickname_details']['nickname_text'] = array('#type' => 'textfield'); - - $form['Description_details']['Description_label'] = array( - '#type' => 'item', - '#title' => t('Description'), - ); - $form['Description_details']['description_text'] = array('#type' => 'textarea'); - - $form['submit_buttons'] = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - - $form['submit_buttons']['Next' ] = array( - '#type' => 'submit', - '#value' => t('Next' ), - ); - $form['submit_buttons']['Cancel'] = array( - '#type' => 'submit', - '#value' => t('Cancel'), - ); - - return $form; -} - - -function theme_cloud_cluster_create_new_cluster($form) { - - if (isset($form['form'])) { - - $form = $form['form']; - } - - $rows = array( - array( - drupal_render($form['nickname_details']['nickname_label'] ), - drupal_render($form['nickname_details']['nickname_text'] ), - ), - array( - drupal_render($form['Description_details']['Description_label'] ), - drupal_render($form['Description_details']['description_text'] ), - ), - ); - - - $table = theme('table', array('header' => array(), 'rows' => $rows, 'attributes' => array())); - $form['fieldset_cluster_info']['#children'] = $table; - - $output = ''; - $output .= drupal_render($form['fieldset_cluster_info']); - $output .= drupal_render($form['submit_buttons' ]); - $output .= drupal_render_children($form); - - return $output; -} - -/** - * Form validation for creating new cluster - */ -function cloud_cluster_create_new_cluster_validate($form_id, $form_values) { - - $form_values = $form_values['values']; - if ( $form_values['op'] == t('Next') ) { - if ( empty( $form_values['nickname_text']) == TRUE) { - form_set_error('nickname_text', t('Please enter Nickname')); - return; - } - else { - // Check whether same name cluster exists - $query = _cloud_cluster_get_cluster_by_filter_query(); - $query_args = array( - ':cluster_nickname' => $form_values['nickname_text'], - ); - - $result = db_query( $query, $query_args ); - foreach ($result as $db_obj) { - $cluster_id = $db_obj->cluster_id; - if (isset($form_values['cluster_id']) === FALSE || $cluster_id != $form_values['cluster_id']) { - form_set_error('cluster_id', t('Name is already used by a Cluster.')); - } - } - } - } -} - -/** - * Create new cluster submit - */ -function cloud_cluster_create_new_cluster_submit($form_id, &$form_state) { - - $form_values = $form_state['values']; - - if ($form_values['op'] == t('Next')) { - global $user; - $owner = $user->name; - $cluster_id = _cloud_cluster_save_cluster_db($form_values, $owner); - - if ($cluster_id !== NULL ) { - drupal_set_message(t('Cluster successfully created. For the next step, add Server(s) based on Template to Cluster.')); - $enabled_cloud_list = cloud_get_clouds(); - $tmpl_active_count = _cloud_server_templates_get_active_template_count_by_cloud(); - for ($row_counter = 0; $row_counter < count($enabled_cloud_list); $row_counter++) { - $cloud_name = $enabled_cloud_list[$row_counter]["cloud_name"]; - if (isset($tmpl_active_count) == FALSE || isset($tmpl_active_count[$cloud_name]) == FALSE ) { - // No templates repsent - continue; - } - // Goto the first cloud in the list - $form_state['redirect'] = CLOUD_CLUSTER_PATH . '/describe/servers/add_server/' . $cloud_name . '/' . $cluster_id; - return; - } - } - else { - drupal_set_message(t('There was an error while creating Cluster'), 'error'); - } - } - $form_state['redirect'] = CLOUD_CLUSTER_PATH; -} - - -/** - * Display Cluster details information - * - * @param $page_submit - * @param $cluster_id - * Cluster Id which information is to be displayed - * @return - */ -function cloud_cluster_display_detail_info($form, $page_submit = '', $cluster_id = '' ) { - - if (empty($cluster_id) || strlen($cluster_id) == 0 ) { - - drupal_goto( CLOUD_CLUSTER_PATH ); - - return; - } - - $query = _cloud_cluster_get_cluster_by_id_query(); - $query_args = array( - ':cluster_id' => $cluster_id, - ); - - $result = db_query( $query, $query_args ); - $count = 0; - - $filter_params = array( - 'filter_state' => 'all', - ); - - $all_instances_list = cloud_get_all_instances_list($filter_params); - - $form = array(); - $form['fieldset_cluster_info'] = array( - '#type' => 'fieldset', - '#title' => t('Details'), - ); - $form['cluster_info_header' ] = array( - '#prefix' => '

', - '#markup' => t('Cluster Info'), - '#suffix' => '

', - ); - - $txt_disabled = ''; - if (user_access('update cluster') === FALSE ) { - - $txt_disabled = TRUE; - } - - - foreach ($result as $key) { - - $form['nickname_details' ]['nickname_label' ] = array( - '#type' => 'item', - '#title' => t('Nickname'), - ); - $form['nickname_details' ]['nickname_text' ] = array( - '#type' => 'textfield', - '#default_value' => $key->cluster_nickname, - '#disabled' => $txt_disabled, - ); - - $form['Description_details']['Description_label'] = array( - '#type' => 'item', - '#title' => t('Description'), - ); - $form['Description_details']['description_text'] = array( - '#type' => 'textarea', - '#default_value' => $key->description , - '#disabled' => $txt_disabled, - ); - - $form['Creator_details' ]['creator_label' ] = array( - '#type' => 'item', - '#title' => t('Creator'), - ); - $form['Creator_details' ]['creator_text' ] = array('#markup' => t( $key->creator)); - - $servers_count = _cloud_cluster_get_servers_count($key->cluster_id, $all_instances_list); - $form['Servers_details' ]['servers_label' ] = array( - '#type' => 'item', - '#title' => t('Servers'), - ); - $form['Servers_details' ]['servers_text' ] = array('#markup' => t( $servers_count)); - - $run_count = _cloud_cluster_get_running_instance_count($key->cluster_id, '', $all_instances_list); - $form['Running_details' ]['running_label' ] = array( - '#type' => 'item', - '#title' => t('Running'), - ); - $form['Running_details' ]['running_text' ] = array('#markup' => t( $run_count)); - - $form['cluster_id'] = array( - '#type' => 'hidden', - '#value' => $key->cluster_id, - ); - - $form['submit_buttons'] = array( - '#prefix' => '
', - '#type' => 'fieldset', - '#suffix' => '
', - ); - - if (user_access('update cluster') ) { - - // Update button - $form['submit_buttons']['Update'] = array( - '#type' => 'submit', - '#value' => t('Update'), - ); - $confirm_msg = cloud_get_messagebox('Are you sure you want to delete the Cluster?'); - $form['submit_buttons']['Delete'] = array( - '#type' => 'submit', - '#value' => t('Delete'), - '#attributes' => array('onclick' => $confirm_msg), - ); - } - - $form['submit_buttons']['List Clusters'] = array( - '#type' => 'submit', - '#value' => t('List Clusters'), - ); - - $count++; - - break; - } - - if ( $count == 0 ) { - - drupal_goto( CLOUD_CLUSTER_PATH ); - - return; - } - - return $form; -} - - -function theme_cloud_cluster_display_detail_info($form) { - - if (isset($form['form'])) { - - $form = $form['form']; - } - - $rows = array( - array( - drupal_render($form['nickname_details' ]['nickname_label' ] ), - drupal_render($form['nickname_details' ]['nickname_text' ] ), - ), - array( - drupal_render($form['Description_details']['Description_label'] ), - drupal_render($form['Description_details']['description_text'] ), - ), - array( - drupal_render($form['Creator_details' ]['creator_label' ] ), - drupal_render($form['Creator_details' ]['creator_text' ] ), - ), - array( - drupal_render($form['Servers_details' ]['servers_label' ] ), - drupal_render($form['Servers_details' ]['servers_text' ] ), - ), - array( - drupal_render($form['Running_details' ]['running_label' ] ), - drupal_render($form['Running_details' ]['running_text' ] ), - ), - ); - - - $table = theme('table', array('header' => array(), 'rows' => $rows, 'attributes' => array())); - - $form['fieldset_cluster_info']['#children'] = $table; - - $output = drupal_render($form['cluster_info_header'] ); - $output .= drupal_render($form['submit_buttons' ] ); - $output .= drupal_render($form['cluster_id' ] ); - $output .= drupal_render($form['fieldset_cluster_info']); - - $output .= drupal_render_children($form); - - return $output; -} - - -function cloud_cluster_display_detail_info_validate($form_id, $form_values) { - - $form_values = $form_values['values']; - if ( $form_values['op'] == t('Update') ) { - - if ( empty( $form_values['nickname_text']) == TRUE) { - - form_set_error('nickname_text', t('Please enter Nickname')); - - return; - } - else { - - $query = _cloud_cluster_get_cluster_by_filter_query(); - $query_args = array( - ':cluster_nickname' => $form_values['nickname_text'], - ); - - $result = db_query( $query, $query_args )->fetchObject(); - if ($result !== FALSE) { - - $db_obj = $result; - $cluster_id = $db_obj->cluster_id; - - if ($cluster_id != $form_values['cluster_id']) { - form_set_error('cluster_id', t('Name is already used by a Cluster.')); - } - } - } - } -} - - -function cloud_cluster_display_detail_info_submit($form_id, &$form_state) { - - $form_values = $form_state['values']; - - if ( $form_values['op'] == t('List Clusters') ) { - $form_state['redirect'] = CLOUD_CLUSTER_PATH; - } - elseif ($form_values['op'] == t('Update')) { - $cluster_id = $form_values['cluster_id']; - _cloud_cluster_update_cluster_db($form_values, $cluster_id ); - drupal_set_message(t('Cluster has been updated.')); - $form_state['redirect'] = CLOUD_CLUSTER_PATH . '/describe/info/' . $cluster_id; - } - elseif ($form_values['op'] == t('Delete')) { - $cluster_id = $form_values['cluster_id']; - _cloud_cluster_delete_cluster(array(), $form_values, $cluster_id); - $form_state['redirect'] = CLOUD_CLUSTER_PATH; - } -} - - -function _cloud_cluster_stop_all_servers($cluster_id, $action, $all_instances_list = array()) { - - $run_count = _cloud_cluster_get_running_instance_count($cluster_id, '', $all_instances_list); - if ( $run_count < 1 ) { - - return NULL; //No instances running. No action to be taken - } - - if (empty($all_instances_list)) { - - $filter_params = array(); - $filter_params['filter_state'] = 'all'; - $all_instances_list = cloud_get_all_instances_list($filter_params); - } - - - $running_instance_count = 0; - $query = _cloud_cluster_servers_get_query(); - $query->condition('cluster_id', $cluster_id, '='); - $result = $query->execute(); - - - foreach ($result as $key) { - - $instance_ids_str = $key->instance_id; - if (empty($instance_ids_str)) { - - continue; - } - - $instance_ids = explode( ',', $instance_ids_str ); - foreach ($instance_ids as $instance_id) { - - $instance_id = trim($instance_id); - if (isset($all_instances_list[$instance_id])) { - - if ( isset($all_instances_list[$instance_id]['state']) - && drupal_strtolower($all_instances_list[$instance_id]['state']) !== 'terminated' - && drupal_strtolower($all_instances_list[$instance_id]['state']) !== 'halted' - && drupal_strtolower($all_instances_list[$instance_id]['state']) !== 'stopped' - && drupal_strtolower($all_instances_list[$instance_id]['state']) !== 'shutting-down') { - - if ($action == 'stop_all' ) { - - $result_terminate = cloud_perform_action( '', 'terminate', $all_instances_list[$instance_id]['cloud_context'], array($instance_id) ); - } - elseif ($action == 'count_running' ) { - - $running_instance_count++; - } - } - } - } - } - - return $running_instance_count; -} - - -function _cloud_cluster_get_servers_count($cluster_id, $all_instances_list = array()) { - - $servers_count = 0; - $run_count = _cloud_cluster_get_running_instance_count($cluster_id, '', $all_instances_list); - $query = _cloud_cluster_templates_get_query(); - $query_args = array( - ':cluster_id' => $cluster_id, - ); - - $result = db_query( $query, $query_args ); - - if ( $run_count < 1 ) { // No servers running - - foreach ($result as $clust) { // Cluster server object - $servers_count += $clust->count_instances; - } - } - else { // Servers running : Count the number of instances present - foreach ($result as $clust) { // Cluster server object - $instance_ids_str = $clust->instance_id; - $instance_ids = explode( ',', $instance_ids_str); - $servers_count += sizeof($instance_ids); - } - } - - return $servers_count; -} - -function _cloud_cluster_get_servers_count_by_id($cluster_id, $server_id, $all_instances_list = array()) { - - $servers_count = 0; - $run_count = _cloud_cluster_get_running_instance_count($cluster_id, '', $all_instances_list); - $query = _cloud_cluster_templates_server_get_query(); - $query_args = array( - ':cluster_id' => $cluster_id, - ':server_id' => $server_id, - ); - - $result = db_query( $query, $query_args ); - - if ( $run_count < 1 ) { // No servers running - foreach ($result as $clust) { // Cluster server object - $servers_count += $clust->count_instances; - } - } - else { // Servers running : Count the number of instances present - foreach ($result as $clust) { // Cluster server object - $instance_ids_str = $clust->instance_id; - $instance_ids = explode( ',', $instance_ids_str); - $servers_count += sizeof($instance_ids); - } - } - - return $servers_count; -} - - -function _cloud_cluster_get_running_instance_count($cluster_id, $server_id = '', $all_instances_list = array()) { - - $filter_params = array(); - $filter_params['filter_state'] = 'all'; - if (empty($all_instances_list)) { - - $all_instances_list = cloud_get_all_instances_list($filter_params); - } - - $query = ''; - $query_args = array(); - - if ( empty($server_id) ) { - $query = _cloud_cluster_servers_get_query(); - $query->condition('cluster_id', $cluster_id, '='); - - $result = $query->execute(); - } - else { - - $query = _cloud_cluster_server_get_query(); - $query_args = array( - ':cluster_id' => $cluster_id, - ':server_id' => $server_id, - ); - - $result = db_query( $query, $query_args ); - } - - $running_instance_count = 0; - - foreach ($result as $key) { - - $instance_ids_str = $key->instance_id; - if (empty($instance_ids_str)) { - - continue; - } - - $instance_ids = explode( ',', $instance_ids_str ); - foreach ($instance_ids as $instance_id) { - - $instance_id = trim($instance_id); - if (isset($all_instances_list[$instance_id])) { - - if ( isset($all_instances_list[$instance_id]['state']) - && drupal_strtolower($all_instances_list[$instance_id]['state']) !== 'terminated' - && drupal_strtolower($all_instances_list[$instance_id]['state']) !== 'halted' - && drupal_strtolower($all_instances_list[$instance_id]['state']) !== 'stopped' ) { - - $running_instance_count++; - } - } - } - } - - return $running_instance_count; -} - - -/** - * Display List of Templates present in a cluster - * - * @param $page_submit - * @param $cluster_id - * Cluster ID who's server's are to be displayed - * @return - */ -function cloud_cluster_display_templates_list($form, $page_submit = '', $cluster_id = '' ) { - $base = cloud_get_module_base(); - drupal_add_js(cloud_get_module_base() . 'js/cloud.js'); - - if (empty($cluster_id) ) { - drupal_goto( CLOUD_CLUSTER_PATH ); - return; - } - - $filter_params = array(); - $filter_params['filter_state'] = 'all'; - $all_instances_list = cloud_get_all_instances_list($filter_params); - $run_count = _cloud_cluster_get_running_instance_count($cluster_id, '', $all_instances_list); - - $form['submit_buttons'] = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - - if (user_access('update cluster')) { - if ($run_count < 1) { - $tmpl_active_count = _cloud_server_templates_get_active_template_count_by_cloud(); - if (isset($tmpl_active_count) && count($tmpl_active_count) > 0 ) { - $form['submit_buttons']['add_server'] = array( - '#type' => 'submit', - '#value' => t('Add Server'), - ); - } - else { - $form['submit_buttons']['add_server'] = array( - '#type' => 'submit', - '#value' => t('Add Server'), - '#disabled' => TRUE, - ); - $template_url = l(t('Design - Template'), 'design/server_templates'); - drupal_set_message(t('There are no Templates')); - } - - $count_servers = _cloud_cluster_servers_get_count_db($cluster_id); - - if ($count_servers > 0 ) { - - $form['submit_buttons']['start_all_servers'] = array( - '#type' => 'submit', - '#value' => t('Start All Servers'), - ); - // Delete all templates - $confirm_msg = cloud_get_messagebox('Are you sure you want to delete all the templates?'); - $onclick = $confirm_msg; - $form['submit_buttons']['delete_all_servers'] = array( - '#type' => 'submit', - '#value' => t('Delete All Servers'), - '#attributes' => array('onclick' => $onclick), - ); - } - else { - $form['submit_buttons']['start_all_servers'] = array( - '#type' => 'submit', - '#value' => t('Start All Servers' ), - '#disabled' => TRUE, - ); - $form['submit_buttons']['delete_all_servers'] = array( - '#type' => 'submit', - '#value' => t('Delete All Servers'), - '#disabled' => TRUE, - ); - } - } - else { - - $form['submit_buttons']['add_server'] = array( - '#type' => 'submit', - '#value' => t('Add Server'), - '#disabled' => TRUE, - ); - $form['submit_buttons']['start_all_servers'] = array( - '#type' => 'submit', - '#value' => t('Start All Servers' ), - '#disabled' => TRUE, - ); - $form['submit_buttons']['delete_all_servers'] = array( - '#type' => 'submit', - '#value' => t('Delete All Servers'), - '#disabled' => TRUE, - ); - } - } - else { - $form['submit_buttons'] = array( - '#type' => 'item', - '#value' => t(''), - ); - } - - $query = _cloud_cluster_templates_get_query(); - $query_args = array( - ':cluster_id' => $cluster_id, - ); - - $form['server_header'] = array( - '#prefix' => '

', - '#markup' => t('Cluster Servers'), - '#suffix' => '

', - ); - - $form['header'] = array( - '#type' => 'value', - '#value' => array( - array( - 'data' => t('Nickname' ), - 'field' => 'server_nickname', - 'class' => array('nickname-column'), - ), - array( - 'data' => t('Cloud' ), - 'field' => 'cloud_type', - ), - array( - 'data' => t('Template' ), - 'field' => 'template_nickname', - ), - array('data' => t('Servers' )), - array('data' => t('Running' )), - array('data' => t('Actions'), 'class' => 'action-column'), - ), - ); - - $cloud_name_list = cloud_get_all_clouds_display_name(); - $server_list = array(); - - $order_query = db_select(CLOUD_CLUSTER_SERVER_TABLE, 't') - ->extend('TableSort') - ->orderByHeader($form['header']['#value']); - - - $order_by = explode('ORDER BY' , $order_query ); - $query .= ' ORDER BY ' . $order_by[1]; // append order - - $result = db_query( $query, $query_args ); - - - foreach ($result as $clust) { // Cluster server object - $server_id = $clust->server_id; - - $server_list[$server_id]['server_id' ] = $server_id; - $server_list[$server_id]['server_name' ] = $clust->server_nickname; - $server_list[$server_id]['server_template_id'] = $clust->template_id; - $server_list[$server_id]['server_template' ] = $clust->template_nickname; - $server_list[$server_id]['cloud_context' ] = $clust->cloud_type; - $server_list[$server_id]['cloud_context_name'] = isset( $cloud_name_list[$clust->cloud_type] ) - ? $cloud_name_list[$clust->cloud_type] - : $clust->cloud_type; - $server_list[$server_id]['servers' ] = _cloud_cluster_get_servers_count_by_id($cluster_id, $server_id, $all_instances_list = array()); - $server_list[$server_id]['running' ] = _cloud_cluster_get_running_instance_count($cluster_id, $server_id, $all_instances_list); - } - - foreach ( $server_list as $cluster_server ) { - - $server_id = $cluster_server['server_id' ]; - $cloud_context = $cluster_server['cloud_context']; - - $form['server_name' ][$server_id] = array( - '#prefix' => '', - '#markup' => t( $cluster_server['server_name'] ), - '#suffix' => '', - ); - $form['hdnName' ][$server_id] = array( - '#type' => 'hidden', - '#value' => t( $cluster_server['server_name'] ), - ); - $form['Cloud_type' ][$server_id] = array('#markup' => t($cluster_server['cloud_context_name'])); - $form['server_template'][$server_id] = array('#markup' => l($cluster_server['server_template'], - 'design/server_templates/' . $cloud_context . '/' . $cluster_server['server_template_id'] . '/view', - array('query' => array('id' => urlencode($cluster_server['server_template_id'] ))) )); - $form['server_id' ][$server_id] = array( - '#type' => 'hidden', - '#value' => t( $server_id), - ); - $form['servers' ][$server_id] = array('#markup' => t( $cluster_server['servers'] )); - $form['running' ][$server_id] = array('#markup' => t( $cluster_server['running'] )); - $form['cloud_context' ][$server_id] = array( - '#type' => 'value', - '#markup' => $cloud_context, - ); - $form['server_template_id'][$server_id] = array( - '#type' => 'value', - '#markup' => $cluster_server['server_template_id'], - ); - $template_info = array( - 'server_name' => $cluster_server['server_name'], - 'server_id' => $server_id, - 'run_count' => $cluster_server['running'], - 'cluster_id' => $cluster_id, - 'template_id' => $cluster_server['server_template'], - ); - $form['Actions'][$server_id] = array('#markup' => cloud_cluster_template_action($cloud_context, $template_info)); - } - - $form['cluster_id'] = array( - '#type' => 'hidden', - '#value' => t( $cluster_id), - ); - - return $form; -} - - -function theme_cloud_cluster_display_templates_list($form) { - $form = $form['form']; - $output = drupal_render($form['server_header']); - $output .= drupal_render($form['submit_buttons']); - - $cluster_id = $form['cluster_id']['#value']; - $rows = array(); - - $run_count = _cloud_cluster_get_running_instance_count($cluster_id); - if (isset($form['server_name']) ) { - foreach (element_children($form['server_name']) as $deplkey) { - $prop_delete = array(); - $prop_delete['onclick'] = cloud_get_messagebox('Are you sure you want to delete the template "' . $form['hdnName'][$deplkey]['#value'] . '" ?'); - - $rows[] = array( - array( - 'data' => drupal_render($form['server_name' ][$deplkey]), - 'class' => array('nickname-column'), - ), - drupal_render($form['Cloud_type' ][$deplkey]), - drupal_render($form['server_template'][$deplkey]), - drupal_render($form['servers' ][$deplkey]), - drupal_render($form['running' ][$deplkey]), - array( - 'data' => drupal_render($form['Actions'][$deplkey]), - 'class' => 'action-column', - ), - ); - } - } - - $output .= theme('table', array('header' => $form['header']['#value'], 'rows' => $rows, 'attributes' => array())); - $output .= drupal_render_children($form); - return $output; -} - -/** - * Function to render the template actions for a cluster - */ -function cloud_cluster_template_action($cloud_context, $template_info) { - $action_data = ''; - $server_name = $template_info['server_name']; - $server_id = $template_info['server_id']; - $run_count = $template_info['run_count']; - $cluster_id = $template_info['cluster_id']; - $template_id = $template_info['template_id']; - - $prop_delete['onclick'] = cloud_get_messagebox('Are you sure you want to delete the template "' . $server_name . '" ?'); - - if (user_access('delete cluster') && $run_count == 0 ) { - $action_data .= cloud_display_action( - 'images/icon_delete.png', - t('Delete'), - CLOUD_CLUSTER_PATH . '/describe/servers/delete_server/' . $cluster_id . '/' . $server_id, - array('query' => array('server_id' => urlencode($server_id)), 'html' => TRUE), - $prop_delete['onclick']); - } - - if (user_access('edit server template') && module_exists('cloud_inputs') && $run_count == 0) { - $destination = array( - 'destination' => 'design/cluster/describe/cluster_templates/' . $cluster_id, - 'template_id' => $template_id, - 'module' => 'cluster', - 'type' => $cloud_context, - 'server_id' => $server_id, - ); - - $action_data .= cloud_display_action( - 'images/icon_table_inputs.png', - t('Inputs'), - 'design/cloud_cluster_template/' . $cluster_id . '/inputs', - array('query' => $destination, 'html' => TRUE) - ); - } - return $action_data; -} - -function cloud_cluster_display_templates_list_submit($form_id, &$form_state) { - $form_values =& $form_state['values']; - // Check for the operation - if ($form_values['op'] !== t('Stop All Servers')) { - // Check if Instances already running then do nothing return - $run_count = _cloud_cluster_get_running_instance_count($form_values['cluster_id']); - if ( $run_count > 0 ) { - drupal_set_message( check_plain( t( 'Cannot perform operation @operation . Instances are running.', array('@operation' => $form_values['op']) ) ), 'error' ); - $form_state['redirect'] = CLOUD_CLUSTER_PATH . '/describe/cluster_templates/' . $form_values['cluster_id']; - } - } - - if ($form_values['op'] == t('Add Server')) { - $enabled_cloud_list = cloud_get_clouds(); - $tmpl_active_count = _cloud_server_templates_get_active_template_count_by_cloud(); - for ($row_counter = 0; $row_counter < count($enabled_cloud_list); $row_counter++) { - $cloud_name = $enabled_cloud_list[$row_counter]["cloud_name"]; - if (isset($tmpl_active_count) == FALSE || isset($tmpl_active_count[$cloud_name]) == FALSE ) { - // No templates repsent - continue; - } - // Goto the first cloud in the list - $form_state['redirect'] = CLOUD_CLUSTER_PATH . '/describe/servers/add_server/' . $cloud_name . '/' . $form_values['cluster_id']; - return; - } - // No Cloud found - drupal_set_message( t( 'There is no enabled cloud. First enable a Cloud and then try adding a template' ), 'warning' ); - $form_state['redirect'] = CLOUD_CLUSTER_PATH . '/describe/servers/' . $form_values['cluster_id']; - } - elseif ( $form_values['op'] == t('Start All Servers')) { - $form_state['redirect'] = CLOUD_CLUSTER_PATH . '/describe/servers/start_all_servers/' . $form_values['cluster_id']; - return; - } - elseif ( $form_values['op'] == t('Delete All Servers')) { - $run_count = _cloud_cluster_get_running_instance_count($form_values['cluster_id']); - - if ($run_count > 0 ) { - drupal_set_message(t('Unable to delete. Instances running'), 'error'); - $form_state['redirect'] = CLOUD_CLUSTER_PATH . '/describe/cluster_templates/' . $form_values['cluster_id']; - return; - } - else { - _cloud_cluster_delete_all_server_db($form_values['cluster_id']); - drupal_set_message(t('Templates deleted')); - $form_state['redirect'] = CLOUD_CLUSTER_PATH . '/describe/cluster_templates/' . $form_values['cluster_id']; - return; - } - } - elseif ( $form_values['op'] == t('Inputs')) { - $form_state['redirect'] = CLOUD_CLUSTER_PATH . '/' . $form_values['cluster_id'] . '/inputs'; - return; - } -} - -/** - * Ajax callback - */ -function _cloud_cluster_callback_get_cluster_servers_list() { - $cluster_id = isset($_REQUEST['cluster_id']) ? $_REQUEST['cluster_id'] : FALSE; - - if (empty($cluster_id)) { - - $output = 'NULL'; - $html = $output; - print drupal_to_js(array('html' => $html)); - // The exit() call is critical! - exit(); - } - - $form = drupal_get_form('cloud_cluster_display_server_list', $cluster_id); - $output = theme('cloud_cluster_display_server_list', $form); - - $index_start = strrpos( $output, '' ); - $index_end = strrpos( $output, '' ); - if ( isset($form['instance_nickname']) === FALSE || sizeof($form['instance_nickname']) == 0 ) { // No element present - $output = 'NULL'; - } - else { - $output = substr($output, $index_start, $index_end - $index_start); - $output .= ''; - } - print drupal_json_encode(array('html' => $output)); - exit(); - -} - -/** - * Display List of server's present in a cluster - * - * @param $page_submit - * @param $cluster_id - * Cluster ID who's server's are to be displayed - * @return - */ -function cloud_cluster_display_server_list($form, $form_state = '', $cluster_id = '' ) { - - drupal_add_js(cloud_get_module_base() . 'js/cloud.js'); - drupal_add_js(cloud_get_module_base() . 'js/cloud_cluster_auto_refresh_list_servers.js'); - - if (empty($cluster_id) ) { - drupal_goto( CLOUD_CLUSTER_PATH ); - return; - } - - $form = array(); - - $query = _cloud_cluster_servers_get_query(); - $query->condition('cluster_id', $cluster_id, '='); - $result = $query->execute(); - - $filter_params = array(); - $filter_params['filter_state'] = 'all'; - $all_instances_list = cloud_get_all_instances_list($filter_params); - - $form['server_header'] = array( - '#prefix' => '

', - '#markup' => t('Cluster Instances'), - '#suffix' => '

', - ); - - $form['header'] = array( - '#type' => 'value', - '#value' => array( - array( - 'data' => t('Nickname' ), - 'field' => 'server_name', - 'class' => array('nickname-column'), - ), - array( - 'data' => t('Instance name' ), - 'field' => 'instance_nickname', - ), - array( - 'data' => t('Cloud' ), - 'field' => 'cloud_context', - ), - array( - 'data' => t('Zone' ), - 'field' => 'zone', - ), - array( - 'data' => t('Hostname' ), - 'field' => 'host_name', - ), - array( - 'data' => t('ID' ), - 'field' => 'instance_id', - ), - array( - 'data' => t('Template' ), - 'field' => 'server_template', - ), - array( - 'data' => t('State' ), - 'field' => 'state', - ), - array( - 'data' => t('Runtime' ), - 'field' => 'runtime', - ), - array( - 'data' => t('Action' ), - 'class' => 'action-column', - ), - ), - ); - - $form['submit_buttons'] = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - - if ( _cloud_cluster_stop_all_servers($cluster_id, 'count_running', $all_instances_list) > 0 ) { - - $confirm_msg = cloud_get_messagebox('Are you sure you want to stop all the servers ?'); - $onclick = $confirm_msg; - $form['submit_buttons']['stop_all_servers'] = array( - '#type' => 'submit', - '#value' => t('Stop All Servers'), - '#attributes' => array('onclick' => $onclick), - ); - } - else { - - $form['submit_buttons']['stop_all_servers'] = array( - '#type' => 'submit', - '#value' => t('Stop All Servers'), - '#disabled' => TRUE, - ); - } - - $destination = drupal_get_destination(); - $count = 0; - $failover_status = array(); - $cloud_name_list = cloud_get_all_clouds_display_name(); - $server_list = array(); - - $run_count = _cloud_cluster_get_running_instance_count($cluster_id); - - - foreach ($result as $clust) { // Cluster server object - if ($run_count == 0) { - - break; // No instances running - } - - $inst_count = 0; - $inst_found = TRUE; - $instance_ids = array(0); // Dummy array - $instance_ids_str = $clust->instance_id; - if ( empty($instance_ids_str) ) { - - $inst_found = FALSE; - } - else { - - $instance_ids = explode( ',', $instance_ids_str ); - } - - foreach ($instance_ids as $instance_id ) { - - $inst_count++; - $server_id = $clust->server_id; - $index_id = $clust->server_id . '_' . $instance_id; - - $server_list[$index_id]['index_id' ] = $index_id; - $server_list[$index_id]['server_id' ] = $server_id; - $server_list[$index_id]['server_name' ] = $clust->server_nickname; - - if ( $inst_found - && count($instance_ids) > 1 ) { - - $server_list[$index_id]['server_name' ] .= ' #' . $inst_count; // Append #1, #2... - } - - $tmpl = cloud_get_server_template_info($clust->template_id); - $server_list[$index_id]['server_template_id'] = $clust->template_id; - $server_list[$index_id]['server_template' ] = $tmpl->template_nickname; - $server_list[$index_id]['cloud_context' ] = $tmpl->cloud_type; - $server_list[$index_id]['cloud_context_name'] = isset( $cloud_name_list[$tmpl->cloud_type] ) ? $cloud_name_list[$tmpl->cloud_type] : $tmpl->cloud_type; - - - if ( empty($instance_id) === FALSE - && isset($all_instances_list[$instance_id]) ) { - - $instance_info = $all_instances_list[$instance_id]; - - $server_list[$index_id]['instance_nickname'] = trim($instance_info['name']); - $server_list[$index_id]['host_name' ] = $instance_info['hostname']; - $server_list[$index_id]['instance_id' ] = $instance_id; - $server_list[$index_id]['state' ] = ucwords($instance_info['state']); - $server_list[$index_id]['zone' ] = $instance_info['zone']; - $server_list[$index_id]['runtime' ] = $instance_info['runtime']; - $server_list[$index_id]['lock_status' ] = $instance_info['lock_status']; - } - else { - - $server_list[$index_id]['instance_nickname'] = ''; - $server_list[$index_id]['host_name' ] = ''; - $server_list[$index_id]['instance_id' ] = ''; - $server_list[$index_id]['state' ] = ''; - $server_list[$index_id]['zone' ] = ''; - $server_list[$index_id]['runtime' ] = ''; - $server_list[$index_id]['lock_status' ] = ''; - } - - if ( empty($instance_id) === FALSE ) { - - $server_list[$index_id]['instance_id' ] = $instance_id; - } - - } // End of foreach ($instance_ids as $instance_id ) { - } // End of while - - $ts = tablesort_init( $form['header']['#value'] ); - if ($ts['sql']) { - - $field = $ts['sql']; - $server_list = _cloud_sort_by_value( $server_list, $field, $ts['sort'] ); - } - - foreach ( $server_list as $cluster_server ) { - - $index_id = $cluster_server['index_id' ]; - $server_id = $cluster_server['server_id' ]; - $cloud_context = $cluster_server['cloud_context' ]; - $name = $cluster_server['instance_nickname']; - $state = $cluster_server['state' ]; - $hostname = $cluster_server['host_name' ]; - $zone = $cluster_server['zone' ]; - $runtime = $cluster_server['runtime' ]; - $lock_status = $cluster_server['lock_status' ]; - $instance_id = $cluster_server['instance_id' ]; - - $cloud_menu_path = cloud_get_menu_path($cloud_context); - - $form['server_name' ][$index_id] = array( - '#prefix' => '', - '#markup' => t( $cluster_server['server_name'] ), - '#suffix' => '', - ); - $form['hdnName' ][$index_id] = array( - '#type' => 'hidden', - '#value' => t( $cluster_server['server_name'] ), - ); - - if ( !empty($state) - && drupal_strtolower($state) == 'running' ) { - - $form['instance_nickname'][$index_id] = array( - array( - '#markup' => l($name, - $cloud_menu_path . '/instances/describe/' . $instance_id . '/info', - array( - 'query' => array('instance_id' => urlencode($instance_id)), - )) - . (($lock_status == 'Lock') - ? '    ' - : '' - ), // end 'l' function - ), // end array - ); // end $form - } - else { - - $form['instance_nickname'][$index_id] = array('#markup' => $name); - } - - $public_dns = substr( $hostname, 0, strpos($hostname, '.') ); - if ( strlen($public_dns) > 3 ) { // truncate only in case the name is long - $public_dns = substr($hostname, 0, strpos($hostname, '.')) . '...'; - } - else { - - $public_dns = $hostname; - } - - $form['Cloud_type' ][$index_id] = array('#markup' => t( $cluster_server['cloud_context_name'] )); - $form['Zone' ][$index_id] = array('#markup' => t( $zone )); - $form['Public_ip' ][$index_id] = array('#markup' => l($public_dns, - 'http://' . $hostname, array( - 'attributes' => array('target' => '_blank'), - 'query' => array(), - ) )); - $form['Instanceid' ][$index_id] = array('#markup' => t( $instance_id )); - $form['server_template'][$index_id] = array('#markup' => l( $cluster_server['server_template'], 'design/server_templates/' . $cloud_context . '/' . $cluster_server['server_template_id'] . '/view', array('query' => array('id' => urlencode($cluster_server['server_template_id'] )) ))); - $form['State' ][$index_id] = array('#markup' => t( ucwords($state) )); - $form['Runtime' ][$index_id] = array('#markup' => t( ($runtime) - ? cloud_get_runtime($runtime) - : '' - )); - $form['server_id' ][$index_id] = array( - '#type' => 'hidden', - '#value' => t( $server_id), - ); - } - - $form['cluster_id'] = array( - '#type' => 'hidden', - '#value' => t( $cluster_id ), - ); - - return $form; -} - - -/** - * Theme function for cluster display server list - */ -function theme_cloud_cluster_display_server_list($form) { - - $form = $form['form']; - $output = drupal_render($form['server_header' ]); - $output .= drupal_render($form['submit_buttons']); - - $cluster_id = $form['cluster_id']['#value']; - - $filter_params = array(); - $filter_params['filter_state'] = 'all'; - $all_instances_list = cloud_get_all_instances_list(array('filter_state' => 'all')); - - $rows = array(); - if (isset($form['server_name']) ) { - foreach (element_children($form['server_name']) as $deplkey) { - - $row = array( - array( - 'data' => drupal_render($form['server_name' ][$deplkey]), - 'class' => array('nickname-column'), - ), - drupal_render($form['instance_nickname' ][$deplkey]), - drupal_render($form['Cloud_type' ][$deplkey]), - drupal_render($form['Zone' ][$deplkey]), - drupal_render($form['Public_ip' ][$deplkey]), - drupal_render($form['Instanceid' ][$deplkey]), - drupal_render($form['server_template' ][$deplkey]), - drupal_render($form['State' ][$deplkey]), - drupal_render($form['Runtime' ][$deplkey]), - ); - - $action_data = ''; - $server_id = $form['server_id'][$deplkey]['#value']; - if (empty($form['Instanceid'][$deplkey]['#markup']) - || drupal_strtolower( $form['State'][$deplkey]['#markup']) == 'terminated' - || drupal_strtolower( $form['State'][$deplkey]['#markup']) == 'stopped' - || empty( $form['State'][$deplkey]['#markup'])) { - - if (user_access('update cluster')) { - $action_data .= cloud_display_action( - 'images/icon_play.png', - 'launch', - CLOUD_CLUSTER_PATH . '/describe/servers/launch_server/' . $cluster_id . '/' . $server_id, - array('query' => array('instance_id' => $form['Instanceid'][$deplkey]['#markup']), - 'html' => TRUE) - ); - } - } - elseif (empty($form['Instanceid'][$deplkey]['#markup']) === FALSE ) { - - $instance_id = $form['Instanceid'][$deplkey]['#markup']; - if (isset($all_instances_list[$instance_id]) ) { - $action_data .= $all_instances_list[$instance_id]['action_data']; - } - } - - $row[] = array( - 'data' => $action_data, - 'class' => 'action-column', - ); - $rows[] = $row; - } - } - - $table_attr = array(); - $table_attr['id'] = 'cluster_servers_list_table'; - $table_attr['autoupdate_url'] = url( CLOUD_CLUSTER_PATH . '/callback_get_cluster_servers_list' ); - - $output .= theme('table', array('header' => $form['header']['#value'], 'rows' => $rows, 'attributes' => $table_attr)); - - if (count($rows) > 0) { - - $reload_link = l( t( '- Refresh Page -' ), CLOUD_CLUSTER_PATH . '/get_data/' . $cluster_id , array() ); - $ref_link = array( - '#type' => 'item', - '#prefix' => '', - '#markup' => $reload_link, - ); - - $output .= drupal_render($ref_link); - } - - $output .= drupal_render($form['cluster_id'] ); - - $output .= drupal_render_children($form); - - return $output; -} - - -function cloud_cluster_display_server_list_submit($form_id, $form_values) { - - $form_values = $form_values['values']; - - if ( $form_values['op'] == t('Stop All Servers')) { - - _cloud_cluster_stop_all_servers($form_values['cluster_id'], 'stop_all' ); - drupal_goto(CLOUD_CLUSTER_PATH . '/describe/servers/' . $form_values['cluster_id'] ); - return; - } - - return; -} - - -function _cloud_cluster_get_data($cluster_id) { - - cloud_update_all_cloud_data(); - drupal_goto( CLOUD_CLUSTER_PATH . '/describe/servers/' . $cluster_id ); - - return; -} - - -function _cloud_cluster_describe() { - - drupal_goto( CLOUD_CLUSTER_PATH ); - - return; -} - - -/** - * Delete a server from Cluster - * - * @param $form_values - * @param $cluster_id - * Cluster from which server is to be deleted - * @param $server_id - * Server to be deleted - * @return - */ -function _cloud_cluster_delete_server($form, $form_values, $cluster_id = '', $server_id = '') { - - $run_count = _cloud_cluster_get_running_instance_count($cluster_id, $server_id); - - if ($run_count > 0 ) { - - drupal_set_message(t('Cannot delete template. Instances running for this Template'), 'error'); - drupal_goto(CLOUD_CLUSTER_PATH . '/describe/cluster_templates/' . $cluster_id ); - - return; - } - - _cloud_cluster_delete_server_db($server_id); - drupal_set_message(t('Template deleted from Cluster')); - drupal_goto(CLOUD_CLUSTER_PATH . '/describe/cluster_templates/' . $cluster_id ); - - return; -} - - -/** - * Launch a server from Cluster - * - * @param $page_submit - * @param $cluster_id - * Cluster from which server is to be launched - * @param $server_id - * Server which is to be launched - * @return - */ -function _cloud_cluster_launch_server($form, $page_submit = '', $cluster_id = '', $server_id = '' ) { - - $query = _cloud_cluster_get_server_query(); - $query_args = array( - ':server_id' => $server_id, - ); - - $launch_params = array(); - $result = db_query( $query, $query_args ); - - $cluster_id = FALSE; - $server_name = ''; - $template_id = ''; - - $server_obj = NULL; - - foreach ($result as $depl) { - - $launch_params['template_id' ] = $depl->template_id ; - $launch_params['nickname' ] = $depl->server_nickname ; - $launch_params['key_name' ] = $depl->server_sshkey ; - $launch_params['security_group'] = $depl->server_security_group; - $launch_params['placement' ] = $depl->server_zone ; - - - if ( isset($depl->instance_id) - && empty($depl->instance_id) === FALSE ) { - - $launch_params['count_instances'] = 1; - } - - $cluster_id = $depl->cluster_id ; - $server_name = $depl->server_nickname; - $template_id = $depl->template_id ; - - $server_obj = $depl ; - $instance_id = $depl->instance_id ; - - } - - if (!$cluster_id || empty($template_id) ) { // The server configuration not found or the server was deleted - drupal_set_message(t('Server ID not found'), 'error' ); - drupal_goto(CLOUD_CLUSTER_PATH ); - - return; - } - - $cloud_context = _cloud_server_templates_get_cloud($template_id); - - // Launch the instance - $result_launch = cloud_perform_action( '', 'launch_using_params', $cloud_context, $launch_params ); - - - if (count($result_launch)) { // Successfully launched the instance - //$new_instance_ids = isset( $_REQUEST['new_instance_ids'] ) ? $_REQUEST['new_instance_ids'] : array(); - -// if ( isset($new_instance_ids[0]) ) { -// $new_instance_id = $new_instance_ids[0]; -// } -// else { -// $new_instance_id = FALSE; -// } - -// if (empty($instance_id)) { - -// $instance_id = $new_instance_id; -// } -// else { - -// $instance_id = str_replace( $_REQUEST['instance_id'], $new_instance_id, $instance_id); -// } - - $instsance_id = array_shift($result_launch); - $update_query = _cloud_cluster_update_cluster_server_query($instance_id, $server_id); - - drupal_set_message( check_plain(t('Server launched: @server_name', array('@server_name' => $server_name) ) ) ); - drupal_goto(CLOUD_CLUSTER_PATH . '/describe/servers/' . $cluster_id ); - } - else { - - // Failed launch instance - drupal_set_message( check_plain(t('Server launch failed: @server_name', array('@server_name' => $server_name) ) ), 'error' ); - drupal_goto(CLOUD_CLUSTER_PATH . '/describe/servers/' . $cluster_id ); - } - - return; -} - - -/** - * Launch all the server's present in a Cluster - * - * @param $page_submit - * @param $cluster_id - * Cluster from which server's are to be launched - * @return - */ -function _cloud_cluster_launch_server_all($form, $page_submit = '', $cluster_id = '' ) { - - if (empty($cluster_id) ) { - - drupal_goto(CLOUD_CLUSTER_PATH); - - return; - } - - - $query = _cloud_cluster_servers_get_query(); - $query->condition('cluster_id', $cluster_id, '='); - $result = $query->execute(); - - // Get the list of all instances - $cloud_list = cloud_get_all_clouds(); - - $all_instances_list = array(); - $filter_params = array(); - foreach ($cloud_list as $cloud_context) { - - $filter_params['filter_state'] = 'all'; - $instances_list = cloud_get_instances($cloud_context, $filter_params ); - $all_instances_list = array_merge( $all_instances_list, $instances_list ); - } - - $runningserver_cnt = 0; - - foreach ($result as $depl) { // Cluster server object - $instance_ids_str = $depl->instance_id; - if (empty($instance_ids_str) ) { // Launch the instance - $state = ''; - } - else { - - $instance_ids = explode( ',' , $instance_ids_str ); - foreach ($instance_ids as $instance_id ) { - - if (isset($all_instances_list[$instance_id]) ) { - - $instance_info = $all_instances_list[$instance_id]; - $state = $instance_info['state']; - if ( drupal_strtolower($state) === 'running') { // Found a ruuning instance Skip this instance - $runningserver_cnt += 1; - continue; - } - } - } - } - - $server_obj = NULL; - - // Launch instance - $launch_params = array(); - $launch_params['template_id' ] = $depl->template_id ; - $launch_params['nickname' ] = $depl->server_nickname ; - $launch_params['key_name' ] = $depl->server_sshkey ; - $launch_params['security_group'] = $depl->server_security_group; - $launch_params['placement' ] = $depl->server_zone ; - - $server_name = $depl->server_nickname ; - $template_id = $depl->template_id ; - $server_id = $depl->server_id ; - - $server_obj = $depl; - - $cloud_context = _cloud_server_templates_get_cloud($template_id); - - // Launch the instance - $result_launch = cloud_perform_action( '', 'launch_using_params', $cloud_context, $launch_params ); - - - if ($result_launch) { // Successfully launched the instance - //$new_instance_ids = isset( $_REQUEST['new_instance_ids'] ) ? $_REQUEST['new_instance_ids'] : array(); - $instance_id = implode(',', $result_launch); - $update_query = _cloud_cluster_update_cluster_server_query($instance_id, $server_id); - - } - else { - - // Failed launch instance - drupal_set_message( check_plain(t('Server launch failed: @server_name', array('@server_name' => $server_name) ) ), 'error' ); - drupal_goto(CLOUD_CLUSTER_PATH . '/describe/cluster_templates/' . $cluster_id ); - return; - } - } - - drupal_goto(CLOUD_CLUSTER_PATH . '/describe/servers/' . $cluster_id ); -} - - -/** - * Delete a Cluster - * Check whether any Server is running if a server is running do not delete the Cluster. - * - * @param $form_values - * @param $cluster_id - * Cluster to be deleted - * @return - */ -function _cloud_cluster_delete_cluster($form, $form_values, $cluster_id = '') { - - $run_count = _cloud_cluster_get_running_instance_count($cluster_id); - - if ( $run_count > 0 ) { - - drupal_set_message(check_plain('Cannot delete cluster. Instance(s) of cluster are still active. '), 'error'); - - if (isset($form_values['cluster_id']) && $form_values['cluster_id'] == $cluster_id ) { - - drupal_goto(CLOUD_CLUSTER_PATH . '/describe/info/' . $cluster_id ); - } - else { - - drupal_goto(CLOUD_CLUSTER_PATH); - } - } - else { - - _cloud_cluster_delete_by_id($cluster_id) ; - drupal_set_message(t('Cluster deleted successfully')); - drupal_goto(CLOUD_CLUSTER_PATH); - } -} - - -/** - * Add a server to a Cluster - * - * @param $cloud_context - * Server added from this Sub-cloud - * @param $cluster_id - * Cluster to which server is to be added - * @return - */ -function _cloud_cluster_add_server( $cloud_context, $cluster_id) { - - if (empty($cluster_id) ) { - - drupal_goto(CLOUD_CLUSTER_PATH); - - return; - } - - $query = _cloud_cluster_get_cluster_by_id_query(); - $query_args = array( - ':cluster_id' => $cluster_id, - ); - - $result = db_query( $query, $query_args ); - $count = 0; - - $cluster_nickname = ''; - - foreach ($result as $key) { - - $cluster_nickname = $key->cluster_nickname; - $count++; - } - - $params = array(); - $params['cluster_id' ] = $cluster_id ; - $params['cluster_nickname'] = $cluster_nickname; - - - $cloud_list = cloud_get_all_clouds_display_name(); - $is_cloud_enabled = cloud_is_settings_done($cloud_context); - if ($is_cloud_enabled === FALSE ) { - cloud_set_config_error_message($cloud_list[$cloud_context], $cloud_context); - } - else { - - $tmpl_active_count = _cloud_server_templates_get_active_template_count_by_cloud(); - if ( isset($tmpl_active_count[$cloud_context]) == FALSE || $tmpl_active_count[$cloud_context] < 1 ) { - - $template_url = filter_xss( l( t('Design - Template'), 'design/server_templates/' . $cloud_context . '/list' ) ); - drupal_set_message(check_plain(t('There are no Templates for @cloud_name > ', array('@cloud_name' => $cloud_list[$cloud_context]))) . $template_url ); - } - - } - - return cloud_server_templates_notify( '', 'cluster_form', $cloud_context, $params ); -} diff --git a/modules/cloud_cluster/cloud_cluster.info.yml b/modules/cloud_cluster/cloud_cluster.info.yml deleted file mode 100644 index 614ab98..0000000 --- a/modules/cloud_cluster/cloud_cluster.info.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: Cloud Cluster -description: 'A cluster consists of a group of servers that work together' -package: Cloud -dependencies: - - cloud - - cloud_server_template -core: 8.x -version: 8.x-1.x -project: cloud -type: module diff --git a/modules/cloud_cluster/cloud_cluster.install b/modules/cloud_cluster/cloud_cluster.install deleted file mode 100644 index 3651a95..0000000 --- a/modules/cloud_cluster/cloud_cluster.install +++ /dev/null @@ -1,127 +0,0 @@ - 'Cluster of VMs', - 'fields' => array( - 'cluster_id' => array( - 'type' => 'serial' , - 'length' => 11, - ), - 'cluster_nickname' => array( - 'type' => 'varchar', - 'length' => 64, - ), - 'description' => array( - 'type' => 'text' , - 'length' => 255, - ), - 'creator' => array( - 'type' => 'varchar', - 'length' => 64, - ), - ), - 'primary key' => array('cluster_id'), - ); - - - $schema[CLOUD_CLUSTER_SERVER_TABLE] = array( - 'description' => 'Cluster and template table', - 'fields' => array( - 'server_id' => array( - 'type' => 'serial' , - 'length' => 11, - ), - 'cluster_id' => array( - 'type' => 'int' , - 'length' => 11, - ), - 'template_id' => array( - 'type' => 'int' , - 'length' => 11, - ), - 'instance_id' => array( - 'type' => 'varchar', - 'length' => 64, - ), - 'server_nickname' => array( - 'type' => 'varchar', - 'length' => 64, - ), - 'server_sshkey' => array( - 'type' => 'varchar', - 'length' => 64, - ), - 'server_security_group' => array( - 'type' => 'varchar', - 'length' => 64, - ), - 'server_zone' => array( - 'type' => 'varchar', - 'length' => 64, - ), - 'elastic_ip' => array( - 'type' => 'varchar', - 'length' => 16, - ), - 'failover_flag' => array( - 'type' => 'int' , - 'length' => 3 , - 'default' => 0, - ), - 'failover_check_duration' => array( - 'type' => 'int' , - 'length' => 3 , - 'default' => 3, - ), - 'failover_status' => array( - 'type' => 'int' , - 'length' => 3 , - 'default' => 0, - ), - 'last_failover_check_time' => array('type' => 'text'), - ), - 'primary key' => array('server_id'), - ); - - return $schema; - -} -*/ \ No newline at end of file diff --git a/modules/cloud_cluster/cloud_cluster.links.action.yml b/modules/cloud_cluster/cloud_cluster.links.action.yml deleted file mode 100644 index b3a4bfa..0000000 --- a/modules/cloud_cluster/cloud_cluster.links.action.yml +++ /dev/null @@ -1,14 +0,0 @@ -entity.cloud_cluster.add_form: - route_name: entity.cloud_cluster.add_form - title: 'Add Cloud Cluster' - appears_on: - - entity.cloud_cluster.collection - - entity.cloud_cluster.canonical - -entity.cloud_cluster.collection: - route_name: entity.cloud_cluster.collection - title: 'List Cloud Cluster' - appears_on: - - entity.cloud_cluster.add_form - - entity.cloud_cluster.edit_form - - entity.cloud_cluster.delete_form \ No newline at end of file diff --git a/modules/cloud_cluster/cloud_cluster.links.menu.yml b/modules/cloud_cluster/cloud_cluster.links.menu.yml deleted file mode 100644 index 76dffec..0000000 --- a/modules/cloud_cluster/cloud_cluster.links.menu.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Created by yas 2016/06/23. - -# MENU_NORMAL_ITEM -cloud_cluster.menu: - title: 'Cluster' - route_name: 'entity.cloud_cluster.collection' -# base_route: 'cloud.design.menu' - parent: 'cloud.design.menu' - weight: 75 \ No newline at end of file diff --git a/modules/cloud_cluster/cloud_cluster.links.task.yml b/modules/cloud_cluster/cloud_cluster.links.task.yml deleted file mode 100644 index 6a90582..0000000 --- a/modules/cloud_cluster/cloud_cluster.links.task.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Cloud Cluster routing definition - -cloud_cluster.settings_tab: - route_name: cloud_cluster.settings - title: 'Settings' - base_route: cloud_cluster.settings - -entity.cloud_cluster.canonical: - route_name: entity.cloud_cluster.canonical - base_route: entity.cloud_cluster.canonical - title: 'View' - -entity.cloud_cluster.edit_form: - route_name: entity.cloud_cluster.edit_form - base_route: entity.cloud_cluster.canonical - title: Edit - -entity.cloud_cluster.delete_form: - route_name: entity.cloud_cluster.delete_form - base_route: entity.cloud_cluster.canonical - title: Delete - diff --git a/modules/cloud_cluster/cloud_cluster.module b/modules/cloud_cluster/cloud_cluster.module deleted file mode 100644 index 22fad00..0000000 --- a/modules/cloud_cluster/cloud_cluster.module +++ /dev/null @@ -1,278 +0,0 @@ -' . t('A cluster consists of a group of servers that work together.') . '

'; - return $output; - } -} - - -/** - * Implementation of hook_menu(). - */ -/* -function cloud_cluster_menu() { - - $items = array(); - - $items[CLOUD_CLUSTER_PATH] = array( - 'title' => CLOUD_CLUSTER_DISPLAY_NAME, - 'description' => CLOUD_CLUSTER_DISPLAY_NAME, - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_cluster_display_list'), - 'weight' => 10, - 'access arguments' => array('list clusters'), - 'file' => '', - ); - - - $items[CLOUD_CLUSTER_PATH . '/get_data/%'] = array( - 'title' => 'Get data', - 'page callback' => '_cloud_cluster_get_data', - 'page arguments' => array(3), - 'access arguments' => array('list clusters'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - - - $items[CLOUD_CLUSTER_PATH . '/callback_get_cluster_servers_list'] = array( - 'page callback' => '_cloud_cluster_callback_get_cluster_servers_list', - 'type' => MENU_CALLBACK, - 'access arguments' => array('list clusters'), - ); - - $items[CLOUD_CLUSTER_PATH . '/describe'] = array( - 'page callback' => '_cloud_cluster_describe', - 'access arguments' => array('list clusters'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - - - $items[CLOUD_CLUSTER_PATH . '/create'] = array( - 'title' => 'New Cluster', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_cluster_create_new_cluster'), - 'access arguments' => array('create cluster'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - - $items[CLOUD_CLUSTER_PATH . '/delete/%'] = array( - 'title' => 'Delete Cluster', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('_cloud_cluster_delete_cluster', 3), - 'access arguments' => array('delete cluster'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - - $items[CLOUD_CLUSTER_PATH . '/describe/info/%'] = array( - 'title' => 'Info', - 'description' => 'Cluster Details', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_cluster_display_detail_info', 4), - 'access arguments' => array('list clusters'), - 'file' => '', - 'weight' => 1, - 'type' => MENU_LOCAL_TASK, - ); - - - $items[CLOUD_CLUSTER_PATH . '/describe/cluster_templates/%'] = array( - 'title' => 'Design', - 'description' => 'Cluster Design by adding Templates', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_cluster_display_templates_list', 4), - 'access arguments' => array('list clusters'), - 'file' => '', - 'weight' => 2, - 'type' => MENU_LOCAL_TASK, - ); - - - $items[CLOUD_CLUSTER_PATH . '/describe/servers/%'] = array( - 'title' => 'Instances', - 'description' => 'Instances', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_cluster_display_server_list', 4), - 'access arguments' => array('list clusters'), - 'file' => '', - 'weight' => 3, - 'type' => MENU_LOCAL_TASK, - ); - - - $items[CLOUD_CLUSTER_PATH . '/describe/servers/add_server'] = array( - 'title' => 'Add Server to Cluster', - 'description' => 'Add Server to Cluster', - 'access arguments' => array('update cluster'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - - //$enabled_cloud_list = cloud_get_clouds() ; - $cloud_list = cloud_get_all_clouds(); - $row_counter = 0; - $cloud_name_list = cloud_get_all_clouds_display_name(); - - foreach ($cloud_list as $cloud_context) { - //$cloud_name = $enabled_cloud_list[$row_counter]["cloud_name"] ; - //$cloud_display_name = $enabled_cloud_list[$row_counter]["cloud_display_name"] ; - - $items[CLOUD_CLUSTER_PATH . '/describe/servers/add_server/' . $cloud_context . '/%'] = array( - 'title' => $cloud_name_list[$cloud_context], - 'description' => $cloud_name_list[$cloud_context], - 'page callback' => '_cloud_cluster_add_server', - 'page arguments' => array($cloud_context, 6), - 'access arguments' => array('update cluster'), - 'file' => '', - 'weight' => $row_counter, - 'type' => MENU_LOCAL_TASK, - ); - $row_counter++; - } - - - $items[CLOUD_CLUSTER_PATH . '/describe/servers/delete_server/%/%'] = array( - 'page callback' => 'drupal_get_form', - 'page arguments' => array('_cloud_cluster_delete_server' , 5, 6), - 'access arguments' => array('update cluster'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - - $items[CLOUD_CLUSTER_PATH . '/describe/servers/launch_server/%/%'] = array( - 'page callback' => 'drupal_get_form', - 'page arguments' => array('_cloud_cluster_launch_server' , 5, 6), - 'access arguments' => array('update cluster'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - - $items[CLOUD_CLUSTER_PATH . '/describe/servers/start_all_servers/%'] = array( - 'page callback' => 'drupal_get_form', - 'page arguments' => array('_cloud_cluster_launch_server_all', 5), - 'access arguments' => array('update cluster'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - - - return $items; -} -*/ - -function cloud_cluster_theme() { - - return array( - 'cloud_cluster_display_list' => array( - 'render element' => 'form', - 'file' => 'cloud_cluster.inc', - ), - 'cloud_cluster_create_new_cluster' => array( - 'render element' => 'form', - 'file' => 'cloud_cluster.inc', - ), - 'cloud_cluster_display_detail_info' => array( - 'render element' => 'form', - 'file' => 'cloud_cluster.inc', - ), - 'cloud_cluster_display_server_list' => array( - 'render element' => 'form', - 'file' => 'cloud_cluster.inc', - ), - 'cloud_cluster_display_templates_list' => array( - 'render element' => 'form', - 'file' => 'cloud_cluster.inc', - ), - ); -} - -/** - * Implementation of hook_permission(). - */ -/* -function cloud_cluster_permission() { - - return array( - 'create cluster' => array( - 'title' => t('create cluster' ), - 'description' => t('TODO Add a description for \'create cluster\''), - ), - 'list clusters' => array( - 'title' => t('list clusters'), - 'description' => t('TODO Add a description for \'list clusters\''), - ), - 'update cluster' => array( - 'title' => t('update cluster'), - 'description' => t('TODO Add a description for \'update cluster\''), - ), - 'delete cluster' => array( - 'title' => t('delete cluster'), - 'description' => t('TODO Add a description for \'delete cluster\''), - ), - ); -} -*/ - -/* - * This will be called when the respective Cloud submits the Cluster form - * e.g. When Amazon EC2 Cluster form submit's the following function will be called to save the Cluster - */ -function cloud_cluster_add_server_submit($form_id, $form_values) { - - $cluster_id = $form_values['cluster_id'] ; - - if ( $form_values['op'] == t('List Servers') ) { - - drupal_goto( CLOUD_CLUSTER_PATH . '/describe/cluster_templates/' . $cluster_id ); - - return; - } - elseif ($form_values['op'] == t('Save')) { - _cloud_cluster_save_cluster_server_db($form_values); - drupal_set_message(t('Server @server_name added to Cluster.', array('@server_name' => $form_values['nickname_text']) )); - drupal_goto( CLOUD_CLUSTER_PATH . '/describe/cluster_templates/' . $cluster_id ); - } - elseif ($form_values['op'] == t('Add More')) { - - _cloud_cluster_save_cluster_server_db($form_values); - drupal_set_message(t('Server @server_name added to Cluster.', array('@server_name' => $form_values['nickname_text']) )); - - return; - } - - return; -} - - diff --git a/modules/cloud_cluster/cloud_cluster.page.inc b/modules/cloud_cluster/cloud_cluster.page.inc deleted file mode 100644 index 6d98a01..0000000 --- a/modules/cloud_cluster/cloud_cluster.page.inc +++ /dev/null @@ -1,30 +0,0 @@ - 'Cluster' , - 'description' => 'Cluster Test Cases', - 'group' => 'Cloud' , - ); - } - - public function testCluster() { - - // Access to Design | Cluster - $this->drupalGet('design/cluster'); - $this->assertResponse(200, t('HTTP 200: Design | Cluster')); - $this->assertText( t('- Refresh Page -'), t('Found: - Refresh Page -')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - $clusterName = array(); - $clusterDesc = array(); - - for ($i = 0; $i < CLOUD_CLUSTER_REPEAT_COUNT; $i++) { // 3 times - - // Input Fields - $clusterName[] = t('#@number: @date - SimpleTest Cluster Name' , array( - '@number' => $i + 1, - '@date' => date('D M j G:i T Y'))); - $clusterDesc[] = t('#@number: @date - SimpleTest Cluster Description', array( - '@number' => $i + 1, - '@date' => date('D M j G:i T Y'))); - - $edit = array( - 'nickname_text' => $clusterName[$i], - 'description_text' => $clusterDesc[$i], - ); - - $this->drupalPost('design/cluster/create', $edit, t('Next')); - $this->assertResponse(200, t('HTTP 200: New Cluster Form | Add')); - $this->assertText(t('Cluster successfully created.'), - t('Confirm Message:') . t('Cluster successfully created.')); - $this->assertText($clusterName[$i], t('Confirm Item on Listing Page: @cluster_name', array('@cluster_name' => $clusterName[$i]))); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - - for ( $j = 0; $j < $i + 1; $j++) { - - $cluster_id = $j + 1 ; - $this->drupalGet('design/cluster/describe/info/' . $cluster_id ); - $this->assertResponse(200, t('HTTP 200: Display Cluster Detail Page: @number', array('@number' => $cluster_id))); - $this->assertText($clusterDesc[$j], t('Confirm Cluster Description on Infor Page: @cluster_desc', array('@cluster_desc' => $clusterDesc[$j]))); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - } - } - - //filtering cluster item - $filter = array( - 'filter' => 'Test', - 'operation' => 0, - ); - - $this->drupalPost('design/cluster', $filter, t('Apply')); - $this->assertResponse(200, t('HTTP 200: Search Listings | Filter')); - $cluster_id = CLOUD_CLUSTER_REPEAT_COUNT - 1 ; - $this->assertText($clusterName[$cluster_id], t('Confirm Item:') . $clusterName[$cluster_id ]); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - ///////end - } - - - public function testClusterListServers() { - - $edit = array( - 'nickname_text' => 'Cluster_List_Servers', - 'description_text' => 'Cluster_description' , - ); - - $this->drupalPost('design/cluster/create', $edit, t('Next')); - $this->assertResponse(200, t('HTTP 200: New Cluster Form | Add')); - $this->assertText(t('Cluster successfully created.'), t('Confirm Message:') . t('Cluster successfully created.')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - // Access to Cluster | Servers - $this->drupalGet('design/cluster/describe/servers/1'); - $this->assertResponse(200, t('HTTP 200: Cluster | Servers')); - $this->assertText(t('Instances'), t('Found: Instances')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - } - - - public function testClusterModify() { - - $edit = array( - 'nickname_text' => 'Name testClusterModify' , - 'description_text' => 'description_ClusterModify ', - ); - - $this->drupalPost('design/cluster/create', $edit, t('Next')); - $this->assertResponse(200, t('HTTP 200: New Cluster Form | Add')); - $this->assertText( t('Cluster successfully created.'), t('Confirm Message:') . t('Cluster successfully created.')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - // Cluster | Update - $this->drupalGet('design/cluster/describe/servers/1'); - $this->assertResponse(200, t('HTTP 200: Cluster | Instances')); - $this->assertText( t('Instances'), t('Found: Instances')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - $this->drupalGet('design/cluster/describe/info/1' ); - $this->assertResponse(200, t('HTTP 200: Cluster | Servers')); - $this->assertText( t('Nickname'), t('Found: Nickname')); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - - $modify_params = array( - 'nickname_text' => 'New_Nickname' , - 'description_text' => 'New_Description', - 'cluster_id' => '1' , - ); - - $this->drupalPost('design/cluster/describe/info/1', $modify_params, t('Update')); - $this->assertResponse(200, t('HTTP 200: Cluster | Update')); - $this->assertText(t('Cluster has been updated'), t('Cluster has been updated')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - } - - - public function testClusterDelete() { - - // Cluster | Create - $edit = array( - 'nickname_text' => 'Name testClusterDelete', - 'description_text' => 'description_ClusterDelete', - ); - - $this->drupalPost('design/cluster/create', $edit, t('Next')); - $this->assertResponse(200, t('HTTP 200: New Cluster Form | Add')); - $this->assertText(t('Cluster successfully created.'), t('Confirm Message:') . t('Cluster successfully created.')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - // Cluster | Delete - $this->drupalGet('design/cluster/delete/1' ); - $this->assertResponse(200, t('HTTP 200: Cluster | Delete')); - $this->assertText(t('Cluster deleted successfully'), t('Found: Servers')); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - } -} \ No newline at end of file diff --git a/modules/cloud_cluster/cloud_cluster_constants.inc b/modules/cloud_cluster/cloud_cluster_constants.inc deleted file mode 100644 index f3e834e..0000000 --- a/modules/cloud_cluster/cloud_cluster_constants.inc +++ /dev/null @@ -1,18 +0,0 @@ -cluster_count; - } - - return $cluster_count; -} - - -function _cloud_cluster_get_cluster_by_id_query() { - - return $query = 'SELECT c.cluster_id , c.cluster_nickname, c.description, c.creator FROM {' . CLOUD_CLUSTER_TABLE . '} c WHERE cluster_id= :cluster_id '; -} - -function _cloud_cluster_get_cluster_by_filter_query() { - - return $query = 'SELECT c.cluster_id , c.cluster_nickname, c.description, c.creator FROM {' . CLOUD_CLUSTER_TABLE . '} c WHERE cluster_nickname = :cluster_nickname '; -} - -/** - * Insert a cluster in database - * This function insert entry in database and audit logs as well. - * - * @param $form_values - * This is the form-values submitted by new cluster form - * @return return a last inserted cluster-id - */ -function _cloud_cluster_save_cluster_db($form_values, $creator) { - - $nid = db_insert(CLOUD_CLUSTER_TABLE) - ->fields(array( - 'cluster_nickname' => $form_values['nickname_text' ], - 'description' => $form_values['description_text'], - 'creator' => $creator, - )) - ->execute(); - - - // User Activity Log - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => t('Cluster has been added: @cluster_name', array('@cluster_name' => $form_values['nickname_text'])), - 'link' => '', - ) - ); - - - // Get the id of newly inserted cluster - - $cluster_id = NULL; - $result = db_select(CLOUD_CLUSTER_TABLE, 'n') - ->fields('n') - ->condition('cluster_nickname', $form_values['nickname_text' ], '=') - ->condition('description', $form_values['description_text'], '=') - ->condition('creator', $creator, '=') - ->execute(); - - foreach ($result as $res_obj) { - - $cluster_id = $res_obj->cluster_id; - } - - return $cluster_id; -} - - -function _cloud_cluster_update_cluster_db($form_values, $cluster_id) { - - $num_updated = db_update(CLOUD_CLUSTER_TABLE) - ->fields(array( - 'cluster_nickname' => $form_values['nickname_text'], - 'description' => $form_values['description_text'], - )) - ->condition('cluster_id', $cluster_id, '=') - ->execute(); - - // User Activity Log - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => t('Cluster has been modified: @cluster_nickname', array('@cluster_nickname' => $form_values['nickname_text'])), - 'link' => '', - ) - ); - - return; -} - - - -/** - * Delete a Cluster using Cluster Id - * - * @param $cluster_id - * @return - */ -function _cloud_cluster_delete_by_id($cluster_id) { - - $num_deleted = db_delete(CLOUD_CLUSTER_SERVER_TABLE) - ->condition('cluster_id', $cluster_id) - ->execute(); - - $num_deleted = db_delete(CLOUD_CLUSTER_TABLE) - ->condition('cluster_id', $cluster_id) - ->execute(); - - // User Activity Log - cloud_audit_user_activity(array( - 'type' => 'user_activity', - 'message' => t('Cluster has been deleted: @cluster_id', array('@cluster_id' => $cluster_id)), - 'link' => '', - ) - ); - - return TRUE; -} - - -/** - * Return all cluster list - * - * @param $cloud - * @return - */ -function _cloud_cluster_get_all_clusters_query($cloud) { - - return ' select * from {' . CLOUD_CLUSTER_TABLE . '} '; -} - - -// End : DB functions Related to Cluster - - diff --git a/modules/cloud_cluster/cloud_cluster_server_db.inc b/modules/cloud_cluster/cloud_cluster_server_db.inc deleted file mode 100644 index f00e536..0000000 --- a/modules/cloud_cluster/cloud_cluster_server_db.inc +++ /dev/null @@ -1,244 +0,0 @@ -fields(array( - 'cluster_id' => $cluster_id, - 'template_id' => $form_values['template_select' ], - 'server_nickname' => $form_values['nickname_text' ], - 'server_sshkey' => $form_values['ssh_keys_select' ], - 'server_security_group' => @implode(',', $form_values['SG_select'] ), - 'server_zone' => $form_values['zone_select' ], - 'failover_flag' => $failover_select == FALSE ? 0 : $failover_select, - 'elastic_ip' => $ip_select, - )) - ->execute(); - - if ($failover_select) { - $server_id = _cloud_cluster_get_last_added_server_db($form_values); - _cloud_failover_save_server_scenario( $server_id, $form_values['failover_scenario_select']); - } - - // User Activity Log - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => t('Cluster Server has been added: @cluster_name', array('@cluster_name' => $form_values['nickname_text'])), - 'link' => '', - ) - ); - - return; -} - - -function _cloud_cluster_save_cluster_template_db($values) { - - $nid = db_insert(CLOUD_CLUSTER_SERVER_TABLE) // Table name no longer needs {} - ->fields(array( - 'cluster_id' => $values['cluster_id' ], - 'template_id' => $values['template_select' ], - 'server_nickname' => $values['nickname_text' ], - 'server_sshkey' => $values['ssh_keys_select' ], - 'server_security_group' => $values['SG_select' ], - 'server_zone' => $values['zone_select' ], - 'failover_flag' => $values['failover_select' ], - 'elastic_ip' => '', - 'instance_id' => $values['instance_id' ], - )) - ->execute(); - - return; -} - - -function _cloud_cluster_servers_get_query() { - - $query = db_select(CLOUD_CLUSTER_SERVER_TABLE, 'e') - ->fields('e'); - - return $query; -} - - -function _cloud_cluster_server_get_query() { - - return $query = ' select * from - {' . CLOUD_CLUSTER_SERVER_TABLE . '} e WHERE e.cluster_id=:cluster_id and e.server_id=:server_id '; -} - - -function _cloud_cluster_templates_get_query() { - - return $query = ' select e.instance_id, e.server_nickname as server_nickname , tmpl.cloud_type as cloud_type, tmpl.template_nickname as template_nickname , e.cluster_id, tmpl.template_id as template_id, e.template_id, e.server_id , tmpl.count_instances from - {' . CLOUD_CLUSTER_SERVER_TABLE . '} e - LEFT JOIN {' . CLOUD_SERVER_TEMPLATES_TABLE . '} tmpl - on e.template_id = tmpl.template_id - WHERE e.cluster_id=:cluster_id '; -} - -function _cloud_cluster_templates_server_get_query() { - - return $query = ' select e.instance_id, e.server_nickname as server_nickname , tmpl.cloud_type as cloud_type, tmpl.template_nickname as template_nickname , e.cluster_id, tmpl.template_id as template_id, e.template_id, e.server_id , tmpl.count_instances from - {' . CLOUD_CLUSTER_SERVER_TABLE . '} e - LEFT JOIN {' . CLOUD_SERVER_TEMPLATES_TABLE . '} tmpl - on e.template_id = tmpl.template_id - WHERE e.cluster_id=:cluster_id and e.server_id=:server_id '; -} - -function _cloud_cluster_servers_get_count_db($cluster_id) { - - $query = ' select count(*) cnt from - {' . CLOUD_CLUSTER_SERVER_TABLE . '} e WHERE e.cluster_id=:cluster_id '; - - $query_args = array( - ':cluster_id' => $cluster_id, - ); - - $result = db_query( $query, $query_args ); - - foreach ($result as $cnt_res) { // Cluster server object - return $cnt_res->cnt; - } - - return 0; -} - - -function _cloud_cluster_get_server_query() { - - $query = 'select * from {' . CLOUD_CLUSTER_SERVER_TABLE . '} - where server_id=:server_id - '; - - return $query; -} - - -function _cloud_cluster_get_last_added_server_db($form_values) { - - $query = 'SELECT * FROM {' . CLOUD_CLUSTER_SERVER_TABLE . "} c WHERE cluster_id= :cluster_id and template_id= :template_id and server_nickname= :server_nickname - ORDER BY server_id DESC LIMIT 1 "; - $query_args = array( - ':cluster_id' => $form_values['cluster_id'], - ':template_id' => $form_values['template_select'], - ':server_nickname' => $form_values['nickname_text' ], - ); - - $result = db_query( $query, $query_args ); - - - foreach ($result as $key) { - - return $key->server_id; - } - -} - - -function _cloud_cluster_delete_server_db($server_id) { - - $num_deleted = db_delete(CLOUD_CLUSTER_SERVER_TABLE) - ->condition('server_id', $server_id) - ->execute(); - - if (module_exists('cloud_inputs')) { - - $num_deleted = db_delete(CLOUD_INPUTS_PARAMETER_VALUES_TABLE) - ->condition('server_id', $server_id) - ->execute(); - } - - // User Activity Log - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => 'Cluster Server has been deleted.', - 'link' => '', - ) - ); - - return; -} - - -function _cloud_cluster_delete_all_server_db($cluster_id) { - - $num_deleted = db_delete(CLOUD_CLUSTER_SERVER_TABLE) - ->condition('cluster_id', $cluster_id) - ->execute(); - - if (module_exists('cloud_inputs')) { - $num_deleted = db_delete(CLOUD_INPUTS_PARAMETER_VALUES_TABLE) - ->condition('cluster_id', $cluster_id) - ->execute(); - } - - // User Activity Log - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => 'Cluster Servers have been deleted.', - 'link' => '', - ) - ); - - return; -} - - -function _cloud_cluster_update_cluster_server_query($instance_id, $server_id) { - - - $num_updated = db_update(CLOUD_CLUSTER_SERVER_TABLE) - ->fields(array( - 'instance_id' => $instance_id, - )) - ->condition('server_id', $server_id, '=') - ->execute(); - - // User Activity Log - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => 'Cluster server has been modified.', - 'link' => '', - ) - ); - - - return; -} - -/** - * Get server information based on instance id - */ -function cloud_cluster_get_server($instance_id) { - $result = db_select(CLOUD_CLUSTER_SERVER_TABLE, 'c') - ->fields('c') - ->condition('instance_id', $instance_id, '=') - ->execute() - ->fetchAssoc(); - - return $result; -} - -// End : DB functions Related to Cluster_server diff --git a/modules/cloud_cluster/src/CloudClusterInterface.php b/modules/cloud_cluster/src/CloudClusterInterface.php deleted file mode 100644 index 6091fbe..0000000 --- a/modules/cloud_cluster/src/CloudClusterInterface.php +++ /dev/null @@ -1,36 +0,0 @@ -loadInclude('cloud', 'inc', 'cloud.constants'); -/** - * - */ -class CloudClustersController { - -} diff --git a/modules/cloud_cluster/src/Controller/CloudClusterListController.php b/modules/cloud_cluster/src/Controller/CloudClusterListController.php deleted file mode 100644 index fa1f497..0000000 --- a/modules/cloud_cluster/src/Controller/CloudClusterListController.php +++ /dev/null @@ -1,55 +0,0 @@ - t('Name'), 'specifier' => 'name', 'sort' => 'ASC'], - ['data' => t('Description'), 'specifier' => 'description'], - ]; - - return $header + parent::buildHeader(); - } - - /** - * {@inheritdoc} - */ - public function buildRow(EntityInterface $entity) { - - // For debug - // $row['id'] = $entity->id(); - // $row['uuid'] = $entity->uuid(); - $row['name'] = \Drupal::l( - $this->getLabel($entity), - new Url( - 'entity.cloud_cluster.canonical', [ - 'cloud_cluster' => $entity->id(), - ] - ) - ); - $row['description'] = $entity->description(); - - return $row + parent::buildRow($entity); - - } - -} diff --git a/modules/cloud_cluster/src/Entity/CloudCluster.php b/modules/cloud_cluster/src/Entity/CloudCluster.php deleted file mode 100644 index 5f706d3..0000000 --- a/modules/cloud_cluster/src/Entity/CloudCluster.php +++ /dev/null @@ -1,204 +0,0 @@ - \Drupal::currentUser()->id(), - ]; - } - - /** - * {@inheritdoc} - */ - public function description() { - return $this->get('description')->value; - } - - /** - * {@inheritdoc} - */ - public function created() { - return $this->get('created')->value; - } - - /** - * {@inheritdoc} - */ - public function changed() { - return $this->get('changed')->value; - } - - /** - * {@inheritdoc} - */ - public function getOwner() { - return $this->get('user_id')->entity; - } - - /** - * {@inheritdoc} - */ - public function getOwnerId() { - return $this->get('user_id')->target_id; - } - - /** - * {@inheritdoc} - */ - public function setOwnerId($uid) { - $this->set('user_id', $uid); - return $this; - } - - /** - * {@inheritdoc} - */ - public function setOwner(UserInterface $account) { - $this->set('user_id', $account->id()); - return $this; - } - - /** - * The comment language code. - */ - public function langcode() { - return $this->get('langcode'); - } - - /** - * {@inheritdoc} - */ - public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - - $fields['id'] = BaseFieldDefinition::create('integer') - ->setLabel(t('ID')) - ->setDescription(t('The ID of the Cloud Cluster entity.')) - ->setReadOnly(TRUE); - - $fields['uuid'] = BaseFieldDefinition::create('uuid') - ->setLabel(t('UUID')) - ->setDescription(t('The UUID of the Cloud Cluster entity.')) - ->setReadOnly(TRUE); - - $fields['user_id'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Authored by')) - ->setDescription(t('The user ID of the CloudCluster entity author.')) - ->setRevisionable(TRUE) - ->setSetting('target_type', 'user') - ->setSetting('handler', 'default') - ->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId') - ->setTranslatable(TRUE) - ->setDisplayOptions('view', [ - 'label' => 'hidden', - 'type' => 'author', - 'weight' => 0, - ]) - ->setDisplayOptions('form', [ - 'type' => 'entity_reference_autocomplete', - 'weight' => 5, - 'settings' => [ - 'match_operator' => 'CONTAINS', - 'size' => '60', - 'autocomplete_type' => 'tags', - 'placeholder' => '', - ], - ]) - ->setDisplayConfigurable('form', TRUE) - ->setDisplayConfigurable('view', TRUE); - - $fields['name'] = BaseFieldDefinition::create('string') - ->setLabel(t('Name')) - ->setDescription(t('The name of the cloud cluster entity.')) - ->setSettings([ - 'default_value' => '', - 'max_length' => 255, - 'text_processing' => 0, - ]) - ->setDisplayOptions('view', [ - 'label' => 'above', - 'type' => 'string', - 'weight' => -5, - ]) - /* - ->setDisplayOptions('form', array( - 'type' => 'string_textfield', - 'weight' => -6, - )) - */ - ->setDisplayConfigurable('form', TRUE) - ->setDisplayConfigurable('view', TRUE) - ->setRequired(TRUE); - - $fields['description'] = BaseFieldDefinition::create('string') - ->setLabel(t('Description')) - ->setDescription(t('Script Description.')); - - $fields['langcode'] = BaseFieldDefinition::create('language') - ->setLabel(t('Language code')) - ->setDescription(t('The language code of CloudCluster entity.')); - - $fields['created'] = BaseFieldDefinition::create('created') - ->setLabel(t('Created')) - ->setDescription(t('The time that the entity was created.')); - - $fields['changed'] = BaseFieldDefinition::create('changed') - ->setLabel(t('Changed')) - ->setDescription(t('The time that the entity was last edited.')); - - return $fields; - } - -} diff --git a/modules/cloud_cluster/src/Entity/CloudClusterViewsData.php b/modules/cloud_cluster/src/Entity/CloudClusterViewsData.php deleted file mode 100644 index 971bcc1..0000000 --- a/modules/cloud_cluster/src/Entity/CloudClusterViewsData.php +++ /dev/null @@ -1,29 +0,0 @@ - 'id', - 'title' => t('Cloud Cluster'), - 'help' => t('The cloud_cluster entity ID.'), - ]; - - return $data; - } - -} diff --git a/modules/cloud_cluster/src/Form/CloudClusterDeleteForm.php b/modules/cloud_cluster/src/Form/CloudClusterDeleteForm.php deleted file mode 100644 index 5851eb3..0000000 --- a/modules/cloud_cluster/src/Form/CloudClusterDeleteForm.php +++ /dev/null @@ -1,16 +0,0 @@ -entity; - - $form['name'] = [ - '#type' => 'textfield', - '#title' => $this->t('Name'), - '#maxlength' => 255, - '#size' => 60, - '#default_value' => $entity->label(), - '#required' => TRUE, - '#weight' => -5, - ]; - - $form['description'] = [ - '#type' => 'textarea', - '#title' => $this->t('Description'), - '#cols' => 60, - '#rows' => 3, - '#default_value' => $entity->description(), - '#weight' => -5, - '#required' => FALSE, - ]; - - $form['langcode'] = [ - '#title' => t('Language'), - '#type' => 'language_select', - '#default_value' => $entity->getUntranslated()->language()->getId(), - '#languages' => Language::STATE_ALL, - ]; - - $form['actions'] = $this->actions($form, $form_state); - - return $form; - } - -} diff --git a/modules/cloud_cluster/src/Form/CloudClusterSettingsForm.php b/modules/cloud_cluster/src/Form/CloudClusterSettingsForm.php deleted file mode 100644 index 7af9ba7..0000000 --- a/modules/cloud_cluster/src/Form/CloudClusterSettingsForm.php +++ /dev/null @@ -1,56 +0,0 @@ -drupalCreateUser([ - 'add cloud cluster', - 'list cloud cluster', - 'view cloud cluster', - 'edit cloud cluster', - 'delete cloud cluster', - ]); - $this->drupalLogin($web_user); - } - - /** - * Tests CRUD for cloud_cluster information. - */ - public function testCloudCluster() { - - // Access to Cloud Cluster Menu - // $clouds = $this->getClouds(); - // foreach ($clouds as $cloud) {. - $cloud_context = 'default_cloud_context'; - - // List Cloud Cluster for AWS. - $this->drupalGet("/clouds/design/cloud_cluster"); - $this->assertResponse(200, t('HTTP 200: List | Cloud Cluster')); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - - // Add a new cloud_cluster information. - $add = $this->createCloudClusterTestData(); - for ($i = 0; $i < CLOUD_CLUSTER_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $this->drupalPostForm("/clouds/design/cloud_cluster/add", - $add[$i], - t('Save')); - $this->assertResponse(200, t('HTTP 200: Add | A New Cloud Cluster Form #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - $this->assertText(t('The Cloud Cluster entity "@name" has been saved.', [ - '@name' => $add[$i]['name'], - ]), - t('Confirm Message') . ': ' - . t('The Cloud Cluster entity "@name" has been saved.', [ - '@name' => $add[$i]['name'], - ]) - ); - $this->assertText($add[$i]['name'], - t('Name: @name ', [ - '@name' => $add[$i]['name'], - ])); - - // Make sure listing. - $this->drupalGet("/clouds/design/cloud_cluster"); - $this->assertResponse(200, t('HTTP 200: List | Cloud Cluster #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertText($add[$j]['name'], - t("Make sure w/ Listing @num: @name", [ - '@num' => $j + 1, - '@name' => $add[$j]['name'], - ])); - } - } - - // Edit case. - $edit = $this->createCloudClusterTestData(); - // 3 times. - for ($i = 0; $i < CLOUD_CLUSTER_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $this->drupalPostForm("/clouds/design/cloud_cluster/$num/edit", - $edit[$i], - t('Save')); - $this->assertResponse(200, t('HTTP 200: Edit | A New Cloud Cluster Form #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - $this->assertText(t('The Cloud Cluster entity "@name" has been saved.', [ - '@name' => $edit[$i]['name'], - ]), - t('Confirm Message') . ': ' - . t('The Cloud Cluster entity "@name" has been saved.', [ - '@name' => $edit[$i]['name'], - ]) - ); - $this->assertText($edit[$i]['name'], t('Name: @name ', [ - '@name' => $edit[$i]['name'], - ])); - - // Make sure listing. - $this->drupalGet("/clouds/design/cloud_cluster"); - $this->assertResponse(200, t('HTTP 200: List | Cloud Cluster #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertText($edit[$j]['name'], - t("Make sure w/ Listing @num: @name", [ - '@num' => $j + 1, - '@name' => $edit[$j]['name'], - ])); - } - } - - // Delete cloud_cluster Items. - for ($i = 0; $i < CLOUD_CLUSTER_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $this->drupalGet("/clouds/design/cloud_cluster/$num/delete"); - $this->drupalPostForm("/clouds/design/cloud_cluster/$num/delete", - [], - t('Delete')); - $this->assertResponse(200, t('HTTP 200: Delete | Cloud Cluster #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - // Make sure listing. - $this->drupalGet("/clouds/design/cloud_cluster"); - $this->assertResponse(200, t('HTTP 200: Delete | Cloud Cluster #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertNoText($edit[$j]['name'], - t("Make sure w/ Listing @num: @name", [ - '@num' => $j + 1, - '@name' => $edit[$j]['name'], - ])); - } - } - - // Filtering cloud_cluster information item - /* - $filter = array( - 'filter' => 't1', - 'operation' => 0, - ); - - $this->drupalPost("/clouds/design/cloud_cluster", $filter, t('Apply')); - $this->assertResponse(200, t('HTTP 200: Search Listings | Filter')); - $cloud_cluster_id = CLOUD_CLUSTER_REPEAT_COUNT - 1 ; - $this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large'); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - */ - // end - // } // End of foreach. - } - - /** - * - */ - private function createCloudClusterTestData() { - - static $random; - if (!$random) { - $random = new Random(); - } - - // 3 times. - for ($i = 0; $i < CLOUD_CLUSTER_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - // Input Fields. - $data[] = [ - // 'cloud_context' => $cloud_context ,. - 'name' => "Cloud Cluster #$num - " . date('Y/m/d - ') . $random->name(16, TRUE), - 'description' => "#$num: " . date('Y/m/d H:i:s - D M j G:i:s T Y') - . ' - SimpleTest Cloud Cluster Description - ' - . $random->string(32, TRUE), - ]; - } - - return $data; - } - -} diff --git a/modules/cloud_cluster/templates/cloud_cluster.html.twig b/modules/cloud_cluster/templates/cloud_cluster.html.twig deleted file mode 100644 index 08a9c8e..0000000 --- a/modules/cloud_cluster/templates/cloud_cluster.html.twig +++ /dev/null @@ -1,22 +0,0 @@ -{# -/** - * @file cloud_cluster.html.twig - * Default theme implementation to present CloudCluster data. - * - * This template is used when viewing a cloud_cluster entity's page, - * - * - * Available variables: - * - content: A list of content items. Use 'content' to print all content, or - * - attributes: HTML attributes for the container element. - * - * @see template_preprocess_cloud_cluster() - * - * @ingroup themeable - */ -#} - - {% if content %} - {{- content -}} - {% endif %} - diff --git a/modules/cloud_pricing/README.txt b/modules/cloud_pricing/README.txt deleted file mode 100644 index 2208868..0000000 --- a/modules/cloud_pricing/README.txt +++ /dev/null @@ -1,47 +0,0 @@ -BASIC INFO -========== - -- Provides pricing for hourly rate configuration for Billing module. -- You can set up pricing -- Works with Cloud and Billing module. - - -HOW TO USE -========== - -1) Enable Pricing module -2) Go to the menu: Administer | Site configuration | Amazon EC2, OpenStack or Eucalyptus -3) Click 'Pricing Info tab' -4) Click 'New Pricing' to add a new pricing item -5) or edit the existing predefined pricing item(s) - - -DIRECTORY STRUCTURE -=================== - -cloud - +-modules (depends on Cloud module) (Cloud is a core module for Cloud package) - x-cloud_activity_audit - x-cloud_alerts - x-cloud_auto_scaling - x-cloud_billing - x-cloud_cluster - x-cloud_dashboard - x-cloud_failover - x-cloud_inputs - x-cloud_metering - o-cloud_pricing - x-cloud_resource_allocator - x-cloud_scaling_manager - x-cloud_scripting - +-cloud_server_templates - - x... Not released yet. - - -CHANGE HISTORY -============== -2015/xx/xx 8.x-1.x-dev released - - -End of README.txt \ No newline at end of file diff --git a/modules/cloud_pricing/cloud_pricing.constants.inc b/modules/cloud_pricing/cloud_pricing.constants.inc deleted file mode 100644 index be57a7f..0000000 --- a/modules/cloud_pricing/cloud_pricing.constants.inc +++ /dev/null @@ -1,15 +0,0 @@ -condition('id', $id); - - $result = $query->execute(); - $count = 0; - $pricing_obj = $result->fetchObject(); - - // User Activity Log - cloud_audit_user_activity( - array( - 'type' => 'user_activity', - 'message' => t('Pricing has been deleted: @pricing', array('@pricing' => $pricing_obj->instance_type)), - 'link' => '', - ) - ); - - $query = db_delete(CLOUD_PRICING_INSTANCES_TABLE) - ->condition('id', $id) - ->execute(); -} - -/** - * Insert a pricing in database - * This function insert entry in database and audit logs as well. - * - * @param $form_values - * This is the form-values submitted by new pricing form - * @return return a last inserted pricing-id - */ -function _cloud_pricing_insert($form_values) { - - $insert_query_instance = db_insert(CLOUD_SERVER_TEMPLATES_INSTANCE_TYPE_TABLE) - ->fields(array( - 'instance_type' => $form_values['instance_type_select' ], - 'description' => $form_values['description_text' ], - 'cloud_type' => (!empty($form_values['cloud_context']) - ? $form_values['cloud_context'] : ''), - )) - ->execute(); - - $insert_query = db_insert(CLOUD_PRICING_INSTANCES_TABLE) - ->fields(array( - 'instance_type' => $form_values['instance_type_select' ], - 'description' => $form_values['description_text' ], - 'linux_usage' => $form_values['linux_usage_text' ], - 'windows_usage' => $form_values['windows_usage_text' ], - 'cloud_type' => (!empty($form_values['cloud_context'] ) - ? $form_values['cloud_context'] - : '' ), - 'created' => date('c'), - 'updated' => date('c'), - )) - ->execute(); - - // User Activity Log - cloud_audit_user_activity( - array( - 'type' => 'user_activity', - 'message' => t('New Pricing has been added: @pricing', - array('@pricing' => $form_values['instance_type_select'])), - 'link' => '', - ) - ); - - return; -} - -/** - * Update a price in the database - */ -function _cloud_pricing_update($form_values, $pricing_id = '') { - - $query_args = array(); - - $update_query_instance = db_update(CLOUD_SERVER_TEMPLATES_INSTANCE_TYPE_TABLE) - ->fields(array( - 'instance_type' => $form_values['instance_type_select' ], - )) - ->condition('instance_type', $form_values['instance_type_old']) - ->execute(); - - $query_args = array(); - - $update_query = db_update(CLOUD_PRICING_INSTANCES_TABLE) - ->fields(array( - 'instance_type' => $form_values['instance_type_select' ], - 'description' => $form_values['description_text' ], - 'linux_usage' => $form_values['linux_usage_text' ], - 'windows_usage' => $form_values['windows_usage_text' ], - 'cloud_type' => (!empty( $form_values['cloud_context'] ) - ? $form_values['cloud_context'] - : '' ), - 'updated' => date('c'), - )) - ->condition('id', $pricing_id) - ->execute(); - - cloud_audit_user_activity( - array( - 'type' => 'user_activity', - 'message' => t('Pricing has been modified: @pricing', array('@pricing' => $pricing_id)), - 'link' => '', - ) - ); - - return; -} - -/** - * Delete pricing data from the database - */ -function cloud_pricing_delete_data($cloud_context) { - - $query = db_delete(CLOUD_PRICING_INSTANCES_TABLE) - ->condition('cloud_type', $cloud_context) - ->execute(); -} - - -/** - * Delete all pricing data - */ -function cloud_pricing_delete_all_data() { - - $query = db_delete(CLOUD_PRICING_INSTANCES_TABLE) - ->execute(); -} - -/** - * Get pricing by id - */ -function _cloud_pricing_get_by_id($cloud_context, $instance_type) { - - $query_args = array(); - $query = db_select(CLOUD_PRICING_INSTANCES_TABLE, 'a'); - - $result = $query - ->fields('a') - ->condition('instance_type', $instance_type) - ->condition('cloud_type' , $cloud_context) - ->execute(); - - $pricing_info = array(); - - foreach ($result as $pricing_obj) { - $pricing_info['instance_type'] = $pricing_obj->instance_type; - $pricing_info['cloud_type' ] = $pricing_obj->cloud_type; - $pricing_info['linux_usage' ] = $pricing_obj->linux_usage; - } - - return $pricing_info; -} diff --git a/modules/cloud_pricing/cloud_pricing.info.yml b/modules/cloud_pricing/cloud_pricing.info.yml deleted file mode 100644 index 76ab602..0000000 --- a/modules/cloud_pricing/cloud_pricing.info.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: Cloud Pricing -description: 'Get a pricing details of instances.' -package: Cloud -dependencies: - - cloud -core: 8.x -version: 8.x-1.x -project: cloud -type: module diff --git a/modules/cloud_pricing/cloud_pricing.install b/modules/cloud_pricing/cloud_pricing.install deleted file mode 100644 index 5c91505..0000000 --- a/modules/cloud_pricing/cloud_pricing.install +++ /dev/null @@ -1,125 +0,0 @@ -loadInclude('cloud' , 'inc', 'cloud.constants' ); -//\Drupal::moduleHandler()->loadInclude('cloud_pricing', 'inc', 'cloud_pricing.constants'); -//\Drupal::moduleHandler()->loadInclude('cloud_pricing', 'inc', 'cloud_pricing.db' ); - -/** - * Implements hook_install(). - */ -function cloud_pricing_install() { - - // Create tables. -} - -/** - * Implements hook_uninstall(). - */ -function cloud_pricing_uninstall() { - // Remove tables. -} - -/** - * Implementation of hook_schema(). - */ - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -function cloud_pricing_schema() { -/* - \Drupal::moduleHandler()->load('cloud'); - - $schema = array(); - - $schema[CLOUD_PRICING_INSTANCES_TABLE] = array( - 'description' => 'Instances Auto-scaling', - 'fields' => array( - 'id' => array( - 'type' => 'serial' , - 'length' => 11, - ), - 'cloud_type' => array( - 'type' => 'varchar', - 'length' => 255, - ), - 'instance_type' => array( - 'type' => 'varchar', - 'length' => 255, - ), - 'linux_usage' => array( - 'type' => 'float' , - 'default' => 0, - ), - 'windows_usage' => array( - 'type' => 'float' , - 'default' => 0, - ), - 'description' => array('type' => 'text'), - 'created' => array('type' => 'text'), - 'updated' => array('type' => 'text'), - ), - 'primary key' => array('id'), - ); - - // To add more schema just add one more $schema['newtable'] array. - return $schema; -*/ -} - -/** - * Implements hook_enable(). - * - * Update entries from the already enabled clouds - */ -function cloud_pricing_enable() { - -// \Drupal::moduleHandler()->load('cloud'); -// // Check for the Cloud information and update the Pricing info accordingly -// $cloud_list = cloud_get_all_clouds(); -// foreach ($cloud_list as $cloud_context ) { -// -// $module = cloud_get_module($cloud_context); -// //new way to call cloud_set_info -// drupal_load('module', $module); -// $params = \Drupal::moduleHandler()->invoke($module, 'cloud_set_info', [$cloud_context]); -// -// $pricing_data = empty($params['cloud_pricing_data'] ) -// ? array() -// : $params['cloud_pricing_data']; -// -// foreach ($pricing_data as $key => $data) { -// -// $data_values = array(); -// $data_values['instance_type_select'] = $data['instance_type' ]; -// $data_values['description_text' ] = $data['description' ]; -// $data_values['linux_usage_text' ] = $data['linux_or_unix_cost']; -// $data_values['windows_usage_text' ] = $data['windows_cost' ]; -// $data_values['cloud_context' ] = $cloud_context ; -// -// // Insert the data in the Pricing table -// _cloud_pricing_insert($data_values); -// } -// } -} - - -/** - * Implements hook_disable(). - * - * Delete entries from the enabled clouds - */ -function cloud_pricing_disable() { - -// \Drupal::moduleHandler()->load('cloud'); -// cloud_pricing_delete_all_data(); -} diff --git a/modules/cloud_pricing/cloud_pricing.links.action.yml b/modules/cloud_pricing/cloud_pricing.links.action.yml deleted file mode 100644 index 63ff89b..0000000 --- a/modules/cloud_pricing/cloud_pricing.links.action.yml +++ /dev/null @@ -1,13 +0,0 @@ -entity.cloud_pricing.add_form: - route_name: 'entity.cloud_pricing.add_form' - title: 'Add Pricing Information' - appears_on: - - entity.cloud_pricing.collection - -entity.cloud_pricing.collection: - route_name: entity.cloud_pricing.collection - title: 'List Pricing Information' - appears_on: - - entity.cloud_pricing.add_form - - entity.cloud_pricing.edit_form - - entity.cloud_pricing.delete_form \ No newline at end of file diff --git a/modules/cloud_pricing/cloud_pricing.links.menu.yml b/modules/cloud_pricing/cloud_pricing.links.menu.yml deleted file mode 100644 index c97176c..0000000 --- a/modules/cloud_pricing/cloud_pricing.links.menu.yml +++ /dev/null @@ -1,6 +0,0 @@ -# MENU_NORMAL_ITEM -# cloud.pricing.getList: -# title: 'Pricing Info' -# route_name: 'cloud.pricing.getList' -# parent_id: 'cloud.pricing.getList' -# weight: 1 diff --git a/modules/cloud_pricing/cloud_pricing.links.task.yml b/modules/cloud_pricing/cloud_pricing.links.task.yml deleted file mode 100644 index b98a1ca..0000000 --- a/modules/cloud_pricing/cloud_pricing.links.task.yml +++ /dev/null @@ -1,4 +0,0 @@ -entity.cloud_pricing.collection: - title: 'Cloud Pricing Configuration' - route_name: entity.cloud_pricing.collection - base_route: entity.cloud_pricing.collection diff --git a/modules/cloud_pricing/cloud_pricing.module b/modules/cloud_pricing/cloud_pricing.module deleted file mode 100644 index e6fe5d0..0000000 --- a/modules/cloud_pricing/cloud_pricing.module +++ /dev/null @@ -1,102 +0,0 @@ -loadInclude('cloud' , 'inc', 'cloud.constants' ); -\Drupal::moduleHandler()->loadInclude('cloud_pricing', 'inc', 'cloud_pricing.constants'); -\Drupal::moduleHandler()->loadInclude('cloud_pricing', 'inc', 'cloud_pricing' ); -\Drupal::moduleHandler()->loadInclude('cloud_pricing', 'inc', 'cloud_pricing.db' ); - -/** - * Implements hook_help(). - */ -function cloud_pricing_help($route_name, RouteMatchInterface $route_match) { - - switch ($route_name) { - - case 'help.page.cloud_pricing': - $output = '

' . t('The cloud module creates a user interface for users to manage clouds. Users can Create Instances, Describe Instances etc..') . '

'; - - return $output; - } -} - - -/** - * Permission callback function to concatenate the - * access type based on clouds - */ -function cloud_pricing_access($cloud_context, $access) { - - $access = \Drupal::currentUser()->hasPermission($cloud_context . ' ' . $access); - - return $access; -} - -/** - * Implements hook_permission(). - */ -/* -function cloud_pricing_permission() { - - return array( - 'create pricing' => array( - 'title' => t('create pricing'), - 'description' => t('Permission to create pricing'), - ), - 'list pricing' => array( - 'title' => t('list pricing'), - 'description' => t('Permission to view pricing'), - ), - 'edit pricing' => array( - 'title' => t('edit pricing'), - 'description' => t('Permission to edit pricing'), - ), - 'delete pricing' => array( - 'title' => t('delete pricing'), - 'description' => t('Permission to delete pricing'), - ), - ); -} -*/ - -/** - * Implements hook_cloud_save(). - * Store any cloud_pricing data - */ -function cloud_pricing_cloud_save($op, $cloud) { - if ($op == 'create') { - if (isset($cloud->cloud_pricing_data)) { - $pricing_data = &$cloud->cloud_pricing_data; - $cloud_type = $cloud->cloud_name; - foreach ($pricing_data as $key => $data) { - $data_values = array( - 'instance_type_select' => $data['instance_type' ] , - 'description_text' => isset($data['description' ] ) - ? $data['description'] : '' , - 'linux_usage_text' => $data['linux_or_unix_cost'] , - 'windows_usage_text' => $data['windows_cost' ] , - 'cloud_context' => $cloud_type , - ); - // Insert the data in the Pricing table - _cloud_pricing_insert($data_values); - } - } - } -} - -/** - * Implements hook_cloud_delete(). - * Delete the pricing data upon cloud delete - */ -function cloud_pricing_cloud_delete($cloud_name) { - - cloud_pricing_delete_data($cloud_name); -} - diff --git a/modules/cloud_pricing/cloud_pricing.permissions.yml b/modules/cloud_pricing/cloud_pricing.permissions.yml deleted file mode 100644 index d5b893c..0000000 --- a/modules/cloud_pricing/cloud_pricing.permissions.yml +++ /dev/null @@ -1,21 +0,0 @@ -# updated by yas 2016/05/25 - -add cloud pricing: - title: 'Add cloud pricing' - description: 'Allow to add cloud pricing' - -list cloud pricing: - title: 'List cloud pricing' - description: 'Allow access to list cloud pricing' - -view cloud pricing: - title: 'View cloud pricing' - description: 'Allow to view cloud pricing' - -edit cloud pricing: - title: 'Edit cloud pricing' - description: 'Allow to edit cloud pricing' - -delete cloud pricing: - title: 'Delete cloud pricing' - description: 'Allow to delete cloud pricing' diff --git a/modules/cloud_pricing/cloud_pricing.routing.yml b/modules/cloud_pricing/cloud_pricing.routing.yml deleted file mode 100644 index afcec51..0000000 --- a/modules/cloud_pricing/cloud_pricing.routing.yml +++ /dev/null @@ -1,130 +0,0 @@ -# MENU_LOCAL_TASK -# cloud.pricing.getList: -# path: 'admin/config/clouds/{cloud_context}/pricing' -# defaults: -# _form: '\Drupal\cloud_pricing\Form\CloudPricingListForm' -# _title: 'Pricing Info' -# requirements: -# _permission: 'list pricing' -# -# # MENU_CALLBACK -# cloud.pricing.create: -# path: 'admin/config/clouds/{cloud_context}/pricing/create' -# defaults: -# _form: '\Drupal\cloud_pricing\Form\CloudPricingCreateForm' -# _title: 'Add/Edit Pricing' -# requirements: -# _permission: 'create pricing' -# -# # MENU_CALLBACK -# cloud.pricing.edit: -# path: 'admin/config/clouds/{cloud_context}/pricing/{pricing_id}/edit' -# defaults: -# _form: '\Drupal\cloud_pricing\Form\CloudPricingCreateForm' -# _title: 'Add/Edit Pricing' -# requirements: -# _permission: 'edit pricing' -# -# # MENU_CALLBACK -# cloud.pricing.getData: -# path: 'admin/config/clouds/{cloud_context}/pricing/getdata' -# defaults: -# _controller: '\Drupal\cloud_pricing\Controller\CloudPricingController::getData' -# _title: 'Get Pricing Data' -# requirements: -# _permission: 'list pricing' -# -# # MENU_CALLBACK -# cloud.pricing.delete: -# path: 'admin/config/clouds/{cloud_context}/pricing/{pricing_id}/delete' -# defaults: -# _controller: '\Drupal\cloud_pricing\Controller\CloudPricingController::delete' -# _title: 'Delete' -# requirements: -# _permission: 'delete pricing' - -# $items['admin/config/clouds/%/pricing/create'] = array( -# 'title' => 'Add/Edit Pricing', -# 'page callback' => 'drupal_get_form', -# 'page arguments' => array('cloud_pricing_create', '', 3), -# 'access arguments' => array('create pricing'), -# 'type' => MENU_CALLBACK, -# ); -# -# $items['admin/config/clouds/%/pricing/%/edit'] = array( -# 'title' => 'Add/Edit Pricing', -# 'page callback' => 'drupal_get_form', -# 'page arguments' => array('cloud_pricing_create', 5, 3), -# 'access arguments' => array('create pricing'), -# 'type' => MENU_CALLBACK, -# ); -# -# $items['admin/config/clouds/%/pricing/%/delete'] = array( -# 'title' => 'Delete', -# 'page callback' => 'cloud_pricing_delete', -# 'page arguments' => array(5, 3), -# 'access arguments' => array('list pricing'), -# 'type' => MENU_CALLBACK, -# ); -# -# $items['admin/config/pricing/getdata'] = array( -# 'title' => 'pricing Get data', -# 'page callback' => '_cloud_pricing_getdata', -# 'page arguments' => array('Pricing'), -# 'access arguments' => array('list pricing'), -# 'type' => MENU_CALLBACK, -# ); -# $items['admin/config/clouds/%/pricing'] = array( -# 'title' => 'Pricing Info', -# 'description' => 'Pricing Info', -# 'page callback' => 'drupal_get_form', -# 'page arguments' => array('cloud_pricing_list', 3), -# 'access arguments' => array(3, 'administer cloud'), -# 'access callback' => 'cloud_pricing_access', -# 'weight' => 1, -# 'type' => MENU_LOCAL_TASK, -# ); -# -# return $items; -# } - -# CloudPricing routing definition -entity.cloud_pricing.collection: - path: '/admin/config/cloud/{cloud_context}/pricing' - defaults: - _entity_list: 'cloud_pricing' - _title: 'Cloud Pricing Configuration' - requirements: - _permission: 'list cloud pricing' - -entity.cloud_pricing.add_form: - path: '/admin/config/cloud/{cloud_context}/pricing/add' - defaults: - _entity_form: 'cloud_pricing.add' - _title: 'Add Cloud Pricing' - requirements: - _permission: 'add cloud pricing' - -entity.cloud_pricing.edit_form: - path: '/admin/config/cloud/{cloud_context}/pricing/{cloud_pricing}' - defaults: - _entity_form: 'cloud_pricing.edit' - _title: 'Edit Cloud Pricing' - requirements: - _permission: 'edit cloud pricing' - -entity.cloud_pricing.edit_form.edit: - path: '/admin/config/cloud/{cloud_context}/pricing/{cloud_pricing}/edit' - defaults: - _entity_form: 'cloud_pricing.edit' - _title: 'Edit Cloud Pricing' - requirements: - _permission: 'edit cloud pricing' - -entity.cloud_pricing.delete_form: - path: '/admin/config/cloud/{cloud_context}/pricing/{cloud_pricing}/delete' - defaults: - _entity_form: 'cloud_pricing.delete' - _title: 'Delete Cloud Pricing' - requirements: - _permission: 'delete cloud pricing' diff --git a/modules/cloud_pricing/config/schema/cloud_pricing.schema.yml b/modules/cloud_pricing/config/schema/cloud_pricing.schema.yml deleted file mode 100644 index e555800..0000000 --- a/modules/cloud_pricing/config/schema/cloud_pricing.schema.yml +++ /dev/null @@ -1,31 +0,0 @@ -cloud_pricing.cloud.*: - type: config_entity - label: 'Cloud Pricing Information Config' - mapping: - id: - type: string - label: 'ID' - cloud_context: - type: string - label: 'Cloud Context' - instance_type: - type: string - label: 'Instance Type' - description: - type: string - label: 'Description' - linux_usage: - type: float - label: 'Linux Usage' - windows_usage: - type: float - label: 'Windows Usage' - created: - type: integer - label: 'Date Created' - changed: - type: integer - label: 'Date Updated' - uuid: - type: string - label: 'UUID' diff --git a/modules/cloud_pricing/src/CloudPricingInterface.php b/modules/cloud_pricing/src/CloudPricingInterface.php deleted file mode 100644 index d95628f..0000000 --- a/modules/cloud_pricing/src/CloudPricingInterface.php +++ /dev/null @@ -1,47 +0,0 @@ - t('Instance Type'), 'specifier' => 'instance_type'], - ['data' => t('Description'), 'specifier' => 'description'], - ['data' => t('Linux Usage'), 'specifier' => 'linux_usage', 'sort' => 'ASC'], - ['data' => t('Windows Usage'), 'specifier' => 'windows_usage'], - ['data' => t('Date Created'), 'specifier' => 'created'], - ['data' => t('Date Updated'), 'specifier' => 'changed'], - ]; - - return $header + parent::buildHeader(); - } - - /** - * {@inheritdoc} - */ - public function buildRow(EntityInterface $entity) { - - // For debug - // $row['id'] = $entity->id(); - // $row['uuid'] = $entity->uuid(); - $row['instance_type'] = \Drupal::l( - $entity->instance_type(), - new Url( - 'entity.cloud_pricing.edit_form', [ - 'cloud_pricing' => $entity->id(), - // Need to add. - 'cloud_context' => $entity->cloud_context(), - ] - ) - ); - $row['description'] = $entity->description(); - $row['linux_usage'] = '$' . number_format($entity->linux_usage(), 3); - $row['windows_usage'] = '$' . number_format($entity->windows_usage(), 3); - $row['created'] = date('Y/m/d H:i', $entity->created()); - $row['changed'] = date('Y/m/d H:i', $entity->changed()); - - return $row + parent::buildRow($entity); - } - -} diff --git a/modules/cloud_pricing/src/Entity/CloudPricing.php b/modules/cloud_pricing/src/Entity/CloudPricing.php deleted file mode 100644 index 07d4be9..0000000 --- a/modules/cloud_pricing/src/Entity/CloudPricing.php +++ /dev/null @@ -1,153 +0,0 @@ -get('cloud_context'); - } - - /** - * The Cloud Pricing Cloud Context. - */ - public function instance_type() { - return $this->get('instance_type'); - } - - /** - * The Cloud Pricing Linux Usage. - */ - public function linux_usage() { - return $this->get('linux_usage'); - } - - /** - * The Cloud Pricing Windows Usage. - */ - public function windows_usage() { - return $this->get('windows_usage'); - } - - /** - * The Cloud Pricing Description. - */ - public function description() { - return $this->get('description'); - - } - - /** - * The time that the pricing information was created. - */ - public function created() { - return $this->get('created'); - } - - /** - * The time that the pricing information was changed. - */ - public function changed() { - return $this->get('changed'); - } - - /** - * The comment language code. - */ - public function langcode() { - return $this->get('langcode'); - } - -} diff --git a/modules/cloud_pricing/src/Form/CloudPricingDeleteForm.php b/modules/cloud_pricing/src/Form/CloudPricingDeleteForm.php deleted file mode 100644 index e3fa00a..0000000 --- a/modules/cloud_pricing/src/Form/CloudPricingDeleteForm.php +++ /dev/null @@ -1,73 +0,0 @@ -entity; - return $this->t('Are you sure you want to delete %instance_type?', [ - '%instance_type' => $entity->instance_type(), - ]); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - $entity = $this->entity; - $url = new Url('entity.cloud_pricing.collection'); - $url->setRouteParameter('cloud_context', $entity->cloud_context()); - return $url; - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - - $entity = $this->entity; - $entity->delete(); - - /* @FIXME: - // User Activity Log - cloud_audit_user_activity( - array( - 'type' => 'user_activity', - 'message' => t('Pricing has been deleted: @pricing', array('@pricing' => $pricing_obj->instance_type)), - 'link' => '', - ) - ); - */ - drupal_set_message( - $this->t('content @type: deleted @instance_type.', - [ - '@type' => $entity->bundle(), - '@instance_type' => $entity->instance_type(), - ] - ) - ); - - $form_state->setRedirectUrl($this->getCancelUrl()); - } - -} diff --git a/modules/cloud_pricing/src/Form/CloudPricingEditForm.php b/modules/cloud_pricing/src/Form/CloudPricingEditForm.php deleted file mode 100644 index 8921ee3..0000000 --- a/modules/cloud_pricing/src/Form/CloudPricingEditForm.php +++ /dev/null @@ -1,168 +0,0 @@ -entity; - - // Get a parameter from the path. - $cloud_context = \Drupal::routeMatch()->getParameter('cloud_context'); - - $form['cloud_context'] = [ - '#type' => 'textfield', - '#title' => $this->t('Cloud ID'), - '#maxlength' => 255, - '#default_value' => $entity->isNew() - // Get a parameter from the path _or_. - ? $cloud_context - // Get default value. - : $entity->cloud_context(), - '#required' => TRUE, - '#disabled' => TRUE, - ]; - - $form['instance_type'] = [ - '#type' => 'textfield', - '#title' => $this->t('Instance Type'), - '#type' => 'textfield', - '#maxlength' => 255, - '#default_value' => $entity->instance_type(), - '#required' => TRUE, - '#disabled' => !$entity->isNew(), - ]; - - $form['description'] = [ - '#type' => 'textarea', - '#title' => $this->t('Description'), - '#cols' => 60, - '#rows' => 3, - '#default_value' => $entity->description(), - '#required' => TRUE, - ]; - - $form['linux_usage'] = [ - '#type' => 'textfield', - '#title' => $this->t('Linux Usage Charge per Hour ($)'), - '#maxlength' => 20, - '#default_value' => $entity->linux_usage(), - '#required' => TRUE, - ]; - - $form['windows_usage'] = [ - '#type' => 'textfield', - '#title' => $this->t('Windows Usage Charge per Hour ($)'), - '#maxlength' => 20, - '#default_value' => $entity->windows_usage(), - '#required' => TRUE, - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function validate(array $form, FormStateInterface $form_state) { - - $entity = $this->entity; - - $cloud_context = $entity->cloud_context(); - - // Check if ID exists. - if (($entity->isNew() && $this->exist($cloud_context))) { - $form_state->setError($form, $this->t('The %instance_type already exists.', [ - '%instance_type' => $entity->instance_type(), - ])); - } - if (!preg_match(CLOUD_PRICING_VALID_NUMBER, trim($entity->linux_usage()))) { - $form_state->setError($form, $this->t('Please enter valid usage for Linux')); - } - if (!preg_match(CLOUD_PRICING_VALID_NUMBER, trim($entity->windows_usage()))) { - $form_state->setError($form, $this->t('Please enter valid usage for Windows')); - } - } - - /** - * {@inheritdoc} - */ - public function save(array $form, FormStateInterface $form_state) { - - $entity = $this->entity; - - $cloud_context = $entity->isNew() - ? $form['cloud_context']['#value'] - : $entity->cloud_context(); - $instance_type = $entity->instance_type(); - - // When performing action - add. - if ($entity->isNew()) { - - $id = "$cloud_context.$instance_type"; - $entity->set('id', $id); - $entity->set('created', time()); - } - - // When performing action - add or edit. - $entity->set('changed', time()); - - /* @FIXME: - // User Activity Log - cloud_audit_user_activity( - array( - 'type' => 'user_activity', - 'message' => t('New Pricing has been added: @pricing', - array('@pricing' => $form_values['instance_type_select'])), - 'link' => '', - ) - ); - */ - // TRUE or FALSE - if ($entity->save()) { - drupal_set_message( - $this->t('%instance_type pricing information has been saved.', [ - '%instance_type' => $instance_type, - ])); - } - else { - // @FIXME: - // $redirect = 'edit-form'; - $form_state->setError( - $form, $this->t('The %instance_type pricing information was not saved.', [ - '%instance_type' => $instance_type, - ])); - } - - $form_state - ->setRedirectUrl($entity - ->urlInfo('collection') - ->setRouteParameter('cloud_context', $entity->cloud_context())); - } - -} diff --git a/modules/cloud_pricing/src/Tests/CloudPricingTest.php b/modules/cloud_pricing/src/Tests/CloudPricingTest.php deleted file mode 100644 index d426ca6..0000000 --- a/modules/cloud_pricing/src/Tests/CloudPricingTest.php +++ /dev/null @@ -1,245 +0,0 @@ -drupalCreateUser([ - 'add cloud pricing', - 'list cloud pricing', - 'view cloud pricing', - 'edit cloud pricing', - 'delete cloud pricing', - ]); - $this->drupalLogin($web_user); - } - - /** - * Tests CRUD for pricing information. - */ - public function testCloudPricing() { - - // Access to Pricing Menu - // $clouds = $this->getClouds(); - // foreach ($clouds as $cloud) {. - $cloud_context = 'default_cloud_context'; - - // List Pricing for Amazon EC2. - $this->drupalGet("/admin/config/cloud/$cloud_context/pricing"); - $this->assertResponse(200, t('HTTP 200: List | Pricing')); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - - $this->drupalGet("/admin/config/cloud/$cloud_context/pricing/add"); - - // Add a new pricing information. - $add = $this->createPricingTestData(); - for ($i = 0; $i < CLOUD_PRICING_REPEAT_COUNT; $i++) { - - $num = $i + 1; - $instance_type[$i] = $add[$i]['instance_type']; - - $this->drupalPostForm("/admin/config/cloud/$cloud_context/pricing/add", - $add[$i], - t('Save')); - $this->assertResponse(200, t('HTTP 200: Add | A New CloudPricing Form #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - $this->assertText($instance_type[$i] . ' ' . t('pricing information has been saved.'), - t('Confirm Message:') . ' ' - . $instance_type[$i] . ' ' . t('pricing information has been saved.')); - - $this->assertText($instance_type[$i], - t('Instance Type: @instance_type', [ - '@instance_type' => $instance_type[$i], - ])); - $this->assertText(number_format($add[$i]['linux_usage'], 3), - t('Linux Usage: @linux_usage', [ - '@linux_usage' => $add[$i]['linux_usage'], - ])); - $this->assertText(number_format($add[$i]['windows_usage'], 3), - t('Windows Usage: @windows_usage', [ - '@windows_usage' => $add[$i]['windows_usage'], - ])); - - // Make sure listing. - $this->drupalGet("/admin/config/cloud/$cloud_context/pricing"); - $this->assertResponse(200, t('HTTP 200: List | Pricing #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertText($instance_type[$j], - t("Make sure w/ Listing @num: @instance_type", [ - '@num' => $j + 1, - '@instance_type' => $instance_type[$j], - ])); - } - } - - // Edit case. - $edit = $this->createPricingTestData(); - $instance_type = []; - // 3 times. - for ($i = 0; $i < CLOUD_PRICING_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $id = $cloud_context . '.' . $edit[$i]['instance_type']; - $instance_type[$i] = $edit[$i]['instance_type']; - - // Do not send $edit[$i]['instance_type'] as a POST parameter. - unset($edit[$i]['instance_type']); - $this->drupalPostForm("/admin/config/cloud/$cloud_context/pricing/$id", - $edit[$i], - t('Save')); - $this->assertResponse(200, t('HTTP 200: Edit | A New Pricing Form #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - $this->assertText($instance_type[$i] . ' ' . t('pricing information has been saved.'), - t('Confirm Message:') . ' ' - . $instance_type[$i] . ' ' . t('pricing information has been saved.')); - - $this->assertText($instance_type[$i], - t('Instance Type: @instance_type', [ - '@instance_type' => $instance_type[$i], - ])); - $this->assertText(number_format($edit[$i]['linux_usage'], 3), - t('Linux Usage: @linux_usage', [ - '@linux_usage' => $edit[$i]['linux_usage'], - ])); - $this->assertText(number_format($edit[$i]['windows_usage'], 3), - t('Windows Usage: @windows_usage', [ - '@windows_usage' => $edit[$i]['windows_usage'], - ])); - - // Make sure listing. - $this->drupalGet("/admin/config/cloud/$cloud_context/pricing"); - $this->assertResponse(200, t('HTTP 200: List | Pricing #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertText($instance_type[$j], - t("Make sure w/ Listing @num: @instance_type", [ - '@num' => $j + 1, - '@instance_type' => $instance_type[$j], - ])); - } - } - - // Delete pricing Items - // 3 times. - for ($i = 0; $i < CLOUD_PRICING_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $id = $cloud_context . '.' . $instance_type[$i]; - - $this->drupalGet("/admin/config/cloud/$cloud_context/pricing/$id/delete"); - $this->drupalPostForm("/admin/config/cloud/$cloud_context/pricing/$id/delete", - [], - t('Delete')); - $this->assertResponse(200, t('HTTP 200: Pricing | Delete #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - // Make sure listing. - $this->drupalGet("/admin/config/cloud/$cloud_context/pricing"); - $this->assertResponse(200, t('HTTP 200: List | Pricing #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertNoText($instance_type[$j], - t("Make sure w/ Listing @num: @instance_type", [ - '@num' => $j + 1, - '@instance_type' => $instance_type[$j], - ])); - } - } - // Filtering pricing information item - /* - $filter = array( - 'filter' => 't1', - 'operation' => 0, - ); - - $this->drupalPost("/admin/config/cloud/$cloud_context/pricing", $filter, t('Apply')); - $this->assertResponse(200, t('HTTP 200: Search Listings | Filter')); - $pricing_id = CLOUD_PRICING_REPEAT_COUNT - 1 ; - $this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large'); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - */ - // end - // } // End of foreach. - } - - /** - * - */ - private function createPricingTestData() { - - static $random; - if (!$random) { - $random = new Random(); - } - - for ($i = 0; $i < CLOUD_PRICING_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - // Input Fields. - $data[] = [ - 'instance_type' => "m$num.xlarge", - // 12.34 (min . sec) - 'linux_usage' => date('i.s'), - // 12.34 (min . sec) - 'windows_usage' => date('i.s'), - 'description' => "#$num: " . date('Y/m/d H:i:s - D M j G:i:s T Y') - . ' - SimpleTest Pricing Description' - . $random->string(32, TRUE), - ]; - } - - return $data; - } - -} diff --git a/modules/cloud_script/README.txt b/modules/cloud_script/README.txt deleted file mode 100644 index 355470e..0000000 --- a/modules/cloud_script/README.txt +++ /dev/null @@ -1,62 +0,0 @@ -BASIC INFO -========== - -- Provides scripting feature such as bash, Perl and etc (Mainly bash scripts) - on running an instance (or a virtual machine). -- Works with Cloud and Server Templates module. - -* Windows is NOT supported. - - -HOW TO USE -========== - -To create a scripting item for a template - -1) Enable Scripting module -2) Go to the menu: Design | Scripting -3) Click 'New Script' button -4) Enter Name, Description, Script Type, Packages, Inputs, and Script -5) Click 'Add' button -6) Create a template -7) Go to the menu: Design | Template -8) Select a scripting item - -* Scripts are executed by drupal's cron. - Please set up and adjust cron job time for script execution. - - If you set up one minute for cron job, the scripting module - try to execute scripts every one minutes or re-try those. - - -DIRECTORY STRUCTURE -=================== - -cloud - +-modules (depends on Cloud module) (Cloud is a core module for Cloud package) - +-cloud_activity_audit - +-cloud_alerts - x-cloud_auto_scaling - x-cloud_billing - x-cloud_cluster - x-cloud_dashboard - x-cloud_failover - +-cloud_inputs - x-cloud_metering - +-cloud_pricing - x-cloud_resource_allocator - x-cloud_scaling_manager - o-cloud_script - +-cloud_server_templates - - - x... Not released yet. - - -CHANGE HISTORY -============== -2011/12/21 7.x-1.x-dev released - - - -End of README.txt \ No newline at end of file diff --git a/modules/cloud_script/cloud_script.constants.inc b/modules/cloud_script/cloud_script.constants.inc deleted file mode 100644 index 05ea131..0000000 --- a/modules/cloud_script/cloud_script.constants.inc +++ /dev/null @@ -1,25 +0,0 @@ -fields('a'); - - return $query; -} - -function _cloud_script_get_script_query() { - - $query = db_select(CLOUD_SCRIPTING_TABLE, 'a'); - $query - ->fields('a'); - - return $query; -} - - -function _cloud_script_get_count_db() { - - $script_count = 0; - - $query = db_select(CLOUD_SCRIPTING_TABLE, 'a'); - $query->addExpression('COUNT(*)', 'script_count'); - - $result = $query->execute(); - foreach ($result as $script) { - - $script_count = $script->script_count; - } - - return $script_count; -} - - -function _cloud_script_get_script_by_id($script_id) { - - $query = db_select(CLOUD_SCRIPTING_TABLE, 'a'); - $result = $query - ->fields('a') - ->condition('script_id', $script_id) - ->execute(); - - $scripts_obj = $result->fetchObject(); - - return $scripts_obj; -} - - -function _cloud_script_delete($id) { - - //// add watchdog log - - $query = _cloud_script_get_scripts(); - $query - ->condition('script_id', $id, '='); - $result = $query->execute(); - $count = 0; - - $scripts_obj = $result->fetchObject(); - - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => t('Script has been deleted: @script_name', array('@script_name' => $scripts_obj->name)), - 'link' => '', - ) - ); - - //delete script - - $query = db_delete(CLOUD_SCRIPTING_TABLE) - ->condition('script_id', $id) - ->execute(); - - //DELETE FROM scripting template table - - $query = db_delete(CLOUD_SERVER_TEMPLATES_SCRIPTS_TABLE) - ->condition('script_id', $id) - ->execute(); - - - //delete from cloud_inputs table - if (\Drupal::moduleHandler()->moduleExists('cloud_inputs')) { - - $query = db_select(CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE, 'a'); - $query - ->fields('a', array('param_id')) - ->condition('script_id', $id); - $result = $query->execute(); - - - - while ($param = $result->fetchField()) { - - $query = db_delete(CLOUD_INPUTS_PARAMETER_VALUES_TABLE) - ->condition('param_id', array($param)) - ->execute(); - } - } - - //finally delete cloud_script_input_parameter - $query = db_delete(CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE) - ->condition('script_id', array($id)) - ->execute(); - - return; -} - - -/** - * Insert a script in database - * This function insert entry in database and audit logs as well. - * - * @param $form_values - * This is the form-values submitted by new script form - * @return return a last inserted script-id - */ -function _cloud_script_insert_script($form_values) { - $id = $insert_query = db_insert(CLOUD_SCRIPTING_TABLE) - ->fields(array( - 'name' => $form_values['name_text' ], - 'description' => $form_values['description_text' ], - 'type' => $form_values['script_type_select' ], - 'packages' => '', //package not supported right now - 'inputs' => $form_values['inputs_text' ], - 'script_template' => $form_values['script_template_text' ], - 'created' => date('c'), - 'updated' => date('c'), - )) - ->execute(); - - if ( \Drupal::moduleHandler()->moduleExists('cloud_inputs')) { - - $inputs = explode(',', $form_values['inputs_text']); - - if (is_array($inputs) && count($inputs) > 0) { - - foreach ($inputs as $input) { - - if (!empty($input)) { - $insert_input_query = ''; - - $insert_input_query = db_insert(CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE) - ->fields(array( - 'script_id' => $id, - 'input_parameter' => $input, - 'param_type' => 'text', - )) - ->execute(); - } - } - } - } - // User Activity Log - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => t('New Script has been added: @script_name', array('@script_name' => $form_values['name_text'])), - 'link' => '', //d'design/scripting/describe/info&id=' . $id); - ) - ); - return $id; -} - -function _cloud_script_update_script($form_values, $script_id = '') { - - $update_query = db_update(CLOUD_SCRIPTING_TABLE) - ->fields(array( - 'name' => $form_values['name_text' ], - 'description' => $form_values['description_text' ], - 'type' => $form_values['script_type_select' ], - 'packages' => '', - 'inputs' => $form_values['inputs_text' ], - 'script_template' => $form_values['script_template_text' ], - 'updated' => date('c'), - )) - ->condition('script_id', (!empty($form_values['script_id']) ? $form_values['script_id'] : $script_id)) - ->execute(); - - ///insert into script input parameter - if ( \Drupal::moduleHandler()->moduleExists('cloud_inputs')) { - $inputs = explode(',', $form_values['inputs_text']); - $inputs_old = explode(',', $form_values['inputs_text_old']); - - - foreach ($inputs_old as $input_old) { - //grab a list of old ids - use it to delete the old values - //in cloud_inputs_parameter_values table. Otherwise they - //will be orphaned! - if (\Drupal::moduleHandler()->moduleExists('cloud_inputs')) { - - $old_id = db_query("SELECT param_id from {" . CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE . "} where script_id = ':script_id' and input_parameter = ':input_old'", array(':script_id' => $script_id, ':input_old' => $input_old))->fetchField(); - if ($old_id != FALSE) { - - $query = db_delete(CLOUD_INPUTS_PARAMETER_VALUES_TABLE) - ->condition('param_id', array($old_id)) - ->execute(); - } - } - - - $query = db_delete(CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE) - ->condition('script_id', $script_id) - ->condition('input_parameter', $input_old) - ->execute(); - } - - foreach ($inputs as $input) { - - if (!empty($input) ) { - - $get_query = db_select(CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE, 'a'); - $get_query - ->condition('script_id', $script_id) - ->condition('input_parameter', $input) - ->fields('a'); - - $result = $get_query->execute(); - - - $total_input_rows = !empty($result->num_rows) ? $result->num_rows : ''; //mysql_num_rows($result1); - - if ($total_input_rows <= 0) { - //print $total_input_rows;die; - - $nid = db_insert(CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE) - ->fields(array( - 'script_id' => $script_id, - 'input_parameter' => $input, - 'param_type' => 'text', - )) - ->execute(); - } - } - } - } - // User Activity Log - cloud_audit_user_activity( array( - 'type' => 'user_activity', - 'message' => t('Script has been modified: @script_name', array('@script_name' => $form_values['name_text'])), - 'link' => '', // 'design/scripting/describe/info&id=' . $script_id); - ) - ); - - return; -} - - - - -function _cloud_script_get_scripts_of_template() { - - return $query = 'SELECT * FROM {' . CLOUD_SERVER_TEMPLATES_SCRIPTS_TABLE . '} c WHERE server_template_id=:server_template_id ORDER BY `order`'; -} - - -function _cloud_script_get_executed_scripts() { - - - $query = db_select(CLOUD_SCRIPTING_INSTANCES_TABLE, 'a'); - $query - ->fields('a') - ->condition('script_executed', 2); - - return cloud_get_db_results($query); -} - - -function _cloud_script_get_selected_scripts($str_script) { - - $query = db_select(CLOUD_SCRIPTING_TABLE, 'a'); - $query - ->fields('a') - ->condition('script_id', '(' . $str_script . ')', 'IN'); - - return cloud_get_db_results($query); -} - - -function _cloud_script_get_script($script_id) { - - $query = db_select(CLOUD_SCRIPTING_TABLE, 'a'); - $query - ->fields('a') - ->condition('script_id', array($script_id), 'IN'); - $return_val = $query->execute()->fetchAssoc(); - //$return_val = cloud_get_db_results($query); - //return $return_val[0]; - return $return_val; -} - - -function _cloud_script_register_exec_save($instance_id, $script_id, $status) { - - $query = db_select(CLOUD_SCRIPTING_INSTANCES_TABLE, 'a'); - $query - ->fields('a') - ->condition('instance_id', $instance_id) - ->condition('script_id', $script_id); - - $result = $query->execute(); - - - $found = FALSE; - foreach ($result as $key) { - - $found = TRUE; - } - - drupal_log_to_file('DEPLOYMENT::EXECUTE_SCRIPT', 'DRUPAL_BASE', 'INFO', 'FOUND=' . $found ); - if ($found) { // Update Table - $update_query = db_update(CLOUD_SCRIPTING_INSTANCES_TABLE) - ->fields(array( - 'script_executed' => $status, - )) - ->condition('instance_id', $instance_id) - ->condition('script_id', $script_id) - ->execute(); - - drupal_log_to_file('DEPLOYMENT::EXECUTE_SCRIPT', 'DRUPAL_BASE', 'INFO', 'UPDATE=' . $update_query ); - } - else { // Insert in table - $insert_query = db_insert(CLOUD_SCRIPTING_INSTANCES_TABLE) - ->fields(array( - 'instance_id' => $instance_id, - 'script_id' => $script_id, - 'script_executed' => $status, - )) - ->execute(); - drupal_log_to_file('DEPLOYMENT::EXECUTE_SCRIPT', 'DRUPAL_BASE', 'INFO', 'INSERT=' . $insert_query ); - } - - return; -} - - -/** - * function for checking if already there is same script ready for execution. * - * @param unknown_type $instance_id - * @param unknown_type $script_id - * @return TRUE/FALSE - */ -function _cloud_script_is_ready_for_exec($instance_id, $script_id) { - - - $query = db_select('cloud_instance_script', 'a'); - $query - ->fields('a') - ->condition('instance_id', $instance_id) - ->condition('script_id', $script_id) - ->condition('script_executed', 0); - - $row_count = count(cloud_get_db_results($query)); - - if ($row_count > 0) { - return TRUE; - } - else { - return FALSE; - } -} - - -/** - * function for adding script ready for execution on instance. - * @return - */ -function _cloud_script_add_ready_for_exec_on_instance($instance_id, $script_id, $script_executed, $cloud, $cluster_id, $template_id) { - - if ( _cloud_script_is_ready_for_exec($instance_id, $script_id)) { - return; - } - - $insert_query = db_insert(CLOUD_SCRIPTING_INSTANCES_TABLE) - ->fields(array( - 'instance_id' => $instance_id, - 'started' => 'now()', - 'script_id' => $script_id, - 'script_executed' => $script_executed, - 'cluster_id' => $cluster_id, - 'cloud' => $cloud, - 'template_id' => $template_id, - )) - ->execute(); - - return 0; -} - -function _cloud_script_register_script_save($instance_id, $script_id, $status, $cloud, $template_id) { - - $insert_query = db_insert(CLOUD_SCRIPTING_INSTANCES_TABLE) - ->fields(array( - 'instance_id' => $instance_id, - 'started' => 'now()', - 'script_id' => $script_id, - 'script_executed' => $status, - 'cloud' => $cloud, - 'template_id' => $template_id, - )) - ->execute(); - - return; -} - - -function _cloud_script_get_master_script_id_query() { - - $query = db_select(CLOUD_SCRIPTING_MASTER_TABLE, 'a'); - $query - ->fields('a'); - return $query; - -} - - -function _cloud_script_get_by_script_id_instance_id() { - - return $query = 'SELECT * FROM {' . CLOUD_SCRIPTING_INSTANCES_TABLE . "} c WHERE instance_id=:instance_id AND script_id=:script_id "; - -} - -/** - * - * @param type $instance_id - * @return type - */ -function _cloud_script_under_progress_scripts_for_instance_db($params) { - - $instance_id = $params['instance_id']; - $result = array(); - - - $query = db_select(CLOUD_SCRIPTING_INSTANCES_TABLE, 'a'); - $query - ->fields('a') - ->condition('instance_id', $params['instance_id']) - ->condition('script_executed', '2', '!='); - $result_scripts = $query->execute(); - - foreach ($result_scripts as $script) { - - $result[] = $script->script_id; - } - - return $result; -} - - -function _cloud_script_get_scripts_for_instance($instance_id) { - - - $scripts_query = $query = 'SELECT inst_script.script_id FROM {' . CLOUD_SCRIPTING_INSTANCES_TABLE . "} inst_script LEFT JOIN {" . CLOUD_SCRIPTING_TABLE . "} scr ON inst_script.script_id=scr.id WHERE instance_id=':instance_id' "; - $result = array(); - $result_scripts = db_query( $scripts_query, array(':instance_id' => $instance_id) ); - - foreach ($result_scripts as $script) { - - $result[] = $script->script_id; - } - - return $result; -} - -/** - * - * @param $instance_id - * @return unknown_type - */ -function _cloud_script_get_scripts_ready_for_instance_query($instance_id, $script_id) { - - $query = ''; - if (empty($script_id)) { - $query = 'SELECT vis.instance_id, vis.script_id script_id, vis.cluster_id, vis.cloud, vis.template_id, s.script_template script FROM {' . CLOUD_SCRIPTING_INSTANCES_TABLE . '} vis, - {' . CLOUD_SCRIPTING_TABLE . "} s WHERE s.id = vis.script_id and vis.instance_id = '" . $instance_id . "' ORDER BY vis.id"; - } - else { - $query = 'SELECT vis.instance_id, vis.script_id script_id, vis.cluster_id, vis.cloud, vis.template_id, s.script_template script FROM {' . CLOUD_SCRIPTING_INSTANCES_TABLE . '} vis, - {' . CLOUD_SCRIPTING_TABLE . "} s WHERE s.id = vis.script_id and vis.instance_id = '" . $instance_id . "' and vis.script_id = '" . $script_id . "' ORDER BY vis.id"; - } - - return $query; -} - - -/** - * - * @param $cluster_id - * @param $script_id - * @return unknown_type - */ -function _cloud_script_get_cluster_input_query($cluster_id, $script_id) { - - $query = 'SELECT ip.script_id, ip.param_type, ip.input_parameter, pv.cluster_value, pv.value_of_instance_id FROM {CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE} ip, - {' . CLOUD_INPUTS_PARAMETER_VALUES_TABLE . " } pv WHERE ip.param_id = pv.param_id AND pv.cluster_id = " . $cluster_id . " and ip.script_id = '" . $script_id . "'"; - return $query; -} - - -/** - * - * @param $template_id - * @param $script_id - * @return array() - */ -function _cloud_script_get_script_inputs($template_id, $script_id) { - - $query = 'SELECT ip.script_id, ip.param_type, ip.input_parameter, pv.template_value, pv.value_of_instance_id FROM {' . CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE . '} ip, - {' . CLOUD_INPUTS_PARAMETER_VALUES_TABLE . "} pv WHERE ip.param_id = pv.param_id AND pv.template_id = :template_id and ip.script_id = :script_id"; - - return cloud_get_db_results($query, array(':template_id' => $template_id, ':script_id' => $script_id)); -} - -function _cloud_script_get_cluster_script_inputs($script_id, $server_id, $cluster_id) { - $cluster_query = 'SELECT ip.script_id, ip.param_type, ip.input_parameter, pv.cluster_value FROM {' . CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE . '} ip, - {' . CLOUD_INPUTS_PARAMETER_VALUES_TABLE . "} pv WHERE ip.param_id = pv.param_id AND pv.server_id= :server_id and ip.script_id = ':script_id' and pv.cluster_id =:cluster_id "; - return cloud_get_db_results($cluster_query, array('$server_id' => $server_id, ':script_id' => $script_id, 'cluster_id' => $cluster_id)); - -} -/** - * function for getting script id from master scripts table. - * @return script_id(varchar) - */ -function _cloud_script_get_id_from_master($script) { - - $master_script_query = _cloud_script_get_master_script_id_query(); - $master_script_query - ->condition('script_name', $script); - $result_master_script = $query->execute(); - $script_id = ''; - - if ($script_data = $result_master_script->fetchObject()) { - - $script_id = $script_data->script_id; - } - - return $script_id; -} - -/* - * Required functions - */ - -/** - * Function that updates scripting status - * @param $instance_id - * @param $script_ids - * @param $script_executed - * @return - * function for Updating the current status for Script. - */ -function _cloud_script_update_scripts_status($instance_id, $script_id, $script_execution_status) { - $update_query = db_update(CLOUD_SCRIPTING_INSTANCES_TABLE) - ->fields(array( - 'script_executed' => $script_execution_status, - )) - ->condition('instance_id', $instance_id) - ->condition('script_id', $script_id) - ->execute(); - return; -} - -/***NEW FUNCTIONS ADDED****/ - -/** - * Database function to get scripts that are ready to execute - * @param $cloud_context - * @return - */ -function _cloud_script_get_execute_ready_scripts($cloud_context) { - - $query = 'SELECT * FROM {' . CLOUD_SCRIPTING_INSTANCES_TABLE . "} WHERE `script_executed` = '" . CLOUD_SCRIPTING_SCRIPT_READY_FOR_EXECUTION . "' AND instance_id NOT IN "; - $query .= ' ( SELECT instance_id FROM {' . CLOUD_SCRIPTING_INSTANCES_TABLE . "} WHERE `script_executed` = '" . CLOUD_SCRIPTING_SCRIPT_UNDER_EXECUTION . "') ORDER BY instance_id, id"; - - return cloud_get_db_results($query); -} - -/** - * Database function to check a script's execution progress - */ -function _cloud_script_get_under_progress_scripts() { - $scripts = array(); - $result = db_select(CLOUD_SCRIPTING_INSTANCES_TABLE, 'a') - ->fields('a') - ->condition('script_executed', CLOUD_SCRIPTING_SCRIPT_UNDER_EXECUTION) - ->execute(); - while ($record = $result->fetchAssoc()) { - $scripts[] = $record; - } - return $scripts; -} diff --git a/modules/cloud_script/cloud_script.exec.helper.inc b/modules/cloud_script/cloud_script.exec.helper.inc deleted file mode 100644 index 21efe78..0000000 --- a/modules/cloud_script/cloud_script.exec.helper.inc +++ /dev/null @@ -1,351 +0,0 @@ - $cloud_context - */ -function _cloud_script_check_instance_script_status($cloud_context) { - $scripts = _cloud_script_get_under_progress_scripts($cloud_context); - - foreach ($scripts as $script) { - $instance_id = $script['instance_id']; - $script_id = $script['script_id']; - $instance = cloud_get_instance($cloud_context, $instance_id); - if ($instance) { - $key_name = $instance['key_name']; - $perm_file = _cloud_script_get_perm_file($instance_id, $key_name, $cloud_context); - $instance_ip = $instance['dns_name']; - - if ( _cloud_script_is_script_execution_done($cloud_context, $instance_ip, $instance_id, $perm_file, $script_id) == '1') { - _cloud_script_update_scripts_status($instance_id, $script_id, CLOUD_SCRIPTING_SCRIPT_EXECUTED); - } - } - } -} - -/** - * Execute a one off script on the fly. This doesn't read or load - * from the cloud_script tables or any of the scripts setup from - * the template. This is useful for system scripts or arbitrary scripts - * without going through cloud templates - */ -function _cloud_script_exec_one_off_script($cloud_context, $instance_id, $script, $script_name, $background = FALSE) { - $ssh_user_name = aws_cloud_get_ssh_user( $cloud_context, $instance_id); - - $instance = cloud_get_instance($cloud_context, $instance_id); - $key_name = $instance['key_name']; - $instance_ip = $instance['dns_name']; - if (($path = _cloud_script_prepare_directory($instance_id)) != FALSE && - (($perm_file = _cloud_script_get_perm_file($instance_id, $key_name, $cloud_context)) != FALSE)) { - - $script_file = \Drupal::service("file_system")->realpath($path) . '/' . $instance_id . '_' . $script_name; - - $fh = fopen($script_file, 'w'); - if ($fh == FALSE) { - drupal_set_message( t('Unable to create the script file.'), 'error' ); - return; - } - - fwrite($fh, $script); - fclose($fh); - - $cmd = CLOUD_SSH_PATH . ' ' . $ssh_user_name . '@' . $instance_ip . ' -i "' . $perm_file . '" -o \'StrictHostKeyChecking no\' \'nohup bash -s\' < ' . $script_file; - if ($background == TRUE) { - $cmd .= ' > /tmp/log.out 2>&1 &'; - } - $output = array(); - exec($cmd, $output, $retval); - - return $retval; - } -} - -/** - * Helper function that executes a command on a remote instance - */ -function _cloud_script_exec_remote_command($cloud_context, $instance_id, $command, $background = FALSE) { - $ssh_user_name = aws_cloud_get_ssh_user( $cloud_context, $instance_id); - $instance = cloud_get_instance($cloud_context, $instance_id); - $key_name = $instance['key_name']; - $instance_ip = $instance['dns_name']; - if ((($perm_file = _cloud_script_get_perm_file($instance_id, $key_name, $cloud_context)) != FALSE)) { - $cmd = CLOUD_SSH_PATH . ' ' . $ssh_user_name . '@' . $instance_ip . ' -i "' . $perm_file . '" -o \'StrictHostKeyChecking no\' ' . $command; - if ($background == TRUE) { - $cmd . ' > /tmp/log.out 2>&1 &'; - } - exec($cmd, $output, $retval); - - return $output; - } - return FALSE; -} - -/** - * Copy a local file onto the remote server - */ -function _cloud_script_exec_copy_file($cloud_context, $instance_id, $source, $target) { - $success = FALSE; - $ssh_user_name = aws_cloud_get_ssh_user( $cloud_context, $instance_id); - $instance = cloud_get_instance($cloud_context, $instance_id); - $key_name = $instance['key_name']; - $instance_ip = $instance['dns_name']; - if ((($perm_file = _cloud_script_get_perm_file($instance_id, $key_name, $cloud_context)) != FALSE)) { - $cmd = CLOUD_SSH_PATH . ' ' . $ssh_user_name . '@' . $instance_ip . ' -i "' . $perm_file . '" -o \'StrictHostKeyChecking no\' ' . $command; - - $command = $SCP_PATH . " -i $perm_file -o 'StrictHostKeyChecking no' $source $ssh_user_name@$instance_ip:$target "; - - exec($cmd, $output, $retval); - // check the return - $success = ($retval != 0) ? FALSE : TRUE; - } - return $success; -} - -/** - * Function executes a script on an instance - */ -function _cloud_script_exec_scripts_on_instance($cloud_context, $instance, $instance_id, $instance_script_params) { - $script_id = $instance_script_params['script_id']; - if (!empty($script_id)) { - $script_params = _cloud_script_get_script($script_id); - // @todo find a way to not have cross module functions. This should be a hook - $ssh_user_name = aws_cloud_get_ssh_user($cloud_context, $instance_id); - - if (($path = _cloud_script_prepare_directory($instance_id)) != FALSE) { - if (($perm_file = _cloud_script_get_perm_file($instance_id, $instance['key_name'], $cloud_context)) != FALSE) { - $cluster_id = $instance_script_params['cluster_id']; - $template_id = $instance_script_params['template_id']; - $instance_ip = $instance['dns_name']; - $script = $script_params['script_template']; - $script = str_replace("\r\n", "\n", $script); - $script_files = _cloud_script_create_temp_script_files($instance_id, $script_id, $script, $instance_ip, $cluster_id, $cloud_context, $template_id); - $script_dest_path = '/tmp/' . $instance_id . CLOUD_PATH_SEPARATOR . $script_id; - - //Here the main logic starts for executing Script on Remote Machine - if (_cloud_script_is_ssh_enabled($cloud_context, $instance_ip, $instance_id, $perm_file) == '0') { - // Instance is not ready for ssh. Do not execute script right now. Inform the user - drupal_set_message(t('SSH is not enabled on instance @instance. Remote script cannot be executed', array('@instance' => $instance_id))); - return; - } - - $log_file_name = \Drupal::service("file_system")->realpath($path) . CLOUD_PATH_SEPARATOR . REQUEST_TIME . '.log'; - _cloud_script_update_scripts_status($instance_id, $script_id, CLOUD_SCRIPTING_SCRIPT_UNDER_EXECUTION); //Change Script Status to Under Progress - - $tmp_args = ' ' . $instance_ip . ' ' . $perm_file . ' ' . $log_file_name . ' ' . "\"" . $script_files . "\"" . - ' ' . $instance_id . ' ' . $script_id . ' ' . CLOUD_SSH_PATH . ' ' . CLOUD_SCP_PATH . - ' ' . \Drupal::service("file_system")->realpath('public://cloud') . ' ' . \Drupal::service("file_system")->realpath('public://cloud') . CLOUD_SCRIPTING_OUTPUT_LOG_FILE . ' ' . $ssh_user_name . - ' ' . "\"" . $script_dest_path . "\"" ; - - $command = CLOUD_PHP_PATH . ' -f ' . dirname(__FILE__) . CLOUD_PATH_SEPARATOR . 'cloud_script_exec.inc ' . $tmp_args . ' >> ' . \Drupal::service("file_system")->realpath('public://cloud') . '/cloud.log'; - - exec($command, $output, $retval); - } - } - } - return; -} - -/** - * Function prepares the URI for a temporary directory - * for use when executing remote scripts. If the directory - * cannot be created, FALSE is returned - */ -function _cloud_script_prepare_directory($directory) { - $path = CLOUD_SCRIPTING_TEMP_DIRECTORY . '/' . $directory; - if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { - drupal_set_message(t('Unable to create temporary cloud path @path', array('@path' => $path)), 'error'); - return FALSE; - } - return $path; -} - -/** - * This function will do the following. - * a) Remove any magic words - * b) It will check if cluster id is there then we will use Keywords related to cluster - * c) If clusterId is blank then we will use Keywords realted to templateId - * @param $instance_id - * @param $script_id - * @param $script - * @param $instance_ip - * @param $cluster_id - * @param $cloud - * @param $template_id - * @return - */ -function _cloud_script_create_temp_script_files($instance_id, $script_id, $script, $instance_ip, $cluster_id, $cloud, $template_id) { - - $input_params_flag_set = FALSE; - $org_script = $script; - - //see if the instance is part of a cluster. - //if so, update it with the cluster based values - //make sure cloud_cluster is enabled - $cluster_script = FALSE; - if (\Drupal::moduleHandler()->moduleExists('cloud_cluster')) { - if (!empty($instance_id)) { - //check to see if instance is part of a cluster - $server = cloud_cluster_get_server($instance_id); - if ($server != FALSE) { - //grab its parameters and create a script - $script = _scripting_update_cluster_inputs($script_id, $script, $server['server_id'], $server['cluster_id']); - $cluster_script = TRUE; - } - } - } - - //Run the template version if cluster doesn't exist - if ($cluster_script == FALSE) { - $script = _scripting_update_inputs($template_id, $script_id, $script); - } - - $path = _cloud_script_prepare_directory($instance_id); - $script_file = \Drupal::service("file_system")->realpath($path . CLOUD_PATH_SEPARATOR . $script_id); - if (file_unmanaged_save_data($script, $script_file, FILE_EXISTS_REPLACE) != FALSE) { - // add in magic statement which indicates if the script finished - file_put_contents($script_file, _scripting_get_magic_statement('/tmp/' . $instance_id . CLOUD_PATH_SEPARATOR . $script_id), FILE_APPEND); - } - return $script_file; -} - -function _scripting_update_cluster_inputs($script_id, $script, $server_id, $cluster_id) { - if (!empty($server_id)) { - $inputs = _cloud_script_get_cluster_script_inputs($script_id, $server_id, $cluster_id); - foreach ($inputs as $input) { - $keyword = $input['input_parameter']; - $val = $input['cluster_value']; - $type = $input['param_type']; - - if ($type == 'text') { - $script = str_replace(trim($keyword), $val, $script); - } - } - } - return $script; -} - -/** - * Function to update inputs - * @param $template_id - * @param $script - * @return - */ -function _scripting_update_inputs($template_id, $script_id, $script) { - - if (! empty($template_id)) { - - $inputs = _cloud_script_get_script_inputs($template_id, $script_id); - $row_count = count($inputs); - - for ($row = 0; $row < $row_count; $row++) { - - $keyword = $inputs[$row]['input_parameter']; - $val = $inputs[$row]['template_value']; - $type = $inputs[$row]['param_type']; - - if (trim($type) == 'text') { - - $script = str_replace(trim($keyword), $val, $script); - } - } - } - - return $script; -} - -/** - * Writes .done to signify a script is finished - * @param $script_file - * @return - */ -function _scripting_get_magic_statement($script_file) { - return "\n" . "touch $script_file.done"; -} - -/** - * Function to check if a script is done executing on an instance - * @todo: Replace with this function _cloud_script_exec_remote_command() - */ -function _cloud_script_is_script_execution_done($cloud_context, $instance_ip, $instance_id, $perm_file, $script_id ) { - - $ssh_user_name = aws_cloud_get_ssh_user( $cloud_context, $instance_id ); - $script_file = '/tmp/' . $instance_id . CLOUD_PATH_SEPARATOR . $script_id . '.done'; - $remote_command = "[ -f $script_file ] && echo '1' || echo '0'"; - $command = CLOUD_SSH_PATH . ' ' . $ssh_user_name . '@' . $instance_ip . ' -i "' . $perm_file . '" -o \'StrictHostKeyChecking no\' "' . $remote_command . '"'; - exec($command, $output, $retval); - - $result = isset($output[0]) ? $output[0] : 0; - - return $result; -} - - - -/** - * Function to check if SSH is enabled on a specific instance - * @todo: Replace with this function _cloud_script_exec_remote_command() - */ -function _cloud_script_is_ssh_enabled($cloud_context, $instance_ip, $instance_id, $perm_file) { - - $ssh_user_name = aws_cloud_get_ssh_user( $cloud_context, $instance_id ); - $remote_command = "[ -d /tmp ] && echo '1' || echo '0'"; - $command = CLOUD_SSH_PATH . ' ' . $ssh_user_name . '@' . $instance_ip . ' -i "' . $perm_file . '" -o \'StrictHostKeyChecking no\' "' . $remote_command . '"'; - exec($command, $output, $retval); - - $result = isset($output[0]) ? $output[0] : '0'; - - return $result; -} - -/** - * Function to get the permission file based on the cloud and keyname. If the - * key does not exist, the key will be created. - * @param $instance_id - * @param $key_name - * @return - */ -function _cloud_script_get_perm_file($instance_id, $key_name, $cloud_context) { - $perm_file = ''; - $path = _cloud_script_prepare_directory($instance_id); - - if ($path != FALSE) { - $perm_file = \Drupal::service("file_system")->realpath($path) . '/' . $key_name; - - if (file_exists($perm_file) == FALSE) { - $key = cloud_get_ssh_key($cloud_context, $key_name); - if (file_unmanaged_save_data($key, $perm_file, FILE_EXISTS_REPLACE) !== FALSE) { - \Drupal::service("file_system")->chmod($perm_file, 0400); - } - else { - drupal_set_message(t('Unable to save write temporary permissions file @file', array('@file' => $perm_file)), 'error'); - $perm_file = FALSE; // set to false - } - } - } - return $perm_file; -} diff --git a/modules/cloud_script/cloud_script.exec.inc b/modules/cloud_script/cloud_script.exec.inc deleted file mode 100644 index 79313dc..0000000 --- a/modules/cloud_script/cloud_script.exec.inc +++ /dev/null @@ -1,148 +0,0 @@ -' . $command . '
'; - exec( $command, $output, $retval); - _cloud_script_print_output($fh, $command, $retval, $output ); - - if ( $retval != 0 ) { - fwrite($fh, 'Unable to create temporary folder' ); - fclose($fh); - return $retval; - } - - $command = $SCP_PATH . " -i $perm_file -o 'StrictHostKeyChecking no' $script_file $USER@$instance_ip:$folder_name "; - - $output = array(); - exec( $command, $output, $retval); - _cloud_script_print_output($fh, $command, $retval, $output ); - - if ( $retval != 0 ) { - - fwrite($fh, 'Unable to copy the script file: ' . $script_file ); - fclose($fh); - return $retval; - } - - $command = $SSH_PATH . ' ' . $USER . '@' . $instance_ip . ' -i "' . $perm_file . '" -o \'StrictHostKeyChecking no\' "chmod 700 ' . $folder_name . ' "'; - - $output = array(); - exec( $command, $output, $retval); - _cloud_script_print_output($fh, $command, $retval, $output ); - if ( $retval != 0 ) { - - fwrite($fh, 'Unable to change the mode for folder' ); - fclose($fh); - - return $retval; - } - - $command = $SSH_PATH . ' ' . $USER . '@' . $instance_ip . ' -i "' . $perm_file . '" -o \'StrictHostKeyChecking no\' "chmod 700 ' . $folder_name . '/* "'; - - $output = array(); - exec( $command, $output, $retval); - - _cloud_script_print_output($fh, $command, $retval, $output ); - - if ( $retval != 0 ) { - - fwrite($fh, 'Unable to change mode of script files' ); - fclose($fh); - - return $retval; - } - else { - - fwrite($fh, $script_file ); - $script_file = str_replace(' ', ';', trim($script_file)); - fwrite($fh, $script_file ); - } - - $command = $SSH_PATH . ' ' . $USER . '@' . $instance_ip . ' -i "' . $perm_file . '" -o \'StrictHostKeyChecking no\' "sh -l ' . $script_dest_path . ' "'; - - fwrite($fh, 'Executing command ' . $command ); - - exec( $command, $output, $retval); - - _cloud_script_print_output($fh, $command, $retval, $output ); - - $script_execution_log_file = $folder_name . $CLOUD_SCRIPTING_OUTPUT_LOG_FILE; - - if ( $retval != 0 ) { - - fwrite($fh, 'Execution of Script file failed' ); - fclose($fh); - - if (copy($log_file_name, $script_execution_log_file)) { - echo "Failed to copy $log_file_name...\n"; - } - - return $retval; - } - fclose($fh); - - //capture output of script execution to file - - if (copy($log_file_name, $script_execution_log_file)) { - - echo "Failed to copy $log_file_name...\n"; - } - - return 0; -} - - -return 0; - -function _cloud_script_print_output($fh, $command, $retval, $output) { - - fwrite($fh, "cmd: $command\n"); - fwrite($fh, "return: $retval\n"); - - foreach ($output as $key => $val ) { - fwrite($fh, 'output:' . $val . "\n" ); - } - - flush(); -} diff --git a/modules/cloud_script/cloud_script.inc b/modules/cloud_script/cloud_script.inc deleted file mode 100644 index 7d8d5f5..0000000 --- a/modules/cloud_script/cloud_script.inc +++ /dev/null @@ -1,831 +0,0 @@ -getForm('cloud_script_list'); -} - -/** - * Returns a form with listing of scripts - * Build a form including table header and table body - * @param $form_submit - * This is the form-submit submitted by list scripts form - * @return return a form - */ -function cloud_script_list($form, $form_submit) { - - // @FIXME -// The Assets API has totally changed. CSS, JavaScript, and libraries are now -// attached directly to render arrays using the #attached property. -// -// -// @see https://www.drupal.org/node/2169605 -// @see https://www.drupal.org/node/2408597 -// drupal_add_js(cloud_get_module_base() . 'js/cloud.js'); - - - $column = 'name'; - - $form['options'] = array( - '#prefix' => '
', - '#type' => 'fieldset', - '#suffix' => '
', - ); - - $options = array( - t('Nickname' ), - t('Type' ), - ); - - $filter = cloud_get_filter_value( $form_submit, 'filter' ); - $filter = trim($filter); - - $filter_col = cloud_get_filter_value( $form_submit, 'operation'); - $filter_col = isset($filter_col) && $filter_col ? $filter_col : 0; // default: Script Name - - if ( $filter_col == 0 ) { - $column = 'Script Name'; - $sql_col = 'name' ; - } - elseif ($filter_col == 1 ) { - $column = 'Type'; - $sql_col = 'type'; - } - elseif ($filter_col == 2 ) { - $column = 'Packages'; - $sql_col = 'packages'; - } - - if ( isset($filter) ) { - $query_args[] = $sql_col; - $query_args[] = $filter ; - } - else { - $filter = ' 1 '; - $query_args[] = ' '; - } - - $script_count = _cloud_script_get_count_db(); - $filter_disabled = ''; - if ( $script_count < 2 ) { - - $filter_disabled = TRUE; - } - - $form['options']['label' ] = array( - '#type' => 'item' , - '#title' => t('Filter'), - ); - $form['options']['operation'] = array( - '#type' => 'select' , - '#options' => $options , - '#default_value' => $filter_col, - '#disabled' => $filter_disabled, - ); - $form['options']['filter' ] = array( - '#type' => 'textfield', - '#size' => 40 , - '#default_value' => $filter , - '#disabled' => $filter_disabled, - ); - $form['options']['submit' ] = array( - '#type' => 'submit' , - '#value' => t('Apply') , - '#disabled' => $filter_disabled, - ); - if (\Drupal::currentUser()->hasPermission('create script') ) { - $form['options']['script'] = array( - '#type' => 'submit' , - '#value' => t('Create'), - ); - } - - $form['header'] = array( - '#type' => 'value', - '#markup' => array( - array( - 'data' => t('Nickname'), - 'field' => 'name', - 'sort' => 'asc', - 'class' => array('nickname-column'), - ), - array( - 'data' => t('Type'), - 'field' => 'type', - ), - array( - 'data' => t('Packages'), - 'field' => 'packages', - ), - array( - 'data' => t('Inputs'), - 'field' => 'inputs', - ), - array( - 'data' => t('Created'), - 'field' => 'created', - ), - array( - 'data' => t('Updated'), - 'field' => 'updated', - ), - array( - 'data' => t('Action'), - 'class' => 'action-column', - ), - ), - ); - - $query = _cloud_script_get_scripts(); - $query = $query - ->extend('PagerDefault') - ->extend('TableSort') - ->orderByHeader($form['header']['#markup']); - - $query - ->condition($query_args[0], '%%' . $query_args[1] . '%%', 'like') - ->fields('a') - ->limit(CLOUD_SCRIPTING_PAGER_LIMIT); - - $result = $query->execute(); - - $scripting_options = cloud_server_templates_get_scripting_options(); - foreach ($result as $scripts_obj) { - // @FIXME -// l() expects a Url object, created from a route name or external URI. -// $form['Name' ][$scripts_obj->script_id] = array('#markup' => l( $scripts_obj->name, CLOUD_SCRIPTING_PATH . '/describe/' . $scripts_obj->script_id . '/info', array('query' => array('id' => urlencode($scripts_obj->script_id))) )); - //, array(), 'id=' . urlencode($scripts_obj->id) , NULL, FALSE, TRUE ) ) ); - $form['Type' ][$scripts_obj->script_id] = array('#markup' => \Drupal\Component\Utility\SafeMarkup::checkPlain( $scripting_options['CLOUD_SCRIPTING_TYPE_OPTIONS'][$scripts_obj->type] )); - $form['Packages'][$scripts_obj->script_id] = array('#markup' => \Drupal\Component\Utility\SafeMarkup::checkPlain( $scripts_obj->packages )); - $form['Inputs' ][$scripts_obj->script_id] = array('#markup' => \Drupal\Component\Utility\SafeMarkup::checkPlain( $scripts_obj->inputs )); - $form['Created'][$scripts_obj->script_id] = array('#markup' => format_date(strtotime($scripts_obj->created), 'short')); - $form['Updated'][$scripts_obj->script_id] = array('#markup' => format_date(strtotime($scripts_obj->updated), 'short')); - $form['Actions'][$scripts_obj->script_id] = array('#markup' => cloud_script_action(array('script_id' => $scripts_obj->script_id, 'script_name' => $scripts_obj->name))); - } - - $form_state['#redirect'] = FALSE; - return $form; -} - - -/** - * Theme function for cloud script listing page - */ -function theme_cloud_script_list($variables) { - $form = $variables['form']; - $rows = array(); - if (!empty($form['Name'])) { - foreach (\Drupal\Core\Render\Element::children($form['Name']) as $key) { - $rows[] = array( - array( - 'data' => \Drupal::service("renderer")->render($form['Name'][$key]), - 'class' => array('nickname-column'), - ), - \Drupal::service("renderer")->render($form['Type' ][$key]), - \Drupal::service("renderer")->render($form['Packages'][$key]), - \Drupal::service("renderer")->render($form['Inputs' ][$key]), - \Drupal::service("renderer")->render($form['Created'][$key]), - \Drupal::service("renderer")->render($form['Updated'][$key]), - array( - 'data' => \Drupal::service("renderer")->render($form['Actions'][$key]), - 'class' => array('action-column'), - ), - ); - } - } - - $output = \Drupal::service("renderer")->render($form['options']); - // @FIXME -// theme() has been renamed to _theme() and should NEVER be called directly. -// Calling _theme() directly can alter the expected output and potentially -// introduce security issues (see https://www.drupal.org/node/2195739). You -// should use renderable arrays instead. -// -// -// @see https://www.drupal.org/node/2195739 -// $output .= theme('table', array('header' => $form['header']['#markup'], 'rows' => $rows)); - - // @FIXME -// theme() has been renamed to _theme() and should NEVER be called directly. -// Calling _theme() directly can alter the expected output and potentially -// introduce security issues (see https://www.drupal.org/node/2195739). You -// should use renderable arrays instead. -// -// -// @see https://www.drupal.org/node/2195739 -// $output .= theme('pager'); - - $output .= drupal_render_children($form); - return $output; -} - -/** - * Function to render scripting actions links - */ -function cloud_script_action($scripting_info) { - $action_data = array(); - - if (\Drupal::currentUser()->hasPermission('delete script')) { - $prop['onclick'] = cloud_get_messagebox('Are you sure you want to delete the Script "' . $scripting_info['script_name'] . '" ?'); - $action_data[] = cloud_display_action( - 'images/icon_delete.png', - t('Delete'), - CLOUD_SCRIPTING_PATH . '/' . urlencode($scripting_info['script_id']) . '/delete', - array('query' => array('id' => urlencode($scripting_info['script_id'])), 'html' => TRUE), $prop['onclick'] - ); - } - if (\Drupal::currentUser()->hasPermission('edit script')) { - $action_data[] = cloud_display_action( - 'images/icon_clear.png', - t('Edit'), - CLOUD_SCRIPTING_PATH . '/' . urlencode($scripting_info['script_id']) . '/edit', - array('query' => array('id' => urlencode($scripting_info['script_id'])), 'html' => TRUE) - ); - } - - // allow other modules to add action icons - $user_actions = \Drupal::moduleHandler()->invokeAll('cloud_script_action_data', [$scripting_info]); - $action_data = array_merge($action_data, $user_actions); - return implode($action_data); -} - -/** - * Function for submitting cloud script listing page - */ -function cloud_script_list_submit($form_id, &$form_state) { - $form_values =& $form_state['values']; - if ($form_values['op'] == t('Create')) { - $form_state['redirect'] = CLOUD_SCRIPTING_PATH . '/create'; - } - elseif ($form_values['op'] == t('Apply')) { - $param_arr = array( - 'filter' => $form_values['filter'], - 'operation' => $form_values['operation'], - ); - $form_state['redirect'] = array(\Drupal\Core\Url::fromRoute("")->toString(), array('query' => $param_arr)); - } -} - - -/** - * Form function to display Script details - */ -function cloud_script_desc_info($form, $form_submit = '', $script_id = '') { - - if (empty($script_id) || strlen($script_id) == 0 ) { - drupal_goto( CLOUD_SCRIPTING_PATH . '/list'); - return; - } - - $query = _cloud_script_get_scripts(); - $query->condition('script_id', $script_id, '='); - $result = $query - ->execute() - ->fetchObject(); - - $form['fieldset_script_info'] = array( - '#type' => 'fieldset', - '#title' => t('Details'), - ); - - if ($result) { - $script_name = $result->name; - $form['name']['name_label'] = array('#type' => 'item', '#title' => t('Script Name')); - $form['name']['name_text'] = array('#markup' => \Drupal\Component\Utility\SafeMarkup::checkPlain($result->name)); - - $form['type']['type_label'] = array('#type' => 'item', '#title' => t('Script Type')); - $form['type']['type_text'] = array('#markup' => t($result->type)); - - $form['description']['description_label'] = array('#type' => 'item', '#title' => t('Description')); - $form['description']['description_text'] = array('#markup' => \Drupal\Component\Utility\SafeMarkup::checkPlain( $result->description)); - - $form['packages']['packages_label'] = array('#type' => 'item', '#title' => t('Packages')); - $form['packages']['packages_text'] = array('#markup' => \Drupal\Component\Utility\SafeMarkup::checkPlain($result->packages)); - - $form['cloud_inputs']['inputs_label'] = array('#type' => 'item', '#title' => t('Inputs')); - $form['cloud_inputs']['inputs_text'] = array('#markup' => \Drupal\Component\Utility\SafeMarkup::checkPlain($result->inputs)); - - $form['script']['script_label'] = array('#type' => 'item', '#title' => t('Script')); - $form['script']['script_text'] = array('#type' => 'textarea', '#value' => $result->script_template, '#disabled' => 1); - - $form['created']['created_label'] = array('#type' => 'item', '#title' => t('Created')); - $form['created']['created_text'] = array('#markup' => format_date(strtotime($result->created), 'short')); - - $form['updated']['updated_label'] = array('#type' => 'item', '#title' => t('Updated')); - $form['updated']['updated_text'] = array('#markup' => format_date(strtotime($result->updated), 'short')); - - $form['Script']['id'] = array('#type' => 'value', '#value' => $result->script_id); - - $form['submit_buttons'] = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - - if (\Drupal::currentUser()->hasPermission('edit script')) { - $form['submit_buttons']['Edit'] = array( - '#type' => 'submit', - '#value' => t('Edit'), - ); - } - - if (\Drupal::currentUser()->hasPermission('delete script')) { - $confirm_msg = cloud_get_messagebox('Are you sure you want to delete the Script "' . $script_name . '" ?'); - $onclick = $confirm_msg; - $form['submit_buttons']['Delete'] = array( - '#type' => 'submit', - '#value' => t('Delete'), - '#attributes' => array('onclick' => $onclick), - ); - } - - $form['submit_buttons']['List Scripts'] = array( - '#type' => 'submit', - '#value' => t('List Scripts'), - ); - } - return $form; -} - -/** - * Submit function for cloud scription details page - */ -function cloud_script_desc_info_submit($form, &$form_state) { - $op = $form_state['values']['op']; - $script_id = $form_state['values']['id']; - switch ($op) { - case 'Edit': - $form_state['redirect'] = CLOUD_SCRIPTING_PATH . '/' . $script_id . '/edit'; - break; - case 'Delete': - $form_state['redirect'] = CLOUD_SCRIPTING_PATH . '/' . $script_id . '/delete'; - break; - default: - $form_state['redirect'] = CLOUD_SCRIPTING_PATH . '/' . 'list'; - break; - } -} - -/** - * Theme function for cloud script details page - */ -function theme_cloud_script_desc_info($variables) { - $form = $variables['form']; - - $rows = array( - array( - \Drupal::service("renderer")->render($form['name']['name_label']), - \Drupal::service("renderer")->render($form['name']['name_text']), - ), - array( - \Drupal::service("renderer")->render($form['type']['type_label']), - \Drupal::service("renderer")->render($form['type']['type_text']), - ), - array( - \Drupal::service("renderer")->render($form['description']['description_label']), - \Drupal::service("renderer")->render($form['description']['description_text']), - ), - array( - \Drupal::service("renderer")->render($form['packages']['packages_label' ]), - \Drupal::service("renderer")->render($form['packages']['packages_text' ]), - ), - array( - \Drupal::service("renderer")->render($form['cloud_inputs']['inputs_label']), - \Drupal::service("renderer")->render($form['cloud_inputs']['inputs_text']), - ), - array( - \Drupal::service("renderer")->render($form['script']['script_label' ]), - \Drupal::service("renderer")->render($form['script'] ) - . \Drupal::service("renderer")->render($form['script']['script_text' ]), - ), - array( - \Drupal::service("renderer")->render($form['created']['created_label' ]), - \Drupal::service("renderer")->render($form['created']['created_text' ]), - ), - array( - \Drupal::service("renderer")->render($form['updated']['updated_label' ]), - \Drupal::service("renderer")->render($form['updated']['updated_text' ]), - ), - ); - - // @FIXME -// theme() has been renamed to _theme() and should NEVER be called directly. -// Calling _theme() directly can alter the expected output and potentially -// introduce security issues (see https://www.drupal.org/node/2195739). You -// should use renderable arrays instead. -// -// -// @see https://www.drupal.org/node/2195739 -// $table = theme('table', array('header' => NULL, 'rows' => $rows)); - - $form['fieldset_script_info']['#children'] = $table; - - $output = \Drupal::service("renderer")->render($form['submit_buttons' ]); - $output .= \Drupal::service("renderer")->render($form['fieldset_script_info']); - $output .= \Drupal::service("renderer")->render($form['id' ]); - $output .= drupal_render_children($form ); - - return $output; -} - - -/** - * Describe a script using script_id - */ -function cloud_script_desc_script($form_submit = '', $script_id = '') { - - if (empty($script_id) || strlen($script_id) == 0 ) { - drupal_goto( CLOUD_SCRIPTING_PATH . '/list'); - } - - // @FIXME -// // @FIXME -// // The correct configuration object could not be determined. You'll need to -// // rewrite this call manually. -// variable_set( $user->uid . '_desc_info', $script_id ); - - - $query = _cloud_script_get_scripts(); - $query->condition('script_id', $script_id, '='); - $result = $query->execute(); - - $count = 0; - foreach ($result as $key) { - $form['packages' ]['packages_label'] = array( - '#type' => 'item', - '#title' => t('Packages'), - ); - $form['packages' ]['packages_text'] = array('#value' => \Drupal\Component\Utility\SafeMarkup::checkPlain( $key->packages)); - - $form['cloud_inputs']['inputs_label' ] = array( - '#type' => 'item', - '#title' => t('Inputs'), - ); - $form['cloud_inputs']['inputs_text' ] = array('#value' => \Drupal\Component\Utility\SafeMarkup::checkPlain( $key->inputs)); - - $form['script' ]['script_label' ] = array( - '#type' => 'item', - '#title' => t('Script'), - ); - $form['script' ]['script_text' ] = array( - '#type' => 'textarea', - '#value' => \Drupal\Component\Utility\SafeMarkup::checkPlain( $key->script_template), - '#disabled' => 1, - ); - - $form['Script' ]['id' ] = array( - '#type' => 'hidden', - '#value' => $key->script_id, - ); - - $count++; - } - - if ( $count == 0 ) { - drupal_goto( MODULE_PATH . '/list'); - } - - return $form; -} - - -/** - * Theme the script details page - * @see http://drupal.org/node/1354 - */ -function theme_cloud_script_desc_script($variables) { - $form = $variables['form']; - - $rows = array( - array( - \Drupal::service("renderer")->render($form['packages']['packages_label' ]), - \Drupal::service("renderer")->render($form['packages']['packages_text' ]), - ), - array( - \Drupal::service("renderer")->render($form['cloud_inputs']['inputs_label']), - \Drupal::service("renderer")->render($form['cloud_inputs']['inputs_text']), - ), - array( - \Drupal::service("renderer")->render($form['script']['script_label' ]), - \Drupal::service("renderer")->render($form['script'] ) - . \Drupal::service("renderer")->render($form['script']['script_text' ]), - ), - ); - - // @FIXME -// theme() has been renamed to _theme() and should NEVER be called directly. -// Calling _theme() directly can alter the expected output and potentially -// introduce security issues (see https://www.drupal.org/node/2195739). You -// should use renderable arrays instead. -// -// -// @see https://www.drupal.org/node/2195739 -// $output = theme('table', array('header' => NULL, 'rows' => $rows)); - - $output .= \Drupal::service("renderer")->render( $form['id'] ); - $output .= drupal_render_children($form); - - return $output; -} - -/** - * Delete a script - */ -function cloud_script_delete($script_id = '') { - _cloud_script_delete($script_id); - drupal_set_message(t('Script has been deleted successfully.')); - drupal_goto(CLOUD_SCRIPTING_PATH . '/list'); -} - - -/** - * Function to create form for new script - */ -function cloud_script_create($form, $form_submit = '', $script_id = '') { - - $scripting_options = cloud_server_templates_get_scripting_options(); - $action = t('Add'); - // @FIXME -// drupal_set_title() has been removed. There are now a few ways to set the title -// dynamically, depending on the situation. -// -// -// @see https://www.drupal.org/node/2067859 -// drupal_set_title(t('Add Script')); - - - $form['fieldset_script_info' ] = array('#type' => 'fieldset' /* '#title' => t('Script Info') */); - - $form['name' ]['name_label' ] = array( - '#type' => 'item', - '#title' => t('Name'), - ); - $form['name' ]['name_text' ] = array('#type' => 'textfield'); - - $form['description' ]['description_label' ] = array( - '#type' => 'item', - '#title' => t('Description'), - ); - $form['description' ]['description_text' ] = array('#type' => 'textarea'); - - $form['script_type' ]['script_type_label' ] = array( - '#type' => 'item' , - '#title' => t('Script Type'), - '#description' => t('The field value takes Boot, Operational, and Termination
when a script should be executed.
Currently only "booting" time execution is supported.'), - ); - $form['script_type' ]['script_type_select' ] = array( - '#type' => 'select', - '#options' => $scripting_options['CLOUD_SCRIPTING_TYPE_OPTIONS'], - ); - - $form['cloud_inputs' ]['inputs_label' ] = array( - '#type' => 'item' , - '#title' => t('Inputs'), - '#description' => t('Use the inputs as variables under Script code below.
Enter comma separated values. (e.g. MESSAGE, OUTPUT_FILE)
The input parameters are configurable;
the actual parameters can be settled in a template.'), - ); - $form['cloud_inputs' ]['inputs_text' ] = array('#type' => 'textfield'); - - $form['script_template']['script_template_label'] = array( - '#type' => 'item' , - '#title' => t('Script'), - '#description' => t('Put a script template here. (e.g. echo MESSAGE > OUTPUT_FILE)'), - ); - $form['script_template']['script_template_text'] = array('#type' => 'textarea'); - - if ($script_id) { - // @FIXME -// drupal_set_title() has been removed. There are now a few ways to set the title -// dynamically, depending on the situation. -// -// -// @see https://www.drupal.org/node/2067859 -// drupal_set_title(t('Edit Script')); - - $query = _cloud_script_get_scripts(); - $query->condition('script_id', $script_id, '='); - $result = $query->execute(); - $scripts_obj = $result->fetchObject(); - $action = t('Edit'); - $form['script_id' ] = array( - '#type' => 'hidden', - '#value' => $script_id, - ); - $form['inputs_text_old' ] = array( - '#type' => 'hidden', - '#value' => $scripts_obj->inputs, - ); - $form['name' ]['name_text' ]['#default_value'] = isset_variable($scripts_obj->name ); - $form['description' ]['description_text' ]['#default_value'] = isset_variable($scripts_obj->description ); - $form['script_type' ]['script_type_select' ]['#default_value'] = isset_variable($scripts_obj->type ); - $form['packages' ]['packages_text' ]['#default_value'] = isset_variable($scripts_obj->packages ); - $form['cloud_inputs' ]['inputs_text' ]['#default_value'] = isset_variable($scripts_obj->inputs ); - $form['script_template']['script_template_text']['#default_value'] = isset_variable(($scripts_obj->script_template)); - } - - $form['submit_buttons'] = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', - ); - - $form['submit_buttons'][$action] = array( - '#type' => 'submit', - '#value' => t($action ), - ); - $form['submit_buttons']['Cancel'] = array( - '#type' => 'submit', - '#value' => t('Cancel'), - ); - - return $form; -} - - -/** - * Theme the new scripting form - */ -function theme_cloud_script_create($variables) { - $form = $variables['form']; - - $rows = array( - array( - \Drupal::service("renderer")->render($form['name' ]['name_label' ] ), - \Drupal::service("renderer")->render($form['name' ]['name_text' ] ), - ), - array( - \Drupal::service("renderer")->render($form['description' ]['description_label' ] ), - \Drupal::service("renderer")->render($form['description' ]['description_text' ] ), - ), - array( - \Drupal::service("renderer")->render($form['script_type' ]['script_type_label' ] ), - \Drupal::service("renderer")->render($form['script_type' ]['script_type_select' ] ), - ), - array( - \Drupal::service("renderer")->render($form['cloud_inputs' ]['inputs_label' ] ), - \Drupal::service("renderer")->render($form['cloud_inputs' ]['inputs_text' ] ), - ), - array( - \Drupal::service("renderer")->render($form['script_template']['script_template_label'] ), - \Drupal::service("renderer")->render($form['script_template']['script_template_text'] ), - ), - ); - - // @FIXME -// theme() has been renamed to _theme() and should NEVER be called directly. -// Calling _theme() directly can alter the expected output and potentially -// introduce security issues (see https://www.drupal.org/node/2195739). You -// should use renderable arrays instead. -// -// -// @see https://www.drupal.org/node/2195739 -// $table = theme('table', array('header' => NULL, 'rows' => $rows)); - - $form['fieldset_script_info']['#children'] = $table; - - $output = \Drupal::service("renderer")->render($form['launch']); - $output .= \Drupal::service("renderer")->render($form['fieldset_script_info']); - $output .= \Drupal::service("renderer")->render($form['submit_buttons']); - $output .= drupal_render_children($form); - - return $output; -} - - -/** - * Validate the new scripting form - */ -function cloud_script_create_validate($form_id, $form_values) { - $form_values = $form_values['values']; - if ( $form_values['op'] == t('Add' ) || $form_values['op'] == t('Edit') ) { - if ( empty($form_values['name_text']) ) { - form_set_error('name_text', t('You must enter valid Script Name')); - } - else { - $query = _cloud_script_get_script_query(); - $query->condition('name', $form_values['name_text'], '='); - $result = $query->execute()->fetchObject(); - - if ($result) { - $db_obj = $result; - $script_id = $db_obj->script_id; - if ($script_id != $form_values['script_id']) { - form_set_error('script_id', t('Name is already used by a Script.')); - } - } - } - - if ( empty($form_values['script_template_text']) ) { - form_set_error('script_template_text', t('You must enter valid script')); - } - } -} - - -/** - * Submit function for adding a new script - */ -function cloud_script_create_submit($form_id, &$form_state) { - $form_values = $form_state['values']; - - if ($form_values['op'] == t('Add')) { - _cloud_script_insert_script($form_values); - drupal_set_message(t('Script has been saved.')); - } - elseif ($form_values['op'] == t('Edit')) { - $script_id = $form_values['script_id']; - _cloud_script_update_script($form_values, $script_id ); - drupal_set_message(t('Script has been saved.')); - } - $form_state['redirect'] = CLOUD_SCRIPTING_PATH . '/list'; -} - -/** - * Update script status for an instance - */ -function _cloud_script_update_instance_status($dns) { - - $instance_id = _get_instance_by_dns_from_db($dns); - - if ( _cloud_failover_is_endbled_check_by_instance_id($instance_id) > 0 ) { - $result_script_status = _instance_status_update($instance_id, CLOUD_INSTANCE_STATUS_BOOTING ); - } - else { - $scripts_arr = _cloud_script_get_scripts_for_instance($instance_id); - if (sizeof($scripts_arr) == 0 ) { - if ( _cloud_script_check_is_executed($instance_id) > 0 ) { - // Scripts are to be executed - $result_script_status = _instance_status_update($instance_id, CLOUD_INSTANCE_STATUS_BOOTING ); - } - else { - // No scripts present - $result_script_status = _instance_status_update($instance_id, CLOUD_INSTANCE_STATUS_OPERATIONAL ); - } - } - else { - // Scripts are to be executed - $result_script_status = _instance_status_update($instance_id, CLOUD_INSTANCE_STATUS_BOOTING ); - } - } -} - -/** - * Check if a script has been executed - */ -function _cloud_script_check_is_executed($instance_id) { - - $check_scripts_query = " SELECT COUNT(*) AS script_cnt FROM ( SELECT ds.template_id AS tid FROM cloud_cluster_servers ds - LEFT JOIN {" . CLOUD_SERVER_TEMPLATES_TABLE . "} st - ON ds.template_id=st.template_id - WHERE ds.instance_id=:instance_id - ) tmp_tb - LEFT JOIN {" . CLOUD_SERVER_TEMPLATES_SCRIPTS_TABLE . "} sts - ON tmp_tb.tid=sts.server_template_id - "; - - $check_scripts_query_args = array( - ':instance_id' => $instance_id, - ); - - $result = db_query($check_scripts_query, $check_scripts_query_args ); - - if ($result->fetchField() > 0 ) { - return $script_cnt; - } - - $check_scripts_array_query = "SELECT COUNT(*) AS script_cnt - FROM - ( - SELECT arrayid FROM - ( SELECT tas.arrayid as arrayid FROM {" . CLOUD_AUTO_SCALING_ARRAY_LAUNCH_TABLE . "} tas - WHERE tas.instance_id=:instance_id ) vas - LEFT JOIN {" . INSTANCE_ARRAY_TABLE . "} sia on vas.arrayid = sia.id - LEFT JOIN {" . CLOUD_SERVER_TEMPLATES_TABLE . "} st on sia.server_template_id=st.template_id - LEFT JOIN {" . CLOUD_SERVER_TEMPLATES_SCRIPTS_TABLE . "} sts on st.template_id=sts.server_template_id - ) cnt_tbl "; - $check_scripts_array_query_args = array( - ':instance_id' => $instance_id, - ); - $result_arr = db_query($check_scripts_array_query, $check_scripts_array_query_args ); - return $result_arr->fetchField(); -} - -/** - * Redirect to script listing page - */ -function _cloud_script_getdata($src = '') { - if ( $src == NULL || empty($src) ) { - drupal_goto( CLOUD_SCRIPTING_PATH . '/list' ); - } - else { - drupal_goto( $src ); - } -} diff --git a/modules/cloud_script/cloud_script.info.yml b/modules/cloud_script/cloud_script.info.yml deleted file mode 100644 index e05d7cb..0000000 --- a/modules/cloud_script/cloud_script.info.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: Cloud Script -description: 'An executable piece of code.' -package: Cloud -core: 8.x -version: 8.x-1.x -project: cloud -type: module diff --git a/modules/cloud_script/cloud_script.install b/modules/cloud_script/cloud_script.install deleted file mode 100644 index f48b5bd..0000000 --- a/modules/cloud_script/cloud_script.install +++ /dev/null @@ -1,148 +0,0 @@ -loadInclude('cloud' , 'inc', 'cloud.constants' ); -\Drupal::moduleHandler()->loadInclude('cloud_script', 'inc', 'cloud_script.constants'); - -/** - * Implements hook_install(). - */ -function cloud_script_install() { - // Create tables. -} - -/** - * Implements hook_uninstall(). - */ -function cloud_script_uninstall() { - // Remove tables. -} - -/** - * Implementation of hook_schema(). - */ - -/** - * @todo Please document this function. - * @see http://drupal.org/node/1354 - */ -/* -function cloud_script_schema() { - - $schema = array(); - - $schema[CLOUD_SCRIPTING_TABLE] = array( - 'description' => 'Cloud Scripts', - 'fields' => array( - 'script_id' => array( - 'type' => 'serial', - 'length' => 11, - ), - 'name' => array( - 'type' => 'varchar', - 'length' => 255, - ), - 'description' => array('type' => 'text'), - 'type' => array( - 'type' => 'varchar', - 'length' => 50, - ), - 'packages' => array('type' => 'text'), - 'inputs' => array('type' => 'text'), - 'script_template' => array('type' => 'text'), - 'status' => array( - 'type' => 'int' , - 'length' => 3, - 'default' => 1, - ), - 'created' => array('type' => 'text'), - 'updated' => array('type' => 'text'), - ), - 'primary key' => array('script_id'), - ); - - $schema[CLOUD_SCRIPTING_MASTER_TABLE] = array( - 'description' => 'Script Master', - 'fields' => array( - 'script_id' => array( - 'type' => 'varchar', - 'length' => 100, - ), - 'script_name' => array( - 'type' => 'varchar', - 'length' => 255, - ), - ), - 'primary key' => array('script_name'), - ); - - - $schema[CLOUD_SCRIPTING_INPUT_PARAMETER_TABLE] = array( - 'description' => 'Script Input Parameter Table', - 'fields' => array( - 'param_id' => array( - 'type' => 'serial', - 'length' => 11, - ), - 'script_id' => array( - 'type' => 'varchar', - 'length' => 100, - ), - 'input_parameter' => array( - 'type' => 'varchar', - 'length' => 255, - ), - 'param_type' => array( - 'type' => 'varchar', - 'length' => 20, - ), - ), - 'primary key' => array('param_id'), - ); - - $schema[CLOUD_SCRIPTING_INSTANCES_TABLE] = array( - 'description' => 'Instance Scripts', - 'fields' => array( - 'id' => array( - 'type' => 'serial' , - 'length' => 11, - ), - 'instance_id' => array( - 'type' => 'varchar', - 'length' => 64, - ), - 'script_id' => array( - 'type' => 'varchar', - 'length' => 36, - ), - 'started' => array('type' => 'text'), - 'script_executed' => array( - 'type' => 'int' , - 'length' => 3, - ), - 'cluster_id' => array( - 'type' => 'int' , - 'length' => 11, - ), - 'cloud' => array( - 'type' => 'varchar', - 'length' => 50, - ), - 'template_id' => array( - 'type' => 'int' , - 'length' => 11, - ), - ), - 'primary key' => array('id'), - ); - - ///To add more schema just add one more $schema['newtable'] array. - - return $schema; -} -*/ diff --git a/modules/cloud_script/cloud_script.links.action.yml b/modules/cloud_script/cloud_script.links.action.yml deleted file mode 100644 index 8e9bdb5..0000000 --- a/modules/cloud_script/cloud_script.links.action.yml +++ /dev/null @@ -1,14 +0,0 @@ -entity.cloud_script.add_form: - route_name: entity.cloud_script.add_form - title: 'Add Cloud Script' - appears_on: - - entity.cloud_script.collection -# - entity.cloud_script.canonical - -entity.cloud_script.collection: - route_name: entity.cloud_script.collection - title: 'List Cloud Script' - appears_on: - - entity.cloud_script.add_form - - entity.cloud_script.edit_form - - entity.cloud_script.delete_form \ No newline at end of file diff --git a/modules/cloud_script/cloud_script.links.menu.yml b/modules/cloud_script/cloud_script.links.menu.yml deleted file mode 100644 index 516d76e..0000000 --- a/modules/cloud_script/cloud_script.links.menu.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Created by yas 2016/06/23. - -# MENU_NORMAL_ITEM -cloud_script.menu: - title: 'Scripts' - route_name: 'entity.cloud_script.collection' -# base_route: 'cloud.design.menu' - parent: 'cloud.design.menu' - weight: 100 \ No newline at end of file diff --git a/modules/cloud_script/cloud_script.links.task.yml b/modules/cloud_script/cloud_script.links.task.yml deleted file mode 100644 index f3d197e..0000000 --- a/modules/cloud_script/cloud_script.links.task.yml +++ /dev/null @@ -1,21 +0,0 @@ -# CloudScript routing definition -cloud_script.settings_tab: - route_name: cloud_script.settings - title: 'Settings' - base_route: cloud_script.settings - -entity.cloud_script.canonical: - route_name: entity.cloud_script.canonical - base_route: entity.cloud_script.canonical - title: 'View' - -entity.cloud_script.edit_form: - route_name: entity.cloud_script.edit_form - base_route: entity.cloud_script.canonical - title: Edit - -entity.cloud_script.delete_form: - route_name: entity.cloud_script.delete_form - base_route: entity.cloud_script.canonical - title: Delete - diff --git a/modules/cloud_script/cloud_script.module b/modules/cloud_script/cloud_script.module deleted file mode 100644 index ad0da1b..0000000 --- a/modules/cloud_script/cloud_script.module +++ /dev/null @@ -1,186 +0,0 @@ -loadInclude('cloud' , 'inc', 'cloud.constants' ); -\Drupal::moduleHandler()->loadInclude('cloud_script', 'inc', 'cloud_script.constants' ); -\Drupal::moduleHandler()->loadInclude('cloud_script', 'inc', 'cloud_script' ); -\Drupal::moduleHandler()->loadInclude('cloud_script', 'inc', 'cloud_script.db' ); -\Drupal::moduleHandler()->loadInclude('cloud_script', 'inc', 'cloud_script.exec.helper'); - -use Drupal\Core\Routing\RouteMatchInterface; - -/** - * Implements hook_help(). - */ -function cloud_script_help($route_name, RouteMatchInterface $route_match) { - switch ($route_name) { - // Main module help for the cloud_server_templates module. - case 'help.page.cloud_server_templates': - $output = ''; - $output .= '

' . t('About') . '

'; - $output .= '

' . t('Cloud Server Templates') . '

'; - $output = '

' . t('The cloud_script module creates a user interface for users to manage automated script. Users can create automated scripts.') . '

'; - return $output; - - default: - } -} - -/** - * Implements hook_menu(). - */ -/* -function cloud_script_menu() { - $items = array(); - $items['design/scripting/list'] = array( - 'title' => 'Scripting', - 'description' => 'List of all scripts', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_script_list'), - 'weight' => -1, - 'access arguments' => array('list scripts'), - 'file' => '', - ); - $items['design/scripting/create'] = array( - 'title' => 'Add/Edit Script', - 'description' => 'Add/Edit Script', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_script_create'), - 'access arguments' => array('create script'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - $items['design/scripting/%/edit'] = array( - 'title' => 'Add/Edit Script', - 'description' => 'Add/Edit Script', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_script_create', 2), - 'access arguments' => array('create script'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - $items['design/scripting/getdata'] = array( - 'title' => 'Scripting Get data', - 'page callback' => '_cloud_script_getdata', - 'page arguments' => array('cloud_script'), - 'access arguments' => array('list scripts'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - $items['design/scripting/describe/%'] = array( - 'title' => 'Script Info', - 'description' => 'Script Info', - 'access arguments' => array('list scripts'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - $items['design/scripting/describe/%/info'] = array( - 'title' => 'Info', - 'description' => 'Info', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cloud_script_desc_info', 3), - 'access arguments' => array('view script'), - 'file' => '', - 'weight' => 1, - 'type' => MENU_LOCAL_TASK, - ); - $items['design/scripting/%/delete'] = array( - 'title' => 'Delete', - 'page callback' => 'cloud_script_delete', - 'page arguments' => array(2), - 'access arguments' => array('delete script'), - 'file' => '', - 'type' => MENU_CALLBACK, - ); - return $items; -} -*/ - -/** - * Implements hook_permission(). - */ -/* -function cloud_script_permission() { - - return array( - 'create script' => array( - 'title' => t('create script'), - 'description' => t('TODO Add a description for \'create script\''), - ), - 'view script' => array( - 'title' => t('view script'), - 'description' => t('TODO Add a description for \'view script\''), - ), - 'list scripts' => array( - 'title' => t('list scripts' ), - 'description' => t('TODO Add a description for \'list scripts\''), - ), - 'edit script' => array( - 'title' => t('edit script'), - 'description' => t('TODO Add a description for \'edit script\''), - ), - 'delete script' => array( - 'title' => t('delete script'), - 'description' => t('TODO Add a description for \'delete script\''), - ), - ); -} -*/ - -/** - * Implements hook_theme(). - */ -/* -function cloud_script_theme() { - - return array( - 'cloud_script_list' => array( - 'render element' => 'form', - 'file' => 'cloud_script.inc', - ), - 'cloud_script_desc_info' => array( - 'render element' => 'form', - 'file' => 'cloud_script.inc', - ), - 'cloud_script_desc_script' => array( - 'render element' => 'form', - 'file' => 'cloud_script.inc', - ), - 'cloud_script_create' => array( - 'render element' => 'form', - 'file' => 'cloud_script.inc', - ), - ); -} -*/ - -/** - * Implements hook_cron(). - */ -/* -function cloud_script_cron() { - $cloud_list = cloud_get_all_clouds(); - foreach ($cloud_list as $cloud_context) { - _cloud_script_exec_script_on_instances($cloud_context); - } -} -*/ - -/** - * - * @param type $cloud_context - * @param type $op - * @param type $params - * @return type - */ -/* -function _cloud_script_under_progress_scripts_for_instance($params) { - return _cloud_script_under_progress_scripts_for_instance_db($params); -} -*/ \ No newline at end of file diff --git a/modules/cloud_script/cloud_script.page.inc b/modules/cloud_script/cloud_script.page.inc deleted file mode 100644 index 9cda1e2..0000000 --- a/modules/cloud_script/cloud_script.page.inc +++ /dev/null @@ -1,30 +0,0 @@ - OUTPUT_FILE') ; - -class ScriptingTestCase extends CloudTestCase { - - public static function getInfo() { - return array( - 'name' => 'Scripting' , - 'description' => 'Scripting Test Case', - 'group' => 'Cloud' , - ); - } - - public function listScripts() { - - // List Scripting for Amazon EC2 - $this->drupalGet('design/scripting/list'); - $this->assertResponse(200, t('HTTP 200: Design | Scripting' )); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings' )); - - $this->drupalPost('design/scripting/list', '', t('Create')); - } - - public function create() { - - $script = array(); - - // Input Fields - $script['name_text' ] = date('D M j G:i:s T Y') . ' - ' . $this->randomName(); - $script['description_text'] = date('D M j G:i:s T Y') . ' - ' . $this->randomName(); - - $add = array( - //'script_id' => $script['script_id'] , - 'name_text' => $script['name_text' ] , - 'description_text' => $script['description_text'] , - 'script_type_select' => 'boot' , - 'packages_text' => 'aws' , - 'inputs_text' => CLOUD_SCRIPTING_TEST_INPUT , - 'script_template_text' => CLOUD_SCRIPTING_TEST_SCRIPT , - ); - - $this->drupalPost('design/scripting/create', $add, t('Add')); - $this->assertResponse(200, t('HTTP 200: New Script Form | Add')); - $this->assertText(t('Script has been saved.'), - t('Confirm Message:') . t('Script has been saved.')); - $this->assertText($script['name_text'], t('Confirm New Script Item Name : @script_name' , array( - '@script_name' => $script['name_text']))); - $this->assertText(CLOUD_SCRIPTING_TEST_INPUT, t('Confirm New Script Item Input: @script_input', array( - '@script_input' => CLOUD_SCRIPTING_TEST_INPUT))); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - $this->drupalGet('design/scripting/list'); - $this->assertResponse(200, t('HTTP 200: Design | Scripting' )); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - return $script; - } - - public function edit($info) { - - $this->drupalPost('design/scripting/' . $info['script_id'] . '/edit', $info, t('Edit')); - $this->assertResponse(200, t('HTTP 200: New Script Form | Edit')); - $this->assertText(t('Script has been saved.'), - t('Confirm Message:') . t('Script has been saved.')); - $this->assertText($info['name_text' ], t('Confirm New Script Item Name : @script_name' , array( - '@script_name' => $info['name_text'] ))); - $this->assertText(CLOUD_SCRIPTING_TEST_INPUT, t('Confirm New Script Item Input: @script_input', array( - '@script_input' => CLOUD_SCRIPTING_TEST_INPUT))); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - } - - public function delete($script_id = 1) { - - // Delete a Scripting Item - $this->drupalGet("design/scripting/$script_id/delete", array( - 'id' => $script_id, - )); - $this->assertResponse(200, t('HTTP 200: Design | Scripting | Delete')); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - //$this->assertText($scriptName, 'Deleted Item: ' . $scriptName); - } - - public function filter($scriptName = NULL) { - - //filtering script item - $filter = array( - 'filter' => 'Test', - 'operation' => 0, - ); - - $this->drupalPost('design/scripting/list', $filter, t('Apply')); - $this->assertResponse(200, t('HTTP 200: Search Listings | Filter')); - $script_id = CLOUD_SCRIPTING_REPEAT_COUNT - 1 ; - $this->assertText($scriptName[$script_id], t('Confirm Filter Item: @script_name'), array( - '@script_name' => $scriptName[$script_id ])); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - } - - public function testScripting() { - - $this->listScripts(); - - // Create a new script - $script = array(); - for ($i = 0; $i < SCRIPTING_TEST_REPEAT_COUNT; $i++) { // 3 times - - $script[$i + 1] = $this->create(); - } - - //modify case - $script_id = 1; - $info = array( - 'script_id' => $script_id , - 'name_text' => $script[$script_id]['name_text' ] , - 'description_text' => $script[$script_id]['description_text'] , - 'script_type_select' => 'boot' , - 'packages_text' => 'aws' , - 'inputs_text' => CLOUD_SCRIPTING_TEST_INPUT , - 'script_template_text' => CLOUD_SCRIPTING_TEST_SCRIPT , - ); - - $this->edit($info); - $this->delete($script_id = 1); - } -} diff --git a/modules/cloud_script/src/CloudScriptInterface.php b/modules/cloud_script/src/CloudScriptInterface.php deleted file mode 100644 index 99ad173..0000000 --- a/modules/cloud_script/src/CloudScriptInterface.php +++ /dev/null @@ -1,65 +0,0 @@ -loadInclude('cloud', 'inc', 'cloud.constants'); -/** - * - */ -class CloudScriptController extends ControllerBase { - - -} diff --git a/modules/cloud_script/src/Controller/CloudScriptListBuilder.php b/modules/cloud_script/src/Controller/CloudScriptListBuilder.php deleted file mode 100644 index 6420ce7..0000000 --- a/modules/cloud_script/src/Controller/CloudScriptListBuilder.php +++ /dev/null @@ -1,64 +0,0 @@ - t('Name'), 'specifier' => 'name'], - ['data' => t('Description'), 'specifier' => 'description'], - ['data' => t('Type'), 'specifier' => 'type'], - ['data' => t('Input Parameters'), 'specifier' => 'input_parameters'], - ['data' => t('Date Created'), 'specifier' => 'created'], - ['data' => t('Date Updated'), 'specifier' => 'changed', 'sort' => 'DESC'], - ]; - - return $header + parent::buildHeader(); - } - - /** - * {@inheritdoc} - */ - public function buildRow(EntityInterface $entity) { - - // For debug - // $row['id'] = $entity->id(); - // $row['uuid'] = $entity->uuid(); - $row['name'] = \Drupal::l( - $this->getLabel($entity), - new Url( - 'entity.cloud_script.canonical', [ - 'cloud_script' => $entity->id(), - // 'cloud_context' => $entity->cloud_context(), // Need to add. - ] - ) - ); - $row['description'] = $entity->description(); - $row['type'] = $entity->type(); - $row['input_paramters'] = $entity->input_parameters(); - $row['created'] = date('Y/m/d H:i', $entity->created()); - $row['changed'] = date('Y/m/d H:i', $entity->changed()); - - return $row + parent::buildRow($entity); - } - -} diff --git a/modules/cloud_script/src/Entity/CloudScript.php b/modules/cloud_script/src/Entity/CloudScript.php deleted file mode 100644 index e5f5745..0000000 --- a/modules/cloud_script/src/Entity/CloudScript.php +++ /dev/null @@ -1,266 +0,0 @@ - \Drupal::currentUser()->id(), - ]; - } - - /** - * {@inheritdoc} - */ - /* - public function cloud_context() { - return $this->get('cloud_context')->value; - } - */ - - /** - * {@inheritdoc} - */ - public function type() { - return $this->get('type')->value; - } - - /** - * {@inheritdoc} - */ - public function description() { - return $this->get('description')->value; - } - - /** - * {@inheritdoc} - */ - public function input_parameters() { - return $this->get('input_parameters')->value; - } - - /** - * {@inheritdoc} - */ - public function script() { - return $this->get('script')->value; - } - - /** - * {@inheritdoc} - */ - public function created() { - return $this->get('created')->value; - } - - /** - * {@inheritdoc} - */ - public function changed() { - return $this->get('changed')->value; - } - - /** - * {@inheritdoc} - */ - public function getOwner() { - return $this->get('user_id')->entity; - } - - /** - * {@inheritdoc} - */ - public function getOwnerId() { - return $this->get('user_id')->target_id; - } - - /** - * The comment language code. - */ - public function langcode() { - return $this->get('langcode'); - } - - /** - * {@inheritdoc} - */ - /* - public function setCloudContext($cloud_context) { - $this->set('cloud_context', $cloud_context); - return $this; - } - */ - - /** - * {@inheritdoc} - */ - public function setOwnerId($uid) { - $this->set('user_id', $uid); - return $this; - } - - /** - * {@inheritdoc} - */ - public function setOwner(UserInterface $account) { - $this->set('user_id', $account->id()); - return $this; - } - - /** - * {@inheritdoc} - */ - public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - - $fields['id'] = BaseFieldDefinition::create('integer') - ->setLabel(t('ID')) - ->setDescription(t('The ID of the Script entity.')) - ->setReadOnly(TRUE); - - $fields['uuid'] = BaseFieldDefinition::create('uuid') - ->setLabel(t('UUID')) - ->setDescription(t('The UUID of the CloudScript entity.')) - ->setReadOnly(TRUE); - - /* - $fields['cloud_context'] = BaseFieldDefinition::create('string') - ->setRequired(TRUE) - ->setLabel(t('Cloud Provider Machine Name')) - ->setDescription(t('A unique machine name for the cloud provider.')); - */ - - $fields['name'] = BaseFieldDefinition::create('string') - ->setLabel(t('Name')) - ->setDescription(t('The name of the CloudScript entity.')) - ->setSettings([ - 'default_value' => '', - 'max_length' => 255, - 'text_processing' => 0, - ]) - ->setDisplayOptions('view', [ - 'label' => 'above', - 'type' => 'string', - 'weight' => -5, - ]) - /* - ->setDisplayOptions('form', array( - 'type' => 'string_textfield', - 'weight' => -6, - )) - */ - ->setDisplayConfigurable('form', TRUE) - ->setDisplayConfigurable('view', TRUE) - ->setRequired(TRUE); - - $fields['description'] = BaseFieldDefinition::create('string') - ->setLabel(t('Description')) - ->setDescription(t('Script Description.')); - - $fields['type'] = BaseFieldDefinition::create('string') - ->setLabel(t('Type')) - ->setDescription(t('Type.')) - ->setRequired(TRUE); - - $fields['input_parameters'] = BaseFieldDefinition::create('string') - ->setLabel(t('Input Parameters')) - ->setDescription(t('Input Parameters.')) - ->setRequired(TRUE); - - $fields['script'] = BaseFieldDefinition::create('string') - ->setLabel(t('Script')) - ->setDescription(t('Script.')); - - $fields['created'] = BaseFieldDefinition::create('created') - ->setLabel(t('Created')) - ->setDescription(t('The time that the entity was created.')); - - $fields['changed'] = BaseFieldDefinition::create('changed') - ->setLabel(t('Changed')) - ->setDescription(t('The time that the entity was last edited.')); - - $fields['user_id'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Authored by')) - ->setDescription(t('The user ID of the CloudScript entity author.')) - ->setRevisionable(TRUE) - ->setSetting('target_type', 'user') - ->setSetting('handler', 'default') - ->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId') - ->setTranslatable(TRUE) - ->setDisplayOptions('view', [ - 'label' => 'hidden', - 'type' => 'author', - 'weight' => 0, - ]) - ->setDisplayOptions('form', [ - 'type' => 'entity_reference_autocomplete', - 'weight' => 5, - 'settings' => [ - 'match_operator' => 'CONTAINS', - 'size' => '60', - 'autocomplete_type' => 'tags', - 'placeholder' => '', - ], - ]) - ->setDisplayConfigurable('form', TRUE) - ->setDisplayConfigurable('view', TRUE); - - $fields['langcode'] = BaseFieldDefinition::create('language') - ->setLabel(t('Language code')) - ->setDescription(t('The language code of CloudScript entity.')); - - return $fields; - } - -} diff --git a/modules/cloud_script/src/Entity/CloudScriptViewsData.php b/modules/cloud_script/src/Entity/CloudScriptViewsData.php deleted file mode 100644 index 83fc9a4..0000000 --- a/modules/cloud_script/src/Entity/CloudScriptViewsData.php +++ /dev/null @@ -1,29 +0,0 @@ - 'id', - 'title' => t('Cloud Scripts'), - 'help' => t('The cloud_script entity ID.'), - ]; - - return $data; - } - -} diff --git a/modules/cloud_script/src/Form/CloudScriptDeleteForm.php b/modules/cloud_script/src/Form/CloudScriptDeleteForm.php deleted file mode 100644 index 94af22b..0000000 --- a/modules/cloud_script/src/Form/CloudScriptDeleteForm.php +++ /dev/null @@ -1,17 +0,0 @@ -entity; - - $form['name'] = [ - '#type' => 'textfield', - '#title' => $this->t('Name'), - '#maxlength' => 255, - '#size' => 60, - '#default_value' => $entity->label(), - '#required' => TRUE, - '#weight' => -5, - ]; - /* - $form['cloud_context'] = array( - '#type' => 'textfield', - '#title' => $this->t('Cloud ID'), - '#maxlength' => 255, - '#size' => 60, - '#default_value' => !$entity->isNew() - ? $entity->cloud_context() - : $cloud_context, - '#required' => TRUE, - '#weight' => -5, - '#disabled' => TRUE, - ); - */ - $form['description'] = [ - '#type' => 'textarea', - '#title' => $this->t('Description'), - '#cols' => 60, - '#rows' => 3, - '#default_value' => $entity->description(), - '#weight' => -5, - '#required' => FALSE, - ]; - - $form['type'] = [ - '#type' => 'textfield', - '#title' => $this->t('Type'), - '#size' => 60, - '#default_value' => $entity->type(), - '#weight' => -5, - '#required' => FALSE, - ]; - - $form['input_parameters'] = [ - '#type' => 'textfield', - '#title' => $this->t('Input Prameters'), - '#size' => 60, - '#default_value' => $entity->input_parameters(), - '#weight' => -5, - '#required' => FALSE, - ]; - - $form['script'] = [ - '#type' => 'textarea', - '#title' => $this->t('Script'), - '#cols' => 60, - '#rows' => 3, - '#default_value' => $entity->description(), - '#weight' => -5, - '#required' => FALSE, - ]; - - $form['langcode'] = [ - '#title' => t('Language'), - '#type' => 'language_select', - '#default_value' => $entity->getUntranslated()->language()->getId(), - '#languages' => Language::STATE_ALL, - ]; - - $form['actions'] = $this->actions($form, $form_state, $cloud_context); - - return $form; - } - -} diff --git a/modules/cloud_script/src/Form/CloudScrptSettingsForm.php b/modules/cloud_script/src/Form/CloudScrptSettingsForm.php deleted file mode 100644 index 39f1074..0000000 --- a/modules/cloud_script/src/Form/CloudScrptSettingsForm.php +++ /dev/null @@ -1,73 +0,0 @@ -actions($form, $form_state, $cloud_context); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function getOperations(EntityInterface $entity) { - $operations = parent::getOperations($entity); - foreach ($operations as $key => $operation) { - $operations[$key]['url'] - ->setRouteParameter('cloud_context', $entity->getCloudContext()); - } - return $operations; - } - -} diff --git a/modules/cloud_script/src/Tests/CloudScriptTest.php b/modules/cloud_script/src/Tests/CloudScriptTest.php deleted file mode 100644 index 6bcc3f5..0000000 --- a/modules/cloud_script/src/Tests/CloudScriptTest.php +++ /dev/null @@ -1,235 +0,0 @@ -drupalCreateUser([ - 'add cloud script', - 'list cloud script', - 'view cloud script', - 'edit cloud script', - 'delete cloud script', - ]); - $this->drupalLogin($web_user); - } - - /** - * Tests CRUD for scripting information. - */ - public function testCloudScript() { - - // Access to Scripting Menu - // $clouds = $this->getClouds(); - // foreach ($clouds as $cloud) {. - $cloud_context = 'default_cloud_context'; - - // List Scripting for Amazon EC2. - $this->drupalGet('/clouds/design/script'); - $this->assertResponse(200, t('HTTP 200: List | Scripting')); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - - $this->drupalGet('/clouds/design/script/add'); - - // Add a new scripting information. - $add = $this->createScriptingTestData(); - // 3 times. - for ($i = 0; $i < CLOUD_SCRIPTING_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $this->drupalPostForm('/clouds/design/script/add', - $add[$i], - t('Save')); - $this->assertResponse(200, t('HTTP 200: Add | A New CloudScript Form #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - $this->assertText(t('The scripts "@name" has been saved.', [ - '@name' => $add[$i]['name'], - ]), - t('Confirm Message') . ': ' - . t('The scripts "@name" has been saved.', [ - '@name' => $add[$i]['name'], - ]) - ); - $this->assertText($add[$i]['name'], - t('Name: @name ', [ - '@name' => $add[$i]['name'], - ])); - - // Make sure listing. - $this->drupalGet('/clouds/design/script'); - $this->assertResponse(200, t('HTTP 200: List | Scripting #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertText($add[$j]['name'], - t("Make sure w/ Listing @num: @name", [ - '@num' => $j + 1, - '@name' => $add[$j]['name'], - ])); - } - } - - // Edit case. - $edit = $this->createScriptingTestData(); - // 3 times. - for ($i = 0; $i < CLOUD_SCRIPTING_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $this->drupalPostForm("/clouds/design/script/$num/edit", - $edit[$i], - t('Save')); - $this->assertResponse(200, t('HTTP 200: Edit | A New Scripting Form #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); - $this->assertText(t('The scripts "@name" has been saved.', [ - '@name' => $edit[$i]['name'], - ]), - t('Confirm Message') . ': ' - . t('The scripts "@name" has been saved.', [ - '@name' => $edit[$i]['name'], - ]) - ); - $this->assertText($edit[$i]['name'], - t('Name: @name ', [ - '@name' => $edit[$i]['name'], - ])); - - // Make sure listing. - $this->drupalGet('/clouds/design/script'); - $this->assertResponse(200, t('HTTP 200: List | Scripting #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertText($edit[$j]['name'], - t("Make sure w/ Listing @num: @name", [ - '@num' => $j + 1, - '@name' => $edit[$j]['name'], - ])); - } - } - - // Delete scripting Items - // 3 times. - for ($i = 0; $i < CLOUD_SCRIPTING_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - $this->drupalGet("/clouds/design/script/$num/delete"); - $this->drupalPostForm("/clouds/design/script/$num/delete", - [], - t('Delete')); - $this->assertResponse(200, t('HTTP 200: Delete | Scripting #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - - // Make sure listing. - $this->drupalGet('/clouds/design/script'); - $this->assertResponse(200, t('HTTP 200: List | Scripting #@num', ['@num' => $num])); - $this->assertNoText(t('Notice'), t('Make sure w/o Notice')); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - for ($j = 0; $j < $i + 1; $j++) { - $this->assertNoText($edit[$j]['name'], - t("Make sure w/ Listing @num: @name", [ - '@num' => $j + 1, - '@name' => $edit[$j]['name'], - ])); - } - } - - // Filtering scripting information item - /* - $filter = array( - 'filter' => 't1', - 'operation' => 0, - ); - - $this->drupalPost('/clouds/design/script', $filter, t('Apply')); - $this->assertResponse(200, t('HTTP 200: Search Listings | Filter')); - $scripting_id = CLOUD_SCRIPTING_REPEAT_COUNT - 1 ; - $this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large'); - $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' )); - $this->assertNoText(t('warning'), t('Make sure w/o Warnings')); - */ - // end - // } // End of foreach. - } - - /** - * - */ - private function createScriptingTestData() { - - static $random; - if (!$random) { - $random = new Random(); - } - - $data = []; - // 3 times. - for ($i = 0; $i < CLOUD_SCRIPTING_REPEAT_COUNT; $i++) { - - $num = $i + 1; - - // Input Fields. - $data[$i] = [ - // 'cloud_context' => $cloud_context,. - 'name' => "Script #$num - " . date('Y/m/d') . $random->name(8, TRUE), - 'description' => "#$num: " . date('Y/m/d H:i:s - D M j G:i:s T Y') . $random->name(8, TRUE) - . ' - SimpleTest Scripting Description', - 'type' => 'Boot-' . $random->name(8, TRUE), - 'input_parameters' => "#$num: " . date('Y/m/d H:i:s - D M j G:i:s T Y') - . ' - SimpleTest Scripting Input Parameters', - 'script' => "#$num: " . date('Y/m/d H:i:s - D M j G:i:s T Y') - . ' - SimpleTest Scripting Script' . $random->string(32, TRUE), - ]; - } - return $data; - } - -} diff --git a/modules/cloud_script/src/templates/cloud_script.html.twig b/modules/cloud_script/src/templates/cloud_script.html.twig deleted file mode 100644 index 1d09377..0000000 --- a/modules/cloud_script/src/templates/cloud_script.html.twig +++ /dev/null @@ -1,22 +0,0 @@ -{# -/** - * @file cloud_script.html.twig - * Default theme implementation to present CloudScript data. - * - * This template is used when viewing a cloud_script entity's page, - * - * - * Available variables: - * - content: A list of content items. Use 'content' to print all content, or - * - attributes: HTML attributes for the container element. - * - * @see template_preprocess_cloud_script() - * - * @ingroup themeable - */ -#} - - {% if content %} - {{- content -}} - {% endif %} - diff --git a/modules/cloud_service_providers/aws_cloud/aws_cloud.info.yml b/modules/cloud_service_providers/aws_cloud/aws_cloud.info.yml index c1af5a8..42b5783 100644 --- a/modules/cloud_service_providers/aws_cloud/aws_cloud.info.yml +++ b/modules/cloud_service_providers/aws_cloud/aws_cloud.info.yml @@ -7,7 +7,6 @@ dependencies: - drupal:user - cloud - cloud_server_template - - cloud_pricing # core: 8.x # version: 8.x-1.x # project: cloud diff --git a/modules/cloud_service_providers/aws_cloud/aws_cloud_services/aws_cloud.services.inc b/modules/cloud_service_providers/aws_cloud/aws_cloud_services/aws_cloud.services.inc deleted file mode 100644 index f6ae8fd..0000000 --- a/modules/cloud_service_providers/aws_cloud/aws_cloud_services/aws_cloud.services.inc +++ /dev/null @@ -1,126 +0,0 @@ -hasPermission($cloud_context . ' ' . 'list instances') === FALSE) continue; - - $instances = cloud_get_instances($cloud_context, $filter_params ); - - if (empty($instances) === FALSE) { - - $instances_list = array(); - - foreach ($instances as $instance) { - - unset($instance['action_data']); // remove $instance['action_data'] since it is redundant - $instances_list[] = $instance; - } - - $all_instances_list = array_merge( $all_instances_list, $instances_list ); - } - } - - return array('servers', $all_instances_list); -} - -/** -* Callback for launching instances. -* -* @param object $instance -* @return object -*/ -function _aws_cloud_services_launch($cloud_context, $instance) { - - // Call launch instances function - - return (object) array( - 'instance_id' => $instance->instance_id, - 'uri' => services_resource_uri(array('instance', $instance->instance_id)), - ); -} - -/** -* Callback for retrieving instances. -* -* @param string $cloud_context -* @param string $instance_id -* @return object -*/ -function _aws_cloud_services_retrieve($cloud_context, $instance_id) { - - $instance_info = _aws_cloud_get_instance_details_by_id($cloud_context, $instance_id); - - return array('instance', $instance_info); -} - -/** -* Callback for deleting instances. -* -* @param string $instance_id -* @return object -*/ -function _aws_cloud_services_terminate($cloud_context, $instance_id) { - - // needs to implement - - return (object) array( - 'instance_id' => $instance_id, - 'uri' => services_resource_uri(array('instance', $instance_id)), - ); -} - -/** -* Access callback for the instances. -* -* @param string $op -* The operation that's going to be performed. -* @param array $args -* The arguments that will be passed to the callback. -* @return bool -* Whether access is given or not. -*/ -function _aws_cloud_services_access($op, $args) { - - $access = FALSE; - $cloud_context = $args[0]; - $instance_id = $args[1]; - - switch ($op) { - - case 'view': - $access = \Drupal::currentUser()->hasPermission($cloud_context . ' list instances'); - break; - - case 'launch': - // call launch instance function here - $access = \Drupal::currentUser()->hasPermission($cloud_context . ' launch instance'); - break; - - case 'terminate': - // call terminate instance function here - $access = \Drupal::currentUser()->hasPermission($cloud_context . ' terminate instance'); - break; - } - - return $access; -} diff --git a/modules/cloud_service_providers/aws_cloud/aws_cloud_services/aws_cloud_services.info.yml b/modules/cloud_service_providers/aws_cloud/aws_cloud_services/aws_cloud_services.info.yml deleted file mode 100644 index 74d793e..0000000 --- a/modules/cloud_service_providers/aws_cloud/aws_cloud_services/aws_cloud_services.info.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: 'AWS Cloud Services' -description: 'Sample Cloud Abstraction API implementation' -package: Cloud Service Provider -dependencies: - - aws_cloud -# core: 8.x -# version: 8.x-1.x -# project: cloud -type: module - -# Information added by Drupal.org packaging script on 2016-05-12 -version: '8.x-1.x-dev' -core: '8.x' -project: 'cloud' -datestamp: 1463012739 diff --git a/modules/cloud_service_providers/aws_cloud/aws_cloud_services/aws_cloud_services.install b/modules/cloud_service_providers/aws_cloud/aws_cloud_services/aws_cloud_services.install deleted file mode 100644 index d42eb59..0000000 --- a/modules/cloud_service_providers/aws_cloud/aws_cloud_services/aws_cloud_services.install +++ /dev/null @@ -1,11 +0,0 @@ - array( - 'retrieve' => array( - 'help' => 'Retrieves an instance', - 'file' => array('file' => 'inc', 'module' => 'aws_cloud.services'), - 'callback' => '_aws_cloud_services_retrieve', - 'access callback' => '_aws_cloud_services_access' , - 'access arguments' => array('view'), - 'access arguments append' => TRUE, - 'args' => array( - array( - 'name' => 'cloud_context', - 'type' => 'string', - 'description' => 'The cloud name of the instance to get', - 'source' => array('path' => '0'), - 'optional' => FALSE, - ), - array( - 'name' => 'instance_id', - 'type' => 'string', - 'description' => 'The instance id of the instance to get', - 'source' => array('path' => '1'), - 'optional' => FALSE, - ), - ), - ), - 'index' => array( - 'help' => 'Retrieve a listing of instances', - 'file' => array('file' => 'inc', 'module' => 'aws_cloud.services'), - 'callback' => '_aws_cloud_services_index', - 'access callback' => 'user_access', - 'access arguments' => array('access content'), - 'access arguments append' => FALSE, - ), -/* - 'launch' => array( - 'help' => 'Launch an instance', - 'file' => array('file' => 'inc', 'module' => 'aws_cloud.services'), - 'callback' => '_aws_cloud_services_launch', - 'access arguments' => array('launch'), - 'access arguments append' => FALSE, - 'args' => array( - array( - 'name' => 'instance', - 'type' => 'struct', - 'description' => 'The instance object', - 'source' => 'instance', - 'optional' => FALSE, - ), - ), - ), - 'terminate' => array( - 'help' => 'Delete an instance', - 'file' => array('file' => 'inc', 'module' => 'aws_cloud.services'), - 'callback' => '_aws_cloud_services_delete_instance', - 'access callback' => '_aws_cloud_services_access', - 'access arguments' => array('terminate'), - 'access arguments append' => TRUE, - 'args' => array( - array( - 'name' => 'instance_id', - 'type' => 'string', - 'description' => 'The instance id of the instance to delete', - 'source' => array('path' => '0'), - 'optional' => FALSE, - ), - ), - ), -*/ - ), - ); -}