private void validate( ConfigBeanProxy check, String key, String defaultFormat, String... arguments) throws ValidationFailureException { if (check == null) { report.setMessage(localStrings.getLocalString(key, defaultFormat, arguments)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); throw new ValidationFailureException(); } }
@Override public void execute(AdminCommandContext context) { final ActionReport actionReport = context.getActionReport(); Properties extraProperties = actionReport.getExtraProperties(); if (extraProperties == null) { extraProperties = new Properties(); actionReport.setExtraProperties(extraProperties); } Config config = targetUtil.getConfig(target); final NotificationServiceConfiguration notificationServiceConfiguration = config.getExtensionByType(NotificationServiceConfiguration.class); if (notificationServiceConfiguration != null) { try { ConfigSupport.apply( new SingleConfigCode<NotificationServiceConfiguration>() { @Override public Object run( final NotificationServiceConfiguration notificationServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure { if (enabled != null) { notificationServiceConfigurationProxy.enabled(enabled.toString()); } actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); return notificationServiceConfigurationProxy; } }, notificationServiceConfiguration); } catch (TransactionFailure ex) { logger.log(Level.WARNING, "Exception during command ", ex); actionReport.setMessage(ex.getCause().getMessage()); actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } if (dynamic) { if (server.isDas()) { if (targetUtil.getConfig(target).isDas()) { service.getExecutionOptions().setEnabled(enabled); } } else { // apply as not the DAS so implicitly it is for us service.getExecutionOptions().setEnabled(enabled); } } }
private File makingDirectory(File parent, String path, ActionReport report, String errorMsg) { File targetDir = new File(parent, path); boolean created = false; if (!targetDir.exists()) { created = targetDir.mkdir(); if (!created) { report.setMessage(errorMsg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return null; } else { return targetDir; } } else { return targetDir; } }
/** * Executes the command with the command parameters passed as Properties where the keys are the * paramter names and the values the parameter values * * @param context information */ public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); HashMap attrList = new HashMap(); setAttributeList(attrList); ResourceStatus rs; try { rs = managedExecutorServiceMgr.create(domain.getResources(), attrList, properties, target); } catch (Exception e) { report.setMessage( localStrings.getLocalString( "create.managed.executor.service.failed", "Managed executor service {0} creation failed", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS; if (rs.getMessage() != null) { report.setMessage(rs.getMessage()); } if (rs.getStatus() == ResourceStatus.FAILURE) { ec = ActionReport.ExitCode.FAILURE; if (rs.getException() != null) report.setFailureCause(rs.getException()); } report.setActionExitCode(ec); }
@Override public void create(final CreateSsl command, ActionReport report) { NetworkConfig netConfig = command.config.getNetworkConfig(); // ensure we have the specified listener NetworkListener listener = netConfig.getNetworkListener(command.listenerId); Protocol httpProtocol; try { if (listener == null) { report.setMessage( WebContainer.rb.getString( MessageFormat.format(CREATE_SSL_HTTP_NOT_FOUND, command.listenerId))); httpProtocol = command.findOrCreateProtocol(command.listenerId); } else { httpProtocol = listener.findHttpProtocol(); Ssl ssl = httpProtocol.getSsl(); if (ssl != null) { report.setMessage( WebContainer.rb.getString( MessageFormat.format(CREATE_SSL_HTTP_ALREADY_EXISTS, command.listenerId))); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } ConfigSupport.apply( new SingleConfigCode<Protocol>() { public Object run(Protocol param) throws TransactionFailure { Ssl newSsl = param.createChild(Ssl.class); command.populateSslElement(newSsl); param.setSsl(newSsl); return newSsl; } }, httpProtocol); } catch (TransactionFailure e) { command.reportError(report, e); } command.reportSuccess(report); }
private boolean validate(ActionReport actionReport) { boolean result = false; if (value != null) { try { int thresholdValue = Integer.parseInt(value); if (thresholdValue <= 0 || thresholdValue > Short.MAX_VALUE * 2) { actionReport.failure( logger, "Threshold Value must be greater than zero or less than " + Short.MAX_VALUE * 2 + 1); return result; } } catch (NumberFormatException nfe) { actionReport.failure(logger, "Threshold Value is not a valid integer", nfe); return result; } } if (unit != null) { try { if (!unit.equals("NANOSECONDS") && !unit.equals("MICROSECONDS") && !unit.equals("MILLISECONDS") && !unit.equals("SECONDS") && !unit.equals("MINUTES") && !unit.equals("HOURS") && !unit.equals("DAYS")) { actionReport.failure(logger, unit + " is an invalid time unit"); return result; } } catch (IllegalArgumentException iaf) { actionReport.failure(logger, unit + " is an invalid time unit", iaf); return result; } } return true; }
@Override public void delete(DeleteSsl command, ActionReport report) { NetworkConfig netConfig = command.config.getNetworkConfig(); NetworkListener networkListener = netConfig.getNetworkListener(command.listenerId); if (networkListener == null) { report.setMessage( WebContainer.rb.getString( MessageFormat.format(DELETE_SSL_HTTP_LISTENER_NOT_FOUND, command.listenerId))); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } Protocol protocol = networkListener.findHttpProtocol(); if (protocol.getSsl() == null) { report.setMessage( WebContainer.rb.getString( MessageFormat.format(DELETE_SSL_ELEMENT_DOES_NOT_EXIST, command.listenerId))); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } try { ConfigSupport.apply( new SingleConfigCode<Protocol>() { public Object run(Protocol param) { param.setSsl(null); return null; } }, networkListener.findHttpProtocol()); } catch (TransactionFailure e) { command.reportError(report, e); } }
public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); final Logger logger = context.getLogger(); try { validateTarget(target, name); } catch (IllegalArgumentException ie) { report.setMessage(ie.getMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } DeployCommandParameters commandParams = new DeployCommandParameters(); commandParams.name = name; commandParams.enabled = enabled; commandParams.description = description; commandParams.target = target; // create a dummy context to hold params and props ExtendedDeploymentContext deploymentContext = new DeploymentContextImpl(report, logger, null, commandParams, null); Properties appProps = deploymentContext.getAppProps(); if (property != null) { appProps.putAll(property); } // set to default "user", deployers can override it appProps.setProperty(ServerTags.OBJECT_TYPE, "user"); appProps.setProperty(ServerTags.CLASS_NAME, classname); if (classpath != null) { appProps.setProperty(ServerTags.CLASSPATH, classpath); } if (loadorder != null) { appProps.setProperty(ServerTags.LOAD_ORDER, loadorder); } appProps.setProperty(ServerTags.IS_FAILURE_FATAL, failurefatal.toString()); appProps.setProperty(ServerTags.IS_LIFECYCLE, "true"); try { Transaction t = deployment.prepareAppConfigChanges(deploymentContext); deployment.registerAppInDomainXML(null, deploymentContext, t); } catch (Exception e) { report.setMessage("Failed to create lifecycle module: " + e); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); }
/** * Disable the enabled version of the application if it exists. This method is used in versioning * context. * * @param appName application's name * @param target an option supply from admin command, it's retained for compatibility with other * releases * @param report ActionReport, report object to send back to client. * @param subject the Subject on whose behalf to run */ public void handleDisable( final String appName, final String target, final ActionReport report, final Subject subject) throws VersioningSyntaxException { Set<String> versionsToDisable = Collections.EMPTY_SET; if (DeploymentUtils.isDomainTarget(target)) { // retrieve the enabled versions on each target in the domain Map<String, Set<String>> enabledVersions = getEnabledVersionsInReferencedTargets(appName); if (!enabledVersions.isEmpty()) { versionsToDisable = enabledVersions.keySet(); } } else { // retrieve the currently enabled version of the application String enabledVersion = getEnabledVersion(appName, target); if (enabledVersion != null && !enabledVersion.equals(appName)) { versionsToDisable = new HashSet<String>(); versionsToDisable.add(enabledVersion); } } Iterator<String> it = versionsToDisable.iterator(); while (it.hasNext()) { String currentVersion = it.next(); // invoke disable if the currently enabled version is not itself if (currentVersion != null && !currentVersion.equals(appName)) { final ParameterMap parameters = new ParameterMap(); parameters.add("DEFAULT", currentVersion); parameters.add("target", target); ActionReport subReport = report.addSubActionsReport(); CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("disable", subReport, subject); inv.parameters(parameters).execute(); } } }
/** * Executes the command with the command parameters passed as Properties where the keys are the * parameter names and the values the parameter values * * @param context information */ public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); try { Collection<ManagedExecutorService> managedExecutorServices = domain.getResources().getResources(ManagedExecutorService.class); List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>(); List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class); for (ManagedExecutorService managedExecutorService : managedExecutorServices) { String jndiName = managedExecutorService.getJndiName(); if (bindableResourcesHelper.resourceExists(jndiName, target)) { ActionReport.MessagePart part = report.getTopMessagePart().addChild(); part.setMessage(jndiName); Map<String, String> resourceNameMap = new HashMap<String, String>(); String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName); if (logicalName != null) { resourceNameMap.put("logical-jndi-name", logicalName); } resourceNameMap.put("name", jndiName); resourcesList.add(resourceNameMap); } } Properties extraProperties = new Properties(); extraProperties.put("managedExecutorServices", resourcesList); report.setExtraProperties(extraProperties); } catch (Exception e) { report.setMessage( localStrings.getLocalString( "list.managed.executor.service.failed", "List managed executor services failed")); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); }
@Override public void execute(AdminCommandContext context) { ActionReport actionReport = context.getActionReport(); Properties extraProperties = actionReport.getExtraProperties(); if (extraProperties == null) { extraProperties = new Properties(); actionReport.setExtraProperties(extraProperties); } try { calculateHeaders(); helper.checkAndInitializeBatchRuntime(); glassFishBatchSecurityHelper.markInvocationPrivilege(true); executeCommand(context, extraProperties); actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch (Exception ex) { logger.log(Level.FINE, "Exception during command ", ex); actionReport.setMessage(ex.getMessage()); actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); } finally { glassFishBatchSecurityHelper.markInvocationPrivilege(false); } }
@Override public void execute(AdminCommandContext context) { Target targetUtil = habitat.getComponent(Target.class); Config newConfig = targetUtil.getConfig(target); if (newConfig != null) { config = newConfig; } report = context.getActionReport(); try { final Protocols protocols = config.getNetworkConfig().getProtocols(); final Protocol protocol = protocols.findProtocol(protocolName); validate( protocol, "create.http.fail.protocolnotfound", "The specified protocol {0} is not yet configured", protocolName); final Class<?> filterClass = Thread.currentThread().getContextClassLoader().loadClass(classname); if (!com.sun.grizzly.ProtocolFilter.class.isAssignableFrom(filterClass)) { report.setMessage( localStrings.getLocalString( "create.portunif.fail.notfilter", "{0} create failed. Given class is not a ProtocolFilter: {1}", name, classname)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } ProtocolChainInstanceHandler handler = getHandler(protocol); ProtocolChain chain = getChain(handler); ConfigSupport.apply( new SingleConfigCode<ProtocolChain>() { @Override public Object run(ProtocolChain param) throws PropertyVetoException, TransactionFailure { final List<ProtocolFilter> list = param.getProtocolFilter(); for (ProtocolFilter filter : list) { if (name.equals(filter.getName())) { throw new TransactionFailure( String.format("A protocol filter named %s already exists.", name)); } } final ProtocolFilter filter = param.createChild(ProtocolFilter.class); filter.setName(name); filter.setClassname(classname); list.add(filter); return null; } }, chain); } catch (ValidationFailureException e) { return; } catch (Exception e) { e.printStackTrace(); report.setMessage( localStrings.getLocalString( "create.portunif.fail", "{0} create failed: {1}", name, e.getMessage() == null ? "No reason given" : e.getMessage())); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } }
private void retrieveFile( String zipFileName, AdminCommandContext context, File tempDirectory, Properties props, ActionReport report) { // Playing with outbound payload to attach zip file.. Payload.Outbound outboundPayload = context.getOutboundPayload(); // GLASSFISH-17627: pass to DownloadServlet boolean retrieveFiles = false; if (outboundPayload == null) { outboundPayload = PayloadImpl.Outbound.newInstance(); retrieveFiles = true; } // code to files to output directory try { // GLASSFISH-17627: ignore zipFile, but add files directly, similarly to zipFile List<File> files = new ArrayList<File>(Arrays.asList(tempDirectory.listFiles())); for (int i = 0; i < files.size(); i++) { File file = files.get(i); // if the file is directory, "recurse" if (file.isDirectory()) { files.addAll(Arrays.asList(file.listFiles())); continue; } if (file.getAbsolutePath().contains(".zip")) { continue; } outboundPayload.attachFile( "application/octet-stream", tempDirectory.toURI().relativize(file.toURI()), "files", props, file); } if (retrieveFiles) { File targetLocalFile = new File(retrieveFilePath); // CAUTION: file instead of dir if (targetLocalFile.exists()) { throw new Exception("File exists"); } if (!targetLocalFile.getParentFile().exists()) { throw new Exception("Parent directory does not exist"); } FileOutputStream targetStream = null; try { targetStream = new FileOutputStream(targetLocalFile); outboundPayload.writeTo(targetStream); targetStream.flush(); } finally { if (targetStream != null) targetStream.close(); } } } catch (Exception ex) { final String errorMsg = localStrings.getLocalString( "collectlogfiles.copyingZip", "Error while copying zip file to {0}.", retrieveFilePath); report.setMessage(errorMsg); report.setFailureCause(ex); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } }
private void copyLogFilesForLocalhost( String sourceDir, String targetDir, ActionReport report, String instanceName) throws IOException { // Getting all Log Files File logsDir = new File(sourceDir); File allLogFileNames[] = logsDir.listFiles(); if (allLogFileNames == null) { throw new IOException(""); } for (File logFile : allLogFileNames) { if (logFile.isFile()) { // File to copy in output file path. File toFile = new File(targetDir, logFile.getName()); FileInputStream from = null; FileOutputStream to = null; // Copying File try { from = new FileInputStream(logFile); to = new FileOutputStream(toFile); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead); // write } catch (Exception ex) { final String errorMsg = localStrings.getLocalString( "collectlogfiles.errInstanceDownloading", "Error while downloading log file from {0}.", instanceName); report.setMessage(errorMsg); report.setFailureCause(ex); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } finally { if (from != null) try { from.close(); } catch (Exception ex) { } if (to != null) try { to.close(); } catch (Exception ex) { } } if (!toFile.exists()) { final String errorMsg = localStrings.getLocalString( "collectlogfiles.errInstanceDownloading", "Error while downloading log file from {0}.", instanceName); report.setMessage(errorMsg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } } }
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")); }
@Override public void execute(AdminCommandContext context) { final AdminCommandContext theContext = context; final ActionReport actionReport = context.getActionReport(); Properties extraProperties = actionReport.getExtraProperties(); if (extraProperties == null) { extraProperties = new Properties(); actionReport.setExtraProperties(extraProperties); } if (!validate(actionReport)) { return; } Config config = targetUtil.getConfig(target); final RequestTracingServiceConfiguration requestTracingServiceConfiguration = config.getExtensionByType(RequestTracingServiceConfiguration.class); if (requestTracingServiceConfiguration != null) { try { ConfigSupport.apply( new SingleConfigCode<RequestTracingServiceConfiguration>() { @Override public Object run( final RequestTracingServiceConfiguration requestTracingServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure { if (enabled != null) { requestTracingServiceConfigurationProxy.enabled(enabled.toString()); } if (unit != null) { requestTracingServiceConfigurationProxy.setThresholdUnit(unit); } if (value != null) { requestTracingServiceConfigurationProxy.setThresholdValue(value); } actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); return requestTracingServiceConfigurationProxy; } }, requestTracingServiceConfiguration); } catch (TransactionFailure ex) { logger.log(Level.WARNING, "Exception during command ", ex); actionReport.setMessage(ex.getCause().getMessage()); actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } if (dynamic) { if (server.isDas()) { if (targetUtil.getConfig(target).isDas()) { service.getExecutionOptions().setEnabled(enabled); if (value != null) { service.getExecutionOptions().setThresholdValue(Long.valueOf(value)); actionReport.appendMessage( strings.getLocalString( "requesttracing.configure.thresholdvalue.success", "Request Tracing Service Threshold Value is set to {0}.", value) + "\n"); } if (unit != null) { service.getExecutionOptions().setThresholdUnit(TimeUnit.valueOf(unit)); actionReport.appendMessage( strings.getLocalString( "requesttracing.configure.thresholdunit.success", "Request Tracing Service Threshold Unit is set to {0}.", unit) + "\n"); } } } else { service.getExecutionOptions().setEnabled(enabled); if (value != null) { service.getExecutionOptions().setThresholdValue(Long.valueOf(value)); actionReport.appendMessage( strings.getLocalString( "requesttracing.configure.thresholdvalue.success", "Request Tracing Service Threshold Value is set to {0}.", value) + "\n"); } if (unit != null) { service.getExecutionOptions().setThresholdUnit(TimeUnit.valueOf(unit)); actionReport.appendMessage( strings.getLocalString( "requesttracing.configure.thresholdunit.success", "Request Tracing Service Threshold Unit is set to {0}.", unit) + "\n"); } } } }