/** * Returns the refreshed Datacenter selected by id * * @param id: The Datacenter's id selected * @return Datacenter: The Datacenter selected */ @ApiOperation( value = "Refreshes the data about the Vim Instance", notes = "Refreshes the data about the Vim Instance and returns it") @RequestMapping(value = "{id}/refresh", method = RequestMethod.GET) public BaseVimInstance refresh( @PathVariable("id") String id, @RequestHeader(value = "project-id") String projectId) throws VimException, PluginException, IOException, NotFoundException, ExecutionException, InterruptedException { BaseVimInstance vimInstance = vimManagement.query(id, projectId); if (vimInstance == null) throw new NotFoundException("VIM Instance with ID " + id + " not found."); vimManagement.refresh(vimInstance, true).get(); return vimInstance; } }
/** * Adds a new VNF software Image to the datacenter repository * * @param vimInstance : Image to add * @return datacenter: The datacenter filled with values from the core */ @ApiOperation( value = "Adding a Vim Instance", notes = "Takes a Vim Instance json in the request body") @RequestMapping( method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public BaseVimInstance create( @RequestBody @Valid BaseVimInstance vimInstance, @RequestHeader(value = "project-id") String projectId) throws VimException, PluginException, IOException, BadRequestException, ExecutionException, InterruptedException { return vimManagement.add(vimInstance, projectId).get(); }
/** * Removes the Datacenter from the Datacenter repository * * @param id: The Datacenter's id to be deleted */ @ApiOperation( value = " Removing a Vim Instance", notes = "Deletes the Vim Instance belonging to the id specified in the URL") @RequestMapping(value = "{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) public void delete( @PathVariable("id") String id, @RequestHeader(value = "project-id") String projectId) throws NotFoundException, BadRequestException { vimManagement.delete(id, projectId); }
Set<BaseNfvImage> images = vimManagement.queryImagesDirectly(vimInstance); vimManagement.refresh(vimInstance, false).get(); return; vimManagement.refresh(vimInstance, false).get(); throw new VimException("Not all images are active even after timeout!");
public void run() { if (username.contains(".")) { String[] pluginId = username.split(Pattern.quote(".")); if (pluginId.length == 3 && pluginId[0].equals("vim-drivers")) { String vimType = pluginId[1]; log.debug(String.format("Refreshing vims of type %s", vimType)); vimRepository .findByType(vimType) .stream() .parallel() .forEach( vim -> { try { vimManagement.refresh(vim, false).get(); } catch (VimException | PluginException | IOException | InterruptedException | ExecutionException e) { e.printStackTrace(); log.warn( String.format( "Error while refreshing vim %s of type %s after plugin registration", vim.getName(), vim.getType())); } }); } } } };
/** * Returns the list of NFVImage into a VimInstance with id * * @param id of the VimInstance * @return Set<NFVImage> */ @ApiOperation( value = "Retrieve the data about images on a Vim Instance", notes = "Retrieve the data for all images on the Vim Instance which id is specified in the URL") @RequestMapping(value = "{id}/images", method = RequestMethod.GET) public Set<? extends BaseNfvImage> getAllImages( @PathVariable("id") String id, @RequestHeader(value = "project-id") String projectId) throws NotFoundException { BaseVimInstance vimInstance = vimManagement.query(id, projectId); if (vimInstance == null) throw new NotFoundException("VIM Instance with ID " + id + " not found."); return vimInstance.getImages(); }
@Test public void findAllVimInstances() throws NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, NoSuchPaddingException, IllegalBlockSizeException, BadFormatException { when(mock.queryByProjectId("pi")).thenReturn(new ArrayList<>()); assertEquals(mock.queryByProjectId("pi"), restVimInstances.findAll("pi", "Bearer token")); }
/** * This operation updates the Network Service Descriptor (NSD) * * @param new_vimInstance the new datacenter to be updated to * @param id the id of the old datacenter * @return VimInstance the VimInstance updated */ @ApiOperation( value = "Updating a Vim Instance", notes = "Takes a Vim Instance as JSON and updates the Vim Instance with the id specified in the URL") @RequestMapping( value = "{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public BaseVimInstance update( @RequestBody @Valid BaseVimInstance new_vimInstance, @PathVariable("id") String id, @RequestHeader(value = "project-id") String projectId) throws VimException, PluginException, IOException, BadRequestException, NotFoundException, ExecutionException, InterruptedException { return vimManagement.update(new_vimInstance, id, projectId).get(); }
/** * Adds a new {@code NFVImage} to the {@code VimInstance} with the id * * @param id of {@code VimInstance} * @param nfvImage the {@code NFVImage} to be added * @return {@code NFVImage} persisted * @throws VimException */ @ApiOperation( value = "Adds an image to the Vim Instance", notes = "Adds an image to the Vim Instance with id specified in the URL") @RequestMapping(value = "{id}/images", method = RequestMethod.POST) public BaseNfvImage addImage( @PathVariable("id") String id, BaseNfvImage nfvImage, @RequestHeader(value = "project-id") String projectId) throws VimException, PluginException, EntityUnreachableException, IOException, NotFoundException { return vimManagement.addImage(id, nfvImage, projectId); }
/** * Removes the {@code NFVImage} with idImage from {@code VimInstance} with idVim * * @param idVim of {@code VimInstance} * @param idImage of {@code NFVImage} * @throws VimException */ @ApiOperation( value = "Remove an image on the Vim Instance", notes = "Remove the specified by id image from the vim instance") @RequestMapping(value = "{idVim}/images/{idImage}", method = RequestMethod.DELETE) public void deleteImage( @PathVariable("idVim") String idVim, @PathVariable("idImage") String idImage, @RequestHeader(value = "project-id") String projectId) throws VimException, PluginException, EntityUnreachableException, IOException, NotFoundException { vimManagement.deleteImage(idVim, idImage, projectId); }
log.info( String.format("Deleting Network: %s [%s]", vlr.getName(), vlr.getExtId())); vimManagement.deleteNetwork(vlr); } catch (PluginException | VimException e) { e.printStackTrace();
vimInstance = vimManagement.refresh(vimInstance, true).get(); imageChecker.checkImageStatus(vimInstance);
/** * Returns the Datacenter selected by id * * @param id: The Datacenter's id selected * @return Datacenter: The Datacenter selected */ @ApiOperation( value = "Retrieve a Vim Instance", notes = "Returns the Vim Instance JSON belonging to the id specified in the URL") @RequestMapping(value = "{id}", method = RequestMethod.GET) public BaseVimInstance findById( @PathVariable("id") String id, @RequestHeader(value = "project-id") String projectId, @RequestHeader(value = "authorization") String token) throws NotFoundException, BadFormatException { BaseVimInstance vim = vimManagement.query(id, projectId); if (vim == null) throw new NotFoundException("VIM Instance with ID " + id + " not found."); String[] tokenArray = token.split(" "); if (tokenArray.length < 2) throw new BadFormatException("The passed token has a wrong format."); token = tokenArray[1]; if (!componentManager.isService(token)) { handlePrivateInfo(vim); } return vim; }
/** * Returns the list of the Datacenters available * * @return List<Datacenter>: The List of Datacenters available */ @ApiOperation( value = "Retrieving all Vim Instances", notes = "This method returns the list of all the VimInstances on-boarded in this project identified by the header project-id") @RequestMapping(method = RequestMethod.GET) public List<BaseVimInstance> findAll( @RequestHeader(value = "project-id") String projectId, @RequestHeader(value = "authorization") String token) throws BadFormatException { String[] tokenArray = token.split(" "); if (tokenArray.length < 2) throw new BadFormatException("The passed token has a wrong format."); token = tokenArray[1]; Iterable<BaseVimInstance> vimInstances = vimManagement.queryByProjectId(projectId); if (!componentManager.isService(token)) for (BaseVimInstance vim : vimInstances) { handlePrivateInfo(vim); } return (List<BaseVimInstance>) vimInstances; }
@Test public void updateVimInstance() throws VimException, PluginException, IOException, BadRequestException, AlreadyExistingException, NotFoundException, ExecutionException, InterruptedException { OpenstackVimInstance datacenter = new OpenstackVimInstance(); datacenter.setId("123"); datacenter.setName("DC-1"); datacenter.setType("OpenStack"); datacenter.setName("datacenter_test"); when(mock.update(any(datacenter.getClass()), anyString(), anyString())) .thenReturn(new AsyncResult<>(datacenter)); assertEquals(datacenter, restVimInstances.update(datacenter, datacenter.getId(), "pi")); }
/** * Updates the {@code NFVImage} with idImage into {@code VimInstance} with idVim * * @param idVim of {@code VimInstance} * @param image of {@code NFVImage} * @return {@code NFVImage} updated * @throws VimException */ @ApiOperation( value = "Updates the data of an image on the Vim Instance", notes = "Updates an image to the Vim Instance with id specified in the URL") @RequestMapping(value = "{idVim}/images/{idImage}", method = RequestMethod.PUT) public BaseNfvImage updateImage( @PathVariable("idVim") String idVim, @RequestBody @Valid BaseNfvImage image, @RequestHeader(value = "project-id") String projectId) throws VimException, PluginException, EntityUnreachableException, IOException, NotFoundException { return vimManagement.addImage(idVim, image, projectId); }
vimInstance = vimManagement.query(vimInstance.getId(), vimInstance.getProjectId()); vimInstance = vimManagement.refresh(vimInstance, true).get(); vimManagement.refresh(vimInstance, false).get(); for (VNFComponent vnfc : virtualDeploymentUnit.getVnfc()) { for (VNFDConnectionPoint vnfdConnectionPoint : vnfc.getConnection_point()) {
log.info("Created new Flavor -> " + flavor); try { vimManagement.refresh(vimInstance, true).get(); } catch (Exception e) { throw new VimException(e.getMessage(), e);
@Test public void findByIdVimInstance() throws NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, NoSuchPaddingException, IllegalBlockSizeException, NotFoundException, BadFormatException { OpenstackVimInstance datacenter = new OpenstackVimInstance(); datacenter.setId("123"); datacenter.setName("DC-1"); datacenter.setType("OpenStack"); datacenter.setName("datacenter_test"); when(mock.query(anyString(), anyString())).thenReturn(datacenter); assertEquals(datacenter, restVimInstances.findById(datacenter.getId(), "pi", "Bearer token")); }
/** * Removes multiple VIM Instances * * @param ids: the list of VIM Instance IDs * @throws NotFoundException if one of the VIM Instances was not found * @throws BadRequestException if something is wrong with the request */ @RequestMapping( value = "/multipledelete", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ApiOperation( value = "Removing multiple VIM Instances", notes = "Delete Request takes a list of VIM Instance IDs") @ResponseStatus(HttpStatus.NO_CONTENT) public void multipleDelete( @RequestBody @Valid List<String> ids, @RequestHeader(value = "project-id") String projectId) throws NotFoundException, BadRequestException { for (String id : ids) vimManagement.delete(id, projectId); }