Search in sources :

Example 1 with HashModule

use of com.instaclustr.esop.impl.hash.HashModule in project esop by instaclustr.

the class Esop method init.

static void init(final Runnable command, final CassandraJMXSpec jmxSpec, final HashSpec hashSpec, final OperationRequest operationRequest, final Logger logger, final List<Module> appSpecificModules) {
    final List<Module> modules = new ArrayList<>();
    if (jmxSpec != null) {
        modules.add(new CassandraModule(new CassandraJMXConnectionInfo(jmxSpec)));
    } else {
        modules.add(new AbstractModule() {

            @Override
            protected void configure() {
                bind(StorageServiceMBean.class).toProvider(() -> null);
                bind(Cassandra4StorageServiceMBean.class).toProvider(() -> null);
            }
        });
    }
    modules.add(new JacksonModule());
    modules.add(new OperationsModule());
    modules.add(new StorageModules());
    modules.add(new ExecutorsModule());
    modules.add(new UploadingModule());
    modules.add(new DownloadingModule());
    modules.add(new HashModule(hashSpec));
    modules.addAll(appSpecificModules);
    final Injector injector = Guice.createInjector(// production binds singletons as eager by default
    Stage.PRODUCTION, modules);
    GuiceInjectorHolder.INSTANCE.setInjector(injector);
    injector.injectMembers(command);
    final Validator validator = Validation.byDefaultProvider().configure().constraintValidatorFactory(new GuiceInjectingConstraintValidatorFactory()).buildValidatorFactory().getValidator();
    final Set<ConstraintViolation<OperationRequest>> violations = validator.validate(operationRequest);
    if (!violations.isEmpty()) {
        violations.forEach(violation -> logger.error(violation.getMessage()));
        throw new ValidationException();
    }
}
Also used : UploadingModule(com.instaclustr.esop.impl.backup.BackupModules.UploadingModule) ValidationException(javax.validation.ValidationException) ArrayList(java.util.ArrayList) JacksonModule(com.instaclustr.jackson.JacksonModule) OperationsModule(com.instaclustr.operations.OperationsModule) AbstractModule(com.google.inject.AbstractModule) HashModule(com.instaclustr.esop.impl.hash.HashModule) CassandraModule(com.instaclustr.cassandra.CassandraModule) CassandraJMXConnectionInfo(jmx.org.apache.cassandra.CassandraJMXConnectionInfo) DownloadingModule(com.instaclustr.esop.impl.restore.RestoreModules.DownloadingModule) StorageModules(com.instaclustr.esop.guice.StorageModules) ExecutorsModule(com.instaclustr.threading.ExecutorsModule) Injector(com.google.inject.Injector) ConstraintViolation(javax.validation.ConstraintViolation) OperationsModule(com.instaclustr.operations.OperationsModule) Module(com.google.inject.Module) HashModule(com.instaclustr.esop.impl.hash.HashModule) UploadingModule(com.instaclustr.esop.impl.backup.BackupModules.UploadingModule) CassandraModule(com.instaclustr.cassandra.CassandraModule) ExecutorsModule(com.instaclustr.threading.ExecutorsModule) DownloadingModule(com.instaclustr.esop.impl.restore.RestoreModules.DownloadingModule) JacksonModule(com.instaclustr.jackson.JacksonModule) AbstractModule(com.google.inject.AbstractModule) GuiceInjectingConstraintValidatorFactory(com.instaclustr.validation.GuiceInjectingConstraintValidatorFactory) Validator(javax.validation.Validator)

Aggregations

AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 CassandraModule (com.instaclustr.cassandra.CassandraModule)1 StorageModules (com.instaclustr.esop.guice.StorageModules)1 UploadingModule (com.instaclustr.esop.impl.backup.BackupModules.UploadingModule)1 HashModule (com.instaclustr.esop.impl.hash.HashModule)1 DownloadingModule (com.instaclustr.esop.impl.restore.RestoreModules.DownloadingModule)1 JacksonModule (com.instaclustr.jackson.JacksonModule)1 OperationsModule (com.instaclustr.operations.OperationsModule)1 ExecutorsModule (com.instaclustr.threading.ExecutorsModule)1 GuiceInjectingConstraintValidatorFactory (com.instaclustr.validation.GuiceInjectingConstraintValidatorFactory)1 ArrayList (java.util.ArrayList)1 ConstraintViolation (javax.validation.ConstraintViolation)1 ValidationException (javax.validation.ValidationException)1 Validator (javax.validation.Validator)1 CassandraJMXConnectionInfo (jmx.org.apache.cassandra.CassandraJMXConnectionInfo)1