http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientTcpConnectivitySelfTest.java ---------------------------------------------------------------------- diff --cc modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientTcpConnectivitySelfTest.java index e42d824,0000000..63f5945 mode 100644,000000..100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientTcpConnectivitySelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientTcpConnectivitySelfTest.java @@@ -1,75 -1,0 +1,75 @@@ +/* + * 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.ignite.internal.client.integration; + +import org.apache.ignite.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.internal.client.*; +import org.apache.ignite.internal.util.typedef.*; +import org.jetbrains.annotations.*; + +/** + * Tests the REST client-server TCP connectivity with various configurations. + */ +public class ClientTcpConnectivitySelfTest extends ClientAbstractConnectivitySelfTest { + /** {@inheritDoc} */ + @Override protected Ignite startRestNode(String name, @Nullable String addr, @Nullable Integer port) + throws Exception { + IgniteConfiguration cfg = getConfiguration(name); + + assert cfg.getConnectorConfiguration() == null; + + ConnectorConfiguration clientCfg = new ConnectorConfiguration(); + + if (addr != null) + clientCfg.setHost(addr); + + if (port != null) + clientCfg.setPort(port); + + cfg.setConnectorConfiguration(clientCfg); + + return G.start(cfg); + } + + /** {@inheritDoc} */ + @Override protected int defaultRestPort() { + return IgniteConfiguration.DFLT_TCP_PORT; + } + + /** {@inheritDoc} */ + @Override protected String restAddressAttributeName() { - return GridNodeAttributes.ATTR_REST_TCP_ADDRS; ++ return IgniteNodeAttributes.ATTR_REST_TCP_ADDRS; + } + + /** {@inheritDoc} */ + @Override protected String restHostNameAttributeName() { - return GridNodeAttributes.ATTR_REST_TCP_HOST_NAMES; ++ return IgniteNodeAttributes.ATTR_REST_TCP_HOST_NAMES; + } + + /** {@inheritDoc} */ + @Override protected String restPortAttributeName() { - return GridNodeAttributes.ATTR_REST_TCP_PORT; ++ return IgniteNodeAttributes.ATTR_REST_TCP_PORT; + } + + /** {@inheritDoc} */ + @Override protected GridClientProtocol protocol() { + return GridClientProtocol.TCP; + } +}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientTcpUnreachableMultiNodeSelfTest.java ---------------------------------------------------------------------- diff --cc modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientTcpUnreachableMultiNodeSelfTest.java index 07cafee,0000000..bb3710e mode 100644,000000..100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientTcpUnreachableMultiNodeSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientTcpUnreachableMultiNodeSelfTest.java @@@ -1,146 -1,0 +1,134 @@@ +/* + * 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.ignite.internal.client.integration; + +import org.apache.ignite.internal.client.*; +import org.apache.ignite.internal.client.balancer.*; +import org.apache.ignite.internal.util.typedef.*; + +import java.net.*; +import java.util.*; + +/** + * Test for TCP binary rest protocol with unreachable address. + */ +public class ClientTcpUnreachableMultiNodeSelfTest extends ClientTcpMultiNodeSelfTest { + /** {@inheritDoc} */ + @Override protected GridClientLoadBalancer getBalancer() { + final GridClientLoadBalancer b = super.getBalancer(); + + return new TestGridClientLoadBalancer(b); + } + + /** {@inheritDoc} */ + @Override protected GridClientConfiguration clientConfiguration() throws GridClientException { + GridClientConfiguration cfg = super.clientConfiguration(); + + // Setting low connection timeout to allow multiple threads + // pass the unavailable address quickly. + cfg.setConnectTimeout(100); + + return cfg; + } + + /** + * + */ + private class TestGridClientLoadBalancer implements GridClientLoadBalancer, GridClientTopologyListener { + /** */ + private final GridClientLoadBalancer b; + + /** + * @param b Delegating balancer. + */ + TestGridClientLoadBalancer(GridClientLoadBalancer b) { + this.b = b; + } + + /** {@inheritDoc} */ + @Override public GridClientNode balancedNode(Collection<? extends GridClientNode> nodes) + throws GridClientException { + final GridClientNode node = b.balancedNode(nodes); + + return new GridClientNode() { + @Override public <T> T attribute(String name) { + return node.attribute(name); + } + + @Override public Map<String, Object> attributes() { + return node.attributes(); + } + + @Override public Collection<InetSocketAddress> availableAddresses(GridClientProtocol proto, + boolean filterResolved) { + // Fake address first. + return F.asList(new InetSocketAddress("172.22.13.13", 65432), + F.first(node.availableAddresses(proto, filterResolved))); + } + + @Override public Map<String, GridClientCacheMode> caches() { + return node.caches(); + } + + @Override public int replicaCount() { + return node.replicaCount(); + } + - @Override public List<String> jettyAddresses() { - return node.jettyAddresses(); - } - - @Override public List<String> jettyHostNames() { - return node.jettyHostNames(); - } - - @Override public int httpPort() { - return node.httpPort(); - } - + @Override public List<String> tcpAddresses() { + return node.tcpAddresses(); + } + + @Override public List<String> tcpHostNames() { + return node.tcpHostNames(); + } + + @Override public GridClientNodeMetrics metrics() { + return node.metrics(); + } + + @Override public UUID nodeId() { + return node.nodeId(); + } + + @Override public Object consistentId() { + return node.consistentId(); + } + + @Override public int tcpPort() { + return node.tcpPort(); + } + + @Override public boolean connectable() { + return node.connectable(); + } + }; + } + + /** {@inheritDoc} */ + @Override public void onNodeAdded(GridClientNode node) { + if (b instanceof GridClientTopologyListener) + ((GridClientTopologyListener)b).onNodeAdded(node); + } + + /** {@inheritDoc} */ + @Override public void onNodeRemoved(GridClientNode node) { + if (b instanceof GridClientTopologyListener) + ((GridClientTopologyListener)b).onNodeRemoved(node); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterAbstractSelfTest.java ---------------------------------------------------------------------- diff --cc modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterAbstractSelfTest.java index 1c71097,0000000..7bf8ddb mode 100644,000000..100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterAbstractSelfTest.java @@@ -1,125 -1,0 +1,125 @@@ +/* + * 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.ignite.internal.client.router; + +import org.apache.ignite.*; +import org.apache.ignite.internal.client.*; +import org.apache.ignite.internal.client.integration.*; +import org.apache.ignite.internal.client.router.impl.*; +import org.apache.ignite.logger.log4j.*; +import org.apache.ignite.internal.util.typedef.*; + +import java.util.*; + +/** + * Abstract base class for http routing tests. + */ +public abstract class TcpRouterAbstractSelfTest extends ClientAbstractSelfTest { + /** Port number to use by router. */ + private static final int ROUTER_PORT = BINARY_PORT + 1; + + /** TCP router instance. */ + private static GridTcpRouterImpl router; + + /** Send count. */ + private static long sndCnt; + + /** Receive count. */ + private static long rcvCnt; + + /** {@inheritDoc} */ + @Override protected GridClientProtocol protocol() { + return GridClientProtocol.TCP; + } + + /** {@inheritDoc} */ + @Override protected String serverAddress() { + return null; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + sndCnt = router.getSendCount(); + rcvCnt = router.getReceivedCount(); + + super.beforeTest(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + assert router.getSendCount() > sndCnt : + "Failed to ensure network activity [currCnt=" + router.getSendCount() + ", oldCnt=" + sndCnt + ']'; + assert router.getReceivedCount() > rcvCnt: + "Failed to ensure network activity [currCnt=" + router.getReceivedCount() + ", oldCnt=" + rcvCnt + ']'; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + router = new GridTcpRouterImpl(routerConfiguration()); + + router.start(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + router.stop(); + + super.afterTestsStopped(); + } + + /** {@inheritDoc} */ + @Override protected GridClientConfiguration clientConfiguration() throws GridClientException { + GridClientConfiguration cfg = super.clientConfiguration(); + + cfg.setServers(Collections.<String>emptySet()); + cfg.setRouters(Collections.singleton(HOST + ":" + ROUTER_PORT)); + + return cfg; + } + + /** + * @return Router configuration. + * @throws IgniteCheckedException If failed. + */ + public GridTcpRouterConfiguration routerConfiguration() throws IgniteCheckedException { + GridTcpRouterConfiguration cfg = new GridTcpRouterConfiguration(); + + cfg.setHost(HOST); + cfg.setPort(ROUTER_PORT); + cfg.setPortRange(0); + cfg.setServers(Collections.singleton(HOST+":"+BINARY_PORT)); - cfg.setLogger(new IgniteLog4jLogger(ROUTER_LOG_CFG)); ++ cfg.setLogger(new Log4JLogger(ROUTER_LOG_CFG)); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + @Override public void testConnectable() throws Exception { + GridClient client = client(); + + List<GridClientNode> nodes = client.compute().refreshTopology(false, false); + + assertFalse(F.first(nodes).connectable()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterMultiNodeSelfTest.java ---------------------------------------------------------------------- diff --cc modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterMultiNodeSelfTest.java index e59b082,0000000..8eb8421 mode 100644,000000..100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterMultiNodeSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterMultiNodeSelfTest.java @@@ -1,110 -1,0 +1,110 @@@ +/* + * 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.ignite.internal.client.router; + +import org.apache.ignite.*; +import org.apache.ignite.internal.client.*; +import org.apache.ignite.internal.client.integration.*; +import org.apache.ignite.internal.client.router.impl.*; +import org.apache.ignite.logger.log4j.*; + +import java.util.*; + +import static org.apache.ignite.internal.client.integration.ClientAbstractSelfTest.*; + +/** + * + */ +public class TcpRouterMultiNodeSelfTest extends ClientAbstractMultiNodeSelfTest { + /** Number of routers to start in this test. */ + private static final int ROUTERS_CNT = 5; + + /** Where to start routers' port numeration. */ + private static final int ROUTER_TCP_PORT_BASE = REST_TCP_PORT_BASE + NODES_CNT; + + /** Collection of routers. */ + private static Collection<GridTcpRouterImpl> routers = new ArrayList<>(ROUTERS_CNT); + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + for (int i = 0; i < ROUTERS_CNT; i++) + routers.add(new GridTcpRouterImpl(routerConfiguration(i++))); + + for (GridTcpRouterImpl r : routers) + r.start(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + info("Stopping routers..."); + + for (GridTcpRouterImpl r : routers) + r.stop(); + + info("Routers stopped."); + + routers.clear(); + + super.afterTestsStopped(); + } + + /** {@inheritDoc} */ + @Override protected GridClientProtocol protocol() { + return GridClientProtocol.TCP; + } + + /** {@inheritDoc} */ + @Override protected String serverAddress() { + return null; + } + + /** + * @param i Number of router. Used to avoid configuration conflicts. + * @return Router configuration. + * @throws IgniteCheckedException If failed. + */ + private GridTcpRouterConfiguration routerConfiguration(int i) throws IgniteCheckedException { + GridTcpRouterConfiguration cfg = new GridTcpRouterConfiguration(); + + cfg.setHost(HOST); + cfg.setPort(ROUTER_TCP_PORT_BASE + i); + cfg.setPortRange(0); + cfg.setServers(Collections.singleton(HOST + ":" + REST_TCP_PORT_BASE)); - cfg.setLogger(new IgniteLog4jLogger(ROUTER_LOG_CFG)); ++ cfg.setLogger(new Log4JLogger(ROUTER_LOG_CFG)); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected GridClientConfiguration clientConfiguration() throws GridClientException { + GridClientConfiguration cfg = super.clientConfiguration(); + + cfg.setServers(Collections.<String>emptySet()); + + Collection<String> rtrs = new ArrayList<>(ROUTERS_CNT); + + for (int i = 0; i < ROUTERS_CNT; i++) + rtrs.add(HOST + ':' + (ROUTER_TCP_PORT_BASE + i)); + + cfg.setRouters(rtrs); + + return cfg; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/AbstractRestProcessorSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/ClientMemcachedProtocolSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorSignedSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/RestBinaryProtocolSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/RestMemcacheProtocolSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/RestProcessorTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TaskCommandHandlerSelfTest.java ---------------------------------------------------------------------- diff --cc modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TaskCommandHandlerSelfTest.java index 9befeda,ef65ef0..69c0a2a --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TaskCommandHandlerSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TaskCommandHandlerSelfTest.java @@@ -18,7 -18,7 +18,8 @@@ package org.apache.ignite.internal.processors.rest; import org.apache.ignite.*; +import org.apache.ignite.cache.*; + import org.apache.ignite.client.*; import org.apache.ignite.compute.*; import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java ---------------------------------------------------------------------- diff --cc modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java index ae09467,d34f421..84b1cce --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java @@@ -18,13 -18,14 +18,15 @@@ package org.apache.ignite.internal.processors.rest; import org.apache.ignite.*; -import org.apache.ignite.client.marshaller.*; -import org.apache.ignite.client.marshaller.optimized.*; +import org.apache.ignite.internal.client.marshaller.*; +import org.apache.ignite.internal.client.marshaller.optimized.*; + import org.apache.ignite.internal.processors.rest.client.message.*; + import org.apache.ignite.internal.processors.rest.protocols.tcp.*; import org.apache.ignite.internal.util.*; +import org.apache.ignite.logger.java.*; +import org.apache.ignite.internal.processors.rest.client.message.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.logger.java.*; import org.jetbrains.annotations.*; import java.io.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/TcpRestParserSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcComplexQuerySelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcConnectionSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcEmptyCacheSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcLocalCachesSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcPreparedStatementSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcResultSetSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcStatementSelfTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/java/org/apache/ignite/loadtests/client/ClientTcpSslLoadTest.java ---------------------------------------------------------------------- diff --cc modules/clients/src/test/java/org/apache/ignite/loadtests/client/ClientTcpSslLoadTest.java index f96113d,80776bb..7af6643 --- a/modules/clients/src/test/java/org/apache/ignite/loadtests/client/ClientTcpSslLoadTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/ClientTcpSslLoadTest.java @@@ -17,7 -17,8 +17,8 @@@ package org.apache.ignite.loadtests.client; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.client.*; ++import org.apache.ignite.*; +import org.apache.ignite.internal.client.*; import org.apache.ignite.internal.util.typedef.internal.*; /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/resources/spring-cache.xml ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/resources/spring-router-ssl.xml ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/resources/spring-router.xml ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/resources/spring-server-node.xml ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/clients/src/test/resources/spring-server-ssl-node.xml ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java ---------------------------------------------------------------------- diff --cc modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java index da4b174,0000000..499732c mode 100644,000000..100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java @@@ -1,552 -1,0 +1,518 @@@ +/* + * 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.ignite.configuration; + +import org.apache.ignite.*; +import org.apache.ignite.internal.client.ssl.*; +import org.jetbrains.annotations.*; + +import java.net.*; - import java.util.concurrent.*; + +/** + * REST access configuration. + */ +public class ConnectorConfiguration { + /** Default TCP server port. */ + public static final int DFLT_TCP_PORT = 11211; + + /** Default TCP_NODELAY flag. */ + public static final boolean DFLT_TCP_NODELAY = true; + + /** Default TCP direct buffer flag. */ + public static final boolean DFLT_TCP_DIRECT_BUF = false; + + /** Default REST idle timeout. */ + public static final int DFLT_IDLE_TIMEOUT = 7000; + + /** Default rest port range. */ + public static final int DFLT_PORT_RANGE = 100; + + /** Default size of REST thread pool. */ - public static final int DFLT_CORE_THREAD_CNT = IgniteConfiguration.DFLT_PUBLIC_CORE_THREAD_CNT; ++ public static final int DFLT_REST_CORE_THREAD_CNT = IgniteConfiguration.DFLT_PUBLIC_THREAD_CNT; + + /** Default max size of REST thread pool. */ - public static final int DFLT_MAX_THREAD_CNT = IgniteConfiguration.DFLT_PUBLIC_CORE_THREAD_CNT; ++ public static final int DFLT_REST_MAX_THREAD_CNT = IgniteConfiguration.DFLT_PUBLIC_THREAD_CNT; + + /** Default keep alive time for REST thread pool. */ + public static final long DFLT_KEEP_ALIVE_TIME = 0; + + /** Default max queue capacity of REST thread pool. */ + public static final int DFLT_THREADPOOL_QUEUE_CAP = Integer.MAX_VALUE; + + /** Default socket send and receive buffer size. */ + public static final int DFLT_SOCK_BUF_SIZE = 32 * 1024; + + /** Jetty XML configuration path. */ + private String jettyPath; + + /** REST secret key. */ + private String secretKey; + + /** TCP host. */ + private String host; + + /** TCP port. */ + private int port = DFLT_TCP_PORT; + + /** TCP no delay flag. */ + private boolean noDelay = DFLT_TCP_NODELAY; + + /** REST TCP direct buffer flag. */ + private boolean directBuf = DFLT_TCP_DIRECT_BUF; + + /** REST TCP send buffer size. */ + private int sndBufSize = DFLT_SOCK_BUF_SIZE; + + /** REST TCP receive buffer size. */ + private int rcvBufSize = DFLT_SOCK_BUF_SIZE; + + /** REST TCP send queue limit. */ + private int sndQueueLimit; + + /** REST TCP selector count. */ + private int selectorCnt = Math.min(4, Runtime.getRuntime().availableProcessors()); + + /** Idle timeout. */ + private long idleTimeout = DFLT_IDLE_TIMEOUT; + + /** SSL enable flag, default is disabled. */ + private boolean sslEnabled; + + /** SSL need client auth flag. */ + private boolean sslClientAuth; + + /** SSL context factory for rest binary server. */ + private GridSslContextFactory sslCtxFactory; + + /** Port range */ + private int portRange = DFLT_PORT_RANGE; + - /** REST requests executor service. */ - private ExecutorService execSvc; - - /** REST executor service shutdown flag. */ - private boolean execSvcShutdown = true; ++ /** REST requests thread pool size. */ ++ private int execSvcPoolSize = DFLT_REST_CORE_THREAD_CNT; + + /** Client message interceptor. */ + private ConnectorMessageInterceptor msgInterceptor; + + /** + * Creates client connection configuration with all default values. + */ + public ConnectorConfiguration() { + // No-op. + } + + /** + * Creates client connection configuration by copying all properties from + * given configuration. + * + * @param cfg Client configuration. + */ + public ConnectorConfiguration(ConnectorConfiguration cfg) { + assert cfg != null; + + msgInterceptor = cfg.getMessageInterceptor(); - execSvc = cfg.getExecutorService(); - execSvcShutdown = cfg.isExecutorServiceShutdown(); ++ execSvcPoolSize = cfg.getRestThreadPoolSize(); + idleTimeout = cfg.getIdleTimeout(); + jettyPath = cfg.getJettyPath(); + portRange = cfg.getPortRange(); + secretKey = cfg.getSecretKey(); + directBuf = cfg.isDirectBuffer(); + host = cfg.getHost(); + noDelay = cfg.isNoDelay(); + port = cfg.getPort(); + rcvBufSize = cfg.getReceiveBufferSize(); + selectorCnt = cfg.getSelectorCount(); + sndBufSize = cfg.getSendBufferSize(); + sndQueueLimit = cfg.getSendQueueLimit(); + sslClientAuth = cfg.isSslClientAuth(); + sslCtxFactory = cfg.getSslContextFactory(); + sslEnabled = cfg.isSslEnabled(); + } + + /** + * Sets path, either absolute or relative to {@code IGNITE_HOME}, to {@code JETTY} + * XML configuration file. {@code JETTY} is used to support REST over HTTP protocol for - * accessing GridGain APIs remotely. ++ * accessing Ignite APIs remotely. + * + * @param jettyPath Path to {@code JETTY} XML configuration file. + */ + public void setJettyPath(String jettyPath) { + this.jettyPath = jettyPath; + } + + /** + * Gets path, either absolute or relative to {@code IGNITE_HOME}, to {@code Jetty} + * XML configuration file. {@code Jetty} is used to support REST over HTTP protocol for - * accessing GridGain APIs remotely. ++ * accessing Ignite APIs remotely. + * <p> + * If not provided, Jetty instance with default configuration will be started picking + * {@link IgniteSystemProperties#IGNITE_JETTY_HOST} and {@link IgniteSystemProperties#IGNITE_JETTY_PORT} + * as host and port respectively. + * + * @return Path to {@code JETTY} XML configuration file. + * @see IgniteSystemProperties#IGNITE_JETTY_HOST + * @see IgniteSystemProperties#IGNITE_JETTY_PORT + */ + public String getJettyPath() { + return jettyPath; + } + + /** + * Sets secret key to authenticate REST requests. If key is {@code null} or empty authentication is disabled. + * + * @param secretKey REST secret key. + */ + public void setSecretKey(@Nullable String secretKey) { + this.secretKey = secretKey; + } + + /** + * Gets secret key to authenticate REST requests. If key is {@code null} or empty authentication is disabled. + * + * @return Secret key. + * @see IgniteSystemProperties#IGNITE_JETTY_HOST + * @see IgniteSystemProperties#IGNITE_JETTY_PORT + */ + @Nullable public String getSecretKey() { + return secretKey; + } + + /** + * Gets host for TCP binary protocol server. This can be either an + * IP address or a domain name. + * <p> + * If not defined, system-wide local address will be used + * (see {@link IgniteConfiguration#getLocalHost()}. + * <p> + * You can also use {@code 0.0.0.0} value to bind to all + * locally-available IP addresses. + * + * @return TCP host. + */ + public String getHost() { + return host; + } + + /** + * Sets host for TCP binary protocol server. + * + * @param host TCP host. + */ + public void setHost(String host) { + this.host = host; + } + + /** + * Gets port for TCP binary protocol server. + * <p> + * Default is {@link #DFLT_TCP_PORT}. + * + * @return TCP port. + */ + public int getPort() { + return port; + } + + /** + * Sets port for TCP binary protocol server. + * + * @param port TCP port. + */ + public void setPort(int port) { + this.port = port; + } + + /** + * Gets flag indicating whether {@code TCP_NODELAY} option should be set for accepted client connections. + * Setting this option reduces network latency and should be set to {@code true} in majority of cases. + * For more information, see {@link Socket#setTcpNoDelay(boolean)} + * <p/> + * If not specified, default value is {@link #DFLT_TCP_NODELAY}. + * + * @return Whether {@code TCP_NODELAY} option should be enabled. + */ + public boolean isNoDelay() { + return noDelay; + } + + /** + * Sets whether {@code TCP_NODELAY} option should be set for all accepted client connections. + * + * @param noDelay {@code True} if option should be enabled. + * @see #isNoDelay() + */ + public void setNoDelay(boolean noDelay) { + this.noDelay = noDelay; + } + + /** + * Gets flag indicating whether REST TCP server should use direct buffers. A direct buffer is a buffer + * that is allocated and accessed using native system calls, without using JVM heap. Enabling direct + * buffer <em>may</em> improve performance and avoid memory issues (long GC pauses due to huge buffer + * size). + * + * @return Whether direct buffer should be used. + */ + public boolean isDirectBuffer() { + return directBuf; + } + + /** + * Sets whether to use direct buffer for REST TCP server. + * + * @param directBuf {@code True} if option should be enabled. + * @see #isDirectBuffer() + */ + public void setDirectBuffer(boolean directBuf) { + this.directBuf = directBuf; + } + + /** + * Gets REST TCP server send buffer size. + * + * @return REST TCP server send buffer size (0 for default). + */ + public int getSendBufferSize() { + return sndBufSize; + } + + /** + * Sets REST TCP server send buffer size. + * + * @param sndBufSize Send buffer size. + * @see #getSendBufferSize() + */ + public void setSendBufferSize(int sndBufSize) { + this.sndBufSize = sndBufSize; + } + + /** + * Gets REST TCP server receive buffer size. + * + * @return REST TCP server receive buffer size (0 for default). + */ + public int getReceiveBufferSize() { + return rcvBufSize; + } + + /** + * Sets REST TCP server receive buffer size. + * + * @param rcvBufSize Receive buffer size. + * @see #getReceiveBufferSize() + */ + public void setReceiveBufferSize(int rcvBufSize) { + this.rcvBufSize = rcvBufSize; + } + + /** + * Gets REST TCP server send queue limit. If the limit exceeds, all successive writes will + * block until the queue has enough capacity. + * + * @return REST TCP server send queue limit (0 for unlimited). + */ + public int getSendQueueLimit() { + return sndQueueLimit; + } + + /** + * Sets REST TCP server send queue limit. + * + * @param sndQueueLimit REST TCP server send queue limit (0 for unlimited). + * @see #getSendQueueLimit() + */ + public void setSendQueueLimit(int sndQueueLimit) { + this.sndQueueLimit = sndQueueLimit; + } + + /** + * Gets number of selector threads in REST TCP server. Higher value for this parameter + * may increase throughput, but also increases context switching. + * + * @return Number of selector threads for REST TCP server. + */ + public int getSelectorCount() { + return selectorCnt; + } + + /** + * Sets number of selector threads for REST TCP server. + * + * @param selectorCnt Number of selector threads for REST TCP server. + * @see #getSelectorCount() + */ + public void setSelectorCount(int selectorCnt) { + this.selectorCnt = selectorCnt; + } + + /** + * Gets idle timeout for REST server. + * <p> + * This setting is used to reject half-opened sockets. If no packets + * come within idle timeout, the connection is closed. + * + * @return Idle timeout in milliseconds. + */ + public long getIdleTimeout() { + return idleTimeout; + } + + /** + * Sets idle timeout for REST server. + * + * @param idleTimeout Idle timeout in milliseconds. + * @see #getIdleTimeout() + */ + public void setIdleTimeout(long idleTimeout) { + this.idleTimeout = idleTimeout; + } + + /** + * Whether secure socket layer should be enabled on binary rest server. + * <p> + * Note that if this flag is set to {@code true}, an instance of {@link GridSslContextFactory} + * should be provided, otherwise binary rest protocol will fail to start. + * + * @return {@code True} if SSL should be enabled. + */ + public boolean isSslEnabled() { + return sslEnabled; + } + + /** + * Sets whether Secure Socket Layer should be enabled for REST TCP binary protocol. + * <p/> + * Note that if this flag is set to {@code true}, then a valid instance of {@link GridSslContextFactory} + * should be provided in {@code GridConfiguration}. Otherwise, TCP binary protocol will fail to start. + * + * @param sslEnabled {@code True} if SSL should be enabled. + */ + public void setSslEnabled(boolean sslEnabled) { + this.sslEnabled = sslEnabled; + } + + /** + * Gets a flag indicating whether or not remote clients will be required to have a valid SSL certificate which + * validity will be verified with trust manager. + * + * @return Whether or not client authentication is required. + */ + public boolean isSslClientAuth() { + return sslClientAuth; + } + + /** + * Sets flag indicating whether or not SSL client authentication is required. + * + * @param sslClientAuth Whether or not client authentication is required. + */ + public void setSslClientAuth(boolean sslClientAuth) { + this.sslClientAuth = sslClientAuth; + } + + /** + * Gets context factory that will be used for creating a secure socket layer of rest binary server. + * + * @return SslContextFactory instance. + * @see GridSslContextFactory + */ + public GridSslContextFactory getSslContextFactory() { + return sslCtxFactory; + } + + /** + * Sets instance of {@link GridSslContextFactory} that will be used to create an instance of {@code SSLContext} + * for Secure Socket Layer on TCP binary protocol. This factory will only be used if + * {@link #setSslEnabled(boolean)} is set to {@code true}. + * + * @param sslCtxFactory Instance of {@link GridSslContextFactory} + */ + public void setSslContextFactory(GridSslContextFactory sslCtxFactory) { + this.sslCtxFactory = sslCtxFactory; + } + + /** + * Gets number of ports to try if configured port is already in use. + * + * @return Number of ports to try. + */ + public int getPortRange() { + return portRange; + } + + /** + * Sets number of ports to try if configured one is in use. + * + * @param portRange Port range. + */ + public void setPortRange(int portRange) { + this.portRange = portRange; + } + + /** - * Should return an instance of fully configured thread pool to be used for ++ * Should return a thread pool size to be used for + * processing of client messages (REST requests). - * <p> - * If not provided, new executor service will be created using the following - * configuration: - * <ul> - * <li>Core pool size - {@link #DFLT_CORE_THREAD_CNT}</li> - * <li>Max pool size - {@link #DFLT_MAX_THREAD_CNT}</li> - * <li>Queue capacity - {@link #DFLT_THREADPOOL_QUEUE_CAP}</li> - * </ul> - * - * @return Thread pool implementation to be used for processing of client - * messages. - */ - public ExecutorService getExecutorService() { - return execSvc; - } - - /** - * Sets thread pool to use for processing of client messages (REST requests). + * - * @param execSvc Thread pool to use for processing of client messages. - */ - public void setExecutorService(ExecutorService execSvc) { - this.execSvc = execSvc; - } - - /** - * Sets REST executor service shutdown flag. - * - * @param execSvcShutdown REST executor service shutdown flag. ++ * @return Thread pool size to be used for processing of client ++ * messages. + */ - public void setExecutorServiceShutdown(boolean execSvcShutdown) { - this.execSvcShutdown = execSvcShutdown; ++ public int getThreadPoolSize() { ++ return threadPoolSize; + } + + /** - * Shutdown flag for REST executor service. - * <p> - * If not provided, default value {@code true} will be used which will shutdown - * executor service when GridGain stops regardless whether it was started before GridGain - * or by GridGain. ++ * Sets thread pool size to use for processing of client messages (REST requests). + * - * @return REST executor service shutdown flag. ++ * @param threadPoolSize Thread pool size to use for processing of client messages. ++ * @see #getRestThreadPoolSize() + */ - public boolean isExecutorServiceShutdown() { - return execSvcShutdown; ++ public void setThreadPoolSize(int threadPoolSize) { ++ this.threadPoolSize = threadPoolSize; + } + + /** + * Gets interceptor for objects, moving to and from remote clients. + * If this method returns {@code null} then no interception will be applied. + * <p> + * Setting interceptor allows to transform all objects exchanged via REST protocol. + * For example if you use custom serialisation on client you can write interceptor + * to transform binary representations received from client to Java objects and later + * access them from java code directly. + * <p> + * Default value is {@code null}. + * + * @see ConnectorMessageInterceptor + * @return Interceptor. + */ + @Nullable public ConnectorMessageInterceptor getMessageInterceptor() { + return msgInterceptor; + } + + /** + * Sets client message interceptor. + * <p> + * Setting interceptor allows to transform all objects exchanged via REST protocol. + * For example if you use custom serialisation on client you can write interceptor + * to transform binary representations received from client to Java objects and later + * access them from java code directly. + * + * @param interceptor Interceptor. + */ + public void setMessageInterceptor(ConnectorMessageInterceptor interceptor) { + msgInterceptor = interceptor; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java ---------------------------------------------------------------------- diff --cc modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index 2b63da3,31a4fb0..f5c83b7 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@@ -18,11 -18,10 +18,10 @@@ package org.apache.ignite.configuration; import org.apache.ignite.*; - import org.apache.ignite.cache.*; -import org.apache.ignite.client.ssl.*; import org.apache.ignite.events.*; - import org.apache.ignite.fs.*; + import org.apache.ignite.internal.processors.hadoop.*; import org.apache.ignite.internal.managers.eventstorage.*; +import org.apache.ignite.internal.processors.hadoop.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.lifecycle.*; @@@ -47,9 -46,8 +46,7 @@@ import org.apache.ignite.spi.swapspace. import javax.management.*; import java.lang.management.*; -import java.net.*; import java.util.*; - import java.util.concurrent.*; import static org.apache.ignite.plugin.segmentation.GridSegmentationPolicy.*; @@@ -408,8 -415,50 +390,8 @@@ public class IgniteConfiguration private long metricsLogFreq = DFLT_METRICS_LOG_FREQ; /** Local event listeners. */ - private Map<IgnitePredicate<? extends IgniteEvent>, int[]> lsnrs; + private Map<IgnitePredicate<? extends Event>, int[]> lsnrs; - /** TCP host. */ - private String restTcpHost; - - /** TCP port. */ - private int restTcpPort = DFLT_TCP_PORT; - - /** TCP no delay flag. */ - private boolean restTcpNoDelay = DFLT_TCP_NODELAY; - - /** REST TCP direct buffer flag. */ - private boolean restTcpDirectBuf = DFLT_REST_TCP_DIRECT_BUF; - - /** REST TCP send buffer size. */ - private int restTcpSndBufSize; - - /** REST TCP receive buffer size. */ - private int restTcpRcvBufSize; - - /** REST TCP send queue limit. */ - private int restTcpSndQueueLimit; - - /** REST TCP selector count. */ - private int restTcpSelectorCnt = Math.min(4, Runtime.getRuntime().availableProcessors()); - - /** Idle timeout. */ - private long restIdleTimeout = DFLT_REST_IDLE_TIMEOUT; - - /** SSL enable flag, default is disabled. */ - private boolean restTcpSslEnabled; - - /** SSL need client auth flag. */ - private boolean restTcpSslClientAuth; - - /** SSL context factory for rest binary server. */ - private GridSslContextFactory restTcpSslCtxFactory; - - /** Port range */ - private int restPortRange = DFLT_REST_PORT_RANGE; - - /** Folders accessible by REST. */ - private String[] restAccessibleFolders; - /** GGFS configuration. */ private IgniteFsConfiguration[] ggfsCfg; @@@ -426,11 -478,8 +408,8 @@@ private GridHadoopConfiguration hadoopCfg; /** Client access configuration. */ - private ClientConnectionConfiguration clientCfg; + private ConnectorConfiguration connectorCfg = new ConnectorConfiguration(); - /** Portable configuration. */ - private PortableConfiguration portableCfg; - /** Warmup closure. Will be invoked before actual grid start. */ private IgniteInClosure<IgniteConfiguration> warmupClos; @@@ -513,11 -565,24 +493,27 @@@ p2pEnabled = cfg.isPeerClassLoadingEnabled(); p2pLocClsPathExcl = cfg.getPeerClassLoadingLocalClassPathExclude(); p2pMissedCacheSize = cfg.getPeerClassLoadingMissedResourcesCacheSize(); - p2pSvc = cfg.getPeerClassLoadingExecutorService(); - p2pSvcShutdown = cfg.getPeerClassLoadingExecutorServiceShutdown(); + p2pPoolSize = cfg.getPeerClassLoadingThreadPoolSize(); pluginCfgs = cfg.getPluginConfigurations(); - portableCfg = cfg.getPortableConfiguration(); qryCfg = cfg.getQueryConfiguration(); + restAccessibleFolders = cfg.getRestAccessibleFolders(); ++ restEnabled = cfg.isRestEnabled(); + restIdleTimeout = cfg.getRestIdleTimeout(); + restPortRange = cfg.getRestPortRange(); + restSecretKey = cfg.getRestSecretKey(); + restTcpHost = cfg.getRestTcpHost(); + restTcpNoDelay = cfg.isRestTcpNoDelay(); + restTcpDirectBuf = cfg.isRestTcpDirectBuffer(); + restTcpSndBufSize = cfg.getRestTcpSendBufferSize(); + restTcpRcvBufSize = cfg.getRestTcpReceiveBufferSize(); + restTcpSndQueueLimit = cfg.getRestTcpSendQueueLimit(); + restTcpSelectorCnt = cfg.getRestTcpSelectorCount(); + restTcpPort = cfg.getRestTcpPort(); + restTcpSslCtxFactory = cfg.getRestTcpSslContextFactory(); + restTcpSslEnabled = cfg.isRestTcpSslEnabled(); + restTcpSslClientAuth = cfg.isRestTcpSslClientAuth(); ++ restExecSvc = cfg.getRestExecutorService(); ++ restSvcShutdown = cfg.getRestExecutorServiceShutdown(); securityCred = cfg.getSecurityCredentialsProvider(); segChkFreq = cfg.getSegmentCheckFrequency(); segPlc = cfg.getSegmentationPolicy(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java ---------------------------------------------------------------------- diff --cc modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index f95d0f1,d2dced1..bd4efc4 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@@ -1477,18 -1479,15 +1479,19 @@@ public class IgniteKernal extends Clust } /** @throws IgniteCheckedException If registration failed. */ - private void registerExecutorMBeans() throws IgniteCheckedException { - pubExecSvcMBean = registerExecutorMBean(cfg.getExecutorService(), "GridExecutionExecutor"); - sysExecSvcMBean = registerExecutorMBean(cfg.getSystemExecutorService(), "GridSystemExecutor"); - mgmtExecSvcMBean = registerExecutorMBean(cfg.getManagementExecutorService(), "GridManagementExecutor"); - p2PExecSvcMBean = registerExecutorMBean(cfg.getPeerClassLoadingExecutorService(), "GridClassLoadingExecutor"); + private void registerExecutorMBeans(ExecutorService execSvc, ExecutorService sysExecSvc, ExecutorService p2pExecSvc, + ExecutorService mgmtExecSvc, ExecutorService restExecSvc) throws IgniteCheckedException { + pubExecSvcMBean = registerExecutorMBean(execSvc, "GridExecutionExecutor"); + sysExecSvcMBean = registerExecutorMBean(sysExecSvc, "GridSystemExecutor"); + mgmtExecSvcMBean = registerExecutorMBean(mgmtExecSvc, "GridManagementExecutor"); + p2PExecSvcMBean = registerExecutorMBean(p2pExecSvc, "GridClassLoadingExecutor"); - if (restExecSvc != null) - restExecSvcMBean = registerExecutorMBean(restExecSvc, "GridRestExecutor"); + ConnectorConfiguration clientCfg = cfg.getConnectorConfiguration(); + + if (clientCfg != null) { + restExecSvcMBean = clientCfg.getExecutorService() != null ? + registerExecutorMBean(clientCfg.getExecutorService(), "GridRestExecutor") : null; + } } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java ---------------------------------------------------------------------- diff --cc modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java index 288d621,8040f2c..5f4f1ae --- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java @@@ -1427,13 -1387,15 +1388,14 @@@ public class IgnitionEx myCfg.setServiceConfiguration(cfg.getServiceConfiguration()); myCfg.setWarmupClosure(cfg.getWarmupClosure()); myCfg.setPluginConfigurations(cfg.getPluginConfigurations()); - myCfg.setTransactionsConfiguration(new TransactionsConfiguration(cfg.getTransactionsConfiguration())); + myCfg.setTransactionConfiguration(new TransactionConfiguration(cfg.getTransactionConfiguration())); myCfg.setQueryConfiguration(cfg.getQueryConfiguration()); + myCfg.setAtomicConfiguration(cfg.getAtomicConfiguration()); - ClientConnectionConfiguration clientCfg = cfg.getClientConnectionConfiguration(); + ConnectorConfiguration clientCfg = cfg.getConnectorConfiguration(); if (clientCfg != null) - clientCfg = new ClientConnectionConfiguration(clientCfg); - + clientCfg = new ConnectorConfiguration(clientCfg); String ntfStr = IgniteSystemProperties.getString(IGNITE_LIFECYCLE_EMAIL_NOTIFY); @@@ -1496,102 -1458,66 +1458,66 @@@ SwapSpaceSpi swapspaceSpi = cfg.getSwapSpaceSpi(); GridIndexingSpi indexingSpi = cfg.getIndexingSpi(); - execSvc = cfg.getExecutorService(); - sysExecSvc = cfg.getSystemExecutorService(); - p2pExecSvc = cfg.getPeerClassLoadingExecutorService(); - mgmtExecSvc = cfg.getManagementExecutorService(); - ggfsExecSvc = cfg.getGgfsExecutorService(); - - if (execSvc == null) { - isAutoExecSvc = true; - - execSvc = new IgniteThreadPoolExecutor( - "pub-" + cfg.getGridName(), - DFLT_PUBLIC_CORE_THREAD_CNT, - DFLT_PUBLIC_MAX_THREAD_CNT, - DFLT_PUBLIC_KEEP_ALIVE_TIME, - new LinkedBlockingQueue<Runnable>(DFLT_PUBLIC_THREADPOOL_QUEUE_CAP)); - - // Pre-start all threads as they are guaranteed to be needed. - ((ThreadPoolExecutor)execSvc).prestartAllCoreThreads(); - } - - if (sysExecSvc == null) { - isAutoSysSvc = true; - - // Note that since we use 'LinkedBlockingQueue', number of - // maximum threads has no effect. - sysExecSvc = new IgniteThreadPoolExecutor( - "sys-" + cfg.getGridName(), - DFLT_SYSTEM_CORE_THREAD_CNT, - DFLT_SYSTEM_MAX_THREAD_CNT, - DFLT_SYSTEM_KEEP_ALIVE_TIME, - new LinkedBlockingQueue<Runnable>(DFLT_SYSTEM_THREADPOOL_QUEUE_CAP)); - - // Pre-start all threads as they are guaranteed to be needed. - ((ThreadPoolExecutor)sysExecSvc).prestartAllCoreThreads(); - } - - if (mgmtExecSvc == null) { - isAutoMgmtSvc = true; - - // Note that since we use 'LinkedBlockingQueue', number of - // maximum threads has no effect. - // Note, that we do not pre-start threads here as management pool may - // not be needed. - mgmtExecSvc = new IgniteThreadPoolExecutor( - "mgmt-" + cfg.getGridName(), - DFLT_MGMT_THREAD_CNT, - DFLT_MGMT_THREAD_CNT, - 0, - new LinkedBlockingQueue<Runnable>()); - } - - if (p2pExecSvc == null) { - isAutoP2PSvc = true; - - // Note that since we use 'LinkedBlockingQueue', number of - // maximum threads has no effect. - // Note, that we do not pre-start threads here as class loading pool may - // not be needed. - p2pExecSvc = new IgniteThreadPoolExecutor( - "p2p-" + cfg.getGridName(), - DFLT_P2P_THREAD_CNT, - DFLT_P2P_THREAD_CNT, - 0, - new LinkedBlockingQueue<Runnable>()); - } - - if (ggfsExecSvc == null) { - isAutoGgfsSvc = true; - - int procCnt = Runtime.getRuntime().availableProcessors(); + execSvc = new IgniteThreadPoolExecutor( + "pub-" + cfg.getGridName(), + cfg.getPublicThreadPoolSize(), + cfg.getPublicThreadPoolSize(), + DFLT_PUBLIC_KEEP_ALIVE_TIME, + new LinkedBlockingQueue<Runnable>(DFLT_PUBLIC_THREADPOOL_QUEUE_CAP)); + + // Pre-start all threads as they are guaranteed to be needed. + ((ThreadPoolExecutor) execSvc).prestartAllCoreThreads(); + + // Note that since we use 'LinkedBlockingQueue', number of + // maximum threads has no effect. + sysExecSvc = new IgniteThreadPoolExecutor( + "sys-" + cfg.getGridName(), + cfg.getSystemThreadPoolSize(), + cfg.getSystemThreadPoolSize(), + DFLT_SYSTEM_KEEP_ALIVE_TIME, + new LinkedBlockingQueue<Runnable>(DFLT_SYSTEM_THREADPOOL_QUEUE_CAP)); - // Note that we do not pre-start threads here as ggfs pool may not be needed. - ggfsExecSvc = new IgniteThreadPoolExecutor( - "ggfs-" + cfg.getGridName(), - procCnt, - procCnt, - 0, - new LinkedBlockingQueue<Runnable>()); - } + // Pre-start all threads as they are guaranteed to be needed. + ((ThreadPoolExecutor) sysExecSvc).prestartAllCoreThreads(); + + // Note that since we use 'LinkedBlockingQueue', number of + // maximum threads has no effect. + // Note, that we do not pre-start threads here as management pool may + // not be needed. + mgmtExecSvc = new IgniteThreadPoolExecutor( + "mgmt-" + cfg.getGridName(), + cfg.getManagementThreadPoolSize(), + cfg.getManagementThreadPoolSize(), + 0, + new LinkedBlockingQueue<Runnable>()); + + // Note that since we use 'LinkedBlockingQueue', number of + // maximum threads has no effect. + // Note, that we do not pre-start threads here as class loading pool may + // not be needed. + p2pExecSvc = new IgniteThreadPoolExecutor( + "p2p-" + cfg.getGridName(), + cfg.getPeerClassLoadingThreadPoolSize(), + cfg.getPeerClassLoadingThreadPoolSize(), + 0, + new LinkedBlockingQueue<Runnable>()); + + // Note that we do not pre-start threads here as ggfs pool may not be needed. + ggfsExecSvc = new IgniteThreadPoolExecutor( + "ggfs-" + cfg.getGridName(), + cfg.getGgfsThreadPoolSize(), + cfg.getGgfsThreadPoolSize(), + 0, + new LinkedBlockingQueue<Runnable>()); if (clientCfg != null) { - restExecSvc = clientCfg.getExecutorService(); - - if (restExecSvc == null) { - isAutoRestSvc = true; - - restExecSvc = new IgniteThreadPoolExecutor( - "rest-" + cfg.getGridName(), - DFLT_CORE_THREAD_CNT, - DFLT_MAX_THREAD_CNT, - DFLT_KEEP_ALIVE_TIME, - new LinkedBlockingQueue<Runnable>(DFLT_THREADPOOL_QUEUE_CAP) - ); - - clientCfg.setExecutorService(restExecSvc); - } + restExecSvc = new IgniteThreadPoolExecutor( + "rest-" + cfg.getGridName(), - clientCfg.getRestThreadPoolSize(), - clientCfg.getRestThreadPoolSize(), ++ clientCfg.getThreadPoolSize(), ++ clientCfg.getThreadPoolSize(), + DFLT_REST_KEEP_ALIVE_TIME, + new LinkedBlockingQueue<Runnable>(DFLT_REST_THREADPOOL_QUEUE_CAP) + ); } utilityCacheExecSvc = new IgniteThreadPoolExecutor( @@@ -1767,11 -1676,8 +1676,8 @@@ myCfg.setAdminEmails(cfg.getAdminEmails()); // REST configuration. - myCfg.setClientConnectionConfiguration(clientCfg); + myCfg.setConnectorConfiguration(clientCfg); - // Portable configuration. - myCfg.setPortableConfiguration(cfg.getPortableConfiguration()); - // Hadoop configuration. myCfg.setHadoopConfiguration(cfg.getHadoopConfiguration()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClient.java ---------------------------------------------------------------------- diff --cc modules/core/src/main/java/org/apache/ignite/internal/client/GridClient.java index 69df16c,0000000..154f61b mode 100644,000000..100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClient.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/client/GridClient.java @@@ -1,146 -1,0 +1,146 @@@ +/* + * 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.ignite.internal.client; + +import java.util.*; + +/** - * GridGain Java client API. ++ * Ignite Java client API. + * <p> + * Contains functionality to get projections for accessing remote + * data and compute functionality, as well as provide listeners on topology changes. + * <p> + * You can obtain an instance of {@code GridClient} through + * {@link GridClientFactory#start(GridClientConfiguration)}. Note that you + * can have multiple instances of {@code GridClient} running in the same VM. For + * information on how to start or stop Grid please refer to {@link GridClientFactory} class. + * <p> + * Use following methods to get access to remote cache functionality: + * <ul> + * <li>{@link #data()}</li> + * <li>{@link #data(String)}</li> + * </ul> + * Use following methods to get access to remote compute functionality: + * <ul> + * <li>{@link #compute()}</li> + * </ul> + * <h1 class="header">Affinity Awareness</h1> - * One of the unique properties of the GridGain remote clients is that they are ++ * One of the unique properties of the Ignite remote clients is that they are + * affinity aware. In other words, both compute and data APIs will optionally + * contact exactly the node where the data is cached based on some affinity key. + * This allows for collocation of computations and data and avoids extra network + * hops that would be necessary if non-affinity nodes were contacted. + * <p> + * If client can't access some of grid nodes directly (for example due to security restrictions) + * either dedicated Router component could be used or some of Grid nodes could act as routers. + * See {@link GridClientConfiguration#getRouters()} for more details. + * @see GridClientCompute + * @see GridClientData + */ +public interface GridClient extends AutoCloseable { + /** + * Gets a unique client identifier. This identifier is generated by factory on client creation + * and used in identification and authentication procedure on server node. + * + * @return Generated client id. + */ + public UUID id(); + + /** + * Gets a data projection for a default grid cache with {@code null} name. + * + * @return Data projection for grid cache with {@code null} name. + * @throws GridClientException If client was closed. + */ + public GridClientData data() throws GridClientException; + + /** + * Gets a data projection for grid cache with name <tt>cacheName</tt>. If + * no data configuration with given name was provided at client startup, an + * exception will be thrown. + * + * @param cacheName Grid cache name for which data projection should be obtained. + * @return Data projection for grid cache with name <tt>cacheName</tt>. + * @throws GridClientException If client was closed or no configuration with given name was provided. + */ + public GridClientData data(String cacheName) throws GridClientException; + + /** + * Gets a default compute projection. Default compute projection will include all nodes + * in remote grid. Selection of node that will be connected to perform operations will be + * done according to {@link org.apache.ignite.internal.client.balancer.GridClientLoadBalancer} provided in client configuration or + * according to affinity if projection call involves affinity key. + * <p> + * More restricted projection configurations may be created with {@link GridClientCompute} methods. + * + * @return Default compute projection. + * + * @see GridClientCompute + */ + public GridClientCompute compute(); + + /** + * Adds topology listener. Remote grid topology is refreshed every + * {@link GridClientConfiguration#getTopologyRefreshFrequency()} milliseconds. If any node was added or removed, + * a listener will be notified. + * + * @param lsnr Listener to add. + */ + public void addTopologyListener(GridClientTopologyListener lsnr); + + /** + * Removes previously added topology listener. + * + * @param lsnr Listener to remove. + */ + public void removeTopologyListener(GridClientTopologyListener lsnr); + + /** + * Gets an unmodifiable snapshot of topology listeners list. + * + * @return List of topology listeners. + */ + public Collection<GridClientTopologyListener> topologyListeners(); + + /** + * Indicates whether client is connected to remote Grid. + * In other words it allow to determine if client is able to communicate + * with Grid right now. If it can't all methods on Compute and Data projections + * throw {@link GridClientDisconnectedException}. + * <p> + * Connection status is updated in background together with topology update. + * See {@link GridClientConfiguration#getTopologyRefreshFrequency()} for more + * details on how background topology update works. + * <p> + * Note that due to asynchronous nature of topology update and connectivity detection + * this method gives no guarantees for subsequent calls for projections methods. + * It can be used only fo diagnostic and monitoring purposes. + * + * @return Whether client is connected to remote Grid. + */ + public boolean connected(); + + /** + * Closes client instance. This method is identical to + * {@link GridClientFactory#stop(UUID) GridClientFactory.stop(clientId)}. + * <p> + * The method is invoked automatically on objects managed by the + * {@code try-with-resources} statement. + */ + @Override public void close(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a1b1b7a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientCacheFlag.java ---------------------------------------------------------------------- diff --cc modules/core/src/main/java/org/apache/ignite/internal/client/GridClientCacheFlag.java index 48982b0,0000000..1d8ac8e mode 100644,000000..100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientCacheFlag.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientCacheFlag.java @@@ -1,65 -1,0 +1,65 @@@ +/* + * 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.ignite.internal.client; + +import java.util.*; + +/** + * Cache projection flags that specify projection behaviour. + */ +public enum GridClientCacheFlag { + /** Skips store, i.e. no read-through and no write-through behavior. */ + SKIP_STORE, + + /** Skip swap space for reads and writes. */ + SKIP_SWAP, + + /** Synchronous commit. */ + SYNC_COMMIT, + + /** + * Switches a cache projection to work in {@code 'invalidation'} mode. + * Instead of updating remote entries with new values, small invalidation + * messages will be sent to set the values to {@code null}. + */ + INVALIDATE, + + /** + * Disable deserialization of portable objects on get operations. + * If set and portable marshaller is used, {@link GridClientData#get(Object)} + * and {@link GridClientData#getAll(Collection)} methods will return - * instances of {@link org.apache.ignite.portables.PortableObject} class instead of user objects. ++ * instances of {@link org.gridgain.grid.portables.PortableObject} class instead of user objects. + * Use this flag if you don't have corresponding class on your client of + * if you want to get access to some individual fields, but do not want to + * fully deserialize the object. + */ + KEEP_PORTABLES; + + /** */ + private static final GridClientCacheFlag[] VALS = values(); + + /** + * Efficiently gets enumerated value from its ordinal. + * + * @param ord Ordinal value. + * @return Enumerated value or {@code null} if ordinal out of range. + */ + public static GridClientCacheFlag fromOrdinal(int ord) { + return ord >= 0 && ord < VALS.length ? VALS[ord] : null; + } +}