hcpsdk.pathbuilder — unique object names

Due to its internals, bulk ingest activity into HCP delivers best possible performance if multiple parallel writes are directed to different folders take place.

This subpackage offers functionality to create an unique object name along with a pseudo-random path to a folder to store the object in.

The object name generated is an UUID version 1, as defined in RFC 4122. The algorithm uses (one of) the servers MAC addresses, along with the system time to create the UUID.

Intended Use

Applications typically utilize a database to keep reference pointers to objects they stored to HCP. Instead of storing a full path as a reference to each object (i.e.: https://ns.tenant.hcp.domain.com/rest/mypath/myfile), applications should define a data pool that describes the storage target (i.e.: https://ns.tenant.hcp.domain.com, startpath='/rest/myapp').

When storing a reference, an application should store the name generated by hcpsdk.pathbuilder.PathBuilder.getunique(), along with a reference to the data pool used.

Benefits are:

  • Reasonable space usage in the applications database
  • The actual content address (the full URL) is easily computable from the data pool and hcpsdk.pathbuilder.PathBuilder.getpath(reference)
  • In case the applications data needs to be migrated to a different storage system or a different namespace within HCP, it’s just a matter of migrating the data in the background and then changing the data pool definition, keeping application disturbence extremly low.

Classes

PathBuilder

class hcpsdk.pathbuilder.PathBuilder(initialpath='/rest/hcpsdk', annotation=False)[source]

Conversion of a filename into a unique object name and a proper path for HCPs needs. Re-conversion of a unique object name to the path where the object can be found in HCP.

Parameters:
  • initialpath – the leading part of the path
  • annotation – if True, create an XML structure to be used as custom metadata annotation containing a tag with the original filename of the object.
getunique(filename)[source]

Build a unique path / object name scheme.

The path is build from initialpath given during class instantiation plus byte 4 and 3 of the UUID in hexadecimal.

If annotation is True during class instantiation, there will be a third element in the returned tuple, containing an XML structure that can be used as custom metadata annotation for the object.

Parameters:filename – the filename to be transformed
Returns:a tuple consisting of path, unique object name and -eventually- an annotation string.
Raises:hcpsdk.pathbuilder.pathbuilderError

Example:

>>> from hcpsdk.pathbuilder import PathBuilder
>>> p = PathBuilder(initialpath='/rest/mypath', annotation=True)
>>> o = p.getunique('testfile.txt')
>>> o
('/rest/mypath/b4/ec', '8ac8ecb4-9f1e-11e4-a524-98fe94437d8c',
 '<?xml version='1.0' encoding='utf-8'?>
    <hcpsdk_fileobject
        filename="testfile.txt"
        path="/rest/mypath/b4/ec"
        uuid="8ac8ecb4-9f1e-11e4-a524-98fe94437d8c"
 />')
>>>
getpath(objectname)[source]

From a unique object name, retrieve the path in which the object was stored.

Parameters:objectname – an unique object name
Returns:the full path to the object (including its name)
Raises:hcpsdk.pathbuilder.pathbuilderError

Example:

>>> p.getpath('8ac8ecb4-9f1e-11e4-a524-98fe94437d8c')
'/rest/mypath/b4/ec/8ac8ecb4-9f1e-11e4-a524-98fe94437d8c'
>>>

Exceptions

exception hcpsdk.pathbuilder.PathBuilderError(reason)[source]

Used to signal an error during unique object name generation or object name to path mapping.

Parameters:reason – an error description