Search in sources :

Example 66 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class TemplateRestResource method setParentAndTagName.

public void setParentAndTagName(Dom parent, String tagName) {
    if (parent == null) {
        // prevent https://glassfish.dev.java.net/issues/show_bug.cgi?id=14125
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    this.parent = parent;
    this.tagName = tagName;
    synchronized (parent) {
        entity = parent.nodeElement(tagName);
    }
    if (entity == null) {
        // In some cases, the tagName requested is not found in the DOM tree.  This is true,
        // for example, for the various ZeroConf elements (e.g., transaction-service).  If
        // the zero conf element is not in domain.xml, then it won't be in the Dom tree
        // returned by HK2.  If that's the case, we can use ConfigModularityUtils.getOwningObject()
        // to find the ConfigBean matching the path requested, which will add the node to
        // the Dom tree. Once that's done, we can return that node and proceed as normal
        String location = buildPath(parent) + "/" + tagName;
        if (location.startsWith("domain/configs")) {
            final ConfigModularityUtils cmu = locatorBridge.getRemoteLocator().<ConfigModularityUtils>getService(ConfigModularityUtils.class);
            ConfigBeanProxy cbp = cmu.getOwningObject(location);
            if (cbp == null) {
                cbp = cmu.getConfigBeanInstanceFor(cmu.getOwningClassForLocation(location));
            }
            if (cbp != null) {
                entity = Dom.unwrap(cbp);
                childModel = entity.model;
            }
        }
    // throw new WebApplicationException(new Exception("Trying to create an entity using generic create"),Response.Status.INTERNAL_SERVER_ERROR);
    } else {
        childModel = entity.model;
    }
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) WebApplicationException(javax.ws.rs.WebApplicationException) ConfigModularityUtils(com.sun.enterprise.config.modularity.ConfigModularityUtils)

Example 67 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class TemplateRestResource method buildPath.

/**
 * This method will build the path string as needed by ConfigModularityUtils.getOwningObject().
 * There is a mismatch between what the method expects and the way the REST URIs are constructed.
 * For example, for the transaction-service element, the REST URI, stripped of the HTTP and
 * server context information, looks like this:
 * /domain/configs/config/server-config/transaction-service.  The format expected by the
 * getOwningObject(), however, looks like this:
 * domain/configs/server-config/transaction-service. In the REST URIs, if there is a collection of
 * Named items, the type of the collection is inserted into the URI ("config" here) followed by
 * the name of the particular instance ("server-config").  In building the path, we must identify
 * Named instances and insert the name of the instance rather than the type.  We apply this logic
 * as we recurse up to the top of the Dom tree to finish building the path desired.
 * @param node
 * @return
 */
private String buildPath(Dom node) {
    final Dom parentNode = node.parent();
    String part = node.model.getTagName();
    String name = node.attribute("name");
    if (name != null) {
        part = name;
    }
    return (parentNode != null) ? (buildPath(parentNode) + "/" + part) : part;
}
Also used : Dom(org.jvnet.hk2.config.Dom)

Example 68 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class UpgradeLogging method doUpgrade.

private void doUpgrade(Config config) {
    // v3 uses logging.properties to configure the logging facility.
    // move all log-service elements to logging.properties
    final LogService logService = config.getLogService();
    // check if null and exit
    if (logService == null)
        return;
    try {
        RepositoryConfig rc = new RepositoryConfig();
        String configDir = rc.getRepositoryRoot() + File.separator + rc.getRepositoryName() + File.separator + rc.getInstanceName() + File.separator + "config";
        PEFileLayout layout = new PEFileLayout(rc);
        File src = new File(layout.getTemplatesDir(), PEFileLayout.LOGGING_PROPERTIES_FILE);
        File dest = new File(configDir, PEFileLayout.LOGGING_PROPERTIES_FILE);
        if (!dest.exists())
            FileUtils.copy(src, dest);
    } catch (IOException ioe) {
        getLogger().log(Level.SEVERE, FAIL_CREATE_LOG_PROPS, ioe);
    }
    try {
        // Get the logLevels
        ModuleLogLevels mll = logService.getModuleLogLevels();
        Map<String, String> logLevels = mll.getAllLogLevels();
        String file = logService.getFile();
        String payaraNotificationFile = logService.getPayaraNotificationFile();
        String instanceRoot = System.getProperty("com.sun.aas.instanceRoot");
        if (file.contains(instanceRoot)) {
            file = file.replace(instanceRoot, "${com.sun.aas.instanceRoot}");
        }
        if (payaraNotificationFile.contains(instanceRoot)) {
            payaraNotificationFile = payaraNotificationFile.replace(instanceRoot, "${com.sun.aas.instanceRoot}");
        }
        logLevels.put("file", file);
        logLevels.put("payara-notification-file", payaraNotificationFile);
        logLevels.put("use-system-logging", logService.getUseSystemLogging());
        // this can have multiple values so need to add
        logLevels.put("log-handler", logService.getLogHandler());
        logLevels.put("log-filter", logService.getLogFilter());
        logLevels.put("log-to-file", logService.getLogToFile());
        logLevels.put("payara-notification-log-to-file", logService.getPayaraNotificationLogToFile());
        logLevels.put("log-to-console", logService.getLogToConsole());
        logLevels.put("log-rotation-limit-in-bytes", logService.getLogRotationLimitInBytes());
        logLevels.put("fast-logging", logService.getFastLogging());
        logLevels.put("payara-notification-log-rotation-limit-in-bytes", logService.getPayaraNotificationLogRotationLimitInBytes());
        logLevels.put("log-rotation-timelimit-in-minutes", logService.getLogRotationTimelimitInMinutes());
        logLevels.put("payara-notification-log-rotation-timelimit-in-minutes", logService.getPayaraNotificationLogRotationTimelimitInMinutes());
        logLevels.put("alarms", logService.getAlarms());
        logLevels.put("retain-error-statistics-for-hours", logService.getRetainErrorStatisticsForHours());
        logLevels.put("log-standard-streams", logService.getLogStandardStreams());
        final Map<String, String> m = new HashMap<String, String>(logLevels);
        ConfigSupport.apply(new SingleConfigCode<Config>() {

            @Override
            public Object run(Config c) throws PropertyVetoException, TransactionFailure {
                try {
                    // update logging.properties
                    logConfig.setLoggingProperties(m);
                    c.setLogService(null);
                } catch (IOException e) {
                    getLogger().log(Level.SEVERE, FAIL_UPDATE_LOG_PROPS, e);
                }
                return null;
            }
        }, config);
    } catch (TransactionFailure tf) {
        getLogger().log(Level.SEVERE, FAIL_UPGRADE_LOG_SERVICE, tf);
        throw new RuntimeException(tf);
    }
}
Also used : RepositoryConfig(com.sun.enterprise.admin.servermgmt.RepositoryConfig) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) HashMap(java.util.HashMap) RepositoryConfig(com.sun.enterprise.admin.servermgmt.RepositoryConfig) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) PEFileLayout(com.sun.enterprise.admin.servermgmt.pe.PEFileLayout) File(java.io.File)

Example 69 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class BaseSetNotifierConfigurationCommand method execute.

@Override
public void execute(final AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    Config configuration = targetUtil.getConfig(target);
    final NotificationServiceConfiguration notificationServiceConfiguration = configuration.getExtensionByType(NotificationServiceConfiguration.class);
    Class<C> notifierConfigurationClass = NotifierUtils.getConfigurationClass(getClass());
    C c = notificationServiceConfiguration.getNotifierConfigurationByType(notifierConfigurationClass);
    // the tags for their local config (it doesn't get synced back to the DAS).
    if (c == null) {
        try {
            // Create a transaction around the notifier config we want to add the element to, grab it's list
            // of notifiers, and add a new child element to it
            ConfigSupport.apply(notificationServiceConfigurationProxy -> {
                notificationServiceConfigurationProxy.getNotifierConfigurationList().add(notificationServiceConfigurationProxy.createChild(notifierConfigurationClass));
                return notificationServiceConfigurationProxy;
            }, notificationServiceConfiguration);
        } catch (TransactionFailure ex) {
            actionReport.setMessage(ex.getCause().getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        // Attempt to grab the new child element config as the config we want to configure
        c = notificationServiceConfiguration.getNotifierConfigurationByType(notifierConfigurationClass);
        // If we still can't find the config, exit out - something has gone wrong
        if (c == null) {
            actionReport.setMessage("Could not locate notifier config");
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    try {
        ConfigSupport.apply(cProxy -> {
            applyValues(cProxy);
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
            return cProxy;
        }, c);
        // If the service is being changed dynamically
        if (dynamic) {
            if (server.isDas()) {
                if (targetUtil.getConfig(target).isDas()) {
                    configureDynamically(c);
                }
            } else {
                configureDynamically(c);
            }
        }
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Exception during command ", ex);
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Example 70 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class JobCleanUpService method postConstruct.

@Override
public void postConstruct() {
    micro = Version.getFullVersion().contains("Micro");
    if (micro) {
        // if Micro we don't have any jobs to cleanup
        return;
    }
    logger.log(Level.FINE, KernelLoggerInfo.initializingJobCleanup);
    scheduler = Executors.newScheduledThreadPool(10, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread result = new Thread(r);
            result.setDaemon(true);
            result.setName("Job Cleanup Service");
            return result;
        }
    });
    managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(managedJobConfig);
    logger.fine(KernelLoggerInfo.initializingManagedConfigBean);
    bean.addListener(this);
    scheduleCleanUp();
}
Also used : ManagedJobConfig(com.sun.enterprise.config.serverbeans.ManagedJobConfig) ObservableBean(org.jvnet.hk2.config.ObservableBean)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)34 PropertyVetoException (java.beans.PropertyVetoException)26 ActionReport (org.glassfish.api.ActionReport)25 Config (com.sun.enterprise.config.serverbeans.Config)21 Property (org.jvnet.hk2.config.types.Property)17 ArrayList (java.util.ArrayList)9 Properties (java.util.Properties)9 HealthCheckServiceConfiguration (fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration)7 Service (org.jvnet.hk2.annotations.Service)7 File (java.io.File)6 HashMap (java.util.HashMap)6 List (java.util.List)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 StuckThreadsChecker (fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker)4 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 ObservableBean (org.jvnet.hk2.config.ObservableBean)4 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)4 Transactions (org.jvnet.hk2.config.Transactions)4 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)4 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)4