Search in sources :

Example 1 with LeadershipAware

use of com.hortonworks.registries.common.ha.LeadershipAware in project registry by hortonworks.

the class RegistryApplication method registerResources.

private void registerResources(Environment environment, RegistryConfiguration registryConfiguration) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    storageManager = getStorageManager(registryConfiguration.getStorageProviderConfiguration());
    if (storageManager instanceof TransactionManager)
        transactionManager = (TransactionManager) storageManager;
    else
        transactionManager = new NOOPTransactionManager();
    FileStorage fileStorage = getJarStorage(registryConfiguration.getFileStorageConfiguration());
    List<ModuleConfiguration> modules = registryConfiguration.getModules();
    List<Object> resourcesToRegister = new ArrayList<>();
    for (ModuleConfiguration moduleConfiguration : modules) {
        String moduleName = moduleConfiguration.getName();
        String moduleClassName = moduleConfiguration.getClassName();
        LOG.info("Registering module [{}] with class [{}]", moduleName, moduleClassName);
        ModuleRegistration moduleRegistration = (ModuleRegistration) Class.forName(moduleClassName).newInstance();
        if (moduleConfiguration.getConfig() == null) {
            moduleConfiguration.setConfig(new HashMap<String, Object>());
        }
        moduleRegistration.init(moduleConfiguration.getConfig(), fileStorage);
        if (moduleRegistration instanceof StorageManagerAware) {
            LOG.info("Module [{}] is StorageManagerAware and setting StorageManager.", moduleName);
            StorageManagerAware storageManagerAware = (StorageManagerAware) moduleRegistration;
            storageManagerAware.setStorageManager(storageManager);
        }
        if (moduleRegistration instanceof LeadershipAware) {
            LOG.info("Module [{}] is registered for LeadershipParticipant registration.", moduleName);
            LeadershipAware leadershipAware = (LeadershipAware) moduleRegistration;
            leadershipAware.setLeadershipParticipant(leadershipParticipantRef);
        }
        if (moduleRegistration instanceof HAServersAware) {
            LOG.info("Module [{}] is registered for HAServersAware registration.");
            HAServersAware leadershipAware = (HAServersAware) moduleRegistration;
            leadershipAware.setHAServerConfigManager(haServerNotificationManager);
        }
        resourcesToRegister.addAll(moduleRegistration.getResources());
    }
    LOG.info("Registering resources to Jersey environment: [{}]", resourcesToRegister);
    for (Object resource : resourcesToRegister) {
        environment.jersey().register(resource);
    }
    environment.jersey().register(MultiPartFeature.class);
    environment.jersey().register(new TransactionEventListener(transactionManager));
}
Also used : ModuleConfiguration(com.hortonworks.registries.common.ModuleConfiguration) ArrayList(java.util.ArrayList) NOOPTransactionManager(com.hortonworks.registries.storage.NOOPTransactionManager) TransactionEventListener(com.hortonworks.registries.storage.transaction.TransactionEventListener) LeadershipAware(com.hortonworks.registries.common.ha.LeadershipAware) NOOPTransactionManager(com.hortonworks.registries.storage.NOOPTransactionManager) TransactionManager(com.hortonworks.registries.storage.TransactionManager) StorageManagerAware(com.hortonworks.registries.storage.StorageManagerAware) FileStorage(com.hortonworks.registries.common.util.FileStorage) ModuleRegistration(com.hortonworks.registries.common.ModuleRegistration) HAServersAware(com.hortonworks.registries.schemaregistry.HAServersAware)

Aggregations

ModuleConfiguration (com.hortonworks.registries.common.ModuleConfiguration)1 ModuleRegistration (com.hortonworks.registries.common.ModuleRegistration)1 LeadershipAware (com.hortonworks.registries.common.ha.LeadershipAware)1 FileStorage (com.hortonworks.registries.common.util.FileStorage)1 HAServersAware (com.hortonworks.registries.schemaregistry.HAServersAware)1 NOOPTransactionManager (com.hortonworks.registries.storage.NOOPTransactionManager)1 StorageManagerAware (com.hortonworks.registries.storage.StorageManagerAware)1 TransactionManager (com.hortonworks.registries.storage.TransactionManager)1 TransactionEventListener (com.hortonworks.registries.storage.transaction.TransactionEventListener)1 ArrayList (java.util.ArrayList)1