Search in sources :

Example 26 with Cluster

use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.

the class ClusterHandler method getClusterForConfig.

@Handler(id = "gf.getClusterForConfig", input = { @HandlerInput(name = "configName", type = String.class, required = true) }, output = { @HandlerOutput(name = "cluster", type = String.class) })
public static void getClusterForConfig(HandlerContext handlerCtx) {
    String configName = (String) handlerCtx.getInputValue("configName");
    String clusterName = null;
    Domain domain = GuiUtil.getHabitat().getService(Domain.class);
    for (Cluster cluster : domain.getClusters().getCluster()) {
        if (cluster.getConfigRef().equals(configName)) {
            clusterName = cluster.getName();
            break;
        }
    }
    if (clusterName != null) {
        handlerCtx.setOutputValue("cluster", clusterName);
    } else {
    // 
    }
}
Also used : Cluster(com.sun.enterprise.config.serverbeans.Cluster) Domain(com.sun.enterprise.config.serverbeans.Domain) Handler(com.sun.jsftemplating.annotation.Handler)

Example 27 with Cluster

use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.

the class MigrateTimers method validateCluster.

private String validateCluster() {
    // verify fromServer is clusteredInstance
    Cluster fromServerCluster = targetUtil.getClusterForInstance(fromServer);
    if (fromServerCluster == null) {
        return localStrings.getString("migrate.timers.fromServerNotClusteredInstance", fromServer);
    }
    // verify fromServer is not running
    if (isServerRunning(fromServer)) {
        return localStrings.getString("migrate.timers.migrateFromServerStillRunning", fromServer);
    }
    // in the same cluster as fromServer
    if (target.equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
        List<Server> instances = fromServerCluster.getInstances();
        for (Server instance : instances) {
            if (instance.isRunning()) {
                target = instance.getName();
                needRedirect = true;
            }
        }
        // if destination is still DAS, that means no running server is available
        if (target.equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            return localStrings.getString("migrate.timers.noRunningInstanceToChoose", target);
        }
    } else {
        // verify fromServer and destinationServer are in the same cluster, and
        // verify destination is a clustered instance.
        Cluster destinationServerCluster = targetUtil.getClusterForInstance(target);
        if (!fromServerCluster.getName().equals(destinationServerCluster.getName())) {
            return localStrings.getString("migrate.timers.fromServerAndTargetNotInSameCluster", fromServer, target);
        }
        // verify destinationServer is running
        if (!isServerRunning(target)) {
            return localStrings.getString("migrate.timers.destinationServerIsNotAlive", target);
        }
    }
    return null;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Example 28 with Cluster

use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.

the class DeploymentCommandUtils method replicateEnableDisableToContainingCluster.

/**
 * Replicates an enable or disable command to all instances in the cluster
 * of which the target is a member.  If the target is not cluster member
 * this method is a no-op.
 * @param commandName name of the command to replicate to cluster instances
 * @param domain domain containing the relevant configuration
 * @param target name of the target being enabled or disabled
 * @param appName name of the application being enabled or disabled
 * @param habitat hk2 habitat
 * @param context command context passed to the running enable or disable command
 * @param command command object
 * @return
 */
public static ActionReport.ExitCode replicateEnableDisableToContainingCluster(final String commandName, final Domain domain, final String target, final String appName, final ServiceLocator habitat, final AdminCommandContext context, final AdminCommand command) throws IllegalArgumentException, IllegalAccessException {
    /*
         * If the target is a cluster instance, the DAS will broadcast the command
         * to all instances in the cluster so they can all update their configs.
         */
    final Cluster containingCluster = domain.getClusterForInstance(target);
    if (containingCluster != null) {
        final ParameterMapExtractor extractor = new ParameterMapExtractor(command);
        final ParameterMap pMap = extractor.extract(Collections.EMPTY_LIST);
        pMap.set("DEFAULT", appName);
        return ClusterOperationUtil.replicateCommand(commandName, FailurePolicy.Error, FailurePolicy.Warn, FailurePolicy.Ignore, containingCluster.getInstances(), context, pMap, habitat);
    }
    return ActionReport.ExitCode.SUCCESS;
}
Also used : ParameterMapExtractor(org.glassfish.common.util.admin.ParameterMapExtractor) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ParameterMap(org.glassfish.api.admin.ParameterMap)

Example 29 with Cluster

use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.

the class GetHostAndPortCommand method getAccessChecks.

@Override
public Collection<? extends AccessCheck> getAccessChecks() {
    final List<AccessCheck> accessChecks = new ArrayList<AccessCheck>();
    String configName = null;
    Server server = domain.getServerNamed(target);
    if (server != null) {
        configName = server.getConfigRef();
    } else {
        Cluster cluster = domain.getClusterNamed(target);
        if (cluster != null) {
            configName = cluster.getConfigRef();
        }
    }
    config = configs.getConfigByName(configName);
    if (config != null) {
        accessChecks.add(new AccessCheck(AccessRequired.Util.resourceNameFromConfigBeanProxy(config), "read"));
    }
    return accessChecks;
}
Also used : AccessCheck(org.glassfish.api.admin.AccessRequired.AccessCheck) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Server(com.sun.enterprise.config.serverbeans.Server) ArrayList(java.util.ArrayList) Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Example 30 with Cluster

use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.

the class CollectLogFiles method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Properties props = initFileXferProps();
    Server targetServer = domain.getServerNamed(target);
    if (targetServer != null && targetServer.isDas()) {
        // This loop if target instance is DAS
        String logFileDetails = "";
        String zipFile = "";
        try {
            // getting log file values from logging.propertie file.
            logFileDetails = loggingConfig.getLoggingFileDetails();
        } catch (Exception ex) {
            final String errorMsg = localStrings.getLocalString("collectlogfiles.errGettingLogFiles", "Error while getting log file attribute for {0}.", target);
            report.setMessage(errorMsg);
            report.setFailureCause(ex);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        File targetDir = makingDirectoryOnDas(targetServer.getName(), report);
        try {
            String sourceDir = "";
            if (logFileDetails.contains("${com.sun.aas.instanceRoot}/logs")) {
                sourceDir = env.getDomainRoot() + File.separator + "logs";
            } else {
                sourceDir = logFileDetails.substring(0, logFileDetails.lastIndexOf(File.separator));
            }
            copyLogFilesForLocalhost(sourceDir, targetDir.getAbsolutePath(), report, targetServer.getName());
        } catch (Exception ex) {
            final String errorMsg = localStrings.getLocalString("collectlogfiles.errInstanceDownloading", "Error while downloading log files from {0}.", target);
            report.setMessage(errorMsg);
            report.setFailureCause(ex);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        try {
            String zipFilePath = getZipFilePath().getAbsolutePath();
            zipFile = loggingConfig.createZipFile(zipFilePath);
            if (zipFile == null || new File(zipFile) == null) {
                // Failure during zip
                final String errorMsg = localStrings.getLocalString("collectlogfiles.creatingZip", "Error while creating zip file {0}.", zipFilePath);
                report.setMessage(errorMsg);
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        } catch (Exception e) {
            // Catching Exception if any
            final String errorMsg = localStrings.getLocalString("collectlogfiles.creatingZip", "Error while creating zip file {0}.", zipFile);
            report.setMessage(errorMsg);
            report.setFailureCause(e);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        if (this.retrieve) {
            retrieveFile(zipFile, context, getZipFilePath(), props, report);
            report.setMessage(localStrings.getLocalString("collectlogfiles.instance.success", "Created Zip file under {0}.", retrieveFilePath + File.separator + new File(zipFile).getName()));
        } else {
            report.setMessage(localStrings.getLocalString("collectlogfiles.instance.success", "Created Zip file under {0}.", zipFile));
        }
    } else if (targetServer != null && targetServer.isInstance()) {
        // This loop if target standalone instance
        String instanceName = targetServer.getName();
        String serverNode = targetServer.getNodeRef();
        Node node = domain.getNodes().getNode(serverNode);
        String zipFile = "";
        File targetDir = null;
        String logFileDetails = "";
        try {
            // getting log file values from logging.propertie file.
            logFileDetails = getInstanceLogFileDirectory(targetServer);
        } catch (Exception ex) {
            final String errorMsg = localStrings.getLocalString("collectlogfiles.errGettingLogFiles", "Error while getting log file attribute for {0}.", target);
            report.setMessage(errorMsg);
            report.setFailureCause(ex);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        targetDir = makingDirectoryOnDas(targetServer.getName(), report);
        try {
            if (node.isLocal()) {
                String sourceDir = getLogDirForLocalNode(logFileDetails, node, serverNode, instanceName);
                copyLogFilesForLocalhost(sourceDir, targetDir.getAbsolutePath(), report, instanceName);
            } else {
                new LogFilterForInstance().downloadAllInstanceLogFiles(habitat, targetServer, domain, LOGGER, instanceName, targetDir.getAbsolutePath(), logFileDetails);
            }
        } catch (Exception ex) {
            final String errorMsg = localStrings.getLocalString("collectlogfiles.errInstanceDownloading", "Error while downloading log files from {0}.", instanceName);
            report.setMessage(errorMsg);
            report.setFailureCause(ex);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        try {
            // Creating zip file and returning zip file absolute path.
            String zipFilePath = getZipFilePath().getAbsolutePath();
            zipFile = loggingConfig.createZipFile(zipFilePath);
            if (zipFile == null || new File(zipFile) == null) {
                // Failure during zip
                final String errorMsg = localStrings.getLocalString("collectlogfiles.creatingZip", "Error while creating zip file {0}.", zipFilePath);
                report.setMessage(errorMsg);
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        } catch (Exception ex) {
            final String errorMsg = localStrings.getLocalString("collectlogfiles.creatingZip", "Error while creating zip file {0}.", zipFile);
            report.setMessage(errorMsg);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        if (this.retrieve) {
            retrieveFile(zipFile, context, getZipFilePath(), props, report);
            report.setMessage(localStrings.getLocalString("collectlogfiles.instance.success", "Created Zip file under {0}.", retrieveFilePath + File.separator + new File(zipFile).getName()));
        } else {
            report.setMessage(localStrings.getLocalString("collectlogfiles.instance.success", "Created Zip file under {0}.", zipFile));
        }
    } else {
        // This loop if target is cluster
        String finalMessage = "";
        String zipFile = "";
        File targetDir = null;
        // code to download server.log file for DAS. Bug fix 16088
        String logFileDetails = "";
        try {
            // getting log file values from logging.propertie file.
            logFileDetails = loggingConfig.getLoggingFileDetails();
        } catch (Exception ex) {
            final String errorMsg = localStrings.getLocalString("collectlogfiles.errGettingLogFiles", "Error while getting log file attribute for {0}.", target);
            report.setMessage(errorMsg);
            report.setFailureCause(ex);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        targetDir = makingDirectoryOnDas(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME, report);
        try {
            String sourceDir = "";
            if (logFileDetails.contains("${com.sun.aas.instanceRoot}/logs")) {
                sourceDir = env.getDomainRoot() + File.separator + "logs";
            } else {
                sourceDir = logFileDetails.substring(0, logFileDetails.lastIndexOf(File.separator));
            }
            copyLogFilesForLocalhost(sourceDir, targetDir.getAbsolutePath(), report, SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME);
        } catch (Exception ex) {
            final String errorMsg = localStrings.getLocalString("collectlogfiles.errInstanceDownloading", "Error while downloading log files from {0}.", target);
            report.setMessage(errorMsg);
            report.setFailureCause(ex);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        /**
         ***************************************************
         */
        com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
        List<Server> instances = cluster.getInstances();
        int instanceCount = 0;
        int errorCount = 0;
        for (Server instance : instances) {
            // downloading log files for all instances which is part of cluster under temp directory.
            String instanceName = instance.getName();
            String serverNode = instance.getNodeRef();
            Node node = domain.getNodes().getNode(serverNode);
            boolean errorOccur = false;
            instanceCount++;
            logFileDetails = "";
            try {
                // getting log file values from logging.propertie file.
                logFileDetails = getInstanceLogFileDirectory(domain.getServerNamed(instanceName));
            } catch (Exception ex) {
                final String errorMsg = localStrings.getLocalString("collectlogfiles.errGettingLogFiles", "Error while getting log file attribute for {0}.", target);
                report.setMessage(errorMsg);
                report.setFailureCause(ex);
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            try {
                targetDir = makingDirectoryOnDas(instanceName, report);
                if (node.isLocal()) {
                    String sourceDir = getLogDirForLocalNode(logFileDetails, node, serverNode, instanceName);
                    copyLogFilesForLocalhost(sourceDir, targetDir.getAbsolutePath(), report, instanceName);
                } else {
                    new LogFilterForInstance().downloadAllInstanceLogFiles(habitat, instance, domain, LOGGER, instanceName, targetDir.getAbsolutePath(), logFileDetails);
                }
            } catch (Exception ex) {
                errorCount++;
                final String errorMsg = localStrings.getLocalString("collectlogfiles.errInstanceDownloading", "Error while downloading log files from {0}.", instanceName);
                errorOccur = true;
                finalMessage += errorMsg + "\n";
            }
            if (!errorOccur) {
                final String successMsg = localStrings.getLocalString("collectlogfiles.successInstanceDownloading", "Log files are downloaded for {0}.", instanceName);
                finalMessage += successMsg + "\n";
            }
        }
        report.setMessage(finalMessage);
        if (instanceCount != errorCount) {
            try {
                String zipFilePath = getZipFilePath().getAbsolutePath();
                // Creating zip file and returning zip file absolute path.
                zipFile = loggingConfig.createZipFile(zipFilePath);
                if (zipFile == null || new File(zipFile) == null) {
                    // Failure during zip
                    final String errorMsg = localStrings.getLocalString("collectlogfiles.creatingZip", "Error while creating zip file {0}.", zipFilePath);
                    report.setMessage(errorMsg);
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    return;
                }
            } catch (Exception ex) {
                final String errorMsg = localStrings.getLocalString("collectlogfiles.creatingZip", "Error while creating zip file {0}.", zipFile);
                report.setMessage(errorMsg);
                report.setFailureCause(ex);
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            if (this.retrieve) {
                retrieveFile(zipFile, context, getZipFilePath(), props, report);
                report.setMessage(localStrings.getLocalString("collectlogfiles.cluster.success", "{0} Created Zip file under {1}.", finalMessage, retrieveFilePath + File.separator + new File(zipFile).getName()));
            } else {
                report.setMessage(localStrings.getLocalString("collectlogfiles.cluster.success", "{0} Created Zip file under {1}.", finalMessage, zipFile));
            }
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else if (instanceCount == 0) {
            report.setMessage(localStrings.getLocalString("collectlogfiles.noinstance", "No instances are defined as part of {0}. So there are no files to zip.", target));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        } else {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
    deleteDir(new File(env.getInstanceRoot() + File.separator + "collected-logs" + File.separator + "logs"));
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Node(com.sun.enterprise.config.serverbeans.Node) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ArrayList(java.util.ArrayList) List(java.util.List) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) File(java.io.File) IOException(java.io.IOException) LogFilterForInstance(com.sun.enterprise.server.logging.logviewer.backend.LogFilterForInstance)

Aggregations

Cluster (com.sun.enterprise.config.serverbeans.Cluster)45 Server (com.sun.enterprise.config.serverbeans.Server)26 ActionReport (org.glassfish.api.ActionReport)12 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)9 Domain (com.sun.enterprise.config.serverbeans.Domain)8 HashMap (java.util.HashMap)8 Config (com.sun.enterprise.config.serverbeans.Config)6 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)5 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)5 PropertyVetoException (java.beans.PropertyVetoException)5 Test (org.junit.Test)5 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)4 Logger (java.util.logging.Logger)4 ConfigBean (org.jvnet.hk2.config.ConfigBean)4 ConfigSupport (org.jvnet.hk2.config.ConfigSupport)4 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)3 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)3