Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
af5b9e8
Correction of typos and comments in header file
tadeas-hejnic Feb 7, 2025
57b9b7a
Correction of typos and comments in source file
tadeas-hejnic Feb 7, 2025
3769082
Small adjustments in Instrumentor
tadeas-hejnic Feb 7, 2025
e3029f0
Small typos correction, the time calculation bug fixed
tadeas-hejnic Feb 7, 2025
f7637b5
Typo in file name correction in CMakeList
tadeas-hejnic Feb 7, 2025
f46d214
Typo in file name correction in header file include
tadeas-hejnic Feb 7, 2025
c9b2b73
Typos and inconsistence correction
tadeas-hejnic Feb 7, 2025
b0fea84
Typos and inconsistence correction
tadeas-hejnic Feb 7, 2025
0562879
TODOs for adding the exception message to warning - DONE
tadeas-hejnic Feb 7, 2025
fca3b60
Fix: default vars were not set after building with test vars
tadeas-hejnic Mar 3, 2025
6330598
Fix: error while building
tadeas-hejnic Mar 3, 2025
bc6f833
appDataFoulder.h -> appDataFolder.h
tadeas-hejnic Dec 17, 2025
1e8724b
extra handle for JTRACE
tadeas-hejnic Dec 17, 2025
9c919c1
merge
tadeas-hejnic Dec 17, 2025
1cbde64
remove duplicated lines
tadeas-hejnic Dec 17, 2025
aecf108
typo fix
tadeas-hejnic Dec 17, 2025
37259c8
typo fix
tadeas-hejnic Dec 17, 2025
d868e6e
typo in success
tadeas-hejnic Dec 17, 2025
0e3e80a
get back to prev version
tadeas-hejnic Dec 17, 2025
06e1807
checkout to latest impl of logger
tadeas-hejnic Dec 17, 2025
4f78984
add missing hashtag
tadeas-hejnic Dec 17, 2025
6bc2826
minor changes, m_headers use in resolvePath
tadeas-hejnic Jan 6, 2026
5d2e119
fixing naming convention diffs
tadeas-hejnic Jan 6, 2026
81ffa2e
code hygiene, variables order, naming convention, ...
tadeas-hejnic Jan 6, 2026
856ded5
m_Log -> m_log to match the naming convention
tadeas-hejnic Jan 6, 2026
f45f4e7
fix of variable name
tadeas-hejnic Jan 6, 2026
70ef824
fix of compiler errors
tadeas-hejnic Jan 6, 2026
1adbf5a
variable names fix
tadeas-hejnic Jan 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions AyonBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
AyonCppApiPrj.setup_prj()


SetDefaultVars = Project.Stage("SetDefaultVars")
SetDefaultVars.add_funcs(
Project.Func("", AyonCppApiPrj.setVar, "AYON_CPP_API_ENALBE_GBENCH", "OFF"),
Project.Func("", AyonCppApiPrj.setVar, "AYON_CPP_API_ENALBE_GTEST", "OFF"),
Comment on lines +24 to +25
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in variable names: 'ENALBE' should be 'ENABLE' in both GBENCH and GTEST variable names.

Copilot uses AI. Check for mistakes.
Project.Func("", AyonCppApiPrj.setVar, "JTRACE", "0"),
Project.Func("", AyonCppApiPrj.setVar, "ReleaseType", "Release"),
)
AyonCppApiPrj.add_stage(SetDefaultVars)

SetTestVars = Project.Stage("SetTestVars")
SetTestVars.add_funcs(
Project.Func("", AyonCppApiPrj.setVar, "AYON_CPP_API_ENALBE_GBENCH", "ON"),
Expand Down
2 changes: 1 addition & 1 deletion ext/ayon-cpp-dev-tools
452 changes: 226 additions & 226 deletions src/AyonCppApi/AyonCppApi.cpp

Large diffs are not rendered by default.

209 changes: 98 additions & 111 deletions src/AyonCppApi/AyonCppApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <utility>
#include <vector>
#include "lib/ynput/lib/logging/AyonLogger.hpp"
#include "appDataFoulder.h"
#include "appDataFolder.h"
#include "httplib.h"
#include "nlohmann/json_fwd.hpp"

Expand All @@ -21,14 +21,13 @@

/**
* @class AyonApi
* @brief Central Ayon api class \n
* @brief Central Ayon api class
* Class for exposing Ayon server functions to C++ users. Uses httplib internally for communication with the server
*
*/
class AyonApi {
public:
/**
* @brief constructor
* @brief Constructor
*/
AyonApi(const std::optional<std::string> &logFilePos,
const std::string &authKey,
Expand All @@ -37,205 +36,193 @@ class AyonApi {
const std::string &siteId,
std::optional<int> concurrency = std::nullopt);
/**
* @brief destructor
* @brief Destructor
*/
~AyonApi();

/**
* @brief returns the stored apikey. Retrieved from the appropriate env variable. (the variable is loaded from
* loadEnvVars())
* @brief Returns the stored API key. Passed in the constructor.
*/
std::string getKey();
/**
* @brief returns the stored AYON server url. Retrieved from the appropriate env variable. (the variable is
* loaded from loadEnvVars())
* @brief Returns the stored AYON server URL. Passed in the constructor.
*/
std::string getUrl();

/**
* @brief runns a get command and returns the response body as std::string
* @brief Runs a GET command
*
* @param endPoint reachable http / https endpoint
* @param headers http headers
* @param sucsessStatus define what http response code should be considered a success.
* @param endPoint Reachable HTTP/HTTPS endpoint
* @param headers HTTP headers
* @param successStatus Defines what HTTP response code should be considered a success.
* @return The response body as nlohmann::json
*/
nlohmann::json GET(const std::shared_ptr<std::string> endPoint,
const std::shared_ptr<httplib::Headers> headers,
uint8_t sucsessStatus);
uint8_t successStatus);

/**
* @brief post Request via a shared httplib client ( serial )
* @brief POST request via a shared httplib client (serial)
*
* @param endPoint the AYON enpoint to hit
* @param headers the http header that you want to send
* @param jsonPayload the payload in json format
* @param sucsessStatus defines what status code is considered a success and brakes the retry loop.
* @param endPoint The AYON endpoint to hit
* @param headers The HTTP headers to send
* @param jsonPayload The payload in JSON format
* @param successStatus Defines what status code is considered a success and breaks the retry loop
* @return The response body as nlohmann::json
*/
nlohmann::json SPOST(const std::shared_ptr<std::string> endPoint,
const std::shared_ptr<httplib::Headers> headers,
nlohmann::json jsonPayload,
const std::shared_ptr<uint8_t> sucsessStatus);
const std::shared_ptr<uint8_t> successStatus);
/**
* @brief http post request utilizing the creation of a new httplib client ( Generative Async )
* @brief HTTP POST request utilizing the creation of a new httplib client (Generative Async)
*
* @param endPoint the AYON enpoint to hit
* @param headers the http header that you want to send
* @param jsonPayload the payload in json format
* @param sucsessStatus defines what status code is considered a success and brakes the retry loop.
* @param endPoint The AYON endpoint to hit
* @param headers The HTTP headers to send
* @param jsonPayload The payload in JSON format
* @param successStatus Defines what status code is considered a success and breaks the retry loop.
* @return The response body as nlohmann::json
*/
nlohmann::json CPOST(const std::shared_ptr<std::string> endPoint,
const std::shared_ptr<httplib::Headers> headers,
nlohmann::json jsonPayload,
const std::shared_ptr<uint8_t> sucsessStatus);
const std::shared_ptr<uint8_t> successStatus);

/**
* @brief uses the uri resolve endpoint on the AYON server in order to resolve an uri path towards the local
* path \n gets the siteId from an variable stored in the class
* @brief Uses the URI resolve endpoint on the AYON server to resolve a URI path to the local path.
* Gets the siteId from a variable stored in the class.
*
* @param uriPath
* @param uriPath The URI path to resolve.
* @return A pair containing the asset identifier (ayon:// path) and the machine local file location.
*/
std::pair<std::string, std::string> resolvePath(const std::string &uriPath);

/**
* @brief resolves a vector off paths against the AYON server in an async way uses auto generated batch requests
* @brief Resolves a vector of paths against the AYON server asynchronously using auto-generated batch requests.
*
* @param uriPaths
* @param uriPaths The vector of URI paths to resolve.
* @return An unordered map containing the resolved paths.
*/
std::unordered_map<std::string, std::string> batchResolvePath(std::vector<std::string> &uriPaths);

/**
* @brief this function takes a ayon path uri response(resolved ayon://path) and returns a pair of
* assetIdentifier(ayon:// path) and the machine local file location
* @brief Takes an AYON path URI response (resolved ayon://path) and returns a pair of
* asset identifier (ayon:// path) and the machine local file location.
*
* @param uriResolverRespone json representation off the resolves the ayon/api/resolve endpoint returns
* @param uriResolverResponse JSON representation of the response from the AYON API resolve endpoint.
* @return A pair containing the asset identifier and the machine local file location.
*/
std::pair<std::string, std::string> getAssetIdent(const nlohmann::json &uriResolverRespone);
std::pair<std::string, std::string> getAssetIdent(const nlohmann::json &uriResolverResponse);

/**
* @brief get function for shared AyonLogger pointer used by this class instance
* @brief Get function for shared AyonLogger pointer used by this class instance
*/
std::shared_ptr<AyonLogger> logPointer();

/**
* @brief gets the site root overwrites for the current project. Current project is defined via an env variable
* @brief Gets the site root overwrites for the current project. Current project is defined via an env variable
* for now
*/
std::unordered_map<std::string, std::string>*
getSiteRoots(); // TODO think about if this should only support current project or multiple projects
const std::unordered_map<std::string, std::string>& getSiteRoots(); // TODO think about if this should only support current project or multiple projects

/**
* @brief replaces {root[var]} for ayon:// paths
* @brief Replaces {root[var]} for ayon:// paths.
*
* @param rootLessPath endpoint response for ayon://path with {root[var]} available if no root can be found the
* path will be returned as is
* @param rootLessPath Endpoint response for ayon://path with {root[var]}.
* If no root can be found, the path will be returned as is.
*/
std::string rootReplace(const std::string &rootLessPath);

private:
/**
* @brief calls the server in an serial way by sharing the AyonServer pointer
* @brief Calls the server in a serial way by sharing the AyonServer pointer.
*
* @param endPoint endpoint that ayon resolve is loaded on
* @param headers http headers
* @param Payload json payload to be resolved by endpoint
* @param sucsessStatus defines what is considered a success response to break the retry loop
* @param endPoint Endpoint that AYON resolve is loaded on.
* @param headers HTTP headers.
* @param payload JSON payload to be resolved by endpoint.
* @param successStatus Defines what is considered a success response to break the retry loop.
*/
std::string serialCorePost(const std::string &endPoint,
httplib::Headers headers,
std::string &Payload,
const int &sucsessStatus);
std::string &payload,
const int &successStatus);
/**
* @brief calls the server while creating a new client instance to stay async
* @brief Calls the server while creating a new client instance to stay async.
*
* @param endPoint endpoint that ayon resolve is loaded on
* @param headers http headers
* @param Payload json payload to be resolved by endpoint
* @param sucsessStatus defines what is considered a success response to break the retry loop
* @param endPoint Endpoint that AYON resolve is loaded on.
* @param headers HTTP headers.
* @param payload JSON payload to be resolved by endpoint.
* @param successStatus Defines what is considered a success response to break the retry loop.
*/
std::string GenerativeCorePost(const std::string &endPoint,
std::string generativeCorePost(const std::string &endPoint,
httplib::Headers headers,
std::string &Payload,
const int &sucsessStatus);
std::string &payload,
const int &successStatus);

/**
* @brief converts a vector off uris into an string to serve into CorePost funcs
* @brief Converts a vector of URIs into a string to serve into CorePost functions.
*
* @param uriVec vector off str uris
* @param uriVec Vector of string URIs.
*/
std::string convertUriVecToString(const std::vector<std::string> &uriVec);

/**
* @brief checks if the m_AyonServer is running on ssl based on m_serverUrl
* dumb implementation but it should work - function from httplib is not working
* @brief Checks if the m_ayonServer is running on SSL based on m_serverUrl
* Simple implementation - httplib's built-in check is not working
*
* @return true if m_serverUrl starts with https://
*/
bool isSSL() const;

/**
* @brief sets the ssl cert path for the m_AyonServer httplib client
* @brief Sets the SSL cert path for the m_ayonServer httplib client
*/
void setSSL();

std::unique_ptr<httplib::Client> m_AyonServer;

std::unordered_map<std::string, std::string> m_siteRoots;
// Core Dependencies
std::unique_ptr<httplib::Client> m_ayonServer;
std::shared_ptr<AyonLogger> m_log;

// ----- Env Varibles
// Configuration from Constructor
const std::string m_authKey;
const std::string m_serverUrl;
std::string m_ayonProjectName;

// ---- Server Vars
std::string m_siteId;
std::string m_userName;

// --- HTTP Headers
const int m_numThreads;

// Runtime State
std::unordered_map<std::string, std::string> m_siteRoots;
httplib::Headers m_headers;

// --- Runtime Dep Vars

// Async Grp Generation Varibles
uint8_t m_minGrpSizeForAsyncRequests = 10;
uint16_t m_regroupSizeForAsyncRequests = 200;
uint16_t m_maxGroupSizeForAsyncRequests = 300;
uint16_t m_minVecSizeForGroupSplitAsyncRequests = 50;
uint8_t m_maxCallRetrys = 8;
uint16_t m_retryWaight = 800;

/**
* @brief maximum number off threads that the cpu can handle at the same time. Will be set via constructor
*/
const int m_num_threads; // set by constructor
std::shared_ptr<AyonLogger> m_Log;
std::string m_userName;
bool m_serverBusy = false;

// URI Resolution Configuration
std::string m_uriResolverEndpoint = "/api/resolve";
std::string m_uriResolverEndpointPathOnlyVar = "?pathOnly=true";
bool m_pathOnlyReselution = true;

std::mutex m_ConcurentRequestAfterffoMutex;
uint8_t m_maxConcurentRequestAfterffo = 8;

uint16_t m_GenerativeCorePostMaxLoopIterations = 200;

uint16_t m_connectionTimeOutMax = 200;
uint8_t m_readTimeOutMax = 160;

bool m_pathOnlyResolution = true;

/**
* @brief decides if the cpp api removes duplicates from batch request vector default is true
* @brief Decides if the cpp API removes duplicates from batch request vector. Default is true
*/
bool m_batchResolveOptimizeVector = true;

uint16_t m_ServerBusyCode = 503;
uint16_t m_RequestDelayWhenServerBusy = 10000;

/**
* @brief this bool will be set to true if a 503 is encountered
*/
bool m_serverBusy = false;

/**
* @brief needed for serial resolve operations. to lock acces to AyonServer shared pointer
*/
std::mutex m_AyonServerMutex;
uint8_t m_minGroupSizeForAsyncRequests = 10;
uint16_t m_regroupSizeForAsyncRequests = 200;
uint16_t m_maxGroupSizeForAsyncRequests = 300;
uint16_t m_minVecSizeForGroupSplitAsyncRequests = 50;

// Retry and Timeout Configuration
uint8_t m_maxCallRetries = 8;
uint16_t m_retryWait = 800;
uint16_t m_serverBusyCode = 503;
uint16_t m_requestDelayWhenServerBusy = 10000;
uint16_t m_connectionTimeoutMax = 200;
uint8_t m_readTimeoutMax = 160;
uint16_t m_generativeCorePostMaxLoopIterations = 200;

// Thread Synchronization
std::mutex m_ayonServerMutex;
std::mutex m_concurrentRequestAfter503Mutex;
uint8_t m_maxConcurrentRequestsAfter503 = 8;
};

#endif // !AYONCPPAPI_H
2 changes: 1 addition & 1 deletion src/AyonCppApi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ install (
)

install (
FILES AyonCppApi.h appDataFoulder.h devMacros.h Instrumentor.h
FILES AyonCppApi.h appDataFolder.h devMacros.h Instrumentor.h
DESTINATION include
)
Loading