Search in sources :

Example 21 with Server

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;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) org.glassfish.api.admin(org.glassfish.api.admin) ActionReport(org.glassfish.api.ActionReport) CommandModelImpl(org.glassfish.common.util.admin.CommandModelImpl)

Example 22 with Server

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();
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) NodeInfo(com.sun.enterprise.util.cluster.NodeInfo) Node(com.sun.enterprise.config.serverbeans.Node)

Example 23 with Server

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);
    }
}
Also used : SyncRequest(com.sun.enterprise.util.cluster.SyncRequest) Server(com.sun.enterprise.config.serverbeans.Server) ActionReport(org.glassfish.api.ActionReport)

Example 24 with Server

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;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) LoggingConfig(com.sun.common.util.logging.LoggingConfig)

Example 25 with Server

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());
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ServerContext(org.glassfish.internal.api.ServerContext) Server(com.sun.enterprise.config.serverbeans.Server) Deployment(org.glassfish.internal.deployment.Deployment) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) File(java.io.File)

Aggregations

Server (com.sun.enterprise.config.serverbeans.Server)101 ActionReport (org.glassfish.api.ActionReport)32 Cluster (com.sun.enterprise.config.serverbeans.Cluster)25 Domain (com.sun.enterprise.config.serverbeans.Domain)15 Node (com.sun.enterprise.config.serverbeans.Node)15 Config (com.sun.enterprise.config.serverbeans.Config)14 Properties (java.util.Properties)14 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 PropertyVetoException (java.beans.PropertyVetoException)11 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)9 ParameterMap (org.glassfish.api.admin.ParameterMap)9 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)8 File (java.io.File)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)8 Logger (java.util.logging.Logger)7 Map (java.util.Map)6 ServerContext (org.glassfish.internal.api.ServerContext)6