Skip to content

Commit

Permalink
Add create_Y2Ksales_cube process
Browse files Browse the repository at this point in the history
  • Loading branch information
Hubert-Heijkers committed May 9, 2024
1 parent 64fc04d commit 6e5c9fd
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def setup_session(username, password):
})
return session

def send_get_request(session, service_root_url, endpoint):
full_url = f"{service_root_url}/{endpoint}"
print(f"<<< GET {full_url}")
response = session.get(full_url)
return response.status_code, response

def send_post_request(session, service_root_url, endpoint, payload):
full_url = f"{service_root_url}/{endpoint}"
headers = {
Expand Down
31 changes: 30 additions & 1 deletion .scripts/validate_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def cleanup():
sys.exit(1)
log_output(f"Database {tm1_database_name} deleted!")

def dump_file_content(file_endpoint):
# Pull the content from the endpoint
status_code, response = send_get_request(session, tm1_service_root_url, f"{database_endpoint}/{file_endpoint}/Content")
if status_code == 200:
log_output(response.text)
else:
log_output(f"Failed to retrieve content from {file_endpoint}!", status_code, response)

# Create the database on our target TM1 service instance
database_create_payload = {
"Name": f"{tm1_database_name}"
Expand Down Expand Up @@ -76,6 +84,27 @@ def cleanup():
sys.exit(1)
log_output("GIT Pull plan executed successfully!")

# Execute the create_Y2Ksales_cube process to validate that it works
process_name = "create_Y2Ksales_cube"
status_code, response = send_post_request(session, tm1_service_root_url, f"{database_endpoint}/Processes('{process_name}')/tm1.ExecuteWithReturn?$expand=*", {})
if status_code != 201:
log_output(f"The request to execute the {process_name} process failed!", status_code, response)
cleanup()
sys.exit(1)
process_execute_status_code = response['ProcessExecuteStatusCode']
process_execute_log_file_name = response['ErrorLogFile']['Filename']
match process_execute_status_code:
case "Aborted":
log_output(f"Process {process_name} aborted.")
dump_file_content(f"Contents('Files')/Contents('.tmp')/Contents('{process_execute_log_file_name}')")
cleanup()
sys.exit(1)
case "CompletedSuccessfully":
log_output(f"Process {process_name} completed successfully.")
case _:
log_output(f"Process {process_name} returned status code: {process_execute_status_code}.")
dump_file_content(f"Contents('Files')/Contents('.tmp')/Contents('{process_execute_log_file_name}')")

# Last but not least, now that we're done testing, lets cleanup by removing the database
log_output("Model deployed successfully!")
log_output("Model deployed and validated successfully!")
cleanup()
65 changes: 65 additions & 0 deletions processes/create_Y2Ksales_cube.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"@type":"Process",
"Name":"create_Y2Ksales_cube",
"HasSecurityAccess":false,
"[email protected]":"create_Y2Ksales_cube.ti",
"DataSource":
{
"Type":"ASCII",
"dataSourceNameForServer":"y2ksales.cma",
"dataSourceNameForClient":"../Contents('Files')/Contents('y2ksales.cma')",
"asciiHeaderRecords":0,
"asciiQuoteCharacter":"\"",
"asciiDecimalSeparator":".",
"asciiThousandSeparator":",",
"asciiDelimiterType":"Character",
"asciiDelimiterChar":","
},
"Parameters":[],
"Variables":
[
{
"Name":"V2",
"Type":"String",
"Position":2,
"StartByte":0,
"EndByte":0
},
{
"Name":"V3",
"Type":"String",
"Position":3,
"StartByte":0,
"EndByte":0
},
{
"Name":"V4",
"Type":"String",
"Position":4,
"StartByte":0,
"EndByte":0
},
{
"Name":"V5",
"Type":"String",
"Position":5,
"StartByte":0,
"EndByte":0
},
{
"Name":"V6",
"Type":"String",
"Position":6,
"StartByte":0,
"EndByte":0
},
{
"Name":"V7",
"Type":"Numeric",
"Position":7,
"StartByte":0,
"EndByte":0
}
],
"UID": "17146564360003"
}
33 changes: 33 additions & 0 deletions processes/create_Y2Ksales_cube.ti
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#region Prolog

#****Begin: Generated Statements***
if ( CubeExists('Y2Ksales') <> 0 );
CubeDestroy('Y2Ksales');
endif;
DIMENSIONSORTORDER('region','','','BYINPUT','ASCENDING');
CUBECREATE('Y2Ksales','actvsbud','region','model','account1','month');
OldCubeLogChanges = CUBEGETLOGCHANGES('Y2Ksales');
CUBESETLOGCHANGES('Y2Ksales', 0);
#****End: Generated Statements****

#endregion
#region Metadata

#****Begin: Generated Statements***
DIMENSIONELEMENTINSERT('region','',V3,'n');
#****End: Generated Statements****

#endregion
#region Data

#****Begin: Generated Statements***
CellPutN(V7,'Y2Ksales',V2,V3,V4,V5,V6);
#****End: Generated Statements****

#endregion
#region Epilog

#****Begin: Generated Statements***
CUBESETLOGCHANGES('Y2Ksales', OldCubeLogChanges);
#****End: Generated Statements****
#endregion

0 comments on commit 6e5c9fd

Please sign in to comment.