Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json params support #8109

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions modules/ducktests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@
<version>5.0.3</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.ignite.internal.ducktest.tests;

import com.fasterxml.jackson.databind.JsonNode;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteDataStreamer;
Expand All @@ -34,13 +35,13 @@ public DataGenerationApplication(Ignite ignite) {
}

/** {@inheritDoc} */
@Override protected void run(String[] args) {
@Override protected void run(JsonNode jsonNode) {
log.info("Creating cache...");

IgniteCache<Integer, Integer> cache = ignite.createCache(args[0]);
IgniteCache<Integer, Integer> cache = ignite.createCache(jsonNode.get("cacheName").asText());

try (IgniteDataStreamer<Integer, Integer> stmr = ignite.dataStreamer(cache.getName())) {
for (int i = 0; i < Integer.parseInt(args[1]); i++) {
for (int i = 0; i < jsonNode.get("range").asInt(); i++) {
anton-vinogradov marked this conversation as resolved.
Show resolved Hide resolved
stmr.addData(i, i);

if (i % 10_000 == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Collection;
import java.util.concurrent.CountDownLatch;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.internal.IgniteEx;
Expand Down Expand Up @@ -47,8 +48,8 @@ public LongTxStreamerApplication(Ignite ignite) {
}

/** {@inheritDoc} */
@Override public void run(String[] args) throws InterruptedException {
IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(args[0]);
@Override public void run(JsonNode jsonNode) throws InterruptedException {
IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(jsonNode.get("cacheName").asText());

log.info("Starting Long Tx...");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.ignite.internal.ducktest.tests.pme_free_switch_test;

import com.fasterxml.jackson.databind.JsonNode;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.internal.ducktest.utils.IgniteAwareApplication;
Expand All @@ -33,10 +34,10 @@ public SingleKeyTxStreamerApplication(Ignite ignite) {
}

/** {@inheritDoc} */
@Override public void run(String[] args) {
IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(args[0]);
@Override public void run(JsonNode jsonNode) {
IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(jsonNode.get("cacheName").asText());

int warmup = Integer.parseInt(args[1]);
int warmup = jsonNode.get("warmup").asInt();

long max = -1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.ignite.internal.ducktest.tests.smoke_test;

import java.util.UUID;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
Expand All @@ -36,7 +37,7 @@ public SimpleApplication(Ignite ignite) {
}

/** {@inheritDoc} */
@Override public void run(String[] args) {
@Override public void run(JsonNode jsonNode) {
IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(UUID.randomUUID().toString());

cache.put(1, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package org.apache.ignite.internal.ducktest.utils;

import java.util.Arrays;
import java.util.Base64;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.IgniteConfiguration;
Expand Down Expand Up @@ -55,9 +57,12 @@ public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start(cfg)) {
IgniteAwareApplication app = (IgniteAwareApplication)clazz.getConstructor(Ignite.class).newInstance(ignite);

String[] appParams = Arrays.copyOfRange(params, 2, params.length);
ObjectMapper mapper = new ObjectMapper();

app.start(appParams);
JsonNode jsonNode = params.length > 2 ?
mapper.readTree(Base64.getDecoder().decode(params[2])) : mapper.createObjectNode();

app.start(jsonNode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.ignite.internal.ducktest.utils;

import java.util.Arrays;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.ignite.Ignite;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.util.typedef.internal.U;
Expand Down Expand Up @@ -159,18 +159,18 @@ protected void recordResult(String name, long val) {
}

/**
*
* @param jsonNode JSON node.
*/
protected abstract void run(String[] args) throws Exception;
protected abstract void run(JsonNode jsonNode) throws Exception;

/**
* @param args Args.
* @param jsonNode JSON node.
*/
public void start(String[] args) {
public void start(JsonNode jsonNode) {
try {
log.info("Application params: " + Arrays.toString(args));
log.info("Application params: " + jsonNode);

run(args);
run(jsonNode);

assert inited : "Was not properly initialized.";
assert finished : "Was not properly finished.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

package org.apache.ignite.internal.ducktest.utils;

import java.util.Arrays;
import java.util.Base64;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

Expand All @@ -40,8 +43,13 @@ public static void main(String[] args) throws Exception {

IgniteAwareApplication app = (IgniteAwareApplication)clazz.getConstructor().newInstance();

String[] appParams = Arrays.copyOfRange(params, 1, params.length);
ObjectMapper mapper = new ObjectMapper();

app.start(appParams);
JsonNode jsonNode = params.length > 2 ?
mapper.readTree(Base64.getDecoder().decode(params[2])) : mapper.createObjectNode();

((ObjectNode)jsonNode).put("cfgPath", params[1]);

app.start(jsonNode);
}
}
2 changes: 1 addition & 1 deletion modules/ducktests/tests/ignitetest/services/ignite.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def start_cmd(self, node):

cmd = "export EXCLUDE_TEST_CLASSES=true; "
cmd += "export IGNITE_LOG_DIR=" + IgniteService.PERSISTENT_ROOT + "; "
cmd += "export USER_LIBS=%s; " % self.user_libs
cmd += "export USER_LIBS=%s; " % ":".join(self.user_libs)
cmd += "%s %s %s 1>> %s 2>> %s &" % \
(self.path.script("ignite.sh"),
jvm_opts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from ignitetest.services.utils.ignite_config import IgniteLoggerConfig, IgniteServerConfig, IgniteClientConfig
from ignitetest.services.utils.ignite_path import IgnitePath
from ignitetest.services.utils.jmx_utils import ignite_jmx_mixin

from ignitetest.tests.utils.version import IgniteVersion


Expand Down Expand Up @@ -66,8 +65,8 @@ def __init__(self, context, num_nodes, modules, client_mode, version, properties

libs = modules or []
libs.extend(["ignite-log4j"])
libs = map(lambda m: self.path.module(m) + "/*", libs)
self.user_libs = ":".join(libs)

self.user_libs = list(map(lambda m: self.path.module(m) + "/*", libs))

def start_node(self, node):
self.init_persistent(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
This module contains the base class to build Ignite aware application written on java.
"""

import base64
import json
import re

from ignitetest.services.utils.ignite_aware import IgniteAwareService
Expand All @@ -26,6 +28,7 @@ class IgniteAwareApplicationService(IgniteAwareService):
"""
The base class to build Ignite aware application written on java.
"""

# pylint: disable=R0913
def __init__(self, context, java_class_name, modules, client_mode, version, properties, params, timeout_sec,
service_java_class_name="org.apache.ignite.internal.ducktest.utils.IgniteAwareApplicationService"):
Expand Down Expand Up @@ -82,7 +85,7 @@ def app_args(self):
args = self.java_class_name + "," + IgniteAwareApplicationService.CONFIG_FILE

if self.params != "":
args += "," + self.params
args += "," + str(base64.b64encode(json.dumps(self.params).encode("UTF-8")))
anton-vinogradov marked this conversation as resolved.
Show resolved Hide resolved

return args

Expand All @@ -103,10 +106,16 @@ def env(self):
"""
:return: Export string of additional environment variables.
"""
if not self.version.is_dev:
# Jackson requred to parse application params at java side. Release's version should be used.
for line in self.nodes[0].account.ssh_capture(
"ls -d %s/libs/optional/ignite-aws/* | grep jackson | tr '\n' ':' | sed 's/.$//'" % self.path.home):
self.user_libs.extend([line])

return "export MAIN_CLASS={main_class}; ".format(main_class=self.servicejava_class_name) + \
"export EXCLUDE_TEST_CLASSES=true; " + \
"export IGNITE_LOG_DIR={log_dir}; ".format(log_dir=self.PERSISTENT_ROOT) + \
"export USER_LIBS=%s:/opt/ignite-dev/modules/ducktests/target/*; " % self.user_libs
"export USER_LIBS=%s:/opt/ignite-dev/modules/ducktests/target/*; " % (":".join(self.user_libs))

def extract_result(self, name):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, version, context):
self.project = context.globals.get("project", "ignite")

home_dir = "%s-%s" % (self.project, str(self.version))
self._home = os.path.join(IgnitePath.IGNITE_INSTALL_ROOT, home_dir)
self.home = os.path.join(IgnitePath.IGNITE_INSTALL_ROOT, home_dir)

def module(self, module_name):
"""
Expand All @@ -48,11 +48,11 @@ def module(self, module_name):
else:
module_path = os.path.join("libs", "optional", module_name)

return os.path.join(self._home, module_path)
return os.path.join(self.home, module_path)

def script(self, script_name):
"""
:param script_name: name of Ignite script
:return: absolute path to the specified script
"""
return os.path.join(self._home, "bin", script_name)
return os.path.join(self.home, "bin", script_name)
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_add_node(self, version):
IgniteApplicationService(self.test_context,
java_class_name="org.apache.ignite.internal.ducktest.tests.DataGenerationApplication",
version=ignite_version,
params="test-cache,%d" % self.DATA_AMOUNT,
params={"cacheName": "test-cache", "range": self.DATA_AMOUNT},
timeout_sec=self.PRELOAD_TIMEOUT).run()

ignite = IgniteService(self.test_context, num_nodes=1, version=ignite_version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test(self, version):
self.test_context,
java_class_name="org.apache.ignite.internal.ducktest.tests.pme_free_switch_test.LongTxStreamerApplication",
properties=self.properties(),
params="test-cache",
params={"cacheName": "test-cache"},
version=ignite_version)

long_tx_streamer.start()
Expand All @@ -100,7 +100,7 @@ def test(self, version):
java_class_name="org.apache.ignite.internal.ducktest.tests.pme_free_switch_test."
"SingleKeyTxStreamerApplication",
properties=self.properties(),
params="test-cache,1000",
params={"cacheName": "test-cache", "warmup": 1000},
version=ignite_version)

single_key_tx_streamer.start()
Expand Down
1 change: 1 addition & 0 deletions modules/ducktests/tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import re
import sys

from setuptools import find_packages, setup
from setuptools.command.test import test as TestCommand

Expand Down