void loadMessages(String dir) { try { //load messages from the runtime jar URL url = Messages.class.getClassLoader().getResource(dir); if (url == null) { return; } URI uri = url.toURI(); if ("jar".equals(uri.getScheme())) { // jar scheme is required for Jenkins: // https://github.com/folio-org/raml-module-builder/pull/111 try (FileSystem fileSystem = getFileSystem(uri)) { Path messagePath = fileSystem.getPath(dir); loadMessages(messagePath); } } else { Path messagePath = Paths.get(uri); loadMessages(messagePath); } } catch (IOException|URISyntaxException e) { throw new IllegalArgumentException(dir, e); } }
public void get(String id, Handler<ExtendedAsyncResult<DeploymentDescriptor>> fut) { if (!list.containsKey(id)) { fut.handle(new Failure<>(NOT_FOUND, messages.getMessage("10705", id))); } else { fut.handle(new Success<>(list.get(id))); } } }
/** * Return the message from the properties file. * @param code - message code * @param messageArguments - message arguments to insert, see java.text.MessageFormat.format() * @return the message with arguments inserted */ public String getMessage(String code, Object... messageArguments) { final String language = currentLanguage; String pattern = getMessageSingle(language, code); if (pattern == null) { pattern = getMessageSingle(DEFAULT_LANGUAGE, code); } if (pattern == null) { return "Error message not found: " + language + " " + code; } else { return MessageFormat.format(pattern, messageArguments); } }
public void init(String[] args, Handler<AsyncResult<Vertx>> fut) { final Logger logger = OkapiLogger.get(); Messages.setLanguage(getProperty("lang", "en")); if (args.length < 1) { fut.handle(Future.failedFuture(messages.getMessage("10600"))); return; } if (parseOptions(args, fut)) { return; } final String mode = conf.getString("mode", "dev"); switch (mode) { case "dev": case "initdatabase": case "purgedatabase": deploy(new MainVerticle(), Vertx.vertx(vopt), fut); break; case "cluster": case "proxy": case "deployment": deployClustered(logger, fut); break; default: fut.handle(Future.failedFuture(messages.getMessage("10601",mode))); } }
Messages() { // throws exception on error loadAllMessages(); }
void loadAllMessages() { loadMessages(INFRA_MESSAGES_DIR); if (messageMap.isEmpty()) { throw new IllegalStateException("Messages not found: " + INFRA_MESSAGES_DIR); } //load project specific messages - they may not exist loadMessages(MESSAGES_DIR); }
private boolean deleteCheckDep(String id, Handler<ExtendedAsyncResult<Void>> fut, LinkedHashMap<String, ModuleDescriptor> mods) { if (!mods.containsKey(id)) { fut.handle(new Failure<>(NOT_FOUND, messages.getMessage("10207"))); return true; } mods.remove(id); String res = DepResolution.checkAllDependencies(mods); if (!res.isEmpty()) { fut.handle(new Failure<>(USER, messages.getMessage("10208", id, res))); return true; } else { return false; } }
private void responseError(int code, Throwable cause) { if (cause != null && cause.getMessage() != null) { responseError(code, cause.getMessage()); } else { responseError(code, messages.getMessage("10300")); } }
private int getExposedPort(JsonObject b) { JsonObject config = b.getJsonObject("Config"); if (config == null) { throw (new IllegalArgumentException(messages.getMessage("11302"))); } JsonObject exposedPorts = config.getJsonObject("ExposedPorts"); if (exposedPorts == null) { throw (new IllegalArgumentException(messages.getMessage("11301"))); } int exposedPort = 0; Iterator<Map.Entry<String, Object>> iterator = exposedPorts.iterator(); while (iterator.hasNext()) { Map.Entry<String, Object> next = iterator.next(); String key = next.getKey(); String sPort = key.split("/")[0]; if (exposedPort == 0) { exposedPort = Integer.valueOf(sPort); } } return exposedPort; }
private void getNode1(String nodeId, Handler<ExtendedAsyncResult<NodeDescriptor>> fut) { if (clusterManager != null) { List<String> n = clusterManager.getNodes(); if (!n.contains(nodeId)) { fut.handle(new Failure<>(NOT_FOUND, messages.getMessage("10806", nodeId))); return; } } nodes.get(nodeId, fut); }
private void add1(EnvEntry env, Handler<ExtendedAsyncResult<Void>> fut) { if (env.getName() == null) { fut.handle(new Failure<>(USER, messages.getMessage("10900"))); } else if (env.getValue() == null) { fut.handle(new Failure<>(USER, messages.getMessage("10901"))); } else { envMap.add(env.getName(), env, fut); } }
} else { if (hostPort == 0) { startFuture.handle(Future.failedFuture(messages.getMessage("11300"))); return;
DropwizardHelper.config(graphiteHost, graphitePort, tu, reporterPeriod, vopt, hostName); } else { fut.handle(Future.failedFuture(messages.getMessage("10602", args[i]))); return true;
private void waitPortToClose(Handler<AsyncResult<Void>> stopFuture, int iter) { if (port > 0) { // fail if port is already in use NetClientOptions options = new NetClientOptions().setConnectTimeout(50); NetClient c = vertx.createNetClient(options); c.connect(port, "localhost", res -> { if (res.succeeded()) { NetSocket socket = res.result(); socket.close(); if (iter > 0) { vertx.setTimer(100, x -> waitPortToClose(stopFuture, iter - 1)); } else { stopFuture.handle(Future.failedFuture(messages.getMessage("11503", Integer.toString(port)))); } } else { stopFuture.handle(Future.succeededFuture()); } }); } else { stopFuture.handle(Future.succeededFuture()); } }
future.handle(Future.failedFuture(messages.getMessage("11500", p.exitValue()))); return;
private void deleteTenant(String id, Handler<ExtendedAsyncResult<String>> fut) { if (XOkapiHeaders.SUPERTENANT_ID.equals(id)) { fut.handle(new Failure<>(USER, messages.getMessage("11603", id))); // Change of behavior, used to return 403 return; } tenantManager.delete(id, res -> { if (res.failed()) { fut.handle(new Failure<>(res.getType(), res.cause())); return; } fut.handle(new Success<>("")); }); }
/** * Check a module list for conflicts. * * @param modlist modules to be checked * @return error message listing conflicts, or "" if no problems */ public static String checkAllConflicts(Map<String, ModuleDescriptor> modlist) { Map<String, String> provs = new HashMap<>(); // interface name to module name List<String> conflicts = new LinkedList<>(); for (ModuleDescriptor md : modlist.values()) { InterfaceDescriptor[] provides = md.getProvidesList(); for (InterfaceDescriptor mi : provides) { if (mi.isRegularHandler()) { String confl = provs.get(mi.getId()); if (confl == null || confl.isEmpty()) { provs.put(mi.getId(), md.getId()); } else { String msg = messages.getMessage("10202", mi.getId(), md.getId(), confl); conflicts.add(msg); } } } } return String.join(". ", conflicts); }
private void tryConnect(Handler<AsyncResult<Void>> startFuture, int count) { NetClientOptions options = new NetClientOptions().setConnectTimeout(MILLISECONDS); NetClient c = vertx.createNetClient(options); logger.debug("ProcessModuleHandle.tryConnect() port " + port + " count " + count); c.connect(port, "localhost", res -> { if (res.succeeded()) { logger.info("Connected to service at port " + port + " count " + count); NetSocket socket = res.result(); socket.close(); try { p.getErrorStream().close(); } catch (Exception e) { logger.error("Closing streams failed: " + e); } startFuture.handle(Future.succeededFuture()); } else if (!p.isAlive() && p.exitValue() != 0) { logger.warn("Service returned with exit code " + p.exitValue()); startFuture.handle(Future.failedFuture(messages.getMessage("11500", p.exitValue()))); } else if (count < maxIterations) { vertx.setTimer((long) (count + 1) * MILLISECONDS, id -> tryConnect(startFuture, count + 1)); } else { this.stopProcess(res2 -> startFuture.handle(Future.failedFuture(messages.getMessage("11501", Integer.toString(port), res.cause().getMessage()))) ); } }); }
@Override public void updateModules(String id, SortedMap<String, Boolean> enabled, Handler<ExtendedAsyncResult<Void>> fut) { JsonObject jq = new JsonObject().put("_id", id); cli.find(COLLECTION, jq, gres -> { if (gres.failed()) { logger.debug("disableModule: find failed: " + gres.cause().getMessage()); fut.handle(new Failure<>(INTERNAL, gres.cause())); } else { List<JsonObject> l = gres.result(); if (l.isEmpty()) { logger.debug("disableModule: not found: " + id); fut.handle(new Failure<>(NOT_FOUND, messages.getMessage("1100", id))); } else { JsonObject d = l.get(0); final Tenant t = decodeTenant(d); t.setEnabled(enabled); JsonObject document = encodeTenant(t, id); cli.save(COLLECTION, document, sres -> { if (sres.failed()) { logger.debug("TenantStoreMongo: disable: saving failed: " + sres.cause().getMessage()); fut.handle(new Failure<>(INTERNAL, sres.cause())); } else { fut.handle(new Success<>()); } }); } } }); }
@Override public void start(Handler<AsyncResult<Void>> startFuture) { if (port > 0) { // fail if port is already in use NetClientOptions options = new NetClientOptions().setConnectTimeout(200); NetClient c = vertx.createNetClient(options); c.connect(port, "localhost", res -> { if (res.succeeded()) { NetSocket socket = res.result(); socket.close(); startFuture.handle(Future.failedFuture(messages.getMessage("11502", Integer.toString(port)))); } else { start2(startFuture); } }); } else { start2(startFuture); } }