2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.dao.cassandra;
23 import com.datastax.driver.core.Session;
24 import com.datastax.driver.mapping.MappingManager;
25 import fj.data.Either;
26 import org.apache.commons.lang3.tuple.ImmutablePair;
27 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
28 import org.openecomp.sdc.be.resources.data.togglz.FeatureToggleEvent;
29 import org.openecomp.sdc.common.log.wrappers.Logger;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Component;
33 import javax.annotation.PostConstruct;
34 import java.util.List;
36 @Component("feature_toggle_dao")
37 public class FeatureToggleDao extends CassandraDao {
39 private FeatureToggleAccessor featureToggleAccessor;
40 private static Logger logger = Logger.getLogger(FeatureToggleDao.class.getName());
42 public FeatureToggleDao(CassandraClient cassandraClient) {
43 super(cassandraClient);
49 String keyspace = AuditingTypesConstants.REPO_KEYSPACE;
50 if (client.isConnected()) {
51 Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> result = client.connect(keyspace);
52 if (result.isLeft()) {
53 session = result.left().value().left;
54 manager = result.left().value().right;
55 featureToggleAccessor = manager.createAccessor(FeatureToggleAccessor.class);
56 logger.info("** FeatureToggleDao created");
58 logger.info("** FeatureToggleDao failed");
59 throw new RuntimeException(
60 "Repo keyspace [" + keyspace + "] failed to connect with error : " + result.right().value());
63 logger.info("** Cassandra client isn't connected");
64 logger.info("** FeatureToggleDao created, but not connected");
68 public CassandraOperationStatus save(FeatureToggleEvent featureToggleEvent) {
69 return client.save(featureToggleEvent, FeatureToggleEvent.class, manager);
72 public FeatureToggleEvent get(String feature_name) {
73 return client.getById(feature_name, FeatureToggleEvent.class, manager)
76 logger.debug("Failed to retrieve state of feature [{}] due to error {}", feature_name, r.toString());
81 public CassandraOperationStatus delete(String feature_name) {
82 return client.delete(feature_name, FeatureToggleEvent.class, manager);
85 public List<FeatureToggleEvent> getAllFeatures() {
86 return featureToggleAccessor.getAllFeatures().all();