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 {
//
}
}
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;
}
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;
}
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;
}
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"));
}
Aggregations