Skip to content

Commit

Permalink
GEODE-7186: Move HttpService implementation into its own module (apac…
Browse files Browse the repository at this point in the history
…he#4040)

- For maven/gradle consumption, this component becomes an optional
  dependency.
- The CacheService.init() method now returns a boolean indicating
  whether the given service was initialized or not.
- Services are now created before cache creation resourcce events are
  emitted.
  • Loading branch information
jdeppe-pivotal authored Sep 17, 2019
1 parent 4ec8741 commit 1ea49f0
Show file tree
Hide file tree
Showing 40 changed files with 315 additions and 215 deletions.
6 changes: 6 additions & 0 deletions boms/geode-all-bom/src/test/resources/expected-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,12 @@
<version>1.11.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-http-service</artifactId>
<version>1.11.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ lib/geode-connectors-0.0.0.jar
lib/geode-core-0.0.0.jar
lib/geode-cq-0.0.0.jar
lib/geode-dependencies.jar
lib/geode-http-service-0.0.0.jar
lib/geode-jca-0.0.0.rar
lib/geode-lucene-0.0.0.jar
lib/geode-management-0.0.0.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ geode-common-0.0.0.jar
geode-connectors-0.0.0.jar
geode-core-0.0.0.jar
geode-cq-0.0.0.jar
geode-http-service-0.0.0.jar
geode-lucene-0.0.0.jar
geode-management-0.0.0.jar
geode-memcached-0.0.0.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ public void destroyRegionMapping(String regionName) {
mappingsByRegion.remove(regionName);
}

@Override
public void init(Cache cache) {}


@Override
public Class<? extends CacheService> getInterface() {
return JdbcConnectorService.class;
Expand Down
7 changes: 1 addition & 6 deletions geode-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,7 @@ dependencies {
ext.optional = true
}

//Jetty is used by the http service, which is used for the developer and management rest APIs
implementation('org.eclipse.jetty:jetty-webapp') {
ext.optional = true
}
// Jetty is used by the http service, which is used for the developer and management rest APIs
implementation('org.eclipse.jetty:jetty-server') {
runtimeOnly(project(':geode-http-service')) {
ext.optional = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
package org.apache.geode.internal.cache;

import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.internal.HttpService;

public class CacheServiceJUnitTest {

Expand All @@ -41,8 +42,8 @@ public void tearDown() {

@Test
public void test() {
MockCacheService service = cache.getService(MockCacheService.class);
assertEquals(cache, service.getCache());
HttpService service = cache.getService(HttpService.class);
assertThat(service).isNotNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@
import java.nio.file.Path;
import java.util.Map;

import org.apache.geode.internal.cache.CacheService;
import org.apache.geode.internal.cache.InternalCache;

/**
* This interface provides access to the simple http service exposed on the Geode
* {@link InternalCache}. An instance can be retrieved by calling
* {@code InternalCache.getHttpService()}.
* {@code InternalCache.getService(HttpService.class)}.
*/
public interface HttpService {
public interface HttpService extends CacheService {

/**
* Stop the service. This should also stop any transitively managed components. Starting the
* service is implicitly handled by {@link #addWebApplication(String, Path, Map)}
*/
void stop();
String SECURITY_SERVICE_SERVLET_CONTEXT_PARAM = "org.apache.geode.securityService";

String CLUSTER_MANAGEMENT_SERVICE_CONTEXT_PARAM = "org.apache.geode.cluster.management.service";

String GEODE_SSLCONFIG_SERVLET_CONTEXT_PARAM = "org.apache.geode.sslConfig";

String AUTH_TOKEN_ENABLED_PARAM = "org.apache.geode.auth.token.enabled";

/**
* Add a new web application in the form of a war file. This method is also implicitly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.geode.cache.client.internal.locator.LocatorStatusRequest;
import org.apache.geode.cache.client.internal.locator.QueueConnectionRequest;
import org.apache.geode.cache.client.internal.locator.wan.LocatorMembershipListener;
import org.apache.geode.cache.internal.HttpService;
import org.apache.geode.distributed.ConfigurationProperties;
import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.distributed.Locator;
Expand All @@ -72,7 +73,6 @@
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.InternalCacheBuilder;
import org.apache.geode.internal.cache.InternalHttpService;
import org.apache.geode.internal.cache.tier.sockets.TcpServerFactory;
import org.apache.geode.internal.cache.wan.WANServiceProvider;
import org.apache.geode.internal.config.JAXBService;
Expand Down Expand Up @@ -757,19 +757,19 @@ private void startClusterManagementService() throws IOException {
}

Map<String, Object> serviceAttributes = new HashMap<>();
serviceAttributes.put(InternalHttpService.SECURITY_SERVICE_SERVLET_CONTEXT_PARAM,
serviceAttributes.put(HttpService.SECURITY_SERVICE_SERVLET_CONTEXT_PARAM,
internalCache.getSecurityService());
serviceAttributes.put(InternalHttpService.CLUSTER_MANAGEMENT_SERVICE_CONTEXT_PARAM,
serviceAttributes.put(HttpService.CLUSTER_MANAGEMENT_SERVICE_CONTEXT_PARAM,
clusterManagementService);

String[] authEnabledComponents = distributionConfig.getSecurityAuthTokenEnabledComponents();

boolean managementAuthTokenEnabled = Arrays.stream(authEnabledComponents)
.anyMatch(AuthTokenEnabledComponents::hasManagement);
serviceAttributes.put(InternalHttpService.AUTH_TOKEN_ENABLED_PARAM, managementAuthTokenEnabled);
serviceAttributes.put(HttpService.AUTH_TOKEN_ENABLED_PARAM, managementAuthTokenEnabled);

if (distributionConfig.getEnableManagementRestService()) {
internalCache.getHttpService().ifPresent(x -> {
internalCache.getOptionalService(HttpService.class).ifPresent(x -> {
try {
logger.info("Geode Property {}=true Geode Management Rest Service is enabled.",
ConfigurationProperties.ENABLE_MANAGEMENT_REST_SERVICE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ public interface CacheService {
*
* Services are initialized in random order, fairly early on in cache initialization. In
* particular, the cache.xml has not yet been parsed.
*
* @return a boolean indicating whether the service was successfully initialized. If false, then
* the service will not subsequently be available.
*/
void init(Cache cache);
default boolean init(Cache cache) {
return true;
}

/**
* Return the class or interface used to look up this service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
import org.apache.geode.cache.client.internal.PoolImpl;
import org.apache.geode.cache.control.ResourceManager;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.cache.internal.HttpService;
import org.apache.geode.cache.query.QueryService;
import org.apache.geode.cache.query.internal.DefaultQueryService;
import org.apache.geode.cache.query.internal.InternalQueryService;
Expand Down Expand Up @@ -223,10 +222,8 @@
import org.apache.geode.internal.logging.LoggingExecutors;
import org.apache.geode.internal.logging.LoggingThread;
import org.apache.geode.internal.monitoring.ThreadsMonitoring;
import org.apache.geode.internal.net.SSLConfigurationFactory;
import org.apache.geode.internal.net.SocketCreator;
import org.apache.geode.internal.offheap.MemoryAllocator;
import org.apache.geode.internal.security.SecurableCommunicationChannel;
import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.internal.security.SecurityServiceFactory;
import org.apache.geode.internal.sequencelog.SequenceLoggerImpl;
Expand Down Expand Up @@ -599,8 +596,6 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has

private final ClusterConfigurationLoader ccLoader = new ClusterConfigurationLoader();

private Optional<HttpService> httpService = Optional.ofNullable(null);

private final MeterRegistry meterRegistry;
private final Set<MeterRegistry> meterSubregistries;

Expand Down Expand Up @@ -934,22 +929,6 @@ public static GemFireCacheImpl getForPdx(String reason) {

addRegionEntrySynchronizationListener(new GatewaySenderQueueEntrySynchronizationListener());
backupService = new BackupService(this);
if (!this.isClient) {
if (systemConfig.getHttpServicePort() == 0) {
logger.info("HttpService is disabled with http-serivce-port = 0");
httpService = Optional.empty();
} else {
try {
httpService =
Optional.of(new InternalHttpService(systemConfig.getHttpServiceBindAddress(),
systemConfig.getHttpServicePort(), SSLConfigurationFactory
.getSSLConfigForComponent(systemConfig,
SecurableCommunicationChannel.WEB)));
} catch (Throwable ex) {
logger.warn("Could not enable HttpService: {}", ex.getMessage());
}
}
}
} // synchronized

clientMetadataService = new ClientMetadataService(this);
Expand Down Expand Up @@ -1005,11 +984,6 @@ public Set<MeterRegistry> getMeterSubregistries() {
return meterSubregistries;
}

@Override
public Optional<HttpService> getHttpService() {
return httpService;
}

@Override
public void reLoadClusterConfiguration() throws IOException, ClassNotFoundException {
configurationResponse = requestSharedConfiguration();
Expand Down Expand Up @@ -1243,10 +1217,16 @@ public void initialize() {
// This call may need to be moved inside initializeDeclarativeCache.
jmxAdvisor.initializationGate(); // Entry to GemFire Management service

// this starts up the ManagementService, register and federate the internal beans
initializeServices();

// This starts up the ManagementService, registers and federates the internal beans. Since it
// may be starting up web services, it relies on the prior step which would have started the
// HttpService.
system.handleResourceEvent(ResourceEvent.CACHE_CREATE, this);

initializeServices();
// Resource events, generated for started services. These events may depend on the prior
// CACHE_CREATE event which is why they are split out separately.
handleResourceEventsForCacheServices();

boolean completedCacheXml = false;
try {
Expand Down Expand Up @@ -1294,10 +1274,20 @@ void applyJarAndXmlFromClusterConfig() {
private void initializeServices() {
ServiceLoader<CacheService> loader = ServiceLoader.load(CacheService.class);
for (CacheService service : loader) {
service.init(this);
services.put(service.getInterface(), service);
try {
if (service.init(this)) {
services.put(service.getInterface(), service);
logger.info("Initialized cache service {}", service.getClass().getName());
}
} catch (Exception ex) {
logger.warn("Cache service " + service.getClass().getName() + " failed to initialize", ex);
}
}
}

private void handleResourceEventsForCacheServices() {
for (CacheService service : services.values()) {
system.handleResourceEvent(ResourceEvent.CACHE_SERVICE_CREATE, service);
logger.info("Initialized cache service {}", service.getClass().getName());
}
}

Expand Down Expand Up @@ -2179,8 +2169,6 @@ public void close(String reason, Throwable systemFailureCause, boolean keepAlive

stopServices();

httpService.ifPresent(HttpService::stop);

// no need to track PR instances since we won't create any more
// cacheServers or gatewayHubs
if (isDebugEnabled) {
Expand Down Expand Up @@ -3657,6 +3645,11 @@ public <T extends CacheService> T getService(Class<T> clazz) {
return clazz.cast(services.get(clazz));
}

@Override
public <T extends CacheService> Optional<T> getOptionalService(Class<T> clazz) {
return Optional.ofNullable(getService(clazz));
}

@Override
public Collection<CacheService> getServices() {
return Collections.unmodifiableCollection(services.values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
import org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl;
import org.apache.geode.cache.client.internal.ClientMetadataService;
import org.apache.geode.cache.internal.HttpService;
import org.apache.geode.cache.query.QueryService;
import org.apache.geode.cache.query.internal.InternalQueryService;
import org.apache.geode.cache.query.internal.QueryMonitor;
Expand Down Expand Up @@ -93,6 +92,8 @@ public interface InternalCache extends Cache, Extensible<Cache>, CacheTime, Reco

<T extends CacheService> T getService(Class<T> clazz);

<T extends CacheService> Optional<T> getOptionalService(Class<T> clazz);

Collection<CacheService> getServices();

SystemTimer getCCPTimer();
Expand Down Expand Up @@ -379,8 +380,6 @@ void invokeRegionEntrySynchronizationListenersAfterSynchronization(
*/
InternalCacheForClientAccess getCacheForProcessingClientRequests();

Optional<HttpService> getHttpService();

void initialize();

void throwCacheExistsException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl;
import org.apache.geode.cache.client.internal.ClientMetadataService;
import org.apache.geode.cache.control.ResourceManager;
import org.apache.geode.cache.internal.HttpService;
import org.apache.geode.cache.query.QueryService;
import org.apache.geode.cache.query.internal.InternalQueryService;
import org.apache.geode.cache.query.internal.QueryMonitor;
Expand Down Expand Up @@ -635,6 +634,11 @@ public <T extends CacheService> T getService(Class<T> clazz) {
return delegate.getService(clazz);
}

@Override
public <T extends CacheService> Optional<T> getOptionalService(Class<T> clazz) {
return Optional.ofNullable(getService(clazz));
}

@Override
public Collection<CacheService> getServices() {
return delegate.getServices();
Expand Down Expand Up @@ -1229,11 +1233,6 @@ public InternalCacheForClientAccess getCacheForProcessingClientRequests() {
return this;
}

@Override
public Optional<HttpService> getHttpService() {
return delegate.getHttpService();
}

@Override
public void initialize() {
// do nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.cache.client.internal.ClientMetadataService;
import org.apache.geode.cache.client.internal.PoolImpl;
import org.apache.geode.cache.internal.HttpService;
import org.apache.geode.cache.query.CqAttributes;
import org.apache.geode.cache.query.CqQuery;
import org.apache.geode.cache.query.CqServiceStatistics;
Expand Down Expand Up @@ -2108,6 +2107,11 @@ public <T extends CacheService> T getService(Class<T> clazz) {
throw new UnsupportedOperationException("Should not be invoked");
}

@Override
public <T extends CacheService> Optional<T> getOptionalService(Class<T> clazz) {
throw new UnsupportedOperationException("Should not be invoked");
}

@Override
public Collection<CacheService> getServices() {
throw new UnsupportedOperationException("Should not be invoked");
Expand Down Expand Up @@ -2411,11 +2415,6 @@ public void throwCacheExistsException() {
throw new UnsupportedOperationException("Should not be invoked");
}

@Override
public Optional<HttpService> getHttpService() {
throw new UnsupportedOperationException("Should not be invoked");
}

@Override
public MeterRegistry getMeterRegistry() {
throw new UnsupportedOperationException("Should not be invoked");
Expand Down
Loading

0 comments on commit 1ea49f0

Please sign in to comment.