Skip to content

Commit

Permalink
GG-14565 Can't connect to cluster by JDBC with cache read-only permis…
Browse files Browse the repository at this point in the history
…sions.
  • Loading branch information
denis-chudov committed Jun 25, 2019
1 parent 19e5c54 commit e1462d1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
Expand Up @@ -64,8 +64,12 @@
*/
@Deprecated
public class JdbcConnection implements Connection {
/** Validation task name. */
private static final String VALID_TASK_NAME =
/** Connection validation task name. */
private static final String CONNECTION_VALID_TASK_NAME =
"org.apache.ignite.internal.jdbc.JdbcConnectionValidationTask";

/** Cache validation task name. */
private static final String CACHE_VALID_TASK_NAME =
"org.apache.ignite.internal.processors.cache.query.jdbc.GridCacheQueryJdbcValidationTask";

/** Ignite client. */
Expand All @@ -86,6 +90,9 @@ public class JdbcConnection implements Connection {
/** Timeout. */
private int timeout;

/** Whether using security. */
private boolean usingSecurity;

/**
* Creates new connection.
*
Expand Down Expand Up @@ -114,10 +121,14 @@ public JdbcConnection(String url, Properties props) throws SQLException {
String passwd = props.getProperty("password");

if (!F.isEmpty(user)) {
usingSecurity = true;

SecurityCredentials creds = new SecurityCredentials(user, passwd);

cfg.setSecurityCredentialsProvider(new SecurityCredentialsBasicProvider(creds));
}
else
usingSecurity = false;

// Disable all fetching and caching for metadata.
cfg.setEnableMetricsCache(false);
Expand Down Expand Up @@ -452,7 +463,9 @@ public JdbcConnection(String url, Properties props) throws SQLException {
throw new SQLException("Invalid timeout: " + timeout);

try {
return client.compute().<Boolean>executeAsync(VALID_TASK_NAME, cacheName).get(timeout, SECONDS);
return client.compute()
.<Boolean>executeAsync(usingSecurity ? CONNECTION_VALID_TASK_NAME : CACHE_VALID_TASK_NAME, cacheName)
.get(timeout, SECONDS);
}
catch (GridClientDisconnectedException | GridClientFutureTimeoutException e) {
throw new SQLException("Failed to establish connection.", e);
Expand Down
@@ -0,0 +1,53 @@
/*
* Copyright 2019 GridGain Systems, Inc. and Contributors.
*
* Licensed under the GridGain Community Edition License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
*
* 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.ignite.internal.jdbc;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.ignite.IgniteException;
import org.apache.ignite.compute.ComputeJob;
import org.apache.ignite.compute.ComputeJobAdapter;
import org.apache.ignite.compute.ComputeJobResult;
import org.apache.ignite.compute.ComputeTaskSplitAdapter;
import org.apache.ignite.internal.util.typedef.F;
import org.jetbrains.annotations.Nullable;

/**
* This task is used for JDBCConnection validation.
*
* @deprecated Using Ignite client node based JDBC driver is preferable.
* See documentation of {@link org.apache.ignite.IgniteJdbcDriver} for details.
*/
@Deprecated
public class JdbcConnectionValidationTask extends ComputeTaskSplitAdapter<Object, Boolean> {
/** */
private static final long serialVersionUID = 0L;

/** {@inheritDoc} */
@Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteException {
return Collections.singletonList(new ComputeJobAdapter() {
@Override public Object execute() throws IgniteException {
return true;
}
});
}

/** {@inheritDoc} */
@Nullable @Override public Boolean reduce(List<ComputeJobResult> results) throws IgniteException {
return F.first(results).getData();
}
}

0 comments on commit e1462d1

Please sign in to comment.