Search in sources :

Example 1 with IndexOptions

use of io.vertx.ext.mongo.IndexOptions in project hono by eclipse.

the class MongoDbBasedDeviceDao method createIndices.

/**
 * Creates the indices in the MongoDB that can be used to make querying of data more efficient.
 *
 * @return A succeeded future if the indices have been created. Otherwise, a failed future.
 */
public Future<Void> createIndices() {
    final Promise<Void> result = Promise.promise();
    if (creatingIndices.compareAndSet(false, true)) {
        // create unique index on device ID
        return createIndex(new JsonObject().put(DeviceDto.FIELD_TENANT_ID, 1).put(DeviceDto.FIELD_DEVICE_ID, 1), new IndexOptions().unique(true)).onSuccess(ok -> indicesCreated.set(true)).onComplete(r -> {
            creatingIndices.set(false);
            result.handle(r);
        });
    } else {
        LOG.debug("already trying to create indices");
    }
    return result.future();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Filter(org.eclipse.hono.service.management.Filter) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientErrorException(org.eclipse.hono.client.ClientErrorException) Status(io.vertx.ext.healthchecks.Status) Sort(org.eclipse.hono.service.management.Sort) HealthCheckHandler(io.vertx.ext.healthchecks.HealthCheckHandler) HealthCheckProvider(org.eclipse.hono.service.HealthCheckProvider) SearchResult(org.eclipse.hono.service.management.SearchResult) References(io.opentracing.References) JsonObject(io.vertx.core.json.JsonObject) TracingHelper(org.eclipse.hono.tracing.TracingHelper) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) DeviceWithId(org.eclipse.hono.service.management.device.DeviceWithId) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) Promise(io.vertx.core.Promise) Set(java.util.Set) MongoClient(io.vertx.ext.mongo.MongoClient) RegistrationConstants(org.eclipse.hono.util.RegistrationConstants) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) DeviceDto(org.eclipse.hono.service.management.device.DeviceDto) Future(io.vertx.core.Future) SpanContext(io.opentracing.SpanContext) Objects(java.util.Objects) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) IndexOptions(io.vertx.ext.mongo.IndexOptions) Optional(java.util.Optional) Span(io.opentracing.Span) FindOptions(io.vertx.ext.mongo.FindOptions) UpdateOptions(io.vertx.ext.mongo.UpdateOptions) MongoDbDocumentBuilder(org.eclipse.hono.deviceregistry.mongodb.utils.MongoDbDocumentBuilder) IndexOptions(io.vertx.ext.mongo.IndexOptions) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with IndexOptions

use of io.vertx.ext.mongo.IndexOptions in project hono by eclipse.

the class MongoDbBasedTenantDao method createIndices.

/**
 * Creates the indices in the MongoDB that can be used to make querying of data more efficient.
 *
 * @return A succeeded future if the indices have been created. Otherwise, a failed future.
 */
public Future<Void> createIndices() {
    final Promise<Void> result = Promise.promise();
    if (creatingIndices.compareAndSet(false, true)) {
        final String trustedCaField = TenantDto.FIELD_TENANT + "." + RegistryManagementConstants.FIELD_PAYLOAD_TRUSTED_CA;
        // create unique index on tenant ID
        return createIndex(new JsonObject().put(RegistryManagementConstants.FIELD_PAYLOAD_TENANT_ID, 1), new IndexOptions().unique(true)).compose(ok -> {
            final String aliasField = TenantDto.FIELD_TENANT + "." + RegistryManagementConstants.FIELD_ALIAS;
            return createIndex(new JsonObject().put(aliasField, 1), new IndexOptions().unique(true).partialFilterExpression(new JsonObject().put(aliasField, new JsonObject().put("$exists", true))));
        }).compose(ok -> {
            return createIndex(new JsonObject().put(RegistryManagementConstants.FIELD_PAYLOAD_TENANT_ID, 1).put(TenantDto.FIELD_TENANT + "." + RegistryManagementConstants.FIELD_TRUST_ANCHOR_GROUP, 1).put(trustedCaField + "." + RegistryManagementConstants.FIELD_PAYLOAD_SUBJECT_DN, 1), new IndexOptions().partialFilterExpression(new JsonObject().put(trustedCaField, new JsonObject().put("$exists", true))));
        }).compose(ok -> dropIndex(new JsonObject().put(trustedCaField + "." + RegistryManagementConstants.FIELD_PAYLOAD_SUBJECT_DN, 1), new IndexOptions().unique(true).partialFilterExpression(new JsonObject().put(trustedCaField, new JsonObject().put("$exists", true))))).onSuccess(ok -> indicesCreated.set(true)).onComplete(r -> {
            creatingIndices.set(false);
            result.handle(r);
        });
    } else {
        LOG.debug("already trying to create indices");
    }
    return result.future();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) X500Principal(javax.security.auth.x500.X500Principal) Filter(org.eclipse.hono.service.management.Filter) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientErrorException(org.eclipse.hono.client.ClientErrorException) Constants(org.eclipse.hono.util.Constants) Tenant(org.eclipse.hono.service.management.tenant.Tenant) ArrayList(java.util.ArrayList) Status(io.vertx.ext.healthchecks.Status) Sort(org.eclipse.hono.service.management.Sort) HealthCheckHandler(io.vertx.ext.healthchecks.HealthCheckHandler) HealthCheckProvider(org.eclipse.hono.service.HealthCheckProvider) SearchResult(org.eclipse.hono.service.management.SearchResult) References(io.opentracing.References) JsonObject(io.vertx.core.json.JsonObject) TracingHelper(org.eclipse.hono.tracing.TracingHelper) TenantDto(org.eclipse.hono.service.management.tenant.TenantDto) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) Promise(io.vertx.core.Promise) TenantWithId(org.eclipse.hono.service.management.tenant.TenantWithId) MongoClient(io.vertx.ext.mongo.MongoClient) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) SpanContext(io.opentracing.SpanContext) Objects(java.util.Objects) List(java.util.List) IndexOptions(io.vertx.ext.mongo.IndexOptions) Optional(java.util.Optional) Span(io.opentracing.Span) FindOptions(io.vertx.ext.mongo.FindOptions) UpdateOptions(io.vertx.ext.mongo.UpdateOptions) MongoDbDocumentBuilder(org.eclipse.hono.deviceregistry.mongodb.utils.MongoDbDocumentBuilder) IndexOptions(io.vertx.ext.mongo.IndexOptions) JsonObject(io.vertx.core.json.JsonObject)

Example 3 with IndexOptions

use of io.vertx.ext.mongo.IndexOptions in project hono by eclipse.

the class MongoDbBasedCredentialsDao method createIndices.

/**
 * Creates the indices in the MongoDB that can be used to make querying of data more efficient.
 *
 * @return A succeeded future if the indices have been created. Otherwise, a failed future.
 */
public Future<Void> createIndices() {
    final Promise<Void> result = Promise.promise();
    if (creatingIndices.compareAndSet(false, true)) {
        // create unique index on tenant and device ID
        createIndex(new JsonObject().put(RegistryManagementConstants.FIELD_PAYLOAD_TENANT_ID, 1).put(RegistryManagementConstants.FIELD_PAYLOAD_DEVICE_ID, 1), new IndexOptions().unique(true)).compose(ok -> createIndex(new JsonObject().put(RegistryManagementConstants.FIELD_PAYLOAD_TENANT_ID, 1).put(KEY_AUTH_ID, 1).put(KEY_CREDENTIALS_TYPE, 1), new IndexOptions().unique(true).partialFilterExpression(new JsonObject().put(KEY_AUTH_ID, new JsonObject().put("$exists", true)).put(KEY_CREDENTIALS_TYPE, new JsonObject().put("$exists", true))))).compose(ok -> createIndex(new JsonObject().put(KEY_AUTH_ID, 1).put(KEY_CREDENTIALS_TYPE, 1), new IndexOptions().name(IDX_CREDENTIALS_TYPE_AND_AUTH_ID))).onSuccess(ok -> indicesCreated.set(true)).onComplete(r -> {
            creatingIndices.set(false);
            result.handle(r);
        });
    } else {
        LOG.debug("already trying to create indices");
    }
    return result.future();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientErrorException(org.eclipse.hono.client.ClientErrorException) Status(io.vertx.ext.healthchecks.Status) FieldLevelEncryption(org.eclipse.hono.deviceregistry.util.FieldLevelEncryption) HealthCheckHandler(io.vertx.ext.healthchecks.HealthCheckHandler) HealthCheckProvider(org.eclipse.hono.service.HealthCheckProvider) References(io.opentracing.References) JsonObject(io.vertx.core.json.JsonObject) TracingHelper(org.eclipse.hono.tracing.TracingHelper) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) Promise(io.vertx.core.Promise) MongoClient(io.vertx.ext.mongo.MongoClient) UUID(java.util.UUID) Future(io.vertx.core.Future) SpanContext(io.opentracing.SpanContext) Objects(java.util.Objects) CredentialsDto(org.eclipse.hono.service.management.credentials.CredentialsDto) IndexOptions(io.vertx.ext.mongo.IndexOptions) Optional(java.util.Optional) Span(io.opentracing.Span) FindOptions(io.vertx.ext.mongo.FindOptions) UpdateOptions(io.vertx.ext.mongo.UpdateOptions) MongoDbDocumentBuilder(org.eclipse.hono.deviceregistry.mongodb.utils.MongoDbDocumentBuilder) IndexOptions(io.vertx.ext.mongo.IndexOptions) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

References (io.opentracing.References)3 Span (io.opentracing.Span)3 SpanContext (io.opentracing.SpanContext)3 Tracer (io.opentracing.Tracer)3 Future (io.vertx.core.Future)3 Promise (io.vertx.core.Promise)3 JsonObject (io.vertx.core.json.JsonObject)3 HealthCheckHandler (io.vertx.ext.healthchecks.HealthCheckHandler)3 Status (io.vertx.ext.healthchecks.Status)3 FindOptions (io.vertx.ext.mongo.FindOptions)3 IndexOptions (io.vertx.ext.mongo.IndexOptions)3 MongoClient (io.vertx.ext.mongo.MongoClient)3 UpdateOptions (io.vertx.ext.mongo.UpdateOptions)3 HttpURLConnection (java.net.HttpURLConnection)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 UUID (java.util.UUID)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ClientErrorException (org.eclipse.hono.client.ClientErrorException)3 MongoDbDocumentBuilder (org.eclipse.hono.deviceregistry.mongodb.utils.MongoDbDocumentBuilder)3