Search in sources :

Example 66 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class RevokePersistentIDRequest method createResponse.

@Override
protected AdminResponse createResponse(DistributionManager dm) {
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null && !cache.isClosed()) {
        PersistentMemberManager mm = cache.getPersistentMemberManager();
        mm.revokeMember(this.pattern);
    }
    return new RevokePersistentIDResponse(this.getSender());
}
Also used : PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 67 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class RootRegionResponse method create.

/**
   * Returns a {@code RootRegionResponse} that will be returned to the specified recipient. The
   * message will contains a copy of the local manager's system config.
   */
public static RootRegionResponse create(DistributionManager dm, InternalDistributedMember recipient) {
    RootRegionResponse m = new RootRegionResponse();
    try {
        InternalCache cache = (InternalCache) CacheFactory.getInstance(dm.getSystem());
        final Collection roots;
        if (!Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "PRDebug")) {
            roots = cache.rootRegions();
        } else {
            roots = cache.rootRegions(true);
        }
        List regionNames = new ArrayList();
        List userAttributes = new ArrayList();
        for (Object root : roots) {
            Region r = (Region) root;
            regionNames.add(r.getName());
            userAttributes.add(CacheDisplay.getCachedObjectDisplay(r.getUserAttribute(), GemFireVM.LIGHTWEIGHT_CACHE_VALUE));
        }
        String[] temp = new String[0];
        m.regions = (String[]) regionNames.toArray(temp);
        m.userAttrs = (String[]) userAttributes.toArray(temp);
        ;
    } catch (CancelException ignore) {
    /* no cache yet */
    }
    m.setRecipient(recipient);
    return m;
}
Also used : ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) Collection(java.util.Collection) Region(org.apache.geode.cache.Region) ArrayList(java.util.ArrayList) List(java.util.List) CancelException(org.apache.geode.CancelException)

Example 68 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class MissingPersistentIDsRequest method createResponse.

@Override
protected AdminResponse createResponse(DistributionManager dm) {
    Set<PersistentID> missingIds = new HashSet<>();
    Set<PersistentID> localPatterns = new HashSet<>();
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null && !cache.isClosed()) {
        PersistentMemberManager mm = cache.getPersistentMemberManager();
        Map<String, Set<PersistentMemberID>> waitingRegions = mm.getWaitingRegions();
        for (Map.Entry<String, Set<PersistentMemberID>> entry : waitingRegions.entrySet()) {
            for (PersistentMemberID id : entry.getValue()) {
                missingIds.add(new PersistentMemberPattern(id));
            }
        }
        Set<PersistentMemberID> localIds = mm.getPersistentIDs();
        for (PersistentMemberID id : localIds) {
            localPatterns.add(new PersistentMemberPattern(id));
        }
    }
    return new MissingPersistentIDsResponse(missingIds, localPatterns, this.getSender());
}
Also used : PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) InternalCache(org.apache.geode.internal.cache.InternalCache) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) Map(java.util.Map) HashSet(java.util.HashSet) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 69 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class RefreshMemberSnapshotResponse method create.

/**
   * Returns a {@code FetchSysCfgResponse} that will be returned to the specified recipient. The
   * message will contains a copy of the local manager's config.
   */
public static RefreshMemberSnapshotResponse create(DistributionManager dm, InternalDistributedMember recipient) {
    RefreshMemberSnapshotResponse m = new RefreshMemberSnapshotResponse();
    m.setRecipient(recipient);
    try {
        DistributedSystem sys = dm.getSystem();
        InternalCache c = (InternalCache) CacheFactory.getInstance(sys);
        m.snapshot = new GemFireMemberStatus(c);
    } catch (Exception ignore) {
        m.snapshot = null;
    }
    return m;
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) GemFireMemberStatus(org.apache.geode.admin.GemFireMemberStatus) DistributedSystem(org.apache.geode.distributed.DistributedSystem) IOException(java.io.IOException)

Example 70 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class ExecuteFunction65 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection servConn, long start) throws IOException {
    Object function = null;
    Object args = null;
    MemberMappedArgument memberMappedArg = null;
    byte hasResult = 0;
    byte functionState = 0;
    boolean isReexecute = false;
    try {
        functionState = clientMessage.getPart(0).getSerializedForm()[0];
        if (functionState == AbstractExecution.HA_HASRESULT_NO_OPTIMIZEFORWRITE_REEXECUTE) {
            functionState = AbstractExecution.HA_HASRESULT_NO_OPTIMIZEFORWRITE;
            isReexecute = true;
        } else if (functionState == AbstractExecution.HA_HASRESULT_OPTIMIZEFORWRITE_REEXECUTE) {
            functionState = AbstractExecution.HA_HASRESULT_OPTIMIZEFORWRITE;
            isReexecute = true;
        }
        if (functionState != 1) {
            hasResult = (byte) ((functionState & 2) - 1);
        } else {
            hasResult = functionState;
        }
        if (hasResult == 1) {
            servConn.setAsTrue(REQUIRES_RESPONSE);
            servConn.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
        }
        function = clientMessage.getPart(1).getStringOrObject();
        args = clientMessage.getPart(2).getObject();
        Part part = clientMessage.getPart(3);
        if (part != null) {
            memberMappedArg = (MemberMappedArgument) part.getObject();
        }
    } catch (ClassNotFoundException exception) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), exception);
        if (hasResult == 1) {
            writeChunkedException(clientMessage, exception, servConn);
            servConn.setAsTrue(RESPONDED);
            return;
        }
    }
    if (function == null) {
        final String message = LocalizedStrings.ExecuteFunction_THE_INPUT_FUNCTION_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString();
        logger.warn("{}: {}", servConn.getName(), message);
        sendError(hasResult, clientMessage, message, servConn);
        return;
    }
    // Execute function on the cache
    try {
        Function functionObject = null;
        if (function instanceof String) {
            functionObject = FunctionService.getFunction((String) function);
            if (functionObject == null) {
                final String message = LocalizedStrings.ExecuteFunction_FUNCTION_NAMED_0_IS_NOT_REGISTERED.toLocalizedString(function);
                logger.warn("{}: {}", servConn.getName(), message);
                sendError(hasResult, clientMessage, message, servConn);
                return;
            } else {
                byte functionStateOnServerSide = AbstractExecution.getFunctionState(functionObject.isHA(), functionObject.hasResult(), functionObject.optimizeForWrite());
                if (logger.isDebugEnabled()) {
                    logger.debug("Function State on server side: {} on client: {}", functionStateOnServerSide, functionState);
                }
                if (functionStateOnServerSide != functionState) {
                    String message = LocalizedStrings.FunctionService_FUNCTION_ATTRIBUTE_MISMATCH_CLIENT_SERVER.toLocalizedString(function);
                    logger.warn("{}: {}", servConn.getName(), message);
                    sendError(hasResult, clientMessage, message, servConn);
                    return;
                }
            }
        } else {
            functionObject = (Function) function;
        }
        FunctionStats stats = FunctionStats.getFunctionStats(functionObject.getId());
        this.securityService.authorizeDataWrite();
        // check if the caller is authorized to do this operation on server
        AuthorizeRequest authzRequest = servConn.getAuthzRequest();
        ExecuteFunctionOperationContext executeContext = null;
        if (authzRequest != null) {
            executeContext = authzRequest.executeFunctionAuthorize(functionObject.getId(), null, null, args, functionObject.optimizeForWrite());
        }
        ChunkedMessage m = servConn.getFunctionResponseMessage();
        m.setTransactionId(clientMessage.getTransactionId());
        ResultSender resultSender = new ServerToClientFunctionResultSender65(m, MessageType.EXECUTE_FUNCTION_RESULT, servConn, functionObject, executeContext);
        InternalDistributedMember localVM = (InternalDistributedMember) servConn.getCache().getDistributedSystem().getDistributedMember();
        FunctionContext context = null;
        if (memberMappedArg != null) {
            context = new FunctionContextImpl(functionObject.getId(), memberMappedArg.getArgumentsForMember(localVM.getId()), resultSender, isReexecute);
        } else {
            context = new FunctionContextImpl(functionObject.getId(), args, resultSender, isReexecute);
        }
        HandShake handShake = (HandShake) servConn.getHandshake();
        int earlierClientReadTimeout = handShake.getClientReadTimeout();
        handShake.setClientReadTimeout(0);
        try {
            long startExecution = stats.startTime();
            stats.startFunctionExecution(functionObject.hasResult());
            if (logger.isDebugEnabled()) {
                logger.debug("Executing Function on Server: {} with context: {}", servConn, context);
            }
            InternalCache cache = servConn.getCache();
            HeapMemoryMonitor hmm = ((InternalResourceManager) cache.getResourceManager()).getHeapMonitor();
            if (functionObject.optimizeForWrite() && cache != null && hmm.getState().isCritical() && !MemoryThresholds.isLowMemoryExceptionDisabled()) {
                Set<DistributedMember> sm = Collections.singleton((DistributedMember) cache.getMyId());
                Exception e = new LowMemoryException(LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_0_FUNCEXEC_MEMBERS_1.toLocalizedString(new Object[] { functionObject.getId(), sm }), sm);
                sendException(hasResult, clientMessage, e.getMessage(), servConn, e);
                return;
            }
            functionObject.execute(context);
            if (!((ServerToClientFunctionResultSender65) resultSender).isLastResultReceived() && functionObject.hasResult()) {
                throw new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(functionObject.getId()));
            }
            stats.endFunctionExecution(startExecution, functionObject.hasResult());
        } catch (FunctionException functionException) {
            stats.endFunctionExecutionWithException(functionObject.hasResult());
            throw functionException;
        } catch (Exception exception) {
            stats.endFunctionExecutionWithException(functionObject.hasResult());
            throw new FunctionException(exception);
        } finally {
            handShake.setClientReadTimeout(earlierClientReadTimeout);
        }
    } catch (IOException ioException) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), ioException);
        String message = LocalizedStrings.ExecuteFunction_SERVER_COULD_NOT_SEND_THE_REPLY.toLocalizedString();
        sendException(hasResult, clientMessage, message, servConn, ioException);
    } catch (InternalFunctionInvocationTargetException internalfunctionException) {
        // 2> in case of HA member departed
        if (logger.isDebugEnabled()) {
            logger.debug(LocalizedMessage.create(LocalizedStrings.ExecuteFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, new Object[] { function }), internalfunctionException);
        }
        final String message = internalfunctionException.getMessage();
        sendException(hasResult, clientMessage, message, servConn, internalfunctionException);
    } catch (Exception e) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), e);
        final String message = e.getMessage();
        sendException(hasResult, clientMessage, message, servConn, e);
    }
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) InternalCache(org.apache.geode.internal.cache.InternalCache) ResultSender(org.apache.geode.cache.execute.ResultSender) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager) Function(org.apache.geode.cache.execute.Function) HandShake(org.apache.geode.internal.cache.tier.sockets.HandShake) MemberMappedArgument(org.apache.geode.internal.cache.execute.MemberMappedArgument) FunctionStats(org.apache.geode.internal.cache.execute.FunctionStats) LowMemoryException(org.apache.geode.cache.LowMemoryException) FunctionContextImpl(org.apache.geode.internal.cache.execute.FunctionContextImpl) ExecuteFunctionOperationContext(org.apache.geode.cache.operations.ExecuteFunctionOperationContext) ServerToClientFunctionResultSender65(org.apache.geode.internal.cache.execute.ServerToClientFunctionResultSender65) FunctionException(org.apache.geode.cache.execute.FunctionException) HeapMemoryMonitor(org.apache.geode.internal.cache.control.HeapMemoryMonitor) IOException(java.io.IOException) FunctionContext(org.apache.geode.cache.execute.FunctionContext) FunctionException(org.apache.geode.cache.execute.FunctionException) LowMemoryException(org.apache.geode.cache.LowMemoryException) IOException(java.io.IOException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Part(org.apache.geode.internal.cache.tier.sockets.Part) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Aggregations

InternalCache (org.apache.geode.internal.cache.InternalCache)267 DistributedMember (org.apache.geode.distributed.DistributedMember)78 Test (org.junit.Test)64 UnitTest (org.apache.geode.test.junit.categories.UnitTest)52 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)35 HashSet (java.util.HashSet)35 CliMetaData (org.apache.geode.management.cli.CliMetaData)34 CliCommand (org.springframework.shell.core.annotation.CliCommand)34 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)32 Region (org.apache.geode.cache.Region)31 Result (org.apache.geode.management.cli.Result)30 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)30 Expectations (org.jmock.Expectations)30 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)26 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)24 Set (java.util.Set)23 ResultCollector (org.apache.geode.cache.execute.ResultCollector)22 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)20