Search in sources :

Example 46 with ConfigBeanProxy

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

the class InstallerThread method install.

/**
 * <p> Install the admingui.war file.</p>
 */
private void install() throws Exception {
    if (domain.getSystemApplicationReferencedFrom(env.getInstanceName(), AdminConsoleAdapter.ADMIN_APP_NAME) != null) {
        // Application is already installed
        adapter.setStateMsg(AdapterState.APPLICATION_INSTALLED_BUT_NOT_LOADED);
        return;
    }
    // Set the adapter state
    adapter.setStateMsg(AdapterState.INSTALLING);
    if (log.isLoggable(Level.FINE)) {
        log.log(Level.FINE, "Installing the Admin Console Application...");
    }
    // create the application entry in domain.xml
    ConfigCode code = new ConfigCode() {

        @Override
        public Object run(ConfigBeanProxy... proxies) throws PropertyVetoException, TransactionFailure {
            SystemApplications sa = (SystemApplications) proxies[0];
            Application app = sa.createChild(Application.class);
            sa.getModules().add(app);
            app.setName(AdminConsoleAdapter.ADMIN_APP_NAME);
            app.setEnabled(Boolean.TRUE.toString());
            // TODO
            app.setObjectType("system-admin");
            app.setDirectoryDeployed("true");
            app.setContextRoot(contextRoot);
            try {
                app.setLocation("${com.sun.aas.installRootURI}/lib/install/applications/" + AdminConsoleAdapter.ADMIN_APP_NAME);
            } catch (Exception me) {
                // can't do anything
                throw new RuntimeException(me);
            }
            Module singleModule = app.createChild(Module.class);
            app.getModule().add(singleModule);
            singleModule.setName(app.getName());
            Engine webe = singleModule.createChild(Engine.class);
            webe.setSniffer("web");
            Engine sece = singleModule.createChild(Engine.class);
            sece.setSniffer("security");
            singleModule.getEngines().add(webe);
            singleModule.getEngines().add(sece);
            Server s = (Server) proxies[1];
            List<ApplicationRef> arefs = s.getApplicationRef();
            ApplicationRef aref = s.createChild(ApplicationRef.class);
            aref.setRef(app.getName());
            aref.setEnabled(Boolean.TRUE.toString());
            // TODO
            aref.setVirtualServers(getVirtualServerList());
            arefs.add(aref);
            return true;
        }
    };
    Server server = domain.getServerNamed(env.getInstanceName());
    ConfigSupport.apply(code, domain.getSystemApplications(), server);
    // Set the adapter state
    adapter.setStateMsg(AdapterState.APPLICATION_INSTALLED_BUT_NOT_LOADED);
    if (log.isLoggable(Level.FINE)) {
        log.log(Level.FINE, "Admin Console Application Installed.");
    }
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) PropertyVetoException(java.beans.PropertyVetoException)

Example 47 with ConfigBeanProxy

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

the class ConfigModularityUtils method applyCustomTokens.

public synchronized <T extends ConfigBeanProxy> void applyCustomTokens(final ConfigBeanDefaultValue configBeanDefaultValue, T finalConfigBean, ConfigBeanProxy parent) throws TransactionFailure, PropertyVetoException {
    // then that is the freaking parent, get it and set the SystemProperty :D
    if (parent instanceof SystemPropertyBag) {
        addSystemPropertyForToken(configBeanDefaultValue.getCustomizationTokens(), (SystemPropertyBag) parent);
    } else {
        ConfigBeanProxy curParent = finalConfigBean;
        while (!(curParent instanceof SystemPropertyBag)) {
            curParent = curParent.getParent();
        }
        if (configBeanDefaultValue.getCustomizationTokens().size() != 0) {
            final boolean oldIP = isIgnorePersisting();
            try {
                setIgnorePersisting(true);
                final SystemPropertyBag bag = (SystemPropertyBag) curParent;
                final List<ConfigCustomizationToken> tokens = configBeanDefaultValue.getCustomizationTokens();
                ConfigSupport.apply(new SingleConfigCode<SystemPropertyBag>() {

                    public Object run(SystemPropertyBag param) throws PropertyVetoException, TransactionFailure {
                        addSystemPropertyForToken(tokens, bag);
                        return param;
                    }
                }, bag);
            } finally {
                setIgnorePersisting(oldIP);
            }
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCustomizationToken(com.sun.enterprise.config.modularity.customization.ConfigCustomizationToken) SystemPropertyBag(com.sun.enterprise.config.serverbeans.SystemPropertyBag)

Example 48 with ConfigBeanProxy

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

the class ConfigModularityUtils method deleteConfigurationForConfigBean.

public boolean deleteConfigurationForConfigBean(ConfigBeanProxy configBean, Collection col, ConfigBeanDefaultValue defaultValue) {
    String name;
    ConfigBeanProxy itemToRemove;
    try {
        Class configBeanClass = getClassForFullName(defaultValue.getConfigBeanClassName());
        name = getNameForConfigBean(configBean, configBeanClass);
        itemToRemove = getNamedConfigBeanFromCollection(col, name, configBeanClass);
        if (itemToRemove != null) {
            col.remove(itemToRemove);
            return true;
        }
        if (name == null) {
            col.remove(configBean);
            return true;
        }
    } catch (Exception ex) {
        return false;
    }
    return false;
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) PropertyVetoException(java.beans.PropertyVetoException) XMLStreamException(javax.xml.stream.XMLStreamException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Example 49 with ConfigBeanProxy

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

the class ConfigModularityUtils method replacePropertiesWithCurrentValue.

public String replacePropertiesWithCurrentValue(String xmlConfiguration, ConfigBeanDefaultValue value) throws InvocationTargetException, IllegalAccessException {
    for (ConfigCustomizationToken token : value.getCustomizationTokens()) {
        String toReplace = "${" + token.getName() + "}";
        ConfigBeanProxy current = getCurrentConfigBeanForDefaultValue(value);
        String propertyValue = getPropertyValue(token, current);
        if (propertyValue != null) {
            xmlConfiguration = xmlConfiguration.replace(toReplace, propertyValue);
        }
    }
    return xmlConfiguration;
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCustomizationToken(com.sun.enterprise.config.modularity.customization.ConfigCustomizationToken)

Example 50 with ConfigBeanProxy

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

the class DeleteModuleConfigCommand method deleteDependentConfigElement.

private void deleteDependentConfigElement(final ConfigBeanDefaultValue defaultValue) {
    Class parentClass = configModularityUtils.getOwningClassForLocation(defaultValue.getLocation());
    final Class configBeanClass = configModularityUtils.getClassForFullName(defaultValue.getConfigBeanClassName());
    final Method m = configModularityUtils.findSuitableCollectionGetter(parentClass, configBeanClass);
    if (m != null) {
        try {
            final ConfigBeanProxy parent = configModularityUtils.getOwningObject(defaultValue.getLocation());
            ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {

                @Override
                public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
                    List col = null;
                    ConfigBeanProxy configBean = null;
                    try {
                        col = (List) m.invoke(param);
                        if (col != null) {
                            configBean = configModularityUtils.getCurrentConfigBeanForDefaultValue(defaultValue);
                        }
                    } catch (Exception e) {
                        String message = localStrings.getLocalString("delete.module.config.failed.deleting.dependant", "Failed to remove all configuration elements related to your service form domain.xml. You can use create-module-config --dryRun with your module name to see all relevant configurations and try removing the config elements ");
                        report.setMessage(message);
                        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                        LOG.log(Level.INFO, DELETE_MODULE_CONFIG_FAILED_DELETING_DEPENDENT, e);
                    }
                    if (configBean != null) {
                        boolean deleted = configModularityUtils.deleteConfigurationForConfigBean(configBean, col, defaultValue);
                        if (!deleted) {
                            for (int i = 0; i < col.size(); i++) {
                                if (configBeanClass.isAssignableFrom(col.get(i).getClass())) {
                                    col.remove(col.get(i));
                                    removeCustomTokens(defaultValue, configBean, parent);
                                    return param;
                                }
                            }
                        }
                    }
                    return param;
                }
            }, parent);
        } catch (Exception e) {
            String message = localStrings.getLocalString("delete.module.config.failed.deleting.dependant", "Failed to remove all configuration elements related to your service form domain.xml. You can use create-module-config --dryRun with your module name to see all relevant configurations and try removing the config elements ");
            report.setMessage(message);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            LOG.log(Level.INFO, DELETE_MODULE_CONFIG_FAILED_DELETING_DEPENDENT, e);
        }
    } else {
        report.setMessage(localStrings.getLocalString("delete.module.config.failed.deleting.dependant", "Failed to remove all configuration elements related to your service form domain.xml. You can use create-module-config --dryRun with your module name to see all relevant configurations and try removing the config elements "));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) List(java.util.List) Method(java.lang.reflect.Method) PropertyVetoException(java.beans.PropertyVetoException)

Aggregations

ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)41 PropertyVetoException (java.beans.PropertyVetoException)21 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)14 Method (java.lang.reflect.Method)11 ArrayList (java.util.ArrayList)11 ConfigCode (org.jvnet.hk2.config.ConfigCode)10 Config (com.sun.enterprise.config.serverbeans.Config)8 Server (com.sun.enterprise.config.serverbeans.Server)6 IOException (java.io.IOException)6 List (java.util.List)6 ActionReport (org.glassfish.api.ActionReport)6 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)6 Protocol (org.glassfish.grizzly.config.dom.Protocol)6 MultiException (org.glassfish.hk2.api.MultiException)6 ConfigModel (org.jvnet.hk2.config.ConfigModel)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 XMLStreamException (javax.xml.stream.XMLStreamException)5 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)5 ConfigBean (org.jvnet.hk2.config.ConfigBean)5 Property (org.jvnet.hk2.config.types.Property)5