private void createIfNeeded(Path path) { File dir = application.getFileReference(path); if ( ! dir.exists()) { if (!dir.mkdirs()) throw new IllegalStateException("Could not create " + dir); } }
/** * Returns the directory which contains the source model to use for these arguments */ public static File sourceModelFile(ApplicationPackage application, Path sourceModelPath) { return application.getFileReference(ApplicationPackage.MODELS_DIR.append(sourceModelPath)); }
/** Workaround for being constructed with the .preprocessed dir as root while later being used outside it */ private Path correct(Path path) { if (application.getFileReference(Path.fromString("")).getAbsolutePath().endsWith(FilesApplicationPackage.preprocessed) && ! path.elements().contains(FilesApplicationPackage.preprocessed)) { return Path.fromString(FilesApplicationPackage.preprocessed).append(path); } else { return path; } }
private void validateRankingConstant(RankingConstant rankingConstant, ApplicationPackage application) throws FileNotFoundException { // TODO: Handle validation of URI soon too. if (rankingConstant.getPathType() == RankingConstant.PathType.FILE) { String constantFile = rankingConstant.getFileName(); if (application.getFileReference(Path.fromString("")).getAbsolutePath().endsWith(FilesApplicationPackage.preprocessed) && constantFile.startsWith(FilesApplicationPackage.preprocessed)) { constantFile = constantFile.substring(FilesApplicationPackage.preprocessed.length()); } ApplicationFile tensorApplicationFile = application.getFile(Path.fromString(constantFile)); new ConstantTensorJsonValidator().validate(constantFile, rankingConstant.getTensorType(), tensorApplicationFile.createReader()); } }
@Override public void validate(VespaModel model, DeployState deployState) { ApplicationPackage app = deployState.getApplicationPackage(); for (ComponentInfo info : app.getComponentsInfo(deployState.getVespaVersion())) { try { this.jarFile = new JarFile(app.getFileReference(Path.fromString(info.getPathRelativeToAppDir()))); } catch (ZipException e) { throw new IllegalArgumentException("Error opening jar file '" + info.getPathRelativeToAppDir() + "'. Please check that this is a valid jar file"); } catch (IOException e) { e.printStackTrace(); } try { validateAll(deployState.getDeployLogger()); } catch (IOException e) { e.printStackTrace(); } } }
this.queryProfiles = queryProfiles; // TODO: Remove this by seeing how pagetemplates are propagated this.semanticRules = semanticRules; // TODO: Remove this by seeing how pagetemplates are propagated this.importedModels = new ImportedMlModels(applicationPackage.getFileReference(ApplicationPackage.MODELS_DIR), modelImporters);
/** * Adds this constant to the application package as a file, * such that it can be distributed using file distribution. * * @return the path to the stored constant, relative to the application package root */ Path writeLargeConstant(String name, Tensor constant) { Path constantsPath = modelFiles.largeConstantsContentPath(); // "tbf" ending for "typed binary format" - recognized by the nodes receiving the file: Path constantPath = constantsPath.append(name + ".tbf"); // Remember the constant in a file we replicate in ZooKeeper application.getFile(modelFiles.largeConstantsInfoPath().append(name + ".constant")) .writeFile(new StringReader(name + ":" + constant.type() + ":" + correct(constantPath))); // Write content explicitly as a file on the file system as this is distributed using file distribution // - but only if this is a global model to avoid writing the same constants for each rank profile // where they are used if (modelFiles.modelName.isGlobal()) { createIfNeeded(constantsPath); IOUtils.writeFile(application.getFileReference(constantPath), TypedBinaryFormat.encode(constant)); } return correct(constantPath); }