Search in sources :

Example 46 with Config

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

the class ConfigModularityUtils method getOwner.

public ConfigBeanProxy getOwner(ConfigBeanProxy parent, String parentElement, String childElement) throws InvocationTargetException, IllegalAccessException {
    if (childElement.contains("CURRENT_INSTANCE_CONFIG_NAME")) {
        return serviceLocator.<Config>getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
    }
    if (childElement.contains("CURRENT_INSTANCE_SERVER_NAME")) {
        return serviceLocator.<Server>getService(Server.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
    }
    if (childElement.endsWith("]")) {
        String componentName;
        String elementName;
        elementName = childElement.substring(childElement.lastIndexOf("/") + 1, childElement.indexOf("["));
        componentName = childElement.substring(childElement.lastIndexOf("[") + 1, childElement.indexOf("]"));
        Class childClass = getClassFor(elementName);
        Class parentClass = getClassFor(parentElement);
        Method m = findSuitableCollectionGetter(parentClass, childClass);
        if (m != null) {
            try {
                Collection col = (Collection) m.invoke(parent);
                componentName = resolveExpression(componentName);
                return getNamedConfigBeanFromCollection(col, componentName, childClass);
            } catch (Exception e) {
                LogHelper.log(LOG, Level.INFO, invalidPath, e, childElement, componentName);
            }
        }
        return null;
    } else {
        Class clz = getClassFor(childElement);
        if (parent == null)
            return null;
        Method m = getMatchingGetterMethod(parent.getClass(), clz);
        if (m != null) {
            return (ConfigBeanProxy) m.invoke(parent);
        } else {
            try {
                m = parent.getClass().getMethod("getExtensionByType", java.lang.Class.class);
            } catch (NoSuchMethodException e) {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.log(Level.FINE, "Cannot find getExtensionByType", e);
                }
            }
            if (m != null) {
                return (ConfigBeanProxy) m.invoke(parent, clz);
            }
            return null;
        }
    }
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) Collection(java.util.Collection) Method(java.lang.reflect.Method) PropertyVetoException(java.beans.PropertyVetoException) XMLStreamException(javax.xml.stream.XMLStreamException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Example 47 with Config

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

the class CreateModuleConfigCommand method preAuthorization.

@Override
public boolean preAuthorization(AdminCommandContext context) {
    report = context.getActionReport();
    if (target != null) {
        Config newConfig = getConfigForName(target, serviceLocator, domain);
        if (newConfig != null) {
            config = newConfig;
        }
        if (config == null) {
            report.setMessage(localStrings.getLocalString("create.module.config.target.name.invalid", "The target name specified is invalid. Please double check the target name and try again"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return false;
        }
    }
    if (isAll && (serviceName != null)) {
        report.setMessage(localStrings.getLocalString("create.module.config.service.name.ignored", "One of the --all service name parameters can be used at a time. These two options can not be used together."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return false;
    }
    return true;
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config)

Example 48 with Config

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

the class DeleteModuleConfigCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    report = context.getActionReport();
    if (target != null) {
        Config newConfig = getConfigForName(target, serviceLocator, domain);
        if (newConfig != null) {
            config = newConfig;
        }
        if (config == null) {
            report.setMessage(localStrings.getLocalString("delete.module.config.target.name.invalid", "The target name specified is invalid. Please double check the target name and try again."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (serviceName == null) {
        report.setMessage(localStrings.getLocalString("delete.module.config.service.name.is.required", "The service name is required, please specify which service you want to delete its default configuration."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    final String className = configModularityUtils.convertConfigElementNameToClassName(serviceName);
    Class configBeanType = configModularityUtils.getClassFor(serviceName);
    if (configBeanType == null) {
        String msg = localStrings.getLocalString("delete.module.config.not.such.a.service.found", "Your service name does not match any service installed on this domain.");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    if (configModularityUtils.hasCustomConfig(configBeanType)) {
        List<ConfigBeanDefaultValue> defaults = configModularityUtils.getDefaultConfigurations(configBeanType, configModularityUtils.getRuntimeTypePrefix(serverenv.getStartupContext()));
        deleteDependentConfigElements(defaults);
    } else {
        deleteTopLevelExtensionByType(config, className, configBeanType);
    }
}
Also used : ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue) Config(com.sun.enterprise.config.serverbeans.Config)

Example 49 with Config

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

the class SynchronizeRealmFromConfig method execute.

@Override
public void execute(AdminCommandContext context) {
    Config realConfig = null;
    try {
        realConfig = configs.getConfigByName(target);
    } catch (Exception ex) {
    }
    if (realConfig == null) {
        Server targetServer = domain.getServerNamed(target);
        if (targetServer != null) {
            realConfig = domain.getConfigNamed(targetServer.getConfigRef());
        }
        com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
        if (cluster != null) {
            realConfig = domain.getConfigNamed(cluster.getConfigRef());
        }
    }
    ActionReport report = context.getActionReport();
    try {
        // TODO: can i use realConfig.equals(config) instead
        if (realConfig.getName().equals(config.getName())) {
            this.setRestartRequired(report);
            return;
        }
        // this is not an active config so try and update the backend
        // directly
        Realm r = realmsManager.getFromLoadedRealms(realConfig.getName(), realmName);
        if (r == null) {
            // realm is not loaded yet
            report.setMessage(_localStrings.getLocalString("REALM_SYNCH_SUCCESSFUL", "Synchronization of Realm {0} from Configuration Successful.", new Object[] { realmName }));
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
            return;
        }
        // now we really need to update the realm in the backend from the config.
        realmsManager.removeFromLoadedRealms(realConfig.getName(), realmName);
        boolean done = this.instantiateRealm(realConfig, realmName);
        if (done) {
            report.setMessage(_localStrings.getLocalString("REALM_SYNCH_SUCCESSFUL", "Synchronization of Realm {0} from Configuration Successful.", new Object[] { realmName }));
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
            return;
        }
    } catch (BadRealmException ex) {
        // throw new RuntimeException(ex);
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    } catch (NoSuchRealmException ex) {
        // throw new RuntimeException(ex);
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    } catch (Exception ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) Realm(com.sun.enterprise.security.auth.realm.Realm)

Example 50 with Config

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

the class SecureAdminConfigUpgrade method writableConfig.

private Config writableConfig(final Config c) throws TransactionFailure {
    Config result = writableConfigs.get(c.getName());
    if (result == null) {
        result = transaction().enroll(c);
        writableConfigs.put(c.getName(), result);
    }
    return result;
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)152 ActionReport (org.glassfish.api.ActionReport)73 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)50 PropertyVetoException (java.beans.PropertyVetoException)34 Target (org.glassfish.internal.api.Target)31 CommandTarget (org.glassfish.config.support.CommandTarget)30 Properties (java.util.Properties)28 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)23 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 HashMap (java.util.HashMap)17 Server (com.sun.enterprise.config.serverbeans.Server)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Logger (java.util.logging.Logger)14 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)13 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10 Level (java.util.logging.Level)10 LogRecord (java.util.logging.LogRecord)10