Bug 816599

Summary: Resource.getOperationHistories() returns no data
Product: [JBoss] JBoss Operations Network Reporter: Viet Nguyen <vnguyen>
Component: CLIAssignee: RHQ Project Maintainer <rhq-maint>
Status: CLOSED NOTABUG QA Contact: Mike Foley <mfoley>
Severity: medium Docs Contact:
Priority: medium    
Version: JON 3.1.0CC: lkrejci
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-04-30 14:40:02 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
test case none

Description Viet Nguyen 2012-04-26 13:40:49 UTC
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

Comment 1 Viet Nguyen 2012-04-26 13:41:14 UTC
Created attachment 580480 [details]
test case

Comment 2 Lukas Krejci 2012-04-30 14:40:02 UTC
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)

Comment 3 Lukas Krejci 2012-04-30 14:42:24 UTC
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;

Comment 4 Viet Nguyen 2012-04-30 21:04:38 UTC
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);
}

Comment 5 Viet Nguyen 2012-04-30 21:30:02 UTC
Another word if I schedule operation X does getOperationHistories give me the ability to see X?

Comment 6 Lukas Krejci 2012-05-02 08:21:03 UTC
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.

Comment 7 Viet Nguyen 2012-05-07 20:39:17 UTC
User error! it's working now.  I missed 1 very important call:

opHistCrit.fetchResults(true)

Comment 8 Mike Foley 2012-05-08 19:33:32 UTC
per BZ triage ... crouch, loleary, foley