/** * Execute some logic on one config bean of type T protected by a transaction * * @param code code to execute * @param param config object participating in the transaction * @return list of events that represents the modified config elements. * @throws TransactionFailure when code did not run successfully */ public static <T extends ConfigBeanProxy> Object apply(final SingleConfigCode<T> code, T param) throws TransactionFailure { //ConfigBeanProxy[] objects = { param }; return apply((new ConfigCode() { @SuppressWarnings("unchecked") public Object run(ConfigBeanProxy... objects) throws PropertyVetoException, TransactionFailure { return code.run((T) objects[0]); } }), param); }
public void testGetImplAndAddListener() { SimpleConnector sc = habitat.getService(SimpleConnector.class); final EjbContainerAvailability ejb = sc.getEjbContainerAvailability(); ObservableBean obean = (ObservableBean) ConfigSupport.getImpl(ejb); EjbObservableBean ejbBean = new EjbObservableBean(); obean.addListener(ejbBean); try { ConfigSupport.apply(new SingleConfigCode<EjbContainerAvailability>() { @Override public Object run(EjbContainerAvailability param) ConfigSupport.apply(new SingleConfigCode<EjbContainerAvailability>() { @Override public Object run(EjbContainerAvailability param) + ConfigSupport.getImpl(ejb).getClass().getName()); System.out.println("getImpl(ejb).getMasterView() == > " + ConfigSupport.getImpl(ejb).getMasterView().getClass().getName()); System.out.println("getImpl(ejb).getProxyType() == > " + ConfigSupport.getImpl(ejb).getProxyType().getClass().getName()); } catch (Exception e) { e.printStackTrace();
@Override public UnprocessedChangeEvents changed(final PropertyChangeEvent[] events) { return ConfigSupport.sortAndDispatch( events, new Changed() { @Override public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) { if (t instanceof Domain) { return processDomain(type, (Domain) t, events); } else if (t instanceof SecureAdmin) { return processSecureAdmin(type, (SecureAdmin) t, events); } return null; } }, logger); }
throws TransactionFailure { return createAndSet(parent, childType, convertMapToAttributeChanges(attributes), runnable);
/** * Executes the command with the command parameters passed as Properties * where the keys are the paramter names and the values the parameter values * * @param context information */ public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); try { ConfigSupport.apply(new SingleConfigCode<SecurityService>() { public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure { param.getAuthRealm().remove(authRealm); //temporary fix - since the SecurityConfigListener is not being called on an realm delete. SecurityConfigListener.authRealmDeleted(authRealm); return null; } }, securityService); } catch(TransactionFailure e) { report.setMessage(localStrings.getLocalString( "delete.auth.realm.fail", "Deletion of Authrealm {0} failed", authRealmName) + " " + e.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); }
static void setMBeanEnabled(MonitoringService ms, final String enabled, final ActionReport report) { try { ConfigSupport.apply(new SingleConfigCode<MonitoringService>() { public Object run(MonitoringService param) throws PropertyVetoException, TransactionFailure { param.setMbeanEnabled(enabled); return param; } }, ms); } catch(TransactionFailure tfe) { report.setMessage(localStrings.getLocalString("disable.monitoring.exception", "Encountered exception while setting mbean-enabled to false {0}", tfe.getMessage())); report.setActionExitCode(ActionReport.ExitCode.FAILURE); } }
private void addSslToJMXConnector(Config config, ActionReport report) { AdminService adminService = config.getAdminService(); 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; 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)); ConfigSupport.apply(new SingleConfigCode<JmxConnector>() { @Override public Object run(JmxConnector param)
@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); actionReport.setMessage("Either dataSourceLookupName or executorServiceLookupName must be specified."); actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); return; System.out.println("** EXECUTING -d " + dataSourceLookupName + " -x " + executorServiceLookupName); BatchRuntimeConfiguration batchRuntimeConfiguration = config.getExtensionByType(BatchRuntimeConfiguration.class); if (batchRuntimeConfiguration != null) { ConfigSupport.apply(new SingleConfigCode<BatchRuntimeConfiguration>() { @Override public Object run(final BatchRuntimeConfiguration batchRuntimeConfigurationProxy) actionReport.setMessage(txfEx.getCause().getMessage()); actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); return;
@Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); Logger logger= context.getLogger(); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setMessage(KernelLoggerInfo.getLogger().getResourceBundle().getString(KernelLoggerInfo.getFailManagedJobConfig)); return; ConfigSupport.apply(new SingleConfigCode<ManagedJobConfig>() { report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setMessage(e.getMessage());
@Override public void execute(AdminCommandContext context) { ActionReport ar = context.getActionReport(); if (virtualizations==null) { ar.failure(RuntimeContext.logger, "No virtualization configuration found"); return; } for (final Virtualization v : virtualizations.getVirtualizations()) { if (v.getName().equals(name)) { try { ConfigSupport.apply(new SingleConfigCode<Virtualizations>() { @Override public Object run(Virtualizations wVirts) throws PropertyVetoException, TransactionFailure { wVirts.getVirtualizations().remove(v); return null; } }, virtualizations); } catch (TransactionFailure transactionFailure) { ar.failure(RuntimeContext.logger, "Cannot delete " + name + " virtualization config", transactionFailure); } ar.setActionExitCode(ActionReport.ExitCode.SUCCESS); ar.setMessage("Configuration deleted successfully"); return; } } ar.failure(RuntimeContext.logger, "Cannot find virtualization configuration named " + name); } }
@Override public void execute(final AdminCommandContext context) { final ActionReport result = context.getActionReport(); String msg = localStrings.getLocalString(GenericDeleteCommand.class, "TypeAndNameResolver.target_object_not_found", "Cannot find a {0} with a name {1}", targetType.getSimpleName(), name); logger.log(Level.SEVERE, ConfigApiLoggerInfo.TARGET_OBJ_NOT_FOUND, new Object[] {resolver.getClass().toString(), parentType, targetType}); result.failure(logger, msg); return; ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() { @Override public Object run(ConfigBeanProxy parentProxy) throws PropertyVetoException, TransactionFailure { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericDeleteCommand.transaction_exception", "Exception while deleting the configuration {0} :{1}", child.getImplementation(), e.getMessage()); result.failure(logger, msg);
private NetworkConfig getNetworkConfig() throws TransactionFailure { NetworkConfig config = currentConfig.getNetworkConfig(); if (config == null) { config = (NetworkConfig) ConfigSupport.apply(new SingleConfigCode<Config>() { public Object run(Config param) throws PropertyVetoException, TransactionFailure { final NetworkConfig netConfig = param.createChild(NetworkConfig.class); netConfig.setProtocols(netConfig.createChild(Protocols.class)); netConfig.setNetworkListeners(netConfig.createChild(NetworkListeners.class)); netConfig.setTransports(netConfig.createChild(Transports.class)); param.setNetworkConfig(netConfig); return netConfig; } }, currentConfig); } return config; }
@Override public Object run(ConfigBeanProxy parentProxy) throws PropertyVetoException, TransactionFailure { ConfigSupport._deleteChild(child.parent(), (WriteableView) Proxy.getInvocationHandler(parentProxy), child); DeletionDecorator<ConfigBeanProxy, ConfigBeanProxy> decorator = habitat.getService(delete.decorator()); if (decorator==null) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.deletion_decorator_not_found", "The DeletionDecorator {0} could not be found in the habitat,is it annotated with @Service ?", delete.decorator().toString()); result.failure(logger, msg); throw new TransactionFailure(msg); } else { // inject the decorator with any parameters from the initial CLI invocation manager.inject(decorator, paramResolver); // invoke the decorator decorator.decorate(context, parentProxy, tgt); } return null; } }, parentProxy);
if (matchingNodes.isEmpty()) { fail(context, localStrings.getLocalString("admin.set.configuration.notfound", "No configuration found for {0}", targetName)); return false; fail(context, localStrings.getLocalString("admin.set.configuration.notfound", "No configuration found for {0}", targetName)); return false; ConfigSupport.createAndSet((ConfigBean) parentNode, Property.class, attributes); success(context, targetName, value); runLegacyChecks(context); fail(context, localStrings.getLocalString("admin.set.attribute.change.failure", "Could not change the attributes: {0}", transactionFailure.getMessage()), transactionFailure); return false; ConfigSupport.deleteChild((ConfigBean) targetNode.parent(), (ConfigBean) targetNode); delPropertySuccess = true; } catch (TransactionFailure transactionFailure) { fail(context, localStrings.getLocalString("admin.set.attribute.change.failure", "Could not change the attributes: {0}", transactionFailure.getMessage()), transactionFailure); return false; config.apply(changes); success(context, targetName, value); runLegacyChecks(context);
private void createConfigElement(final String configElement) { try { ConfigSupport.apply(new SingleConfigCode<MonitoringService>() { public Object run(MonitoringService param) throws PropertyVetoException, TransactionFailure { ContainerMonitoring newItem = param.createChild(ContainerMonitoring.class); newItem.setName(configElement); param.getContainerMonitoring().add(newItem); return newItem; } }, monitoringService); } catch (TransactionFailure tf) { String msg = localStrings.getLocalString(cannotCreateConfigElement, "Unable to create container-monitoring for", configElement); logger.log(Level.SEVERE, msg, tf); } }
private void upgradeGroupManagementServiceElements() throws TransactionFailure { List<Config> lconfigs = configs.getConfig(); for (Config c : lconfigs) { LogRecord lr = new LogRecord(Level.FINE, "Upgrade config " + c.getName()); lr.setLoggerName(getClass().getName()); EarlyLogHandler.earlyMessages.add(lr); ConfigSupport.apply(new GroupManagementServiceConfigCode(), c); } }
/** * Returns the type of configuration object this config proxy represents. * @param element is the configuration object * @return the configuration interface class */ public static <T extends ConfigBeanProxy> Class<T> proxyType(T element) { ConfigView bean = getImpl(element); return bean.getProxyType(); }
private void updateThreadPool(NetworkConfig config, final ConnectionPool pool) throws TransactionFailure { final Config parent = config.getParent(Config.class); for (ThreadPool threadPool : parent.getThreadPools().getThreadPool()) { ConfigSupport.apply(new SingleConfigCode<ThreadPool>() { @Override public Object run(ThreadPool param) { param.setMaxQueueSize(pool.getQueueSizeInBytes()); if (param.getMinThreadPoolSize() == null || Integer.parseInt(param.getMinThreadPoolSize()) < 2) { param.setMinThreadPoolSize("2"); } return null; } }, threadPool); } } }
private void createWebContainerConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("web-container")) { SessionManager sm = defaultConfig.getWebContainer().getSessionConfig().getSessionManager(); ConfigSupport.apply(new WebContainerConfigCode(), sm); break; } } } }
@Override public void postConstruct() { // Listen to monitoring level changes Config c = habitat.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME); ts = c.getExtensionByType(TransactionService.class); ModuleMonitoringLevels mml = c.getMonitoringService().getModuleMonitoringLevels(); ((ObservableBean)ConfigSupport.getImpl(mml)).addListener(this); }