/** Returns whether a model store for this application and model name exists */ public boolean exists() { return application.getFile(modelFiles.storedModelReplicatedPath()).exists(); }
/** Reads the previously stored function expressions for these arguments */ List<Pair<String, RankingExpression>> readFunctions() { try { ApplicationFile file = application.getFile(modelFiles.functionsPath()); if ( ! file.exists()) return Collections.emptyList(); List<Pair<String, RankingExpression>> functions = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(file.createReader())) { String line; while (null != (line = reader.readLine())) { String[] parts = line.split("\t"); String name = parts[0]; try { RankingExpression expression = new RankingExpression(parts[0], parts[1]); functions.add(new Pair<>(name, expression)); } catch (ParseException e) { throw new IllegalStateException("Could not parse " + name, e); } } return functions; } } catch (IOException e) { throw new UncheckedIOException(e); } }
private Collection<Element> getPermanentServices(DeployState deployState) throws IOException, SAXException { List<Element> permanentServices = new ArrayList<>(); Optional<ApplicationPackage> applicationPackage = deployState.getPermanentApplicationPackage(); if (applicationPackage.isPresent()) { ApplicationFile file = applicationPackage.get().getFile(Path.fromString(ApplicationPackage.PERMANENT_SERVICES)); if (file.exists()) { try (Reader reader = file.createReader()) { Element permanentServicesRoot = getServicesFromReader(reader); permanentServices.addAll(getServiceElements(permanentServicesRoot)); } } } return permanentServices; }
private List<Pair<String, Tensor>> readSmallConstants() { try { ApplicationFile file = application.getFile(modelFiles.smallConstantsPath()); if ( ! file.exists()) return Collections.emptyList(); List<Pair<String, Tensor>> constants = new ArrayList<>(); BufferedReader reader = new BufferedReader(file.createReader()); String line; while (null != (line = reader.readLine())) { String[] parts = line.split("\t"); String name = parts[0]; TensorType type = TensorType.fromSpec(parts[1]); Tensor tensor = Tensor.from(type, parts[2]); constants.add(new Pair<>(name, tensor)); } return constants; } catch (IOException e) { throw new UncheckedIOException(e); } }
Map<String, ExpressionFunction> readExpressions() { Map<String, ExpressionFunction> expressions = new HashMap<>(); ApplicationFile expressionPath = application.getFile(modelFiles.expressionsPath()); if ( ! expressionPath.exists() || ! expressionPath.isDirectory()) return Collections.emptyMap(); for (ApplicationFile expressionFile : expressionPath.listFiles()) { try (BufferedReader reader = new BufferedReader(expressionFile.createReader())){ String name = expressionFile.getPath().getName(); expressions.put(name, readExpression(name, reader)); } catch (IOException e) { throw new UncheckedIOException("Failed reading " + expressionFile.getPath(), e); } catch (ParseException e) { throw new IllegalStateException("Invalid stored expression in " + expressionFile, e); } } return expressions; }