Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
This Blog presents a simple Java utility to validate the deployment of ThingWatcher.
It is important to note that the utility used is not a real life situation, the intent was to keep it as simple as possible in order to achieve its aim: validation of the deployment.
An understanding of Java IDE (such as Eclipse) is necessary in order to run the utility with relevant dependency and classpath setup. Those are beyond the scope of this posting.
We will cover the following points:
A strict adherence to the ThingWatcher deployment guide is recommended in order to first deploy training and model microservices as well as to familiarize yourself with ThingWatcher APIs.
Prior to testing ThingWatcher, both the training and model microservices should be up and running
The media for ThingWatcher (including model and training micro-service) should be downloaded from PTC Software Download page .
The commands to deploy the micro-services will vary depending on the platform used and are presented in the ThingWatcher deployment guide.
As a reference example, on Windows the command will be similar to the following:
$ docker load < "D:\PTC\MED-61147-CD-522_F000_ThingWorx-Analytics-ThingWatcher-52-2\components\ModelService\ModelService\model-service.tar"
3. Install model service:
$ docker run -d -p 8080:8080 -v '/d/TWatcherStorage/model:/data/models' -v '/d/TWatcherStorage/db:/tmp/' twxml/model-service:1.0 -Dfile.storage.path=/data/models -jar maven/model-1.0.jar server maven/standalone-evaluator.yml
4. Load training micro service tar file
$ docker load < "D:\PTC\MED-61147-CD-522_F000_ThingWorx-Analytics-ThingWatcher-52-2\components\TrainingService\TrainingService\training-service.tar"
5. Install training service
$ docker run -d -p 8090:8080 twxml/training-service:1.0.0 -Dmodel.destination.uri=model://192.168.99.100:8080/models -jar maven/training-standalone-1.0.0-bin.jar server /maven/training-standalone-single.yml
Note: the -Dmodel.destination.uri points here to the model micro-service host. To find the ip address, enter docker-machine ip on the model micro-service docker machine.
6. Validate micro-services deployment:
Execute docker ps and confirmed that both services are up, as in the following example:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b6a29b95611 twxml/training-service:1.0.0 "java -Dmodel.destina" 13 days ago Up 44 minutes 8081/tcp, 0.0.0.0:8090->8080/tcp modest_albattani
8c13c0bc910e twxml/model-service:1.0 "java -Dfile.storage." 2 weeks ago Up 44 minutes 0.0.0.0:8080->8080/tcp, 8081/tcp thirsty_ptolemy
The code declares a thingwatcher in the following snippet:
ThingWatcher thingwatcher = new ThingWatcherBuilder()
.certainty(90.0)
.trainingDataDuration(60)
.trainingDataDurationUnit(DurationUnit.SECOND)
.trainingBaseURI("http://192.168.99.100:8090/training")
.getThingWatcher();
It is advised to save the output to a file in order to review the logging once the utility has run.
A review of the output log file will shows that somewhere between timestamp 900000 and 990000, the isAnomalousValue is true.
[main] INFO com.thingworx.analytics.demo.Main - Value = 901700,9017.0,-9016.403802019577
[main] INFO com.thingworx.analytics.demo.Main - isAnomalousValue = true
[main] INFO com.thingworx.analytics.demo.Main - ThingWatcherStat = MONITORING
As part of validating the successful deployment of ThingWatcher, it is recommended to validate the correct creation of a training and model job.
Validate training job creation
In order to validate the successful creation of a training job, execute a GET request to the training micro service : http://192.168.99.100:8090/training (update the ip address to the one on your system)
This should return a COMPLETED job whose body starts with something similar to:
In order to validate the successful creation of a model job, execute a GET request to http://192.168.99.100:8080/models (update the ip address to the one on your system) to see all the models that have been created. For example:
Alternatively, click (or use) the URI reported in the training job output, here http://192.168.99.100:8080/models/6/pmml.xml, to see the complete model definition. The output will be similar to:
When this sample test runs correctly, the ThingWatcher deployment has been validated.
Update for ThingWorx Analytics 8.0
To Note:
Christophe
I set the Thingwatcher according to the above guide, edit trainingBaseUrl and run the java utility(main.java) to run Training.
I got an error like below.
What is the problem?
2월 19, 2017 10:41:53 오전 com.thingworx.analytics.thingwatcher.ThingWatcher <init>
INFO: ThingWatcher [ ID: a539027a-3ac7-48a6-b798-10edf188e710, Certainty: 90.0, MinimumTrainingDataDuration: 60, TrainingDataDurationUnit: SECOND, PMMLModelURI: null, TrainingURI: http://127.0.0.1:8090/training ]
2월 19, 2017 10:41:54 오전 com.thingworx.analytics.demo.Main main
INFO: Waiting for thingwatcher training to complete...
2월 19, 2017 10:41:59 오전 com.thingworx.analytics.demo.Main main
INFO: Waiting for thingwatcher training to complete...
2월 19, 2017 10:42:04 오전 com.thingworx.analytics.demo.Main main
INFO: Waiting for thingwatcher training to complete...
com.thingworx.analytics.thingwatcher.Trainer$TrainingJobErrorException: Training job with id 2 entered into an incomplete state [FAILED] unable to process models. Error message: [NullPointerException: ]
at com.thingworx.analytics.thingwatcher.Trainer.lambda$getPMMLModelUri$1(Trainer.java:45)
at java.util.Optional.orElseThrow(Unknown Source)
at com.thingworx.analytics.thingwatcher.Trainer.getPMMLModelUri(Trainer.java:45)
at com.thingworx.analytics.thingwatcher.ThingWatcher.attemptTransitionToMonitoringState(ThingWatcher.java:338)
at com.thingworx.analytics.thingwatcher.ThingWatcher.monitor(ThingWatcher.java:157)
at com.thingworx.analytics.demo.Main.main(Main.java:55)
com.thingworx.analytics.thingwatcher.Trainer$TrainingJobErrorException: Training job with id 2 entered into an incomplete state [FAILED] unable to process models. Error message: [NullPointerException: ]
at com.thingworx.analytics.thingwatcher.Trainer.lambda$getPMMLModelUri$1(Trainer.java:45)
...........................................................
Hi Yong June Kim
From the output you pasted, the trainingBaseURI is set to http://127.0.0.1:8090/training .
If you follow the installation steps, the training model service runs inside docker so I would expect a docker ip address here and not the localhost one. Having said that it seems ThingWatcher does find the training micro service but it would seem you have not follow the setup described in the ThingWatcher guide.
It probably would be interesting to have the details of what exactly you have done.
The error reported here, though , is most likely due to the training microservice not finding the model micro service.
While initializing the training micro service (see command in step 5 of pre-requisite above) the model.destination.uri property should point to the location of the model micro service ( model://192.168.99.100:8080/models in the example). I would think the URI was incorrect in your command.
As a troubleshooting step, you can try accessing this URI in a browser: http://192.168.99.100:8080/models, you should get the list of models or {"values":[],"total":0,"next":null,"previous":null} if none have been created yet. If you get some error of type http 404, then the URI is not correct.
Once you have the correct URI, you will need to initialize a new training service with a similar command as in step 5 above but with correct model URI for you.
You will also need to stop and delete the current training microservice which points to the wrong URI.
Hope this helps.
Kind regards
Christophe
Hi Christophe
I set the Thingwatcher according to the above guide, edit trainingBaseUrl and run the java utility(main.java) to run Training.
My code error like picture .
What is the problem?
Hi
What version are you using ?
The main.java was created with 52.2 version of ThingWatcher - I think it woudl work up to version 7.4.
For version 8.0, you would need to check the chapter Update for ThingWorx Analytics 8.0 in the blog
Hope this helps
Christophe
Hi Christophe
I see , I using version 8.0, thanks.