public MeshNameProvider() throws Exception { init(); }
public static MeshNameProvider getInstance() { if (instance == null) { try { instance = new MeshNameProvider(); } catch (Exception e) { throw new RuntimeException(e); } } return instance; }
@Override public RootVertex<Node> getRootVertex() { return boot.meshRoot().getNodeRoot(); }
/** * Generate a default configuration with meaningful default settings. The keystore password will be randomly generated and set. * * @return */ private static MeshOptions generateDefaultConfig() { MeshOptions options = new MeshOptions(); options.getAuthenticationOptions().setKeystorePassword(UUIDUtil.randomUUID()); options.setNodeName(MeshNameProvider.getInstance().getRandomName()); return options; }
public static void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("mesh.jar", options()); } }
/** * Generate a random name. * * @return */ public String getRandomName() { try { JSONArray adjArray = adjectives.getJSONArray("data"); int randomAdjectiveIndex = (int) (Math.random() * adjArray.length()); String partA = StringUtils.trim(adjArray.getString(randomAdjectiveIndex)); LocalDate now = getDate(); if (now.getDayOfMonth() == 1 && now.getMonth() == Month.APRIL) { return partA + " Skynet"; } JSONArray nameArray = names.getJSONArray("data"); int randomNameIndex = (int) (Math.random() * nameArray.length()); String partB = StringUtils.trim(nameArray.getString(randomNameIndex)); return partA + " " + partB; } catch (Exception e) { log.error("Error while getting random name.", e); return "Unknown"; } }
@Override public RootVertex<SchemaContainer> getRootVertex() { return boot.meshRoot().getSchemaContainerRoot(); }
/** * Parse the given command line arguments and return the parsed representation. * * @param args * @return * @throws ParseException */ public static CommandLine parse(String... args) throws ParseException { CommandLineParser parser = new BasicParser(); return parser.parse(options(), args); }
@Override public RootVertex<Role> getRootVertex() { return boot.meshRoot().getRoleRoot(); }
@Override public RootVertex<MicroschemaContainer> getRootVertex() { return boot.meshRoot().getMicroschemaContainerRoot(); }
@Override public RootVertex<User> getRootVertex() { return boot.meshRoot().getUserRoot(); }
@Override public RootVertex<Group> getRootVertex() { return boot.meshRoot().getGroupRoot(); }
@Override public RootVertex<TagFamily> getRootVertex() { return boot.meshRoot().getTagFamilyRoot(); }
@Override public RootVertex<Tag> getRootVertex() { return boot.meshRoot().getTagRoot(); }
@Override public RootVertex<Project> getRootVertex() { return boot.meshRoot().getProjectRoot(); }
@Override public Set<String> filterUnknownIndices(Set<String> indices) { return db.tx(() -> { Set<String> activeIndices = new HashSet<>(); for (Project project : boot.meshRoot().getProjectRoot().findAll()) { activeIndices.add(TagFamily.composeIndexName(project.getUuid())); } return indices.stream() .filter(i -> i.startsWith(getType())) .filter(i -> !activeIndices.contains(i)) .collect(Collectors.toSet()); }); }
@Override public Set<String> filterUnknownIndices(Set<String> indices) { return db.tx(() -> { Set<String> activeIndices = new HashSet<>(); for (Project project : boot.meshRoot().getProjectRoot().findAll()) { activeIndices.add(Tag.composeIndexName(project.getUuid())); } return indices.stream() .filter(i -> i.startsWith(getType() + "-")) .filter(i -> !activeIndices.contains(i)) .collect(Collectors.toSet()); }); }
@Override public Map<String, IndexInfo> getIndices() { return db.tx(() -> { Map<String, IndexInfo> indexInfo = new HashMap<>(); ProjectRoot projectRoot = boot.meshRoot().getProjectRoot(); for (Project project : projectRoot.findAll()) { String indexName = Tag.composeIndexName(project.getUuid()); IndexInfo info = new IndexInfo(indexName, null, getMappingProvider().getMapping(), "tag"); indexInfo.put(indexName, info); } return indexInfo; }); }
@Override public Map<String, IndexInfo> getIndices() { return db.tx(() -> { ProjectRoot root = boot.meshRoot().getProjectRoot(); Map<String, IndexInfo> indexInfo = new HashMap<>(); for (Project project : root.findAll()) { String indexName = TagFamily.composeIndexName(project.getUuid()); IndexInfo info = new IndexInfo(indexName, null, getMappingProvider().getMapping(), "tagFamily"); indexInfo.put(indexName, info); } return indexInfo; }); }