@Override public BaseVimInstance query(String id, String projectId) { return vimRepository.findFirstByIdAndProjectId(id, 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); }
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 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); } }
/** * 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; }
@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); }
throws VimException, PluginException, IOException, BadRequestException, NotFoundException { validateVimInstance(vimInstance, ""); BaseVimInstance vimInstanceOld = vimRepository.findFirstByIdAndProjectId(id, projectId); if (vimInstanceOld == null) throw new NotFoundException("VIM Instance with ID " + id + " not found.");
for (VNFCInstance vnfcInstance : vdu.getVnfc_instance()) { BaseVimInstance vimInstance = vimInstanceRepository.findFirstByIdAndProjectId( vnfcInstance.getVim_id(), projectId); if (!vimInstance.getType().equals("test")) {
@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()); }
initMocks(); OpenstackVimInstance vimInstanceExp = createVimInstance(); when(vimRepository.findFirstByIdAndProjectId(vimInstanceExp.getId(), projectId)) .thenReturn(vimInstanceExp); when(vimRepository.save(vimInstanceExp)).thenReturn(vimInstanceExp);