/** * Returns the list of VirtualNetworkFunctionDescriptor into a NSD with id * * @param id of NSD * @return Set<VirtualNetworkFunctionDescriptor>: List of VirtualNetworkFunctionDescriptor into * NSD */ @ApiOperation( value = "Returns the Virtual Network Function Records of a NSR", notes = "Returns all the VNFRs that are part of the specified NSR") @RequestMapping( value = "{id}/vnfrecords", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.OK) public Set<VirtualNetworkFunctionRecord> getVirtualNetworkFunctionRecords( @PathVariable("id") String id, @RequestHeader(value = "project-id") String projectId) throws NotFoundException { NetworkServiceRecord nsr = networkServiceRecordManagement.query(id, projectId); log.trace("*****" + nsr.getVnfr().toString()); return nsr.getVnfr(); }
private VirtualNetworkFunctionRecord getVnfrTarget( NetworkServiceRecord networkServiceRecord, String target) throws NotFoundException { for (VirtualNetworkFunctionRecord vnfr : networkServiceRecord.getVnfr()) { if (vnfr.getName().equals(target)) { return vnfr; } } throw new NotFoundException("The vnfr with name: " + target + " is not found"); }
@Override @Transactional public NetworkServiceRecord saveCascade(NetworkServiceRecord networkServiceRecord) { vnfrRepository.save(networkServiceRecord.getVnfr()); return networkServiceRecordRepository.save(networkServiceRecord); }
@Override @Transactional public void deleteVNFRecord(String idNsr, String idVnfr) { SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z"); NetworkServiceRecord nsr = networkServiceRecordRepository.findFirstById(idNsr); if (nsr != null) { nsr.setUpdatedAt(format.format(new Date())); nsr.getVnfr().remove(vnfrRepository.findFirstById(idVnfr)); } vnfrRepository.delete(idVnfr); }
private VirtualNetworkFunctionRecord getVirtualNetworkFunctionRecord( String idVnf, NetworkServiceRecord networkServiceRecord) throws NotFoundException { VirtualNetworkFunctionRecord virtualNetworkFunctionRecord = null; for (VirtualNetworkFunctionRecord virtualNetworkFunctionRecord1 : networkServiceRecord.getVnfr()) { if (virtualNetworkFunctionRecord1.getId().equals(idVnf)) { virtualNetworkFunctionRecord = virtualNetworkFunctionRecord1; break; } } if (virtualNetworkFunctionRecord == null) { throw new NotFoundException("No VirtualNetworkFunctionRecord found with id " + idVnf); } return virtualNetworkFunctionRecord; }
@ApiOperation( value = "Add a Virtual Network Function Record", notes = "Add a new VNFR to an already existing NSR") @RequestMapping( value = "{id}/vnfrecords/", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public VirtualNetworkFunctionRecord postVNFR( @RequestBody @Valid VirtualNetworkFunctionRecord vnfRecord, @PathVariable("id") String id, @RequestHeader(value = "project-id") String projectId) throws NotFoundException { NetworkServiceRecord nsr = networkServiceRecordManagement.query(id, projectId); nsr.getVnfr().add(vnfRecord); networkServiceRecordManagement.update(nsr, id, projectId); return vnfRecord; }
@ApiOperation( value = "Update a Virtual Network Function Record in a NSR", notes = "Specify the ids of the parent NSR and of the VNFR which will be updated") @RequestMapping(value = "{idNsr}/vnfrecords/{idVnfr}/update", method = RequestMethod.POST) @ResponseStatus(HttpStatus.ACCEPTED) public void updateVnfr( @PathVariable("idNsr") String idNsr, @PathVariable("idVnfr") String idVnfr, @RequestHeader(value = "project-id") String projectId) throws NotFoundException, BadFormatException, ExecutionException, InterruptedException { NetworkServiceRecord nsr = networkServiceRecordManagement.query(idNsr, projectId); VirtualNetworkFunctionRecord vnfRecord = networkServiceRecordManagement.getVirtualNetworkFunctionRecord(idNsr, idVnfr, projectId); nsr.getVnfr().add(vnfRecord); log.info("Executing UPDATE for VNFR: " + vnfRecord.getName()); networkServiceRecordManagement.updateVnfr(idNsr, idVnfr, projectId); }
protected VirtualNetworkFunctionRecord getNextToCallStart( VirtualNetworkFunctionRecord virtualNetworkFunctionRecord) { Map<String, Integer> vnfrNames = vnfmManager.getVnfrNames().get(virtualNetworkFunctionRecord.getParent_ns_id()); if (vnfrNames != null) { log.debug("List of VNFRs to start: " + vnfrNames); if (!vnfrNames.isEmpty()) { for (Entry<String, Integer> entry : vnfrNames.entrySet()) { vnfrNames.remove(entry.getKey()); for (VirtualNetworkFunctionRecord vnfr : networkServiceRecordRepository .findFirstById(virtualNetworkFunctionRecord.getParent_ns_id()) .getVnfr()) { if (vnfr.getName().equals(entry.getKey())) { return vnfr; } } return null; } } } return null; }
public Set<String> getNotInitializedVnfrSource(Set<String> ids, NetworkServiceRecord nsr) { Set<String> res = new HashSet<>(); for (String sourceName : ids) { log.debug("Looking for VNFR name: " + sourceName); boolean found = false; for (VirtualNetworkFunctionRecord vnfr : nsr.getVnfr()) { if (sourceName.equals(vnfr.getName())) { found = true; if (vnfr.getStatus().ordinal() < Status.INITIALIZED.ordinal()) res.add(vnfr.getName() + nsr.getId()); } } if (!found) res.add(sourceName + nsr.getId()); } if (!res.isEmpty()) log.debug("There are the following not initialized vnfr sources:" + res); return res; }
private VirtualNetworkFunctionRecord getVNFR(NetworkServiceRecord nsr, String vnfrName) throws NotFoundException { for (VirtualNetworkFunctionRecord vnfr : nsr.getVnfr()) { if (vnfr.getName().equalsIgnoreCase(vnfrName)) { return vnfr; } } throw new NotFoundException( "No VNFR with name " + vnfrName + " in NSR " + nsr.getName() + " (" + nsr.getId() + ")"); }
private String getVNFCHostname(NetworkServiceRecord nsr, String vnfcId) { for (VirtualNetworkFunctionRecord vnfr : nsr.getVnfr()) { for (VirtualDeploymentUnit vdu : vnfr.getVdu()) { for (VNFCInstance vnfcInstance : vdu.getVnfc_instance()) { if (vnfcInstance.getId().equals(vnfcId)) { return vnfcInstance.getHostname(); } } } } return null; }
@Override @Transactional public VirtualNetworkFunctionRecord addVnfr(VirtualNetworkFunctionRecord vnfr, String nsrId) throws NsrNotFoundException { if (networkServiceRecordRepository.exists(nsrId)) { vnfr = vnfrRepository.save(vnfr); SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z"); NetworkServiceRecord nsr = networkServiceRecordRepository.findFirstById(nsrId); nsr.setUpdatedAt(format.format(new Date())); nsr.getVnfr().add(vnfr); return vnfr; } vnfrRepository.delete(vnfr.getId()); throw new NsrNotFoundException( String.format( "NSR with id [%s] does not exist, may be already deleted, ignoring save", nsrId)); }
/** * Returns the VirtualNetworkFunctionRecord with idVnf into NSR with idNsr * * @param idNsr of Nsr * @param idVnf of VirtualNetworkFunctionRecord * @param projectId the current projectId * @return VirtualNetworkFunctionRecord selected */ @Override public VirtualNetworkFunctionRecord getVirtualNetworkFunctionRecord( String idNsr, String idVnf, String projectId) throws NotFoundException { NetworkServiceRecord networkServiceRecord = query(idNsr, projectId); for (VirtualNetworkFunctionRecord virtualNetworkFunctionRecord : networkServiceRecord.getVnfr()) { if (virtualNetworkFunctionRecord.getId().equals(idVnf)) { return virtualNetworkFunctionRecord; } } throw new NotFoundException("VNFR with ID " + idVnf + " was not found in NSR with ID " + idNsr); }
@ApiOperation( value = "Upgrade a Virtual Network Function Record in a NSR", notes = "Specify the ids of the parent NSR and of the VNFR which will be upgraded") @RequestMapping( value = "{idNsr}/vnfrecords/{idVnfr}/upgrade", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public void upgradeVnfr( @PathVariable("idNsr") String idNsr, @PathVariable("idVnfr") String idVnfr, @RequestHeader(value = "project-id") String projectId, @RequestBody @Valid JsonObject body) throws NotFoundException, BadFormatException, BadRequestException, ExecutionException, InterruptedException, IOException, VimException, PluginException { NetworkServiceRecord nsr = networkServiceRecordManagement.query(idNsr, projectId); VirtualNetworkFunctionRecord vnfRecord = networkServiceRecordManagement.getVirtualNetworkFunctionRecord(idNsr, idVnfr, projectId); nsr.getVnfr().add(vnfRecord); String upgradeRequestEntityKey = "vnfdId"; if (!body.has(upgradeRequestEntityKey) || !body.getAsJsonPrimitive(upgradeRequestEntityKey).isString()) throw new BadRequestException( "The passed JSON is not correct. It should include a string field named: " + upgradeRequestEntityKey); // String vnfPackageId = body.getAsJsonPrimitive("vnfPackageId").getAsString(); String upgradeVnfdId = body.getAsJsonPrimitive(upgradeRequestEntityKey).getAsString(); log.info("Executing UPGRADE for VNFR: " + vnfRecord.getName()); networkServiceRecordManagement.upgradeVnfr(idNsr, idVnfr, projectId, upgradeVnfdId); }
protected boolean allVnfrInInactive(NetworkServiceRecord nsr) { for (VirtualNetworkFunctionRecord virtualNetworkFunctionRecord : nsr.getVnfr()) { if (virtualNetworkFunctionRecord.getStatus().ordinal() < Status.INACTIVE.ordinal()) { log.trace( "VNFR " + virtualNetworkFunctionRecord.getName() + " is in state: " + virtualNetworkFunctionRecord.getStatus()); return false; } } return true; }
@Override public VnfmOrLogMessage getLog(String nsrId, String vnfrName, String hostname) throws NotFoundException, InterruptedException, BadFormatException, ExecutionException { for (VirtualNetworkFunctionRecord virtualNetworkFunctionRecord : networkServiceRecordRepository.findFirstById(nsrId).getVnfr()) { if (virtualNetworkFunctionRecord.getName().equals(vnfrName)) { for (VirtualDeploymentUnit virtualDeploymentUnit : virtualNetworkFunctionRecord.getVdu()) { for (VNFCInstance vnfcInstance : virtualDeploymentUnit.getVnfc_instance()) { if (hostname.equals(vnfcInstance.getHostname())) { log.debug("Requesting log from VNFM"); Future<NFVMessage> futureMessage = vnfmManager.requestLog(virtualNetworkFunctionRecord, hostname); VnfmOrLogMessage vnfmOrLogMessage = (VnfmOrLogMessage) futureMessage.get(); return vnfmOrLogMessage; } } } } } throw new NotFoundException("Error something was not found"); } }
vnfrRepository.findFirstById( nsrFather .getVnfr() .stream() .filter(vnfr -> vnfr.getName().equals(vnfRecordDependency.getTarget()))
@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); }
public void deleteVNFRecord(String idNsr, String idVnf, String projectId) throws NotFoundException { // TODO the logic of this request for the moment deletes only the VNFR from the DB, need to be // removed from the // running NetworkServiceRecord VirtualNetworkFunctionRecord vnfr = vnfrRepository.findOne(idVnf); if (vnfr == null) { throw new NotFoundException("Not found VNFR with ID: " + idVnf); } if (!vnfr.getParent_ns_id().equals(idNsr)) { throw new NotFoundException("Not found VNFR " + idVnf + " in the given NSR " + idNsr); } if (!vnfr.getProjectId().equals(projectId)) { throw new UnauthorizedUserException("VNFR not contained in the chosen project."); } nsrRepository.deleteVNFRecord(idNsr, idVnf); NetworkServiceRecord nsr = query(idNsr, projectId); if (nsr != null) { for (VirtualNetworkFunctionRecord virtualNetworkFunctionRecord : nsr.getVnfr()) { if (nsr.getStatus().ordinal() > virtualNetworkFunctionRecord.getStatus().ordinal()) { nsr.setStatus(vnfr.getStatus()); } } nsrRepository.saveCascade(nsr); } else { log.warn("Parent NS does not exist anymore..."); } }