diff --git a/CHANGES.md b/CHANGES.md index 2b7710fb..2a7889ae 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## Version 1.0.0 (Not yet Released) +* Generate Unique EcChronos ID #678 * Create RepairConfiguration class for repair configurations - Issue #716 * Create DistributedJmxProxy and DistributedJmxProxyFactory - Issue #715 * Create a New Maven Module "utils" for Common Code Reuse - Issue #720 diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/AgentConnectionConfig.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/AgentConnectionConfig.java index 681898a2..b6e9f797 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/AgentConnectionConfig.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/AgentConnectionConfig.java @@ -37,6 +37,7 @@ public final class AgentConnectionConfig private RackAware myRackAware = new RackAware(); private HostAware myHostAware = new HostAware(); private Class myDatacenterAwarePolicy = DataCenterAwarePolicy.class; + private String myInstanceName; /** * Default constructor for AgentConnectionConfig. @@ -46,6 +47,40 @@ public AgentConnectionConfig() } + /** + * Gets unique ecchronos instance name. + * + * @return the instance name. + */ + @JsonProperty("instanceName") + public String getInstanceName() + { + return myInstanceName; + } + + /** + * Sets unique instance name. + * + * @param instanceName + * the instance name as a string. + * @throws ConfigurationException + * if the provided instance name is invalid. + */ + @JsonProperty("instanceName") + public void setInstanceName(final String instanceName) throws ConfigurationException + { + if (instanceName == null || instanceName.isBlank()) + { + throw new ConfigurationException( + "Invalid instance name: " + + + instanceName + + + "\nInstance name must not be null or empty"); + } + myInstanceName = instanceName; + } + /** * Gets the connection type. * diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/spring/BeanConfigurator.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/spring/BeanConfigurator.java index a80f0b8e..68e29dd9 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/spring/BeanConfigurator.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/spring/BeanConfigurator.java @@ -96,7 +96,7 @@ public BeanConfigurator() throws ConfigurationException, UnknownHostException Security security = getSecurityConfig(); cqlSecurity.set(security.getCqlSecurity()); jmxSecurity.set(security.getJmxSecurity()); - ecChronosID = ECCHORONS_ID_PRE_STRING.concat(InetAddress.getLocalHost().getHostName()); + ecChronosID = getConfiguration().getConnectionConfig().getCqlConnection().getAgentConnectionConfig().getInstanceName(); } /** diff --git a/application/src/main/resources/ecc.yml b/application/src/main/resources/ecc.yml index 212ecd52..384ada9c 100644 --- a/application/src/main/resources/ecc.yml +++ b/application/src/main/resources/ecc.yml @@ -24,6 +24,10 @@ connection: ## to connect to. The application will use the configurations ## specified below, connecting to the listed hosts; agent: + ## Each ecchronos instance must have unique name. + ## (instanceName: unique identifier), that will be used + ## as ecchronos_id (partition key in nodes_sync table). + instanceName: unique_identifier ## Define the Agent strategy, it can be ## - datacenterAware; ## - rackAware; and diff --git a/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java b/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java index ffb246fc..18704c18 100644 --- a/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java +++ b/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java @@ -313,5 +313,11 @@ public void testRepairType() RepairType repairType = repairConfig.getRepairType(); assertThat(repairType).isEqualTo(RepairType.VNODE); } + + @Test + public void testInstanceName() + { + assertThat(nativeConnection.getAgentConnectionConfig().getInstanceName()).isEqualTo("unique_identifier"); + } } diff --git a/application/src/test/resources/all_set.yml b/application/src/test/resources/all_set.yml index 6f87ba92..d3556042 100644 --- a/application/src/test/resources/all_set.yml +++ b/application/src/test/resources/all_set.yml @@ -16,6 +16,7 @@ connection: cql: agent: + instanceName: unique_identifier type: datacenterAware localDatacenter: datacenter1 datacenterAwarePolicy: com.ericsson.bss.cassandra.ecchronos.connection.DataCenterAwarePolicy diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 055ce6cf..343e19d1 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -49,6 +49,7 @@ Configuration is available on ecc.yml in the below format. connection: cql: agent: + instanceName: Each instance must have unique instance name. This will be used as ecchronos_id (partition key in nodes_sync table) type: datacenterAware contactPoints: - host: 127.0.0.1 @@ -80,7 +81,7 @@ connection: ### Nodes Sync -To keep track about nodes and instances, the Agent implementation uses the table nodes_sync, that declare nodes by specific ecChronos instances, so to use the Agent is mandatory to create the table below: +To keep track about nodes and instances, the Agent implementation uses the table nodes_sync, that declare nodes by specific ecChronos instances, each instance must have unique instance name, that must be defined in connection.cql.agent.instanceName in ecc.yml. This will be used as ecchronos_id (partition key in nodes_sync table), to use the agent, is mandatory to create the table below: ```cql CREATE TABLE ecchronos.nodes_sync