TERR Samples

Introduction

TIBCO StreamBase operator for TERR and the TIBCO StreamBase operator for TERR Predict were designed to make it easy to use TERR within a StreamBase application and support many options for dealing with TERR. These samples illustrate the minimum needed to use TERR. Their purpose is not to teach TERR; for that, see the extensive TERR documentation.

The TERR operators require an installation of TERR 4.0 or later on the same machine on which StreamBase is installed, as described in the Authoring Guide pages for each operator.

Note

StreamBase releases since 7.6.3 have bundled a Developer Edition of TERR in STREAMBASE_HOME/terr. You can use the bundled edition of TERR for experimentation and development, but not for deployment as described in License Considerations.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top menu, click FileLoad StreamBase Sample.

  • Type terr to narrow the list of options.

  • Select Use the TERR and TERR Predict Operators from the Applications category.

  • Click OK.

StreamBase Studio creates a single project to contain the sample's files.

TERR Predict Sample

The TERR Predict sample shows how the TERR Predict operator works. It is set up to use the included myModel.RDS file, which contains the following R data as follows:

lm(y~x, data.frame(x=1:100,y=log(1:100)))

Running TERR Predict Sample in StreamBase Studio

The steps to run this sample in Studio are as follows:

  1. In the Package Explorer view, open the predict.sbapp file to view and inspect the EventFlow. Notes are also provided on the EventFlow Editor canvas.

  2. To run the application, right-click the predict.sbapp file and invoke Run AsStreamBase Application.

  3. In the Manual Input view of the SB Test/Debug perspective, you can either leave the input null for defaults to be used, or you can enter values for an input tuple.

    Each input tuple results in an R execution and a result is returned in the terrData output tuple. The status stream displays any messages if the execution had any errors.

TERR General Sample

The TERR General sample shows how the TERR General operator works. It is set up to use the included myModel.r, myModel.RDS, and myModel.RData files, which all contain the same R data as follows:

lm(y~x, data.frame(x=1:100,y=log(1:100)))

Running TERR General Sample in StreamBase Studio

The steps to run this sample in Studio are as follows:

  1. In the Package Explorer view, open the general.sbapp file to view and inspect the EventFlow. Notes are also provided on the EventFlow Editor canvas.

  2. To run the application, right-click the general.sbapp file and invoke Run AsStreamBase Application.

  3. In the Manual Input view of the SB Test/Debug perspective, you can either leave the input null for defaults to be used, or you can enter values for an input tuple.

    Each input tuple results in an R execution and a result is returned in the terrData output tuple. The status stream displays any messages if the execution had any errors.

TERR Init Via File Load Sample

The TERR Init Via File Load sample shows how the TERR General operator can load R data objects during runtime. It is set up to use the included myModel.r, myModel.RDS, and myModel.RData files, which all contain the same R data as follows:

lm(y~x, data.frame(x=1:100,y=log(1:100)))

Running TERR Init Via File Load Sample in StreamBase Studio

The steps to run this sample in Studio are as follows:

  1. In the Package Explorer view, open the init_via_fileload.sbapp file to view and inspect the EventFlow. Notes are also provided on the EventFlow Editor canvas.

  2. To run the application, right-click the init_via_fileload.sbapp file and invoke Run AsStreamBase Application.

  3. In the Manual Input view of the SB Test/Debug perspective, you can either leave the input null for defaults to be used, or you can enter values for an input tuple.

    Each input tuple results in an R execution and a result is returned in the terrData output tuple. The status stream displays any messages if the execution had any errors.

TERR Advanced Sample

The TERR Advanced sample shows how you could change from using the TERR Predict Operator over to use the TERR General operator without having to change event flow. If you have a use case that changes and you require the more advanced feature set of the TERR General operator you can set it up to mirror how the TERR Predict operator works fairly easily. The file advanced_demo.R in the project explorer shows what R information is stored in the RDS files used in this example.

Running TERR Advanced Sample in StreamBase Studio

The steps to run this sample in Studio are as follows:

  1. In the Package Explorer view, open the advanced.sbapp file to view and inspect the EventFlow. Notes are also provided on the EventFlow Editor canvas.

  2. To run the application, right-click the advanced.sbapp file and invoke Run AsStreamBase Application.

  3. In the Manual Input view of the SB Test/Debug perspective press the send tuple button to send a tuple into the event flow.

    Each input tuple results in an R execution and notice that the result of the TERRGeneralOut and TERRPredictOut streams match each other.

TERR Artifact Management Sample

The artifact management sample demonstrates how you can use a TIBCO Artifact Management Server to connect to the TibcoAMS operator and feed data into the TERR Operator to load new version of R artifacts at runtime.

The TIBCO Artifact Management Server is a separately installed product. This sample assumes that you have a running TIBCO Artifact Management Server that is accessible by StreamBase. Refer to the product documentation for more information regarding the Artifact Management Server.

This sample also requires that you do the following:

  1. Create a project folder in the Artifact Management Server called sample.

  2. Navigate to sample/terr from your StreamBase installation directory and upload the myModel.rds file to the AMS sample project folder. Note that the sample/terr directory in StreamBase is a different directory from the AMS sample project folder.

Running the TERR Artifact Management Sample in StreamBase Studio

Run this sample in Studio as follows:

  1. In the Package Explorer view, open the artifactmanagement.sbapp file to view and inspect the EventFlow. Notes are also provided on the EventFlow Editor canvas.

  2. Double-click the TibcoAMS operator to view the operator properties and verify the information is correct. The operator is configured to work with a default fresh install of the Artifact Management Server.

  3. To run the application, right-click the artifactmanagement.sbapp file and invoke Run AsStreamBase Application.

  4. The application will try to pull the myModel.rds file from the Artifact Management Server.

  5. In the Manual Input view of the SB Test/Debug perspective press the send tuple button to send a tuple into the event flow.

    Each input tuple results in an R execution. Notice that the result of the Data streams match each other.

  6. From the Artifact Management Server, deploy the model again to the running artifactmanagement.sbapp application using the following properties:

    1. Target Type: StreamBase URI

    2. StreamBase Server URI: sb://localhost

      If you are running the Artifact Management Server and StreamBase Studio on the same machine, you may need to change sb://localhost to sb://your machine name.

    3. Target StreamBase Operator: default.TibcoAMS

  7. In the Application Output view, notice the Status output tuple showing a new model was loaded.

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_terr

See Default Installation Directories for the default location of studio-workspace on your system.