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 your solution in an application server.
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 your solution, a user can select the ESXi
hosts on which to run the solution from a list on the solution Configuration page. The solution can update the scope of the sample ESX agency according to the hosts that the user selects.Your solution can define a function to update the scope of the ESX agency in the
MyAgentHandler.java
class.- Write a function that implements the vSphere Web Services API to detect compute resources on which to run the solution.Your solution can provide a helper class,MyVcUtils.java, that defines functions to obtain the compute resources on which to run the solution.MyAgentHandler.javacalls theMyVcUtils.getComputeResources()method to obtain a list ofManagedObjectReferenceobjects for theESXihosts running invCenter Server.public void updateConfig(String[] updates) throws RuntimeFaultFaultMsg { waitForSetup(); boolean changed = false; Map<String, ManagedObjectReference> crs = _myvcUtils.getComputeResources();
- Add theManagedObjectReferenceobjects for the compute resources to aHashSetthat defines the ESX agency scope.TheMyAgentHandler.javaclass adds the list ofManagedObjectReferenceobjects that theMyVcUtils.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.TheMyAgentHandler.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.