/** * This operation is used to query the information of the Network Service Descriptor (NSD), * including any related VNFFGD and VLD. */ @Override public NetworkServiceDescriptor query(String id, String projectId) { return nsdRepository.findFirstByIdAndProjectId(id, projectId); }
/** Removes the Security with idS from NSD with id */ @Override public void deleteSecurty(String idNsd, String idS, String projectId) throws NotFoundException { if (nsdRepository.findFirstByIdAndProjectId(idNsd, projectId) == null) throw new NotFoundException("No NSD found with ID " + idNsd); nsdRepository.deleteSecurity(idNsd, idS); }
/** * Removes the VNFDependency into NSD * * @param idNsd of NSD * @param idVnfd of VNFD */ @Override public void deleteVNFDependency(String idNsd, String idVnfd, String projectId) throws NotFoundException { log.debug("Removing VNFDependency with id: " + idVnfd + " from NSD with id: " + idNsd); if (nsdRepository.findFirstByIdAndProjectId(idNsd, projectId) == null) throw new NotFoundException("No NSD found with ID " + idNsd); nsdRepository.deleteVNFDependency(idNsd, idVnfd); return; }
/** * Returns the VNFDependency selected by idVnfd into NSD with idNsd * * @return VNFDependency */ @Override public VNFDependency getVnfDependency(String idNsd, String idVnfd, String projectId) throws NotFoundException { if (nsdRepository.findFirstByIdAndProjectId(idNsd, projectId) == null) throw new NotFoundException("No NSD found with ID " + idNsd); return vnfDependencyRepository.findOne(idVnfd); }
/** * Adds or Updates the Security into NSD * * @return Security */ @Override public Security addSecurity(String id, Security security, String projectId) throws NotFoundException { if (nsdRepository.findFirstByIdAndProjectId(id, projectId) == null) throw new NotFoundException("No NSD found with ID " + id); return nsdRepository.addSecurity(id, security); }
/** * Save or Update the VNFDependency into NSD with idNsd * * @return VNFDependency */ @Override public VNFDependency saveVNFDependency( String idNsd, VNFDependency vnfDependency, String projectId) throws NotFoundException { if (nsdRepository.findFirstByIdAndProjectId(idNsd, projectId) == null) throw new NotFoundException("No NSD found with ID " + idNsd); nsdRepository.addVnfDependency(vnfDependency, idNsd); return vnfDependency; }
/** * This operation added a new VNFD to the NSD with {@code id} * * @param vnfd VirtualNetworkFunctionDescriptor to be persisted * @param id of NetworkServiceDescriptor * @return the persisted VirtualNetworkFunctionDescriptor */ public VirtualNetworkFunctionDescriptor addVnfd( VirtualNetworkFunctionDescriptor vnfd, String id, String projectId) throws NotFoundException { if (nsdRepository.findFirstByIdAndProjectId(id, projectId) == null) throw new NotFoundException("No NSD found with ID " + id); return nsdRepository.addVnfd(vnfd, id); }
/** * Add or Update the PhysicalNetworkFunctionDescriptor into NSD * * @return PhysicalNetworkFunctionDescriptor */ @Override public PhysicalNetworkFunctionDescriptor addPnfDescriptor( PhysicalNetworkFunctionDescriptor pDescriptor, String idNsd, String projectId) throws NotFoundException { if (nsdRepository.findFirstByIdAndProjectId(idNsd, projectId) == null) throw new NotFoundException("No NSD found with ID " + idNsd); return nsdRepository.addPnfDescriptor(pDescriptor, idNsd); }
/** * Deletes the PhysicalNetworkFunctionDescriptor from NSD * * @param idNsd of NSD * @param idPnf of PhysicalNetworkFunctionDescriptor */ @Override public void deletePhysicalNetworkFunctionDescriptor(String idNsd, String idPnf, String projectId) throws NotFoundException { if (nsdRepository.findFirstByIdAndProjectId(idNsd, projectId) == null) throw new NotFoundException("No NSD found with ID " + idNsd); nsdRepository.deletePhysicalNetworkFunctionDescriptor(idNsd, idPnf); }
@Override public void addVnfr( NetworkServiceRecord networkServiceRecord, VirtualNetworkFunctionDescriptor vnfd, DeployNSRBody body, Map<String, Set<String>> vduVimInstances, String monitoringIp) throws NotFoundException, InterruptedException, BadFormatException, ExecutionException { NetworkServiceDescriptor nsd = nsdRepository.findFirstByIdAndProjectId( networkServiceRecord.getDescriptor_reference(), networkServiceRecord.getProjectId()); vnfStateHandler.handleVNF(nsd, networkServiceRecord, body, vduVimInstances, vnfd, monitoringIp); }
/** * Returns the PhysicalNetworkFunctionDescriptor with idPnf into NSD with idNsd * * @return PhysicalNetworkFunctionDescriptor selected */ @Override public PhysicalNetworkFunctionDescriptor getPhysicalNetworkFunctionDescriptor( String idNsd, String idPnf, String projectId) throws NotFoundException { if (nsdRepository.findFirstByIdAndProjectId(idNsd, projectId) == null) throw new NotFoundException("No NSD found with ID " + idNsd); PhysicalNetworkFunctionDescriptor physicalNetworkFunctionDescriptor = pnfDescriptorRepository.findOne(idPnf); if (physicalNetworkFunctionDescriptor == null) throw new NotFoundException( "PhysicalNetworkFunctionDescriptor with id " + idPnf + " doesn't exist"); return physicalNetworkFunctionDescriptor; }
/** * Returns the VirtualNetworkFunctionDescriptor with the ID idVnfd from the Network Service * Descriptor with ID idNsd. * * @param idNsd of NSD * @param idVnfd of VirtualNetworkFunctionDescriptor */ @Override public VirtualNetworkFunctionDescriptor getVirtualNetworkFunctionDescriptor( String idNsd, String idVnfd, String projectId) throws NotFoundException { NetworkServiceDescriptor nsd = nsdRepository.findFirstByIdAndProjectId(idNsd, projectId); if (nsd == null) throw new NotFoundException("Did not find a Network Service Descriptor with ID " + idNsd); for (VirtualNetworkFunctionDescriptor vnfd : nsd.getVnfd()) { if (vnfd.getId().equals(idVnfd)) { if (!vnfd.getProjectId().equals(projectId)) throw new UnauthorizedUserException( "VNFD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)"); return vnfd; } } throw new NotFoundException( "The NSD with ID " + idNsd + " does not contain a VNFD with ID " + idVnfd); }
/** * Updates the VNFDescriptor into NSD with idNsd * * @return VirtualNetworkFunctionDescriptor */ @Override public VirtualNetworkFunctionDescriptor updateVNF( String idNsd, String idVfn, VirtualNetworkFunctionDescriptor vnfDescriptor, String projectId) throws NotFoundException { if (nsdRepository.findFirstByIdAndProjectId(idNsd, projectId) == null) throw new NotFoundException("No NSD found with ID " + idNsd); if (vnfdRepository.findFirstByIdAndProjectId(vnfDescriptor.getId(), projectId) == null) throw new NotFoundException("No VNFD found with ID " + vnfDescriptor.getId()); nsdRepository.addVnfd(vnfDescriptor, idNsd); return vnfDescriptor; }
@Test public void nsdManagementQueryTest() throws WrongStatusException, EntityInUseException, BadRequestException, NotFoundException { when(nsdRepository.findAll()).thenReturn(new ArrayList<NetworkServiceDescriptor>()); when(nsdRepository.findByProjectId(anyString())) .thenReturn(new ArrayList<NetworkServiceDescriptor>()); Iterable<NetworkServiceDescriptor> nsds = nsdManagement.query(); Assert.assertEquals(nsds.iterator().hasNext(), false); final NetworkServiceDescriptor nsd_exp = createNetworkServiceDescriptor(); when(nsdRepository.findAll()) .thenReturn( new ArrayList<NetworkServiceDescriptor>() { { add(nsd_exp); } }); when(nsdRepository.findByProjectId(anyString())) .thenReturn( new ArrayList<NetworkServiceDescriptor>() { { add(nsd_exp); } }); nsds = nsdManagement.query(); when(nsrRepository.findAll()).thenReturn(new ArrayList<NetworkServiceRecord>()); Assert.assertEquals(nsds.iterator().hasNext(), true); when(nsdRepository.findFirstByIdAndProjectId(anyString(), eq(projectId))).thenReturn(nsd_exp); nsdManagement.delete(nsd_exp.getId(), projectId); }
@Test public void nsdManagementEnableTest() throws NotFoundException, WrongStatusException, BadFormatException, NetworkServiceIntegrityException, CyclicDependenciesException, EntityInUseException, BadRequestException, IOException, AlreadyExistingException, PluginException, IncompatibleVNFPackage, VimException, InterruptedException, EntityUnreachableException { NetworkServiceDescriptor nsd_exp = createNetworkServiceDescriptor(); when(vimRepository.findByProjectId(anyString())) .thenReturn( new ArrayList<BaseVimInstance>() { { add(createVimInstance()); } }); nsdManagement.onboard(nsd_exp, projectId); when(nsdRepository.findFirstByIdAndProjectId(anyString(), eq(projectId))).thenReturn(nsd_exp); when(nsdRepository.findFirstById(anyString())).thenReturn(nsd_exp); Assert.assertTrue(nsdManagement.enable(nsd_exp.getId())); Assert.assertTrue(nsd_exp.isEnabled()); when(nsrRepository.findAll()).thenReturn(new ArrayList<NetworkServiceRecord>()); when(nsrRepository.findByProjectId(anyString())) .thenReturn(new ArrayList<NetworkServiceRecord>()); nsdManagement.delete(nsd_exp.getId(), projectId); }
/** * This operation allows updating a Network Service Descriptor (NSD), including any related VNFFGD * and VLD.This update might include creating/deleting new VNFFGDs and/or new VLDs. * * @param newNsd : the new values to be updated */ @Override public NetworkServiceDescriptor update(NetworkServiceDescriptor newNsd, String projectId) throws NotFoundException, BadRequestException { SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z"); if (newNsd.getId() == null || newNsd.getId().isEmpty()) { throw new BadRequestException("No id found in the passed NSD"); } NetworkServiceDescriptor updatingNsd = nsdRepository.findFirstByIdAndProjectId(newNsd.getId(), projectId); if (updatingNsd == null) { throw new NotFoundException( "Did not find a Network Service Descriptor with ID " + newNsd.getId()); } updatingNsd.setUpdatedAt(format.format(new Date())); updatingNsd.setName(newNsd.getName()); updatingNsd.setEnabled(newNsd.isEnabled()); updatingNsd.setNfvo_version(newNsd.getNfvo_version()); updatingNsd.setVendor(newNsd.getVendor()); updatingNsd.setVersion(newNsd.getVersion()); return nsdRepository.save(updatingNsd); }
@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); }
when(nsdRepository.findFirstByIdAndProjectId(anyString(), eq(projectId))).thenReturn(nsd_exp); Assert.assertFalse(nsdManagement.disable(nsd_exp.getId())); Assert.assertFalse(nsd_exp.isEnabled());
log.info("Removing NetworkServiceDescriptor with id " + id); NetworkServiceDescriptor networkServiceDescriptor = nsdRepository.findFirstByIdAndProjectId(id, projectId); if (networkServiceDescriptor == null) throw new BadRequestException("Did not find a Network Service Descriptor with ID " + id);
private void assertEqualsNSD(NetworkServiceDescriptor nsd_exp) throws NoResultException { when(nsdRepository.findFirstByIdAndProjectId(nsd_exp.getId(), projectId)).thenReturn(nsd_exp); NetworkServiceDescriptor nsd = nsdManagement.query(nsd_exp.getId(), projectId); Assert.assertEquals(nsd_exp.getId(), nsd.getId()); Assert.assertEquals(nsd_exp.getName(), nsd.getName()); Assert.assertEquals(nsd_exp.getVendor(), nsd.getVendor()); Assert.assertEquals(nsd_exp.getHbVersion(), nsd.getHbVersion()); Assert.assertEquals(nsd_exp.isEnabled(), nsd.isEnabled()); }