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

IGNITE-24216 Prefer node from connect string to run control.sh commands #11817

Merged
merged 5 commits into from
Jan 16, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package org.apache.ignite.internal.commandline;

import java.util.Collection;
import java.util.function.Consumer;
import org.apache.ignite.Ignition;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.ClientConfiguration;
import org.apache.ignite.internal.client.GridClientNode;
import org.apache.ignite.internal.client.GridClientNodeStateBeforeStart;
Expand All @@ -34,6 +36,7 @@
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.MANAGEMENT_CLIENT_ATTR;
import static org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLIENT_LISTENER_PORT;

/**
* Adapter of new management API command for {@code control.sh} execution flow.
Expand All @@ -54,7 +57,16 @@ public CliIgniteClientInvoker(Command<A, ?> cmd, A arg, ClientConfiguration cfg)

/** {@inheritDoc} */
@Override protected GridClientNode defaultNode() {
return CommandUtils.clusterToClientNode(igniteClient().cluster().forOldest().node());
String[] addr = cfg.getAddresses()[0].split(":");

String host = addr[0];
String port = addr[1];

Collection<ClusterNode> nodes = igniteClient().cluster().nodes();

return CommandUtils.clusterToClientNode(F.find(nodes, U.oldest(nodes, null), node ->
(node.hostNames().contains(host) || node.addresses().contains(host))
&& port.equals(node.attribute(CLIENT_LISTENER_PORT).toString())));
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.ignite.util.GridCommandHandlerPropertiesTest;
import org.apache.ignite.util.GridCommandHandlerScheduleIndexRebuildTest;
import org.apache.ignite.util.GridCommandHandlerTracingConfigurationTest;
import org.apache.ignite.util.IdleVerifyDumpTest;
import org.apache.ignite.util.MetricCommandTest;
import org.apache.ignite.util.PerformanceStatisticsCommandTest;
import org.apache.ignite.util.SystemViewCommandTest;
Expand Down Expand Up @@ -72,7 +73,9 @@
CdcCommandTest.class,
CdcResendCommandTest.class,

SecurityCommandHandlerPermissionsTest.class
SecurityCommandHandlerPermissionsTest.class,

IdleVerifyDumpTest.class
})
public class IgniteControlUtilityTestSuite2 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ public void testCacheIdleVerifyDumpExcludedCaches() throws Exception {
/**
* @return Build matcher for dump file name.
*/
@NotNull private Matcher dumpFileNameMatcher() {
@NotNull static Matcher dumpFileNameMatcher() {
Pattern fileNamePattern = Pattern.compile(".*" + IdleVerifyDumpTask.class.getSimpleName()
+ " successfully written output to '(.*)'");
return fileNamePattern.matcher(testOut.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.util;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.junit.Test;

import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
import static org.apache.ignite.testframework.GridTestUtils.assertContains;
import static org.apache.ignite.util.GridCommandHandlerClusterByClassTest.dumpFileNameMatcher;

/** */
public class IdleVerifyDumpTest extends GridCommandHandlerClusterByClassAbstractTest {
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
return super.getConfiguration(igniteInstanceName)
.setWorkDirectory(nodeWorkDirectory(igniteInstanceName));
}

/**
* Test ensuring that idle verify dump output file is created exactly
* on server node specified via the --host parameter.
*/
@Test
public void testDumpResultMatchesConnection() throws Exception {
injectTestSystemOut();

client.createCache(DEFAULT_CACHE_NAME).put(1, 1);

checkDump(0);

checkDump(1);
}

/** */
private void checkDump(int nodeIdx) throws Exception {
assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", "--dump", "--port", connectorPort(grid(nodeIdx))));

Matcher fileNameMatcher = dumpFileNameMatcher();

assertTrue(fileNameMatcher.find());

Path dumpFileName = Paths.get(fileNameMatcher.group(1));

String dumpRes = new String(Files.readAllBytes(dumpFileName));

assertContains(log, dumpRes, "The check procedure has finished, no conflicts have been found.");

assertContains(log, dumpFileName.toString(), nodeWorkDirectory(getTestIgniteInstanceName(nodeIdx)));
}

/** */
private String nodeWorkDirectory(String igniteInstanceName) throws IgniteCheckedException {
return new File(U.defaultWorkDirectory(), igniteInstanceName).getAbsolutePath();
}
}
Loading