Search in sources :

Example 1 with GemFireException

use of org.apache.geode.GemFireException in project geode by apache.

the class StartVsdCommand method startVsd.

@CliCommand(value = CliStrings.START_VSD, help = CliStrings.START_VSD__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_M_AND_M, CliStrings.TOPIC_GEODE_STATISTICS })
public Result startVsd(@CliOption(key = CliStrings.START_VSD__FILE, help = CliStrings.START_VSD__FILE__HELP) final String[] statisticsArchiveFilePathnames) {
    try {
        String geodeHome = System.getenv("GEODE_HOME");
        assertState(StringUtils.isNotBlank(geodeHome), CliStrings.GEODE_HOME_NOT_FOUND_ERROR_MESSAGE);
        assertState(IOUtils.isExistingPathname(getPathToVsd()), String.format(CliStrings.START_VSD__NOT_FOUND_ERROR_MESSAGE, geodeHome));
        String[] vsdCommandLine = createdVsdCommandLine(statisticsArchiveFilePathnames);
        if (isDebugging()) {
            getGfsh().printAsInfo(String.format("GemFire VSD command-line (%1$s)", Arrays.toString(vsdCommandLine)));
        }
        Process vsdProcess = Runtime.getRuntime().exec(vsdCommandLine);
        getGfsh().printAsInfo(CliStrings.START_VSD__RUN);
        String vsdProcessOutput = waitAndCaptureProcessStandardErrorStream(vsdProcess);
        InfoResultData infoResultData = ResultBuilder.createInfoResultData();
        if (StringUtils.isNotBlank(vsdProcessOutput)) {
            infoResultData.addLine(StringUtils.LINE_SEPARATOR);
            infoResultData.addLine(vsdProcessOutput);
        }
        return ResultBuilder.buildResult(infoResultData);
    } catch (GemFireException | IllegalStateException | IllegalArgumentException | FileNotFoundException e) {
        return ResultBuilder.createShellClientErrorResult(e.getMessage());
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.START_VSD__ERROR_MESSAGE, toString(t, false)));
    }
}
Also used : GemFireException(org.apache.geode.GemFireException) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) FileNotFoundException(java.io.FileNotFoundException) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 2 with GemFireException

use of org.apache.geode.GemFireException in project geode by apache.

the class SingleHopClientExecutor method submitAllHA.

static boolean submitAllHA(List callableTasks, LocalRegion region, boolean isHA, ResultCollector rc, Set<String> failedNodes) {
    ClientMetadataService cms = region.getCache().getClientMetadataService();
    boolean reexecute = false;
    if (callableTasks != null && !callableTasks.isEmpty()) {
        List futures = null;
        try {
            futures = execService.invokeAll(callableTasks);
        } catch (RejectedExecutionException rejectedExecutionEx) {
            throw rejectedExecutionEx;
        } catch (InterruptedException e) {
            throw new InternalGemFireException(e.getMessage());
        }
        if (futures != null) {
            GemFireException functionExecutionException = null;
            Iterator futureItr = futures.iterator();
            Iterator taskItr = callableTasks.iterator();
            final boolean isDebugEnabled = logger.isDebugEnabled();
            while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
                Future fut = (Future) futureItr.next();
                SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
                ServerLocation server = task.getServer();
                try {
                    fut.get();
                    if (isDebugEnabled) {
                        logger.debug("ExecuteRegionFunctionSingleHopOp#got result from {}", server);
                    }
                } catch (InterruptedException e) {
                    throw new InternalGemFireException(e.getMessage());
                } catch (ExecutionException ee) {
                    if (ee.getCause() instanceof InternalFunctionInvocationTargetException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.InternalFunctionInvocationTargetException : Caused by :{}", ee.getCause());
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return false;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        reexecute = true;
                        failedNodes.addAll(((InternalFunctionInvocationTargetException) ee.getCause()).getFailedNodeSet());
                        // Clear the results only if isHA so that partial results can be returned.
                        if (isHA) {
                            rc.clearResults();
                        } else {
                            if (ee.getCause().getCause() != null) {
                                functionExecutionException = new FunctionInvocationTargetException(ee.getCause().getCause());
                            } else {
                                functionExecutionException = new FunctionInvocationTargetException(new BucketMovedException(LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE.toLocalizedString()));
                            }
                        }
                    } else if (ee.getCause() instanceof FunctionException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.FunctionException : Caused by :{}", ee.getCause());
                        }
                        FunctionException fe = (FunctionException) ee.getCause();
                        if (isHA) {
                            throw fe;
                        } else {
                            functionExecutionException = fe;
                        }
                    } else if (ee.getCause() instanceof ServerOperationException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerOperationException : Caused by :{}", ee.getCause());
                        }
                        ServerOperationException soe = (ServerOperationException) ee.getCause();
                        if (isHA) {
                            throw soe;
                        } else {
                            functionExecutionException = soe;
                        }
                    } else if (ee.getCause() instanceof ServerConnectivityException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerConnectivityException : Caused by :{} The failed server is: {}", ee.getCause(), server);
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return false;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        // Clear the results only if isHA so that partial results can be returned.
                        if (isHA) {
                            reexecute = true;
                            rc.clearResults();
                        } else {
                            functionExecutionException = (ServerConnectivityException) ee.getCause();
                        }
                    } else {
                        throw executionThrowable(ee.getCause());
                    }
                }
            }
            if (functionExecutionException != null) {
                throw functionExecutionException;
            }
        }
    }
    return reexecute;
}
Also used : InternalGemFireException(org.apache.geode.InternalGemFireException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) FunctionException(org.apache.geode.cache.execute.FunctionException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) InternalGemFireException(org.apache.geode.InternalGemFireException) GemFireException(org.apache.geode.GemFireException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) Iterator(java.util.Iterator) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) Future(java.util.concurrent.Future) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) List(java.util.List) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with GemFireException

use of org.apache.geode.GemFireException in project geode by apache.

the class QueueManagerImpl method getAllConnections.

public QueueConnections getAllConnections() {
    ConnectionList snapshot = queueConnections;
    if (snapshot.getPrimary() == null) {
        // wait for a new primary to become available.
        synchronized (lock) {
            snapshot = queueConnections;
            while (snapshot.getPrimary() == null && !snapshot.primaryDiscoveryFailed() && !shuttingDown && pool.getPoolOrCacheCancelInProgress() == null) {
                try {
                    lock.wait();
                } catch (InterruptedException ignore) {
                    Thread.currentThread().interrupt();
                    break;
                }
                snapshot = queueConnections;
            }
        }
    }
    if (snapshot.getPrimary() == null) {
        pool.getCancelCriterion().checkCancelInProgress(null);
        GemFireException exception = snapshot.getPrimaryDiscoveryException();
        if (exception == null || exception instanceof NoSubscriptionServersAvailableException) {
            exception = new NoSubscriptionServersAvailableException(exception);
        } else {
            exception = new ServerConnectivityException(exception.getMessage(), exception);
        }
        throw exception;
    }
    return snapshot;
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) GemFireException(org.apache.geode.GemFireException) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException)

Example 4 with GemFireException

use of org.apache.geode.GemFireException in project geode by apache.

the class StatArchiveHandler method handleArchiverException.

private void handleArchiverException(GemFireException ex) {
    if (this.archiver.getSampleCount() > 0) {
        StringWriter sw = new StringWriter();
        ex.printStackTrace(new PrintWriter(sw, true));
        logger.warn(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.HostStatSampler_STATISTIC_ARCHIVER_SHUTTING_DOWN_BECAUSE__0, sw));
    }
    try {
        this.archiver.close();
    } catch (GemFireException ignore) {
        if (this.archiver.getSampleCount() > 0) {
            logger.warn(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.HostStatSampler_STATISIC_ARCHIVER_SHUTDOWN_FAILED_BECAUSE__0, ignore.getMessage()));
        }
    }
    if (this.archiver.getSampleCount() == 0 && this.archiveId != -1) {
        // dec since we didn't use the file and close deleted it.
        this.archiveId--;
    }
    this.archiver = null;
}
Also used : GemFireException(org.apache.geode.GemFireException) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 5 with GemFireException

use of org.apache.geode.GemFireException in project geode by apache.

the class StatArchiveHandler method changeArchiveFile.

/**
   * Changes the archive file to the new file or disables archiving if an empty string is specified.
   * <p/>
   * If the file name matches any archive file(s) already in {@link #archiveDir} then this may
   * trigger rolling and/or removal if appropriate based on
   * {@link StatArchiveHandlerConfig#getArchiveFileSizeLimit() file size limit} and
   * {@link StatArchiveHandlerConfig#getArchiveDiskSpaceLimit() disk space limit}.
   * <p/>
   * If resetHandler is true, then this handler will reset itself with the SampleCollector by
   * removing and re-adding itself in order to receive allocation notifications about all resource
   * types and instances.
   * 
   * @param newFile
   * @param resetHandler
   * @param nanosTimeStamp
   */
private void changeArchiveFile(File newFile, boolean resetHandler, long nanosTimeStamp) {
    final boolean isDebugEnabled_STATISTICS = logger.isTraceEnabled(LogMarker.STATISTICS);
    if (isDebugEnabled_STATISTICS) {
        logger.trace(LogMarker.STATISTICS, "StatArchiveHandler#changeArchiveFile newFile={}, nanosTimeStamp={}", newFile, nanosTimeStamp);
    }
    StatArchiveWriter newArchiver = null;
    boolean archiveClosed = false;
    if (newFile.getPath().equals("")) {
        // disable archiving
        if (!this.disabledArchiving) {
            this.disabledArchiving = true;
            logger.info(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_DISABLING_STATISTIC_ARCHIVAL));
        }
    } else {
        this.disabledArchiving = false;
        if (this.config.getArchiveFileSizeLimit() != 0) {
            // to getRollingArchiveName(newFile).
            if (archiver != null) {
                archiveClosed = true;
                synchronized (this) {
                    if (resetHandler) {
                        if (isDebugEnabled_STATISTICS) {
                            logger.trace(LogMarker.STATISTICS, "StatArchiveHandler#changeArchiveFile removing handler");
                        }
                        this.collector.removeSampleHandler(this);
                    }
                    try {
                        archiver.close();
                    } catch (GemFireException ignore) {
                        logger.warn(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_STATISTIC_ARCHIVE_CLOSE_FAILED_BECAUSE__0, ignore.getMessage()));
                    }
                }
            }
        }
        if (newFile.exists()) {
            File oldFile;
            if (this.config.getArchiveFileSizeLimit() != 0) {
                oldFile = getRollingArchiveName(newFile, archiveClosed);
            } else {
                oldFile = getRenameArchiveName(newFile);
            }
            if (!newFile.renameTo(oldFile)) {
                logger.warn(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_COULD_NOT_RENAME_0_TO_1, new Object[] { newFile, oldFile }));
            } else {
                logger.info(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_RENAMED_OLD_EXISTING_ARCHIVE_TO__0_, oldFile));
            }
        } else {
            if (!newFile.getAbsoluteFile().getParentFile().equals(archiveDir)) {
                this.archiveDir = newFile.getAbsoluteFile().getParentFile();
                if (!this.archiveDir.exists()) {
                    this.archiveDir.mkdirs();
                }
            }
            if (this.config.getArchiveFileSizeLimit() != 0) {
                initMainArchiveId(newFile);
            }
        }
        try {
            StatArchiveDescriptor archiveDescriptor = new StatArchiveDescriptor.Builder().setArchiveName(newFile.getAbsolutePath()).setSystemId(this.config.getSystemId()).setSystemStartTime(this.config.getSystemStartTime()).setSystemDirectoryPath(this.config.getSystemDirectoryPath()).setProductDescription(this.config.getProductDescription()).build();
            newArchiver = new StatArchiveWriter(archiveDescriptor);
            newArchiver.initialize(nanosTimeStamp);
        } catch (GemFireIOException ex) {
            logger.warn(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_COULD_NOT_OPEN_STATISTIC_ARCHIVE_0_CAUSE_1, new Object[] { newFile, ex.getLocalizedMessage() }));
            throw ex;
        }
    }
    synchronized (this) {
        if (archiveClosed) {
            if (archiver != null) {
                removeOldArchives(newFile, this.config.getArchiveDiskSpaceLimit());
            }
        } else {
            if (resetHandler) {
                if (isDebugEnabled_STATISTICS) {
                    logger.trace(LogMarker.STATISTICS, "StatArchiveHandler#changeArchiveFile removing handler");
                }
                this.collector.removeSampleHandler(this);
            }
            if (archiver != null) {
                try {
                    archiver.close();
                } catch (GemFireException ignore) {
                    logger.warn(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_STATISTIC_ARCHIVE_CLOSE_FAILED_BECAUSE__0, ignore.getMessage()));
                }
                removeOldArchives(newFile, this.config.getArchiveDiskSpaceLimit());
            }
        }
        archiver = newArchiver;
        if (resetHandler && newArchiver != null) {
            if (isDebugEnabled_STATISTICS) {
                logger.trace(LogMarker.STATISTICS, "StatArchiveHandler#changeArchiveFile adding handler");
            }
            this.collector.addSampleHandler(this);
        }
    }
}
Also used : GemFireException(org.apache.geode.GemFireException) GemFireIOException(org.apache.geode.GemFireIOException) File(java.io.File)

Aggregations

GemFireException (org.apache.geode.GemFireException)12 ExecutionException (java.util.concurrent.ExecutionException)3 Future (java.util.concurrent.Future)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 CliMetaData (org.apache.geode.management.cli.CliMetaData)3 CliCommand (org.springframework.shell.core.annotation.CliCommand)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InternalGemFireError (org.apache.geode.InternalGemFireError)2 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)2 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)2 InfoResultData (org.apache.geode.management.internal.cli.result.InfoResultData)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Iterator (java.util.Iterator)1 List (java.util.List)1 GemFireIOException (org.apache.geode.GemFireIOException)1