-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to using custom Ingestor for cloud resource specifications #1489
Merged
eiffel777
merged 10 commits into
ubccr:xdmod9.5
from
eiffel777:change-state-cloud-resource-specs
Feb 25, 2021
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
40c8b10
changing ingestion of cloud resource specs to use an Ingestor instead…
eiffel777 83aa9cf
updated comments and some test data
eiffel777 b3f008b
updating comments
eiffel777 0b8d928
Merge branch 'xdmod9.5' into change-state-cloud-resource-specs
eiffel777 661cd26
fixes for tests
eiffel777 8659446
change name of array element from start_date_ts to fact_date to be mo…
eiffel777 feb3f91
Merge branch 'xdmod9.5' into change-state-cloud-resource-specs
eiffel777 2038f22
fixing merge conflicts
eiffel777 f94d7de
fixing merge conflicts
eiffel777 d7f51de
Merge branch 'change-state-cloud-resource-specs' of https://github.co…
eiffel777 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
classes/ETL/Ingestor/CloudResourceSpecsStateTransformIngestor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
/* ========================================================================================== | ||
* This class simulates a Finite State Machine to reconstruct the start and end time of a specific | ||
* set of vcpus and memory for a cloud host. It get a set of rows that contains the vcpus and memory | ||
* sorted by resource, host and start time of the configuration. This list is iterated over and an end | ||
* time is set anytime a changed is detected in the number of vcpus or memory for a host. | ||
* | ||
* If no changes are found the current date is considered the end date of the configuration | ||
* | ||
* A -1 value for the vcpus and memory_mb means the host was not available on that day | ||
* | ||
* @author Greg Dean <gmdean@buffalo.edu> | ||
* @date 2021-01-27 | ||
*/ | ||
|
||
namespace ETL\Ingestor; | ||
|
||
use ETL\aOptions; | ||
use ETL\iAction; | ||
use ETL\aAction; | ||
use ETL\Configuration\EtlConfiguration; | ||
use ETL\EtlOverseerOptions; | ||
|
||
use Psr\Log\LoggerInterface; | ||
|
||
class CloudResourceSpecsStateTransformIngestor extends pdoIngestor implements iAction | ||
{ | ||
|
||
private $_instance_state; | ||
|
||
/** | ||
* @see ETL\Ingestor\pdoIngestor::__construct() | ||
*/ | ||
public function __construct(aOptions $options, EtlConfiguration $etlConfig, LoggerInterface $logger = null) | ||
{ | ||
parent::__construct($options, $etlConfig, $logger); | ||
|
||
$this->_end_time = $etlConfig->getVariableStore()->endDate ? date('Y-m-d H:i:s', strtotime($etlConfig->getVariableStore()->endDate)) : null; | ||
|
||
$this->resetInstance(); | ||
} | ||
|
||
private function initInstance($srcRecord) | ||
{ | ||
// Since we only get information for when a configuration changes we assume a configuration has an end date | ||
// of today unless we have a row that tells us otherwise | ||
$default_end_time = isset($this->_end_time) ? $this->_end_time : date('Y-m-d') . ' 23:59:59'; | ||
|
||
$this->_instance_state = array( | ||
'resource_id' => $srcRecord['resource_id'], | ||
'hostname' => $srcRecord['hostname'], | ||
'vcpus' => $srcRecord['vcpus'], | ||
'memory_mb' => $srcRecord['memory_mb'], | ||
'start_date_ts' => strtotime($srcRecord['fact_date'] . " 00:00:00"), | ||
'end_date_ts' => strtotime($default_end_time), | ||
'start_day_id' => date('Y', strtotime($srcRecord['fact_date'])) * 100000 + date('z', strtotime($srcRecord['fact_date'])) + 1, | ||
'end_day_id' => date('Y', strtotime($default_end_time)) * 100000 + date('z', strtotime($default_end_time)) + 1 | ||
); | ||
} | ||
|
||
private function resetInstance() | ||
{ | ||
$this->_instance_state = null; | ||
} | ||
|
||
private function updateInstance($srcRecord) | ||
{ | ||
// The -1 is to make sure we use the last second of the previous day | ||
$end_date_timestamp = strtotime($srcRecord['fact_date'] . " 00:00:00") - 1; | ||
$this->_instance_state['end_date_ts'] = $end_date_timestamp; | ||
|
||
// date(z) is zero indexed so +1 is needed to get the correct day of the year | ||
$this->_instance_state['end_day_id'] = date('Y', $end_date_timestamp) * 100000 + date('z', $end_date_timestamp) + 1; | ||
} | ||
|
||
/** | ||
* @see ETL\Ingestor\pdoIngestor::transform() | ||
*/ | ||
protected function transform(array $srcRecord, &$orderId) | ||
{ | ||
// We want to just flush when we hit the dummy row | ||
if ($srcRecord['fact_date'] === 0) { | ||
if (isset($this->_instance_state)) { | ||
return array($this->_instance_state); | ||
} else { | ||
return array(); | ||
} | ||
} | ||
|
||
if ($this->_instance_state === null) { | ||
if($srcRecord['vcpus'] == -1 && $srcRecord['memory_mb'] == -1) { | ||
return array(); | ||
} | ||
|
||
$this->initInstance($srcRecord); | ||
} | ||
|
||
$transformedRecord = array(); | ||
|
||
if (($this->_instance_state['hostname'] != $srcRecord['hostname']) || ($this->_instance_state['resource_id'] != $srcRecord['resource_id']) || ($this->_instance_state['vcpus'] != $srcRecord['vcpus'] || $this->_instance_state['memory_mb'] != $srcRecord['memory_mb'])) { | ||
|
||
// Only update the instance if the only thing that is different between $srcRecord and $this->_instance_state is that either the memory or vcpus changed | ||
if (($this->_instance_state['vcpus'] != $srcRecord['vcpus'] || $this->_instance_state['memory_mb'] != $srcRecord['memory_mb']) | ||
&& ($this->_instance_state['hostname'] == $srcRecord['hostname']) && ($this->_instance_state['resource_id'] == $srcRecord['resource_id'])) { | ||
$this->updateInstance($srcRecord); | ||
} | ||
|
||
$transformedRecord[] = $this->_instance_state; | ||
$this->resetInstance(); | ||
|
||
// Under most circumstances when we detect a change we want to start a new row with data from the row that has changed. This is not | ||
// the case when the change detected is a -1 value for vcpus or memory_mb. When vcpus or memory_mb is -1 it means the host has been | ||
// removed and we just want to end the row and not create a new row. | ||
if($srcRecord['vcpus'] != -1 && $srcRecord['memory_mb'] != -1) { | ||
$this->initInstance($srcRecord); | ||
} | ||
} | ||
|
||
return $transformedRecord; | ||
} | ||
|
||
protected function getSourceQueryString() | ||
{ | ||
$sql = parent::getSourceQueryString(); | ||
|
||
// Due to the way the Finite State Machine handles the rows in event reconstruction, the last row | ||
// is lost. To work around this we add a dummy row filled with zeroes. | ||
$colCount = count($this->etlSourceQuery->records); | ||
$unionValues = array_fill(0, $colCount, 0); | ||
$sql .= "\nUNION ALL\nSELECT " . implode(',', $unionValues) . "\nORDER BY 1 DESC, 2 ASC, 5 ASC"; | ||
|
||
return $sql; | ||
} | ||
|
||
public function transformHelper(array $srcRecord) | ||
{ | ||
$orderId = 0; | ||
return $this->transform($srcRecord, $orderId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
configuration/etl/etl_action_defs.d/cloud_common/resource_specifications_transformer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"table_definition": { | ||
"$ref": "${table_definition_dir}/cloud_common/cloud_resource_specs.json#/table_definition" | ||
}, | ||
"destination_record_map": { | ||
"cloud_resource_specs": { | ||
"resource_id": "resource_id", | ||
"hostname": "hostname", | ||
"vcpus": "vcpus", | ||
"memory_mb": "memory_mb", | ||
"start_date_ts": "start_date_ts", | ||
"end_date_ts": "end_date_ts", | ||
"start_day_id": "start_day_id", | ||
"end_day_id": "end_day_id" | ||
} | ||
}, | ||
"source_query": { | ||
"records": { | ||
"resource_id": "srs.resource_id", | ||
"hostname": "srs.hostname", | ||
"vcpus": "srs.vcpus", | ||
"memory_mb": "srs.memory_mb", | ||
"fact_date": "srs.fact_date", | ||
"start_date_ts": -1, | ||
"end_date_ts": -1, | ||
"start_day_id": -1, | ||
"end_day_id": -1 | ||
}, | ||
"joins": [{ | ||
"name": "staging_resource_specifications", | ||
"schema": "${SOURCE_SCHEMA}", | ||
"alias": "srs" | ||
}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...s/xdmod/etlv2/configuration/input/etl_action_defs_8.0.0.d/cloud_resource_specs_state.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"table_definition": { | ||
"$ref": "../etl_tables_8.0.0.d/cloud_resource_specs.json#/table_definition" | ||
}, | ||
"destination_record_map": { | ||
"cloud_resource_specs": { | ||
"resource_id": "resource_id", | ||
"hostname": "hostname", | ||
"vcpus": "vcpus", | ||
"memory_mb": "memory_mb", | ||
"start_date_ts": "start_date_ts", | ||
"end_date_ts": "end_date_ts", | ||
"start_day_id": "start_day_id", | ||
"end_day_id": "end_day_id" | ||
} | ||
}, | ||
"source_query": { | ||
"records": { | ||
"resource_id": "srs.resource_id", | ||
"hostname": "srs.hostname", | ||
"vcpus": "srs.vcpus", | ||
"memory_mb": "srs.memory_mb", | ||
"start_date_ts": "srs.fact_date", | ||
"end_date_ts": -1, | ||
"start_day_id": -1, | ||
"end_day_id": -1 | ||
}, | ||
"joins": [{ | ||
"name": "staging_resource_specifications", | ||
"schema": "${SOURCE_SCHEMA}", | ||
"alias": "srs" | ||
}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What scenario is handled here? When would you have the first record have vcpus and memory_mb as -1?