Search in sources :

Example 61 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class UpdateResourceRef method execute.

/**
 * Execution method for updating the configuration of a ResourceRef. Will be
 * replicated if the target is a cluster.
 *
 * @param context context for the command.
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    // Make a list of all ResourceRefs that need to change
    List<ResourceRef> resourceRefsToChange = new ArrayList<>();
    // Add the ResourceRef from a named server if the target is a server
    Server server = domain.getServerNamed(target);
    // if the target is a server
    if (server != null) {
        ResourceRef serverResourceRef = server.getResourceRef(name);
        // if the ResourceRef doesn't exist
        if (serverResourceRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(serverResourceRef);
    }
    // Add the ResourceRef from a named config if the target is a config
    Config config = domain.getConfigNamed(target);
    // if the target is a config
    if (config != null) {
        ResourceRef configResourceRef = config.getResourceRef(name);
        // if the ResourceRef doesn't exist
        if (configResourceRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(configResourceRef);
    }
    // Add the ResourceRefs from a named cluster if the target is a cluster
    Cluster cluster = domain.getClusterNamed(target);
    // if the target is a cluster
    if (cluster != null) {
        ResourceRef clusterResourceRef = cluster.getResourceRef(name);
        // if the ResourceRef doesn't exist
        if (clusterResourceRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(clusterResourceRef);
        for (Server instance : cluster.getInstances()) {
            ResourceRef instanceResourceRef = instance.getResourceRef(name);
            // if the server in the cluster contains the ResourceRef
            if (instanceResourceRef != null) {
                resourceRefsToChange.add(instanceResourceRef);
            }
        }
    }
    // Add the ResourceRefs from a named Deployment Group if the target is a Deployment Group
    DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
    if (dg != null) {
        ResourceRef ref = dg.getResourceRef(name);
        if (ref == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(ref);
        for (Server instance : dg.getInstances()) {
            ResourceRef instanceResourceRef = instance.getResourceRef(name);
            // if the server in the dg contains the ResourceRef
            if (instanceResourceRef != null) {
                resourceRefsToChange.add(instanceResourceRef);
            }
        }
    }
    // Apply the configuration to the listed ResourceRefs
    try {
        ConfigSupport.apply(new ConfigCode() {

            @Override
            public Object run(ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
                for (ConfigBeanProxy proxy : params) {
                    if (proxy instanceof ResourceRef) {
                        ResourceRef resourceRefProxy = (ResourceRef) proxy;
                        if (enabled != null) {
                            resourceRefProxy.setEnabled(enabled.toString());
                        }
                    }
                }
                report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return true;
            }
        }, resourceRefsToChange.toArray(new ResourceRef[] {}));
    } catch (TransactionFailure ex) {
        report.failure(logger, ex.getLocalizedMessage());
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) PropertyVetoException(java.beans.PropertyVetoException) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 62 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class CreateSsl method addSslToJMXConnector.

private void addSslToJMXConnector(Config config, ActionReport report) {
    AdminService adminService = config.getAdminService();
    // ensure we have the specified listener
    JmxConnector jmxConnector = null;
    for (JmxConnector jmxConn : adminService.getJmxConnector()) {
        if (jmxConn.getName().equals(listenerId)) {
            jmxConnector = jmxConn;
        }
    }
    if (jmxConnector == null) {
        report.setMessage(localStrings.getLocalString("create.ssl.jmx.notfound", "JMX Connector named {0} to which this ssl element is " + "being added does not exist.", listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (jmxConnector.getSsl() != null) {
        report.setMessage(localStrings.getLocalString("create.ssl.jmx.alreadyExists", "IIOP Listener named {0} to which this ssl element is " + "being added already has an ssl element.", listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<JmxConnector>() {

            @Override
            public Object run(JmxConnector param) throws PropertyVetoException, TransactionFailure {
                Ssl newSsl = param.createChild(Ssl.class);
                populateSslElement(newSsl);
                param.setSsl(newSsl);
                return newSsl;
            }
        }, jmxConnector);
    } catch (TransactionFailure e) {
        reportError(report, e);
    }
    reportSuccess(report);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) AdminService(com.sun.enterprise.config.serverbeans.AdminService) JmxConnector(com.sun.enterprise.config.serverbeans.JmxConnector) Ssl(org.glassfish.grizzly.config.dom.Ssl)

Example 63 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class DeleteSsl method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Target targetUtil = habitat.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    if (!type.equals("iiop-service")) {
        if (listenerId == null) {
            report.setMessage(localStrings.getLocalString("create.ssl.listenerid.missing", "Listener id needs to be specified"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    try {
        SslConfigHandler sslConfigHandler = habitat.getService(SslConfigHandler.class, type);
        if (sslConfigHandler != null) {
            sslConfigHandler.delete(this, report);
        } else if ("jmx-connector".equals(type)) {
            JmxConnector jmxConnector = null;
            for (JmxConnector listener : config.getAdminService().getJmxConnector()) {
                if (listener.getName().equals(listenerId)) {
                    jmxConnector = listener;
                }
            }
            if (jmxConnector == null) {
                report.setMessage(localStrings.getLocalString("delete.ssl.jmx.connector.notfound", "Iiop Listener named {0} not found", listenerId));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            if (jmxConnector.getSsl() == null) {
                report.setMessage(localStrings.getLocalString("delete.ssl.element.doesnotexist", "Ssl element does " + "not exist for Listener named {0}", listenerId));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            ConfigSupport.apply(new SingleConfigCode<JmxConnector>() {

                public Object run(JmxConnector param) throws PropertyVetoException {
                    param.setSsl(null);
                    return null;
                }
            }, jmxConnector);
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
    } catch (TransactionFailure e) {
        reportError(report, e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ActionReport(org.glassfish.api.ActionReport)

Example 64 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class SystemPropertiesCliResource method getConfig.

protected Dom getConfig(Dom domain, String configName) {
    Dom rootConfig;
    List<Dom> configs;
    synchronized (domain) {
        rootConfig = domain.nodeElements("configs").get(0);
    }
    synchronized (rootConfig) {
        configs = rootConfig.nodeElements("config");
    }
    for (Dom config : configs) {
        if (config.attribute("name").equals(configName)) {
            return config;
        }
    }
    return null;
}
Also used : Dom(org.jvnet.hk2.config.Dom)

Example 65 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class ResourceUtil method getMethodMetaData.

/**
 * Constructs and returns the resource method meta-data. This method is
 * called to get meta-data in case of update method (POST).
 *
 * @param configBeanModel the config bean associated with the resource.
 * @return MethodMetaData the meta-data store for the resource method.
 */
public static MethodMetaData getMethodMetaData(ConfigModel configBeanModel) {
    MethodMetaData methodMetaData = new MethodMetaData();
    Class<? extends ConfigBeanProxy> configBeanProxy = null;
    try {
        configBeanProxy = (Class<? extends ConfigBeanProxy>) configBeanModel.classLoaderHolder.loadClass(configBeanModel.targetTypeName);
        Set<String> attributeNames = configBeanModel.getAttributeNames();
        for (String attributeName : attributeNames) {
            String methodName = getAttributeMethodName(attributeName);
            Method method = null;
            try {
                method = configBeanProxy.getMethod(methodName);
            } catch (NoSuchMethodException e) {
                // Method not found, so let's try a brute force method if the method
                // can't be found via the method above.  For example: for
                // Ssl.getSSLInactivityTimeout(), we calculate getSslInactivityTimeout,
                // which doesn't match due to case.
                String booleanMethodName = getAttributeBooleanMethodName(attributeName);
                for (Method m : configBeanProxy.getMethods()) {
                    if (m.getName().equalsIgnoreCase(methodName) || m.getName().equalsIgnoreCase(booleanMethodName)) {
                        method = m;
                    }
                }
            }
            Attribute attribute = method.getAnnotation(Attribute.class);
            if (attribute != null) {
                ParameterMetaData parameterMetaData = getParameterMetaData(attribute);
                if (method.getAnnotation(Deprecated.class) != null) {
                    parameterMetaData.putAttribute(Constants.DEPRECATED, "true");
                }
                // camelCase the attributeName before passing out
                attributeName = eleminateHypen(attributeName);
                methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
            }
        }
    } catch (MultiException e) {
        e.printStackTrace();
    }
    return methodMetaData;
}
Also used : Attribute(org.jvnet.hk2.config.Attribute) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) Method(java.lang.reflect.Method) MultiException(org.glassfish.hk2.api.MultiException) ParameterMetaData(org.glassfish.admin.rest.provider.ParameterMetaData)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)81 Config (com.sun.enterprise.config.serverbeans.Config)69 ActionReport (org.glassfish.api.ActionReport)60 PropertyVetoException (java.beans.PropertyVetoException)59 Property (org.jvnet.hk2.config.types.Property)50 CommandTarget (org.glassfish.config.support.CommandTarget)24 Target (org.glassfish.internal.api.Target)23 Properties (java.util.Properties)21 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)17 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)15 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 Server (com.sun.enterprise.config.serverbeans.Server)14 List (java.util.List)14 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)14 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 IOException (java.io.IOException)10 Map (java.util.Map)10 Cluster (com.sun.enterprise.config.serverbeans.Cluster)9