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);
}
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);
}
}
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();
});
}
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());
}
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();
});
}
Aggregations