Update the Agency Scope
of a Solution
You define the ESX
agency scope of a solution by passing the managed object references (MoRefs) of
the vSphere compute resources to the solution.
- Verify that you have set up and started the EAM Sample Solution in an application server.
- Verify that you have openedin an editor.eam_work_folder\src\com\vmware\eam\sample\solution\AgentHandler.java
- Openin an editor.eam_work_folder\src\com\vmware\eam\sample\solution\utils\VcUtilsjava
You set the initial ESX agency
scope in the
scope
property of the
AgencyConfigInfo
object. You can change the scope when a solution runs by calling the
Agency.update()
method.
For example, in the EAM Sample Solution, users select the
hosts on
which to run the solution from a list on the EAM Sample Solution Configuration
page. The EAM Sample Solution updates the scope of the sample ESX agency
according to the hosts that the user selects.
The EAM Sample Solution
defines a function to update the scope of the ESX agency in the
AgentHandler.java
class.
- Write a function that implements the vSphere Web Services API to detect compute resources on which to run the solution.The EAM Sample Solution provides a helper class,VcUtils.java, that defines functions to obtain the compute resources on which to run the solution.AgentHandler.javacalls theVcUtils.getComputeResources()method to obtain a list ofManagedObjectReferenceobjects for the hosts running in .public void updateConfig(String[] updates) throws RuntimeFaultFaultMsg { waitForSetup(); boolean changed = false; Map<String, ManagedObjectReference> crs = _vcUtils.getComputeResources();
- Add theManagedObjectReferenceobjects for the compute resources to aHashSetthat defines the ESX agency scope.TheAgentHandler.javaclass adds the list ofManagedObjectReferenceobjects that theVcUtils.getComputeResources()method returns to the existing scope and updates the list if additional compute resources are present.Set<ManagedObjectReference> newScope = new HashSet<ManagedObjectReference>(); for (String update : updates) { String[] kv = update.split("=", 2); if (kv[0].equals("scope")) { try { ManagedObjectReference cr = crs.get(kv[1]); if (cr == null) { continue; } ManagedObjectReference moRef = new ManagedObjectReference(); moRef.setType(cr.getType()); moRef.setValue(cr.getValue()); newScope.add(moRef); } catch (NullPointerException e) { // ignore } } }
- Create anAgencyComputeResourceScopeinstance to contain the scopeHashSet.AgencyComputeResourceScope scopeDO = (AgencyComputeResourceScope) _agencyConfigInfo.getScope(); Set<ManagedObjectReference> oldScope = new HashSet<ManagedObjectReference>(scopeDO.getComputeResource());
- Compare the old scope to the new scope to establish whether any compute resources have been added or removed.TheAgentHandler.javaclass compares the size of the new scope to the initial scope and adds any new compute resources to theHashSetofManagedObjectReferenceobjects.if (!oldScope.containsAll(newScope) || oldScope.size() != newScope.size()) { AgencyComputeResourceScope scope = new AgencyComputeResourceScope(); scope.getComputeResource().addAll(newScope); agencyConfigInfo.setScope(scope); changed = true; }
- If the new scope differs from the old scope, callAgency.update()to add the new scope to the ESX agency.if (changed) { assert _agency != null; try { _eamConnection.getStub().update(_agency, agencyConfigInfo); } catch (Exception e) { _log.error("Failed to update agency. Reason: " + e.getMessage()); } updateConfiguration(); } }
You defined a function in a
solution to detect changes of scope and to update an ESX agency.