Search in sources :

Example 61 with InternalCache

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

the class FindRestEnabledServersFunction method execute.

public void execute(FunctionContext context) {
    try {
        InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
        DistributionConfig config = InternalDistributedSystem.getAnyInstance().getConfig();
        String bindAddress = RestAgent.getBindAddressForHttpService(config);
        final String protocolType = config.getHttpServiceSSLEnabled() ? "https" : "http";
        if (cache.isRESTServiceRunning()) {
            context.getResultSender().lastResult(protocolType + "://" + bindAddress + ":" + config.getHttpServicePort());
        } else {
            context.getResultSender().lastResult("");
        }
    } catch (CacheClosedException ex) {
        context.getResultSender().lastResult("");
    }
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Example 62 with InternalCache

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

the class ServerRegionFunctionExecutor method validateExecution.

@Override
public void validateExecution(Function function, Set targetMembers) {
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null && cache.getTxManager().getTXState() != null) {
        TXStateProxyImpl tx = (TXStateProxyImpl) cache.getTxManager().getTXState();
        tx.getRealDeal(null, region);
        tx.incOperationCount();
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) TXStateProxyImpl(org.apache.geode.internal.cache.TXStateProxyImpl)

Example 63 with InternalCache

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

the class BaseCommand method execute.

@Override
public void execute(Message clientMessage, ServerConnection serverConnection) {
    // Read the request and update the statistics
    long start = DistributionStats.getStatTime();
    if (EntryLogger.isEnabled() && serverConnection != null) {
        EntryLogger.setSource(serverConnection.getMembershipID(), "c2s");
    }
    boolean shouldMasquerade = shouldMasqueradeForTx(clientMessage, serverConnection);
    try {
        if (shouldMasquerade) {
            InternalCache cache = serverConnection.getCache();
            InternalDistributedMember member = (InternalDistributedMember) serverConnection.getProxyID().getDistributedMember();
            TXManagerImpl txMgr = cache.getTxManager();
            TXStateProxy tx = null;
            try {
                tx = txMgr.masqueradeAs(clientMessage, member, false);
                cmdExecute(clientMessage, serverConnection, start);
                tx.updateProxyServer(txMgr.getMemberId());
            } finally {
                txMgr.unmasquerade(tx);
            }
        } else {
            cmdExecute(clientMessage, serverConnection, start);
        }
    } catch (TransactionException | CopyException | SerializationException | CacheWriterException | CacheLoaderException | GemFireSecurityException | PartitionOfflineException | MessageTooLargeException e) {
        handleExceptionNoDisconnect(clientMessage, serverConnection, e);
    } catch (EOFException eof) {
        BaseCommand.handleEOFException(clientMessage, serverConnection, eof);
    } catch (InterruptedIOException e) {
        // Solaris only
        BaseCommand.handleInterruptedIOException(serverConnection, e);
    } catch (IOException e) {
        BaseCommand.handleIOException(clientMessage, serverConnection, e);
    } catch (DistributedSystemDisconnectedException e) {
        BaseCommand.handleShutdownException(clientMessage, serverConnection, e);
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Throwable e) {
        BaseCommand.handleThrowable(clientMessage, serverConnection, e);
    } finally {
        EntryLogger.clearSource();
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) CopyException(org.apache.geode.CopyException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) SerializationException(org.apache.geode.SerializationException) InternalCache(org.apache.geode.internal.cache.InternalCache) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) TransactionException(org.apache.geode.cache.TransactionException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) EOFException(java.io.EOFException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 64 with InternalCache

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

the class CacheXmlGenerator method parse.

/**
   * Called by the transformer to parse the "input source". We ignore the input source and, instead,
   * generate SAX events to the {@link #setContentHandler ContentHandler}.
   */
public void parse(InputSource input) throws SAXException {
    Assert.assertTrue(this.handler != null);
    boolean isClientCache = this.creation instanceof ClientCacheCreation;
    handler.startDocument();
    AttributesImpl atts = new AttributesImpl();
    if (this.useSchema) {
        if (null == version.getSchemaLocation()) {
            // TODO jbarrett - localize
            throw new IllegalStateException("No schema for version " + version.getVersion());
        }
        // add schema location for cache schema.
        handler.startPrefixMapping(W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI);
        addAttribute(atts, W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, version.getNamespace() + " " + version.getSchemaLocation());
        // add cache schema to default prefix.
        handler.startPrefixMapping(XmlConstants.DEFAULT_PREFIX, version.getNamespace());
        addAttribute(atts, VERSION, this.version.getVersion());
    }
    if (creation.hasLockLease()) {
        atts.addAttribute("", "", LOCK_LEASE, "", String.valueOf(creation.getLockLease()));
    }
    if (creation.hasLockTimeout()) {
        atts.addAttribute("", "", LOCK_TIMEOUT, "", String.valueOf(creation.getLockTimeout()));
    }
    if (creation.hasSearchTimeout()) {
        atts.addAttribute("", "", SEARCH_TIMEOUT, "", String.valueOf(creation.getSearchTimeout()));
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_5) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
    // TODO
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
        if (creation.hasMessageSyncInterval()) {
            atts.addAttribute("", "", MESSAGE_SYNC_INTERVAL, "", String.valueOf(creation.getMessageSyncInterval()));
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) {
        if (creation.hasServer()) {
            atts.addAttribute("", "", IS_SERVER, "", String.valueOf(creation.isServer()));
        }
        if (creation.hasCopyOnRead()) {
            atts.addAttribute("", "", COPY_ON_READ, "", String.valueOf(creation.getCopyOnRead()));
        }
    }
    if (isClientCache) {
        handler.startElement("", CLIENT_CACHE, CLIENT_CACHE, atts);
    } else {
        handler.startElement("", CACHE, CACHE, atts);
    }
    if (this.cache != null) {
        if (!isClientCache) {
            generate(this.cache.getCacheTransactionManager());
        } else if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
            generate(this.cache.getCacheTransactionManager());
        }
        generateDynamicRegionFactory(this.cache);
        if (!isClientCache) {
            if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
                Set<GatewaySender> senderSet = cache.getGatewaySenders();
                for (GatewaySender sender : senderSet) {
                    generateGatewaySender(sender);
                }
                generateGatewayReceiver(this.cache);
                generateAsyncEventQueue(this.cache);
            }
        }
        if (!isClientCache && this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
            if (this.cache.getGatewayConflictResolver() != null) {
                generate(GATEWAY_CONFLICT_RESOLVER, this.cache.getGatewayConflictResolver());
            }
        }
        if (!isClientCache) {
            for (Iterator iter = this.cache.getCacheServers().iterator(); iter.hasNext(); ) {
                CacheServer bridge = (CacheServer) iter.next();
                generate(bridge);
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
            Iterator pools;
            if (this.cache instanceof GemFireCacheImpl) {
                pools = PoolManager.getAll().values().iterator();
            } else {
                pools = this.creation.getPools().values().iterator();
            }
            while (pools.hasNext()) {
                Pool cp = (Pool) pools.next();
                generate(cp);
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
            if (this.cache instanceof GemFireCacheImpl) {
                InternalCache gfc = (InternalCache) this.cache;
                for (DiskStore ds : gfc.listDiskStores()) {
                    generate(ds);
                }
            } else {
                for (DiskStore ds : this.creation.listDiskStores()) {
                    generate(ds);
                }
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
            generatePdx();
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) >= 0) {
            Map namedAttributes = this.cache.listRegionAttributes();
            for (Iterator iter = namedAttributes.entrySet().iterator(); iter.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iter.next();
                String id = (String) entry.getKey();
                RegionAttributes attrs = (RegionAttributes) entry.getValue();
                // Since CacheCreation predefines these even in later versions
                // we need to exclude them in all versions.
                // It would be better if CacheCreation could only predefine them
                // for versions 6.5 and later but that is not easy to do
                {
                    if (this.creation instanceof ClientCacheCreation) {
                        try {
                            ClientRegionShortcut.valueOf(id);
                            // skip this guy since id mapped to one of the enum types
                            continue;
                        } catch (IllegalArgumentException ignore) {
                        // id is not a shortcut so go ahead and call generate
                        }
                    } else {
                        try {
                            RegionShortcut.valueOf(id);
                            // skip this guy since id mapped to one of the enum types
                            continue;
                        } catch (IllegalArgumentException ignore) {
                        // id is not a shortcut so go ahead and call generate
                        }
                    }
                }
                generate(id, attrs);
            }
        }
        if (cache instanceof GemFireCacheImpl) {
            generateRegions();
        } else {
            TreeSet rSet = new TreeSet(new RegionComparator());
            rSet.addAll(this.cache.rootRegions());
            Iterator it = rSet.iterator();
            while (it.hasNext()) {
                Region root = (Region) it.next();
                generateRegion(root);
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
            generateFunctionService();
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
            generateResourceManager();
            generateSerializerRegistration();
        }
        if (!isClientCache) {
            if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
                if (this.cache instanceof GemFireCacheImpl) {
                    InternalCache internalCache = (InternalCache) this.cache;
                    for (File file : internalCache.getBackupFiles()) {
                        generateBackupFile(file);
                    }
                } else {
                    for (File file : this.creation.getBackupFiles()) {
                        generateBackupFile(file);
                    }
                }
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
            generateInitializer();
        }
    }
    if (cache instanceof Extensible) {
        @SuppressWarnings("unchecked") final Extensible<Cache> extensible = (Extensible<Cache>) cache;
        generate(extensible);
    }
    if (isClientCache) {
        handler.endElement("", CLIENT_CACHE, CLIENT_CACHE);
    } else {
        handler.endElement("", CACHE, CACHE);
    }
    handler.endDocument();
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) InternalCache(org.apache.geode.internal.cache.InternalCache) DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) CacheServer(org.apache.geode.cache.server.CacheServer) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Pool(org.apache.geode.cache.client.Pool) GatewaySender(org.apache.geode.cache.wan.GatewaySender) Extensible(org.apache.geode.internal.cache.extension.Extensible) DiskStore(org.apache.geode.cache.DiskStore) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Map(java.util.Map) File(java.io.File) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalClientCache(org.apache.geode.cache.client.internal.InternalClientCache)

Example 65 with InternalCache

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

the class CacheXmlGenerator method generatePdx.

private void generatePdx() throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    CacheConfig config = ((InternalCache) cache).getCacheConfig();
    if (config.pdxReadSerializedUserSet) {
        if (generateDefaults() || this.cache.getPdxReadSerialized())
            atts.addAttribute("", "", READ_SERIALIZED, "", Boolean.toString(this.cache.getPdxReadSerialized()));
    }
    if (config.pdxIgnoreUnreadFieldsUserSet) {
        if (generateDefaults() || this.cache.getPdxIgnoreUnreadFields())
            atts.addAttribute("", "", IGNORE_UNREAD_FIELDS, "", Boolean.toString(this.cache.getPdxIgnoreUnreadFields()));
    }
    if (config.pdxPersistentUserSet) {
        if (generateDefaults() || this.cache.getPdxPersistent())
            atts.addAttribute("", "", PERSISTENT, "", Boolean.toString(this.cache.getPdxPersistent()));
    }
    if (config.pdxDiskStoreUserSet) {
        if (generateDefaults() || this.cache.getPdxDiskStore() != null && !this.cache.getPdxDiskStore().equals(""))
            atts.addAttribute("", "", DISK_STORE_NAME, "", this.cache.getPdxDiskStore());
    }
    if (!generateDefaults() && this.cache.getPdxSerializer() == null && atts.getLength() == 0) {
        return;
    }
    handler.startElement("", PDX, PDX, atts);
    if (this.cache.getPdxSerializer() != null) {
        generate(PDX_SERIALIZER, this.cache.getPdxSerializer());
    }
    handler.endElement("", PDX, PDX);
}
Also used : DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheConfig(org.apache.geode.internal.cache.CacheConfig)

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