Script script = new Script(); script.setName(scriptName); script.setPayload(scriptContent.getBytes());
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; }
vnfScripts = new HashSet<>(); for (Script script : scripts) { String[] splitted_name = script.getName().split("!_!"); Script s = new Script(); s.setName(splitted_name[1]); s.setPayload(script.getPayload()); vnfScripts.add(s);
@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); }
@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); }
Script script = new Script(); String[] splittedName = fileName.split("/"); if (splittedName.length > 2) { String scriptName = splittedName[1] + "!_!" + splittedName[splittedName.length - 1]; folderNames.add(splittedName[1]); script.setName(scriptName); } else script.setName(splittedName[splittedName.length - 1]); script.setPayload(baos.toByteArray()); this.scripts.add(script);
Script script = new Script(); script.setName(entry.getName().substring(8)); script.setPayload(content); if (vnfPackage.getScripts() == null) vnfPackage.setScripts(new HashSet<>()); vnfPackage.getScripts().add(script);