Search in sources :

Example 26 with ModuleDescriptor

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

the class ModuleManager method createList2.

private void createList2(List<ModuleDescriptor> list, Handler<ExtendedAsyncResult<Void>> fut) {
    CompList<Void> futures = new CompList<>(INTERNAL);
    for (ModuleDescriptor md : list) {
        Future<Void> f = Future.future();
        createList3(md, f::handle);
        futures.add(f);
    }
    futures.all(fut);
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) CompList(org.folio.okapi.util.CompList)

Example 27 with ModuleDescriptor

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

the class ModuleManager method addModuleDependencies.

public int addModuleDependencies(ModuleDescriptor md, Map<String, ModuleDescriptor> modsAvailable, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml) {
    int sum = 0;
    logger.info("addModuleDependencies " + md.getId());
    for (InterfaceDescriptor req : md.getRequiresList()) {
        int v = checkInterfaceDependency(req, modsAvailable, modsEnabled, tml);
        if (v == -1) {
            return v;
        }
        sum += v;
    }
    List<ModuleDescriptor> fromModule = new LinkedList<>();
    sum += resolveModuleConflicts(md, modsEnabled, tml, fromModule);
    logger.info("addModuleDependencies - add " + md.getId());
    modsEnabled.put(md.getId(), md);
    TenantModuleDescriptor tm = new TenantModuleDescriptor();
    tm.setAction("enable");
    if (!fromModule.isEmpty()) {
        tm.setFrom(fromModule.get(0).getId());
    }
    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) LinkedList(java.util.LinkedList) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Example 28 with ModuleDescriptor

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

the class ModuleManager method createList.

/**
 * Create a whole list of modules.
 *
 * @param list
 * @param fut
 */
public void createList(List<ModuleDescriptor> list, boolean check, Handler<ExtendedAsyncResult<Void>> fut) {
    modules.getAll(ares -> {
        if (ares.failed()) {
            fut.handle(new Failure<>(ares.getType(), ares.cause()));
            return;
        }
        LinkedHashMap<String, ModuleDescriptor> tempList = ares.result();
        LinkedList<ModuleDescriptor> nList = new LinkedList<>();
        for (ModuleDescriptor md : list) {
            final String id = md.getId();
            if (tempList.containsKey(id)) {
                ModuleDescriptor exMd = tempList.get(id);
                String exJson = Json.encodePrettily(exMd);
                String json = Json.encodePrettily(md);
                if (!json.equals(exJson)) {
                    fut.handle(new Failure<>(USER, "create: module " + id + " exists already"));
                    return;
                }
            } else {
                tempList.put(id, md);
                nList.add(md);
            }
        }
        if (check) {
            String res = checkAllDependencies(tempList);
            if (!res.isEmpty()) {
                fut.handle(new Failure<>(USER, res));
                return;
            }
        }
        createList2(nList, fut);
    });
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) LinkedList(java.util.LinkedList)

Example 29 with ModuleDescriptor

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

the class ModuleManager method getModulesWithFilter.

public void getModulesWithFilter(ModuleId filter, boolean preRelease, Handler<ExtendedAsyncResult<List<ModuleDescriptor>>> fut) {
    modules.getAll(kres -> {
        if (kres.failed()) {
            fut.handle(new Failure<>(kres.getType(), kres.cause()));
        } else {
            List<ModuleDescriptor> mdl = new LinkedList<>();
            for (ModuleDescriptor md : kres.result().values()) {
                String id = md.getId();
                ModuleId idThis = new ModuleId(id);
                if ((filter == null || idThis.hasPrefix(filter)) && (preRelease || !idThis.hasPreRelease())) {
                    mdl.add(md);
                }
            }
            fut.handle(new Success<>(mdl));
        }
    });
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleId(org.folio.okapi.common.ModuleId) LinkedList(java.util.LinkedList)

Example 30 with ModuleDescriptor

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

the class ModuleManager method loadModules.

/**
 * Load the modules from the database, if not already loaded.
 *
 * @param fut
 */
private void loadModules(Handler<ExtendedAsyncResult<Void>> fut) {
    if (moduleStore == null) {
        logger.debug("No ModuleStorage to load from, starting with empty");
        fut.handle(new Success<>());
        return;
    }
    modules.size(kres -> {
        if (kres.failed()) {
            fut.handle(new Failure<>(INTERNAL, kres.cause()));
            return;
        }
        if (kres.result() > 0) {
            logger.debug("Not loading modules, looks like someone already did");
            fut.handle(new Success<>());
            return;
        }
        moduleStore.getAll(mres -> {
            if (mres.failed()) {
                fut.handle(new Failure<>(mres.getType(), mres.cause()));
                return;
            }
            CompList<Void> futures = new CompList<>(INTERNAL);
            for (ModuleDescriptor md : mres.result()) {
                Future<Void> f = Future.future();
                modules.add(md.getId(), md, f::handle);
                futures.add(f);
            }
            futures.all(fut);
        });
    });
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) CompList(org.folio.okapi.util.CompList)

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