Search in sources :

Example 1 with Storage

use of org.folio.inventory.storage.Storage in project mod-inventory by folio-org.

the class InventoryVerticle method start.

@Override
public void start(Promise<Void> started) {
    Logging.initialiseFormat();
    final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass());
    Router router = Router.router(vertx);
    server = vertx.createHttpServer();
    JsonObject config = vertx.getOrCreateContext().config();
    log.info("Received Config");
    config.fieldNames().forEach(key -> log.info(String.format("%s:%s", key, config.getValue(key).toString())));
    HttpClient client = vertx.createHttpClient();
    Storage storage = Storage.basedUpon(vertx, config, client);
    new IngestMessageProcessor(storage).register(vertx.eventBus());
    router.route().handler(WebRequestDiagnostics::outputDiagnostics);
    new ModsIngestion(storage, client).register(router);
    new Items(storage, client).register(router);
    new MoveApi(storage, client).register(router);
    new Instances(storage, client).register(router);
    new Holdings(storage).register(router);
    new InstancesBatch(storage, client).register(router);
    new IsbnUtilsApi().register(router);
    new ItemsByHoldingsRecordId(storage, client).register(router);
    new InventoryConfigApi().register(router);
    new TenantApi().register(router);
    Handler<AsyncResult<HttpServer>> onHttpServerStart = result -> {
        if (result.succeeded()) {
            log.info(String.format("Listening on %s", server.actualPort()));
            started.complete();
        } else {
            started.fail(result.cause());
        }
    };
    server.requestHandler(router).listen(config.getInteger("port"), onHttpServerStart);
}
Also used : WebRequestDiagnostics(org.folio.inventory.common.WebRequestDiagnostics) PostgresClientFactory(org.folio.inventory.common.dao.PostgresClientFactory) HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router) InstancesBatch(org.folio.inventory.resources.InstancesBatch) TenantApi(org.folio.inventory.resources.TenantApi) Instances(org.folio.inventory.resources.Instances) IsbnUtilsApi(org.folio.inventory.resources.IsbnUtilsApi) Holdings(org.folio.inventory.resources.Holdings) Items(org.folio.inventory.resources.Items) JsonObject(io.vertx.core.json.JsonObject) ModsIngestion(org.folio.inventory.resources.ingest.ModsIngestion) AsyncResult(io.vertx.core.AsyncResult) MoveApi(org.folio.inventory.resources.MoveApi) Promise(io.vertx.core.Promise) MethodHandles(java.lang.invoke.MethodHandles) ItemsByHoldingsRecordId(org.folio.inventory.resources.ItemsByHoldingsRecordId) InventoryConfigApi(org.folio.inventory.resources.InventoryConfigApi) Storage(org.folio.inventory.storage.Storage) Logger(org.apache.logging.log4j.Logger) AbstractVerticle(io.vertx.core.AbstractVerticle) IngestMessageProcessor(org.folio.inventory.domain.ingest.IngestMessageProcessor) Handler(io.vertx.core.Handler) LogManager(org.apache.logging.log4j.LogManager) HttpClient(io.vertx.core.http.HttpClient) Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject) ItemsByHoldingsRecordId(org.folio.inventory.resources.ItemsByHoldingsRecordId) WebRequestDiagnostics(org.folio.inventory.common.WebRequestDiagnostics) IsbnUtilsApi(org.folio.inventory.resources.IsbnUtilsApi) Logger(org.apache.logging.log4j.Logger) IngestMessageProcessor(org.folio.inventory.domain.ingest.IngestMessageProcessor) Instances(org.folio.inventory.resources.Instances) InstancesBatch(org.folio.inventory.resources.InstancesBatch) TenantApi(org.folio.inventory.resources.TenantApi) Storage(org.folio.inventory.storage.Storage) Holdings(org.folio.inventory.resources.Holdings) HttpClient(io.vertx.core.http.HttpClient) Items(org.folio.inventory.resources.Items) ModsIngestion(org.folio.inventory.resources.ingest.ModsIngestion) AsyncResult(io.vertx.core.AsyncResult) MoveApi(org.folio.inventory.resources.MoveApi) InventoryConfigApi(org.folio.inventory.resources.InventoryConfigApi)

Example 2 with Storage

use of org.folio.inventory.storage.Storage in project mod-inventory by folio-org.

the class InstancesBatch method updateRelatedRecords.

/**
 * Updates relationships for specified created instances.
 *
 * @param newInstances     the new instances containing relationship arrays to persist.
 * @param createdInstances instances from storage whose relationships will be updated.
 * @param routingContext   routingContext
 * @param webContext       webContext
 */
private Future<CompositeFuture> updateRelatedRecords(List<JsonObject> newInstances, List<Instance> createdInstances, RoutingContext routingContext, WebContext webContext) {
    try {
        Map<String, Instance> mapInstanceById = newInstances.stream().collect(Collectors.toMap(instance -> instance.getString("id"), Instance::fromJson));
        List<Future> updateRelationshipsFutures = new ArrayList<>();
        for (Instance createdInstance : createdInstances) {
            Instance newInstance = mapInstanceById.get(createdInstance.getId());
            if (newInstance != null) {
                createdInstance.setParentInstances(newInstance.getParentInstances());
                createdInstance.setChildInstances(newInstance.getChildInstances());
                createdInstance.setPrecedingTitles(newInstance.getPrecedingTitles());
                createdInstance.setSucceedingTitles(newInstance.getSucceedingTitles());
                Promise<Void> updatePromise = Promise.promise();
                updateRelationshipsFutures.add(updatePromise.future());
                updateRelatedRecords(routingContext, webContext, createdInstance).whenComplete((result, ex) -> {
                    if (ex == null) {
                        updatePromise.complete();
                    } else {
                        log.warn("Exception occurred", ex);
                        handleFailure(getKnownException(ex), routingContext);
                    }
                });
            }
        }
        return CompositeFuture.join(updateRelationshipsFutures);
    } catch (IllegalStateException e) {
        log.error("Can not update instances relationships cause: " + e);
        return Future.failedFuture(e);
    }
}
Also used : WebContext(org.folio.inventory.common.WebContext) InstancePrecedingSucceedingTitleValidators.isTitleMissingForUnconnectedPrecedingSucceeding(org.folio.inventory.validation.InstancePrecedingSucceedingTitleValidators.isTitleMissingForUnconnectedPrecedingSucceeding) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) StringUtils(org.apache.commons.lang3.StringUtils) EndpointFailureHandler.handleFailure(org.folio.inventory.support.EndpointFailureHandler.handleFailure) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) JsonArrayHelper.toList(org.folio.inventory.support.JsonArrayHelper.toList) EndpointFailureHandler.getKnownException(org.folio.inventory.support.EndpointFailureHandler.getKnownException) RedirectResponse(org.folio.inventory.support.http.server.RedirectResponse) Promise(io.vertx.core.Promise) BatchResult(org.folio.inventory.domain.BatchResult) UUID(java.util.UUID) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) PrecedingSucceedingTitle(org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle) Storage(org.folio.inventory.storage.Storage) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) Instance(org.folio.inventory.domain.instances.Instance) HttpClient(io.vertx.core.http.HttpClient) Instance(org.folio.inventory.domain.instances.Instance) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future)

Example 3 with Storage

use of org.folio.inventory.storage.Storage in project mod-inventory by folio-org.

the class DataImportConsumerVerticle method start.

@Override
public void start(Promise<Void> startPromise) {
    JsonObject config = vertx.getOrCreateContext().config();
    KafkaConfig kafkaConfig = KafkaConfig.builder().envId(config.getString(KAFKA_ENV)).kafkaHost(config.getString(KAFKA_HOST)).kafkaPort(config.getString(KAFKA_PORT)).okapiUrl(config.getString(OKAPI_URL)).replicationFactor(Integer.parseInt(config.getString(KAFKA_REPLICATION_FACTOR))).maxRequestSize(Integer.parseInt(config.getString(KAFKA_MAX_REQUEST_SIZE))).build();
    LOGGER.info(format("kafkaConfig: %s", kafkaConfig));
    EventManager.registerKafkaEventPublisher(kafkaConfig, vertx, maxDistributionNumber);
    HttpClientOptions params = new HttpClientOptions().setConnectTimeout(DEFAULT_HTTP_TIMEOUT_IN_MILLISECONDS);
    HttpClient client = vertx.createHttpClient(params);
    Storage storage = Storage.basedUpon(vertx, config, client);
    String profileSnapshotExpirationTime = getCacheEnvVariable(config, "inventory.profile-snapshot-cache.expiration.time.seconds");
    String mappingMetadataExpirationTime = getCacheEnvVariable(config, "inventory.mapping-metadata-cache.expiration.time.seconds");
    ProfileSnapshotCache profileSnapshotCache = new ProfileSnapshotCache(vertx, client, Long.parseLong(profileSnapshotExpirationTime));
    MappingMetadataCache mappingMetadataCache = new MappingMetadataCache(vertx, client, Long.parseLong(mappingMetadataExpirationTime));
    DataImportKafkaHandler dataImportKafkaHandler = new DataImportKafkaHandler(vertx, storage, client, profileSnapshotCache, kafkaConfig, mappingMetadataCache);
    List<Future> futures = EVENT_TYPES.stream().map(eventType -> createKafkaConsumerWrapper(kafkaConfig, eventType, dataImportKafkaHandler)).collect(Collectors.toList());
    CompositeFuture.all(futures).onFailure(startPromise::fail).onSuccess(ar -> {
        futures.forEach(future -> consumerWrappers.add((KafkaConsumerWrapper<String, String>) future.result()));
        startPromise.complete();
    });
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) DI_SRS_MARC_BIB_RECORD_NOT_MATCHED(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_NOT_MATCHED) DI_SRS_MARC_AUTHORITY_RECORD_MODIFIED_READY_FOR_POST_PROCESSING(org.folio.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_MODIFIED_READY_FOR_POST_PROCESSING) DI_INVENTORY_INSTANCE_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_MATCHED) DI_SRS_MARC_BIB_RECORD_MATCHED_READY_FOR_POST_PROCESSING(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MATCHED_READY_FOR_POST_PROCESSING) JsonObject(io.vertx.core.json.JsonObject) EventManager(org.folio.processing.events.EventManager) ProfileSnapshotCache(org.folio.inventory.dataimport.cache.ProfileSnapshotCache) DI_INVENTORY_INSTANCE_UPDATED(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_UPDATED) DI_INVENTORY_ITEM_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_ITEM_MATCHED) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) String.format(java.lang.String.format) DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED(org.folio.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED) Storage(org.folio.inventory.storage.Storage) List(java.util.List) SubscriptionDefinition(org.folio.kafka.SubscriptionDefinition) Logger(org.apache.logging.log4j.Logger) DI_INVENTORY_INSTANCE_CREATED(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_CREATED) AbstractVerticle(io.vertx.core.AbstractVerticle) KAFKA_REPLICATION_FACTOR(org.folio.inventory.dataimport.util.KafkaConfigConstants.KAFKA_REPLICATION_FACTOR) DI_SRS_MARC_AUTHORITY_RECORD_CREATED(org.folio.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_CREATED) DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING) ConsumerWrapperUtil(org.folio.inventory.dataimport.util.ConsumerWrapperUtil) HttpClient(io.vertx.core.http.HttpClient) KAFKA_MAX_REQUEST_SIZE(org.folio.inventory.dataimport.util.KafkaConfigConstants.KAFKA_MAX_REQUEST_SIZE) DataImportEventTypes(org.folio.DataImportEventTypes) DI_INVENTORY_HOLDING_CREATED(org.folio.DataImportEventTypes.DI_INVENTORY_HOLDING_CREATED) KafkaConsumerWrapper(org.folio.kafka.KafkaConsumerWrapper) DI_INVENTORY_HOLDING_NOT_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_HOLDING_NOT_MATCHED) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) GlobalLoadSensor(org.folio.kafka.GlobalLoadSensor) DI_INVENTORY_ITEM_CREATED(org.folio.DataImportEventTypes.DI_INVENTORY_ITEM_CREATED) KAFKA_PORT(org.folio.inventory.dataimport.util.KafkaConfigConstants.KAFKA_PORT) KafkaTopicNameHelper(org.folio.kafka.KafkaTopicNameHelper) HttpClientOptions(io.vertx.core.http.HttpClientOptions) DI_SRS_MARC_HOLDING_RECORD_CREATED(org.folio.DataImportEventTypes.DI_SRS_MARC_HOLDING_RECORD_CREATED) Promise(io.vertx.core.Promise) DI_INVENTORY_HOLDING_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_HOLDING_MATCHED) KAFKA_ENV(org.folio.inventory.dataimport.util.KafkaConfigConstants.KAFKA_ENV) DI_SRS_MARC_BIB_RECORD_CREATED(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_CREATED) AsyncRecordHandler(org.folio.kafka.AsyncRecordHandler) DI_INVENTORY_HOLDING_UPDATED(org.folio.DataImportEventTypes.DI_INVENTORY_HOLDING_UPDATED) DI_SRS_MARC_AUTHORITY_RECORD_DELETED(org.folio.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_DELETED) DI_INVENTORY_INSTANCE_NOT_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_NOT_MATCHED) DI_SRS_MARC_BIB_RECORD_MODIFIED(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MODIFIED) DI_INVENTORY_ITEM_NOT_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_ITEM_NOT_MATCHED) DI_SRS_MARC_BIB_RECORD_MATCHED(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MATCHED) LogManager(org.apache.logging.log4j.LogManager) KAFKA_HOST(org.folio.inventory.dataimport.util.KafkaConfigConstants.KAFKA_HOST) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) KafkaConfig(org.folio.kafka.KafkaConfig) OKAPI_URL(org.folio.inventory.dataimport.util.KafkaConfigConstants.OKAPI_URL) DataImportKafkaHandler(org.folio.inventory.dataimport.consumers.DataImportKafkaHandler) KafkaConsumerWrapper(org.folio.kafka.KafkaConsumerWrapper) JsonObject(io.vertx.core.json.JsonObject) ProfileSnapshotCache(org.folio.inventory.dataimport.cache.ProfileSnapshotCache) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Storage(org.folio.inventory.storage.Storage) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) HttpClient(io.vertx.core.http.HttpClient) Future(io.vertx.core.Future) CompositeFuture(io.vertx.core.CompositeFuture) DataImportKafkaHandler(org.folio.inventory.dataimport.consumers.DataImportKafkaHandler) KafkaConfig(org.folio.kafka.KafkaConfig)

Example 4 with Storage

use of org.folio.inventory.storage.Storage in project mod-inventory by folio-org.

the class MarcHridSetConsumerVerticle method start.

@Override
public void start(Promise<Void> startPromise) {
    JsonObject config = vertx.getOrCreateContext().config();
    KafkaConfig kafkaConfig = KafkaConfig.builder().envId(config.getString(KAFKA_ENV)).kafkaHost(config.getString(KAFKA_HOST)).kafkaPort(config.getString(KAFKA_PORT)).okapiUrl(config.getString(OKAPI_URL)).replicationFactor(Integer.parseInt(config.getString(KAFKA_REPLICATION_FACTOR))).maxRequestSize(Integer.parseInt(config.getString(KAFKA_MAX_REQUEST_SIZE))).build();
    LOGGER.info("kafkaConfig: {}", kafkaConfig);
    marcBibConsumerWrapper = createConsumerByEvent(kafkaConfig, DI_SRS_MARC_BIB_INSTANCE_HRID_SET);
    marcHoldingsConsumerWrapper = createConsumerByEvent(kafkaConfig, DI_SRS_MARC_HOLDINGS_HOLDING_HRID_SET);
    HttpClient client = vertx.createHttpClient();
    Storage storage = Storage.basedUpon(vertx, config, client);
    InstanceUpdateDelegate instanceUpdateDelegate = new InstanceUpdateDelegate(storage);
    HoldingsUpdateDelegate holdingsRecordUpdateDelegate = new HoldingsUpdateDelegate(storage);
    String mappingMetadataExpirationTime = getCacheEnvVariable(config, "inventory.mapping-metadata-cache.expiration.time.seconds");
    MappingMetadataCache mappingMetadataCache = new MappingMetadataCache(vertx, client, Long.parseLong(mappingMetadataExpirationTime));
    MarcBibInstanceHridSetKafkaHandler marcBibInstanceHridSetKafkaHandler = new MarcBibInstanceHridSetKafkaHandler(instanceUpdateDelegate, mappingMetadataCache);
    MarcHoldingsRecordHridSetKafkaHandler marcHoldingsRecordHridSetKafkaHandler = new MarcHoldingsRecordHridSetKafkaHandler(holdingsRecordUpdateDelegate, mappingMetadataCache);
    CompositeFuture.all(marcBibConsumerWrapper.start(marcBibInstanceHridSetKafkaHandler, constructModuleName()), marcHoldingsConsumerWrapper.start(marcHoldingsRecordHridSetKafkaHandler, constructModuleName())).onFailure(startPromise::fail).onSuccess(ar -> startPromise.complete());
}
Also used : MarcBibInstanceHridSetKafkaHandler(org.folio.inventory.dataimport.consumers.MarcBibInstanceHridSetKafkaHandler) Storage(org.folio.inventory.storage.Storage) MarcHoldingsRecordHridSetKafkaHandler(org.folio.inventory.dataimport.consumers.MarcHoldingsRecordHridSetKafkaHandler) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) HttpClient(io.vertx.core.http.HttpClient) InstanceUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate) JsonObject(io.vertx.core.json.JsonObject) HoldingsUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate) KafkaConfig(org.folio.kafka.KafkaConfig)

Example 5 with Storage

use of org.folio.inventory.storage.Storage in project mod-inventory by folio-org.

the class QuickMarcConsumerVerticle method start.

@Override
public void start(Promise<Void> startPromise) {
    JsonObject config = vertx.getOrCreateContext().config();
    KafkaConfig kafkaConfig = getKafkaConfig(config);
    HttpClient client = vertx.createHttpClient();
    Storage storage = Storage.basedUpon(vertx, config, client);
    var precedingSucceedingTitlesHelper = new PrecedingSucceedingTitlesHelper(WebClient.wrap(client));
    var handler = new QuickMarcKafkaHandler(vertx, storage, maxDistributionNumber, kafkaConfig, precedingSucceedingTitlesHelper);
    var kafkaConsumerFuture = createKafkaConsumer(kafkaConfig, QMEventTypes.QM_SRS_MARC_RECORD_UPDATED, handler);
    kafkaConsumerFuture.onFailure(startPromise::fail).onSuccess(ar -> {
        consumer = ar;
        startPromise.complete();
    });
}
Also used : Storage(org.folio.inventory.storage.Storage) HttpClient(io.vertx.core.http.HttpClient) PrecedingSucceedingTitlesHelper(org.folio.inventory.dataimport.handlers.actions.PrecedingSucceedingTitlesHelper) QuickMarcKafkaHandler(org.folio.inventory.dataimport.consumers.QuickMarcKafkaHandler) JsonObject(io.vertx.core.json.JsonObject) KafkaConfig(org.folio.kafka.KafkaConfig)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)5 JsonObject (io.vertx.core.json.JsonObject)5 Storage (org.folio.inventory.storage.Storage)5 Promise (io.vertx.core.Promise)3 KafkaConfig (org.folio.kafka.KafkaConfig)3 AbstractVerticle (io.vertx.core.AbstractVerticle)2 CompositeFuture (io.vertx.core.CompositeFuture)2 Future (io.vertx.core.Future)2 Router (io.vertx.ext.web.Router)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 MappingMetadataCache (org.folio.inventory.dataimport.cache.MappingMetadataCache)2 AsyncResult (io.vertx.core.AsyncResult)1 Handler (io.vertx.core.Handler)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1