private String getUserDataFromPackage(Set<Script> scripts) throws UnsupportedEncodingException { String userdata = null; for (Script script : scripts) { if (script.getName().equals("userdata.sh") || script.getName().equals("user-data.sh")) { ByteArrayInputStream bis = new ByteArrayInputStream(script.getPayload()); Scanner s = new Scanner(bis).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; } } return userdata; }
@ApiOperation( value = "Retrieve a script from a VNF Package", notes = "The ids of the package and the script are provided in the URL") @RequestMapping( value = "{id}/scripts/{scriptId}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) public String getScript( @PathVariable("id") String id, @PathVariable("scriptId") String scriptId, @RequestHeader(value = "project-id") String projectId) throws NotFoundException { VNFPackage vnfPackage = vnfPackageManagement.query(id, projectId); if (vnfPackage == null) throw new NotFoundException("No VNFPackage found with ID " + id); for (Script script : vnfPackage.getScripts()) { if (script.getId().equals(scriptId)) { return new String(script.getPayload()); } } throw new NotFoundException( "Script with id " + scriptId + " was not found into package with id " + id); }
@ApiOperation( value = "Update a script of a VNF Package", notes = "The updated script has to be passed in the Request Body") @RequestMapping( value = "{id}/scripts/{scriptId}", method = RequestMethod.PUT, produces = MediaType.TEXT_PLAIN_VALUE, consumes = MediaType.TEXT_PLAIN_VALUE) public String updateScript( @PathVariable("id") String vnfPackageId, @PathVariable("scriptId") String scriptId, @RequestBody String scriptNew, @RequestHeader(value = "project-id") String projectId) throws NotFoundException, BadFormatException, ExecutionException, InterruptedException { VNFPackage vnfPackage = vnfPackageManagement.query(vnfPackageId, projectId); if (vnfPackage == null) throw new NotFoundException("No VNFPackage found with ID " + vnfPackageId); for (Script script : vnfPackage.getScripts()) { if (script.getId().equals(scriptId)) { script.setPayload(scriptNew.getBytes()); script = vnfPackageManagement.updateScript(script, vnfPackageId); return new String(script.getPayload()); } } throw new NotFoundException( "Script with id " + scriptId + " was not found into package with id " + vnfPackageId); }
Script s = new Script(); s.setName(splitted_name[1]); s.setPayload(script.getPayload()); vnfScripts.add(s);