Search in sources :

Example 1 with MicroprofileConfigConfiguration

use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.

the class GetConfigOrdinal method execute.

@Override
public void execute(AdminCommandContext context) {
    Config configVal = targetUtil.getConfig(target);
    MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.class);
    if (serviceConfig != null) {
        Integer result = -1;
        switch(source) {
            case DOMAIN:
                {
                    result = Integer.parseInt(serviceConfig.getDomainOrdinality());
                    break;
                }
            case CONFIG:
                {
                    result = Integer.parseInt(serviceConfig.getConfigOrdinality());
                    break;
                }
            case SERVER:
                {
                    result = Integer.parseInt(serviceConfig.getServerOrdinality());
                    break;
                }
            case APPLICATION:
                {
                    result = Integer.parseInt(serviceConfig.getApplicationOrdinality());
                    break;
                }
            case MODULE:
                {
                    result = Integer.parseInt(serviceConfig.getModuleOrdinality());
                    break;
                }
            case CLUSTER:
                {
                    result = Integer.parseInt(serviceConfig.getClusterOrdinality());
                    break;
                }
            case JNDI:
                {
                    result = Integer.parseInt(serviceConfig.getJndiOrdinality());
                    break;
                }
            case SECRETS:
                {
                    result = Integer.parseInt(serviceConfig.getSecretDirOrdinality());
                    break;
                }
            case PASSWORD:
                {
                    result = Integer.parseInt(serviceConfig.getPasswordOrdinality());
                    break;
                }
            case JDBC:
                {
                    result = Integer.parseInt(serviceConfig.getJdbcOrdinality());
                    break;
                }
            case CLOUD:
                {
                    result = Integer.parseInt(serviceConfig.getCloudOrdinality());
                    break;
                }
            case LDAP:
                {
                    result = Integer.parseInt(serviceConfig.getLdapOrdinality());
                    break;
                }
        }
        context.getActionReport().setMessage(source + " : " + result.toString());
        Map<String, Object> extraPropertiesMap = new HashMap<>();
        extraPropertiesMap.put("source", source);
        extraPropertiesMap.put("ordinal", result);
        Properties extraProperties = new Properties();
        extraProperties.put("configConfiguration", extraPropertiesMap);
        context.getActionReport().setExtraProperties(extraProperties);
    } else {
        context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "No configuration with name " + target);
    }
}
Also used : MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) Properties(java.util.Properties)

Example 2 with MicroprofileConfigConfiguration

use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.

the class SetConfigCacheDuration method execute.

@Override
public void execute(AdminCommandContext context) {
    Config configVal = targetUtil.getConfig(target);
    MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.class);
    if (serviceConfig != null) {
        try {
            ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>() {

                @Override
                public Object run(MicroprofileConfigConfiguration config) {
                    config.setCacheDurationSeconds(Integer.toString(durationInSeconds));
                    return null;
                }
            }, serviceConfig);
        } catch (TransactionFailure ex) {
            // set failure
            context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "Failed to update message", ex);
        }
    } else {
        context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "No configuration with name " + target);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) Config(com.sun.enterprise.config.serverbeans.Config)

Example 3 with MicroprofileConfigConfiguration

use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.

the class SetConfigOrdinal method execute.

@Override
public void execute(AdminCommandContext context) {
    Config configVal = targetUtil.getConfig(target);
    MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.class);
    if (serviceConfig != null) {
        try {
            // to perform a transaction on the domain.xml you need to use this construct
            // see https://github.com/hk2-project/hk2/blob/master/hk2-configuration/persistence/hk2-xml-dom/hk2-config/src/main/java/org/jvnet/hk2/config/ConfigSupport.java
            ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>() {

                @Override
                public Object run(MicroprofileConfigConfiguration config) {
                    switch(source) {
                        case DOMAIN:
                            {
                                config.setDomainOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case CONFIG:
                            {
                                config.setConfigOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case SERVER:
                            {
                                config.setServerOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case APPLICATION:
                            {
                                config.setApplicationOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case MODULE:
                            {
                                config.setModuleOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case CLUSTER:
                            {
                                config.setClusterOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case JNDI:
                            {
                                config.setJndiOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case SECRETS:
                            {
                                config.setSecretDirOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case PASSWORD:
                            {
                                config.setPasswordOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case JDBC:
                            {
                                config.setJdbcOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case CLOUD:
                            {
                                config.setCloudOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case LDAP:
                            {
                                config.setLdapOrdinality(Integer.toString(ordinal));
                                break;
                            }
                    }
                    return null;
                }
            }, serviceConfig);
        } catch (TransactionFailure ex) {
            // set failure
            context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "Failed to update message", ex);
        }
    } else {
        context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "No configuration with name " + target);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) Config(com.sun.enterprise.config.serverbeans.Config)

Example 4 with MicroprofileConfigConfiguration

use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.

the class BaseGetConfigSourceConfigurationCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    // Get the command report
    final ActionReport report = context.getActionReport();
    // Get the target configuration
    final Config targetConfig = targetUtil.getConfig(target);
    if (targetConfig == null) {
        report.setMessage("No such config named: " + target);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Initialise the extra properties
    Properties extraProperties = report.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        report.setExtraProperties(extraProperties);
    }
    final MicroprofileConfigConfiguration mpConfigConfiguration = targetConfig.getExtensionByType(MicroprofileConfigConfiguration.class);
    Class<C> configSourceConfigurationClass = ConfigSourceExtensions.getConfigurationClass(getClass());
    C c = mpConfigConfiguration.getConfigSourceConfigurationByType(configSourceConfigurationClass);
    Properties extraProps = new Properties();
    extraProps.put("configSourceConfiguration", getConfigSourceProperties(c));
    if (c == null) {
        report.setMessage("ConfigSource Configuration is not defined");
    } else {
        report.setMessage(listConfiguration(c));
    }
    report.setExtraProperties(extraProps);
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Example 5 with MicroprofileConfigConfiguration

use of fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration in project Payara by payara.

the class DirConfigSourceTest method testFindDir_RelativePath.

@Test
public void testFindDir_RelativePath() throws IOException {
    // given
    System.setProperty("com.sun.aas.instanceRoot", testDirectory.toString());
    MicroprofileConfigConfiguration config = mock(MicroprofileConfigConfiguration.class);
    when(configService.getMPConfig()).thenReturn(config);
    when(config.getSecretDir()).thenReturn(".");
    // when
    Optional<Path> sut = source.findDir();
    // then
    assertEquals(testDirectory, sut.get());
}
Also used : Path(java.nio.file.Path) MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) Test(org.junit.Test)

Aggregations

MicroprofileConfigConfiguration (fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration)11 Config (com.sun.enterprise.config.serverbeans.Config)7 Path (java.nio.file.Path)5 Properties (java.util.Properties)4 Test (org.junit.Test)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 PropertyVetoException (java.beans.PropertyVetoException)2 HashMap (java.util.HashMap)2 ActionReport (org.glassfish.api.ActionReport)2