Contents
Note
This operator is deprecated in 11.1.1 and will be removed in future versions.
TIBCO Streaming operator for TERR and the TIBCO Streaming 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 bundles 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.
In StreamBase® Studio, import this sample with the following steps:
-
From the top-level menu, click
> . -
Enter
terr
to narrow the list of options. -
Select the TERR and TERR Predict Operators from the Other TIBCO Product Connectivity category.
-
Click
.
StreamBase® Studio creates a single project to contain the sample's files.
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)))
The steps to run this sample in Studio are as follows:
-
In the Project Explorer view, open the sample you just loaded.
If you see red marks on a project folder, wait a moment for the project to load its features.
If the red marks do not resolve themselves after a minute, select the project, right-click, and select
> from the context menu. -
Open the
src/main/eventflow/
folder.packageName
-
Open the
file and click thepredict.sbapp
Run button. This opens the SB Test/Debug perspective and starts the module. Notes are also provided on the EventFlow Editor canvas.
-
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.
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)))
The steps to run this sample in Studio are as follows:
-
Continuing with the same sample, open the
file and click thegeneral.sbapp
Run button. This opens the SB Test/Debug perspective and starts the module. Notes are provided on the EventFlow Editor canvas.
-
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.
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)))
The steps to run this sample in Studio are as follows:
-
Continuing with the same sample, open the
file and click theinit_via_fileload.sbapp
Run button. This opens the SB Test/Debug perspective and starts the module. Notes are also provided on the EventFlow Editor canvas.
-
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.
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.
The steps to run this sample in Studio are as follows:
-
Continuing with the same sample, open the
file and click theadvanced.sbapp
Run button. This opens the SB Test/Debug perspective and starts the module. Notes are also provided on the EventFlow Editor canvas.
-
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
andTERRPredictOut
streams match each other.
The artifact management sample demonstrates how you can use TIBCO Streaming Model Management Server (MMS) to load new versions of R artifacts at runtime.
MMS is a separately installed product. This sample assumes that you have a running MMS that is accessible by StreamBase. Refer to the product documentation for more information regarding MMS.
This sample also requires that you do the following:
-
Create a project in Model Management Server with Group identifier as
com.example
and Artifact identifier assample-terr
. -
Create a new Managed File artifact called
advanced_demo_data.rds
in MMS. SelectR data
for the Type, then to thesample/terr/src/main/resources/advanced_demo_data.rds
file in your StreamBase installation directory.Now, create a new Model artifact called
advanced_demo_model.rds
. SelectR
for the Type andunknown
for the Category. Follow the same steps as above to select thesample/terr/src/main/resources/advanced_demo_model.rds
file.Note that the
sample/terr
directory in StreamBase is a different directory than the MMS project folder. -
Create a new Deploy Descriptor for the project. The cluster you wish to deploy to must already be running. First follow the steps below to launch the fragment in Studio, but do not send any data yet. Once the launch is completed in Studio, create the deploy descriptor in MMS, selecting the Target as the cluster that was created in Studio (this is your computer username by default).
Approve the project for deployment to this cluster by opening the Properties for the project and selecting the cluster in the Approvals section.
Run this sample in Studio as follows:
-
Continuing with the same sample, open the
artifactmanagement.sbapp
file and click theRun button. This opens the SB Test/Debug perspective and starts the module. Notes are also provided on the EventFlow Editor canvas.
-
The application will try to pull the artifacts from MMS. Note that the
Required On Startup
option is disabled for all operators, which means artifacts do not need to be loaded from MMS when the fragment is launched. If Required on Startup is enabled, and if all artifacts cannot be loaded within a specific period of time, the system will fail with anartifact timeout
exception. -
Go back to MMS and Deploy the project. If the deployment succeeds, you will see a message in Studio's log. This message indicates that the artifact from MMS is now being used by the TERR operators.
-
In the Manual Input view of the SB Test/Debug perspective press the send tuple button to send a tuple into the module.
Each input tuple results in an R execution. Notice that the result of the
Data
streams match each other. -
In the Output Streams view, notice the
Status
output tuple showing a new model was loaded.
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.