/** List all Services. */ @ApiOperation(value = "List Services", notes = "List all services") @RequestMapping( value = "/services", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.OK) @PreAuthorize("hasAnyRole('ROLE_ADMIN')") public List<ServiceMetadata> listServices(@RequestHeader(value = "project-id") String projectId) { return (List<ServiceMetadata>) componentManager.listServices(); } }
/** * Registers a Service. For this to work, the Service has to be already created. The request body * is expected to be a String. This String has to be the word 'register' encrypted with the Key * obtained while creating the Service. This method returns a token encapsulated in a Json object * which can be used by the Service to issue requests to the NFVO API. * * @param serviceRegisterBody * @return * @throws IOException * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ @ApiOperation(value = "Register Service", notes = "Register an already created Service.") @RequestMapping( value = "/services/register", method = RequestMethod.POST, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public JsonObject registerService(@RequestBody String serviceRegisterBody) throws NoSuchAlgorithmException, NotFoundException, InvalidKeyException, BadPaddingException, NoSuchPaddingException, IllegalBlockSizeException { JsonObject response = new JsonObject(); response.add("token", new JsonPrimitive(componentManager.registerService(serviceRegisterBody))); return response; }
/** Delete multiple Services. */ @ApiOperation( value = "Delete multiple Services", notes = "In the Request Body pass a list of service ids that have to be deleted") @RequestMapping( value = "/services/multipledelete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.NO_CONTENT) @PreAuthorize("hasAnyRole('ROLE_ADMIN')") public void multipleDelete(@RequestBody @Valid List<String> ids) { if (componentManager != null) { for (String id : ids) { log.info("Removing Service with id: " + id); componentManager.removeService(id); } } }
/** * 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; }
@Override public void onApplicationEvent(ContextClosedEvent event) { log.info("Shutting down..."); PluginStartup.destroy(); componentManager.removeTokens(); } }
/** * Create a new Service. This generates a new AES Key that can be used for registering the * Service. * * @param projectId * @param serviceCreateBody * @return * @throws IOException * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ @ApiOperation( value = "Create Service", notes = "Enable a new Service. This generates a new AES Key that must be used in the Service SDK") @RequestMapping( value = "/services/create", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) @ResponseStatus(HttpStatus.CREATED) @PreAuthorize("hasAnyRole('ROLE_ADMIN')") public String createService( @RequestHeader(value = "project-id") String projectId, @RequestBody @Valid ServiceCreateBody serviceCreateBody) throws NotFoundException, MissingParameterException { String serviceName = serviceCreateBody.getName(); List<String> projects = serviceCreateBody.getRoles(); return componentManager.createService(serviceName, projectId, projects); }
/** * 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; }
if (endpoint.getProjectId() == null || endpoint.getProjectId().equals("")) endpoint.setProjectId(projectId); if ((!componentManager.isService(token) && !utils.isAdmin()) && endpoint.getProjectId().equals("*")) throw new BadRequestException("Only services and admin can register to all events"); if (!utils.isAdmin() && !componentManager.isService(token) && utils .getCurrentUser()
/** Delete a new Service. */ @ApiOperation(value = "Delete Service", notes = "Remove a specific service") @RequestMapping( value = "/services/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.OK) @PreAuthorize("hasAnyRole('ROLE_ADMIN')") public void deleteService( @RequestHeader(value = "project-id") String projectId, @PathVariable("id") String id) { log.debug("id is " + id); componentManager.removeService(id); }