이 콘텐츠는 선택한 언어로 제공되지 않습니다.
12.6. Operations
12.6.1. Starting and Stopping a Resource 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
A resource can simple be started by using an operation.
This example looks for a specific resource by name, and then runs the start() function.
Example 12.16. Simple Start
Each resource type has its own defined operations, and even simple tasks like start and stop may have different methods depending on the resource. Try using a proxy resource and then the operations method to list the available operations.
A more complex start or stop script can be used to iterate over an array of resources of the same type.
Example 12.17. Starting an Array 1
Example 12.18. Starting an Array 2
12.6.2. Scheduling Operations 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
The simplest way to run an operation is to create a proxy for the resource, and then run the operation on that proxy, in the form proxyName.operationName().
Example 12.19. Immediate Operation
Operations can be run on a schedule. A schedule requires several configuration pieces:
- The resource ID
- The operation name
- A delay period, meaning when in the future to start the operation (optional)
- A repeat interval and count (optional)
- A timeout period (optional)
- Configuration parameters, if required by the operation
- A description of the scheduled operation (optional)
This example runs an availability scan on a specific agent.
Example 12.20. Scheduled Operation Example
This immediately prints the information for the scheduled operation.
ResourceOperationSchedule: resource: Resource[id=10008, uuid=e11390ec-34c4-49df-a4b6-c37c516f545c, type={RHQAgent}RHQ Agent, key=server.example.com RHQ Agent, name=RHQ Agent, parent=server.example.com, version=3.3]
ResourceOperationSchedule:
resource: Resource[id=10008, uuid=e11390ec-34c4-49df-a4b6-c37c516f545c, type={RHQAgent}RHQ Agent, key=server.example.com RHQ Agent, name=RHQ Agent, parent=server.example.com, version=3.3]
12.6.3. Retrieving the Results of an Operation 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
Some operations really only report a success or failure, and that is all the information that is required. Other operations, however, may retrieve information from a resource or make a more complex change on the resource. In that case, that information needs to be returned so it can be used in further tasks.
The
fetchResults(true)
method can be used to return the results of the operation as part of the search for the operation history.
Example 12.21. Printing the Results of a Process Scan
In this longer example, the script first runs an operation (a process scan on a platform) and then prints the results.
The first part of the script sets up the requirement for the resource ID and then searchs for that resource.
if (args.length != 1) { throw "we need a resource id as an argument"; } var platform = ResourceManager.getResource(args[0]);
if (args.length != 1) {
throw "we need a resource id as an argument";
}
var platform = ResourceManager.getResource(args[0]);
The next part schedules the process scan operation. As covered in Section 12.6.2, “Scheduling Operations”, this sets the resource ID, operation name, and operation settings.
The last part retrieves the operation history with two additional search settings:
- fetchResults(true), which is required to include the operation result data and not just the status
- a sort method, in this case addSortStartTime
There are also a couple of sleeps in the script to ensure that the operation has time to complete before the script attempts to retrieve the results.
This script prints the results of the operation as long as the operation has completed successfully:
} else { pretty.print(operations.get(0).getResults()); break; }
} else {
pretty.print(operations.get(0).getResults());
break;
}
12.6.4. Checking a Resource's Operations History 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
The operation history for a resource exists as an object, so it can be searched for, by criteria, same as other objects.
Example 12.22. Viewing the Operation History
The (successful) operation results are in Configuration objects in the results table.
resource results ----------------------------------------------------------------------------------------------------------------- Resource[id=10008, uuid=e11390ec-34c4-49df-a4b6-c37c516f545c, type={RHQAgent}RHQ Agent, key=server.example.com RHQ Age Configuration[id=13903] Resource[id=10008, uuid=e11390ec-34c4-49df-a4b6-c37c516f545c, type={RHQAgent}RHQ Agent, key=server.example.com RHQ Age Configuration[id=13913] 2 rows
resource results
-----------------------------------------------------------------------------------------------------------------
Resource[id=10008, uuid=e11390ec-34c4-49df-a4b6-c37c516f545c, type={RHQAgent}RHQ Agent, key=server.example.com RHQ Age Configuration[id=13903]
Resource[id=10008, uuid=e11390ec-34c4-49df-a4b6-c37c516f545c, type={RHQAgent}RHQ Agent, key=server.example.com RHQ Age Configuration[id=13913]
2 rows