@Test public void createAffinityRuleThrowsAntiAffineHostGroupNotFoundException() throws Exception { VmInputs vmInputs = getVmInputs(); doReturn(clusterConfigInfoExMock).when(clusterComputeResourceServiceSpy, GET_CLUSTER_CONFIGURATION, any(ConnectionResources.class), any(ManagedObjectReference.class), any(String.class)); doReturn(false).when(clusterComputeResourceServiceSpy, RULE_EXISTS, any(ClusterConfigInfoEx.class), any(String.class)); doThrow(new RuntimeFaultFaultMsg(ANTI_AFFINE_HOST_GROUP_DOES_NOT_EXIST, new RuntimeFault())) .when(clusterComputeResourceServiceSpy, ADD_ANTI_AFFINE_GROUP_TO_RULE, any(ClusterVmHostRuleInfo.class), any(ClusterConfigInfoEx.class), any(String.class)); thrownException.expectMessage(ANTI_AFFINE_HOST_GROUP_DOES_NOT_EXIST); clusterComputeResourceServiceSpy.createAffinityRule(httpInputsMock, vmInputs, "", "antiAffineHostGroup"); }
public Map<String, String> createAffinityRule(HttpInputs httpInputs, VmInputs vmInputs, String affineHostGroupName, String antiAffineHostGroupName) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs); try { ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName()); if (ruleExists(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs.getRuleName())) { throw new Exception(String.format(RULE_ALREADY_EXISTS, vmInputs.getRuleName())); } else { ClusterVmHostRuleInfo clusterVmHostRuleInfo = getClusterVmHostRuleInfo(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs, affineHostGroupName, antiAffineHostGroupName); ClusterRuleSpec clusterRuleSpec = new ClusterRuleSpec(); clusterRuleSpec.setInfo(clusterVmHostRuleInfo); clusterRuleSpec.setOperation(ArrayUpdateOperation.ADD); return reconfigureClusterRule(vmInputs, connectionResources, clusterMor, clusterRuleSpec); } } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } }
ClusterComputeResourceService { public Map<String, String> createAffinityRule(HttpInputs httpInputs, VmInputs vmInputs, String affineHostGroupName, String antiAffineHostGroupName) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs); try { ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName()); if (ruleExists(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs.getRuleName())) { throw new Exception(String.format(RULE_ALREADY_EXISTS, vmInputs.getRuleName())); } else { ClusterVmHostRuleInfo clusterVmHostRuleInfo = getClusterVmHostRuleInfo(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs, affineHostGroupName, antiAffineHostGroupName); ClusterRuleSpec clusterRuleSpec = new ClusterRuleSpec(); clusterRuleSpec.setInfo(clusterVmHostRuleInfo); clusterRuleSpec.setOperation(ArrayUpdateOperation.ADD); return reconfigureClusterRule(vmInputs, connectionResources, clusterMor, clusterRuleSpec); } } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } } }
ClusterComputeResourceService { public Map<String, String> createAffinityRule(HttpInputs httpInputs, VmInputs vmInputs, String affineHostGroupName, String antiAffineHostGroupName) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs); try { ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName()); if (ruleExists(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs.getRuleName())) { throw new Exception(String.format(RULE_ALREADY_EXISTS, vmInputs.getRuleName())); } else { ClusterVmHostRuleInfo clusterVmHostRuleInfo = getClusterVmHostRuleInfo(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs, affineHostGroupName, antiAffineHostGroupName); ClusterRuleSpec clusterRuleSpec = new ClusterRuleSpec(); clusterRuleSpec.setInfo(clusterVmHostRuleInfo); clusterRuleSpec.setOperation(ArrayUpdateOperation.ADD); return reconfigureClusterRule(vmInputs, connectionResources, clusterMor, clusterRuleSpec); } } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } }  }
ClusterComputeResourceService { public Map<String, String> createAffinityRule(HttpInputs httpInputs, VmInputs vmInputs, String affineHostGroupName, String antiAffineHostGroupName) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs); try { ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName()); if (ruleExists(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs.getRuleName())) { throw new Exception(String.format(RULE_ALREADY_EXISTS, vmInputs.getRuleName())); } else { ClusterVmHostRuleInfo clusterVmHostRuleInfo = getClusterVmHostRuleInfo(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs, affineHostGroupName, antiAffineHostGroupName); ClusterRuleSpec clusterRuleSpec = new ClusterRuleSpec(); clusterRuleSpec.setInfo(clusterVmHostRuleInfo); clusterRuleSpec.setOperation(ArrayUpdateOperation.ADD); return reconfigureClusterRule(vmInputs, connectionResources, clusterMor, clusterRuleSpec); } } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } }  Map<String, String> updateOrAddVmOverride(final HttpInputs httpInputs, final VmInputs vmInputs, final String restartPriority); String getVmOverride(final HttpInputs httpInputs, final VmInputs vmInputs); Map<String, String> createVmGroup(HttpInputs httpInputs, VmInputs vmInputs, List<String> vmNameList); Map<String, String> deleteVmGroup(HttpInputs httpInputs, VmInputs vmInputs); String listGroups(HttpInputs httpInputs, String clusterName, String delimiter, Class clazz); Map<String, String> createHostGroup(HttpInputs httpInputs, VmInputs vmInputs, List<String> hostNameList); Map<String, String> deleteHostGroup(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> createAffinityRule(HttpInputs httpInputs, VmInputs vmInputs,
                                                  String affineHostGroupName, String antiAffineHostGroupName); Map<String, String> deleteClusterRule(HttpInputs httpInputs, VmInputs vmInputs); }
ClusterComputeResourceService { public Map<String, String> createAffinityRule(HttpInputs httpInputs, VmInputs vmInputs, String affineHostGroupName, String antiAffineHostGroupName) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs); try { ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName()); if (ruleExists(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs.getRuleName())) { throw new Exception(String.format(RULE_ALREADY_EXISTS, vmInputs.getRuleName())); } else { ClusterVmHostRuleInfo clusterVmHostRuleInfo = getClusterVmHostRuleInfo(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs, affineHostGroupName, antiAffineHostGroupName); ClusterRuleSpec clusterRuleSpec = new ClusterRuleSpec(); clusterRuleSpec.setInfo(clusterVmHostRuleInfo); clusterRuleSpec.setOperation(ArrayUpdateOperation.ADD); return reconfigureClusterRule(vmInputs, connectionResources, clusterMor, clusterRuleSpec); } } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } }  Map<String, String> updateOrAddVmOverride(final HttpInputs httpInputs, final VmInputs vmInputs, final String restartPriority); String getVmOverride(final HttpInputs httpInputs, final VmInputs vmInputs); Map<String, String> createVmGroup(HttpInputs httpInputs, VmInputs vmInputs, List<String> vmNameList); Map<String, String> deleteVmGroup(HttpInputs httpInputs, VmInputs vmInputs); String listGroups(HttpInputs httpInputs, String clusterName, String delimiter, Class clazz); Map<String, String> createHostGroup(HttpInputs httpInputs, VmInputs vmInputs, List<String> hostNameList); Map<String, String> deleteHostGroup(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> createAffinityRule(HttpInputs httpInputs, VmInputs vmInputs,
                                                  String affineHostGroupName, String antiAffineHostGroupName); Map<String, String> deleteClusterRule(HttpInputs httpInputs, VmInputs vmInputs);  }