diff --git a/.scripts/common.py b/.scripts/common.py index f928805..f1e3d5b 100644 --- a/.scripts/common.py +++ b/.scripts/common.py @@ -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 = { diff --git a/.scripts/validate_model.py b/.scripts/validate_model.py index 198b616..4ddce96 100644 --- a/.scripts/validate_model.py +++ b/.scripts/validate_model.py @@ -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}" @@ -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() \ No newline at end of file diff --git a/processes/create_Y2Ksales_cube.json b/processes/create_Y2Ksales_cube.json new file mode 100644 index 0000000..e6f7c76 --- /dev/null +++ b/processes/create_Y2Ksales_cube.json @@ -0,0 +1,65 @@ +{ + "@type":"Process", + "Name":"create_Y2Ksales_cube", + "HasSecurityAccess":false, + "Code@Code.link":"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" +} \ No newline at end of file diff --git a/processes/create_Y2Ksales_cube.ti b/processes/create_Y2Ksales_cube.ti new file mode 100644 index 0000000..d38fcc0 --- /dev/null +++ b/processes/create_Y2Ksales_cube.ti @@ -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 \ No newline at end of file