@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 @Transactional public NetworkServiceRecord saveCascade(NetworkServiceRecord networkServiceRecord) { vnfrRepository.save(networkServiceRecord.getVnfr()); return networkServiceRecordRepository.save(networkServiceRecord); }
@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)); }
protected void saveVirtualNetworkFunctionRecord() throws NsrNotFoundException { if (networkServiceRecordRepository.exists(virtualNetworkFunctionRecord.getParent_ns_id())) { try { lock.lock(); log.trace( "ACTION is: " + action + " and the VNFR id is: " + virtualNetworkFunctionRecord.getId()); SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z"); if (virtualNetworkFunctionRecord.getId() == null || virtualNetworkFunctionRecord.getId().isEmpty()) { virtualNetworkFunctionRecord.setCreatedAt(format.format(new Date())); virtualNetworkFunctionRecord.setUpdatedAt(format.format(new Date())); virtualNetworkFunctionRecord = networkServiceRecordRepository.addVnfr( virtualNetworkFunctionRecord, virtualNetworkFunctionRecord.getParent_ns_id()); } else { virtualNetworkFunctionRecord.setUpdatedAt(format.format(new Date())); virtualNetworkFunctionRecord = vnfrRepository.save(virtualNetworkFunctionRecord); } } finally { lock.unlock(); } } }
log.debug("The nsr id is: " + virtualNetworkFunctionRecord.getParent_ns_id()); networkServiceRecord = nsrRepository.findFirstById(virtualNetworkFunctionRecord.getParent_ns_id()); log.trace("Found NSR: " + networkServiceRecord); } catch (Exception ignored) { SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z"); networkServiceRecord.setUpdatedAt(format.format(new Date())); networkServiceRecord = nsrRepository.save(networkServiceRecord); foundAndSet = true; } catch (OptimisticLockingFailureException ignored) { networkServiceRecord = nsrRepository.findFirstById(networkServiceRecord.getId()); networkServiceRecord.setTask("Scaled in"); networkServiceRecord.setUpdatedAt(format.format(new Date())); networkServiceRecord = nsrRepository.save(networkServiceRecord); publishEvent( Action.SCALE_IN, networkServiceRecord, networkServiceRecord.getProjectId()); networkServiceRecord.setTask("Scaled out"); networkServiceRecord.setUpdatedAt(format.format(new Date())); networkServiceRecord = nsrRepository.save(networkServiceRecord); publishEvent( Action.SCALE_OUT, networkServiceRecord, networkServiceRecord.getProjectId()); networkServiceRecord.setTask("Healed"); networkServiceRecord.setUpdatedAt(format.format(new Date())); networkServiceRecord = nsrRepository.save(networkServiceRecord);
if (nsrRepository.exists(virtualNetworkFunctionRecord.getParent_ns_id())) { NetworkServiceRecord nsr = nsrRepository.findFirstById(virtualNetworkFunctionRecord.getParent_ns_id()); synchronized (NetworkServiceRecordManagement.class) { try { nsr.setVnfr(new HashSet<>()); nsrRepository.delete(nsr); ApplicationEventNFVO event = new ApplicationEventNFVO(
AlreadyExistingException { final NetworkServiceDescriptor nsd_exp = createNetworkServiceDescriptor(); when(nsrRepository.save(any(NetworkServiceRecord.class))) .thenAnswer( (Answer<NetworkServiceRecord>) }); when(nsrRepository.saveCascade(any(NetworkServiceRecord.class))) .thenAnswer( (Answer<NetworkServiceRecord>)
+ " VNFM Logs"); NetworkServiceRecord networkServiceRecord = networkServiceRecordRepository.findFirstById(nsrId); networkServiceRecord.setStatus(Status.ERROR); log.debug("Setting the NSR " + networkServiceRecord.getName() + " in state ERROR"); networkServiceRecordRepository.save(networkServiceRecord);
private synchronized NetworkServiceRecord getNetworkServiceRecordInAnyState( String id, String projectId) throws NotFoundException { NetworkServiceRecord networkServiceRecord = nsrRepository.findFirstByIdAndProjectId(id, projectId); if (networkServiceRecord == null) { throw new NotFoundException("No NetworkServiceRecord found with ID " + id); } return networkServiceRecord; }
@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); }
log.info("Looking for NetworkServiceRecord with id: " + nsrId); if (!nsrRepository.existsByIdAndProjectIdAndStatus(nsrId, projectId, Status.ACTIVE)) throw new BadRequestException("NSR is not in ACTIVE status"); NetworkServiceRecord nsr = nsrRepository.findFirstByIdAndProjectId(nsrId, projectId); networkServiceRecord = nsrRepository.saveCascade(networkServiceRecord); scaleOUT( networkServiceRecord,
@Override public Iterable<NetworkServiceRecord> query() { return nsrRepository.findAll(); }
/** * Removes a VNFDependency from an NSR. * * @param idNsr ID of the NSR * @param idVnfd ID of the VNFDependency * @param projectId the current projectId */ @Override public void deleteVNFDependency(String idNsr, String idVnfd, String projectId) throws NotFoundException { NetworkServiceRecord nsr = query(idNsr, projectId); VNFRecordDependency vnfDependency = null; for (VNFRecordDependency vnfdep : nsr.getVnf_dependency()) { if (vnfdep.getId().equals(idVnfd)) { vnfDependency = vnfdep; } } if (vnfDependency == null) { throw new NotFoundException( "No VNFDependency with ID " + idVnfd + " found in NSR with ID " + idNsr); } nsr.getVnf_dependency().remove(vnfDependency); nsrRepository.saveCascade(nsr); }
log.info("Removing NSR with id: " + id); NetworkServiceRecord networkServiceRecord = nsrRepository.findFirstByIdAndProjectId(id, projectId); if (networkServiceRecord == null) { throw new NotFoundException("NetworkServiceRecord with ID " + id + " was not found"); nsrRepository.delete(networkServiceRecord.getId());
@Test public void nsrManagementQueryTest() throws NotFoundException { when(nsrRepository.findAll()).thenReturn(new ArrayList<NetworkServiceRecord>()); Iterable<NetworkServiceRecord> nsds = nsrManagement.query(); Assert.assertEquals(nsds.iterator().hasNext(), false); final NetworkServiceRecord nsd_exp = createNetworkServiceRecord(); when(nsrRepository.findAll()) .thenReturn( new ArrayList<NetworkServiceRecord>() { { add(nsd_exp); } }); nsds = nsrManagement.query(); Assert.assertEquals(nsds.iterator().hasNext(), true); when(nsrRepository.findOne(nsd_exp.getId())).thenReturn(nsd_exp); assertEqualsNSR(nsd_exp); }
@Test public void nsrManagementUpdateTest() throws NotFoundException { final NetworkServiceRecord nsd_exp = createNetworkServiceRecord(); when(nsrRepository.findOne(nsd_exp.getId())).thenReturn(nsd_exp); when(nsrRepository.findFirstByIdAndProjectId(nsd_exp.getId(), projectId)).thenReturn(nsd_exp); NetworkServiceRecord new_nsr = createNetworkServiceRecord(); new_nsr.setName("UpdatedName"); nsrManagement.update(new_nsr, nsd_exp.getId(), projectId); new_nsr.setId(nsd_exp.getId()); assertEqualsNSR(new_nsr); }
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..."); } }
@Override public List<NetworkServiceRecord> queryByProjectId(String projectId) { return nsrRepository.findByProjectId(projectId); }
when(nsrRepository.save(any(NetworkServiceRecord.class))) .thenAnswer( (Answer<NetworkServiceRecord>) return (NetworkServiceRecord) args[0]; }); when(nsrRepository.saveCascade(any(NetworkServiceRecord.class))) .thenAnswer( (Answer<NetworkServiceRecord>)
@Override public NetworkServiceRecord query(String id, String projectId) throws NotFoundException { log.trace("Id is: " + id); NetworkServiceRecord networkServiceRecord = nsrRepository.findFirstByIdAndProjectId(id, projectId); if (networkServiceRecord == null) { throw new NotFoundException("NetworkServiceRecord with ID " + id + " not found"); } return networkServiceRecord; }