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

Introduce utils Module to Reuse Common Code #724

Merged
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
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changes

## Version 1.0.0 (Not yet Release)
## Version 1.0.0 (Not yet Released)

* Create a New Maven Module "utils" for Common Code Reuse - Issue #720
* Implement ReplicationStateImpl to Manage and Cache Token Range to Replica Mappings - Issue #719
* Implement NodeResolverImpl to Resolve Nodes by IP Address and UUID - Issue #718
* Specify Interval for Next Connection - Issue #674
Expand Down
6 changes: 6 additions & 0 deletions application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.ericsson.bss.cassandra.ecchronos</groupId>
<artifactId>utils</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
*/
package com.ericsson.bss.cassandra.ecchronos.application.config;

import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.ConfigurationException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileSystems;
import java.nio.file.Path;

import com.ericsson.bss.cassandra.ecchronos.application.exceptions.ConfigurationException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
*/
package com.ericsson.bss.cassandra.ecchronos.application.config.connection;

import com.ericsson.bss.cassandra.ecchronos.utils.enums.connection.ConnectionType;
import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.ConfigurationException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.datastax.oss.driver.internal.core.loadbalancing.DefaultLoadBalancingPolicy;
import com.ericsson.bss.cassandra.ecchronos.application.exceptions.ConfigurationException;
import com.ericsson.bss.cassandra.ecchronos.connection.DataCenterAwarePolicy;
import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down Expand Up @@ -227,27 +228,6 @@ public HostAware getHostAware()
return myHostAware;
}

/**
* Enum representing the connection types.
*/
public enum ConnectionType
{
/**
* ecChronos will register its control over all the nodes in the specified datacenter.
*/
datacenterAware,

/**
* ecChronos is responsible only for a subset of racks specified in the declared list.
*/
rackAware,

/**
* ecChronos is responsible only for the specified list of hosts.
*/
hostAware
}

/**
* Configuration for datacenter-aware connections.
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public AgentNativeConnectionProvider(
DistributedNativeBuilder nativeConnectionBuilder =
DistributedNativeConnectionProviderImpl.builder()
.withInitialContactPoints(resolveInitialContactPoints(agentConnectionConfig.getContactPoints()))
.withAgentType(agentConnectionConfig.getType().toString())
.withAgentType(agentConnectionConfig.getType())
.withLocalDatacenter(agentConnectionConfig.getLocalDatacenter())
.withAuthProvider(authProvider)
.withSslEngineFactory(sslEngineFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import com.ericsson.bss.cassandra.ecchronos.core.impl.state.ReplicationStateImpl;
import com.ericsson.bss.cassandra.ecchronos.core.metadata.NodeResolver;
import com.ericsson.bss.cassandra.ecchronos.core.state.ReplicationState;
import com.ericsson.bss.cassandra.ecchronos.data.exceptions.EcChronosException;
import com.ericsson.bss.cassandra.ecchronos.data.sync.EccNodesSync;

import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.ConfigurationException;
import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.EcChronosException;
import java.net.InetAddress;
import java.io.IOException;
import java.net.UnknownHostException;
Expand All @@ -38,7 +39,6 @@
import com.ericsson.bss.cassandra.ecchronos.application.config.ConfigRefresher;
import com.ericsson.bss.cassandra.ecchronos.application.config.ConfigurationHelper;
import com.ericsson.bss.cassandra.ecchronos.application.config.security.Security;
import com.ericsson.bss.cassandra.ecchronos.application.exceptions.ConfigurationException;
import com.ericsson.bss.cassandra.ecchronos.application.providers.AgentNativeConnectionProvider;
import com.ericsson.bss.cassandra.ecchronos.connection.CertificateHandler;
import com.ericsson.bss.cassandra.ecchronos.connection.DistributedNativeConnectionProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.ericsson.bss.cassandra.ecchronos.application.config.Config;
import com.ericsson.bss.cassandra.ecchronos.connection.DistributedJmxConnectionProvider;
import com.ericsson.bss.cassandra.ecchronos.connection.DistributedNativeConnectionProvider;
import com.ericsson.bss.cassandra.ecchronos.data.enums.NodeStatus;
import com.ericsson.bss.cassandra.ecchronos.data.sync.EccNodesSync;
import com.ericsson.bss.cassandra.ecchronos.utils.enums.sync.NodeStatus;
import com.google.common.annotations.VisibleForTesting;
import jakarta.annotation.PostConstruct;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
package com.ericsson.bss.cassandra.ecchronos.application.config;

import com.ericsson.bss.cassandra.ecchronos.application.config.connection.*;
import com.ericsson.bss.cassandra.ecchronos.application.exceptions.ConfigurationException;
import com.ericsson.bss.cassandra.ecchronos.application.providers.AgentJmxConnectionProvider;
import com.ericsson.bss.cassandra.ecchronos.application.providers.AgentNativeConnectionProvider;
import com.ericsson.bss.cassandra.ecchronos.connection.DataCenterAwarePolicy;
import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.databind.DatabindException;
import com.ericsson.bss.cassandra.ecchronos.utils.enums.connection.ConnectionType;
import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.ConfigurationException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

Expand All @@ -30,7 +29,6 @@

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
Expand All @@ -47,7 +45,7 @@ public class TestConfig
private static DistributedJmxConnection distributedJmxConnection;

@Before
public void setup() throws StreamReadException, DatabindException, IOException
public void setup() throws IOException
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

Expand All @@ -66,7 +64,7 @@ public void setup() throws StreamReadException, DatabindException, IOException
@Test
public void testDefaultAgentType()
{
assertThat(nativeConnection.getAgentConnectionConfig().getType()).isEqualTo(AgentConnectionConfig.ConnectionType.datacenterAware);
assertThat(nativeConnection.getAgentConnectionConfig().getType()).isEqualTo(ConnectionType.datacenterAware);
}

@Test
Expand Down Expand Up @@ -237,12 +235,13 @@ public void testMaxDelayLessThanStartDelayThrowsException()
});
assertEquals("Max delay cannot be less than start delay.", exception.getMessage());
}

@Test
public void testConnectionDelay()
{
Interval connectionDelay = config.getConnectionConfig().getConnectionDelay();
assertThat(connectionDelay.getUnit()).isEqualTo(TimeUnit.MINUTES);
assertThat(connectionDelay.getTime()).isEqualTo(45l);
}

}

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

import static org.assertj.core.api.Assertions.assertThat;


public class TestDefaultConfig
{
private static final String DEFAULT_AGENT_FILE_NAME = "nothing_set.yml";
Expand All @@ -47,8 +46,6 @@ public void setup() throws StreamReadException, DatabindException, IOException

}



@Test
public void testConnectionDelayDefault()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import com.ericsson.bss.cassandra.ecchronos.application.config.connection.RetryPolicyConfig;
import com.ericsson.bss.cassandra.ecchronos.connection.DistributedJmxConnectionProvider;
import com.ericsson.bss.cassandra.ecchronos.connection.DistributedNativeConnectionProvider;
import com.ericsson.bss.cassandra.ecchronos.data.enums.NodeStatus;
import com.ericsson.bss.cassandra.ecchronos.data.sync.EccNodesSync;
import com.ericsson.bss.cassandra.ecchronos.utils.enums.sync.NodeStatus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
Expand Down
7 changes: 7 additions & 0 deletions connection.impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
<artifactId>data</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.ericsson.bss.cassandra.ecchronos</groupId>
<artifactId>utils</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Cassandra driver -->
<dependency>
<groupId>com.datastax.oss</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.servererrors.QueryExecutionException;
import com.ericsson.bss.cassandra.ecchronos.connection.impl.providers.DistributedJmxConnectionProviderImpl;
import com.ericsson.bss.cassandra.ecchronos.data.enums.NodeStatus;
import com.ericsson.bss.cassandra.ecchronos.data.exceptions.EcChronosException;
import com.ericsson.bss.cassandra.ecchronos.data.sync.EccNodesSync;
import com.ericsson.bss.cassandra.ecchronos.utils.enums.sync.NodeStatus;
import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.EcChronosException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

import com.ericsson.bss.cassandra.ecchronos.connection.CustomDriverOption;
import com.ericsson.bss.cassandra.ecchronos.connection.DataCenterAwarePolicy;
import com.ericsson.bss.cassandra.ecchronos.connection.impl.enums.ConnectionType;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import com.datastax.oss.driver.api.core.auth.AuthProvider;
Expand All @@ -31,6 +30,7 @@
import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting;
import com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric;
import com.ericsson.bss.cassandra.ecchronos.connection.impl.providers.DistributedNativeConnectionProviderImpl;
import com.ericsson.bss.cassandra.ecchronos.utils.enums.connection.ConnectionType;
import com.google.common.collect.ImmutableList;

import java.net.InetSocketAddress;
Expand Down Expand Up @@ -95,9 +95,9 @@ public final DistributedNativeBuilder withInitialContactPoints(final List<InetSo
* the type of the agent as a {@link String}.
* @return the current instance of {@link DistributedNativeBuilder}.
*/
public final DistributedNativeBuilder withAgentType(final String type)
public final DistributedNativeBuilder withAgentType(final ConnectionType type)
{
myType = ConnectionType.valueOf(type);
myType = type;
return this;
}

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

import com.ericsson.bss.cassandra.ecchronos.connection.impl.builders.ContactEndPoint;
import com.ericsson.bss.cassandra.ecchronos.connection.impl.builders.DistributedNativeBuilder;
import com.ericsson.bss.cassandra.ecchronos.utils.enums.connection.ConnectionType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -136,7 +137,7 @@ public void testResolveRackAware() throws SecurityException, IllegalArgumentExce

DistributedNativeBuilder provider = DistributedNativeConnectionProviderImpl.builder()
.withInitialContactPoints(contactPoints)
.withAgentType("rackAware")
.withAgentType(ConnectionType.rackAware)
.withRackAware(rackList);

List<Node> realNodesList = provider.testResolveRackNodes(mySessionMock, rackList);
Expand All @@ -155,7 +156,7 @@ public void testResolveHostAware()
hostList.add(new InetSocketAddress("127.0.0.3", 9042));
DistributedNativeBuilder provider = DistributedNativeConnectionProviderImpl.builder()
.withInitialContactPoints(contactPoints)
.withAgentType("hostAware")
.withAgentType(ConnectionType.hostAware)
.withHostAware(hostList);
List<Node> realNodesList = provider.testResolveHostAware(mySessionMock, hostList);
assertEquals(3, realNodesList.size());
Expand Down
2 changes: 1 addition & 1 deletion core.impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
<version>${project.version}</version>
</dependency>

<!-- Cassandra driver -->
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
</dependency>

<!-- Cassandra driver -->
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-query-builder</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
package com.ericsson.bss.cassandra.ecchronos.core.impl.table;

import com.ericsson.bss.cassandra.ecchronos.core.exceptions.EcChronosException;
import com.ericsson.bss.cassandra.ecchronos.core.table.TableReference;
import com.ericsson.bss.cassandra.ecchronos.core.table.TableReferenceFactory;
import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.EcChronosException;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
Expand Down
7 changes: 7 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
<artifactId>core</artifactId>

<dependencies>
<!-- Internal -->
<dependency>
<groupId>com.ericsson.bss.cassandra.ecchronos</groupId>
<artifactId>utils</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Cassandra driver -->
<dependency>
<groupId>com.datastax.oss</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.ericsson.bss.cassandra.ecchronos.core.table;

import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata;
import com.ericsson.bss.cassandra.ecchronos.core.exceptions.EcChronosException;
import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.EcChronosException;
import java.util.Set;

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ public interface TableReferenceFactory
* Get all table references in keyspace.
*
* @param keyspace The keyspace name
* @throws com.ericsson.bss.cassandra.ecchronos.core.exceptions.EcChronosException if keyspace does not exist.
* @throws EcChronosException if keyspace does not exist.
* @return A unique set of all table references for a specific keyspace.
*/
Set<TableReference> forKeyspace(String keyspace) throws EcChronosException;
Expand Down
Loading