Skip to content

Commit

Permalink
GEODE-6280: Create new public module for the Management API
Browse files Browse the repository at this point in the history
- This moves the classes under `org.apache.geode.cache.configuration` package
  into a public module: `geode-managament-api`. The intent is that this module
  will have no dependencies to `geode-core` but will allow consumers to perform
  administration tasks (creating regions, etc.).
- `geode-core` will now depend on both `geode-management-api` as well as
  `geode-common` (transitively). Suggestions on how to improve these new
  dependencies are welcome.

Signed-off-by: Peter Tran <ptran@pivotal.io>
  • Loading branch information
jdeppe-pivotal committed Jan 22, 2019
1 parent bd45232 commit 8214a64
Show file tree
Hide file tree
Showing 52 changed files with 1,100 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ WHERE <args>:
geode-modules-session-internal.jar
geode-core.jar
geode-json.jar
geode-common.jar
geode-management.jar
antlr.jar
log4j-core.jar
log4j-api.jar
Expand Down Expand Up @@ -261,6 +263,8 @@ SESSION_JAR="${LIB_DIR}/geode-modules-session-${VERSION}.jar"
declare -a OTHER_JARS
OTHER_JARS=(${GEODE}/lib/geode-core-${VERSION}.jar \
${GEODE}/lib/geode-json-${VERSION}.jar \
${GEODE}/lib/geode-common-${VERSION}.jar \
${GEODE}/lib/geode-management-${VERSION}.jar \
${GEODE}/lib/antlr-@ANTLR_VERSION@.jar \
${GEODE}/lib/log4j-core-@LOG4J_VERSION@.jar \
${GEODE}/lib/log4j-api-@LOG4J_VERSION@.jar \
Expand Down
1 change: 1 addition & 0 deletions geode-assembly/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ dependencies {
archives project(':geode-web')
archives project(':geode-web-api')
archives project(':geode-web-management')
archives project(':geode-management')
archives project(':geode-wan')
archives project(':geode-cq')
archives project(':geode-rebalancer')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ public String jarSkipPropertyName() {
}

private static final String[] tomcatRequiredJars =
{"antlr", "commons-io", "commons-lang", "commons-validator", "fastutil", "geode-core",
"javax.transaction-api", "jgroups", "log4j-api", "log4j-core", "log4j-jul", "shiro-core"};
{"antlr", "commons-io", "commons-lang", "commons-validator", "fastutil", "geode-common",
"geode-core", "geode-management", "javax.transaction-api", "jgroups", "log4j-api",
"log4j-core", "log4j-jul", "shiro-core"};

private final TomcatVersion version;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ lib/geode-dependencies.jar
lib/geode-jca-0.0.0.rar
lib/geode-json-0.0.0.jar
lib/geode-lucene-0.0.0.jar
lib/geode-management-0.0.0.jar
lib/geode-old-client-support-0.0.0.jar
lib/geode-protobuf-0.0.0.jar
lib/geode-protobuf-messages-0.0.0.jar
Expand Down
107 changes: 54 additions & 53 deletions geode-assembly/src/integrationTest/resources/dependency_classpath.txt
Original file line number Diff line number Diff line change
@@ -1,75 +1,76 @@
HikariCP-3.2.0.jar
antlr-2.7.7.jar
classgraph-4.0.6.jar
commons-beanutils-1.9.3.jar
commons-codec-1.10.jar
commons-collections-3.2.2.jar
commons-io-2.6.jar
commons-lang3-3.8.1.jar
commons-logging-1.2.jar
commons-math3-3.2.jar
commons-validator-1.6.jar
fastutil-8.2.2.jar
geo-0.7.1.jar
geode-common-0.0.0.jar
geode-json-0.0.0.jar
geode-core-0.0.0.jar
geode-connectors-0.0.0.jar
geode-core-0.0.0.jar
geode-cq-0.0.0.jar
geode-json-0.0.0.jar
geode-lucene-0.0.0.jar
geode-management-0.0.0.jar
geode-old-client-support-0.0.0.jar
geode-protobuf-0.0.0.jar
geode-protobuf-messages-0.0.0.jar
geode-wan-0.0.0.jar
geode-cq-0.0.0.jar
geode-rebalancer-0.0.0.jar
antlr-2.7.7.jar
jgroups-3.6.14.Final.jar
jackson-databind-2.9.7.jar
geode-wan-0.0.0.jar
grumpy-core-0.2.2.jar
istack-commons-runtime-2.2.jar
jackson-annotations-2.9.7.jar
spring-shell-1.2.0.RELEASE.jar
commons-io-2.6.jar
commons-validator-1.6.jar
jackson-core-2.9.7.jar
jackson-databind-2.9.7.jar
jansi-1.17.1.jar
javax.activation-1.2.0.jar
javax.activation-api-1.2.0.jar
javax.resource-api-1.7.1.jar
javax.servlet-api-3.1.0.jar
javax.transaction-api-1.3.jar
jaxb-api-2.3.1.jar
jaxb-impl-2.3.1.jar
commons-lang3-3.8.1.jar
netty-all-4.1.31.Final.jar
fastutil-8.2.2.jar
javax.resource-api-1.7.1.jar
jetty-http-9.4.12.v20180830.jar
jetty-io-9.4.12.v20180830.jar
jetty-security-9.4.12.v20180830.jar
jetty-server-9.4.12.v20180830.jar
jetty-servlet-9.4.12.v20180830.jar
jetty-util-9.4.12.v20180830.jar
jetty-webapp-9.4.12.v20180830.jar
jetty-xml-9.4.12.v20180830.jar
jgroups-3.6.14.Final.jar
jline-2.12.jar
jna-4.1.0.jar
jopt-simple-5.0.4.jar
log4j-slf4j-impl-2.11.1.jar
log4j-api-2.11.1.jar
log4j-core-2.11.1.jar
log4j-jcl-2.11.1.jar
log4j-jul-2.11.1.jar
log4j-api-2.11.1.jar
geo-0.7.1.jar
jetty-webapp-9.4.12.v20180830.jar
spring-core-4.3.20.RELEASE.jar
snappy-0.4.jar
shiro-core-1.4.0.jar
classgraph-4.0.6.jar
log4j-slf4j-impl-2.11.1.jar
lucene-analyzers-common-6.6.2.jar
lucene-analyzers-phonetic-6.6.2.jar
lucene-core-6.6.2.jar
lucene-queries-6.6.2.jar
lucene-queryparser-6.6.2.jar
netty-all-4.1.31.Final.jar
protobuf-java-3.6.1.jar
rmiio-2.1.2.jar
istack-commons-runtime-2.2.jar
jansi-1.17.1.jar
shiro-cache-1.4.0.jar
shiro-crypto-hash-1.4.0.jar
shiro-crypto-cipher-1.4.0.jar
shiro-config-ogdl-1.4.0.jar
shiro-config-core-1.4.0.jar
shiro-event-1.4.0.jar
shiro-config-ogdl-1.4.0.jar
shiro-core-1.4.0.jar
shiro-crypto-cipher-1.4.0.jar
shiro-crypto-core-1.4.0.jar
shiro-crypto-hash-1.4.0.jar
shiro-event-1.4.0.jar
shiro-lang-1.4.0.jar
slf4j-api-1.7.25.jar
jackson-core-2.9.7.jar
commons-beanutils-1.9.3.jar
commons-logging-1.2.jar
commons-collections-3.2.2.jar
javax.activation-api-1.2.0.jar
javax.transaction-api-1.3.jar
grumpy-core-0.2.2.jar
jetty-xml-9.4.12.v20180830.jar
jetty-servlet-9.4.12.v20180830.jar
jline-2.12.jar
commons-math3-3.2.jar
jetty-security-9.4.12.v20180830.jar
jetty-server-9.4.12.v20180830.jar
jetty-http-9.4.12.v20180830.jar
jetty-io-9.4.12.v20180830.jar
jetty-util-9.4.12.v20180830.jar
javax.servlet-api-3.1.0.jar
HikariCP-3.2.0.jar
lucene-analyzers-phonetic-6.6.2.jar
lucene-analyzers-common-6.6.2.jar
lucene-queryparser-6.6.2.jar
lucene-core-6.6.2.jar
lucene-queries-6.6.2.jar
commons-codec-1.10.jar
protobuf-java-3.6.1.jar
snappy-0.4.jar
spring-core-4.3.20.RELEASE.jar
spring-shell-1.2.0.RELEASE.jar
1 change: 0 additions & 1 deletion geode-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
apply from: "${project.projectDir}/../gradle/geode-dependency-management.gradle"
apply from: "${project.projectDir}/../gradle/publish.gradle"


dependencies {
testCompile('junit:junit')
testCompile('org.assertj:assertj-core')
Expand Down
3 changes: 1 addition & 2 deletions geode-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,10 @@ dependencies {

compile(project(':geode-common'))
compile(project(':geode-json'))

compile(project(':geode-management'))

jcaAnnotationProcessor 'org.apache.logging.log4j:log4j-core'


jcaCompile(sourceSets.main.output)

jmhCompile('org.apache.logging.log4j:log4j-core')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.util.Properties;


/**
* An object that can be described in a declarative caching XML file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.management.cli.CliFunction;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.configuration.domain.DeclarableTypeInstantiator;

/**
* Function used by the 'alter region' gfsh command to alter a region on each member.
Expand Down Expand Up @@ -188,7 +189,7 @@ void alterRegion(Cache cache, RegionConfig deltaConfig) {
// Add new cache listeners
for (DeclarableType newCacheListener : newCacheListeners) {
if (!newCacheListener.equals(DeclarableType.EMPTY)) {
mutator.addCacheListener(newCacheListener.newInstance(cache));
mutator.addCacheListener(DeclarableTypeInstantiator.newInstance(newCacheListener, cache));
}
}
if (logger.isDebugEnabled()) {
Expand All @@ -201,7 +202,7 @@ void alterRegion(Cache cache, RegionConfig deltaConfig) {
if (cacheLoader.equals(DeclarableType.EMPTY)) {
mutator.setCacheLoader(null);
} else {
mutator.setCacheLoader(cacheLoader.newInstance(cache));
mutator.setCacheLoader(DeclarableTypeInstantiator.newInstance(cacheLoader, cache));
}

if (logger.isDebugEnabled()) {
Expand All @@ -214,7 +215,7 @@ void alterRegion(Cache cache, RegionConfig deltaConfig) {
if (cacheWriter.equals(DeclarableType.EMPTY)) {
mutator.setCacheWriter(null);
} else {
mutator.setCacheWriter(cacheWriter.newInstance(cache));
mutator.setCacheWriter(DeclarableTypeInstantiator.newInstance(cacheWriter, cache));
}

if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -254,7 +255,7 @@ private void updateExpirationAttributes(Cache cache,
if (newCustomExpiry.equals(DeclarableType.EMPTY)) {
mutator2.accept(null);
} else {
mutator2.accept(newCustomExpiry.newInstance(cache));
mutator2.accept(DeclarableTypeInstantiator.newInstance(newCustomExpiry, cache));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.apache.geode.management.internal.configuration.domain;

import java.util.Properties;

import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Declarable;
import org.apache.geode.cache.configuration.DeclarableType;
import org.apache.geode.cache.configuration.ObjectType;
import org.apache.geode.cache.configuration.ParameterType;
import org.apache.geode.internal.ClassPathLoader;
import org.apache.geode.management.internal.cli.domain.ClassName;

public abstract class DeclarableTypeInstantiator {

public static <T extends Declarable> T newInstance(DeclarableType declarableType, Cache cache) {
try {
Class<T> loadedClass =
(Class<T>) ClassPathLoader.getLatest().forName(declarableType.getClassName());
T declarable = loadedClass.newInstance();
Properties initProperties = new Properties();
for (ParameterType parameter : declarableType.getParameters()) {
initProperties.put(parameter.getName(), newInstance(parameter, cache));
}
declarable.initialize(cache, initProperties);
return declarable;
} catch (Exception e) {
throw new RuntimeException(
"Error instantiating class: <" + declarableType.getClassName() + ">", e);
}
}

public static <T> T newInstance(ObjectType objectType, Cache cache) {
if (objectType.getString() != null) {
return (T) objectType.getString();
}

if (objectType.getDeclarable() != null) {
return newInstance(objectType.getDeclarable(), cache);
}

return null;
}

public static <V> V newInstance(ClassName<?> type, Cache cache) {
try {
Class<V> loadedClass = (Class<V>) ClassPathLoader.getLatest().forName(type.getClassName());
V object = loadedClass.newInstance();
if (object instanceof Declarable) {
Declarable declarable = (Declarable) object;
declarable.initialize(cache, type.getInitProperties());
declarable.init(type.getInitProperties()); // for backwards compatibility
}
return object;
} catch (Exception e) {
throw new RuntimeException("Error instantiating class: <" + type.getClassName() + ">", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.junit.Test;

import org.apache.geode.management.internal.configuration.domain.DeclarableTypeInstantiator;


public class ClassNameTest {
Expand All @@ -44,7 +45,8 @@ public void empty() {

@Test
public void emptyCanNotInstantiate() {
assertThatThrownBy(() -> ClassName.EMPTY.newInstance(null)).isInstanceOf(RuntimeException.class)
assertThatThrownBy(() -> DeclarableTypeInstantiator.newInstance(ClassName.EMPTY, null))
.isInstanceOf(RuntimeException.class)
.hasMessageContaining("Error instantiating class");
}

Expand Down Expand Up @@ -100,15 +102,15 @@ public void illegalJson() {
@Test
public void getInstance() {
ClassName<String> klass = new ClassName("java.lang.String");
String s = klass.newInstance(null);
String s = DeclarableTypeInstantiator.newInstance(klass, null);
assertThat(s.toString()).isEqualTo("");
}

@Test
public void getInstanceWithProps() {
String json = "{\"k\":\"v\"}";
ClassName<MyCacheWriter> cacheWriter = new ClassName<>(MyCacheWriter.class.getName(), json);
MyCacheWriter obj = cacheWriter.newInstance(null);
MyCacheWriter obj = DeclarableTypeInstantiator.newInstance(cacheWriter, null);
assertThat(obj.getProperties()).containsEntry("k", "v").containsOnlyKeys("k");
}
}

0 comments on commit 8214a64

Please sign in to comment.