@Override public Object getQueryableId() { return getId(); }
private void verifyInput(Network network, VdsNetworkInterface nic, NetworkAttachment networkAttachment) { boolean unmanaged = networkAttachment == null && nic != null; boolean newAttachment = networkAttachment != null && networkAttachment.getId() == null && network != null; boolean existingAttachment = networkAttachment != null && networkAttachment.getId() != null && network != null && nic != null; assert unmanaged || newAttachment || existingAttachment : "the input of the ctor is wrong"; //$NON-NLS-1$ }
public void setHostNetworkQos(AnonymousHostNetworkQos hostNetworkQos) { this.hostNetworkQos = hostNetworkQos; if (this.hostNetworkQos != null) { this.hostNetworkQos.setId(this.getId()); } }
private void verifyRelationWithHostNetworkQos(NetworkAttachment entity) { AnonymousHostNetworkQos hostNetworkQos = entity.getHostNetworkQos(); if (hostNetworkQos != null && !Objects.equals(hostNetworkQos.getId(), entity.getId())) { throw new IllegalArgumentException( String.format("Overridden HostNetworkQos using id %s which does not related to given entity id %s", hostNetworkQos.getId(), entity.getId())); } }
public void addNetworkAttachmentToParameters(NetworkAttachment networkAttachment) { assert networkAttachment.getId() == null : "When adding attachment to parameters its id should be null"; //$NON-NLS-1$ Guid idOfAttachmentNetworkWasPreviouslyAttachedTo = networkIdToExistingAttachmentId.get(networkAttachment.getNetworkId()); networkAttachment.setId(idOfAttachmentNetworkWasPreviouslyAttachedTo); if (idOfAttachmentNetworkWasPreviouslyAttachedTo != null) { removedNetworkAttachments.remove(idOfAttachmentNetworkWasPreviouslyAttachedTo); } networkAttachments.add(networkAttachment); }
private void initNetworkIdToExistingAttachmentMap() { Map<Guid, Guid> networkIdToExistingAttachmentId = new HashMap<>(); for (NetworkAttachment attachment : hostSetupNetworksParametersData.getNetworkAttachments()) { networkIdToExistingAttachmentId.put(attachment.getNetworkId(), attachment.getId()); } hostSetupNetworksParametersData.setNetworkIdToExistingAttachmentId(networkIdToExistingAttachmentId); }
protected final NetworkAttachment setUpEntityExpectations(NetworkAttachment entity, int index) { when(entity.getId()).thenReturn(GUIDS[index]); when(entity.getNetworkId()).thenReturn(GUIDS[index]); setUpEntityExpectations(entity); return entity; }
private void assertNetworkAttachment(NetworkAttachment networkAttachment, Guid attachmentId, Guid networkId, Guid nicId) { assertThat("id mismatch", networkAttachment.getId(), is(attachmentId)); //$NON-NLS-1$ assertThat("network id mismatch", networkAttachment.getNetworkId(), equalTo(networkId)); //$NON-NLS-1$ assertThat("nicId mismatch", networkAttachment.getNicId(), equalTo(nicId)); //$NON-NLS-1$ }
protected final NetworkAttachment setUpEntityExpectations(NetworkAttachment entity, int index) { when(entity.getId()).thenReturn(GUIDS[index]); when(entity.getNetworkId()).thenReturn(GUIDS[index]); setUpEntityExpectations(entity); return entity; }
private void initNetworkIdToExistingAttachmentIdMap(NetworkAttachment... attachments) { Map<Guid, Guid> networkIdToExistingAttachmentId = new HashMap<>(); for (NetworkAttachment attachment : attachments) { networkIdToExistingAttachmentId.put(attachment.getNetworkId(), attachment.getId()); } dataFromHostSetupNetworksModel.setNetworkIdToExistingAttachmentId(networkIdToExistingAttachmentId); }
@Override public void removeByNetworkId(Guid networkId) { List<NetworkAttachment> networkAttachments = getAllForNetwork(networkId); for (NetworkAttachment networkAttachment : networkAttachments) { hostNetworkQosDao.remove(networkAttachment.getId()); } getCallsHandler().executeModification("RemoveNetworkAttachmentByNetworkId", createIdParameterMapper(networkId)); }
@Test public void testDetachingPreexistingNetworkAttachment() { NetworkAttachment attachment = createAttachmentOnNetworkModelAndUpdateParams(networkInterfaceModelOfNicA, logicalNetworkModelOfNetworkA); Guid attachmentId = attachment.getId(); NetworkOperation.DETACH_NETWORK.getTarget().executeNetworkCommand( logicalNetworkModelOfNetworkA, null, dataFromHostSetupNetworksModel); assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(0)); assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(1)); Guid removedNetworkAttachmentId = dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().iterator().next(); assertThat("id mismatch", removedNetworkAttachmentId, is(attachmentId)); //$NON-NLS-1$ }
public NetworkAttachment(NetworkAttachment networkAttachment) { id = networkAttachment.getId(); nicId = networkAttachment.getNicId(); nicName = networkAttachment.getNicName(); networkId = networkAttachment.getNetworkId(); networkName = networkAttachment.getNetworkName(); ipConfiguration = networkAttachment.getIpConfiguration(); properties = networkAttachment.getProperties(); overrideConfiguration = networkAttachment.isOverrideConfiguration(); reportedConfigurations = networkAttachment.getReportedConfigurations(); }
/** * Ensures that the remove is working correctly */ @Test public void testRemove() { dao.save(networkAttachment); NetworkAttachment result = dao.get(networkAttachment.getId()); assertNotNull(result); dao.remove(networkAttachment.getId()); assertNull(dao.get(networkAttachment.getId())); assertNull(dnsResolverConfigurationDao.get(networkAttachment.getDnsResolverConfiguration().getId())); }
@Override public void save(NetworkAttachment entity) { verifyRelationWithHostNetworkQos(entity); hostNetworkQosDao.persistQosChanges(entity.getId(), asHostNetworkQos(entity.getHostNetworkQos())); DnsResolverConfiguration dnsResolverConfiguration = entity.getDnsResolverConfiguration(); if (dnsResolverConfiguration != null) { Validate.isTrue(dnsResolverConfiguration.getId() == null); dnsResolverConfigurationDao.save(dnsResolverConfiguration); } super.save(entity); }
/** * Ensures that the save is working correctly */ @Test public void testSave() { dao.save(networkAttachment); NetworkAttachment result = dao.get(networkAttachment.getId()); assertNotNull(result); assertNetworkAttachmentEquals(networkAttachment, result); }
@Override protected MapSqlParameterSource createFullParametersMapper(NetworkAttachment networkAttachment) { MapSqlParameterSource mapper = createIdParameterMapper(networkAttachment.getId()) .addValue("network_id", networkAttachment.getNetworkId()) .addValue("nic_id", networkAttachment.getNicId()) .addValue("custom_properties", SerializationFactory.getSerializer().serialize(networkAttachment.getProperties())); mapIpConfiguration(networkAttachment, mapper); mapper.addValue("dns_resolver_configuration_id", getDnsResolverConfigurationId(networkAttachment)); return mapper; }
private void assertNetworkAttachmentEquals(NetworkAttachment expected, NetworkAttachment actual) { assertEquals(expected.getId(), actual.getId()); assertEquals(expected.getNetworkId(), actual.getNetworkId()); assertEquals(expected.getNicId(), actual.getNicId()); assertEquals(expected.getNicName(), actual.getNicName()); assertEquals(expected.getIpConfiguration(), actual.getIpConfiguration()); assertEquals(expected.getProperties().entrySet(), actual.getProperties().entrySet()); assertEquals(expected.getDnsResolverConfiguration(), actual.getDnsResolverConfiguration()); }
@Test public void testRemoveByNetworkId() { //store ids for for case it gets changed during processing somehow. Guid networkAttachmentId = networkAttachment.getId(); Guid networkIdUsedForAttachmentRemoval = networkAttachment.getNetworkId(); //persist & verify presence dao.save(networkAttachment); assertNotNull(dao.get(networkAttachmentId)); //delete & verify absence dao.removeByNetworkId(networkIdUsedForAttachmentRemoval); assertNull(dao.get(networkAttachmentId)); }