use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class DeleteLogLevel method execute.
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
boolean isCluster = false;
boolean isDas = false;
boolean isInstance = false;
StringBuffer successMsg = new StringBuffer();
boolean isConfig = false;
boolean success = false;
String targetConfigName = "";
Map<String, String> m = new HashMap<String, String>();
try {
String[] loggerNames = properties.split("(?<!\\\\):");
for (final Object key : loggerNames) {
final String logger_name = (String) key;
m.put(logger_name + ".level", null);
}
Config config = domain.getConfigNamed(target);
if (config != null) {
targetConfigName = target;
isConfig = true;
Server targetServer = domain.getServerNamed(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME);
if (targetServer != null && targetServer.getConfigRef().equals(target)) {
isDas = true;
}
targetServer = null;
} else {
Server targetServer = domain.getServerNamed(target);
if (targetServer != null && targetServer.isDas()) {
isDas = true;
} else {
com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
if (cluster != null) {
isCluster = true;
targetConfigName = cluster.getConfigRef();
} else if (targetServer != null) {
isInstance = true;
targetConfigName = targetServer.getConfigRef();
}
}
if (isInstance) {
Cluster clusterForInstance = targetServer.getCluster();
if (clusterForInstance != null) {
targetConfigName = clusterForInstance.getConfigRef();
}
}
}
if (isCluster || isInstance) {
loggingConfig.deleteLoggingProperties(m, targetConfigName);
success = true;
} else if (isDas) {
loggingConfig.deleteLoggingProperties(m);
success = true;
} else if (isConfig) {
// This loop is for the config which is not part of any target
loggingConfig.deleteLoggingProperties(m, targetConfigName);
success = true;
} else {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
String msg = localStrings.getLocalString("invalid.target.sys.props", "Invalid target: {0}. Valid default target is a server named ''server'' (default) or cluster name.", target);
report.setMessage(msg);
return;
}
if (success) {
successMsg.append(localStrings.getLocalString("delete.log.level.success", "These logging levels are deleted for {0}.", target));
report.setMessage(successMsg.toString());
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
} catch (IOException e) {
report.setMessage(localStrings.getLocalString("delete.log.level.failed", "Could not delete logger levels for {0}.", target));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class SetConfigOrdinal method execute.
@Override
public void execute(AdminCommandContext context) {
Config configVal = targetUtil.getConfig(target);
MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.class);
if (serviceConfig != null) {
try {
// to perform a transaction on the domain.xml you need to use this construct
// see https://github.com/hk2-project/hk2/blob/master/hk2-configuration/persistence/hk2-xml-dom/hk2-config/src/main/java/org/jvnet/hk2/config/ConfigSupport.java
ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>() {
@Override
public Object run(MicroprofileConfigConfiguration config) {
switch(source) {
case "domain":
{
config.setDomainOrdinality(Integer.toString(ordinal));
break;
}
case "config":
{
config.setConfigOrdinality(Integer.toString(ordinal));
break;
}
case "server":
{
config.setServerOrdinality(Integer.toString(ordinal));
break;
}
case "application":
{
config.setApplicationOrdinality(Integer.toString(ordinal));
break;
}
case "module":
{
config.setModuleOrdinality(Integer.toString(ordinal));
break;
}
case "cluster":
{
config.setClusterOrdinality(Integer.toString(ordinal));
break;
}
case "jndi":
{
config.setJNDIOrdinality(Integer.toString(ordinal));
break;
}
case "secrets":
{
config.setSecretDirOrdinality(Integer.toString(ordinal));
break;
}
}
return null;
}
}, serviceConfig);
} catch (TransactionFailure ex) {
// set failure
context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "Failed to update message", ex);
}
} else {
context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "No configuration with name " + target);
}
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class ConfigConfigSource method setValue.
public boolean setValue(final String propertyName, final String propertyValue) throws TransactionFailure {
boolean success = false;
Config config = domainConfiguration.getConfigs().getConfigByName(configurationName);
if (config != null) {
Property p = config.getProperty(PROPERTY_PREFIX + propertyName);
if (p == null) {
ConfigSupport.apply(new SingleConfigCode<Config>() {
@Override
public Object run(Config config) throws TransactionFailure, PropertyVetoException {
Property prop = config.createChild(Property.class);
prop.setName(PROPERTY_PREFIX + propertyName);
prop.setValue(propertyValue);
config.getProperty().add(prop);
return null;
}
}, config);
} else {
ConfigSupport.apply(new SingleConfigCode<Property>() {
@Override
public Object run(Property config) throws TransactionFailure, PropertyVetoException {
config.setValue(propertyValue);
return null;
}
}, p);
}
success = true;
}
return success;
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class ConfigConfigSource method deleteValue.
public boolean deleteValue(String propertyName) throws TransactionFailure {
boolean result = false;
Config config = domainConfiguration.getConfigs().getConfigByName(configurationName);
if (config != null) {
for (Property object : config.getProperty()) {
if ((PROPERTY_PREFIX + propertyName).equals(object.getName())) {
ConfigSupport.deleteChild((ConfigBean) ConfigBean.unwrap(config), (ConfigBean) ConfigBean.unwrap(object));
result = true;
}
}
}
return result;
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class ConfigConfigSource method getValue.
@Override
public String getValue(String propertyName) {
String result = null;
Config config = domainConfiguration.getConfigs().getConfigByName(configurationName);
if (config != null) {
result = config.getPropertyValue(PROPERTY_PREFIX + propertyName);
}
return result;
}
Aggregations