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 3 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 @@ -17,6 +17,7 @@

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

import com.fasterxml.jackson.databind.JsonNode;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
import org.apache.ignite.Ignite;
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 @@ -17,6 +17,7 @@

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

import com.fasterxml.jackson.databind.JsonNode;
import java.util.UUID;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
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,11 @@

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

import java.util.Arrays;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import java.util.Base64;
import java.util.Map;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.IgniteConfiguration;
Expand All @@ -27,6 +31,8 @@
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
*
*/
Expand Down Expand Up @@ -55,9 +61,14 @@ 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();

ObjectReader reader = mapper.readerFor(Map.class);

JsonNode jsonNode = params.length > 2 ?
reader.readTree(new String(Base64.getDecoder().decode(params[2]), UTF_8)) : mapper.createObjectNode();

app.start(appParams);
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,10 +17,17 @@

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

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

import static java.nio.charset.StandardCharsets.UTF_8;

/**
*
*/
Expand All @@ -40,8 +47,15 @@ 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();

ObjectReader reader = mapper.readerFor(Map.class);
anton-vinogradov marked this conversation as resolved.
Show resolved Hide resolved

JsonNode jsonNode = params.length > 2 ?
reader.readTree(new String(Base64.getDecoder().decode(params[2]), UTF_8)) : mapper.createObjectNode();

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

app.start(appParams);
app.start(jsonNode);
}
}
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 Down Expand Up @@ -82,7 +84,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 @@ -106,7 +108,23 @@ def env(self):
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/*%s; " % \
anton-vinogradov marked this conversation as resolved.
Show resolved Hide resolved
(self.user_libs, self.app_service_libs())

def app_service_libs(self):
"""
:return: Libs required to start IgniteAwareApplication java implementation.
"""
if self.version.is_dev:
return ""

libs = ""

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):
libs += ":" + line

return 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