@Override public int hashCode() { return Objects.hash( super.hashCode(), getSlaves(), getActiveSlave() ); }
private boolean bondsHasSameSlaves(Bond existingNic) { Collection<String> slavesOfBondFromRequest = replaceNullWithEmptyList(getSlaves()); Collection<String> slavesOfExistingBond = replaceNullWithEmptyList(existingNic.getSlaves()); //bonds can be in any order, and I don't want to change this order during this check. return slavesOfBondFromRequest.size() == slavesOfExistingBond.size() && slavesOfBondFromRequest.containsAll(slavesOfExistingBond); }
public static CreateOrUpdateBond fromBond(Bond bond) { CreateOrUpdateBond createOrUpdateBond = new CreateOrUpdateBond(); createOrUpdateBond.setId(bond.getId()); createOrUpdateBond.setName(bond.getName()); createOrUpdateBond.setSlaves(new HashSet<>(bond.getSlaves())); createOrUpdateBond.setBondOptions(bond.getBondOptions()); return createOrUpdateBond; }
@Test public void testRemoveSlaveFromBond() { existingBond.getSlaves().add(nicC.getName()); addBondToParamsAndModel(existingBond, bondNetworkInterfaceModelA, Collections.emptyList()); when(bondNetworkInterfaceModelA.getSlaves()) .thenReturn(Arrays.asList(networkInterfaceModelOfNicA, networkInterfaceModelOfNicB, networkInterfaceModelOfNicC)); NetworkAttachment networkAttachment = createAttachmentOnNetworkModelAndUpdateParams(bondNetworkInterfaceModelA, logicalNetworkModelOfNetworkA); when(networkInterfaceModelOfNicA.getBond()).thenReturn(bondNetworkInterfaceModelA); NetworkOperation.REMOVE_FROM_BOND.getTarget().executeNetworkCommand( networkInterfaceModelOfNicA, null, dataFromHostSetupNetworksModel); // related network attachment will be updated, not removed and created new one. assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1)); Guid networkAttachmentId = dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next().getId(); assertThat("id mismatch", networkAttachmentId, is(networkAttachment.getId())); //$NON-NLS-1$ assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0)); assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1)); CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next(); assertBond(newOrModifiedBond, existingBondId, Arrays.asList(nicB, nicC)); assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(0)); }
@Override protected ToStringBuilder appendAttributes(ToStringBuilder tsb) { return super.appendAttributes(tsb) .append("macAddress", getMacAddress()) .append("bondOptions", getBondOptions()) .append("labels", getLabels()) .append("slaves", getSlaves()) .append("activeSlave", getActiveSlave()); }
@Mapping(from = HostNic.class, to = Bond.class) public static Bond map(HostNic model, Bond template) { Bond entity = template == null ? new Bond() : template; if (model.isSetId()) { entity.setId(GuidUtils.asGuid(model.getId())); } if (model.isSetName()) { entity.setName(model.getName()); } if (model.isSetBonding()) { entity.setBonded(true); if (model.getBonding().isSetSlaves()) { entity.getSlaves().clear(); for (HostNic slave : model.getBonding().getSlaves().getHostNics()) { if (slave.isSetName()) { entity.getSlaves().add(slave.getName()); } } } if (model.getBonding().isSetOptions()) { entity.setBondOptions(calculateBondingOptionsString(model)); } } if (model.isSetQos()) { entity.setQos((HostNetworkQos) QosMapper.map(model.getQos(), null)); } return entity; }
@Test public void testBondMapping() { HostNic model = new HostNic(); model.setId(Guid.newGuid().toString()); model.setName(RandomUtils.instance().nextString(10)); model.setBonding(new Bonding()); model.getBonding().setSlaves(new HostNics()); HostNic slaveA = new HostNic(); slaveA.setName(RandomUtils.instance().nextString(10)); model.getBonding().getSlaves().getHostNics().add(slaveA); Bond entity = HostNicMapper.map(model, null); assertNotNull(entity); assertEquals(model.getId(), entity.getId().toString()); assertEquals(model.getName(), entity.getName()); assertEquals(model.getBonding().getSlaves().getHostNics().size(), entity.getSlaves().size()); for (HostNic slave : model.getBonding().getSlaves().getHostNics()) { assertTrue(entity.getSlaves().contains(slave.getName())); } }