summaryrefslogtreecommitdiffstats
path: root/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra')
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java12
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCacheAccessor.java47
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleAccessor.java32
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleDao.java89
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java7
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java2
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java54
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java137
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java4
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ConsumerEventTableDefinition.java101
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/FeatureToggleEventTableDesc.java97
11 files changed, 420 insertions, 162 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java
index 30da6bce6e..3b1fca4cd0 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java
@@ -25,7 +25,7 @@ import com.datastax.driver.core.Session;
import com.datastax.driver.mapping.MappingManager;
import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.resources.data.DAOArtifactData;
import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -67,16 +67,16 @@ public class ArtifactCassandraDao extends CassandraDao {
}
}
- public CassandraOperationStatus saveArtifact(ESArtifactData artifact) {
- return client.save(artifact, ESArtifactData.class, manager);
+ public CassandraOperationStatus saveArtifact(DAOArtifactData artifact) {
+ return client.save(artifact, DAOArtifactData.class, manager);
}
- public Either<ESArtifactData, CassandraOperationStatus> getArtifact(String artifactId) {
- return client.getById(artifactId, ESArtifactData.class, manager);
+ public Either<DAOArtifactData, CassandraOperationStatus> getArtifact(String artifactId) {
+ return client.getById(artifactId, DAOArtifactData.class, manager);
}
public CassandraOperationStatus deleteArtifact(String artifactId) {
- return client.delete(artifactId, ESArtifactData.class, manager);
+ return client.delete(artifactId, DAOArtifactData.class, manager);
}
/**
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCacheAccessor.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCacheAccessor.java
new file mode 100644
index 0000000000..a8f21c9922
--- /dev/null
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCacheAccessor.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.dao.cassandra;
+
+import com.datastax.driver.mapping.Result;
+import com.datastax.driver.mapping.annotations.Accessor;
+import com.datastax.driver.mapping.annotations.Param;
+import com.datastax.driver.mapping.annotations.Query;
+import org.openecomp.sdc.be.resources.data.ComponentCacheData;
+
+import java.util.List;
+
+@Accessor
+public interface ComponentCacheAccessor {
+
+ @Query("SELECT * FROM sdccomponent.componentcache WHERE id IN :ids ALLOW FILTERING")
+ Result<ComponentCacheData> getComponents(@Param("ids") List<String> ids);
+
+ @Query("SELECT * FROM sdccomponent.componentcache WHERE id = :id ALLOW FILTERING")
+ Result<ComponentCacheData> getComponent(@Param("id") String id);
+
+ @Query("SELECT id,modification_time,type FROM sdccomponent.componentcache ALLOW FILTERING")
+ Result<ComponentCacheData> getAllComponentIdTimeAndType();
+
+ // @Query("SELECT * FROM sdcartifact.resources LIMIT 2000")
+ // Result<DAOArtifactData> getListOfResources();
+
+ // Result<DAOArtifactData> getListOfResources(List<String> dids);
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleAccessor.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleAccessor.java
new file mode 100644
index 0000000000..9c639b6cca
--- /dev/null
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleAccessor.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.dao.cassandra;
+
+import com.datastax.driver.mapping.Result;
+import com.datastax.driver.mapping.annotations.Accessor;
+import com.datastax.driver.mapping.annotations.Query;
+import org.openecomp.sdc.be.resources.data.togglz.FeatureToggleEvent;
+
+@Accessor
+public interface FeatureToggleAccessor {
+ @Query("SELECT * FROM sdcrepository.featuretogglestate")
+ Result<FeatureToggleEvent> getAllFeatures();
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleDao.java
new file mode 100644
index 0000000000..dae34ae8e7
--- /dev/null
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleDao.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.dao.cassandra;
+
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.MappingManager;
+import fj.data.Either;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
+import org.openecomp.sdc.be.resources.data.togglz.FeatureToggleEvent;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+
+@Component("feature_toggle_dao")
+public class FeatureToggleDao extends CassandraDao {
+
+ private FeatureToggleAccessor featureToggleAccessor;
+ private static Logger logger = Logger.getLogger(FeatureToggleDao.class.getName());
+
+ public FeatureToggleDao(CassandraClient cassandraClient) {
+ super(cassandraClient);
+ }
+
+
+ @PostConstruct
+ public void init() {
+ String keyspace = AuditingTypesConstants.REPO_KEYSPACE;
+ if (client.isConnected()) {
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> result = client.connect(keyspace);
+ if (result.isLeft()) {
+ session = result.left().value().left;
+ manager = result.left().value().right;
+ featureToggleAccessor = manager.createAccessor(FeatureToggleAccessor.class);
+ logger.info("** FeatureToggleDao created");
+ } else {
+ logger.info("** FeatureToggleDao failed");
+ throw new RuntimeException(
+ "Repo keyspace [" + keyspace + "] failed to connect with error : " + result.right().value());
+ }
+ } else {
+ logger.info("** Cassandra client isn't connected");
+ logger.info("** FeatureToggleDao created, but not connected");
+ }
+ }
+
+ public CassandraOperationStatus save(FeatureToggleEvent featureToggleEvent) {
+ return client.save(featureToggleEvent, FeatureToggleEvent.class, manager);
+ }
+
+ public FeatureToggleEvent get(String feature_name) {
+ return client.getById(feature_name, FeatureToggleEvent.class, manager)
+ .left()
+ .on(r -> {
+ logger.debug("Failed to retrieve state of feature [{}] due to error {}", feature_name, r.toString());
+ return null;
+ });
+ }
+
+ public CassandraOperationStatus delete(String feature_name) {
+ return client.delete(feature_name, FeatureToggleEvent.class, manager);
+ }
+
+ public List<FeatureToggleEvent> getAllFeatures() {
+ return featureToggleAccessor.getAllFeatures().all();
+ }
+
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java
index 22fa3646bd..e009ea6251 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java
@@ -39,7 +39,6 @@ import java.util.List;
@Component("operational-environment-dao")
public class OperationalEnvironmentDao extends CassandraDao {
- private static final String OPERATIONAL_ENVIRONMENT_DAO = "OperationalEnvironmentDao";
private static Logger logger = Logger.getLogger(OperationalEnvironmentDao.class.getName());
private OperationalEnvironmentsAccessor operationalEnvironmentsAccessor;
@@ -59,13 +58,13 @@ public class OperationalEnvironmentDao extends CassandraDao {
operationalEnvironmentsAccessor = manager.createAccessor(OperationalEnvironmentsAccessor.class);
logger.debug("** OperationalEnvironmentDao created");
} else {
- logger.error(EcompLoggerErrorCode.DATA_ERROR, OPERATIONAL_ENVIRONMENT_DAO, OPERATIONAL_ENVIRONMENT_DAO, "** OperationalEnvironmentDao failed");
+ logger.error(EcompLoggerErrorCode.DATA_ERROR, "OperationalEnvironmentDao", "OperationalEnvironmentDao", "** OperationalEnvironmentDao failed");
throw new RuntimeException("OperationalEnvironment keyspace [" + keyspace + "] failed to connect with error : "
+ result.right().value());
}
} else {
- logger.error(EcompLoggerErrorCode.DATA_ERROR, OPERATIONAL_ENVIRONMENT_DAO, OPERATIONAL_ENVIRONMENT_DAO, "** Cassandra client isn't connected");
- logger.error(EcompLoggerErrorCode.DATA_ERROR, OPERATIONAL_ENVIRONMENT_DAO, OPERATIONAL_ENVIRONMENT_DAO, "** OperationalEnvironmentDao created, but not connected");
+ logger.error(EcompLoggerErrorCode.DATA_ERROR, "OperationalEnvironmentDao", "OperationalEnvironmentDao", "** Cassandra client isn't connected");
+ logger.error(EcompLoggerErrorCode.DATA_ERROR, "OperationalEnvironmentDao", "OperationalEnvironmentDao", "** OperationalEnvironmentDao created, but not connected");
}
}
public CassandraOperationStatus save(OperationalEnvironmentEntry operationalEnvironmentEntry) {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java
index 76aaad95a5..b2d9b5c7ea 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java
@@ -44,7 +44,7 @@ public class SdcSchemaFilesCassandraDao extends CassandraDao {
public SdcSchemaFilesCassandraDao(CassandraClient cassandraClient) {
super(cassandraClient);
}
-
+
@PostConstruct
public void init() {
String keyspace = AuditingTypesConstants.ARTIFACT_KEYSPACE;
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java
index 53d71fe3cf..8c09e55c9d 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java
@@ -7,9 +7,9 @@
* Licensed 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.
@@ -40,17 +40,6 @@ import java.util.function.Supplier;
public class SdcSchemaBuilder {
- /**
- * creat key space statment for SimpleStrategy
- */
- private static final String CREATE_KEYSPACE_SIMPLE_STRATEGY = "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'SimpleStrategy', %s};";
- /**
- * creat key space statment for NetworkTopologyStrategy
- */
- private static final String CREATE_KEYSPACE_NETWORK_TOPOLOGY_STRATEGY = "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'NetworkTopologyStrategy', %s};";
-
- private static Logger log = Logger.getLogger(SdcSchemaBuilder.class.getName());
-
private SdcSchemaUtils sdcSchemaUtils;
private Supplier<Configuration.CassandrConfig> cassandraConfigSupplier;
@@ -58,6 +47,16 @@ public class SdcSchemaBuilder {
this.sdcSchemaUtils = sdcSchemaUtils;
this.cassandraConfigSupplier = cassandraConfigSupplier;
}
+ /**
+ * creat key space statment for SimpleStrategy
+ */
+ private static final String CREATE_KEYSPACE_SIMPLE_STRATEGY = "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'SimpleStrategy', %s};";
+ /**
+ * creat key space statment for NetworkTopologyStrategy
+ */
+ private static final String CREATE_KEYSPACE_NETWORK_TOPOLOGY_STRATEGY = "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'NetworkTopologyStrategy', %s};";
+
+ private static Logger log = Logger.getLogger(SdcSchemaBuilder.class.getName());
//TODO remove after 1707_OS migration
private static void handle1707OSMigration(Map<String, Map<String, List<String>>> cassndraMetadata, Map<String, List<ITableDescription>> schemeData){
@@ -66,12 +65,12 @@ public class SdcSchemaBuilder {
list.add(new OldExternalApiEventTableDesc());
schemeData.put("attaudit", list);
}
-
+
}
/**
* the method creates all keyspaces, tables and indexes in case they do not
* already exist. the method can be run multiple times. the method uses the
- * internal enums and external configuration for its operation *
+ * internal enums and external configuration for its operation *
* @return true if the create operation was successful
*/
public boolean createSchema() {
@@ -142,7 +141,7 @@ public class SdcSchemaBuilder {
* creation of a map conting the names of keyspaces tabls and indexes
* already defined in the cassandra keyspacename -> tablename -> list of
* indexes info
- *
+ *
* @param keyspacesMetadata
* cassndra mmetadata
* @return a map of maps of lists holding parsed info
@@ -156,7 +155,7 @@ public class SdcSchemaBuilder {
.map(IndexMetadata::getName)
.collect(Collectors.toList())))));
}
-
+
private static Map<String, Map<String, List<String>>> getMetadataTablesStructure(
List<KeyspaceMetadata> keyspacesMetadata) {
return keyspacesMetadata.stream()
@@ -172,7 +171,7 @@ public class SdcSchemaBuilder {
* the method builds an index name according to a defined logic
* <table>
* _<column>_idx
- *
+ *
* @param table: table name
* @param column: column name
* @return string name of the index
@@ -187,7 +186,7 @@ public class SdcSchemaBuilder {
* @param iTableDescriptions: a list of table description we want to create
* @param keyspaceMetadate: the current tables that exist in the cassandra under this keyspace
* @param session: the session object used for the execution of the query.
- * @param existingTablesMetadata
+ * @param existingTablesMetadata
* the current tables columns that exist in the cassandra under this
* keyspace
*/
@@ -250,8 +249,8 @@ public class SdcSchemaBuilder {
* @param columnDescription
*/
private static void alterTable(Session session, Map<String, List<String>> existingTablesMetadata,
- ITableDescription tableDescription, String tableName,
- Map<String, ImmutablePair<DataType, Boolean>> columnDescription) {
+ ITableDescription tableDescription, String tableName,
+ Map<String, ImmutablePair<DataType, Boolean>> columnDescription) {
List<String> definedTableColumns = existingTablesMetadata.get(tableName);
//add column to casandra if was added to table definition
for (Map.Entry<String, ImmutablePair<DataType, Boolean>> column : columnDescription.entrySet()) {
@@ -269,7 +268,7 @@ public class SdcSchemaBuilder {
/**
* the method create the keyspace in case it does not already exists the
* method uses configurtion to select the needed replication strategy
- *
+ *
* @param keyspace: name of the keyspace we want to create
* @param cassndraMetadata: cassndra metadata
* @param session: the session object used for the execution of the query.
@@ -307,7 +306,7 @@ public class SdcSchemaBuilder {
/**
* the method retries the schem info from the enums describing the tables
- *
+ *
* @return a map of keyspaces to there table info
*/
private static Map<String, List<ITableDescription>> getSchemeData() {
@@ -326,14 +325,14 @@ public class SdcSchemaBuilder {
}
/**
- * the methoed creates the query string for the given keyspace the methoed
+ * the methoed creates the query string for the given keyspace the methoed
* valides the given data according the the requirments of the replication
* strategy SimpleStrategy: "CREATE KEYSPACE IF NOT EXISTS
* <keyspaceName></keyspaceName> WITH replication =
* {'class':'SimpleStrategy', 'replication_factor':2};" SimpleStrategy:
* "CREATE KEYSPACE IF NOT EXISTS <keyspaceName></keyspaceName> WITH
* replication = {'class':'NetworkTopologyStrategy', 'dc1' : 2 ,dc2 : 2 };"
- *
+ *
* @param keyspace
* name of the keyspace we want to create
* @param keyspaceInfo
@@ -390,9 +389,9 @@ public class SdcSchemaBuilder {
public enum ReplicationStrategy {
NETWORK_TOPOLOGY_STRATEGY("NetworkTopologyStrategy"), SIMPLE_STRATEGY("SimpleStrategy");
- private String strategyName;
+ public String strategyName;
- ReplicationStrategy(String strategyName) {
+ private ReplicationStrategy(String strategyName) {
this.strategyName = strategyName;
}
@@ -400,4 +399,5 @@ public class SdcSchemaBuilder {
return strategyName;
}
}
+
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java
index e6b091b72f..3d68980d73 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java
@@ -22,8 +22,13 @@
package org.openecomp.sdc.be.dao.cassandra.schema;
import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Metadata;
+import com.datastax.driver.core.ProtocolVersion;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SocketOptions;
+import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
+import com.datastax.driver.core.policies.LoadBalancingPolicy;
+import com.datastax.driver.core.policies.TokenAwarePolicy;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -34,12 +39,31 @@ import java.util.function.Supplier;
public class SdcSchemaUtils {
private static Logger log = Logger.getLogger(SdcSchemaUtils.class.getName());
+ private Cluster cluster;
+ private boolean isConnected;
+
+
+
+ public SdcSchemaUtils() {
+ super();
+ try {
+ isConnected = false;
+ cluster = createCluster();
+ isConnected = true;
+ } catch (Exception e) {
+ log.info("** CassandraClient isn't connected. error is {}", e);
+ }
+
+ log.info("** cluster created");
+ }
/**
* the method creates the cluster object using the supplied cassandra nodes
* in the configuration
*
* @return cluster object our null in case of an invalid configuration
+ *
+ *
*/
public Cluster createCluster() {
final Configuration.CassandrConfig config = getCassandraConfig();
@@ -53,41 +77,104 @@ public class SdcSchemaUtils {
Cluster.Builder clusterBuilder = Cluster.builder();
nodes.forEach(node -> clusterBuilder.addContactPoint(node).withPort(cassandraPort));
- clusterBuilder.withMaxSchemaAgreementWaitSeconds(60);
-
- if (config.isAuthenticate()) {
- String username = config.getUsername();
- String password = config.getPassword();
- if (username == null || password == null) {
- log.info("authentication is enabled but username or password were not supplied.");
- return null;
+ clusterBuilder.withMaxSchemaAgreementWaitSeconds(60);
+
+ setSocketOptions(clusterBuilder, config);
+ if(!enableAuthentication(clusterBuilder, config)){
+ return null;
+ }
+
+ if(!enableSsl(clusterBuilder, config)){
+ return null;
+ }
+ setLocalDc(clusterBuilder, config);
+
+ return clusterBuilder.build();
+ }
+
+ /**
+ *
+ * @return
+ */
+ public Session connect() {
+ Session session = null;
+ if (cluster != null) {
+ try {
+ session = cluster.connect();
+
+ } catch (Throwable e) {
+ log.debug("Failed to connect cluster, error :", e);
+
}
- clusterBuilder.withCredentials(username, password);
}
- if (config.isSsl()) {
+ return session;
+ }
+
+ public Metadata getMetadata(){
+ if (cluster != null){
+ return cluster.getMetadata();
+ }
+ return null;
+ }
+
+ private void setLocalDc(Cluster.Builder clusterBuilder, Configuration.CassandrConfig config) {
+ String localDataCenter = config.getLocalDataCenter();
+ if (localDataCenter != null) {
+ log.info("localDatacenter was provided, setting Cassndra clint to use datacenter: {} as local.",
+ localDataCenter);
+ LoadBalancingPolicy tokenAwarePolicy = new TokenAwarePolicy(
+ DCAwareRoundRobinPolicy.builder().withLocalDc(localDataCenter).build());
+ clusterBuilder.withLoadBalancingPolicy(tokenAwarePolicy);
+ } else {
+ log.info(
+ "localDatacenter was provided, the driver will use the datacenter of the first contact point that was reached at initialization");
+ }
+ }
+
+ private boolean enableSsl(Cluster.Builder clusterBuilder, Configuration.CassandrConfig config) {
+ boolean ssl = config.isSsl();
+ if (ssl) {
String truststorePath = config.getTruststorePath();
String truststorePassword = config.getTruststorePassword();
if (truststorePath == null || truststorePassword == null) {
- log.info("ssl is enabled but truststorePath or truststorePassword were not supplied.");
- return null;
+ log.error("ssl is enabled but truststorePath or truststorePassword were not supplied.");
+ return false;
+ } else {
+ System.setProperty("javax.net.ssl.trustStore", truststorePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword);
+ clusterBuilder.withSSL();
}
- System.setProperty("javax.net.ssl.trustStore", truststorePath);
- System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword);
- clusterBuilder.withSSL();
+
}
+ return true;
+ }
+
+
+ private void setSocketOptions(Cluster.Builder clusterBuilder, Configuration.CassandrConfig config) {
SocketOptions socketOptions =new SocketOptions();
Integer socketConnectTimeout = config.getSocketConnectTimeout();
if( socketConnectTimeout!=null ){
log.info("SocketConnectTimeout was provided, setting Cassandra client to use SocketConnectTimeout: {} .",socketConnectTimeout);
socketOptions.setConnectTimeoutMillis(socketConnectTimeout);
}
- Integer socketReadTimeout = config.getSocketReadTimeout();
- if( socketReadTimeout != null ){
- log.info("SocketReadTimeout was provided, setting Cassandra client to use SocketReadTimeout: {} .",socketReadTimeout);
- socketOptions.setReadTimeoutMillis(socketReadTimeout);
- }
clusterBuilder.withSocketOptions(socketOptions);
- return clusterBuilder.build();
+ }
+
+ private boolean enableAuthentication(Cluster.Builder clusterBuilder, Configuration.CassandrConfig config) {
+ boolean authenticate = config.isAuthenticate();
+
+ if (authenticate) {
+ String username = config.getUsername();
+ String password = config.getPassword();
+ if (username == null || password == null) {
+ log.error("authentication is enabled but username or password were not supplied.");
+ return false;
+ } else {
+ clusterBuilder.withCredentials(username, password);
+ }
+
+ }
+ return true;
}
public boolean executeStatement(String statement) {
@@ -118,5 +205,13 @@ public class SdcSchemaUtils {
Configuration.CassandrConfig getCassandraConfig() {
return ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig();
}
+
+
+ public void closeCluster() {
+ if (isConnected) {
+ cluster.close();
+ }
+ log.info("** CassandraClient cluster closed");
+ }
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java
index b0209d2a13..a11bcb3881 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java
@@ -35,7 +35,6 @@ public enum Table {
DISTRIBUTION_DEPLOY_EVENT(new DistribDeployEventTableDesc()),
DISTRIBUTION_GET_UEB_CLUSTER_EVENT(new GetUebClusterEventTableDesc()),
AUTH_EVENT(new AuthEventTableDescription()),
- CONSUMER_EVENT(new ConsumerEventTableDefinition()),
CATEGORY_EVENT(new CategoryEventTableDescription()),
GET_USERS_LIST_EVENT(new GetUsersListEventTableDesc()),
GET_CATEGORY_HIERARCHY_EVENT(new GetCatHierEventTableDesc()),
@@ -43,7 +42,8 @@ public enum Table {
SDC_SCHEMA_FILES(new SdcSchemaFilesTableDescription()),
SDC_REPO(new MigrationTasksTableDescription()),
SDC_OPERATIONAL_ENVIRONMENT(new OperationalEnvironmentsTableDescription()),
- AUDIT_ECOMP_OPERATIONAL_ENVIRONMENT(new EcompOperationalEnvironmentEventTableDesc());
+ AUDIT_ECOMP_OPERATIONAL_ENVIRONMENT(new EcompOperationalEnvironmentEventTableDesc()),
+ FEATURE_TOGGLE_STATE(new FeatureToggleEventTableDesc());
ITableDescription tableDescription;
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ConsumerEventTableDefinition.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ConsumerEventTableDefinition.java
deleted file mode 100644
index f829724f4e..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ConsumerEventTableDefinition.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.cassandra.schema.tables;
-
-import com.datastax.driver.core.DataType;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ConsumerEventTableDefinition implements ITableDescription {
-
- @Override
- public List<ImmutablePair<String, DataType>> primaryKeys() {
- List<ImmutablePair<String, DataType>> keys = new ArrayList<>();
- keys.add(new ImmutablePair<>(TIMEBASED_UUID_FIELD, DataType.timeuuid()));
- return keys;
- }
-
- @Override
- public List<ImmutablePair<String, DataType>> clusteringKeys() {
- List<ImmutablePair<String, DataType>> keys = new ArrayList<>();
- keys.add(new ImmutablePair<>(TIMESTAMP_FIELD, DataType.timestamp()));
- return keys;
- }
-
- @Override
- public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() {
- Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>();
-
- for (DEEFieldsDescription field : DEEFieldsDescription.values()) {
- columns.put(field.getName(), new ImmutablePair<>(field.type, field.indexed));
- }
-
- return columns;
- }
-
- @Override
- public String getKeyspace() {
- return AuditingTypesConstants.AUDIT_KEYSPACE;
- }
-
- @Override
- public String getTableName() {
- return AuditingTypesConstants.CONSUMER_EVENT_TYPE;
- }
-
- enum DEEFieldsDescription {
- ACTION("action", DataType.varchar(), true),
- STATUS("status", DataType.varchar(), false),
- DESCRIPTION("description", DataType.varchar(), false),
- ECOMP_USER("ecomp_user", DataType.varchar(), false),
- MODIFIER("modifier", DataType.varchar(), false),
- REQUEST_ID("request_id", DataType.varchar(), false);
-
- private String name;
- private DataType type;
- private boolean indexed;
-
- DEEFieldsDescription(String name, DataType type, boolean indexed) {
- this.name = name;
- this.type = type;
- this.indexed = indexed;
- }
-
- public String getName() {
- return name;
- }
-
- public DataType getType() {
- return type;
- }
-
- public boolean isIndexed() {
- return indexed;
- }
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/FeatureToggleEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/FeatureToggleEventTableDesc.java
new file mode 100644
index 0000000000..4c18f98179
--- /dev/null
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/FeatureToggleEventTableDesc.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.dao.cassandra.schema.tables;
+
+import com.datastax.driver.core.DataType;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class FeatureToggleEventTableDesc implements ITableDescription {
+
+ private static final String FEATURE_NAME = "feature_name";
+
+ @Override
+ public List<ImmutablePair<String, DataType>> primaryKeys() {
+ List<ImmutablePair<String, DataType>> keys = new ArrayList<>();
+ keys.add(new ImmutablePair<>(FEATURE_NAME, DataType.varchar()));
+ return keys;
+ }
+
+ @Override
+ public List<ImmutablePair<String, DataType>> clusteringKeys() {
+ return Lists.newArrayList();
+ }
+
+ @Override
+ public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() {
+ Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>();
+ Arrays.stream(FeatureToggleEventFieldsDescription.values())
+ .forEach(column -> columns.put(column.getName(), ImmutablePair.of(column.getType(), column.isIndexed())));
+ return columns;
+ }
+
+ @Override
+ public String getKeyspace() {
+ return AuditingTypesConstants.REPO_KEYSPACE;
+ }
+
+ @Override
+ public String getTableName() {
+ return AuditingTypesConstants.FEATURE_TOGGLE_STATE;
+ }
+
+ enum FeatureToggleEventFieldsDescription {
+ ENABLED("enabled", DataType.varchar(), false),
+ STRATEGY_ID("strategy_id", DataType.varchar(), false),
+ PARAMETERS("parameters", DataType.varchar(), false);
+
+ private String name;
+ private DataType type;
+ private boolean indexed;
+
+ FeatureToggleEventFieldsDescription(String name, DataType type, boolean indexed) {
+ this.name = name;
+ this.type = type;
+ this.indexed = indexed;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public DataType getType() {
+ return type;
+ }
+
+ public boolean isIndexed() {
+ return indexed;
+ }
+
+ }
+}