use of org.apache.geode.GemFireIOException in project geode by apache.
the class DiskStoreUpgrader method main.
public static void main(String[] args) {
String errorString = null;
String stackTraceString = null;
String diskStoreName = null;
String diskDirsStr = null;
String[] diskDirs = null;
String maxOpLogSize = null;
long maxOplogSize = -1;
if (args.length < 3) {
throw new IllegalArgumentException("Requires 3 arguments : <diskStoreName> <diskDirs> <maxOpLogSize>");
}
Properties prop = new Properties();
try {
prop.load(new StringReader(args[0] + GfshParser.LINE_SEPARATOR + args[1] + GfshParser.LINE_SEPARATOR + args[2]));
} catch (IOException e) {
throw new IllegalArgumentException("Requires 3 arguments : <diskStoreName> <diskDirs> <maxOpLogSize>");
}
try {
diskStoreName = prop.getProperty(CliStrings.UPGRADE_OFFLINE_DISK_STORE__NAME);
diskDirsStr = prop.getProperty(CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS);
diskDirs = diskDirsStr.split(",");
maxOpLogSize = prop.getProperty(CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE);
maxOplogSize = Long.valueOf(maxOpLogSize);
upgrade(diskStoreName, diskDirs, maxOplogSize);
} catch (GemFireIOException e) {
Throwable cause = e.getCause();
if (cause instanceof IllegalStateException) {
String message = cause.getMessage();
if (stringMatches(LocalizedStrings.DiskInitFile_THE_INIT_FILE_0_DOES_NOT_EXIST.toLocalizedString("(.*)"), message)) {
errorString = CliStrings.format(CliStrings.UPGRADE_OFFLINE_DISK_STORE__MSG__CANNOT_LOCATE_0_DISKSTORE_IN_1, diskStoreName, CliUtil.arrayToString(diskDirs));
} else {
errorString = message;
}
} else if (cause instanceof DiskAccessException) {
boolean isKnownCause = false;
Throwable nestedCause = cause.getCause();
if (nestedCause instanceof IOException) {
String message = nestedCause.getMessage();
if (stringMatches(LocalizedStrings.Oplog_THE_FILE_0_IS_BEING_USED_BY_ANOTHER_PROCESS.toLocalizedString("(.*)"), message)) {
errorString = CliStrings.UPGRADE_OFFLINE_DISK_STORE__MSG__DISKSTORE_IN_USE_COMPACT_DISKSTORE_CAN_BE_USED;
isKnownCause = true;
}
}
if (!isKnownCause) {
errorString = CliStrings.format(CliStrings.UPGRADE_OFFLINE_DISK_STORE__MSG__CANNOT_ACCESS_DISKSTORE_0_FROM_1_CHECK_GFSH_LOGS, new Object[] { diskStoreName, CliUtil.arrayToString(diskDirs) });
}
} else {
// which are other known exceptions?
errorString = e.getMessage();
}
stackTraceString = CliUtil.stackTraceAsString(e);
} catch (IllegalArgumentException e) {
errorString = e.getMessage();
stackTraceString = CliUtil.stackTraceAsString(e);
} finally {
if (errorString != null) {
System.err.println(errorString);
}
if (stackTraceString != null) {
System.err.println(STACKTRACE_START);
System.err.println(stackTraceString);
}
}
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class EntryEventImpl method getSerializedValue.
public byte[] getSerializedValue() {
if (this.newValueBytes == null) {
final Object val;
val = basicGetNewValue();
if (val instanceof byte[]) {
return (byte[]) val;
} else if (val instanceof CachedDeserializable) {
return ((CachedDeserializable) val).getSerializedValue();
}
try {
return CacheServerHelper.serialize(val);
} catch (IOException ioe) {
throw new GemFireIOException("unexpected exception", ioe);
}
} else {
return this.newValueBytes;
}
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class LogWriterAppenders method createLogWriterAppender.
/**
* Creates the log writer appender for a distributed system based on the system's parsed
* configuration. The initial banner and messages are also entered into the log by this method.
*
* @param isLoner Whether the distributed system is a loner or not
* @param isSecurity Whether a log for security related messages has to be created
* @param config The DistributionConfig for the target distributed system
* @param logConfig if true log the configuration
* @throws GemFireIOException if the log file can't be opened for writing
*/
static LogWriterAppender createLogWriterAppender(final boolean appendToFile, final boolean isLoner, final boolean isSecurity, final LogConfig config, final boolean logConfig) {
final boolean isDistributionConfig = config instanceof DistributionConfig;
final DistributionConfig dsConfig = isDistributionConfig ? (DistributionConfig) config : null;
File logFile = config.getLogFile();
String firstMsg = null;
boolean firstMsgWarning = false;
AlertAppender.getInstance().setAlertingDisabled(isLoner);
// security-log-file is specified in DistributionConfig
if (isSecurity) {
if (isDistributionConfig) {
File tmpLogFile = dsConfig.getSecurityLogFile();
if (tmpLogFile != null && !tmpLogFile.equals(new File(""))) {
logFile = tmpLogFile;
}
} else {
throw new IllegalArgumentException("DistributionConfig is expected for SecurityLogWriter");
}
}
// log-file is NOT specified in DistributionConfig
if (logFile == null || logFile.equals(new File(""))) {
// out = System.out;
return null;
}
// if logFile exists attempt to rename it for rolling
if (logFile.exists()) {
final boolean useChildLogging = config.getLogFile() != null && !config.getLogFile().equals(new File("")) && config.getLogFileSizeLimit() != 0;
final boolean statArchivesRolling = isDistributionConfig && dsConfig.getStatisticArchiveFile() != null && !dsConfig.getStatisticArchiveFile().equals(new File("")) && dsConfig.getArchiveFileSizeLimit() != 0 && dsConfig.getStatisticSamplingEnabled();
if (!appendToFile || useChildLogging || statArchivesRolling) {
// check useChildLogging for
// bug 50659
final File oldMain = ManagerLogWriter.getLogNameForOldMainLog(logFile, isSecurity || useChildLogging || statArchivesRolling);
final boolean succeeded = LogFileUtils.renameAggressively(logFile, oldMain);
if (succeeded) {
firstMsg = LocalizedStrings.InternalDistributedSystem_RENAMED_OLD_LOG_FILE_TO_0.toLocalizedString(oldMain);
} else {
firstMsgWarning = true;
firstMsg = LocalizedStrings.InternalDistributedSystem_COULD_NOT_RENAME_0_TO_1.toLocalizedString(new Object[] { logFile, oldMain });
}
}
}
// create a FileOutputStream to the logFile
FileOutputStream fos;
try {
fos = new FileOutputStream(logFile, true);
} catch (FileNotFoundException ex) {
String s = LocalizedStrings.InternalDistributedSystem_COULD_NOT_OPEN_LOG_FILE_0.toLocalizedString(logFile);
throw new GemFireIOException(s, ex);
}
final PrintStream out = new PrintStream(fos);
// create the ManagerLogWriter that LogWriterAppender will wrap
ManagerLogWriter mlw = null;
String logWriterLoggerName = null;
if (isSecurity) {
mlw = new SecurityManagerLogWriter(dsConfig.getSecurityLogLevel(), out, config.getName());
logWriterLoggerName = LogService.SECURITY_LOGGER_NAME;
} else {
mlw = new ManagerLogWriter(config.getLogLevel(), out, config.getName());
logWriterLoggerName = LogService.MAIN_LOGGER_NAME;
}
mlw.setConfig(config);
// if (mlw.infoEnabled()) { -- skip here and instead do this in LogWriterFactory when creating
// the LogWriterLogger
// if (!isLoner /* do this on a loner to fix bug 35602 */
// || !Boolean.getBoolean(InternalLocator.INHIBIT_DM_BANNER)) {
// mlw.info(Banner.getString(null));
// }
// }
AppenderContext[] appenderContext = new AppenderContext[1];
if (isSecurity) {
appenderContext[0] = LogService.getAppenderContext(LogService.SECURITY_LOGGER_NAME);
} else {
// ROOT or
appenderContext[0] = LogService.getAppenderContext();
// gemfire.logging.appenders.LOGGER
}
// create the LogWriterAppender that delegates to ManagerLogWriter;
final LogWriterAppender appender = LogWriterAppender.create(appenderContext, logWriterLoggerName, mlw, fos);
// #51819
if (!isSecurity && LogService.MAIN_LOGGER_NAME.equals(logWriterLoggerName) && LogService.isUsingGemFireDefaultConfig()) {
LogService.removeConsoleAppender();
}
// log the first msg about renaming logFile for rolling if it pre-existed
final InternalLogWriter logWriter = mlw;
if (firstMsg != null) {
if (firstMsgWarning) {
logWriter.warning(firstMsg);
} else {
logWriter.info(firstMsg);
}
}
// log the config
if (logConfig) {
if (!isLoner) {
// LOG:CONFIG: changed from config to info
logWriter.info(LocalizedStrings.InternalDistributedSystem_STARTUP_CONFIGURATIONN_0, config.toLoggerString());
}
}
// LOG: do NOT allow redirectOutput
if (ALLOW_REDIRECT) {
// fix #46493 by moving redirectOutput invocation here
if (ProcessLauncherContext.isRedirectingOutput()) {
try {
OSProcess.redirectOutput(config.getLogFile());
} catch (IOException e) {
logWriter.error(e);
// throw new GemFireIOException("Unable to redirect output to " + config.getLogFile(), e);
}
}
}
return appender;
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class ProductUseLog method createLogWriter.
private synchronized void createLogWriter() {
FileOutputStream fos;
try {
fos = new FileOutputStream(productUseLogFile, true);
} catch (FileNotFoundException ex) {
String s = LocalizedStrings.InternalDistributedSystem_COULD_NOT_OPEN_LOG_FILE_0.toLocalizedString(productUseLogFile);
throw new GemFireIOException(s, ex);
}
PrintStream out = new PrintStream(fos);
this.logWriter = new PureLogWriter(this.logLevel, out);
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class RuntimeDistributionConfigImpl method setStatisticArchiveFile.
@Override
public void setStatisticArchiveFile(File value) {
value = (File) checkAttribute(STATISTIC_ARCHIVE_FILE, value);
if (value == null) {
value = new File("");
}
try {
this.ds.getStatSampler().changeArchive(value);
} catch (GemFireIOException ex) {
throw new IllegalArgumentException(ex.getMessage());
}
this.statisticArchiveFile = value;
getAttSourceMap().put(STATISTIC_ARCHIVE_FILE, ConfigSource.runtime());
}
Aggregations