Description of problem: Version-Release number of selected component (if applicable): JON 3.0.1.GA CLI 4.2.0.JON.3.0.1.GA How reproducible: Steps to Reproduce: 1. schedule viewProcessList on a resource type="Linux" 2. call resource.getOperationHistories() Actual results: empty list Expected results: viewProcessList Additional info: See attached test script
Created attachment 580480 [details] test case
While this is slightly non-trivial to learn, the operation histories are not loaded along with the resource unless specifically asked for. Also in your script you do: var server = resources.get(0); ... schedule an operation on the server resource ... var histories = server.getOperationHistories() Unfortunately, this doesn't work like that. The resources you obtain from the server are not "connected" to the live data, so calling the getOperationHistories() method on the "server" resource WILL NOT query the RHQ server for the current state of that collection, but rather will return the histories AS THEY WERE, when the "server" resource was retrieved from the RHQ server (and btw, because the operation histories are NOT fetched with the resource by default, the list would be empty anyway). To obtain the histories, you need to: var historyCriteria = new ResourceOperationHistoryCriteria; historyCriteria.addFilterResourceIds([server.id]); var histories = OperationManager.findResourceOperationHistoriesByCriteria(historyCriteria)
One other way to do it is to: var resourceCriteria = new ResourceCriteria; resourceCriteria.fetchOperationHistories(true); ... setup the resource criteria to find the resources you want ... var resources = ResourceManager.findResourcesByCriteria(resourceCriteria) now you can: var history = resources.get(0).operationHistories;
Thanks for the tips. I tried both ways and were getting history objects back but the conguration object is null var resourceCriteria = new ResourceCriteria; resourceCriteria.fetchOperationHistories(true); resourceCriteria.addFilterResourceTypeName("Linux"); var resources = ResourceManager.findResourcesByCriteria(resourceCriteria); var histories = resources.get(0).getOperationHistories(); for(i=0; i<histories.size(); i++) { var config = histories.get(i).getResults(); pretty.print(config); }
Another word if I schedule operation X does getOperationHistories give me the ability to see X?
First the "results question": Unfortunately using the resourceCriteria, you cannot specify that you want to fetch the results of the operations and so the results will always be empty if you use only ResourceCriteria object. This is done to minimize the traffic and DB load. The workflow is supposed to be: 1) query the operation histories 2) loop through them, find the interesting one 3) query additional details on it To get the results of the operation, you therefore need to ask the RHQ server again like: var opHistCrit = new ResourceOperationHistoryCriteria; ... set up the opHistCrit to find the history entry you want, either using "addFilterId" method or any other "addFilter" method available ... opHistCrit.fetchResults(true) //if you want to fetch the parameters passed to the operation, you also need to opHistCrit.fetchParameters(true) var histories = OperationManager.findResourceOperationHistoriesByCriteria(opHistCrit) The name of the operation can be determined from: history.operationDefinition.name; This is always available on the history object, so you don't need to do any other queries to get at the name, even if you use just the ResourceCriteria to get the operation history on resources.
User error! it's working now. I missed 1 very important call: opHistCrit.fetchResults(true)
per BZ triage ... crouch, loleary, foley