Search in sources :

Example 21 with ModuleDescriptor

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

the class TenantManager method ead2PermMod.

/**
 * enableAndDisable helper 2: Choose which permission module to invoke.
 *
 * @param tenant
 * @param mdFrom
 * @param mdTo
 * @param pc
 * @param fut
 */
private void ead2PermMod(Tenant tenant, ModuleDescriptor mdFrom, ModuleDescriptor mdTo, ProxyContext pc, Handler<ExtendedAsyncResult<Void>> fut) {
    String moduleFrom = mdFrom != null ? mdFrom.getId() : null;
    String moduleTo = mdTo.getId();
    findSystemInterface(tenant, res -> {
        if (res.failed()) {
            if (res.getType() == NOT_FOUND) {
                // no perms interface.
                if (mdTo.getSystemInterface("_tenantPermissions") != null) {
                    pc.debug("ead2PermMod: Here we reload perms of all enabled modules");
                    Set<String> listModules = tenant.listModules();
                    pc.debug("Got a list of already-enabled moduled: " + Json.encode(listModules));
                    Iterator<String> modit = listModules.iterator();
                    ead3RealoadPerms(tenant, modit, moduleFrom, mdTo, mdTo, pc, fut);
                    return;
                }
                pc.debug("enablePermissions: No tenantPermissions interface found. " + "Carrying on without it.");
                ead5commit(tenant, moduleFrom, moduleTo, pc, fut);
            } else {
                pc.responseError(res.getType(), res.cause());
            }
        } else {
            ModuleDescriptor permsMod = res.result();
            if (mdTo.getSystemInterface("_tenantPermissions") != null) {
                pc.debug("Using the tenantPermissions of this module itself");
                permsMod = mdTo;
            }
            ead4Permissions(tenant, moduleFrom, mdTo, permsMod, pc, fut);
        }
    });
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor)

Example 22 with ModuleDescriptor

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

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

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

the class TenantManager method listModulesFromInterface.

public void listModulesFromInterface(String tenantId, String interfaceName, String interfaceType, Handler<ExtendedAsyncResult<List<ModuleDescriptor>>> fut) {
    tenants.get(tenantId, tres -> {
        if (tres.failed()) {
            fut.handle(new Failure<>(tres.getType(), tres.cause()));
            return;
        }
        Tenant tenant = tres.result();
        List<ModuleDescriptor> mdList = new LinkedList<>();
        moduleManager.getEnabledModules(tenant, mres -> {
            if (mres.failed()) {
                fut.handle(new Failure<>(mres.getType(), mres.cause()));
                return;
            }
            List<ModuleDescriptor> modlist = mres.result();
            for (ModuleDescriptor md : modlist) {
                for (InterfaceDescriptor provide : md.getProvidesList()) {
                    if (interfaceName.equals(provide.getId()) && (interfaceType == null || provide.isType(interfaceType))) {
                        mdList.add(md);
                        break;
                    }
                }
            }
            fut.handle(new Success<>(mdList));
        });
    // modlist
    });
// tenant
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) Tenant(org.folio.okapi.bean.Tenant) LinkedList(java.util.LinkedList) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Example 25 with ModuleDescriptor

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

the class TenantManager method listInterfaces.

private void listInterfaces(Tenant tenant, boolean full, String interfaceType, Handler<ExtendedAsyncResult<List<InterfaceDescriptor>>> fut) {
    List<InterfaceDescriptor> intList = new LinkedList<>();
    moduleManager.getEnabledModules(tenant, mres -> {
        if (mres.failed()) {
            fut.handle(new Failure<>(mres.getType(), mres.cause()));
            return;
        }
        List<ModuleDescriptor> modlist = mres.result();
        Set<String> ids = new HashSet<>();
        for (ModuleDescriptor md : modlist) {
            for (InterfaceDescriptor provide : md.getProvidesList()) {
                if (interfaceType == null || provide.isType(interfaceType)) {
                    if (full) {
                        intList.add(provide);
                    } else {
                        if (ids.add(provide.getId())) {
                            InterfaceDescriptor tmp = new InterfaceDescriptor();
                            tmp.setId(provide.getId());
                            tmp.setVersion(provide.getVersion());
                            intList.add(tmp);
                        }
                    }
                }
            }
        }
        fut.handle(new Success<>(intList));
    });
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) LinkedList(java.util.LinkedList) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor) HashSet(java.util.HashSet)

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