Search in sources :

Example 1 with TenantModuleDescriptor

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

the class ModuleManager method resolveModuleConflicts.

private int resolveModuleConflicts(ModuleDescriptor md, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml, List<ModuleDescriptor> fromModule) {
    int v = 0;
    Iterator<String> it = modsEnabled.keySet().iterator();
    while (it.hasNext()) {
        String runningmodule = it.next();
        ModuleDescriptor rm = modsEnabled.get(runningmodule);
        if (md.getProduct().equals(rm.getProduct())) {
            logger.info("resolveModuleConflicts from " + runningmodule);
            fromModule.add(rm);
            modsEnabled.remove(runningmodule);
            it = modsEnabled.keySet().iterator();
            v++;
        } else {
            for (InterfaceDescriptor pi : rm.getProvidesList()) {
                if (pi.isRegularHandler()) {
                    String confl = pi.getId();
                    for (InterfaceDescriptor mi : md.getProvidesList()) {
                        if (mi.getId().equals(confl) && mi.isRegularHandler() && modsEnabled.containsKey(runningmodule)) {
                            logger.info("resolveModuleConflicts remove " + runningmodule);
                            TenantModuleDescriptor tm = new TenantModuleDescriptor();
                            tm.setAction("disable");
                            tm.setId(runningmodule);
                            tml.add(tm);
                            modsEnabled.remove(runningmodule);
                            it = modsEnabled.keySet().iterator();
                            v++;
                        }
                    }
                }
            }
        }
    }
    return v;
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Example 2 with TenantModuleDescriptor

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

the class ModuleManager method removeModuleDependencies.

public int removeModuleDependencies(ModuleDescriptor md, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml) {
    int sum = 0;
    logger.info("removeModuleDependencies " + md.getId());
    if (!modsEnabled.containsKey(md.getId())) {
        return 0;
    }
    InterfaceDescriptor[] provides = md.getProvidesList();
    for (InterfaceDescriptor prov : provides) {
        if (prov.isRegularHandler()) {
            Iterator<String> it = modsEnabled.keySet().iterator();
            while (it.hasNext()) {
                String runningmodule = it.next();
                ModuleDescriptor rm = modsEnabled.get(runningmodule);
                InterfaceDescriptor[] requires = rm.getRequiresList();
                for (InterfaceDescriptor ri : requires) {
                    if (prov.getId().equals(ri.getId())) {
                        sum += removeModuleDependencies(rm, modsEnabled, tml);
                        it = modsEnabled.keySet().iterator();
                    }
                }
            }
        }
    }
    modsEnabled.remove(md.getId());
    TenantModuleDescriptor tm = new TenantModuleDescriptor();
    tm.setAction("disable");
    tm.setId(md.getId());
    tml.add(tm);
    return sum + 1;
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Example 3 with TenantModuleDescriptor

use of org.folio.okapi.bean.TenantModuleDescriptor 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 4 with TenantModuleDescriptor

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

the class InternalModule method installModulesForTenant.

private void installModulesForTenant(ProxyContext pc, String id, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        TenantInstallOptions options = createTenantOptions(pc.getCtx());
        final TenantModuleDescriptor[] tml = Json.decodeValue(body, TenantModuleDescriptor[].class);
        List<TenantModuleDescriptor> tm = new LinkedList<>();
        Collections.addAll(tm, tml);
        tenantManager.installUpgradeModules(id, pc, options, tm, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
            } else {
                logger.info("installUpgradeModules returns:\n" + Json.encodePrettily(res.result()));
                fut.handle(new Success<>(Json.encodePrettily(res.result())));
            }
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) DecodeException(io.vertx.core.json.DecodeException) LinkedList(java.util.LinkedList) Failure(org.folio.okapi.common.Failure) TenantInstallOptions(org.folio.okapi.util.TenantInstallOptions)

Example 5 with TenantModuleDescriptor

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

the class InternalModule method upgradeModuleForTenant.

private void upgradeModuleForTenant(ProxyContext pc, String id, String mod, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final String module_from = mod;
        final TenantModuleDescriptor td = Json.decodeValue(body, TenantModuleDescriptor.class);
        final String module_to = td.getId();
        tenantManager.enableAndDisableModule(id, module_from, module_to, pc, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            td.setId(res.result());
            final String uri = pc.getCtx().request().uri();
            final String regex = "^(.*)/" + module_from + "$";
            final String newuri = uri.replaceAll(regex, "$1");
            location(pc, td.getId(), newuri, Json.encodePrettily(td), fut);
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Aggregations

TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)17 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)9 LinkedList (java.util.LinkedList)4 InterfaceDescriptor (org.folio.okapi.bean.InterfaceDescriptor)4 DecodeException (io.vertx.core.json.DecodeException)3 Failure (org.folio.okapi.common.Failure)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Tenant (org.folio.okapi.bean.Tenant)2 ModuleId (org.folio.okapi.common.ModuleId)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TenantInstallOptions (org.folio.okapi.util.TenantInstallOptions)1