Skip to content

Commit

Permalink
Bug/geode 4798: Add JDBC Connector classes to sanctioned serializables (
Browse files Browse the repository at this point in the history
apache#1592)


  * Added infrastructure to handle sanctioning serializables in JDBC Connector and
    improve use of serializable in the module
  • Loading branch information
Nick Reich authored Mar 12, 2018
1 parent 386b92b commit 0908acb
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AlterConnectionFunction
extends JdbcCliFunction<ConnectionConfiguration, CliFunctionResult> {

AlterConnectionFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class AlterMappingFunction extends JdbcCliFunction<RegionMapping, CliFunctionResult> {

AlterMappingFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CreateConnectionFunction
extends JdbcCliFunction<ConnectionConfiguration, CliFunctionResult> {

CreateConnectionFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class CreateMappingFunction extends JdbcCliFunction<RegionMapping, CliFunctionResult> {

CreateMappingFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class DescribeConnectionFunction extends JdbcCliFunction<String, ConnectionConfiguration> {

DescribeConnectionFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class DescribeMappingFunction extends JdbcCliFunction<String, RegionMapping> {

DescribeMappingFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class DestroyConnectionFunction extends JdbcCliFunction<String, CliFunctionResult> {

DestroyConnectionFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class DestroyMappingFunction extends JdbcCliFunction<String, CliFunctionResult> {

DestroyMappingFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Handles exceptions by returning an error result to GFSH
*/
class ExceptionHandler implements Serializable {
class ExceptionHandler {
private static final Logger logger = LogService.getLogger();

void handleException(final FunctionContext<?> context, final Exception exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* Provides JDBC command dependencies provided in the FunctionContext
*/
class FunctionContextArgumentProvider implements Serializable {
class FunctionContextArgumentProvider {

static InternalCache getCacheFromContext(FunctionContext<?> context) {
return (InternalCache) context.getCache();
Expand All @@ -45,26 +45,26 @@ static String getMemberFromContext(FunctionContext<?> context) {
/**
* Returns the JdbcConnectorService
*/
JdbcConnectorService getJdbcConnectorService(FunctionContext<?> context) {
static JdbcConnectorService getJdbcConnectorService(FunctionContext<?> context) {
return getCacheFromContext(context).getService(JdbcConnectorService.class);
}

/**
* Returns the name of the distributed member or its id if it has no name
*/
String getMember(FunctionContext<?> context) {
static String getMember(FunctionContext<?> context) {
return getMemberFromContext(context);
}

/**
* Returns XmlEntity for JdbcConnectorServiceXmlGenerator snippet of cache xml
*/
XmlEntity createXmlEntity(FunctionContext<?> context) {
static XmlEntity createXmlEntity(FunctionContext<?> context) {
return new XmlEntity(createCacheProvider(context), CACHE, PREFIX, NAMESPACE,
CONNECTION_SERVICE.getTypeName(), NAME, CONNECTION_SERVICE.getTypeName());
}

private XmlEntity.CacheProvider createCacheProvider(FunctionContext<?> context) {
private static XmlEntity.CacheProvider createCacheProvider(FunctionContext<?> context) {
return () -> getCacheFromContext(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@
@Experimental
public abstract class JdbcCliFunction<T1, T2> implements InternalFunction<T1> {

private final FunctionContextArgumentProvider argumentProvider;
private final ExceptionHandler exceptionHandler;
private final transient ExceptionHandler exceptionHandler;

JdbcCliFunction(FunctionContextArgumentProvider argumentProvider,
ExceptionHandler exceptionHandler) {
this.argumentProvider = argumentProvider;
this.exceptionHandler = exceptionHandler;
JdbcCliFunction() {
this.exceptionHandler = new ExceptionHandler();
}

@Override
Expand All @@ -45,7 +42,8 @@ public String getId() {
@Override
public void execute(FunctionContext<T1> context) {
try {
JdbcConnectorService service = argumentProvider.getJdbcConnectorService(context);
JdbcConnectorService service =
FunctionContextArgumentProvider.getJdbcConnectorService(context);
T2 result = getFunctionResult(service, context);
context.getResultSender().lastResult(result);
} catch (Exception e) {
Expand All @@ -54,11 +52,11 @@ public void execute(FunctionContext<T1> context) {
}

String getMember(FunctionContext<T1> context) {
return argumentProvider.getMember(context);
return FunctionContextArgumentProvider.getMember(context);
}

XmlEntity createXmlEntity(FunctionContext<T1> context) {
return argumentProvider.createXmlEntity(context);
return FunctionContextArgumentProvider.createXmlEntity(context);
}

abstract T2 getFunctionResult(JdbcConnectorService service, FunctionContext<T1> context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class ListConnectionFunction extends JdbcCliFunction<Void, ConnectionConfiguration[]> {

ListConnectionFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class ListMappingFunction extends JdbcCliFunction<Void, RegionMapping[]> {

ListMappingFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.internal;

import java.io.IOException;
import java.net.URL;
import java.util.Collection;

import org.apache.geode.distributed.internal.DistributedSystemService;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.internal.ClassPathLoader;
import org.apache.geode.internal.InternalDataSerializer;

public class ConnectorsDistributedSystemService implements DistributedSystemService {
@Override
public void init(InternalDistributedSystem internalDistributedSystem) {

}

@Override
public Class getInterface() {
return getClass();
}

@Override
public Collection<String> getSerializationWhitelist() throws IOException {
URL sanctionedSerializables = ClassPathLoader.getLatest().getResource(getClass(),
"sanctioned-geode-connectors-serializables.txt");
return InternalDataSerializer.loadClassNames(sanctionedSerializables);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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.
org.apache.geode.internal.ConnectorsDistributedSystemService

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
org/apache/geode/connectors/jdbc/JdbcConnectorException,true,1
org/apache/geode/connectors/jdbc/internal/ConnectionConfigExistsException,false
org/apache/geode/connectors/jdbc/internal/ConnectionConfigNotFoundException,false
org/apache/geode/connectors/jdbc/internal/ConnectionConfiguration,false,name:java/lang/String,parameters:java/util/Map,password:java/lang/String,url:java/lang/String,user:java/lang/String
org/apache/geode/connectors/jdbc/internal/RegionMapping,false,columnToFieldMap:java/util/Map,connectionConfigName:java/lang/String,fieldToColumnMap:java/util/Map,pdxClassName:java/lang/String,primaryKeyInValue:java/lang/Boolean,regionName:java/lang/String,tableName:java/lang/String
org/apache/geode/connectors/jdbc/internal/RegionMappingExistsException,false
org/apache/geode/connectors/jdbc/internal/RegionMappingNotFoundException,false
org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionFunction,false
org/apache/geode/connectors/jdbc/internal/cli/AlterMappingFunction,false
org/apache/geode/connectors/jdbc/internal/cli/CreateConnectionFunction,false
org/apache/geode/connectors/jdbc/internal/cli/CreateMappingFunction,false
org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionFunction,false
org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingFunction,false
org/apache/geode/connectors/jdbc/internal/cli/DestroyConnectionFunction,false
org/apache/geode/connectors/jdbc/internal/cli/DestroyMappingFunction,false
org/apache/geode/connectors/jdbc/internal/cli/JdbcCliFunction,false
org/apache/geode/connectors/jdbc/internal/cli/ListConnectionFunction,false
org/apache/geode/connectors/jdbc/internal/cli/ListMappingFunction,false
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.codeAnalysis;

import org.junit.experimental.categories.Category;

import org.apache.geode.test.junit.categories.IntegrationTest;
import org.apache.geode.test.junit.categories.LuceneTest;


@Category({IntegrationTest.class})
public class AnalyzeConnectorsSerializablesJUnitTest extends AnalyzeSerializablesJUnitTest {

@Override
protected String getModuleName() {
return "geode-connectors";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
class InheritsDefaultPermissionsJDBCFunction extends JdbcCliFunction<String, CliFunctionResult> {

InheritsDefaultPermissionsJDBCFunction() {
super(new FunctionContextArgumentProvider(), new ExceptionHandler());
super();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public class JdbcCliFunctionTest {

@Before
public void setup() {
FunctionContextArgumentProvider argumentProvider = mock(FunctionContextArgumentProvider.class);
ExceptionHandler exceptionHandler = mock(ExceptionHandler.class);
function = new JdbcCliFunction<Void, Void>(argumentProvider, exceptionHandler) {
function = new JdbcCliFunction<Void, Void>() {
@Override
Void getFunctionResult(JdbcConnectorService service, FunctionContext<Void> context) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
org/apache/geode/connectors/jdbc/internal/xml/ElementType
org/apache/geode/connectors/jdbc/internal/xml/ElementType$1
org/apache/geode/connectors/jdbc/internal/xml/ElementType$2
org/apache/geode/connectors/jdbc/internal/xml/ElementType$3
org/apache/geode/connectors/jdbc/internal/xml/ElementType$4
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ public abstract class InternalDataSerializer extends DataSerializer implements D
// jar deployment
+ ";com.sun.proxy.$Proxy*" + ";com.healthmarketscience.rmiio.RemoteInputStream"

+ ";org.apache.geode.connectors.jdbc.internal.**" // TODO - remove this! See GEODE-4752

// geode-modules
+ ";org.apache.geode.modules.util.SessionCustomExpiry" + ";";

Expand Down

0 comments on commit 0908acb

Please sign in to comment.