@Override public BaseVimInstance query(String vimId) { return vimRepository.findFirstById(vimId); }
@Override public Iterable<BaseVimInstance> queryByProjectId(String projectId) { return vimRepository.findByProjectId(projectId); }
/** Removes the NFVImage with idImage from VimInstance with idVim */ @Override public void deleteImage(String idVim, String idImage, String projectId) throws VimException, PluginException, EntityUnreachableException, IOException, NotFoundException { BaseVimInstance vimInstance = vimRepository.findFirstByIdAndProjectId(idVim, projectId); if (vimInstance == null) throw new NotFoundException("VIM Instance with ID " + idVim + " not found."); if (!vimInstance.isActive()) { throw new EntityUnreachableException( "VimInstance " + vimInstance.getName() + " is not reachable"); } vimRepository.deleteImage(idVim, idImage); refresh(vimInstance, false); }
/** * Adds a new NFVImage to the VimInstance with id * * @param id of VimInstance * @param image the new NFVImage * @return NFVImage */ @Override public BaseNfvImage addImage(String id, BaseNfvImage image, String projectId) throws VimException, PluginException, EntityUnreachableException, IOException, NotFoundException { BaseVimInstance vimInstance = vimRepository.findFirstByIdAndProjectId(id, projectId); if (vimInstance == null) throw new NotFoundException("No VIMInstance found with ID " + id); if (!vimInstance.isActive()) { throw new EntityUnreachableException( "VimInstance " + vimInstance.getName() + " is not reachable"); } image = vimRepository.addImage(id, image); refresh(vimInstance, true); return image; }
}); when(vimRepository.findByProjectIdAndName(anyString(), anyString())) .thenReturn(createVimInstance()); when(vimRepository.findByProjectId(anyString())) .thenReturn( new ArrayList<BaseVimInstance>() { when(vimRepository.findAll()) .thenReturn( new ArrayList<BaseVimInstance>() {
vimInstanceRepository.findByProjectIdAndName(vdu.getProjectId(), vimName);
for (BaseVimInstance vimInstance : vimRepository.findAll()) { if (vimInstance.getType().equals("test")) { continue; + " is not reachable anymore. Set the VimInstance to not active."); vimInstance.setActive(false); vimRepository.save(vimInstance); } else if (!vimInstance.isActive() && InetAddress.getByName(authUrl.getHost()).isReachable(5000)) { + " is reachable. Set the VimInstance to active."); vimInstance.setActive(true); vimRepository.save(vimInstance);
NetworkServiceDescriptor nsd_exp = createNetworkServiceDescriptor(); nsd_exp.setEnabled(true); when(vimRepository.findAll()) .thenReturn( new ArrayList<BaseVimInstance>() { when(vimRepository.findByProjectId(anyString())) .thenReturn( new ArrayList<BaseVimInstance>() {
initMocks(); OpenstackVimInstance vimInstanceExp = createVimInstance(); when(vimRepository.findFirstByIdAndProjectId(vimInstanceExp.getId(), projectId)) .thenReturn(vimInstanceExp); when(vimRepository.save(vimInstanceExp)).thenReturn(vimInstanceExp); OpenstackVimInstance vimInstance_new = createVimInstance(); vimInstance_new.setName("UpdatedName"); vimInstance_new.setTenant("UpdatedTenant"); vimInstance_new.setUsername("UpdatedUsername"); when(vimRepository.save(any(BaseVimInstance.class))).thenReturn(vimInstance_new); when(vnfdRepository.findByProjectId(anyString())).thenReturn(new ArrayList<>()); when(vnfrRepository.findByProjectId(anyString())).thenReturn(new ArrayList<>());
@Test public void nfvImageManagementDeleteTest() throws NotFoundException, BadRequestException { OpenstackVimInstance vimInstance_exp = createVimInstance(); when(vimRepository.findOne(vimInstance_exp.getId())).thenReturn(vimInstance_exp); when(vimRepository.findFirstByIdAndProjectId(vimInstance_exp.getId(), projectId)) .thenReturn(vimInstance_exp); vimManagement.delete(vimInstance_exp.getId(), projectId); when(vimRepository.findOne(vimInstance_exp.getId())).thenReturn(null); when(vimRepository.findFirstByIdAndProjectId(vimInstance_exp.getId(), projectId)) .thenReturn(null); BaseVimInstance vimInstance_new = vimManagement.query(vimInstance_exp.getId(), projectId); Assert.assertNull(vimInstance_new); } }
@Override public BaseVimInstance query(String id, String projectId) { return vimRepository.findFirstByIdAndProjectId(id, projectId); }
@Override public void delete(String id, String projectId) throws NotFoundException, BadRequestException { BaseVimInstance vimInstance = vimRepository.findFirstByIdAndProjectId(id, projectId); if (vimInstance == null) { throw new NotFoundException("Vim Instance with id " + id + " was not found"); } if (checkForVimInVnfr) { for (NetworkServiceRecord nsr : nsrRepository.findByProjectId(projectId)) { for (VirtualNetworkFunctionRecord vnfr : nsr.getVnfr()) { for (VirtualDeploymentUnit vdu : vnfr.getVdu()) { if (vdu.getVimInstanceName().contains(vimInstance.getName())) { throw new BadRequestException( "Cannot delete VIM Instance " + vimInstance.getName() + " while it is in use."); } } } } } vimRepository.delete(vimInstance); }
vimInstance = vimRepository.save(vimInstance);
@Test public void nsdManagementUpdateTest() throws NotFoundException, BadFormatException, NetworkServiceIntegrityException, CyclicDependenciesException, WrongStatusException, EntityInUseException, BadRequestException, AlreadyExistingException, IOException, VimException, IncompatibleVNFPackage, PluginException, InterruptedException, EntityUnreachableException { when(nsdRepository.findAll()).thenReturn(new ArrayList<NetworkServiceDescriptor>()); when(nsdRepository.findByProjectId(anyString())) .thenReturn(new ArrayList<NetworkServiceDescriptor>()); NetworkServiceDescriptor nsd_exp = createNetworkServiceDescriptor(); when(vimRepository.findAll()) .thenReturn( new ArrayList<BaseVimInstance>() { { add(createVimInstance()); } }); nsdManagement.onboard(nsd_exp, projectId); when(nsdRepository.findOne(nsd_exp.getId())).thenReturn(nsd_exp); when(nsdRepository.findFirstByIdAndProjectId(nsd_exp.getId(), projectId)).thenReturn(nsd_exp); NetworkServiceDescriptor new_nsd = createNetworkServiceDescriptor(); new_nsd.setName("UpdatedName"); nsdManagement.update(new_nsd, projectId); new_nsd.setId(nsd_exp.getId()); assertEqualsNSD(new_nsd); when(nsrRepository.findAll()).thenReturn(new ArrayList<NetworkServiceRecord>()); nsdManagement.delete(nsd_exp.getId(), projectId); }
AlreadyExistingException { when(vimRepository.findByProjectIdAndName(anyString(), anyString())) .thenReturn(createVimInstance()); NetworkServiceDescriptor networkServiceDescriptor = createNetworkServiceDescriptor(); when(nsdRepository.findFirstByIdAndProjectId(anyString(), eq(projectId))) .thenReturn(networkServiceDescriptor); when(vimRepository.findAll()) .thenReturn( new ArrayList<BaseVimInstance>() { when(vimRepository.findByProjectId(anyString())) .thenReturn( new ArrayList<BaseVimInstance>() {
@Test public void vnfLifecycleOperationGrantingTest() throws VimException, PluginException { VirtualNetworkFunctionRecord vnfr = createVirtualNetworkFunctionRecord(); when(vimInstanceRepository.findByProjectIdAndName(anyString(), anyString())) .thenReturn(createVimInstance()); when(vimBroker.getLeftQuota(any(BaseVimInstance.class))).thenReturn(createMaxQuota()); Map<String, BaseVimInstance> granted = vnfLifecycleOperationGranting.grantLifecycleOperation(vnfr); log.debug(granted.size() + " == " + vnfr.getVdu().size()); Assert.assertTrue(granted.size() == vnfr.getVdu().size()); when(vimBroker.getLeftQuota(any(BaseVimInstance.class))).thenReturn(createMinQuota()); granted = vnfLifecycleOperationGranting.grantLifecycleOperation(vnfr); Assert.assertFalse(granted.size() == vnfr.getVdu().size()); }
@Test public void nfvImageManagementQueryTest() { OpenstackVimInstance vimInstance_exp = createVimInstance(); when(vimRepository.findOne(vimInstance_exp.getId())).thenReturn(vimInstance_exp); when(vimRepository.findFirstByIdAndProjectId(vimInstance_exp.getId(), projectId)) .thenReturn(vimInstance_exp); OpenstackVimInstance vimInstance_new = (OpenstackVimInstance) vimManagement.query(vimInstance_exp.getId(), projectId); Assert.assertEquals(vimInstance_exp.getId(), vimInstance_new.getId()); Assert.assertEquals(vimInstance_exp.getName(), vimInstance_new.getName()); Assert.assertEquals(vimInstance_exp.getFlavours().size(), vimInstance_new.getFlavours().size()); Assert.assertEquals(vimInstance_exp.getImages().size(), vimInstance_new.getImages().size()); Assert.assertEquals(vimInstance_exp.getNetworks().size(), vimInstance_new.getNetworks().size()); }
public BaseNfvImage queryImage(String idVim, String idImage, String projectId) throws EntityUnreachableException, NotFoundException { BaseVimInstance vimInstance = vimRepository.findFirstByIdAndProjectId(idVim, projectId); if (vimInstance == null) throw new NotFoundException("VIM Instance with ID " + idVim + " not found."); if (!vimInstance.isActive()) { throw new EntityUnreachableException( "VimInstance " + vimInstance.getName() + " is not reachable"); } try { refresh(vimInstance, true); } catch (Exception e) { log.error( "Unable to refresh the VIM instance with ID " + idVim + " before querying the image with ID " + idImage); e.printStackTrace(); } for (BaseNfvImage image : vimInstance.getImages()) { if (image.getId().equals(idImage)) return imageRepository.findOne(idImage); } throw new NotFoundException( "Did not find image with ID " + idImage + " for the VIM instance " + vimInstance.getName() + " with ID " + idVim); }
@Test public void vimManagementRefreshTest() throws VimException, PluginException, IOException, ExecutionException, InterruptedException { initMocks(); BaseVimInstance vimInstance = createVimInstance(); when(vimRepository.save(any(BaseVimInstance.class))).thenReturn(vimInstance); vimManagement.refresh(vimInstance, false).get(); // Assert.assertEquals(2, vimInstance.getFlavours().size()); Assert.assertEquals(2, vimInstance.getImages().size()); Assert.assertEquals(1, vimInstance.getNetworks().size()); }
AlreadyExistingException { when(vimRepository.findByProjectIdAndName(anyString(), anyString())) .thenReturn(createVimInstance()); when(nsrRepository.save(any(NetworkServiceRecord.class))) virtualNetworkFunctionDescriptor.getLifecycle_event().add(event); final BaseVimInstance vimInstance = createVimInstance(); when(vimRepository.findAll()) .thenReturn( new ArrayList<BaseVimInstance>() { when(vimRepository.findByProjectId(anyString())) .thenReturn( new ArrayList<BaseVimInstance>() {