Search in sources :

Example 6 with ModuleDescriptor

use of org.folio.okapi.bean.ModuleDescriptor in project okapi by folio-org.

the class PullManager method getList.

private void getList(String urlBase, Handler<ExtendedAsyncResult<ModuleDescriptor[]>> fut) {
    String url = urlBase;
    if (!url.endsWith("/")) {
        url += "/";
    }
    url += "_/proxy/modules";
    final Buffer body = Buffer.buffer();
    HttpClientRequest req = httpClient.getAbs(url, res -> {
        res.handler(body::appendBuffer);
        res.endHandler(x -> {
            if (res.statusCode() != 200) {
                fut.handle(new Failure<>(ErrorType.USER, body.toString()));
            } else {
                ModuleDescriptor[] ml = Json.decodeValue(body.toString(), ModuleDescriptor[].class);
                fut.handle(new Success<>(ml));
            }
        });
        res.exceptionHandler(x -> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
    });
    req.exceptionHandler(x -> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
    req.end();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Failure(org.folio.okapi.common.Failure)

Example 7 with ModuleDescriptor

use of org.folio.okapi.bean.ModuleDescriptor in project okapi by folio-org.

the class PullManager method getFullReq.

private void getFullReq(String url, Handler<ExtendedAsyncResult<List<ModuleDescriptor>>> fut, List<ModuleDescriptor> ml, String urlBase, Iterator<ModuleDescriptor> it) {
    final Buffer body = Buffer.buffer();
    HttpClientRequest req = httpClient.getAbs(url, res -> {
        res.handler(body::appendBuffer);
        res.endHandler(x -> {
            if (concurrentRuns > 0) {
                concurrentRuns--;
            }
            if (res.statusCode() != 200) {
                if (!concurrentComplete) {
                    concurrentComplete = true;
                    fut.handle(new Failure<>(ErrorType.USER, body.toString()));
                }
            } else {
                ModuleDescriptor md = Json.decodeValue(body.toString(), ModuleDescriptor.class);
                ml.add(md);
                getFull(urlBase, it, ml, fut);
            }
        });
        res.exceptionHandler(x -> {
            if (concurrentRuns > 0) {
                concurrentRuns--;
            }
            if (!concurrentComplete) {
                concurrentComplete = true;
                fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage()));
            }
        });
    });
    req.exceptionHandler(x -> {
        if (concurrentRuns > 0) {
            concurrentRuns--;
        }
        if (!concurrentComplete) {
            concurrentComplete = true;
            fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage()));
        }
    });
    req.end();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Example 8 with ModuleDescriptor

use of org.folio.okapi.bean.ModuleDescriptor in project okapi by folio-org.

the class TenantManager method checkDependencies.

/**
 * Check module dependencies and conflicts.
 *
 * @param tenant to check for
 * @param modFrom module to be removed. Ignored in the checks
 * @param modTo module to be added
 * @param fut Callback for error messages, or a simple Success
 */
private void checkDependencies(Tenant tenant, ModuleDescriptor modFrom, ModuleDescriptor modTo, Handler<ExtendedAsyncResult<Void>> fut) {
    moduleManager.getEnabledModules(tenant, gres -> {
        if (gres.failed()) {
            fut.handle(new Failure<>(gres.getType(), gres.cause()));
            return;
        }
        List<ModuleDescriptor> modlist = gres.result();
        HashMap<String, ModuleDescriptor> mods = new HashMap<>(modlist.size());
        for (ModuleDescriptor md : modlist) {
            mods.put(md.getId(), md);
        }
        if (modFrom != null) {
            mods.remove(modFrom.getId());
        }
        if (modTo != null) {
            ModuleDescriptor already = mods.get(modTo.getId());
            if (already != null) {
                fut.handle(new Failure<>(USER, "Module " + modTo.getId() + " already provided"));
                return;
            }
            mods.put(modTo.getId(), modTo);
        }
        String conflicts = moduleManager.checkAllConflicts(mods);
        String deps = moduleManager.checkAllDependencies(mods);
        if (conflicts.isEmpty() && deps.isEmpty()) {
            fut.handle(new Success<>());
        } else {
            fut.handle(new Failure<>(USER, conflicts + " " + deps));
        }
    });
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) HashMap(java.util.HashMap)

Example 9 with ModuleDescriptor

use of org.folio.okapi.bean.ModuleDescriptor in project okapi by folio-org.

the class TenantManager method installUpgradeModules.

public void installUpgradeModules(String tenantId, ProxyContext pc, TenantInstallOptions options, List<TenantModuleDescriptor> tml, Handler<ExtendedAsyncResult<List<TenantModuleDescriptor>>> fut) {
    tenants.get(tenantId, gres -> {
        if (gres.failed()) {
            fut.handle(new Failure<>(gres.getType(), gres.cause()));
            return;
        }
        Tenant t = gres.result();
        moduleManager.getModulesWithFilter(null, options.getPreRelease(), mres -> {
            if (mres.failed()) {
                fut.handle(new Failure<>(mres.getType(), mres.cause()));
                return;
            }
            List<ModuleDescriptor> modResult = mres.result();
            HashMap<String, ModuleDescriptor> modsAvailable = new HashMap<>(modResult.size());
            HashMap<String, ModuleDescriptor> modsEnabled = new HashMap<>();
            for (ModuleDescriptor md : modResult) {
                modsAvailable.put(md.getId(), md);
                logger.info("mod available: " + md.getId());
                if (t.isEnabled(md.getId())) {
                    logger.info("mod enabled: " + md.getId());
                    modsEnabled.put(md.getId(), md);
                }
            }
            List<TenantModuleDescriptor> tml2 = prepareTenantModuleList(modsAvailable, modsEnabled, tml);
            installUpgradeModules2(t, pc, options, modsAvailable, modsEnabled, tml2, fut);
        });
    });
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) Tenant(org.folio.okapi.bean.Tenant) HashMap(java.util.HashMap)

Example 10 with ModuleDescriptor

use of org.folio.okapi.bean.ModuleDescriptor in project okapi by folio-org.

the class TenantManager method findSystemInterfaceR.

private void findSystemInterfaceR(Tenant tenant, String interfaceName, Iterator<String> it, Handler<ExtendedAsyncResult<ModuleDescriptor>> fut) {
    if (!it.hasNext()) {
        fut.handle(new Failure<>(NOT_FOUND, "No module provides " + 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);
    });
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor)

Aggregations

ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)34 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)24 InterfaceDescriptor (org.folio.okapi.bean.InterfaceDescriptor)7 LinkedList (java.util.LinkedList)6 DecodeException (io.vertx.core.json.DecodeException)4 HashMap (java.util.HashMap)4 Failure (org.folio.okapi.common.Failure)4 Buffer (io.vertx.core.buffer.Buffer)3 ArrayList (java.util.ArrayList)3 ModuleInstance (org.folio.okapi.bean.ModuleInstance)3 RoutingEntry (org.folio.okapi.bean.RoutingEntry)3 Tenant (org.folio.okapi.bean.Tenant)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 LinkedHashMap (java.util.LinkedHashMap)2 ModuleId (org.folio.okapi.common.ModuleId)2 CompList (org.folio.okapi.util.CompList)2 HttpServerRequest (io.vertx.core.http.HttpServerRequest)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1