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))); } } }
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); } }
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))); } }
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()); } }
/** * 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 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<>("")); }); }
@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); } }
public void deploy(DeploymentDescriptor md1, Handler<ExtendedAsyncResult<DeploymentDescriptor>> fut) { String id = md1.getInstId(); if (id != null && list.containsKey(id)) { fut.handle(new Failure<>(USER, messages.getMessage("10700", id))); return; } String srvc = md1.getSrvcId(); if (srvc == null) { fut.handle(new Failure<>(USER, messages.getMessage("10701"))); return; } Timer.Context tim = DropwizardHelper.getTimerContext("deploy." + srvc + ".deploy"); int usePort = ports.get(); if (usePort == -1) { fut.handle(new Failure<>(USER, messages.getMessage("10702"))); tim.close(); return; } String url = "http://" + host + ":" + usePort; if (id == null) { id = UUID.randomUUID().toString(); md1.setInstId(id); } logger.info("deploy instId " + id); deploy2(fut, tim, usePort, md1, url); }
private void addAndDeploy2(DeploymentDescriptor dd, ModuleDescriptor md, ProxyContext pc, Handler<ExtendedAsyncResult<DeploymentDescriptor>> fut, final String nodeId) { String modId = dd.getSrvcId(); LaunchDescriptor modLaunchDesc = md.getLaunchDescriptor(); if (modLaunchDesc == null) { fut.handle(new Failure<>(USER, messages.getMessage("10804", modId))); } else { dd.setDescriptor(modLaunchDesc); callDeploy(nodeId, pc, dd, fut); } }
private static boolean tmAction(TenantModuleDescriptor tm, Map<String, ModuleDescriptor> modsAvailable, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml, Handler<ExtendedAsyncResult<Boolean>> fut) { String id = tm.getId(); TenantModuleDescriptor.Action action = tm.getAction(); if (null == action) { fut.handle(new Failure<>(INTERNAL, messages.getMessage("10404", "null"))); return true; } else { switch (action) { case enable: return tmEnable(id, modsAvailable, modsEnabled, tml, fut); case uptodate: return false; case disable: return tmDisable(id, modsAvailable, modsEnabled, tml, fut); default: fut.handle(new Failure<>(INTERNAL, messages.getMessage("10404", action.name()))); return true; } } }
private void location(ProxyContext pc, String id, String baseUri, String s, Handler<ExtendedAsyncResult<String>> fut) { String uri; try { if (baseUri == null) { uri = pc.getCtx().request().uri(); } else { uri = baseUri; } int idx = uri.indexOf('?'); if (idx != -1) { uri = uri.substring(0, idx); } uri = uri + "/" + URLEncoder.encode(id, "UTF-8"); pc.getCtx().response().putHeader("Location", uri); pc.getCtx().response().setStatusCode(201); fut.handle(new Success<>(s)); } catch (UnsupportedEncodingException ex) { fut.handle(new Failure<>(INTERNAL, messages.getMessage("11600", id, ex.getMessage()))); } }
public void get(String srvcId, String instId, Handler<ExtendedAsyncResult<DeploymentDescriptor>> fut) { deployments.get(srvcId, instId, resGet -> { if (resGet.failed()) { fut.handle(new Failure<>(resGet.getType(), resGet.cause())); } else { DeploymentDescriptor md = resGet.result(); String url = md.getUrl(); // check that the node is alive, but only on non-url instances if (clusterManager != null && url == null && !clusterManager.getNodes().contains(md.getNodeId())) { fut.handle(new Failure<>(NOT_FOUND, messages.getMessage("10805"))); return; } fut.handle(new Success<>(md)); } }); }
private void updateModule(ProxyContext pc, String id, String body, Handler<ExtendedAsyncResult<String>> fut) { try { final ModuleDescriptor md = Json.decodeValue(body, ModuleDescriptor.class); if (!id.equals(md.getId())) { fut.handle(new Failure<>(USER, messages.getMessage("11606", md.getId(), id))); return; } String validerr = md.validate(pc); if (!validerr.isEmpty()) { fut.handle(new Failure<>(USER, validerr)); return; } moduleManager.update(md, res -> { if (res.failed()) { fut.handle(new Failure<>(res.getType(), res.cause())); return; } final String s = Json.encodePrettily(md); fut.handle(new Success<>(s)); }); } catch (DecodeException ex) { fut.handle(new Failure<>(USER, ex)); } }
private void createTenant(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) { try { final TenantDescriptor td = Json.decodeValue(body, TenantDescriptor.class); if (td.getId() == null || td.getId().isEmpty()) { td.setId(UUID.randomUUID().toString()); } final String id = td.getId(); if (!id.matches("^[a-z0-9_-]+$")) { fut.handle(new Failure<>(USER, messages.getMessage("11601", id))); return; } Tenant t = new Tenant(td); tenantManager.insert(t, res -> { if (res.failed()) { fut.handle(new Failure<>(res.getType(), res.cause())); return; } location(pc, id, null, Json.encodePrettily(t.getDescriptor()), fut); }); } catch (DecodeException ex) { fut.handle(new Failure<>(USER, ex)); } }
private void updateTenant(String id, String body, Handler<ExtendedAsyncResult<String>> fut) { try { final TenantDescriptor td = Json.decodeValue(body, TenantDescriptor.class); if (!id.equals(td.getId())) { fut.handle(new Failure<>(USER, messages.getMessage("11602", td.getId(), id))); return; } Tenant t = new Tenant(td); tenantManager.updateDescriptor(td, res -> { if (res.failed()) { fut.handle(new Failure<>(res.getType(), res.cause())); return; } final String s = Json.encodePrettily(t.getDescriptor()); fut.handle(new Success<>(s)); }); } catch (DecodeException ex) { fut.handle(new Failure<>(USER, ex)); } }
private void findSystemInterfaceR(Tenant tenant, String interfaceName, Iterator<String> it, Handler<ExtendedAsyncResult<ModuleDescriptor>> fut) { if (!it.hasNext()) { fut.handle(new Failure<>(NOT_FOUND, messages.getMessage("10403", interfaceName))); return; } String mid = it.next(); moduleManager.get(mid, gres -> { if (gres.failed()) { // should not happen fut.handle(new Failure<>(gres.getType(), gres.cause())); return; } ModuleDescriptor md = gres.result(); logger.debug("findSystemInterface: looking at " + mid + ": " + " si: " + md.getSystemInterface(interfaceName)); if (md.getSystemInterface(interfaceName) != null ) { logger.debug("findSystemInterface: found " + mid); fut.handle(new Success<>(md)); return; } findSystemInterfaceR(tenant, interfaceName, it, fut); }); }