Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into IGNITE-24163
Browse files Browse the repository at this point in the history
# Conflicts:
#	modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/impl/ConfigurationBasedSinkRegistry.java
  • Loading branch information
PakhomovAlexander committed Jan 8, 2025
2 parents 48a11bf + 3739f46 commit e48737e
Show file tree
Hide file tree
Showing 93 changed files with 1,973 additions and 514 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.apache.ignite.lang.ErrorGroup.ERR_PREFIX;
import static org.apache.ignite.lang.ErrorGroup.errorMessage;
import static org.apache.ignite.lang.ErrorGroup.extractErrorCode;
import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;
import static org.apache.ignite.lang.ErrorGroups.errorGroupByCode;
import static org.apache.ignite.lang.ErrorGroups.extractGroupCode;
import static org.apache.ignite.lang.util.TraceIdUtils.getOrCreateTraceId;
Expand Down Expand Up @@ -57,45 +56,6 @@ public class IgniteException extends RuntimeException implements TraceableExcept
@SuppressWarnings({"NonFinalFieldOfException", "FieldMayBeFinal"})
private UUID traceId;

/**
* Creates an empty exception.
*/
@Deprecated
public IgniteException() {
this(INTERNAL_ERR);
}

/**
* Creates an exception with the given error message.
*
* @param msg Error message.
*/
@Deprecated
public IgniteException(String msg) {
this(INTERNAL_ERR, msg);
}

/**
* Creates a grid exception with the given throwable as a cause and source of the error message.
*
* @param cause Non-null throwable cause.
*/
@Deprecated
public IgniteException(Throwable cause) {
this(INTERNAL_ERR, cause);
}

/**
* Creates an exception with the given error message and optional nested exception.
*
* @param msg Error message.
* @param cause Optional nested exception (can be {@code null}).
*/
@Deprecated
public IgniteException(String msg, @Nullable Throwable cause) {
this(INTERNAL_ERR, msg, cause);
}

/**
* Creates an exception with the given error code.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.ignite.lang;

import java.util.UUID;
import org.apache.ignite.lang.ErrorGroups.Common;
import org.apache.ignite.lang.ErrorGroups.Marshalling;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -33,7 +33,7 @@ public class MarshallerException extends IgniteException {
* @param cause Non-null throwable cause.
*/
public MarshallerException(String msg, @Nullable Throwable cause) {
super(Common.USER_OBJECT_SERIALIZATION_ERR, msg, cause);
super(Marshalling.COMMON_ERR, msg, cause);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@

/** This exception is thrown if a transaction can't be finished for some reason. */
public class TransactionException extends IgniteException {
/**
* Creates a new transaction exception with a message.
*
* @param message The message.
*/
@Deprecated
public TransactionException(String message) {
super(message);
}

/**
* Creates a new transaction exception with a cause.
*
* @param cause The cause.
*/
@Deprecated
public TransactionException(Throwable cause) {
super(cause);
}

/**
* Creates a new transaction exception with the given error code and cause.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.ignite.client.handler;

import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;

import org.apache.ignite.lang.IgniteException;
import org.jetbrains.annotations.Nullable;

Expand All @@ -43,7 +45,9 @@ public ClientResource(Object obj, @Nullable Runnable releaseRunnable) {
*/
public <T> T get(Class<T> type) {
if (!type.isInstance(obj)) {
throw new IgniteException("Incorrect resource type. Expected " + type.getName() + ", but got " + obj.getClass().getName());
throw new IgniteException(
INTERNAL_ERR,
"Incorrect resource type. Expected " + type.getName() + ", but got " + obj.getClass().getName());
}

return (T) obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public Builder asyncContinuationExecutor(Executor asyncContinuationExecutor) {
* @return This instance.
*/
public Builder heartbeatInterval(long heartbeatInterval) {
if (heartbeatInterval < 0) {
throw new IllegalArgumentException("Heartbeat interval [" + heartbeatInterval + "] "
+ "must be a non-negative integer value.");
}

this.heartbeatInterval = heartbeatInterval;

return this;
Expand All @@ -255,6 +260,11 @@ public Builder heartbeatInterval(long heartbeatInterval) {
* @return This instance.
*/
public Builder heartbeatTimeout(long heartbeatTimeout) {
if (heartbeatTimeout < 0) {
throw new IllegalArgumentException("Heartbeat timeout [" + heartbeatTimeout + "] "
+ "must be a non-negative integer value.");
}

this.heartbeatTimeout = heartbeatTimeout;

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.Serializable;
import java.net.Inet6Address;
import java.net.UnknownHostException;
import org.apache.ignite.lang.ErrorGroups.Client;
import org.apache.ignite.lang.IgniteException;

/**
Expand Down Expand Up @@ -107,7 +108,7 @@ public static HostAndPort parse(String addrStr, int dfltPort, String errMsgPrefi
* @return Parsed port.
* @throws IgniteException If failed.
*/
private static int parsePort(String portStr, String addrStr, String errMsgPrefix) throws IgniteException {
private static int parsePort(String portStr, String addrStr, String errMsgPrefix) {
try {
int port = Integer.parseInt(portStr);

Expand All @@ -129,8 +130,8 @@ private static int parsePort(String portStr, String addrStr, String errMsgPrefix
* @param errMsg Error message.
* @return Exception.
*/
private static IgniteException createParseError(String addrStr, String errMsgPrefix, String errMsg) {
return new IgniteException(errMsgPrefix + " (" + errMsg + "): " + addrStr);
private static RuntimeException createParseError(String addrStr, String errMsgPrefix, String errMsg) {
return new IgniteException(Client.CONFIGURATION_ERR, errMsgPrefix + " (" + errMsg + "): " + addrStr);
}

/**
Expand All @@ -142,8 +143,8 @@ private static IgniteException createParseError(String addrStr, String errMsgPre
* @param cause Cause exception.
* @return Exception.
*/
private static IgniteException createParseError(String addrStr, String errMsgPrefix, String errMsg, Throwable cause) {
return new IgniteException(errMsgPrefix + " (" + errMsg + "): " + addrStr, cause);
private static RuntimeException createParseError(String addrStr, String errMsgPrefix, String errMsg, Throwable cause) {
return new IgniteException(Client.CONFIGURATION_ERR, errMsgPrefix + " (" + errMsg + "): " + addrStr, cause);
}

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

package org.apache.ignite.client;

import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -70,19 +69,6 @@ public void testHeartbeatShorterThanIdleTimeoutKeepsConnectionAlive() throws Exc
}
}

@SuppressWarnings("ThrowableNotThrown")
@Test
public void testInvalidHeartbeatIntervalThrows() {
try (var srv = new TestServer(300, new FakeIgnite())) {

Builder builder = IgniteClient.builder()
.addresses("127.0.0.1:" + srv.port())
.heartbeatInterval(-50);

assertThrowsWithCause(builder::build, IllegalArgumentException.class, "Negative delay.");
}
}

@Test
public void testHeartbeatTimeoutClosesConnection() throws Exception {
Function<Integer, Integer> responseDelayFunc = requestCount -> requestCount > 1 ? 500 : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static java.util.concurrent.CompletableFuture.failedFuture;
import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
Expand Down Expand Up @@ -153,13 +154,13 @@ public TestClientHandlerModule(
@Override
public CompletableFuture<Void> startAsync(ComponentContext componentContext) {
if (channel != null) {
throw new IgniteException("ClientHandlerModule is already started.");
throw new IgniteException(INTERNAL_ERR, "ClientHandlerModule is already started.");
}

try {
channel = startEndpoint().channel();
} catch (InterruptedException e) {
throw new IgniteException(e);
throw new IgniteException(INTERNAL_ERR, e);
}

return nullCompletedFuture();
Expand Down Expand Up @@ -250,13 +251,13 @@ protected void initChannel(Channel ch) {
if (bindRes.isSuccess()) {
ch = bindRes.channel();
} else if (!(bindRes.cause() instanceof BindException)) {
throw new IgniteException(bindRes.cause());
throw new IgniteException(INTERNAL_ERR, bindRes.cause());
}

if (ch == null) {
String msg = "Cannot start thin client connector endpoint. Port " + port + " is in use.";

throw new IgniteException(msg);
throw new IgniteException(INTERNAL_ERR, msg);
}

return ch.closeFuture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.ignite.client.fakes;

import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;
import static org.mockito.Mockito.mock;

import java.util.ArrayList;
Expand Down Expand Up @@ -106,7 +107,7 @@ public TableViewInternal createTable(String name, int id) {
var oldTable = tables.putIfAbsent(name, newTable);

if (oldTable != null) {
throw new IgniteException(TABLE_EXISTS);
throw new IgniteException(INTERNAL_ERR, TABLE_EXISTS);
}

tablesById.put(newTable.tableId(), newTable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.ignite.internal.metrics.exporters.validator;
package org.apache.ignite.configuration.validation;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -28,5 +28,5 @@
*/
@Target(FIELD)
@Retention(RUNTIME)
public @interface EndpointValidator {
public @interface Endpoint {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.ignite.internal.configuration.presentation;

import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigException;
import com.typesafe.config.ConfigFactory;
Expand Down Expand Up @@ -89,7 +91,7 @@ public CompletableFuture<Void> update(String cfgUpdate) {
} else if (e instanceof ConfigurationChangeException) {
throw (RuntimeException) e.getCause();
} else {
throw new IgniteException(e);
throw new IgniteException(INTERNAL_ERR, e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public class ConfigurationValidatorImpl implements ConfigurationValidator {
new PowerOfTwoValidator(),
new RangeValidator(),
new NotBlankValidator(),
new CamelCaseKeysValidator()
new CamelCaseKeysValidator(),
new EndpointValidator()
);

/** Lazy annotations cache for configuration schema fields. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@
* limitations under the License.
*/

package org.apache.ignite.internal.metrics.exporters.validator;
package org.apache.ignite.internal.configuration.validation;

import java.net.MalformedURLException;
import java.net.URL;
import org.apache.ignite.configuration.validation.Endpoint;
import org.apache.ignite.configuration.validation.ValidationContext;
import org.apache.ignite.configuration.validation.ValidationIssue;
import org.apache.ignite.configuration.validation.Validator;

/** Implementation of the {@link EndpointValidator}. */
public class EndpointValidatorImpl implements Validator<EndpointValidator, String> {
public static final EndpointValidatorImpl INSTANCE = new EndpointValidatorImpl();

/** {@link Validator} implementation for the {@link Endpoint} annotation. */
public class EndpointValidator implements Validator<Endpoint, String> {
@Override
public void validate(EndpointValidator annotation, ValidationContext<String> ctx) {
public void validate(Endpoint annotation, ValidationContext<String> ctx) {
String endpoint = ctx.getNewValue();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@
* limitations under the License.
*/

package org.apache.ignite.internal.metrics.exporters.validator;
package org.apache.ignite.internal.configuration.validation;

import static org.apache.ignite.internal.configuration.validation.TestValidationUtil.mockValidationContext;
import static org.mockito.Mockito.mock;

import org.apache.ignite.configuration.validation.Endpoint;
import org.apache.ignite.configuration.validation.ValidationContext;
import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
import org.apache.ignite.internal.configuration.validation.TestValidationUtil;
import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/** Tests for {@link EndpointValidatorImpl}. */
/** Tests for {@link Endpoint}. */
@ExtendWith(ConfigurationExtension.class)
class EndpointValidatorImplTest extends BaseIgniteAbstractTest {
class EndpointValidatorTest extends BaseIgniteAbstractTest {
private static final EndpointValidator VALIDATOR = new EndpointValidator();

@ParameterizedTest
@ValueSource(strings = {
"http://127.0.0.1:8080",
Expand Down Expand Up @@ -94,8 +96,8 @@ private static void validate(String newValue, String @Nullable ... errorMessageP
);

TestValidationUtil.validate(
EndpointValidatorImpl.INSTANCE,
mock(EndpointValidator.class),
VALIDATOR,
mock(Endpoint.class),
ctx,
errorMessagePrefixes
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void result(@Nullable Serializable r) {

MetaStorageCommandsFactory commandsFactory = new MetaStorageCommandsFactory();

CommandIdGenerator commandIdGenerator = new CommandIdGenerator(UUID::randomUUID);
CommandIdGenerator commandIdGenerator = new CommandIdGenerator(UUID.randomUUID());

lenient().doAnswer(invocationClose -> {
Iif iif = invocationClose.getArgument(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void result(@Nullable Serializable r) {

MetaStorageCommandsFactory commandsFactory = new MetaStorageCommandsFactory();

CommandIdGenerator commandIdGenerator = new CommandIdGenerator(UUID::randomUUID);
CommandIdGenerator commandIdGenerator = new CommandIdGenerator(UUID.randomUUID());

lenient().doAnswer(invocationClose -> {
Iif iif = invocationClose.getArgument(0);
Expand Down
Loading

0 comments on commit e48737e

Please sign in to comment.