Connector Templates
SDK Connector Templates
The following SDK connector templates are available with the Analytics Extension extension:
TW.AnalysisServices.BasicSDKConnectorTemplate
This template provides the simplest connector implementation based on the ThingWorx Edge SDK-based client implementation deployment configuration. In addition to the core functionality, the basic SDK connector template provides the following features to execute jobs:
Managing clients
Updating results by call back
Uploading result files
Supporting simulations
TW.AnalysisServices.SDKConnectorTemplate
This template provides the simplest connector implementation based on the ThingWorx Edge SDK-based client implementation deployment configuration. In addition to the functionality that is provided by TW.AnalysisServices.BasicSDKConnectorTemplate, this connector template provides the following functionality:
Managing models
Querying input and result data shapes
Customizable Connector Template
The following cutomizable connector template is available with the Analytics Extension extension:
TW.AnalysisServices.AnalysisConnectorTemplate
To communicate with the Analytics Manager framework successfully, a customized analysis connector must implement the thing template, TW.AnalysisServices.AnalysisConnectorTemplate that is provided with the extension.
This following table provides information about the services that this template provides:
Service and Description
Input parameter
Output
InfoTable submitJob (InfoTable inputs) — Executes a job asynchronously.
Input data shape PTC.Capability.Analysis.SolvableDataShape
Returns an infotable with the Job ID.
InfoTable executeJob (InfoTable inputs) — Executes a job synchronously and provides the results immediately.
Input data shape PTC.Capability.Analysis.SolvableDataShape
Returns an infotable with the Job ID and the result of job execution which is the result data shape for the model.
To add more features to your connector, choose any of the following appropriate thing shapes that are available and implement the services that these Thing Shapes contain:
Thing Shape
Description
Available Services
Input and Output
PTC.Capability.Analysis.Connector.ClientManager
Implemented by those analysis providers that want the Analytics Manager framework to manage agents that run the analysis provider runtime instance. The job distribution to the agents is handled by the router by using the ClientHealthData information.
The router template TW.AnalysisServices.RouterTemplate is packaged with the Analytics Manager extension and it handles round robin routing. A new router template can be defined in the connector and specified as router template in the configuration. For more information, see Create a Custom Router Template.
void connect(InfoTable clientData) — Used by agents on start up to create client things and corresponding configurations or properties, if any.
The input infotable clientData has the TW.AnalysisServices.ClientData data shape with fields such as ClientID, list of DeployedModels, and optional HostName and PortName fields, if non-SDK clients communicate with the server.
Returns the ResourceAvailable event after the client connects successfully.
InfoTable getClientHealthData() — Used to poll the health information of the clients. It provides the heartbeat and queries health information and sets the health information on the client things.
The input infotable. ClientHealth has the TW.AnalysisServices.ClientHealthData data shape with the ClientId, memory, CPUusage, diskSpace, and running Jobcount fields.
Returns the ResourceUnavailable event conditionally if the client disconnects.
PTC.Capability.Analysis.Connector.IODataStructureProvider
Implemented by connectors to provide input and result data structures for a given model.
JSON getInputDataShape(modelName) — Used to obtain the input data structure for a given model.
Returns a JSON that represents the input data shape for a given model.
JSON getOutputDataShape(modelName) — Used to obtain the result data shape for a given model. You can also use this service to implement the creation of the result data shape.
Returns a JSON that represents the result data shape for the given model.
PTC.Capability.Analysis.Connector.ModelManager
Implemented by connectors for analysis providers that accept runtime deployment of models.
If the connector has implemented the PTC.Capability.Analysis.Connector.ClientManager thing shape along with ModelDeployer, then this service should be delegated to the corresponding service calls on the client.
String deployModel (InfoTable modelData) — Used to deploy the model to the analysis provider.
The TW.Analysis.ModelDeploymentDataShape data shape should be used to construct the modelData infotable. This data shape consists of the modelName, repository,fileDescriptor, path, and downloadLink fields.
Returns the status of model deployment as one of the following:
DEPLOY_FAILED
DEPLOY_COMPLETE
DEPLOY_INPROCESS
Boolean isModelDeployed(String modelName) — Checks if the specified model is deployed.
Returns a boolean value, 1 if the specified model is deployed.
PTC.Capability.Analysis.Connector.CallbackResultsProvider
Implemented by connectors through which analysis providers can communicate the job updates, that is, job status, results, and, result files on job completion to the ThingWorx server.
For Edge SDK-based client with fileTransfer, the resultFilesInfo JSON must specify the fileName and virtualDirectory. (The url is not required.)
[
{
"fileName":"file1.extension",
"virtualDirectory" :"MappedVirtualDirectoryName/Folder1"
}
]
For non-SDK clients with fileTransfer, the resultFilesInfo JSON must specify the fileName and url. (The virtualDirectory is not required.)
[
{
"fileName":"file1.extension",
"url":"http:\\url-to-poll file from"
}
]
void updateJob(String jobId, String status, InfoTable results, JSON resultFilesInfo) — Used by the analysis agent to communicate job (specified by Job ID) updates to the connector.
As input, specify the resultFilesInfo parameter as a JSON structure with information about the result files.
Returns the ResultAvailable event so that the AnalysisResourceProvider can update the Job. Ensure that the data shape of the results infotable must match the result data shape of the model used.
void uploadResultFiles(jobId, JSON resultFilesInfo) — Used by the analysis agent to communicate information about the result files. Use this service only if job files are not available when updateJob is called or the job files are generated asynchronously during job execution.
As input, specify the resultFilesInfo parameter as a JSON structure with information about the result files.
Returns the ResultAvailable event so that the AnalysisResourceProvider can update the Job. Ensure that the data shape of the results infotable must match the result data shape of the model used.
PTC.Capability.Analysis.Connector.PolledResultsProvider
Implemented by connectors for analysis providers that query analysis job status and results.
Configure the polling interval for this Thing Shape. The polling interval is the time interval in milliseconds at which the analysis provider queries the job results, status, and files. The default value is -1 that implies no polling is required.
Polling is implemented in the Analytics Manager framework that would poll the implementing connectors at the configured polling interval through these services to get the job status, job results, and the list of files for job results. If result files exist, the provider pulls the files from the specified URL and copies them to the job repository.
Infotable getJobResults (Infotable inputs) — Used to obtain the job result of the specified job ID.
The inputs infotable consists of at least the job ID to query results. It can also have other computation service-specific parameters.
Returns the job results.
String getJobStatus(Infotable inputs)— Used to obtain the job status of the specified job ID.
The inputs infotable consists of at least the job ID to query results. It can also have other computation service-specific parameters.
Returns the job status as either of the following:
COMPLETED
FAILED
NOT_EXECUTED
INPROCESS
ONHOLD
JSON getJobResultFilesList(string jobID) — Used to obtain the list of result files for the specified job ID.
Returns the list of result files in the form of a JSON file. The JSON structure is the same as resultFilesInfo.
PTC.Capability.Analysis.Connector.FileStorageProvider
While configuring the provider, if the connector implements this Thing Shape, a FileRespository is created internally and it is associated with the configuration. Job-specific files are saved in this repository.
-
-
PTC.Capability.Analysis.Connector.SimulationProvider
Implemented by connectors for analysis providers which can run a job in the simulation mode.
String startJob(InfoTable inputs) — Assigns the job and starts an agent.
Returns the job ID.
InfoTable stopJob(String jobId, String clientId) — Stops a simulation job, and puts the job in the ONHOLD status.
As inputs, specify the job ID to be stopped and the client ID where the job is running.
Returns the last results of the job that has been stopped.
InfoTable updateJobInputs(String jobId, String clientId, InfoTable inputParams) — Sends updated inputs for the specified job ID to the specified client ID.
Returns the results of the run.
This custom connector must be packaged as an extension. For more information about developing a ThingWorx extension, refer to the ThingWorx Server documentation.
Was this helpful?