Search in sources :

Example 11 with TenantModuleDescriptor

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

the class TenantManager method installCommit1.

/* phase 1 deploy modules if necessary */
private void installCommit1(Tenant t, ProxyContext pc, TenantInstallOptions options, Map<String, ModuleDescriptor> modsAvailable, List<TenantModuleDescriptor> tml, Iterator<TenantModuleDescriptor> it, Handler<ExtendedAsyncResult<Void>> fut) {
    if (it.hasNext() && options.getDeploy()) {
        TenantModuleDescriptor tm = it.next();
        if ("enable".equals(tm.getAction()) || "uptodate".equals(tm.getAction())) {
            ModuleDescriptor md = modsAvailable.get(tm.getId());
            proxyService.autoDeploy(md, pc, res -> {
                if (res.failed()) {
                    fut.handle(new Failure<>(res.getType(), res.cause()));
                } else {
                    installCommit1(t, pc, options, modsAvailable, tml, it, fut);
                }
            });
        } else {
            installCommit1(t, pc, options, modsAvailable, tml, it, fut);
        }
    } else {
        installCommit2(t, pc, options, modsAvailable, tml, tml.iterator(), fut);
    }
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor)

Example 12 with TenantModuleDescriptor

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

the class TenantManager method tmEnable.

private boolean tmEnable(String id, Map<String, ModuleDescriptor> modsAvailable, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml, Handler<ExtendedAsyncResult<Boolean>> fut) {
    ModuleId moduleId = new ModuleId(id);
    if (!moduleId.hasSemVer()) {
        id = moduleId.getLatest(modsAvailable.keySet());
    }
    if (!modsAvailable.containsKey(id)) {
        fut.handle(new Failure<>(NOT_FOUND, id));
        return true;
    }
    if (modsEnabled.containsKey(id)) {
        boolean alreadyEnabled = false;
        for (TenantModuleDescriptor tm : tml) {
            if (tm.getId().equals(id)) {
                alreadyEnabled = true;
            }
        }
        if (!alreadyEnabled) {
            TenantModuleDescriptor tmu = new TenantModuleDescriptor();
            tmu.setAction("uptodate");
            tmu.setId(id);
            tml.add(tmu);
        }
    } else {
        moduleManager.addModuleDependencies(modsAvailable.get(id), modsAvailable, modsEnabled, tml);
    }
    return false;
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleId(org.folio.okapi.common.ModuleId)

Example 13 with TenantModuleDescriptor

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

the class TenantManager method installCommit3.

/* phase 3 undeploy if no longer needed */
private void installCommit3(Tenant tenant, ProxyContext pc, TenantInstallOptions options, Map<String, ModuleDescriptor> modsAvailable, List<TenantModuleDescriptor> tml, Iterator<TenantModuleDescriptor> it, Handler<ExtendedAsyncResult<Void>> fut) {
    if (it.hasNext() && options.getDeploy()) {
        TenantModuleDescriptor tm = it.next();
        ModuleDescriptor md = null;
        if ("enable".equals(tm.getAction())) {
            md = modsAvailable.get(tm.getFrom());
        }
        if ("disable".equals(tm.getAction())) {
            md = modsAvailable.get(tm.getId());
        }
        if (md != null) {
            final ModuleDescriptor mdF = md;
            getModuleUser(md.getId(), ures -> {
                if (ures.failed()) {
                    // in use or other error, so skip
                    installCommit3(tenant, pc, options, modsAvailable, tml, it, fut);
                } else {
                    // success means : not in use, so we can undeploy it
                    proxyService.autoUndeploy(mdF, pc, res -> {
                        if (res.failed()) {
                            fut.handle(new Failure<>(res.getType(), res.cause()));
                        } else {
                            installCommit3(tenant, pc, options, modsAvailable, tml, it, fut);
                        }
                    });
                }
            });
        } else {
            installCommit3(tenant, pc, options, modsAvailable, tml, it, fut);
        }
    } else {
        fut.handle(new Success<>());
    }
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor)

Example 14 with TenantModuleDescriptor

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

the class TenantManager method prepareTenantModuleList.

private List<TenantModuleDescriptor> prepareTenantModuleList(Map<String, ModuleDescriptor> modsAvailable, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml) {
    if (tml == null) {
        // upgrade case . Mark all newer modules for install
        List<TenantModuleDescriptor> tml2 = new LinkedList<>();
        for (String fId : modsEnabled.keySet()) {
            ModuleId moduleId = new ModuleId(fId);
            String uId = moduleId.getLatest(modsAvailable.keySet());
            if (!uId.equals(fId)) {
                TenantModuleDescriptor tmd = new TenantModuleDescriptor();
                tmd.setAction("enable");
                tmd.setId(uId);
                logger.info("upgrade.. enable " + uId);
                tmd.setFrom(fId);
                tml2.add(tmd);
            }
        }
        return tml2;
    } else {
        return tml;
    }
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleId(org.folio.okapi.common.ModuleId) LinkedList(java.util.LinkedList)

Example 15 with TenantModuleDescriptor

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

the class TenantManager method installCheckDependencies.

private void installCheckDependencies(Map<String, ModuleDescriptor> modsAvailable, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml, Handler<ExtendedAsyncResult<Boolean>> fut) {
    List<TenantModuleDescriptor> tml2 = new LinkedList<>();
    for (TenantModuleDescriptor tm : tml) {
        if (tmAction(tm, modsAvailable, modsEnabled, tml2, fut)) {
            return;
        }
    }
    String s = moduleManager.checkAllDependencies(modsEnabled);
    if (!s.isEmpty()) {
        logger.warn("installModules.checkAllDependencies: " + s);
        fut.handle(new Failure<>(USER, s));
        return;
    }
    tml.clear();
    for (TenantModuleDescriptor tm : tml2) {
        tml.add(tm);
    }
    logger.info("installModules.returning OK");
    fut.handle(new Success<>(Boolean.TRUE));
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) LinkedList(java.util.LinkedList)

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