Search in sources :

Example 1 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class CompiledSortCriterion method evaluate.

/**
   * evaluates sort criteria in order by clause
   */
public Object evaluate(Object data, ExecutionContext context) {
    Object value = null;
    if (this.columnIndex > 0) {
        value = ((Object[]) data)[this.columnIndex];
    } else if (this.columnIndex == 0) {
        if (data instanceof Object[]) {
            value = ((Object[]) data)[this.columnIndex];
        } else {
            value = data;
        }
    } else {
        throw new IllegalStateException(" Order By Column attribute unmapped");
    }
    context.setCurrentProjectionField(value);
    try {
        return this.expr.evaluate(context);
    } catch (Exception e) {
        // TODO: never throw an anonymous inner class
        throw new CacheException(e) {
        };
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) AmbiguousNameException(org.apache.geode.cache.query.AmbiguousNameException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) CacheException(org.apache.geode.cache.CacheException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException)

Example 2 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class PDXUtils method convertPDX.

public static Object convertPDX(Object obj, boolean isStruct, boolean getDomainObjectForPdx, boolean getDeserializedObject, boolean localResults, boolean[] objectChangedMarker, boolean isDistinct) {
    objectChangedMarker[0] = false;
    if (isStruct) {
        StructImpl simpl = (StructImpl) obj;
        if (getDomainObjectForPdx) {
            try {
                if (simpl.isHasPdx()) {
                    obj = simpl.getPdxFieldValues();
                    objectChangedMarker[0] = true;
                } else {
                    obj = simpl.getFieldValues();
                }
            } catch (Exception ex) {
                throw new CacheException("Unable to retrieve domain object from PdxInstance while building the ResultSet. " + ex.getMessage()) {
                };
            }
        } else {
            Object[] values = simpl.getFieldValues();
            if (getDeserializedObject) {
                for (int i = 0; i < values.length; i++) {
                    if (values[i] instanceof VMCachedDeserializable) {
                        values[i] = ((VMCachedDeserializable) values[i]).getDeserializedForReading();
                    }
                }
            }
            /* This is to convert PdxString to String */
            if (simpl.isHasPdx() && isDistinct && localResults) {
                for (int i = 0; i < values.length; i++) {
                    if (values[i] instanceof PdxString) {
                        values[i] = ((PdxString) values[i]).toString();
                    }
                }
            }
            obj = values;
        }
    } else {
        if (getDomainObjectForPdx) {
            if (obj instanceof PdxInstance) {
                try {
                    obj = ((PdxInstance) obj).getObject();
                    objectChangedMarker[0] = true;
                } catch (Exception ex) {
                    throw new CacheException("Unable to retrieve domain object from PdxInstance while building the ResultSet. " + ex.getMessage()) {
                    };
                }
            } else if (obj instanceof PdxString) {
                obj = ((PdxString) obj).toString();
            }
        } else if (isDistinct && localResults && obj instanceof PdxString) {
            /* This is to convert PdxString to String */
            obj = ((PdxString) obj).toString();
        }
        if (getDeserializedObject && obj instanceof VMCachedDeserializable) {
            obj = ((VMCachedDeserializable) obj).getDeserializedForReading();
            objectChangedMarker[0] = true;
        }
    }
    return obj;
}
Also used : StructImpl(org.apache.geode.cache.query.internal.StructImpl) PdxInstance(org.apache.geode.pdx.PdxInstance) CacheException(org.apache.geode.cache.CacheException) PdxString(org.apache.geode.pdx.internal.PdxString) VMCachedDeserializable(org.apache.geode.internal.cache.VMCachedDeserializable) CacheException(org.apache.geode.cache.CacheException)

Example 3 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class IndexCreationMsg method operateOnPartitionedRegion.

/**
   * This method actually operates on the partitioned region and creates given list of indexes from
   * a index creation message.
   * 
   * @param dm distribution manager.
   * @param pr partitioned region on which to create an index.
   * @throws CacheException indicating a cache level error
   * @throws ForceReattemptException if the peer is no longer available
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion pr, long startTime) throws CacheException, ForceReattemptException {
    // region exists
    ReplyException replyEx = null;
    boolean result = false;
    List<Index> indexes = null;
    List<String> failedIndexNames = new ArrayList<String>();
    if (logger.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        for (IndexCreationData icd : indexDefinitions) {
            sb.append(icd.getIndexName()).append(" ");
        }
        logger.debug("Processing index creation message on this remote partitioned region vm for indexes: {}", sb);
    }
    try {
        indexes = pr.createIndexes(true, indexDefinitions);
    } catch (IndexCreationException e1) {
        replyEx = new ReplyException(LocalizedStrings.IndexCreationMsg_REMOTE_INDEX_CREAION_FAILED.toLocalizedString(), e1);
    } catch (MultiIndexCreationException exx) {
        failedIndexNames.addAll(exx.getExceptionsMap().keySet());
        if (logger.isDebugEnabled()) {
            StringBuffer exceptionMsgs = new StringBuffer();
            for (Exception ex : exx.getExceptionsMap().values()) {
                exceptionMsgs.append(ex.getMessage()).append("\n");
            }
            logger.debug("Got an MultiIndexCreationException with \n: {}", exceptionMsgs);
            logger.debug("{} indexes were created succesfully", failedIndexNames.size());
        }
        replyEx = new ReplyException(LocalizedStrings.IndexCreationMsg_REMOTE_INDEX_CREAION_FAILED.toLocalizedString(), exx);
    }
    if (null == replyEx) {
        result = true;
    }
    if (result) {
        Map<String, Integer> indexBucketsMap = new HashMap<String, Integer>();
        for (Index index : indexes) {
            PartitionedIndex prIndex = (PartitionedIndex) index;
            indexBucketsMap.put(prIndex.getName(), prIndex.getNumberOfIndexedBuckets());
        }
        sendReply(getSender(), getProcessorId(), dm, replyEx, result, indexBucketsMap, pr.getDataStore().getAllLocalBuckets().size());
    } else {
        // add the indexes that were successfully created to the map
        Map<String, Integer> indexBucketsMap = new HashMap<String, Integer>();
        for (IndexCreationData icd : indexDefinitions) {
            // if the index was successfully created
            if (!failedIndexNames.contains(icd.getIndexName())) {
                PartitionedIndex prIndex = (PartitionedIndex) pr.getIndex(icd.getIndexName());
                indexBucketsMap.put(icd.getIndexName(), prIndex.getNumberOfIndexedBuckets());
            }
        }
        sendReply(getSender(), getProcessorId(), dm, replyEx, result, indexBucketsMap, pr.getDataStore().getAllLocalBuckets().size());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Multi Index creation completed on remote host and has sent the reply to the originating vm.");
    }
    return false;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Index(org.apache.geode.cache.query.Index) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) ReplyException(org.apache.geode.distributed.internal.ReplyException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) IndexCreationData(org.apache.geode.cache.query.internal.index.IndexCreationData) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException)

Example 4 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class PRFunctionStreamingResultCollector method getResult.

@Override
public Object getResult() throws FunctionException {
    if (this.resultCollected) {
        throw new FunctionException("Result already collected");
    }
    this.resultCollected = true;
    if (this.hasResult) {
        try {
            this.waitForCacheOrFunctionException(0);
            if (!this.execution.getFailedNodes().isEmpty() && !this.execution.isClientServerMode()) {
                // end the rc and clear it
                endResults();
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(this.fn);
                } else {
                    newRc = this.execution.execute(this.fn.getId());
                }
                return newRc.getResult();
            }
            if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
                throw new FunctionException(this.fites.get(0));
            }
        } catch (FunctionInvocationTargetException fite) {
            // the function.
            if (!execution.getWaitOnExceptionFlag()) {
                if (!this.fn.isHA()) {
                    throw new FunctionException(fite);
                } else if (execution.isClientServerMode()) {
                    clearResults();
                    FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.getMessage(), this.execution.getFailedNodes());
                    throw new FunctionException(iFITE);
                } else {
                    clearResults();
                    this.execution = this.execution.setIsReExecute();
                    ResultCollector newRc = null;
                    if (execution.isFnSerializationReqd()) {
                        newRc = this.execution.execute(this.fn);
                    } else {
                        newRc = this.execution.execute(this.fn.getId());
                    }
                    return newRc.getResult();
                }
            }
        } catch (BucketMovedException e) {
            if (!execution.getWaitOnExceptionFlag()) {
                if (!this.fn.isHA()) {
                    // endResults();
                    FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                    throw new FunctionException(fite);
                } else if (execution.isClientServerMode()) {
                    // endResults();
                    clearResults();
                    FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
                    throw new FunctionException(fite);
                } else {
                    // endResults();
                    clearResults();
                    this.execution = this.execution.setIsReExecute();
                    ResultCollector newRc = null;
                    if (execution.isFnSerializationReqd()) {
                        newRc = this.execution.execute(this.fn);
                    } else {
                        newRc = this.execution.execute(this.fn.getId());
                    }
                    return newRc.getResult();
                }
            }
        } catch (CacheClosedException e) {
            if (!execution.getWaitOnExceptionFlag()) {
                if (!this.fn.isHA()) {
                    // endResults();
                    FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                    throw new FunctionException(fite);
                } else if (execution.isClientServerMode()) {
                    // endResults();
                    clearResults();
                    FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage(), this.execution.getFailedNodes());
                    throw new FunctionException(fite);
                } else {
                    // endResults();
                    clearResults();
                    this.execution = this.execution.setIsReExecute();
                    ResultCollector newRc = null;
                    if (execution.isFnSerializationReqd()) {
                        newRc = this.execution.execute(this.fn);
                    } else {
                        newRc = this.execution.execute(this.fn.getId());
                    }
                    return newRc.getResult();
                }
            }
        } catch (CacheException e) {
            // endResults();
            throw new FunctionException(e);
        } catch (ForceReattemptException e) {
            // the function.
            if (!this.fn.isHA()) {
                throw new FunctionException(e);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(e.getMessage(), this.execution.getFailedNodes());
                throw new FunctionException(iFITE);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(this.fn);
                } else {
                    newRc = this.execution.execute(this.fn.getId());
                }
                return newRc.getResult();
            }
        }
    }
    return this.userRC.getResult();
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) CacheException(org.apache.geode.cache.CacheException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) InternalFunctionException(org.apache.geode.internal.cache.execute.InternalFunctionException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) FunctionStreamingResultCollector(org.apache.geode.internal.cache.execute.FunctionStreamingResultCollector) ResultCollector(org.apache.geode.cache.execute.ResultCollector)

Example 5 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class DistributedTXRegionStub method destroyExistingEntry.

public void destroyExistingEntry(EntryEventImpl event, boolean cacheWrite, Object expectedOldValue) {
    // this.prStats.incPartitionMessagesSent();
    try {
        RemoteOperationResponse response = RemoteDestroyMessage.send(state.getTarget(), event.getLocalRegion(), event, expectedOldValue, DistributionManager.PARTITIONED_REGION_EXECUTOR, true, false);
        response.waitForCacheException();
    } catch (EntryNotFoundException enfe) {
        throw enfe;
    } catch (TransactionDataNotColocatedException enfe) {
        throw enfe;
    } catch (CacheException ce) {
        throw new PartitionedRegionException(LocalizedStrings.PartitionedRegion_DESTROY_OF_ENTRY_ON_0_FAILED.toLocalizedString(state.getTarget()), ce);
    } catch (RegionDestroyedException rde) {
        throw new TransactionDataNotColocatedException(LocalizedStrings.RemoteMessage_REGION_0_NOT_COLOCATED_WITH_TRANSACTION.toLocalizedString(rde.getRegionFullPath()), rde);
    } catch (RemoteOperationException roe) {
        throw new TransactionDataNodeHasDepartedException(roe);
    }
}
Also used : PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) CacheException(org.apache.geode.cache.CacheException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) RemoteOperationException(org.apache.geode.internal.cache.RemoteOperationException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) RemoteOperationResponse(org.apache.geode.internal.cache.RemoteOperationMessage.RemoteOperationResponse) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException)

Aggregations

CacheException (org.apache.geode.cache.CacheException)638 Test (org.junit.Test)445 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)407 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)376 VM (org.apache.geode.test.dunit.VM)375 Region (org.apache.geode.cache.Region)351 Host (org.apache.geode.test.dunit.Host)330 AttributesFactory (org.apache.geode.cache.AttributesFactory)204 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)201 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)191 IOException (java.io.IOException)124 LocalRegion (org.apache.geode.internal.cache.LocalRegion)118 QueryService (org.apache.geode.cache.query.QueryService)107 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)85 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)85 SelectResults (org.apache.geode.cache.query.SelectResults)80 IgnoredException (org.apache.geode.test.dunit.IgnoredException)72 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)64 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)61 Cache (org.apache.geode.cache.Cache)59