Accessing Objects in the IBM SPSS Collaboration and Deployment Services Repository

If you have a license for the IBM® SPSS® Collaboration and Deployment Services Repository, you can store and retrieve objects from the repository by using script commands. Use the repository to manage the lifecycle of data mining models and related predictive objects in the context of enterprise applications, tools, and solutions.

Connecting to the IBM SPSS Collaboration and Deployment Services Repository

To access the repository, you must first set up a valid connection to it, either through the Tools menu of the SPSS Modeler user interface or through the command line. For more information, see IBM SPSS Collaboration and Deployment Services Repository Connection Arguments.

Getting access to the repository

The repository can be accessed from the session, for example:

repo = modeler.script.session().getRepository()

Retrieving objects from the repository

Within a script, use the retrieve* functions to access various objects, including streams, models, output, and nodes. A summary of the retrieval functions is shown in the following table.

Table 1. Retrieve scripting functions
Object Type Repository Function
Stream repo.retrieveStream(String path, String version, String label, Boolean autoManage)
Model repo.retrieveModel(String path, String version, String label, Boolean autoManage)
Output repo.retrieveDocument(String path, String version, String label, Boolean autoManage)
Node repo.retrieveProcessor(String path, String version, String label, ProcessorDiagram diagram)

For example, you can retrieve a stream from the repository with the following function:

stream = repo.retrieveStream("/projects/retention/risk_score.str", None, "production", True)

This example retrieves the risk_score.str stream from the specified folder. The label production identifies which version of the stream to retrieve, and the last parameter specifies that SPSS Modeler is to manage the stream (for example, so the stream appears in the Streams tab if the SPSS Modeler user interface is visible). As an alternative, to use a specific, unlabeled version:

stream = repo.retrieveStream("/projects/retention/risk_score.str", "0:2015-10-12 14:15:41.281", None, True)
Note: If both the version and label parameters are None, then the latest version is returned.

Storing objects in the repository

To use scripting to store objects in the repository, use the store* functions. A summary of the store functions is shown in the following table.

Table 2. Store scripting functions
Object Type Repository Function
Stream repo.storeStream(ProcessorStream stream, String path, String label)
Model repo.storeModel(ModelOutput modelOutput, String path, String label)
Output repo.storeDocument(DocumentOutput documentOutput, String path, String label)
Node repo.storeProcessor(Processor node, String path, String label)

For example, you can store a new version of the risk_score.str stream with the following function:

versionId = repo.storeStream(stream, "/projects/retention/risk_score.str", "test")

This example stores a new version of the stream, associates the "test" label with it, and returns the version marker for the newly created version.

Note: If you do not want to associate a label with the new version, pass None for the label.

Managing repository folders

By using folders within the repository, you can organize objects into logical groups and make it easier to see which objects are related. Create folders by using the createFolder() function, as in the following example:

newpath = repo.createFolder("/projects", "cross-sell")

This example creates a new folder that is called "cross-sell" in the "/projects" folder. The function returns the full path to the new folder.

To rename a folder, use the renameFolder() function:

repo.renameFolder("/projects/cross-sell", "cross-sell-Q1")

The first parameter is the full path to the folder to be renamed, and the second is the new name to give that folder.

To delete an empty folder, use the deleteFolder() function:

repo.deleteFolder("/projects/cross-sell")

Locking and unlocking objects

From a script, you can lock an object to prevent other users from updating any of its existing versions or creating new versions. You can also unlock an object that you have locked.

The syntax to lock and unlock an object is:

repo.lockFile(REPOSITORY_PATH)
repo.lockFile(URI)

repo.unlockFile(REPOSITORY_PATH)
repo.unlockFile(URI)

As with storing and retrieving objects, the REPOSITORY_PATH gives the location of the object in the repository. The path must be enclosed in quotation marks and use forward slashes as delimiters. It is not case sensitive.

repo.lockFile("/myfolder/Stream1.str")
repo.unlockFile("/myfolder/Stream1.str")

Alternatively, you can use a Uniform Resource Identifier (URI) rather than a repository path to give the location of the object. The URI must include the prefix spsscr: and must be fully enclosed in quotation marks. Only forward slashes are allowed as path delimiters, and spaces must be encoded. That is, use %20 instead of a space in the path. The URI is not case sensitive. Here are some examples:

repo.lockFile("spsscr:///myfolder/Stream1.str")
repo.unlockFile("spsscr:///myfolder/Stream1.str")

Note that object locking applies to all versions of an object - you cannot lock or unlock individual versions.