use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.
the class GlassFishClusterExecutor method execute.
/**
* <p>Execute the passed command on targeted remote instances. The list of remote
* instances is usually retrieved from the passed parameters (with a "target"
* parameter for instance) or from the configuration.
*
* <p>Each remote execution must return a different ActionReport so the user
* or framework can get feedback on the success or failure or such executions.
*
* @param commandName the command to execute
* @param context the original command context
* @param parameters the parameters passed to the original local command
* @return an array of @{link org.glassfish.api.ActionReport} for each remote
* execution status.
*/
@Override
public ActionReport.ExitCode execute(String commandName, AdminCommand command, AdminCommandContext context, ParameterMap parameters) {
CommandModel model = command instanceof CommandModelProvider ? ((CommandModelProvider) command).getModel() : new CommandModelImpl(command.getClass());
org.glassfish.api.admin.ExecuteOn clAnnotation = model.getClusteringAttributes();
List<RuntimeType> runtimeTypes = new ArrayList<RuntimeType>();
@ExecuteOn
final class DefaultExecuteOn {
}
if (clAnnotation == null) {
clAnnotation = DefaultExecuteOn.class.getAnnotation(ExecuteOn.class);
}
if (clAnnotation.value().length == 0) {
runtimeTypes.add(RuntimeType.DAS);
runtimeTypes.add(RuntimeType.INSTANCE);
} else {
runtimeTypes.addAll(Arrays.asList(clAnnotation.value()));
}
String targetName = parameters.getOne("target");
if (targetName == null)
targetName = "server";
// only if the target is not "server" or "domain"
if ((runtimeTypes.contains(RuntimeType.ALL)) || ((!CommandTarget.DAS.isValid(habitat, targetName)) && (!CommandTarget.DOMAIN.isValid(habitat, targetName)))) {
// If the target is a cluster and dynamic reconfig enabled is false and RuntimeType is not ALL, no replication
if (targetService.isCluster(targetName) && !runtimeTypes.contains(RuntimeType.ALL)) {
String dynRecfg = targetService.getClusterConfig(targetName).getDynamicReconfigurationEnabled();
if (Boolean.FALSE.equals(Boolean.valueOf(dynRecfg))) {
ActionReport aReport = context.getActionReport().addSubActionsReport();
aReport.setActionExitCode(ActionReport.ExitCode.WARNING);
aReport.setMessage(STRINGS.getLocalString("glassfish.clusterexecutor.dynrecfgdisabled", "WARNING: The command was not replicated to all cluster instances because the" + " dynamic-reconfig-enabled flag is set to false for cluster {0}", targetName));
for (Server s : targetService.getInstances(targetName)) {
instanceState.setState(s.getName(), InstanceState.StateType.RESTART_REQUIRED, false);
instanceState.addFailedCommandToInstance(s.getName(), commandName, parameters);
}
return ActionReport.ExitCode.WARNING;
}
}
List<Server> instancesForReplication = new ArrayList<Server>();
if (runtimeTypes.contains(RuntimeType.ALL)) {
List<Server> allInstances = targetService.getAllInstances();
Set<String> clusterNoReplication = new HashSet<String>();
for (Server s : allInstances) {
String dynRecfg = s.getConfig().getDynamicReconfigurationEnabled();
if (Boolean.TRUE.equals(Boolean.valueOf(dynRecfg))) {
instancesForReplication.add(s);
} else {
clusterNoReplication.add(s.getCluster().getName());
instanceState.setState(s.getName(), InstanceState.StateType.RESTART_REQUIRED, false);
instanceState.addFailedCommandToInstance(s.getName(), commandName, parameters);
}
}
if (!clusterNoReplication.isEmpty()) {
ActionReport aReport = context.getActionReport().addSubActionsReport();
aReport.setActionExitCode(ActionReport.ExitCode.WARNING);
aReport.setMessage(STRINGS.getLocalString("glassfish.clusterexecutor.dynrecfgdisabled", "WARNING: The command was not replicated to all cluster instances because the" + " dynamic-reconfiguration-enabled flag is set to false for cluster(s) {0}", clusterNoReplication));
}
} else {
instancesForReplication = targetService.getInstances(targetName);
}
if (instancesForReplication.isEmpty()) {
ActionReport aReport = context.getActionReport().addSubActionsReport();
aReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
aReport.setMessage(STRINGS.getLocalString("glassfish.clusterexecutor.notargets", "Did not find any suitable instances for target {0}; command executed on DAS only", targetName));
return ActionReport.ExitCode.SUCCESS;
}
return (ClusterOperationUtil.replicateCommand(commandName, clAnnotation.ifFailure(), clAnnotation.ifOffline(), clAnnotation.ifNeverStarted(), instancesForReplication, context, parameters, habitat));
}
return ActionReport.ExitCode.SUCCESS;
}
use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.
the class ListNodesHelper method getNodeList.
public String getNodeList() {
StringBuilder sb = new StringBuilder();
boolean firstNode = true;
for (Node n : nodeList) {
String nodeType = n.getType();
if ((!listType.equals(nodeType) && !listType.equals("ALL")) || nodeType.equals("TEMP")) {
continue;
}
String name = n.getName();
String host = n.getNodeHost();
String installDir = n.getInstallDir();
if (firstNode) {
firstNode = false;
} else {
sb.append(EOL);
}
if (terse) {
sb.append(name);
} else if (!long_opt) {
sb.append(name).append(" ").append(nodeType).append(" ").append(host);
}
if (long_opt) {
List<Server> serversOnNode = servers.getServersOnNode(n);
StringBuilder instanceList = new StringBuilder();
if (!serversOnNode.isEmpty()) {
int i = 0;
for (Server server : serversOnNode) {
if (i > 0)
instanceList.append(", ");
instanceList.append(server.getName());
i++;
}
}
NodeInfo ni = new NodeInfo(name, host, installDir, nodeType, instanceList.toString());
infos.add(ni);
}
}
if (long_opt) {
return NodeInfo.format(infos);
} else {
return sb.toString();
}
}
use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.
the class SynchronizeFiles method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
logger = context.getLogger();
SyncRequest sr = null;
try {
// read the input document
JAXBContext jc = JAXBContext.newInstance(SyncRequest.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
// XXX - needed?
unmarshaller.setSchema(null);
sr = (SyncRequest) unmarshaller.unmarshal(fileList);
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, "SynchronizeFiles: synchronize dir {0}", sr.dir);
}
} catch (Exception ex) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("SynchronizeFiles: Exception reading request");
logger.fine(ex.toString());
}
report.setActionExitCode(ExitCode.FAILURE);
report.setMessage(strings.getLocalString("sync.exception.reading", "SynchronizeFiles: Exception reading request"));
report.setFailureCause(ex);
return;
}
try {
// verify the server instance is valid
Server server = null;
if (servers != null)
server = servers.getServer(sr.instance);
if (server == null) {
report.setActionExitCode(ExitCode.FAILURE);
report.setMessage(strings.getLocalString("sync.unknown.instance", "Unknown server instance: {0}", sr.instance));
return;
}
sync.synchronize(server, sr, context.getOutboundPayload(), report, logger);
stateService.setState(server.getName(), InstanceState.StateType.NO_RESPONSE, true);
stateService.removeFailedCommandsForInstance(server.getName());
} catch (Exception ex) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("SynchronizeFiles: Exception processing request");
logger.fine(ex.toString());
}
report.setActionExitCode(ExitCode.FAILURE);
report.setMessage(strings.getLocalString("sync.exception.processing", "SynchronizeFiles: Exception processing request"));
report.setFailureCause(ex);
}
}
use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.
the class LogManagerService method getLoggingProperties.
/**
* Returns properties based on the DAS/Cluster/Instance
*/
@Override
public Map<String, String> getLoggingProperties() throws IOException {
Server targetServer = domain.getServerNamed(env.getInstanceName());
// Find the logging config
LoggingConfig loggingConfig = loggingConfigFactory.provide();
if (targetServer != null && !targetServer.isDas()) {
if (targetServer.getCluster() != null) {
loggingConfig = loggingConfigFactory.provide(targetServer.getCluster().getConfigRef());
} else if (targetServer.isInstance()) {
loggingConfig = loggingConfigFactory.provide(targetServer.getConfigRef());
}
}
// Validate the properties
Map<String, String> props = loggingConfig.getLoggingProperties();
Map<String, String> invalidProps = validateProps(props);
if (!invalidProps.isEmpty()) {
loggingConfig.deleteLoggingProperties(invalidProps);
props = loggingConfig.getLoggingProperties();
}
return props;
}
use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.
the class MEJBNamingObjectProxy method deployMEJB.
private void deployMEJB() throws IOException {
_logger.info("Loading MEJB app on JNDI look up");
ServerContext serverContext = habitat.getService(ServerContext.class);
File mejbArchive = new File(serverContext.getInstallRoot(), "lib/install/applications/mejb.jar");
DeployCommandParameters deployParams = new DeployCommandParameters(mejbArchive);
String targetName = habitat.<Server>getService(Server.class, ServerEnvironment.DEFAULT_INSTANCE_NAME).getName();
deployParams.target = targetName;
deployParams.name = "mejb";
ActionReport report = habitat.getService(ActionReport.class, "plain");
Deployment deployment = habitat.getService(Deployment.class);
ExtendedDeploymentContext dc = deployment.getBuilder(_logger, deployParams, report).source(mejbArchive).build();
deployment.deploy(dc);
if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
throw new RuntimeException("Failed to deploy MEJB app: " + report.getFailureCause());
}
}
Aggregations