AYON Cpp Api  0.1.0
Loading...
Searching...
No Matches
AyonApi Class Reference

Central Ayon api class Class for exposing Ayon server functions to C++ users. More...

#include <AyonCppApi.h>

Collaboration diagram for AyonApi:

Public Member Functions

 AyonApi (const std::optional< std::string > &logFilePos, const std::string &authKey, const std::string &serverUrl, const std::string &ayonProjectName, const std::string &siteId, std::optional< int > concurrency=std::nullopt)
 Constructor. More...
 
 ~AyonApi ()
 Destructor. More...
 
std::string getKey ()
 Returns the stored API key. More...
 
std::string getUrl ()
 Returns the stored AYON server URL. More...
 
nlohmann::json GET (const std::shared_ptr< std::string > endPoint, const std::shared_ptr< httplib::Headers > headers, uint8_t successStatus)
 Runs a GET command. More...
 
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 > successStatus)
 POST request via a shared httplib client (serial) More...
 
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 > successStatus)
 HTTP POST request utilizing the creation of a new httplib client (Generative Async) More...
 
std::pair< std::string, std::string > resolvePath (const std::string &uriPath)
 Uses the URI resolve endpoint on the AYON server to resolve a URI path to the local path. More...
 
std::unordered_map< std::string, std::string > batchResolvePath (std::vector< std::string > &uriPaths)
 Resolves a vector of paths against the AYON server asynchronously using auto-generated batch requests. More...
 
std::pair< std::string, std::string > getAssetIdent (const nlohmann::json &uriResolverResponse)
 Takes an AYON path URI response (resolved ayon://path) and returns a pair of asset identifier (ayon:// path) and the machine local file location. More...
 
std::shared_ptr< AyonLogger > logPointer ()
 Get function for shared AyonLogger pointer used by this class instance. More...
 
const std::unordered_map< std::string, std::string > & getSiteRoots ()
 Gets the site root overwrites for the current project. More...
 
std::string rootReplace (const std::string &rootLessPath)
 Replaces {root[var]} for ayon:// paths. More...
 

Private Member Functions

std::string serialCorePost (const std::string &endPoint, httplib::Headers headers, std::string &payload, const int &successStatus)
 Calls the server in a serial way by sharing the AyonServer pointer. More...
 
std::string generativeCorePost (const std::string &endPoint, httplib::Headers headers, std::string &payload, const int &successStatus)
 Calls the server while creating a new client instance to stay async. More...
 
std::string convertUriVecToString (const std::vector< std::string > &uriVec)
 Converts a vector of URIs into a string to serve into CorePost functions. More...
 
bool isSSL () const
 Checks if the m_ayonServer is running on SSL based on m_serverUrl Simple implementation - httplib's built-in check is not working. More...
 
void setSSL ()
 Sets the SSL cert path for the m_ayonServer httplib client. More...
 

Private Attributes

std::unique_ptr< httplib::Client > m_ayonServer
 
std::shared_ptr< AyonLogger > m_log
 
const std::string m_authKey
 
const std::string m_serverUrl
 
std::string m_ayonProjectName
 
std::string m_siteId
 
const int m_numThreads
 
std::unordered_map< std::string, std::string > m_siteRoots
 
httplib::Headers m_headers
 
std::string m_userName
 
bool m_serverBusy = false
 
std::string m_uriResolverEndpoint = "/api/resolve"
 
std::string m_uriResolverEndpointPathOnlyVar = "?pathOnly=true"
 
bool m_pathOnlyResolution = true
 
bool m_batchResolveOptimizeVector = true
 Decides if the cpp API removes duplicates from batch request vector. More...
 
uint8_t m_minGroupSizeForAsyncRequests = 10
 
uint16_t m_regroupSizeForAsyncRequests = 200
 
uint16_t m_maxGroupSizeForAsyncRequests = 300
 
uint16_t m_minVecSizeForGroupSplitAsyncRequests = 50
 
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
 
std::mutex m_ayonServerMutex
 
std::mutex m_concurrentRequestAfterServerBusyMutex
 
std::condition_variable m_serverBusyCondVar
 
uint8_t m_maxConcurrentRequestsAfterServerBusy = 8
 

Detailed Description

Central Ayon api class Class for exposing Ayon server functions to C++ users.

Uses httplib internally for communication with the server

Constructor & Destructor Documentation

◆ AyonApi()

AyonApi::AyonApi ( const std::optional< std::string > &  logFilePos,
const std::string &  authKey,
const std::string &  serverUrl,
const std::string &  ayonProjectName,
const std::string &  siteId,
std::optional< int >  concurrency = std::nullopt 
)

Constructor.

Here is the call graph for this function:

◆ ~AyonApi()

AyonApi::~AyonApi ( )

Destructor.

Member Function Documentation

◆ batchResolvePath()

std::unordered_map< std::string, std::string > AyonApi::batchResolvePath ( std::vector< std::string > &  uriPaths)

Resolves a vector of paths against the AYON server asynchronously using auto-generated batch requests.

Parameters
uriPathsThe vector of URI paths to resolve.
Returns
An unordered map containing the resolved paths.
Here is the call graph for this function:

◆ convertUriVecToString()

std::string AyonApi::convertUriVecToString ( const std::vector< std::string > &  uriVec)
private

Converts a vector of URIs into a string to serve into CorePost functions.

Parameters
uriVecVector of string URIs.

◆ CPOST()

nlohmann::json AyonApi::CPOST ( const std::shared_ptr< std::string >  endPoint,
const std::shared_ptr< httplib::Headers >  headers,
nlohmann::json  jsonPayload,
const std::shared_ptr< uint8_t >  successStatus 
)

HTTP POST request utilizing the creation of a new httplib client (Generative Async)

Parameters
endPointThe AYON endpoint to hit
headersThe HTTP headers to send
jsonPayloadThe payload in JSON format
successStatusDefines what status code is considered a success and breaks the retry loop.
Returns
The response body as nlohmann::json
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generativeCorePost()

std::string AyonApi::generativeCorePost ( const std::string &  endPoint,
httplib::Headers  headers,
std::string &  payload,
const int &  successStatus 
)
private

Calls the server while creating a new client instance to stay async.

Parameters
endPointEndpoint that AYON resolve is loaded on.
headersHTTP headers.
payloadJSON payload to be resolved by endpoint.
successStatusDefines what is considered a success response to break the retry loop.
Here is the caller graph for this function:

◆ GET()

nlohmann::json AyonApi::GET ( const std::shared_ptr< std::string >  endPoint,
const std::shared_ptr< httplib::Headers >  headers,
uint8_t  successStatus 
)

Runs a GET command.

Parameters
endPointReachable HTTP/HTTPS endpoint
headersHTTP headers
successStatusDefines what HTTP response code should be considered a success.
Returns
The response body as nlohmann::json
Here is the caller graph for this function:

◆ getAssetIdent()

std::pair< std::string, std::string > AyonApi::getAssetIdent ( const nlohmann::json &  uriResolverResponse)

Takes an AYON path URI response (resolved ayon://path) and returns a pair of asset identifier (ayon:// path) and the machine local file location.

Parameters
uriResolverResponseJSON representation of the response from the AYON API resolve endpoint.
Returns
A pair containing the asset identifier and the machine local file location.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getKey()

std::string AyonApi::getKey ( )

Returns the stored API key.

Passed in the constructor.

◆ getSiteRoots()

const std::unordered_map< std::string, std::string > & AyonApi::getSiteRoots ( )

Gets the site root overwrites for the current project.

Current project is defined via an env variable for now

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUrl()

std::string AyonApi::getUrl ( )

Returns the stored AYON server URL.

Passed in the constructor.

◆ isSSL()

bool AyonApi::isSSL ( ) const
private

Checks if the m_ayonServer is running on SSL based on m_serverUrl Simple implementation - httplib's built-in check is not working.

Returns
true if m_serverUrl starts with https://
Here is the caller graph for this function:

◆ logPointer()

std::shared_ptr< AyonLogger > AyonApi::logPointer ( )

Get function for shared AyonLogger pointer used by this class instance.

◆ resolvePath()

std::pair< std::string, std::string > AyonApi::resolvePath ( const std::string &  uriPath)

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.

Parameters
uriPathThe URI path to resolve.
Returns
A pair containing the asset identifier (ayon:// path) and the machine local file location.
Here is the call graph for this function:

◆ rootReplace()

std::string AyonApi::rootReplace ( const std::string &  rootLessPath)

Replaces {root[var]} for ayon:// paths.

Parameters
rootLessPathEndpoint response for ayon://path with {root[var]}. If no root can be found, the path will be returned as is.
Here is the caller graph for this function:

◆ serialCorePost()

std::string AyonApi::serialCorePost ( const std::string &  endPoint,
httplib::Headers  headers,
std::string &  payload,
const int &  successStatus 
)
private

Calls the server in a serial way by sharing the AyonServer pointer.

Parameters
endPointEndpoint that AYON resolve is loaded on.
headersHTTP headers.
payloadJSON payload to be resolved by endpoint.
successStatusDefines what is considered a success response to break the retry loop.
Here is the caller graph for this function:

◆ setSSL()

void AyonApi::setSSL ( )
private

Sets the SSL cert path for the m_ayonServer httplib client.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPOST()

nlohmann::json AyonApi::SPOST ( const std::shared_ptr< std::string >  endPoint,
const std::shared_ptr< httplib::Headers >  headers,
nlohmann::json  jsonPayload,
const std::shared_ptr< uint8_t >  successStatus 
)

POST request via a shared httplib client (serial)

Parameters
endPointThe AYON endpoint to hit
headersThe HTTP headers to send
jsonPayloadThe payload in JSON format
successStatusDefines what status code is considered a success and breaks the retry loop
Returns
The response body as nlohmann::json
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_authKey

const std::string AyonApi::m_authKey
private

◆ m_ayonProjectName

std::string AyonApi::m_ayonProjectName
private

◆ m_ayonServer

std::unique_ptr<httplib::Client> AyonApi::m_ayonServer
private

◆ m_ayonServerMutex

std::mutex AyonApi::m_ayonServerMutex
private

◆ m_batchResolveOptimizeVector

bool AyonApi::m_batchResolveOptimizeVector = true
private

Decides if the cpp API removes duplicates from batch request vector.

Default is true

◆ m_concurrentRequestAfterServerBusyMutex

std::mutex AyonApi::m_concurrentRequestAfterServerBusyMutex
private

◆ m_connectionTimeoutMax

uint16_t AyonApi::m_connectionTimeoutMax = 200
private

◆ m_generativeCorePostMaxLoopIterations

uint16_t AyonApi::m_generativeCorePostMaxLoopIterations = 200
private

◆ m_headers

httplib::Headers AyonApi::m_headers
private

◆ m_log

std::shared_ptr<AyonLogger> AyonApi::m_log
private

◆ m_maxCallRetries

uint8_t AyonApi::m_maxCallRetries = 8
private

◆ m_maxConcurrentRequestsAfterServerBusy

uint8_t AyonApi::m_maxConcurrentRequestsAfterServerBusy = 8
private

◆ m_maxGroupSizeForAsyncRequests

uint16_t AyonApi::m_maxGroupSizeForAsyncRequests = 300
private

◆ m_minGroupSizeForAsyncRequests

uint8_t AyonApi::m_minGroupSizeForAsyncRequests = 10
private

◆ m_minVecSizeForGroupSplitAsyncRequests

uint16_t AyonApi::m_minVecSizeForGroupSplitAsyncRequests = 50
private

◆ m_numThreads

const int AyonApi::m_numThreads
private

◆ m_pathOnlyResolution

bool AyonApi::m_pathOnlyResolution = true
private

◆ m_readTimeoutMax

uint8_t AyonApi::m_readTimeoutMax = 160
private

◆ m_regroupSizeForAsyncRequests

uint16_t AyonApi::m_regroupSizeForAsyncRequests = 200
private

◆ m_requestDelayWhenServerBusy

uint16_t AyonApi::m_requestDelayWhenServerBusy = 10000
private

◆ m_retryWait

uint16_t AyonApi::m_retryWait = 800
private

◆ m_serverBusy

bool AyonApi::m_serverBusy = false
private

◆ m_serverBusyCode

uint16_t AyonApi::m_serverBusyCode = 503
private

◆ m_serverBusyCondVar

std::condition_variable AyonApi::m_serverBusyCondVar
private

◆ m_serverUrl

const std::string AyonApi::m_serverUrl
private

◆ m_siteId

std::string AyonApi::m_siteId
private

◆ m_siteRoots

std::unordered_map<std::string, std::string> AyonApi::m_siteRoots
private

◆ m_uriResolverEndpoint

std::string AyonApi::m_uriResolverEndpoint = "/api/resolve"
private

◆ m_uriResolverEndpointPathOnlyVar

std::string AyonApi::m_uriResolverEndpointPathOnlyVar = "?pathOnly=true"
private

◆ m_userName

std::string AyonApi::m_userName
private

The documentation for this class was generated from the following files: