Skip to content

Commit

Permalink
Clean Jupyter Notebooks
Browse files Browse the repository at this point in the history
Also fix regression of 6e48e72
  • Loading branch information
philippeVerney committed Jan 16, 2025
1 parent 98ae973 commit 8a2f1d8
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 48 deletions.
35 changes: 19 additions & 16 deletions cmake/swigEtp1_2Include.i.in
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ namespace ETP_NS
/**
* A customer sends to a store to discover all dataspaces available on the store.
* This function should be used with caution if Dataspace Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param storeLastWriteFilter An optional filter to limit the dataspaces returned by date/time last saved to the store.
* The store returns a list of dataspaces whose last changed date/time is greater than the specified date/time.
Expand All @@ -1934,7 +1934,7 @@ namespace ETP_NS
/**
* A customer sends to a store to create one or more dataspaces.
* This function should be used with caution if Dataspace Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param dataspaces ETP general map : One each for each dataspace the customer wants to add or update.
* @param return The map keys corresponding to the dataspaces which have been put successfully into the store.
Expand All @@ -1944,7 +1944,7 @@ namespace ETP_NS
/**
* A customer sends to a store to delete one or more dataspaces.
* This function should be used with caution if Dataspace Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param dataspaceUris ETP general map where the values must be the URIs for the dataspaces the customer wants to delete.
* @param return The map keys corresponding to the dataspaces which have been deleted successfully.
Expand All @@ -1958,7 +1958,7 @@ namespace ETP_NS
/**
* A customer sends to a store to discover information of particular dataspaces.
* This function should be used with caution if Dataspace OSDU Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param dataspaceUris ETP general map : One each for each dataspace, identified by their URI, the customer wants to get info about.
* @param return The dataspaces the store could return.
Expand All @@ -1968,7 +1968,7 @@ namespace ETP_NS
/**
* Copy by reference some dataspaces into another one.
* This function should be used with caution if Dataspace OSDU Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param sourceDataspaceUris ETP general map : One each for each source dataspace to be copied. They are identified by their URI.
* @param targetDataspaceUri The URI of the ETP dataspace where the sourceDataspaces have to be copied by reference.
Expand All @@ -1979,7 +1979,7 @@ namespace ETP_NS
/**
* A customer sends to a store to lock or unlock one or more dataspaces.
* This function should be used with caution if Dataspace OSDU Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param dataspaceUris ETP general map where the values must be the URIs for the dataspaces the customer wants to lock or unlock.
* @param lock true for locking the dataspaces, false to unlock the dataspaces
Expand All @@ -1990,7 +1990,7 @@ namespace ETP_NS
/**
* Copy by reference some dataobjects into another dataspace.
* This function should be used with caution if Dataspace OSDU Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param sourceUris ETP general map : One each for each source dataobject to be copied. They are identified by their URI.
* @param targetDataspaceUri The URI of the ETP dataspace where the source dataobjects have to be copied by reference.
Expand All @@ -2005,7 +2005,7 @@ namespace ETP_NS
/**
* A Customer sends this message to a store to discover data objects in the store.
* This function should be used with caution if Discovery Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param context Includes the URI of the dataspace or data object to begin the discovery, what specific types of data objects are of interest,
* and how many "levels" of relationships in the model to discover, among others.
Expand All @@ -2026,7 +2026,7 @@ namespace ETP_NS
/**
* A customer sends to a store to discover data objects that have been deleted (which are sometimes called "tombstones").
* This function should be used with caution if Discovery Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param dataspaceUri The URI of the dataspace where the objects were deleted.
* @param deleteTimeFilter An optional filter to filter the discovery on a date when the data object was deleted in a particular store.
Expand All @@ -2047,7 +2047,7 @@ namespace ETP_NS
/**
* A customer sends to a store to get one or more data objects, each identified by a URI.
* This function should be used with caution if Store Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param uris ETP general map where the values MUST be the URIs of a data object to be retrieved.
* @param return The received dataobjects in a map where the key makes the link between the asked uris and the received dataobjects.
Expand All @@ -2057,7 +2057,7 @@ namespace ETP_NS
/**
* A customer sends to a store to add or update one or more data objects.
* This function should be used with caution if Store Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param uris ETP general map where the values MUST be the data for each data object in the request, including each one's URI.
* @param return The map keys corresponding to the dataObjects which have been put successfully.
Expand All @@ -2067,7 +2067,7 @@ namespace ETP_NS
/**
* A customer sends to a store to delete one or more data objects from the store.
* This function should be used with caution if Store Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param uris ETP general map where the values MUST be the URIs of a data object to be deleted.
* @param return The map keys corresponding to the dataObjects which have been deleted successfully.
Expand All @@ -2081,26 +2081,29 @@ namespace ETP_NS
/**
* A customer sends to a store to begin a transaction.
* This function should be used with caution if Transaction Handlers have been overidden.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
*
* @param dataspaceUris Indicates the dataspaces involved in the transaction. An empty STRING means the default dataspace. An empty LIST means all dataspaces.
* @param readOnly Indicates that the request in the transaction is read-only (i.e., "get" messages).
* @param readOnly Indicates that the request in the transaction is read-only (i.e., "get" messages).
* @return Failure message or empty string if success
*/
std::string startTransaction(std::vector<std::string> dataspaceUris = {}, bool readOnly = false);

/**
* A customer sends to a store to commit and end a transaction. This message implies that the customer
* has received from or sent to the store all the data required for some purpose. The customer asserts that
* the data sent in the scope of this transaction is a consistent unit of work.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
* @return Failure message or empty string if success
*/
std::string rollbackTransaction();

/*
* A customer sends to a store to cancel a transaction. The store MUST disregard any requests or data sent
* with that transaction. The current transaction (the one being canceled) MUST NOT change the state of
* the store.
* It actually sends a message and block the current thread untill a response has been received from the store.
* It actually sends a message and block the current thread until a response has been received from the store.
* @return Failure message or empty string if success
*/
std::string commitTransaction();

Expand Down
23 changes: 15 additions & 8 deletions python/example/PutHorizon.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"id": "a16222c5-064e-431d-9dae-d3d6c535a6b9",
"metadata": {},
"source": [
"Once FETPAPI wheel installed, you need to first import FESAPI (required dependency) and then fetpapi it in order to be able to call its API."
"Once FETPAPI wheel installed, you need to first import FESAPI (required dependency) and then fetpapi in order to be able to call its API."
]
},
{
Expand Down Expand Up @@ -176,7 +176,7 @@
"if (len(successKeys) == 1):\n",
" print(\"Dataspace has been put\")\n",
"else:\n",
" print(\"Error when putting dataspace\")"
" print(\"Error when putting dataspace. Already present?\")"
]
},
{
Expand All @@ -203,7 +203,7 @@
" fesapi.eml20__LengthUom_m, \"Unknown\",\n",
" False)\n",
"repo.setDefaultCrs(local_3d_crs)\n",
"repo.setHdfProxyFactory(fetpapi.FesapiHdfProxyFactory(client_session));\n",
"repo.setHdfProxyFactory(fetpapi.FesapiHdfProxyFactory(client_session))\n",
"hdf_proxy = repo.createHdfProxy(\"f8160b8f-0517-4c55-ab6e-ed8bcdc87111\", \"Hdf Proxy\",\n",
" \".\", \"fake.h5\",\n",
" fesapi.DataObjectRepository.openingMode_OVERWRITE)\n",
Expand Down Expand Up @@ -233,7 +233,9 @@
"# Create first a transaction in order to be able to rollback if necessary and to easier resolve dependencies to put\n",
"dataspacesToLock = fetpapi.StringVector()\n",
"dataspacesToLock.append(dataspace.uri)\n",
"client_session.startTransaction(dataspacesToLock)\n",
"transactionFailure = client_session.startTransaction(dataspacesToLock)\n",
"if (transactionFailure):\n",
" print (transactionFailure)\n",
"# And let's set a 2x3 geometry on this 2d grid where the Z values equal hundred times the node index.\n",
"# The first (aka I) axis of this 2d grid is aligned on X and the second (aka J) axis of this 2d grid is aligned on Y.\n",
"# The spacing on the first axis between two node is 25m and the spacing on the second axis between two node is 50m\n",
Expand Down Expand Up @@ -266,9 +268,13 @@
"allUuids = repo.getUuids()\n",
"for i, uuid in enumerate(allUuids):\n",
" dataobjects[str(i)] = fetpapi.buildEtpDataObjectFromEnergisticsObject(repo, uuid)\n",
"client_session.putDataObjects(dataobjects)\n",
"# Finally commit the tansaction now that we have put everything we wanted\n",
"client_session.commitTransaction()"
"successKeys = client_session.putDataObjects(dataobjects)\n",
"#for successKey in successKeys:\n",
"# print(successKey)\n",
"# Finally commit the transaction now that we have put everything we wanted\n",
"transactionFailure = client_session.commitTransaction()\n",
"if (transactionFailure):\n",
" print (transactionFailure)"
]
},
{
Expand All @@ -286,7 +292,8 @@
"metadata": {},
"outputs": [],
"source": [
"client_session.close();"
"repo.clear()\n",
"client_session.close()"
]
}
],
Expand Down
7 changes: 4 additions & 3 deletions python/example/etp_client_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ def start_etp_server(client_session):
additionalHeaderField["data-partition-id"] = "osdu"
initialization_params.setAdditionalHandshakeHeaderFields(additionalHeaderField)

print("Creating the session...")
client_session = fetpapi.createClientSession(initialization_params, authorization)
t = Thread(target=start_etp_server, args=(client_session,), daemon=True)
print("Trying to connect to " + etp_server_url + " ...")
t.start()
start_time = perf_counter()
while client_session.isEtpSessionClosed() and perf_counter() - start_time < 5:
sleep(0.25)
sleep(0.25)
print("Trying to connect to " + etp_server_url + " ...")
if client_session.isEtpSessionClosed():
print("The ETP session could not be established in 5 seconds.")
sys.exit()
Expand Down Expand Up @@ -59,7 +62,6 @@ def start_etp_server(client_session):
hdf_proxy_factory = fetpapi.FesapiHdfProxyFactory(client_session)
print("Set specialized HdfProxy to deal with ETP DataArray subprotocol")
repo.setHdfProxyFactory(hdf_proxy_factory)
print(type(hdf_proxy_factory))

print("Get dataobjects from the resources to the DataObjectRepository");
uriMap = fetpapi.MapStringString();
Expand Down Expand Up @@ -102,7 +104,6 @@ def start_etp_server(client_session):
else:
print("This dataspace has no 2d Grid")

print(type(hdf_proxy_factory))
repo.clear()
client_session.close()
print("FINISHED")
4 changes: 2 additions & 2 deletions python/example/fetpapi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"id": "a16222c5-064e-431d-9dae-d3d6c535a6b9",
"metadata": {},
"source": [
"Once FETPAPI wheel installed, you need to first import FESAPI (required dependency) and then fetpapi it in order to be able to call its API."
"Once FETPAPI wheel installed, you need to first import FESAPI (required dependency) and then fetpapi in order to be able to call its API."
]
},
{
Expand Down Expand Up @@ -198,7 +198,7 @@
"metadata": {},
"outputs": [],
"source": [
"client_session.close();"
"client_session.close()"
]
}
],
Expand Down
6 changes: 4 additions & 2 deletions src/etp/AbstractSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ std::vector<std::string> AbstractSession::putDataObjects(const std::map<std::str

if (messageSize + dataObjectSize > maxWebSocketMessagePayloadSize) {
const int64_t sentMessageId = send(msg, correlationId);
result.insert(result.end(), handlers->getSuccessKeys().begin(), handlers->getSuccessKeys().end());
auto successKeys = handlers->getSuccessKeys();
result.insert(result.end(), successKeys.begin(), successKeys.end());
handlers->clearSuccessKeys();

msg.dataObjects.clear();
Expand All @@ -393,7 +394,8 @@ std::vector<std::string> AbstractSession::putDataObjects(const std::map<std::str
++it;
}
sendAndBlock(msg, correlationId, 0x02);
result.insert(result.end(), handlers->getSuccessKeys().begin(), handlers->getSuccessKeys().end());
auto successKeys = handlers->getSuccessKeys();
result.insert(result.end(), successKeys.begin(), successKeys.end());
handlers->clearSuccessKeys();
return result;
}
Expand Down
Loading

0 comments on commit 8a2f1d8

Please sign in to comment.