Search in sources :

Example 16 with TYPE

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

the class ExtensionPatternInvocationImpl method handleExtension.

@Override
public ConfigBeanProxy handleExtension(Object owner, Class ownerType, Object[] params) {
    if (((Class) params[0]).getName().equals("com.sun.enterprise.config.serverbeans.SystemProperty"))
        return null;
    ConfigBeanProxy configExtension = null;
    List<ConfigBeanProxy> extensions = configModularityUtils.getExtensions(((ConfigBean) owner).createProxy(ownerType));
    for (ConfigBeanProxy extension : extensions) {
        try {
            configExtension = (ConfigBeanProxy) ((Class) params[0]).cast(extension);
            return configExtension;
        } catch (Exception e) {
        // ignore, not the right type.
        }
    }
    try {
        ConfigBeanProxy pr = ((ConfigBean) owner).createProxy(ownerType);
        ConfigBeanProxy returnValue = moduleConfigurationLoader.createConfigBeanForType((Class) params[0], pr);
        return returnValue;
    } catch (TransactionFailure transactionFailure) {
        LogHelper.log(LOG, Level.INFO, "Cannot get extension type {0} for {1}.", transactionFailure, new Object[] { owner.getClass().getName(), ownerType.getName() });
        return null;
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigBean(org.jvnet.hk2.config.ConfigBean)

Example 17 with TYPE

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

the class ConfigurationParser method parseAndSetConfigBean.

/**
 * @param <T> the ConfigBeanProxy type we are looking for
 */
public <T extends ConfigBeanProxy> void parseAndSetConfigBean(List<ConfigBeanDefaultValue> values) {
    ConfigParser configParser = new ConfigParser(serviceLocator);
    // I don't use the GlassFish document here as I don't need persistence
    final DomDocument doc = new DomDocument<GlassFishConfigBean>(serviceLocator) {

        @Override
        public Dom make(final ServiceLocator serviceLocator, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
            return new GlassFishConfigBean(serviceLocator, this, dom, configModel, xmlStreamReader);
        }
    };
    // the solution is to put the loop into the apply method...  But it would be some fine amount of work
    for (final ConfigBeanDefaultValue configBeanDefaultValue : values) {
        final ConfigBeanProxy parent = configModularityUtils.getOwningObject(configBeanDefaultValue.getLocation());
        if (parent == null)
            continue;
        ConfigurationPopulator populator = null;
        if (replaceSystemProperties)
            try {
                populator = new ConfigurationPopulator(configModularityUtils.replacePropertiesWithCurrentValue(configBeanDefaultValue.getXmlConfiguration(), configBeanDefaultValue), doc, parent);
            } catch (Exception e) {
                LOG.log(Level.SEVERE, ConfigApiLoggerInfo.CFG_EXT_ADD_FAILED, e);
            }
        else {
            // Check that parent is not null!
            populator = new ConfigurationPopulator(configBeanDefaultValue.getXmlConfiguration(), doc, parent);
        }
        populator.run(configParser);
        synchronized (configModularityUtils) {
            boolean oldValue = configModularityUtils.isIgnorePersisting();
            try {
                Class configBeanClass = configModularityUtils.getClassForFullName(configBeanDefaultValue.getConfigBeanClassName());
                final ConfigBeanProxy pr = doc.getRoot().createProxy(configBeanClass);
                configModularityUtils.setIgnorePersisting(true);
                ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {

                    public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
                        configModularityUtils.setConfigBean(pr, configBeanDefaultValue, param);
                        return param;
                    }
                }, parent);
            } catch (TransactionFailure e) {
                LOG.log(Level.SEVERE, ConfigApiLoggerInfo.CFG_EXT_ADD_FAILED, e);
            } finally {
                configModularityUtils.setIgnorePersisting(oldValue);
            }
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) XMLStreamReader(javax.xml.stream.XMLStreamReader) ConfigParser(org.jvnet.hk2.config.ConfigParser) PropertyVetoException(java.beans.PropertyVetoException) DomDocument(org.jvnet.hk2.config.DomDocument) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) PropertyVetoException(java.beans.PropertyVetoException) ConfigModel(org.jvnet.hk2.config.ConfigModel) ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) GlassFishConfigBean(org.glassfish.config.support.GlassFishConfigBean)

Example 18 with TYPE

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

the class PortUtils method checkInternalConsistency.

/**
 * Make sure all ports that are specified by the user make sense.
 * @param server The new Server element
 * @return null if all went OK.  Otherwise return a String with the error message.
 */
static void checkInternalConsistency(Server server) throws TransactionFailure {
    // Make sure all the system properties for ports have different numbers.
    List<SystemProperty> sysProps = server.getSystemProperty();
    Set<Integer> ports = new TreeSet<Integer>();
    for (SystemProperty sp : sysProps) {
        String name = sp.getName();
        if (PORTSLIST.contains(name)) {
            String val = sp.getValue();
            try {
                boolean wasAdded = ports.add(Integer.parseInt(val));
                if (// TODO unit test
                !wasAdded)
                    throw new TransactionFailure(Strings.get("PortUtils.duplicate_port", val, server.getName()));
            } catch (TransactionFailure tf) {
                // don't re-wrap the same Exception type!
                throw tf;
            } catch (Exception e) {
                // TODO unit test
                throw new TransactionFailure(Strings.get("PortUtils.non_int_port", val, server.getName()));
            }
        }
    }
    checkForLegalPorts(ports, server.getName());
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty)

Example 19 with TYPE

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

the class ActionReportResultHtmlProvider method getContent.

@Override
public String getContent(ActionReportResult proxy) {
    RestActionReporter ar = (RestActionReporter) proxy.getActionReport();
    StringBuilder result = new StringBuilder(ProviderUtil.getHtmlHeader(getBaseUri()));
    final String message = ResourceUtil.encodeString(ar.getCombinedMessage());
    if (!message.isEmpty()) {
        result.append("<h3>").append(message).append(HEADING_END);
    }
    if (proxy.isError()) {
        result.append("<h2>").append(ar.getActionDescription()).append(" Error:</h2>").append(proxy.getErrorMessage());
    } else {
        final Map<String, String> childResources = (Map<String, String>) ar.getExtraProperties().get("childResources");
        final List<Map<String, String>> commands = (List<Map<String, String>>) ar.getExtraProperties().get("commands");
        final MethodMetaData postMetaData = proxy.getMetaData().getMethodMetaData("POST");
        final MethodMetaData deleteMetaData = proxy.getMetaData().getMethodMetaData(DELETE);
        final MethodMetaData getMetaData = proxy.getMetaData().getMethodMetaData("GET");
        final ConfigBean entity = proxy.getEntity();
        if ((proxy.getCommandDisplayName() != null) && (getMetaData != null)) {
            // for commands, we want the output of the command before the form
            if (entity == null) {
                // show extra properties only for non entity pages
                result.append(processReport(ar));
            }
        }
        if ((postMetaData != null) && (entity == null)) {
            String postCommand = getHtmlRespresentationsForCommand(postMetaData, "POST", (proxy.getCommandDisplayName() == null) ? "Create" : proxy.getCommandDisplayName(), uriInfo.get());
            result.append(getHtmlForComponent(postCommand, "Create " + ar.getActionDescription(), ""));
        }
        if ((deleteMetaData != null) && (entity == null)) {
            String deleteCommand = getHtmlRespresentationsForCommand(deleteMetaData, DELETE, (proxy.getCommandDisplayName() == null) ? "Delete" : proxy.getCommandDisplayName(), uriInfo.get());
            result.append(getHtmlForComponent(deleteCommand, "Delete " + ar.getActionDescription(), ""));
        }
        if ((getMetaData != null) && (entity == null) && (proxy.getCommandDisplayName() != null)) {
            String getCommand = getHtmlRespresentationsForCommand(getMetaData, "GET", (proxy.getCommandDisplayName() == null) ? "Get" : proxy.getCommandDisplayName(), uriInfo.get());
            result.append(getHtmlForComponent(getCommand, "Get " + ar.getActionDescription(), ""));
        }
        if (entity != null) {
            String attributes = ProviderUtil.getHtmlRepresentationForAttributes(proxy.getEntity(), uriInfo.get());
            result.append(ProviderUtil.getHtmlForComponent(attributes, ar.getActionDescription() + " Attributes", ""));
            String deleteCommand = ProviderUtil.getHtmlRespresentationsForCommand(proxy.getMetaData().getMethodMetaData(DELETE), DELETE, (proxy.getCommandDisplayName() == null) ? "Delete" : proxy.getCommandDisplayName(), uriInfo.get());
            result.append(ProviderUtil.getHtmlForComponent(deleteCommand, "Delete " + entity.model.getTagName(), ""));
        } else if (proxy.getLeafContent() != null) {
            // it is a single leaf @Element
            String content = "<form action=\"" + uriInfo.get().getAbsolutePath().toString() + "\" method=\"post\">" + "<dl><dt>" + "<label for=\"" + proxy.getLeafContent().name + "\">" + proxy.getLeafContent().name + ":&nbsp;</label>" + "</dt><dd>" + "<input name=\"" + proxy.getLeafContent().name + "\" value =\"" + proxy.getLeafContent().value + "\" type=\"text\" >" + "</dd><dt class=\"button\"></dt><dd class=\"button\"><input value=\"Update\" type=\"submit\"></dd></dl>" + "</form><br><hr class=\"separator\"/";
            result.append(content);
        } else {
            // This is a monitoring result!!!
            final Map vals = (Map) ar.getExtraProperties().get("entity");
            if ((vals != null) && (!vals.isEmpty())) {
                result.append("<ul>");
                for (Map.Entry entry : (Set<Map.Entry>) vals.entrySet()) {
                    Object object = entry.getValue();
                    if (object == null) {
                    // do nothing
                    } else if (object instanceof Collection) {
                        if (!((Collection) object).isEmpty()) {
                            Collection c = ((Collection) object);
                            Iterator i = c.iterator();
                            result.append("<li>").append(entry.getKey());
                            result.append("<ul>");
                            while (i.hasNext()) {
                                result.append("<li>").append(getHtmlRepresentation(i.next())).append(LIST_ITEM_END);
                            }
                            result.append(LIST_END);
                            result.append(LIST_ITEM_END);
                        }
                    } else if (object instanceof Map) {
                        if (!((Map) object).isEmpty()) {
                            Map m = (Map) object;
                            if (vals.size() != 1) {
                                // add a link if more than 1 child
                                result.append("<li>").append(ANCHOR_OPEN).append(uriInfo.get().getAbsolutePath().toString()).append("/").append(entry.getKey()).append("\">").append(entry.getKey()).append("</a>");
                            } else {
                                result.append("<li>").append(entry.getKey());
                            }
                            result.append("<ul>");
                            for (Map.Entry anEntry : (Set<Map.Entry>) m.entrySet()) {
                                final String htmlRepresentation = getHtmlRepresentation(anEntry.getValue());
                                if (htmlRepresentation != null) {
                                    result.append("<li>").append(anEntry.getKey()).append(" : ").append(htmlRepresentation).append(LIST_ITEM_END);
                                }
                            }
                            result.append(LIST_END);
                            result.append(LIST_ITEM_END);
                        }
                    } else {
                        result.append("<li>").append(entry.getKey()).append(" : ").append(object.toString()).append(LIST_ITEM_END);
                    }
                }
                result.append(LIST_END);
            } else {
                // no values to show... give an hint
                if ((childResources == null) || (childResources.isEmpty())) {
                    if ((uriInfo != null) && (uriInfo.get().getPath().equalsIgnoreCase("domain"))) {
                        result.append(getHint(uriInfo.get(), MediaType.TEXT_HTML));
                    }
                }
            }
        }
        if ((childResources != null) && (!childResources.isEmpty())) {
            String childResourceLinks = getResourcesLinks(childResources);
            result.append(ProviderUtil.getHtmlForComponent(childResourceLinks, "Child Resources", ""));
        }
        if ((commands != null) && (!commands.isEmpty())) {
            String commandLinks = getCommandLinks(commands);
            result.append(ProviderUtil.getHtmlForComponent(commandLinks, "Commands", ""));
        }
    }
    return result.append("</div></body></html>").toString();
}
Also used : ConfigBean(org.jvnet.hk2.config.ConfigBean) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) Iterator(java.util.Iterator) Collection(java.util.Collection) List(java.util.List) Map(java.util.Map)

Example 20 with TYPE

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

the class ApplicationLifecycle method startEngine.

private EngineInfo startEngine(DeploymentContext context, Sniffer sniffer, String containerName) throws Exception {
    final ActionReport report = context.getActionReport();
    StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
    // start all the containers associated with sniffers.
    try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, sniffer.getModuleType(), DeploymentTracing.AppStage.PREPARE)) {
        EngineInfo engineInfo = containerRegistry.getContainer(containerName);
        if (engineInfo == null) {
            // need to synchronize on the registry to not end up starting the same container from
            // different threads.
            Collection<EngineInfo> containersInfo = null;
            synchronized (containerRegistry) {
                if (containerRegistry.getContainer(containerName) == null) {
                    DeploymentSpan innerSpan = tracing.startSpan(DeploymentTracing.AppStage.CONTAINER_START);
                    containersInfo = setupContainer(sniffer, logger, context);
                    innerSpan.close();
                    if (containersInfo == null || containersInfo.isEmpty()) {
                        String msg = "Cannot start container(s) associated to application of type : " + sniffer.getModuleType();
                        report.failure(logger, msg, null);
                        throw new Exception(msg);
                    }
                }
            }
            // now start all containers, by now, they should be all setup...
            if (containersInfo != null && !startContainers(containersInfo, logger, context)) {
                final String msg = "Aborting, Failed to start container " + containerName;
                report.failure(logger, msg, null);
                throw new Exception(msg);
            }
        }
        engineInfo = containerRegistry.getContainer(containerName);
        if (engineInfo == null) {
            final String msg = "Aborting, Failed to start container " + containerName;
            report.failure(logger, msg, null);
            throw new Exception(msg);
        }
        return engineInfo;
    }
}
Also used : EngineInfo(org.glassfish.internal.data.EngineInfo) StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) ActionReport(org.glassfish.api.ActionReport) MultiException(org.glassfish.hk2.api.MultiException) DeploymentException(org.glassfish.deployment.common.DeploymentException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) RetryableException(org.jvnet.hk2.config.RetryableException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)15 Property (org.jvnet.hk2.config.types.Property)15 IOException (java.io.IOException)13 ActionReport (org.glassfish.api.ActionReport)13 PropertyVetoException (java.beans.PropertyVetoException)12 List (java.util.List)10 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)10 Method (java.lang.reflect.Method)9 HashMap (java.util.HashMap)9 Map (java.util.Map)7 Logger (java.util.logging.Logger)7 Service (org.jvnet.hk2.annotations.Service)7 ArrayList (java.util.ArrayList)6 Inject (javax.inject.Inject)6 MultiException (org.glassfish.hk2.api.MultiException)6 ConfigBean (org.jvnet.hk2.config.ConfigBean)6 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)5 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)4 Collection (java.util.Collection)4 DeploymentException (org.glassfish.deployment.common.DeploymentException)4