use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.
the class ReferenceConstrainClusterTest method clusterServerRefInvalid.
@Test
public void clusterServerRefInvalid() throws TransactionFailure {
Cluster cluster = habitat.getService(Cluster.class, "clusterA");
assertNotNull(cluster);
ServerRef sref = cluster.getServerRef().get(0);
ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("ref", "server-nonexist");
changes.put(serverConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
fail("Can not reach this point");
} catch (TransactionFailure tf) {
ConstraintViolationException cv = findConstrViolation(tf);
assertNotNull(cv);
}
}
use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.
the class ReferenceConstrainClusterTest method clusterServerRefValid.
@Test
public void clusterServerRefValid() throws TransactionFailure {
Cluster cluster = habitat.getService(Cluster.class, "clusterA");
assertNotNull(cluster);
ServerRef sref = cluster.getServerRef().get(0);
ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("ref", "server");
changes.put(serverConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
} catch (TransactionFailure tf) {
fail("Can not reach this point");
}
}
use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.
the class UpdateResourceRef method execute.
/**
* Execution method for updating the configuration of a ResourceRef. Will be
* replicated if the target is a cluster.
*
* @param context context for the command.
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
// Make a list of all ResourceRefs that need to change
List<ResourceRef> resourceRefsToChange = new ArrayList<>();
// Add the ResourceRef from a named server if the target is a server
Server server = domain.getServerNamed(target);
// if the target is a server
if (server != null) {
ResourceRef serverResourceRef = server.getResourceRef(name);
// if the ResourceRef doesn't exist
if (serverResourceRef == null) {
report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
return;
}
resourceRefsToChange.add(serverResourceRef);
}
// Add the ResourceRef from a named config if the target is a config
Config config = domain.getConfigNamed(target);
// if the target is a config
if (config != null) {
ResourceRef configResourceRef = config.getResourceRef(name);
// if the ResourceRef doesn't exist
if (configResourceRef == null) {
report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
return;
}
resourceRefsToChange.add(configResourceRef);
}
// Add the ResourceRefs from a named cluster if the target is a cluster
Cluster cluster = domain.getClusterNamed(target);
// if the target is a cluster
if (cluster != null) {
ResourceRef clusterResourceRef = cluster.getResourceRef(name);
// if the ResourceRef doesn't exist
if (clusterResourceRef == null) {
report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
return;
}
resourceRefsToChange.add(clusterResourceRef);
for (Server instance : cluster.getInstances()) {
ResourceRef instanceResourceRef = instance.getResourceRef(name);
// if the server in the cluster contains the ResourceRef
if (instanceResourceRef != null) {
resourceRefsToChange.add(instanceResourceRef);
}
}
}
// Add the ResourceRefs from a named Deployment Group if the target is a Deployment Group
DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
if (dg != null) {
ResourceRef ref = dg.getResourceRef(name);
if (ref == null) {
report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
return;
}
resourceRefsToChange.add(ref);
for (Server instance : dg.getInstances()) {
ResourceRef instanceResourceRef = instance.getResourceRef(name);
// if the server in the dg contains the ResourceRef
if (instanceResourceRef != null) {
resourceRefsToChange.add(instanceResourceRef);
}
}
}
// Apply the configuration to the listed ResourceRefs
try {
ConfigSupport.apply(new ConfigCode() {
@Override
public Object run(ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
for (ConfigBeanProxy proxy : params) {
if (proxy instanceof ResourceRef) {
ResourceRef resourceRefProxy = (ResourceRef) proxy;
if (enabled != null) {
resourceRefProxy.setEnabled(enabled.toString());
}
}
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return true;
}
}, resourceRefsToChange.toArray(new ResourceRef[] {}));
} catch (TransactionFailure ex) {
report.failure(logger, ex.getLocalizedMessage());
}
}
use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.
the class CollectLogFiles method getInstanceLogFileDirectory.
/*
This function is used to get log file details from logging.properties file for given target.
*/
private String getInstanceLogFileDirectory(Server targetServer) throws IOException {
String logFileDetailsForServer = "";
String targetConfigName = "";
Cluster clusterForInstance = targetServer.getCluster();
if (clusterForInstance != null) {
targetConfigName = clusterForInstance.getConfigRef();
} else {
targetConfigName = targetServer.getConfigRef();
}
logFileDetailsForServer = loggingConfig.getLoggingFileDetails(targetConfigName);
return logFileDetailsForServer;
}
use of com.sun.enterprise.config.serverbeans.Cluster 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);
}
}
Aggregations