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 protected NFVMessage doWork() throws NsrNotFoundException { log.info("Updated script for VNFR: " + virtualNetworkFunctionRecord.getName()); setHistoryLifecycleEvent(); saveVirtualNetworkFunctionRecord(); 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; }
/** * Execute the update of a Virtual Network Function Record (VNFR) (The UPDATE is intended as the * execution of the scripts associated to the lifecycle UPDATE by the VNF provider) * * @param nsrId * @param vnfrId * @param projectId * @return * @throws NotFoundException */ @Override public VirtualNetworkFunctionRecord updateVnfr(String nsrId, String vnfrId, String projectId) throws NotFoundException, BadFormatException, ExecutionException, InterruptedException { VirtualNetworkFunctionRecord vnfr = vnfrRepository.findByIdAndParent_ns_idAndProjectId(vnfrId, nsrId, projectId); log.info("Updating VNFR: " + vnfr.getName()); vnfmManager.updateVnfr(nsrId, vnfrId, projectId); return vnfr; }
@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; }
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() + ")"); }
script.setPayload(scriptContent.getBytes()); log.info("Executing script: " + script + " on VNFR: " + vnfr.getName()); log.info("Script content:\n----------\n" + scriptContent + "\n----------\n"); networkServiceRecordManagement.executeScript(idNsr, idVnfr, projectId, script);
@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); }
@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; } }
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"); } }
@Override protected NFVMessage doWork() throws Exception { log.info("Release resources for VNFR: " + virtualNetworkFunctionRecord.getName()); for (VirtualDeploymentUnit virtualDeploymentUnit : virtualNetworkFunctionRecord.getVdu()) { log.debug( "Removing VDU: " + virtualDeploymentUnit.getHostname() + " from VNFR " + virtualNetworkFunctionRecord.getId()); for (VNFCInstance vnfcInstance : virtualDeploymentUnit.getVnfc_instance()) { log.debug( "Removing VNFC instance: " + vnfcInstance + " from VNFR " + virtualNetworkFunctionRecord.getId()); this.resourceManagement.release(virtualDeploymentUnit, vnfcInstance); } } setHistoryLifecycleEvent(); saveVirtualNetworkFunctionRecord(); return null; }
@Override public NFVMessage doWork() throws NsrNotFoundException { log.info("Stopped VNFR: " + virtualNetworkFunctionRecord.getName()); VirtualNetworkFunctionRecord existing = vnfrRepository.findFirstById(virtualNetworkFunctionRecord.getId()); log.trace("VNFR existing hibernate version = " + existing.getHbVersion()); log.trace("VNFR reiceived hibernate version = " + virtualNetworkFunctionRecord.getHbVersion()); for (VirtualDeploymentUnit virtualDeploymentUnit : virtualNetworkFunctionRecord.getVdu()) { for (VNFCInstance vnfcInstance : virtualDeploymentUnit.getVnfc_instance()) { log.trace("VNFCI received hibernate version = " + vnfcInstance.getHbVersion()); } } for (VirtualDeploymentUnit virtualDeploymentUnit : existing.getVdu()) { for (VNFCInstance vnfcInstance : virtualDeploymentUnit.getVnfc_instance()) { log.trace("VNFCI existing hibernate version = " + vnfcInstance.getHbVersion()); } } setHistoryLifecycleEvent(); saveVirtualNetworkFunctionRecord(); return null; }
private void sendStart(VirtualNetworkFunctionRecord virtualNetworkFunctionRecord) throws NotFoundException, BadFormatException, ExecutionException, InterruptedException { VnfmSender vnfmSender; log.info("Calling START to: " + virtualNetworkFunctionRecord.getName() + " after MODIFY"); vnfmSender = this.getVnfmSender( vnfmRegister.getVnfm(virtualNetworkFunctionRecord.getEndpoint()).getEndpointType()); vnfStateHandler.executeAction( vnfmSender.sendCommand( new OrVnfmStartStopMessage(virtualNetworkFunctionRecord, null, Action.START), vnfmRegister.getVnfm(virtualNetworkFunctionRecord.getEndpoint()))); }
@Override @Async public Future<NFVMessage> requestLog(VirtualNetworkFunctionRecord vnfr, String hostname) throws NotFoundException, BadFormatException, ExecutionException, InterruptedException { VnfmManagerEndpoint endpoint = generator.getVnfm(vnfr.getEndpoint()); if (endpoint == null) throw new NotFoundException( "VnfManager of type " + vnfr.getType() + " (endpoint = " + vnfr.getEndpoint() + ") is not registered"); OrVnfmLogMessage orVnfmLogMessage = new OrVnfmLogMessage(vnfr.getName(), hostname); VnfmSender vnfmSender; try { vnfmSender = generator.getVnfmSender(endpoint.getEndpointType()); } catch (BeansException e) { throw new NotFoundException(e); } Future<NFVMessage> answerFuture = vnfmSender.sendCommand(orVnfmLogMessage, endpoint); answerFuture.get(); NFVMessage message = answerFuture.get(); return new AsyncResult<>(message); }
@Override public VNFRecordDependency getDependencyForAVNFRecordTarget( VirtualNetworkFunctionRecord virtualNetworkFunctionRecord) { 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()); if (vnfRecordDependency.getTarget().equals(virtualNetworkFunctionRecord.getName())) { return vnfRecordDependency; } } } return null; }
private void sendStart(VirtualNetworkFunctionRecord virtualNetworkFunctionRecord) throws NotFoundException, BadFormatException, ExecutionException, InterruptedException { VnfmSender vnfmSender; vnfmSender = this.getVnfmSender( vnfmRegister.getVnfm(virtualNetworkFunctionRecord.getEndpoint()).getEndpointType()); log.info( "Calling START to: " + virtualNetworkFunctionRecord.getName() + " because it has 0 dependencies"); log.trace( "VNFR (" + virtualNetworkFunctionRecord.getId() + ") hibernate version is = " + virtualNetworkFunctionRecord.getHbVersion()); vnfStateHandler.executeAction( vnfmSender.sendCommand( new OrVnfmStartStopMessage(virtualNetworkFunctionRecord, null, Action.START), vnfmRegister.getVnfm(virtualNetworkFunctionRecord.getEndpoint()))); }
+ nfvMessage.getAction() + " to " + virtualNetworkFunctionRecordDest.getName()); executeAction(vnfmSender.sendCommand(nfvMessage, endpoint)); return new AsyncResult<>(null);
private static void setConfigurations( VirtualNetworkFunctionDescriptor vnfd, VirtualNetworkFunctionRecord virtualNetworkFunctionRecord) { Configuration configuration = new Configuration(); if (vnfd.getConfigurations() != null) { configuration.setName(vnfd.getConfigurations().getName()); } else configuration.setName(virtualNetworkFunctionRecord.getName()); configuration.setConfigurationParameters(new HashSet<ConfigurationParameter>()); if (vnfd.getConfigurations() != null) { for (ConfigurationParameter configurationParameter : vnfd.getConfigurations().getConfigurationParameters()) { ConfigurationParameter cp = new ConfigurationParameter(); cp.setConfKey(configurationParameter.getConfKey()); cp.setValue(configurationParameter.getValue()); configuration.getConfigurationParameters().add(cp); } } virtualNetworkFunctionRecord.setConfigurations(configuration); }