Search in sources :

Example 61 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class ServerConfigSource method getProperties.

@Override
public Map<String, String> getProperties() {
    Server config = domainConfiguration.getServerNamed(configurationName);
    HashMap<String, String> result = new HashMap<>();
    if (config != null) {
        List<Property> properties = config.getProperty();
        for (Property property : properties) {
            if (property.getName().startsWith(PROPERTY_PREFIX)) {
                result.put(property.getName().substring(PROPERTY_PREFIX.length()), property.getValue());
            }
        }
    }
    return result;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) HashMap(java.util.HashMap) Property(org.jvnet.hk2.config.types.Property)

Example 62 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class ServerConfigSource method deleteValue.

public boolean deleteValue(String propertyName) throws TransactionFailure {
    boolean result = false;
    Server config = domainConfiguration.getServerNamed(configurationName);
    if (config != null) {
        for (Property object : config.getProperty()) {
            if ((PROPERTY_PREFIX + propertyName).equals(object.getName())) {
                ConfigSupport.deleteChild((ConfigBean) ConfigBean.unwrap(config), (ConfigBean) ConfigBean.unwrap(object));
                result = true;
            }
        }
    }
    return result;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Property(org.jvnet.hk2.config.types.Property)

Example 63 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class ServerConfigSource method setValue.

public boolean setValue(final String propertyName, final String propertyValue) throws TransactionFailure {
    boolean result = false;
    Server config = domainConfiguration.getServerNamed(configurationName);
    if (config != null) {
        Property p = config.getProperty(PROPERTY_PREFIX + propertyName);
        if (p == null) {
            ConfigSupport.apply(new SingleConfigCode<Server>() {

                @Override
                public Object run(Server configuration) throws TransactionFailure, PropertyVetoException {
                    Property prop = configuration.createChild(Property.class);
                    prop.setName(PROPERTY_PREFIX + propertyName);
                    prop.setValue(propertyValue);
                    configuration.getProperty().add(prop);
                    return null;
                }
            }, config);
        } else {
            ConfigSupport.apply(new SingleConfigCode<Property>() {

                @Override
                public Object run(Property config) throws TransactionFailure, PropertyVetoException {
                    config.setValue(propertyValue);
                    return null;
                }
            }, p);
        }
        result = true;
    }
    return result;
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyVetoException(java.beans.PropertyVetoException) Server(com.sun.enterprise.config.serverbeans.Server) Property(org.jvnet.hk2.config.types.Property)

Example 64 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class SetHazelcastConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final AdminCommandContext theContext = context;
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    if (!validate(actionReport)) {
        return;
    }
    HazelcastRuntimeConfiguration hazelcastRuntimeConfiguration = domain.getExtensionByType(HazelcastRuntimeConfiguration.class);
    if (hazelcastRuntimeConfiguration != null) {
        try {
            ConfigSupport.apply(new SingleConfigCode<HazelcastRuntimeConfiguration>() {

                @Override
                public Object run(final HazelcastRuntimeConfiguration hazelcastRuntimeConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                    if (startPort != null) {
                        hazelcastRuntimeConfigurationProxy.setStartPort(startPort);
                    }
                    if (multiCastGroup != null) {
                        hazelcastRuntimeConfigurationProxy.setMulticastGroup(multiCastGroup);
                    }
                    if (multicastPort != null) {
                        hazelcastRuntimeConfigurationProxy.setMulticastPort(multicastPort);
                    }
                    if (configFile != null) {
                        hazelcastRuntimeConfigurationProxy.setHazelcastConfigurationFile(configFile);
                    }
                    if (hostawarePartitioning != null) {
                        hazelcastRuntimeConfigurationProxy.setHostAwarePartitioning(hostawarePartitioning.toString());
                    }
                    if (hzClusterName != null) {
                        hazelcastRuntimeConfigurationProxy.setClusterGroupName(hzClusterName);
                    }
                    if (hzClusterPassword != null) {
                        hazelcastRuntimeConfigurationProxy.setClusterGroupPassword(hzClusterPassword);
                    }
                    if (licenseKey != null) {
                        hazelcastRuntimeConfigurationProxy.setLicenseKey(licenseKey);
                    }
                    if (dasPublicAddress != null) {
                        hazelcastRuntimeConfigurationProxy.setDASPublicAddress(dasPublicAddress);
                    }
                    if (dasBindAddress != null) {
                        hazelcastRuntimeConfigurationProxy.setDASBindAddress(dasBindAddress);
                    }
                    if (dasPort != null) {
                        hazelcastRuntimeConfigurationProxy.setDasPort(dasPort);
                    }
                    if (clusterMode != null) {
                        hazelcastRuntimeConfigurationProxy.setDiscoveryMode(clusterMode);
                    }
                    if (tcpipMembers != null) {
                        hazelcastRuntimeConfigurationProxy.setTcpipMembers(tcpipMembers);
                    }
                    if (interfaces != null) {
                        hazelcastRuntimeConfigurationProxy.setInterface(interfaces);
                    }
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return null;
                }
            }, hazelcastRuntimeConfiguration);
            // get the configs that need the change applied if target is domain it is all configs
            Config config = targetUtil.getConfig(target);
            List<Config> configsToApply = new ArrayList<>(5);
            if (config == null && target.equals("domain")) {
                configsToApply.addAll(domain.getConfigs().getConfig());
            } else if (config != null) {
                configsToApply.add(config);
            }
            for (Config configToApply : configsToApply) {
                HazelcastConfigSpecificConfiguration nodeConfiguration = configToApply.getExtensionByType(HazelcastConfigSpecificConfiguration.class);
                ConfigSupport.apply(new SingleConfigCode<HazelcastConfigSpecificConfiguration>() {

                    @Override
                    public Object run(final HazelcastConfigSpecificConfiguration hazelcastRuntimeConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                        if (jndiName != null) {
                            hazelcastRuntimeConfigurationProxy.setJNDIName(jndiName);
                        }
                        if (enabled != null) {
                            hazelcastRuntimeConfigurationProxy.setEnabled(enabled.toString());
                        }
                        if (lite != null) {
                            hazelcastRuntimeConfigurationProxy.setLite(lite.toString());
                        }
                        if (cacheManagerJndiName != null) {
                            hazelcastRuntimeConfigurationProxy.setCacheManagerJNDIName(cacheManagerJndiName);
                        }
                        if (cachingProviderJndiName != null) {
                            hazelcastRuntimeConfigurationProxy.setCachingProviderJNDIName(cachingProviderJndiName);
                        }
                        if (executorPoolSize != null) {
                            hazelcastRuntimeConfigurationProxy.setExecutorPoolSize(executorPoolSize);
                        }
                        if (executorQueueCapacity != null) {
                            hazelcastRuntimeConfigurationProxy.setExecutorQueueCapacity(executorQueueCapacity);
                        }
                        if (scheduledExecutorPoolSize != null) {
                            hazelcastRuntimeConfigurationProxy.setScheduledExecutorPoolSize(scheduledExecutorPoolSize);
                        }
                        if (scheduledExecutorQueueCapacity != null) {
                            hazelcastRuntimeConfigurationProxy.setScheduledExecutorQueueCapacity(scheduledExecutorQueueCapacity);
                        }
                        if (memberName != null) {
                            hazelcastRuntimeConfigurationProxy.setMemberName(memberName);
                        }
                        if (memberGroup != null) {
                            hazelcastRuntimeConfigurationProxy.setMemberGroup(memberGroup);
                        }
                        actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                        return null;
                    }
                }, nodeConfiguration);
            }
        } catch (TransactionFailure ex) {
            logger.log(Level.WARNING, "Exception during command ", ex);
            actionReport.setMessage(ex.getCause().getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        if (dynamic) {
            boolean isEnabled = false;
            if (enabled != null) {
                isEnabled = enabled;
            } else {
                isEnabled = hazelcast.isEnabled();
            }
            // this command runs on all instances so they can update their configuration.
            if ("domain".equals(target)) {
                hazelcast.setEnabled(isEnabled);
            } else {
                for (Server targetServer : targetUtil.getInstances(target)) {
                    if (server.getInstanceName().equals(targetServer.getName())) {
                        hazelcast.setEnabled(isEnabled);
                    }
                }
            }
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) HazelcastRuntimeConfiguration(fish.payara.nucleus.hazelcast.HazelcastRuntimeConfiguration) Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) HazelcastConfigSpecificConfiguration(fish.payara.nucleus.hazelcast.HazelcastConfigSpecificConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) PropertyVetoException(java.beans.PropertyVetoException) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext)

Example 65 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class SetHazelcastConfiguration method enableOnTarget.

private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) {
    // for all affected targets restart hazelcast.
    // However do in turn to prevent a major data loss
    CommandRunner runner = serviceLocator.getService(CommandRunner.class);
    ActionReport subReport = context.getActionReport().addSubActionsReport();
    CommandRunner.CommandInvocation inv;
    inv = runner.getCommandInvocation("restart-hazelcast", subReport, context.getSubject());
    List<Server> serversAffected = targetUtil.getInstances(target);
    for (Server server : serversAffected) {
        ParameterMap params = new ParameterMap();
        params.add("target", server.getName());
        inv.parameters(params);
        inv.execute();
        // swallow the offline warning as it is not a problem
        if (subReport.hasWarnings()) {
            subReport.setMessage("");
        }
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

Aggregations

Server (com.sun.enterprise.config.serverbeans.Server)86 ActionReport (org.glassfish.api.ActionReport)27 Cluster (com.sun.enterprise.config.serverbeans.Cluster)26 Domain (com.sun.enterprise.config.serverbeans.Domain)16 Config (com.sun.enterprise.config.serverbeans.Config)15 ArrayList (java.util.ArrayList)12 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)11 PropertyVetoException (java.beans.PropertyVetoException)11 Properties (java.util.Properties)10 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)10 HashMap (java.util.HashMap)9 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)8 File (java.io.File)8 IOException (java.io.IOException)8 Test (org.junit.Test)8 Property (org.jvnet.hk2.config.types.Property)8 Node (com.sun.enterprise.config.serverbeans.Node)7 Map (java.util.Map)7 Logger (java.util.logging.Logger)7 ParameterMap (org.glassfish.api.admin.ParameterMap)7