public static function generateInstances(\alojaweb\Filters\Filters $filters, $param_names, $params, $generalize, $db = null) { $filter_options = $filters->getFilterChoices(); $paramAllOptions = $tokens = $instances = array(); // Get info from clusters (Part of header_names!) $cluster_header_names = array('id_cluster' => 'Cluster', 'datanodes' => 'Datanodes', 'vm_OS' => 'VM.OS', 'vm_cores' => 'VM.Cores', 'vm_RAM' => 'VM.RAM', 'provider' => 'Provider', 'vm_size' => 'VM.Size', 'type' => 'Type'); $cluster_descriptor = array(); $query = "select " . implode(",", array_keys($cluster_header_names)) . " from aloja2.clusters;"; $rows = $db->get_rows($query); foreach ($rows as $row) { $cid = $row['id_cluster']; foreach (array_keys($cluster_header_names) as $cname) { $cluster_descriptor[$cid][$cname] = $row[$cname]; } } // If "No Clusters" -> All clusters if (empty($params['id_cluster'])) { $params['id_cluster'] = array(); $paramAllOptions['id_cluster'] = $filter_options['id_cluster']; foreach ($paramAllOptions['id_cluster'] as $par) { $params['id_cluster'][] = $par; } } // For each cluster selected, launch an instance... foreach ($params['id_cluster'] as $cl) { // Reduce the instance to the HW filter override, or even remove instance if no HW coincides $remove_if_no_props = FALSE; foreach (array_keys($cluster_header_names) as $cname) { if (!empty($params[$cname])) { // FIXME - When clusters have more than 1 characteristic, change this // Get only the current_props in params[cname] $current_props = $cluster_descriptor[$cl][$cname]; $current_props = array($current_props); $coincidences = array_intersect($current_props, $params[$cname]); if (empty($coincidences)) { $remove_if_no_props = TRUE; } else { $cluster_descriptor[$cl][$cname] = $coincidences; } } } if ($remove_if_no_props) { continue; } $cl_characteristics = "Cl" . Utils::multi_implode($cluster_descriptor[$cl], ','); $instance = ''; foreach ($param_names as $p) { // Ignore for now. Will be used at each cluster characteristics if (array_key_exists($p, $cluster_header_names) && $p != "id_cluster") { continue; } if ($p != "id_cluster") { if (array_key_exists($p, $filter_options)) { $paramAllOptions[$p] = $filter_options[$p]; } $tokens[$p] = ''; if ($generalize && empty($params[$p])) { $tokens[$p] = '*'; } elseif (!$generalize && empty($params[$p])) { foreach ($paramAllOptions[$p] as $par) { $tokens[$p] = $tokens[$p] . ($tokens[$p] != '' ? '|' : '') . ($p == 'comp' ? 'Cmp' : '') . ($p == 'id_cluster' ? 'Cl' : '') . $par; } } else { if (is_array($params[$p])) { foreach ($params[$p] as $par) { $tokens[$p] = $tokens[$p] . ($tokens[$p] != '' ? '|' : '') . ($p == 'comp' ? 'Cmp' : '') . ($p == 'id_cluster' ? 'Cl' : '') . $par; } } else { $tokens[$p] = $params[$p]; } } $instance = $instance . ($instance == '' ? '' : ',') . $tokens[$p]; } else { $instance = $instance . ($instance == '' ? '' : ',') . $cl_characteristics; } } $instances[] = $instance; } return $instances; }
public static function completeInstances(\alojaweb\Filters\Filters $filters, $instances, $param_names, $params, $db = null) { $filter_options = $filters->getFilterChoices(); // Fetch Network values $query = "SELECT MAX(n1.`maxtxkB/s`) AS maxtxkbs, MAX(n1.`maxrxkB/s`) AS maxrxkbs,\n\t\t\t \t MAX(n1.`maxtxpck/s`) AS maxtxpcks, MAX(n1.`maxrxpck/s`) AS maxrxpcks,\n\t\t\t\t MAX(n1.`maxtxcmp/s`) AS maxtxcmps, MAX(n1.`maxrxcmp/s`) AS maxrxcmps,\n\t\t\t\t MAX(n1.`maxrxmcst/s`) AS maxrxmscts,\n\t\t\t\t e1.net AS net, c1.vm_cores, c1.vm_RAM, c1.vm_size, c1.vm_OS, c1.provider\n\t\t\t FROM aloja2.precal_network_metrics AS n1,\n\t\t\t \t aloja2.execs AS e1 LEFT JOIN aloja2.clusters AS c1 ON e1.id_cluster = c1.id_cluster\n\t\t\t WHERE e1.id_exec = n1.id_exec\n\t\t\t GROUP BY e1.net, c1.vm_cores, c1.vm_RAM, c1.vm_size, c1.vm_OS, c1.provider"; $rows = $db->get_rows($query); if (empty($rows)) { throw new \Exception('Error retrieving precalculated data from Network. Metrics must be generated (enter into "Performance Metrics" page)'); } $netinfo = array(); foreach ($rows as $row) { $id = $row['net'] . '-' . $row['vm_cores'] . '-' . $row['vm_RAM'] . '-' . $row['vm_size'] . '-' . $row['vm_OS'] . '-' . $row['provider']; $netinfo[$id] = $row['maxtxkbs'] . ',' . $row['maxrxkbs'] . ',' . $row['maxtxpcks'] . ',' . $row['maxrxpcks'] . ',' . $row['maxtxcmps'] . ',' . $row['maxrxcmps'] . ',' . $row['maxrxmscts']; } // Fetch Disk values $query = "SELECT MAX(d1.maxtps) AS maxtps, MAX(d1.maxsvctm) as maxsvctm,\n\t\t\t\t MAX(d1.`maxrd_sec/s`) as maxrds, MAX(d1.`maxwr_sec/s`) as maxwrs,\n\t\t\t\t MAX(d1.maxrq_sz) as maxrqsz, MAX(d1.maxqu_sz) as maxqusz,\n\t\t\t\t MAX(d1.maxawait) as maxawait, MAX(d1.`max%util`) as maxutil,\n\t\t\t\t e2.disk AS disk, c1.vm_cores, c1.vm_RAM, c1.vm_size, c1.vm_OS, c1.provider\n\t\t\t FROM aloja2.precal_disk_metrics AS d1,\n\t\t\t\t aloja2.execs AS e2 LEFT JOIN aloja2.clusters AS c1 ON e2.id_cluster = c1.id_cluster\n\t\t\t WHERE e2.id_exec = d1.id_exec\n\t\t\t GROUP BY e2.disk, c1.vm_cores, c1.vm_RAM, c1.vm_size, c1.vm_OS, c1.provider"; $rows = $db->get_rows($query); if (empty($rows)) { throw new \Exception('Error retrieving precalculated data from Disks. Metrics must be generated (enter into "Performance Metrics" page)'); } $diskinfo = array(); foreach ($rows as $row) { $id = $row['disk'] . '-' . $row['vm_cores'] . '-' . $row['vm_RAM'] . '-' . $row['vm_size'] . '-' . $row['vm_OS'] . '-' . $row['provider']; $diskinfo[$id] = $row['maxtps'] . ',' . $row['maxsvctm'] . ',' . $row['maxrds'] . ',' . $row['maxwrs'] . ',' . $row['maxrqsz'] . ',' . $row['maxqusz'] . ',' . $row['maxawait'] . ',' . $row['maxutil']; } //For each instance, check NET & DISK, and expand/multiplicate $instances_expanded = array(); foreach ($instances as $inst_n) { if (empty($params['net'])) { $params['net'] = array(); $paramAllOptions['net'] = $filter_options['net']; foreach ($paramAllOptions['net'] as $par) { $params['net'][] = $par; } } $netpos = array_search('net', $param_names); // Multiple values -> decompose $diskpos = array_search('disk', $param_names); // Multiple values -> decompose $corepos = array_search('vm_cores', $param_names); // Unique value, due to decomposition by id_cluster $rampos = array_search('vm_RAM', $param_names); // Unique value, due to decomposition by id_cluster $sizepos = array_search('vm_size', $param_names); // Unique value, due to decomposition by id_cluster $ospos = array_search('vm_OS', $param_names); // Unique value, due to decomposition by id_cluster $providerpos = array_search('provider', $param_names); // Unique value, due to decomposition by id_cluster // Combinatory effort... $instances_l1 = array(); foreach ($params['net'] as $pnet) { $aux = explode(",", $inst_n); $aux[$netpos] = $pnet; $id = $pnet . '-' . $aux[$corepos] . '-' . $aux[$rampos] . '-' . $aux[$sizepos] . '-' . $aux[$ospos] . '-' . $aux[$providerpos]; if (array_key_exists($id, $netinfo)) { $aux[] = $netinfo[$id]; } else { $aux[] = "0,0,0,0,0,0,0"; } $instances_l1[] = implode(",", $aux); } foreach ($instances_l1 as $inst_d) { foreach ($params['disk'] as $pdisk) { $aux = explode(",", $inst_d); $aux[$diskpos] = $pdisk; $id = $pdisk . '-' . $aux[$corepos] . '-' . $aux[$rampos] . '-' . $aux[$sizepos] . '-' . $aux[$ospos] . '-' . $aux[$providerpos]; if (array_key_exists($id, $diskinfo)) { $aux[] = $diskinfo[$id]; } else { $aux[] = "0,0,0,0,0,0,0,0"; } $instances_expanded[] = implode(",", $aux); } } } return $instances_expanded; }
public function buildFilterGroups($customFilterGroups) { $this->filters->overrideFilterGroups($customFilterGroups); }