org.wso2.carbon.config.provider.ConfigProvider Java Examples

The following examples show how to use org.wso2.carbon.config.provider.ConfigProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileBasedUserStore.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(StartupContext startupContext, Map<String, String> properties) throws Exception {
    Path usersYamlFile;
    String usersFilePath = System.getProperty(BrokerAuthConstants.SYSTEM_PARAM_USERS_CONFIG);
    if (usersFilePath == null || usersFilePath.trim().isEmpty()) {
        // use current path.
        usersYamlFile = Paths.get("", BrokerAuthConstants.USERS_FILE_NAME).toAbsolutePath();
    } else {
        usersYamlFile = Paths.get(usersFilePath).toAbsolutePath();
    }
    ConfigProvider configProvider = ConfigProviderFactory.getConfigProvider(usersYamlFile, null);
    UsersFile usersFile = configProvider
            .getConfigurationObject(BrokerAuthConstants.USERS_CONFIG_NAMESPACE, UsersFile.class);
    if (usersFile != null) {
        List<UserConfig> usersList = usersFile.getUserConfigs();
        for (UserConfig userConfig : usersList) {
            if (userConfig != null && userConfig.getUsername() != null) {
                userRegistry.put(userConfig.getUsername(), new User(userConfig.getUsername(),
                                                                    userConfig.getPassword().toCharArray(),
                                                                    new HashSet<>(userConfig.getRoles())));
            } else {
                LOGGER.error("User or username can not be null");
            }
        }
    }
}
 
Example #2
Source File: CarbonCoreComponent.java    From carbon-kernel with Apache License 2.0 6 votes vote down vote up
@Activate
public void activate() {
    try {
        logger.debug("Activating CarbonCoreComponent");

        // 1) Get config provider from data holder
        ConfigProvider configProvider = DataHolder.getInstance().getConfigProvider();

        // 2) Creates the CarbonRuntime instance using the Carbon configuration provider.
        CarbonRuntime carbonRuntime = CarbonRuntimeFactory.createCarbonRuntime(configProvider);

        // 3) Register CarbonRuntime instance as an OSGi bundle.
        DataHolder.getInstance().getBundleContext()
                .registerService(CarbonRuntime.class.getName(), carbonRuntime, null);

    } catch (Throwable throwable) {
        logger.error("Error while activating CarbonCoreComponent");
    }
}
 
Example #3
Source File: HTTPMonitoringConfigBuilder.java    From msf4j with Apache License 2.0 5 votes vote down vote up
public static HTTPMonitoringConfig build() {
    HTTPMonitoringConfig configurationObject;
    ConfigProvider configProvider = AnalyticUtils.getConfigurationProvider();

    try {
        configurationObject =
                configProvider.getConfigurationObject(HTTPMonitoringConfig.class);
    } catch (ConfigurationException e) {
        throw new RuntimeException(
                "Error while loading " + HTTPMonitoringConfig.class.getName() + " from config provider", e);
    }

    return configurationObject;
}
 
Example #4
Source File: Main.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
/**
 * Loads configurations during the broker start up.
 * method will try to <br/>
 *  (1) Load the configuration file specified in 'broker.file' (e.g. -Dbroker.file={FilePath}). <br/>
 *  (2) If -Dbroker.file is not specified, the broker.yaml file exists in current directory and load it. <br/>
 *
 * <b>Note: </b> if provided configuration file cannot be read broker will not start.
 * @param startupContext startup context of the broker
 */
private static void initConfigProvider(StartupContext startupContext) throws ConfigurationException {
    Path brokerYamlFile;
    String brokerFilePath = System.getProperty(BrokerCoreConfiguration.SYSTEM_PARAM_BROKER_CONFIG_FILE);
    if (brokerFilePath == null || brokerFilePath.trim().isEmpty()) {
        // use current path.
        brokerYamlFile = Paths.get("", BrokerCoreConfiguration.BROKER_FILE_NAME).toAbsolutePath();
    } else {
        brokerYamlFile = Paths.get(brokerFilePath).toAbsolutePath();
    }

    ConfigProvider configProvider = ConfigProviderFactory.getConfigProvider(brokerYamlFile);
    startupContext.registerService(BrokerConfigProvider.class,
                                   (BrokerConfigProvider) configProvider::getConfigurationObject);
}
 
Example #5
Source File: CarbonContextTest.java    From carbon-kernel with Apache License 2.0 5 votes vote down vote up
private void setupCarbonConfig(String tenantName) throws Exception {
    System.setProperty(org.wso2.carbon.utils.Constants.CARBON_HOME,
                       Paths.get(testDir.toString(), "carbon-context").toString());
    System.setProperty(Constants.TENANT_NAME, tenantName);
    ConfigProvider configProvider = new CarbonConfigProviderImpl();
    CarbonRuntime carbonRuntime = CarbonRuntimeFactory.createCarbonRuntime(configProvider);
}
 
Example #6
Source File: AnalyticsSC.java    From msf4j with Apache License 2.0 5 votes vote down vote up
@Reference(
        name = "carbon-config",
        service = ConfigProvider.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unregisterConfigProvider"
)
protected void registerConfigProvider(ConfigProvider configProvider) {
    DataHolder.getInstance().setConfigProvider(configProvider);
}
 
Example #7
Source File: CarbonRuntimeFactory.java    From carbon-kernel with Apache License 2.0 5 votes vote down vote up
public static CarbonRuntime createCarbonRuntime(ConfigProvider configProvider) throws Exception {

        CarbonConfiguration carbonConfiguration = configProvider.getConfigurationObject(
                        CarbonConfiguration.class);
        PrivilegedCarbonRuntime carbonRuntime = new DefaultCarbonRuntime();
        carbonRuntime.setCarbonConfiguration(carbonConfiguration);
        return carbonRuntime;
    }
 
Example #8
Source File: CarbonCoreComponent.java    From carbon-kernel with Apache License 2.0 5 votes vote down vote up
@Reference(
        name = "org.wso2.carbon.config",
        service = ConfigProvider.class,
        cardinality = ReferenceCardinality.AT_LEAST_ONE,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unregisterConfigProvider"
)
protected void registerConfigProvider(ConfigProvider configProvider) {
    DataHolder.getInstance().setConfigProvider(configProvider);
}
 
Example #9
Source File: CarbonRuntimeFactoryTest.java    From carbon-kernel with Apache License 2.0 4 votes vote down vote up
@BeforeTest
public void setup() throws Exception {
    ConfigProvider configProvider = new CarbonConfigProviderImpl();
    carbonRuntime = CarbonRuntimeFactory.createCarbonRuntime(configProvider);
}
 
Example #10
Source File: CarbonCoreComponent.java    From carbon-kernel with Apache License 2.0 4 votes vote down vote up
protected void unregisterConfigProvider(ConfigProvider configProvider) {
    DataHolder.getInstance().setConfigProvider(null);
}
 
Example #11
Source File: DataHolder.java    From msf4j with Apache License 2.0 4 votes vote down vote up
public ConfigProvider getConfigProvider() {
    return configProvider;
}
 
Example #12
Source File: DataHolder.java    From msf4j with Apache License 2.0 4 votes vote down vote up
public void setConfigProvider(ConfigProvider configProvider) {
    this.configProvider = configProvider;
}
 
Example #13
Source File: MicroservicesServerSC.java    From msf4j with Apache License 2.0 4 votes vote down vote up
protected void unregisterConfigProvider(ConfigProvider configProvider) {
    DataHolder.getInstance().setConfigProvider(null);
}
 
Example #14
Source File: MicroservicesServerSC.java    From msf4j with Apache License 2.0 4 votes vote down vote up
@Reference(
        name = "carbon.config.provider",
        service = ConfigProvider.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unregisterConfigProvider"
)
protected void registerConfigProvider(ConfigProvider configProvider) {
    DataHolder.getInstance().setConfigProvider(configProvider);
    try {
        final TransportsConfiguration transportsConfiguration;
        Object transportConf = configProvider.getConfigurationObject(STREAMLINED_TRANSPORT_NAMESPACE);
        if (transportConf != null) {
            transportsConfiguration = Utils.resolveTransportsNSConfiguration(transportConf);
        } else {
            transportsConfiguration = configProvider.getConfigurationObject
                    (MSF4JConstants.WSO2_TRANSPORT_HTTP_CONFIG_NAMESPACE, TransportsConfiguration.class);
        }

        CarbonConfiguration carbonConfig = configProvider.getConfigurationObject(CarbonConfiguration.class);
        transportsConfiguration.getListenerConfigurations().forEach(
                listenerConfiguration -> listenerConfiguration.setPort(
                        listenerConfiguration.getPort() + carbonConfig.getPortsConfig().getOffset()));

        Set<ListenerConfiguration> listenerConfigurations =
                transportsConfiguration.getListenerConfigurations();
        if (listenerConfigurations.isEmpty()) {
            listenerConfigurations = new HashSet<>();
            listenerConfigurations.add(new ListenerConfiguration());
        }

        ServerBootstrapConfiguration serverBootstrapConfiguration =
                HttpConnectorUtil.getServerBootstrapConfiguration(transportsConfiguration.getTransportProperties());
        HttpWsConnectorFactory connectorFactory = new DefaultHttpWsConnectorFactory();
        listenerConfigurations.forEach(listenerConfiguration -> {
            ServerConnector serverConnector =
                    connectorFactory.createServerConnector(serverBootstrapConfiguration, listenerConfiguration);
            MicroservicesRegistryImpl microservicesRegistry = new MicroservicesRegistryImpl();
            Map<String, MicroservicesRegistryImpl> microservicesRegistries =
                    DataHolder.getInstance().getMicroservicesRegistries();
            Dictionary<String, String> properties = new Hashtable<>();
            properties.put(MSF4JConstants.CHANNEL_ID, serverConnector.getConnectorID());
            microservicesRegistries.put(serverConnector.getConnectorID(), microservicesRegistry);
            DataHolder.getInstance().getBundleContext()
                    .registerService(MicroservicesRegistry.class, microservicesRegistry, properties);
            listenerConfigurationMap.put(serverConnector.getConnectorID(), listenerConfiguration);
            serverConnectors.add(serverConnector);
        });
    } catch (ConfigurationException e) {
        log.error("Error while loading TransportsConfiguration", e);
        throw new RuntimeException("Error while loading TransportsConfiguration", e);
    }
    StartupServiceUtils.updateServiceCache("wso2-microservices-server", ConfigProvider.class);
}
 
Example #15
Source File: AnalyticsSC.java    From msf4j with Apache License 2.0 4 votes vote down vote up
protected void unregisterConfigProvider(ConfigProvider configProvider) {
    DataHolder.getInstance().setConfigProvider(null);
}
 
Example #16
Source File: DataHolder.java    From msf4j with Apache License 2.0 4 votes vote down vote up
public void setConfigProvider(ConfigProvider configProvider) {
    this.configProvider = configProvider;
}
 
Example #17
Source File: DataHolder.java    From msf4j with Apache License 2.0 4 votes vote down vote up
public ConfigProvider getConfigProvider() {
    return configProvider;
}
 
Example #18
Source File: DataHolder.java    From carbon-kernel with Apache License 2.0 2 votes vote down vote up
/**
 * Getter method of ${@link ConfigProvider}.
 *
 * @return configProvider
 */
public ConfigProvider getConfigProvider() {
    return configProvider;
}
 
Example #19
Source File: DataHolder.java    From carbon-kernel with Apache License 2.0 2 votes vote down vote up
/**
 * Setter method of ${@link ConfigProvider}.
 *
 * @param configProvider configuration provider object
 */
public void setConfigProvider(ConfigProvider configProvider) {
    this.configProvider = configProvider;
}