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;
}
}
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;
}
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);
}
}
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);
}
}
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();
}
Aggregations