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() + ")"); }
if (networkServiceRecord.getStatus().ordinal() == Status.NULL.ordinal()) { throw new WrongStatusException( "The NetworkService " + networkServiceRecord.getId() + " is in the wrong state. ( Status= " + networkServiceRecord.getStatus() + " )"); if (networkServiceRecord.getStatus().ordinal() != Status.ACTIVE.ordinal() && networkServiceRecord.getStatus().ordinal() != Status.ERROR.ordinal()) { throw new WrongStatusException( "The NetworkService " + networkServiceRecord.getId() + " is in the wrong state. ( Status= " + networkServiceRecord.getStatus() + " )"); if (!networkServiceRecord.getVnfr().isEmpty()) { networkServiceRecord.setStatus(Status.TERMINATED); // TODO maybe terminating? for (VirtualNetworkFunctionRecord vnfr : networkServiceRecord.getVnfr()) { vnfmManager.release(vnfr); vnfrRepository.findByParentNsId(networkServiceRecord.getId())) { if (removeAfterTimeout) { VNFRTerminator terminator = new VNFRTerminator(); nsrRepository.delete(networkServiceRecord.getId());
@Override @Transactional public VNFRecordDependency addVnfRecordDependency( VNFRecordDependency vnfRecordDependencyd, String id) { SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z"); NetworkServiceRecord nsr = networkServiceRecordRepository.findFirstById(id); nsr.setUpdatedAt(format.format(new Date())); vnfRecordDependencyd = vnfRecordDependencyRepository.save(vnfRecordDependencyd); nsr.getVnf_dependency().add(vnfRecordDependencyd); return vnfRecordDependencyd; } }
@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); }
NetworkServiceRecord networkServiceRecord = new NetworkServiceRecord(); networkServiceRecord.setCreatedAt(getFormat().format(new Date())); networkServiceRecord.setUpdatedAt(getFormat().format(new Date())); networkServiceRecord.setTask("Onboarding"); networkServiceRecord.setKeyNames(new HashSet<>()); networkServiceRecord.setDescriptor_reference(networkServiceDescriptor.getId()); networkServiceRecord.setName(networkServiceDescriptor.getName()); networkServiceRecord.setVendor(networkServiceDescriptor.getVendor()); networkServiceRecord.setMonitoring_parameter(new HashSet<>()); networkServiceRecord .getMonitoring_parameter() .addAll(networkServiceDescriptor.getMonitoring_parameter()); networkServiceRecord.setAuto_scale_policy(new HashSet<>()); networkServiceRecord .getAuto_scale_policy() .addAll(networkServiceDescriptor.getAuto_scale_policy()); networkServiceRecord.setVnfr(new HashSet<>()); networkServiceRecord.setVnf_dependency(new HashSet<>()); networkServiceRecord.setLifecycle_event(new HashSet<>()); Set<PhysicalNetworkFunctionRecord> pnfrs = new HashSet<>(); if (networkServiceDescriptor.getPnfd() != null) networkServiceRecord.setPnfr(pnfrs); networkServiceRecord.setStatus(Status.NULL); networkServiceRecord.setVnffgr(new HashSet<>()); networkServiceRecord.setVersion(networkServiceDescriptor.getVersion()); networkServiceRecord.setVlr(new HashSet<>()); if (networkServiceDescriptor.getVld() != null) {
log.debug("looking for NSD with id: " + networkServiceRecord.getDescriptor_reference()); if (virtualNetworkFunctionRecord.getStatus().ordinal() != Status.TERMINATED.ordinal() && nsdRepository .findFirstById(networkServiceRecord.getDescriptor_reference()) .getVnfd() .size() > networkServiceRecord.getVnfr().size()) { log.debug( "Not all the VNFR have been created yet, it is useless to set the NSR status."); log.debug("Checking the status of NSR: " + networkServiceRecord.getName()); for (VirtualNetworkFunctionRecord vnfr : networkServiceRecord.getVnfr()) { log.debug("VNFR " + vnfr.getName() + " is in state: " + vnfr.getStatus()); if (status.ordinal() > vnfr.getStatus().ordinal()) { .getVnfr() .stream() .anyMatch(vnfr -> vnfr.getStatus().ordinal() == Status.TERMINATED.ordinal()) networkServiceRecord.setStatus(status); SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z"); networkServiceRecord.setUpdatedAt(format.format(new Date())); networkServiceRecord = nsrRepository.save(networkServiceRecord); foundAndSet = true; log.debug("Now the status is: " + networkServiceRecord.getStatus()); if (status.ordinal() == Status.ACTIVE.ordinal()) {
ExecutionException, CyclicDependenciesException, NetworkServiceIntegrityException { Map<String, Set<String>> vduVimInstances = new HashMap<>(); log.info("Scaling NetworkServiceRecord: " + networkServiceRecord.getName()); log.trace("Scaling NetworkServiceRecord: " + networkServiceRecord); log.info("VNFD to add is: " + vnfd.getName()); networkServiceRecord.getDescriptor_reference(), projectId); networkServiceRecord.setStatus(Status.SCALING); networkServiceRecord.setTask("Scaling out"); if (body != null && body.getKeys() != null && !body.getKeys().isEmpty()) { for (Key key : body.getKeys()) { networkServiceRecord.getKeyNames().add(key.getName()); log.debug( "Persisted NSR " + networkServiceRecord.getName() + ". Got id: " + networkServiceRecord.getId()); } catch (OptimisticLockingFailureException e) { if (attempt >= 3) { for (VNFRecordDependency vnfrd : networkServiceRecord.getVnf_dependency()) { if (vnfrd.getTarget().equals(vnfd.getName())) { for (String vnfrSourceName : vnfrd.getIdType().keySet()) { log.debug("Returning NSR " + networkServiceRecord.getName()); return networkServiceRecord;
String.format( formatBar, networkServiceRecord.getName(), networkServiceRecord.getStatus(), networkServiceRecord.getId(), networkServiceRecord.getProjectId())) .append("\n"); result
private NetworkServiceRecord createNetworkServiceRecord() { final NetworkServiceRecord nsr = new NetworkServiceRecord(); nsr.setVendor("FOKUS"); nsr.setProjectId(projectId); nsr.setStatus(Status.ACTIVE); nsr.setMonitoring_parameter(new HashSet<>()); nsr.getMonitoring_parameter().add("monitor1"); nsr.getMonitoring_parameter().add("monitor2"); nsr.getMonitoring_parameter().add("monitor3"); HashSet<VirtualNetworkFunctionRecord> virtualNetworkFunctionRecords = new HashSet<>(); VirtualNetworkFunctionRecord virtualNetworkFunctionRecord = new VirtualNetworkFunctionRecord(); nsr.setVnfr(virtualNetworkFunctionRecords); return nsr;
/** * 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(); }
if (nsr.getDescriptor_reference().equals(id)) { if (nsr.getStatus().ordinal() != Status.ACTIVE.ordinal()) { throw new WrongStatusException( "The NetworkServiceRecord " + nsr.getName() + " (" + nsr.getId() + ")" + " created from the NetworkServiceDescriptor " + ")" + " is not yet in ACTIVE state but in " + nsr.getStatus() + ".");
dependencyManagement.getDependencyForAVNFRecordSource(virtualNetworkFunctionRecord); networkServiceRecord.setTask("Scaling in"); networkServiceRecord.getVnfr()) { if (virtualNetworkFunctionRecord1.getName().equals(dependency.getTarget())) { vnfmManager.removeVnfcDependency(virtualNetworkFunctionRecord1, vnfcInstance); log.debug("Actual NSR stats is: " + networkServiceRecord.getStatus()); for (VirtualNetworkFunctionRecord vnfr : networkServiceRecord.getVnfr()) { boolean stopVNFR = true; for (VirtualDeploymentUnit vdu : vnfr.getVdu()) { && (networkServiceRecord.getStatus().ordinal() != Status.ERROR.ordinal())) { stopVNFR = false; break; for (VirtualNetworkFunctionRecord vnfr : networkServiceRecord.getVnfr()) { if (vnfr.getStatus().ordinal() == Status.INACTIVE.ordinal()) { networkServiceRecord.setStatus(Status.INACTIVE); break; publisher.dispatchEvent(eventNFVO); if (networkServiceRecord.getStatus().ordinal() == Status.SCALING.ordinal()) { networkServiceRecord.setStatus(Status.ACTIVE); networkServiceRecord.setTask("Scaled in");
+ " dependencies: " + sourceList); if (sourceList.contains(vnfrSourceName + nsrFather.getId())) { sourceList.remove(vnfrSourceName + nsrFather.getId()); if (sourceList.isEmpty()) { vnfrRepository.findFirstById( nsrFather .getVnfr() .stream() .filter(vnfr -> vnfr.getName().equals(vnfRecordDependency.getTarget())) if (nsrFather.getStatus().ordinal() != Status.ERROR.ordinal()) { log.debug("Sending MODIFY to " + target.getName()); OrVnfmGenericMessage orVnfmGenericMessage =
private void assertEqualsNSR(NetworkServiceRecord nsr_exp) throws NoResultException, NotFoundException { when(nsrRepository.findFirstByIdAndProjectId(nsr_exp.getId(), projectId)).thenReturn(nsr_exp); NetworkServiceRecord networkServiceRecord = nsrManagement.query(nsr_exp.getId(), projectId); Assert.assertEquals(nsr_exp.getId(), networkServiceRecord.getId()); Assert.assertEquals(nsr_exp.getName(), networkServiceRecord.getName()); Assert.assertEquals(nsr_exp.getVendor(), networkServiceRecord.getVendor()); Assert.assertEquals(nsr_exp.getVersion(), networkServiceRecord.getVersion()); }
if (body != null && body.getKeys() != null && !body.getKeys().isEmpty()) { for (Key key : body.getKeys()) { networkServiceRecord.getKeyNames().add(key.getName()); networkServiceRecord.setProjectId(projectID); try { networkServiceRecord = nsrRepository.saveCascade(networkServiceRecord); log.debug( "Persisted NSR " + networkServiceRecord.getName() + ". Got id: " + networkServiceRecord.getId()); } catch (OptimisticLockingFailureException e) { if (attempt >= 3) { vnfmManager.deploy( networkServiceDescriptor, networkServiceRecord, body, vduVimInstances, monitoringIp); log.debug("Returning NSR " + networkServiceRecord.getName()); return networkServiceRecord;
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..."); } }
networkServiceRecord.setStatus(Status.RESUMING); for (VirtualNetworkFunctionRecord failedVnfr : networkServiceRecord.getVnfr()) { log.debug("Setting VNFR Dependency for RESUMED VNFR"); for (VNFRecordDependency vnfRecordDependency : networkServiceRecord.getVnf_dependency()) { if (vnfRecordDependency.getTarget().equals(failedVnfr.getName())) { log.debug( for (VNFRecordDependency vnfrDependency : networkServiceRecord.getVnf_dependency()) {
@Override public List<VNFRecordDependency> getDependencyForAVNFRecordSource( VirtualNetworkFunctionRecord virtualNetworkFunctionRecord) { List<VNFRecordDependency> res = new ArrayList<>(); NetworkServiceRecord nsr = nsrRepository.findFirstById(virtualNetworkFunctionRecord.getParent_ns_id()); if (nsr.getStatus().ordinal() != Status.ERROR.ordinal()) { Set<VNFRecordDependency> vnfRecordDependencies = nsr.getVnf_dependency(); for (VNFRecordDependency vnfRecordDependency : vnfRecordDependencies) { vnfRecordDependency = vnfrDependencyRepository.findOne(vnfRecordDependency.getId()); log.trace( "Checking if " + virtualNetworkFunctionRecord.getName() + " is source for " + vnfRecordDependency); if (vnfRecordDependency.getIdType().containsKey(virtualNetworkFunctionRecord.getName())) { res.add(vnfRecordDependency); } } } return res; } }
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; }
@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); }