diff options
Diffstat (limited to 'catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra')
28 files changed, 3502 insertions, 0 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 new file mode 100644 index 0000000000..36d9b60eb5 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java @@ -0,0 +1,110 @@ +/*- + * ============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 javax.annotation.PostConstruct; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.resources.data.ESArtifactData; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import com.datastax.driver.core.Session; +import com.datastax.driver.mapping.MappingManager; + +import fj.data.Either; + +@Component("artifact-cassandra-dao") +public class ArtifactCassandraDao extends CassandraDao { + + private static Logger logger = LoggerFactory.getLogger(ArtifactCassandraDao.class.getName()); + + public ArtifactCassandraDao() { + super(); + + } + + @PostConstruct + public void init() { + String keyspace = AuditingTypesConstants.ARTIFACT_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; + logger.info("** ArtifactCassandraDao created"); + } else { + logger.info("** ArtifactCassandraDao failed"); + throw new RuntimeException("Artifact keyspace [" + keyspace + "] failed to connect with error : " + + result.right().value()); + } + } else { + logger.info("** Cassandra client isn't connected"); + logger.info("** ArtifactCassandraDao created, but not connected"); + } + } + + public CassandraOperationStatus saveArtifact(ESArtifactData artifact) { + return client.save(artifact, ESArtifactData.class, manager); + } + + public Either<ESArtifactData, CassandraOperationStatus> getArtifact(String artifactId) { + return client.getById(artifactId, ESArtifactData.class, manager); + } + + public CassandraOperationStatus deleteArtifact(String artifactId) { + return client.delete(artifactId, ESArtifactData.class, manager); + } + + /** + * ---------for use in JUnit only--------------- the method deletes all the + * tables in the audit keyspace + * + * @return the status of the last failed operation or ok if all the deletes + * were successful + */ + public CassandraOperationStatus deleteAllArtifacts() { + logger.info("cleaning all artifacts."); + String query = "truncate sdcArtifact.resources;"; + try { + session.execute(query); + } catch (Exception e) { + logger.debug("Failed to clean artifacts", e); + return CassandraOperationStatus.GENERAL_ERROR; + } + logger.info("cleaning all artifacts finished succsesfully."); + return CassandraOperationStatus.OK; + } + + /** + * the method checks if the given table is empty in the artifact keyspace + * + * @param tableName + * the name of the table we want to check + * @return true if the table is empty + */ + public Either<Boolean, CassandraOperationStatus> isTableEmpty(String tableName) { + return super.isTableEmpty(tableName); + } + +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/AuditAccessor.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/AuditAccessor.java new file mode 100644 index 0000000000..c9262909bf --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/AuditAccessor.java @@ -0,0 +1,75 @@ +/*- + * ============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 org.openecomp.sdc.be.resources.data.auditing.DistributionDeployEvent; +import org.openecomp.sdc.be.resources.data.auditing.DistributionNotificationEvent; +import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent; +import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent; + +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; + +@Accessor +public interface AuditAccessor { + + // ***** distributionstatusevent table + @Query("SELECT * FROM sdcAudit.distributionstatusevent WHERE DID = :did AND ACTION = 'DStatus' ALLOW FILTERING") + Result<DistributionStatusEvent> getListOfDistributionStatuses(@Param("did") String did); + + // ***** resourceadminevent table + @Query("SELECT * FROM sdcAudit.resourceadminevent WHERE SERVICE_INSTANCE_ID = :serviceInstanceId AND ACTION = 'DRequest' ALLOW FILTERING") + Result<ResourceAdminEvent> getServiceDistributionStatus(@Param("serviceInstanceId") String serviceInstanceId); + + @Query("SELECT * FROM sdcAudit.resourceadminevent WHERE SERVICE_INSTANCE_ID = :serviceInstanceId ") + Result<ResourceAdminEvent> getByServiceInstanceId(@Param("serviceInstanceId") String serviceInstanceId); + + @Query("SELECT * FROM sdcAudit.resourceadminevent WHERE SERVICE_INSTANCE_ID = :serviceInstanceId AND PREV_VERSION = :prevVersion ALLOW FILTERING") + Result<ResourceAdminEvent> getAuditByServiceIdAndPrevVersion(@Param("serviceInstanceId") String serviceInstanceId, + @Param("prevVersion") String prevVersion); + + @Query("SELECT * FROM sdcAudit.resourceadminevent WHERE DID = :did AND ACTION = :action ALLOW FILTERING") + Result<ResourceAdminEvent> getDistributionRequest(@Param("did") String did, @Param("action") String action); + + @Query("SELECT * FROM sdcAudit.resourceadminevent WHERE SERVICE_INSTANCE_ID = :serviceInstanceId AND CURR_VERSION = :currVersion ALLOW FILTERING") + Result<ResourceAdminEvent> getAuditByServiceIdAndCurrVersion(@Param("serviceInstanceId") String serviceInstanceId, + @Param("currVersion") String currVersion); + + // ***** distributiondeployevent table + @Query("SELECT * FROM sdcAudit.distributiondeployevent WHERE SERVICE_INSTANCE_ID = :serviceInstanceId AND ACTION = 'DResult' ALLOW FILTERING") + Result<DistributionDeployEvent> getServiceDistributionDeploy(@Param("serviceInstanceId") String serviceInstanceId); + + @Query("SELECT * FROM sdcAudit.distributiondeployevent WHERE DID = :did AND ACTION = :action AND STATUS = :status ALLOW FILTERING") + Result<DistributionDeployEvent> getDistributionDeployByStatus(@Param("did") String did, + @Param("action") String action, @Param("status") String status); + + // ***** distributionnotificationevent table + @Query("SELECT * FROM sdcAudit.distributionnotificationevent WHERE SERVICE_INSTANCE_ID = :serviceInstanceId AND ACTION = 'DNotify' ALLOW FILTERING") + Result<DistributionNotificationEvent> getServiceDistributionNotify( + @Param("serviceInstanceId") String serviceInstanceId); + + @Query("SELECT * FROM sdcAudit.distributionnotificationevent WHERE DID = :did AND ACTION = :action ALLOW FILTERING") + Result<DistributionNotificationEvent> getDistributionNotify(@Param("did") String did, + @Param("action") String action); + +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDao.java new file mode 100644 index 0000000000..73b55b909c --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/AuditCassandraDao.java @@ -0,0 +1,383 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.BeEcompErrorManager; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.cassandra.schema.Table; +import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; +import org.openecomp.sdc.be.resources.data.auditing.DistributionDeployEvent; +import org.openecomp.sdc.be.resources.data.auditing.DistributionNotificationEvent; +import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent; +import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent; +import org.openecomp.sdc.common.config.EcompErrorName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import com.datastax.driver.core.Session; +import com.datastax.driver.mapping.MappingManager; +import com.datastax.driver.mapping.Result; + +import fj.data.Either; + +@Component("audit-cassandra-dao") +public class AuditCassandraDao extends CassandraDao { + + private AuditAccessor auditAccessor; + + private static Logger logger = LoggerFactory.getLogger(AuditCassandraDao.class.getName()); + + public AuditCassandraDao() { + super(); + } + + @PostConstruct + public void init() { + String keyspace = AuditingTypesConstants.AUDIT_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; + auditAccessor = manager.createAccessor(AuditAccessor.class); + logger.info("** AuditCassandraDao created"); + } else { + logger.info("** AuditCassandraDao failed"); + throw new RuntimeException( + "Audit keyspace [" + keyspace + "] failed to connect with error : " + result.right().value()); + } + } else { + logger.info("** Cassandra client isn't connected"); + logger.info("** AuditCassandraDao created, but not connected"); + } + + } + + @SuppressWarnings("unchecked") + public <T extends AuditingGenericEvent> CassandraOperationStatus saveRecord(T entity) { + return client.save(entity, (Class<T>) entity.getClass(), manager); + } + + /** + * + * @param did + * @return + */ + public Either<List<DistributionStatusEvent>, ActionStatus> getListOfDistributionStatuses(String did) { + List<DistributionStatusEvent> remainingElements = new ArrayList<DistributionStatusEvent>(); + + try { + Result<DistributionStatusEvent> events = auditAccessor.getListOfDistributionStatuses(did); + if (events == null) { + logger.debug("not found distribution statuses for did {}", did); + return Either.left(remainingElements); + } + events.all().forEach(event -> { + event.fillFields(); + remainingElements.add(event); + logger.debug(event.toString()); + }); + return Either.left(remainingElements); + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, + "Get DistributionStatuses List"); + BeEcompErrorManager.getInstance().logBeDaoSystemError("Get DistributionStatuses List"); + + logger.debug("failed to get distribution statuses for ", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + public Either<List<DistributionDeployEvent>, ActionStatus> getDistributionDeployByStatus(String did, String action, + String status) { + List<DistributionDeployEvent> remainingElements = new ArrayList<DistributionDeployEvent>(); + + try { + Result<DistributionDeployEvent> events = auditAccessor.getDistributionDeployByStatus(did, action, status); + if (events == null) { + logger.debug("not found distribution statuses for did {}", did); + return Either.left(remainingElements); + } + events.all().forEach(event -> { + event.fillFields(); + remainingElements.add(event); + logger.debug(event.toString()); + }); + + return Either.left(remainingElements); + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, + "Get DistributionStatuses List"); + BeEcompErrorManager.getInstance().logBeDaoSystemError("get Distribution Deploy By Status"); + + logger.debug("failed to get distribution deploy by status for ", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + public Either<List<ResourceAdminEvent>, ActionStatus> getDistributionRequest(String did, String action) { + List<ResourceAdminEvent> remainingElements = new ArrayList<ResourceAdminEvent>(); + + try { + Result<ResourceAdminEvent> events = auditAccessor.getDistributionRequest(did, action); + if (events == null) { + logger.debug("not found distribution requests for did {}", did); + return Either.left(remainingElements); + } + events.all().forEach(event -> { + event.fillFields(); + remainingElements.add(event); + logger.debug(event.toString()); + }); + return Either.left(remainingElements); + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, + "Get DistributionStatuses List"); + BeEcompErrorManager.getInstance().logBeDaoSystemError("get Distribution request"); + + logger.debug("failed to get distribution request for ", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + public Either<List<DistributionNotificationEvent>, ActionStatus> getDistributionNotify(String did, String action) { + List<DistributionNotificationEvent> remainingElements = new ArrayList<DistributionNotificationEvent>(); + + try { + Result<DistributionNotificationEvent> events = auditAccessor.getDistributionNotify(did, action); + if (events == null) { + logger.debug("not found distribution notify for did {}", did); + return Either.left(remainingElements); + } + events.all().forEach(event -> { + event.fillFields(); + remainingElements.add(event); + logger.debug(event.toString()); + }); + + return Either.left(remainingElements); + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, + "Get DistributionStatuses List"); + BeEcompErrorManager.getInstance().logBeDaoSystemError("get Distribution notify"); + + logger.debug("failed to get distribution notify for ", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + public Either<List<ResourceAdminEvent>, ActionStatus> getByServiceInstanceId(String serviceInstanceId) { + List<ResourceAdminEvent> remainingElements = new ArrayList<ResourceAdminEvent>(); + + try { + Result<ResourceAdminEvent> events = auditAccessor.getByServiceInstanceId(serviceInstanceId); + if (events == null) { + logger.debug("not found audit records for serviceInstanceId {}", serviceInstanceId); + return Either.left(remainingElements); + } + events.all().forEach(event -> { + event.fillFields(); + remainingElements.add(event); + logger.debug(event.toString()); + }); + return Either.left(remainingElements); + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, + "Get DistributionStatuses List"); + BeEcompErrorManager.getInstance().logBeDaoSystemError("get Distribution notify"); + + logger.debug("failed to get distribution notify for ", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + /** + * + * @param serviceInstanceId + * @return + */ + public Either<List<? extends AuditingGenericEvent>, ActionStatus> getServiceDistributionStatusesList( + String serviceInstanceId) { + + List<AuditingGenericEvent> resList = new ArrayList<>(); + + try { + Result<ResourceAdminEvent> resourceAdminEvents = auditAccessor + .getServiceDistributionStatus(serviceInstanceId); + + if (resourceAdminEvents != null) { + resourceAdminEvents.all().forEach(event -> { + event.fillFields(); + resList.add(event); + logger.debug(event.toString()); + }); + } + + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, + "Get Service DistributionStatuses List"); + BeEcompErrorManager.getInstance().logBeDaoSystemError("Get Service DistributionStatuses List"); + logger.debug("failed to get distribution statuses for action {}", + AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName(), e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + try { + Result<DistributionDeployEvent> distDeployEvents = auditAccessor + .getServiceDistributionDeploy(serviceInstanceId); + if (distDeployEvents != null) { + distDeployEvents.all().forEach(event -> { + event.fillFields(); + resList.add(event); + logger.debug(event.toString()); + }); + } + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, + "Get Service DistributionStatuses List"); + BeEcompErrorManager.getInstance().logBeDaoSystemError("Get Service DistributionStatuses List"); + logger.debug("failed to get distribution statuses for action {}", + AuditingActionEnum.DISTRIBUTION_DEPLOY.getName(), e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + try { + Result<DistributionNotificationEvent> distNotifEvent = auditAccessor + .getServiceDistributionNotify(serviceInstanceId); + if (distNotifEvent != null) { + distNotifEvent.all().forEach(event -> { + event.fillFields(); + resList.add(event); + logger.debug(event.toString()); + }); + } + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, + "Get Service DistributionStatuses List"); + BeEcompErrorManager.getInstance().logBeDaoSystemError("Get Service DistributionStatuses List"); + logger.debug("failed to get distribution statuses for action {}", + AuditingActionEnum.DISTRIBUTION_NOTIFY.getName(), e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + + return Either.left(resList); + } + + public Either<List<ResourceAdminEvent>, ActionStatus> getAuditByServiceIdAndPrevVersion(String serviceInstanceId, + String prevVersion) { + List<ResourceAdminEvent> remainingElements = new ArrayList<ResourceAdminEvent>(); + + try { + Result<ResourceAdminEvent> events = auditAccessor.getAuditByServiceIdAndPrevVersion(serviceInstanceId, + prevVersion); + if (events == null) { + logger.debug("not found audit records for serviceInstanceId {} andprevVersion {}", serviceInstanceId, + prevVersion); + return Either.left(remainingElements); + } + events.all().forEach(event -> { + event.fillFields(); + remainingElements.add(event); + logger.debug(event.toString()); + }); + return Either.left(remainingElements); + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, + "get Audit By ServiceId And PrevVersion"); + BeEcompErrorManager.getInstance().logBeDaoSystemError("get Audit By ServiceId And PrevVersion"); + + logger.debug("failed to getAuditByServiceIdAndPrevVersion ", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + public Either<List<ResourceAdminEvent>, ActionStatus> getAuditByServiceIdAndCurrVersion(String serviceInstanceId, + String currVersion) { + List<ResourceAdminEvent> remainingElements = new ArrayList<ResourceAdminEvent>(); + + try { + Result<ResourceAdminEvent> events = auditAccessor.getAuditByServiceIdAndCurrVersion(serviceInstanceId, + currVersion); + if (events == null) { + logger.debug("not found audit records for serviceInstanceId {} andprevVersion {}", serviceInstanceId, + currVersion); + return Either.left(remainingElements); + } + events.all().forEach(event -> { + event.fillFields(); + remainingElements.add(event); + logger.debug(event.toString()); + }); + return Either.left(remainingElements); + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, + "get Audit By ServiceId And CurrVersion"); + BeEcompErrorManager.getInstance().logBeDaoSystemError("get Audit By ServiceId And CurrVersion"); + + logger.debug("failed to getAuditByServiceIdAndPrevVersion ", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + /** + * the method checks if the given table is empty in the audit keyspace + * + * @param tableName + * the name of the table we want to check + * @return true if the table is empty + */ + public Either<Boolean, CassandraOperationStatus> isTableEmpty(String tableName) { + return super.isTableEmpty(tableName); + } + + /** + * ---------for use in JUnit only--------------- the method deletes all the + * tables in the audit keyspace + * + * @return the status of the last failed operation or ok if all the deletes + * were successful + */ + public CassandraOperationStatus deleteAllAudit() { + logger.info("cleaning all audit tables."); + String query = "truncate " + AuditingTypesConstants.AUDIT_KEYSPACE + "."; + try { + for (Table table : Table.values()) { + if (table.getTableDescription().getKeyspace().equals(AuditingTypesConstants.AUDIT_KEYSPACE)) { + logger.debug("clean Audit table:{}", table.getTableDescription().getTableName()); + session.execute(query + table.getTableDescription().getTableName() + ";"); + logger.debug("clean Audit table:{} was succsesfull", table.getTableDescription().getTableName()); + } + } + } catch (Exception e) { + logger.error("Failed to clean Audit", e); + return CassandraOperationStatus.GENERAL_ERROR; + } + logger.info("clean all audit finished succsesfully."); + return CassandraOperationStatus.OK; + } +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java new file mode 100644 index 0000000000..10b9b0578c --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java @@ -0,0 +1,207 @@ +/*- + * ============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 java.util.List; + +import javax.annotation.PreDestroy; + +import com.datastax.driver.core.policies.*; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.MappingManager; + +import fj.data.Either; + +@Component("cassandra-client") +public class CassandraClient { + private static Logger logger = LoggerFactory.getLogger(CassandraClient.class.getName()); + + private Cluster cluster; + private boolean isConnected; + + public CassandraClient() { + super(); + isConnected = false; + List<String> cassandraHosts = null; + try { + cassandraHosts = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() + .getCassandraHosts(); + Long reconnectTimeout = ConfigurationManager.getConfigurationManager().getConfiguration() + .getCassandraConfig().getReconnectTimeout(); + + logger.debug("creating cluster to hosts:{} with reconnect timeout:{}", cassandraHosts, reconnectTimeout); + Cluster.Builder clusterBuilder = Cluster.builder() + .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectTimeout)) + .withRetryPolicy(DefaultRetryPolicy.INSTANCE); + + cassandraHosts.forEach(host -> clusterBuilder.addContactPoint(host)); + enableAuthentication(clusterBuilder); + enableSsl(clusterBuilder); + setLocalDc(clusterBuilder); + + cluster = clusterBuilder.build(); + isConnected = true; + } catch (Exception e) { + logger.info("** CassandraClient isn't connected to {}", cassandraHosts); + } + + logger.info("** CassandraClient created"); + } + + private void setLocalDc(Cluster.Builder clusterBuilder) { + String localDataCenter = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() + .getLocalDataCenter(); + if (localDataCenter != null) { + logger.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 { + logger.info( + "localDatacenter was provided, the driver will use the datacenter of the first contact point that was reached at initialization"); + } + } + + private void enableSsl(Cluster.Builder clusterBuilder) { + boolean ssl = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().isSsl(); + if (ssl) { + String truststorePath = ConfigurationManager.getConfigurationManager().getConfiguration() + .getCassandraConfig().getTruststorePath(); + String truststorePassword = ConfigurationManager.getConfigurationManager().getConfiguration() + .getCassandraConfig().getTruststorePassword(); + if (truststorePath == null || truststorePassword == null) { + logger.error("ssl is enabled but truststorePath or truststorePassword were not supplied."); + } else { + System.setProperty("javax.net.ssl.trustStore", truststorePath); + System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword); + clusterBuilder.withSSL(); + } + + } + } + + private void enableAuthentication(Cluster.Builder clusterBuilder) { + boolean authenticate = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() + .isAuthenticate(); + if (authenticate) { + String username = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() + .getUsername(); + String password = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() + .getPassword(); + if (username == null || password == null) { + logger.error("authentication is enabled but username or password were not supplied."); + } else { + clusterBuilder.withCredentials(username, password); + } + + } + } + + /** + * + * @param keyspace + * - key space to connect + * @return + */ + public Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> connect(String keyspace) { + if (cluster != null) { + try { + Session session = cluster.connect(keyspace); + if (session != null) { + MappingManager manager = new MappingManager(session); + return Either.left(new ImmutablePair<Session, MappingManager>(session, manager)); + } else { + return Either.right(CassandraOperationStatus.KEYSPACE_NOT_CONNECTED); + } + } catch (Throwable e) { + logger.debug("Failed to connect to keyspace [{}], error :", keyspace, e); + return Either.right(CassandraOperationStatus.KEYSPACE_NOT_CONNECTED); + } + } + return Either.right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED); + } + + public <T> CassandraOperationStatus save(T entity, Class<T> clazz, MappingManager manager) { + if (!isConnected) { + return CassandraOperationStatus.CLUSTER_NOT_CONNECTED; + } + try { + Mapper<T> mapper = manager.mapper(clazz); + mapper.save(entity); + } catch (Exception e) { + logger.debug("Failed to save entity [{}], error :", entity, e); + return CassandraOperationStatus.GENERAL_ERROR; + } + return CassandraOperationStatus.OK; + } + + public <T> Either<T, CassandraOperationStatus> getById(String id, Class<T> clazz, MappingManager manager) { + if (!isConnected) { + return Either.right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED); + } + try { + Mapper<T> mapper = manager.mapper(clazz); + T result = mapper.get(id); + if (result == null) { + return Either.right(CassandraOperationStatus.NOT_FOUND); + } + return Either.left(result); + } catch (Exception e) { + logger.debug("Failed to get by Id [{}], error :", id, e); + return Either.right(CassandraOperationStatus.GENERAL_ERROR); + } + } + + public <T> CassandraOperationStatus delete(String id, Class<T> clazz, MappingManager manager) { + if (!isConnected) { + return CassandraOperationStatus.CLUSTER_NOT_CONNECTED; + } + try { + Mapper<T> mapper = manager.mapper(clazz); + mapper.delete(id); + } catch (Exception e) { + logger.debug("Failed to delete by id [{}], error :", id, e); + return CassandraOperationStatus.GENERAL_ERROR; + } + return CassandraOperationStatus.OK; + } + + public boolean isConnected() { + return isConnected; + } + + @PreDestroy + public void closeClient() { + if (isConnected) { + cluster.close(); + } + logger.info("** CassandraClient cluster closed"); + } +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraDao.java new file mode 100644 index 0000000000..1d2eb15354 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraDao.java @@ -0,0 +1,65 @@ +/*- + * ============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.core.ResultSet; +import com.datastax.driver.core.Statement; +import com.datastax.driver.core.querybuilder.QueryBuilder; +import fj.data.Either; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import com.datastax.driver.core.Session; +import com.datastax.driver.mapping.MappingManager; + +public abstract class CassandraDao { + + private static Logger logger = LoggerFactory.getLogger(CassandraDao.class.getName()); + + protected Session session; + protected MappingManager manager; + + @Autowired + protected CassandraClient client; + + /** + * the method checks if the given table is empty under the keyspace the + * session was opened to. + * + * @param tableName + * the name of the table we want to check + * @return returns true if the table was empty + */ + protected Either<Boolean, CassandraOperationStatus> isTableEmpty(String tableName) { + + Statement select = QueryBuilder.select().countAll().from(tableName).limit(10); + try { + ResultSet res = session.execute(select); + return Either.left((res.one().getLong("count") != 0 ? false : true)); + + } catch (Exception e) { + logger.debug("Failed check if table is empty", e); + return Either.right(CassandraOperationStatus.GENERAL_ERROR); + } + } + +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraOperationStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraOperationStatus.java new file mode 100644 index 0000000000..52b71c780b --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraOperationStatus.java @@ -0,0 +1,26 @@ +/*- + * ============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; + +public enum CassandraOperationStatus { + OK, CLUSTER_NOT_CONNECTED, KEYSPACE_NOT_CONNECTED, GENERAL_ERROR, NOT_FOUND + +} 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..828072a4e6 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCacheAccessor.java @@ -0,0 +1,48 @@ +/*- + * ============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 java.util.List; + +import org.openecomp.sdc.be.resources.data.ComponentCacheData; + +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; + +@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<ESArtifactData> getListOfResources(); + + // Result<ESArtifactData> getListOfResources(List<String> dids); +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDao.java new file mode 100644 index 0000000000..546dff855e --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCassandraDao.java @@ -0,0 +1,293 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.annotation.PostConstruct; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.BeEcompErrorManager; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.resources.data.ComponentCacheData; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import com.datastax.driver.core.Session; +import com.datastax.driver.mapping.MappingManager; +import com.datastax.driver.mapping.Result; + +import fj.data.Either; + +@Component("component-cassandra-dao") +public class ComponentCassandraDao extends CassandraDao { + + private static Logger logger = LoggerFactory.getLogger(ComponentCassandraDao.class.getName()); + + public static Integer DEFAULT_FETCH_SIZE = 500; + + private ComponentCacheAccessor componentCacheAccessor; + + public ComponentCassandraDao() { + super(); + + } + + @PostConstruct + public void init() { + String keyspace = AuditingTypesConstants.COMPONENT_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; + componentCacheAccessor = manager.createAccessor(ComponentCacheAccessor.class); + logger.info("** ComponentCassandraDao created"); + } else { + logger.info("** ComponentCassandraDao failed"); + throw new RuntimeException("Artifact keyspace [" + keyspace + "] failed to connect with error : " + + result.right().value()); + } + } else { + logger.info("** Cassandra client isn't connected"); + logger.info("** ComponentCassandraDao created, but not connected"); + } + } + + /** + * + * @param ids + * - list of components unique id + * @return + */ + public Either<List<ComponentCacheData>, ActionStatus> getComponents(List<String> ids) { + + List<ComponentCacheData> components = new ArrayList<ComponentCacheData>(); + if (ids == null || true == ids.isEmpty()) { + return Either.left(components); + } + + try { + + Result<ComponentCacheData> events = componentCacheAccessor.getComponents(ids); + if (events == null) { + logger.trace("not found component for ids list of in size {}", ids.size()); + return Either.left(components); + } + events.all().forEach(event -> { + components.add(event); + if (logger.isTraceEnabled()) { + logger.trace("Fetch component uid = {} isDirty = {}", event.getId(), event.getIsDirty()); + } + }); + + logger.debug("Number of components to fetch was {}. Actually, {} components fetched", ids.size(), + components.size()); + + return Either.left(components); + } catch (Exception e) { + BeEcompErrorManager.getInstance().logBeDaoSystemError("GetComponentsFromCache"); + + logger.debug("failed to get components from cache", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + public Either<List<ComponentCacheData>, ActionStatus> getAllComponentIdTimeAndType() { + try { + List<ComponentCacheData> components = new ArrayList<ComponentCacheData>(); + Result<ComponentCacheData> events = componentCacheAccessor.getAllComponentIdTimeAndType(); + if (events == null) { + logger.trace("no component found "); + return Either.left(components); + } + events.all().forEach(event -> { + components.add(event); + if (logger.isTraceEnabled()) { + logger.trace("Fetch component uid = {} isDirty = {}", event.getId(), event.getIsDirty()); + } + }); + + logger.debug("Number of components fetched was {}.", components.size()); + + return Either.left(components); + } catch (Exception e) { + BeEcompErrorManager.getInstance().logBeDaoSystemError("GetComponentsFromCache"); + + logger.debug("failed to get components from cache", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + /** + * + * @param id + * - component unique id + * @return + */ + public Either<ComponentCacheData, ActionStatus> getComponent(String id) { + + if (id == null) { + return Either.right(ActionStatus.INVALID_CONTENT); + } + + try { + + Result<ComponentCacheData> events = componentCacheAccessor.getComponent(id); + if (events == null) { + logger.trace("not found component for id {}", id); + return Either.right(ActionStatus.RESOURCE_NOT_FOUND); + } + + ComponentCacheData componentCacheData = events.one(); + if (componentCacheData != null) { + logger.debug("Component with id {} was found. isDirty={}.", componentCacheData.getId(), + componentCacheData.getIsDirty()); + } else { + return Either.right(ActionStatus.RESOURCE_NOT_FOUND); + } + return Either.left(componentCacheData); + + } catch (Exception e) { + BeEcompErrorManager.getInstance().logBeDaoSystemError("GetComponentFromCache"); + + logger.trace("Failed to get component from cache", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + public CassandraOperationStatus saveComponent(ComponentCacheData componentCacheData) { + return client.save(componentCacheData, ComponentCacheData.class, manager); + } + + /** + * ---------for use in JUnit only--------------- the method deletes all the + * tables in the audit keyspace + * + * @return the status of the last failed operation or ok if all the deletes + * were successful + */ + // public CassandraOperationStatus + // deleteAllPartialComponents(ComponentTypeEnum componentTypeEnum) { + // logger.info("cleaning all partial components of " + componentTypeEnum); + // + // String tableName = getTableName(componentTypeEnum); + // if (tableName == null) { + // BeEcompErrorManager.getInstance().logInvalidInputError("DeletePartialComponentData", + // "input type not found " + componentTypeEnum, ErrorSeverity.INFO); + // return CassandraOperationStatus.NOT_FOUND; + // } + // String query = "truncate " + AuditingTypesConstants.COMPONENT_KEYSPACE + + // "." + tableName; + // try { + // session.execute(query); + // } catch (Exception e) { + // logger.debug("Failed to clean partial components", e); + // return CassandraOperationStatus.GENERAL_ERROR; + // } + // logger.info("cleaning all partial components finished succsesfully."); + // return CassandraOperationStatus.OK; + // } + + /** + * the method checks if the given table is empty in the artifact keyspace + * + * @param tableName + * the name of the table we want to check + * @return true if the table is empty + */ + public Either<Boolean, CassandraOperationStatus> isTableEmpty(String tableName) { + return super.isTableEmpty(tableName); + } + + /** + * + * @param idToTimestampMap + * - list of components unique id + * @return + */ + public Either<ImmutablePair<List<ComponentCacheData>, Set<String>>, ActionStatus> getComponents( + Map<String, Long> idToTimestampMap) { + + List<ComponentCacheData> components = new ArrayList<ComponentCacheData>(); + Set<String> notFetchedFromCache = new HashSet<>(); + ImmutablePair<List<ComponentCacheData>, Set<String>> result = new ImmutablePair<List<ComponentCacheData>, Set<String>>( + components, notFetchedFromCache); + + if (idToTimestampMap == null || true == idToTimestampMap.isEmpty()) { + return Either.left(result); + } + + try { + + Set<String> keySet = idToTimestampMap.keySet(); + List<String> ids = new ArrayList<>(); + ids.addAll(keySet); + Result<ComponentCacheData> events = componentCacheAccessor.getComponents(ids); + if (events == null) { + logger.trace("not found component for ids list of in size {}", ids.size()); + notFetchedFromCache.addAll(idToTimestampMap.keySet()); + return Either.left(result); + } + events.all().forEach(event -> { + long timeFromCache = event.getModificationTime().getTime(); + long timeRequested = idToTimestampMap.get(event.getId()); + if (timeFromCache == timeRequested) { + logger.trace("Fetch component uid = {} from cache", event.getId()); + components.add(event); + } else { + logger.trace( + "Fetch and ignore component uid = {} from cache. Time requested is {} while timestamp in cache is {}", + event.getId(), timeRequested, timeFromCache); + } + }); + + logger.debug("Number of components to fetch was {}. Actually, {} components fetched", ids.size(), + components.size()); + List<String> foundComponents = components.stream().map(p -> p.getId()).collect(Collectors.toList()); + // fetch all ids which was not found in cache/found in cache and not + // updated. + Set<String> notFoundComponents = idToTimestampMap.keySet().stream() + .filter(p -> false == foundComponents.contains(p)).collect(Collectors.toSet()); + + notFetchedFromCache.addAll(notFoundComponents); + + return Either.left(result); + } catch (Exception e) { + BeEcompErrorManager.getInstance().logBeDaoSystemError("GetComponentsFromCache"); + + logger.debug("failed to get components from cache", e); + return Either.right(ActionStatus.GENERAL_ERROR); + } + } + + public CassandraOperationStatus deleteComponent(String id) { + return client.delete(id, ComponentCacheData.class, manager); + } + +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/ITableDescription.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/ITableDescription.java new file mode 100644 index 0000000000..010c3ee8fc --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/ITableDescription.java @@ -0,0 +1,46 @@ +/*- + * ============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; + +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; + +import com.datastax.driver.core.DataType; + +public interface ITableDescription { + + public static final String TIMESTAMP_FIELD = "timestamp1"; + public static final String TIMEBASED_UUID_FIELD = "timebaseduuid"; + public static final String ID_FIELD = "id"; + + public List<ImmutablePair<String, DataType>> primaryKeys(); + + public List<ImmutablePair<String, DataType>> clusteringKeys(); + + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription(); + + public String getKeyspace(); + + public String getTableName(); + +} 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 new file mode 100644 index 0000000000..0f54a25c14 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java @@ -0,0 +1,425 @@ +/*- + * ============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; + +import com.datastax.driver.core.*; +import com.datastax.driver.core.schemabuilder.Alter; +import com.datastax.driver.core.schemabuilder.Create; +import com.datastax.driver.core.schemabuilder.SchemaBuilder; +import com.datastax.driver.core.schemabuilder.SchemaStatement; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.*; +import org.openecomp.sdc.be.config.Configuration; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.net.ssl.SSLContext; +import java.security.NoSuchAlgorithmException; +import java.util.*; +import java.util.stream.Collectors; + +public class SdcSchemaBuilder { + + /** + * creat key space statment for SimpleStrategy + */ + final static String CREATE_KEYSPACE_SIMPLE_STRATEGY = "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'SimpleStrategy', %s};"; + /** + * creat key space statment for NetworkTopologyStrategy + */ + final static String CREATE_KEYSPACE_NETWORK_TOPOLOGY_STRATEGY = "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'NetworkTopologyStrategy', %s};"; + + private static Logger log = LoggerFactory.getLogger(SdcSchemaBuilder.class.getName()); + + /** + * 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 + * + * @return true if the create operation was successful + */ + public static boolean createSchema() { + Cluster cluster = null; + Session session = null; + try { + log.info("creating Schema for Cassandra."); + cluster = createCluster(); + if (cluster == null) { + return false; + } + session = cluster.connect(); + List<KeyspaceMetadata> keyspacesMetadateFromCassandra = cluster.getMetadata().getKeyspaces(); + if (keyspacesMetadateFromCassandra == null) { + log.debug("filed to retrive a list of keyspaces from cassndra"); + return false; + } + log.debug("retrived Cassndra metadata."); + Map<String, Map<String, List<String>>> cassndraMetadata = parseKeyspaceMetadata( + keyspacesMetadateFromCassandra); + Map<String, List<ITableDescription>> schemeData = getSchemeData(); + log.info("creating Keyspaces."); + for (String keyspace : schemeData.keySet()) { + if (!createKeyspace(keyspace, cassndraMetadata, session)) { + return false; + } + Map<String, List<String>> keyspaceMetadate = cassndraMetadata.get(keyspace); + createTables(schemeData.get(keyspace), keyspaceMetadate, session); + + } + return true; + } catch (Exception e) { + log.info("createSchema failed with exception.", e); + } finally { + if (session != null) { + session.close(); + } + if (cluster != null) { + cluster.close(); + } + + } + + return false; + } + + public static boolean deleteSchema() { + Cluster cluster = null; + Session session = null; + try { + log.info("delete Data from Cassandra."); + cluster = createCluster(); + if (cluster == null) { + return false; + } + session = cluster.connect(); + List<KeyspaceMetadata> keyspacesMetadateFromCassandra = cluster.getMetadata().getKeyspaces(); + if (keyspacesMetadateFromCassandra == null) { + log.debug("filed to retrive a list of keyspaces from cassndra"); + return false; + } + log.debug("retrived Cassndra metadata."); + Map<String, Map<String, List<String>>> cassndraMetadata = parseKeyspaceMetadata( + keyspacesMetadateFromCassandra); + cassndraMetadata.forEach((k, v) -> { + if (AuditingTypesConstants.TITAN_KEYSPACE.equals(k)) { + + // session.execute("") + } else if (AuditingTypesConstants.ARTIFACT_KEYSPACE.equals(k)) { + + } else if (AuditingTypesConstants.AUDIT_KEYSPACE.equals(k)) { + + } + }); + + System.out.println(cassndraMetadata); + return true; + } catch (Exception e) { + log.info("deleteSchema failed with exception.", e); + } finally { + if (session != null) { + session.close(); + } + if (cluster != null) { + cluster.close(); + } + + } + + return false; + } + + /** + * 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 + */ + private static Cluster createCluster() { + List<String> nodes = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() + .getCassandraHosts(); + if (nodes == null) { + log.info("no nodes were supplied in configuration."); + return null; + } + log.info("connecting to node:{}.", nodes); + Cluster.Builder clusterBuilder = Cluster.builder(); + nodes.forEach(host -> clusterBuilder.addContactPoint(host)); + + clusterBuilder.withMaxSchemaAgreementWaitSeconds(60); + + boolean authenticate = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() + .isAuthenticate(); + if (authenticate) { + String username = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() + .getUsername(); + String password = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig() + .getPassword(); + if (username == null || password == null) { + log.info("authentication is enabled but username or password were not supplied."); + return null; + } + clusterBuilder.withCredentials(username, password); + } + boolean ssl = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().isSsl(); + if (ssl) { + String truststorePath = ConfigurationManager.getConfigurationManager().getConfiguration() + .getCassandraConfig().getTruststorePath(); + String truststorePassword = ConfigurationManager.getConfigurationManager().getConfiguration() + .getCassandraConfig().getTruststorePassword(); + if (truststorePath == null || truststorePassword == null) { + log.info("ssl is enabled but truststorePath or truststorePassword were not supplied."); + return null; + } + System.setProperty("javax.net.ssl.trustStore", truststorePath); + System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword); + clusterBuilder.withSSL(); + } + return clusterBuilder.build(); + } + + /** + * the method prcess the metadata retrieved from the cassandra for the + * 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 + */ + private static Map<String, Map<String, List<String>>> parseKeyspaceMetadata( + List<KeyspaceMetadata> keyspacesMetadata) { + Map<String, Map<String, List<String>>> cassndraMetadata = keyspacesMetadata.stream() + .collect(Collectors.toMap(keyspaceMetadata -> keyspaceMetadata.getName(), + keyspaceMetadata -> keyspaceMetadata.getTables().stream() + .collect(Collectors.toMap(tableMetadata -> tableMetadata.getName(), + tableMetadata -> tableMetadata.getIndexes().stream() + .map(indexMetadata -> indexMetadata.getName()) + .collect(Collectors.toList()))))); + return cassndraMetadata; + } + + /** + * 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 + */ + private static String createIndexName(String table, String column) { + return new StringBuilder().append(table).append("_").append(column).append("_idx").toString(); + } + + /** + * the method creats all the tables and indexes thet do not already exist + * + * @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. + */ + private static void createTables(List<ITableDescription> iTableDescriptions, + Map<String, List<String>> keyspaceMetadate, Session session) { + + for (ITableDescription tableDescription : iTableDescriptions) { + String tableName = tableDescription.getTableName().toLowerCase(); + Map<String, ImmutablePair<DataType, Boolean>> columnDescription = tableDescription.getColumnDescription(); + log.info("creating tables:{}.", tableName); + if (keyspaceMetadate == null || !keyspaceMetadate.keySet().contains(tableName)) { + Create create = SchemaBuilder.createTable(tableDescription.getKeyspace(), + tableDescription.getTableName()); + for (ImmutablePair<String, DataType> key : tableDescription.primaryKeys()) { + create.addPartitionKey(key.getLeft(), key.getRight()); + } + if (tableDescription.clusteringKeys() != null) { + for (ImmutablePair<String, DataType> key : tableDescription.clusteringKeys()) { + create.addClusteringColumn(key.getLeft(), key.getRight()); + } + } + + for (String columnName : columnDescription.keySet()) { + create.addColumn(columnName, columnDescription.get(columnName).getLeft()); + } + log.trace("exacuting :{}", create.toString()); + ResultSet result = session.execute(create); + log.info("table:{} created succsesfully.", tableName); + } else { + log.info("table:{} already exists skiping.", tableName); + } + List<String> indexNames = (keyspaceMetadate != null ? keyspaceMetadate.get(tableName) : new ArrayList<>()); + log.info("table:{} creating indexes.", tableName); + for (String columnName : columnDescription.keySet()) { + String indexName = createIndexName(tableName, columnName).toLowerCase(); + if (columnDescription.get(columnName).getRight()) { + if (!indexNames.contains(indexName)) { + SchemaStatement creatIndex = SchemaBuilder.createIndex(indexName) + .onTable(tableDescription.getKeyspace(), tableName).andColumn(columnName); + log.info("executing :{}", creatIndex.toString()); + session.execute(creatIndex); + log.info("index:{} created succsesfully.", indexName); + } else { + log.info("index:{} already exists skiping.", indexName); + } + } + } + + } + } + + /** + * 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. + * @return true in case the operation was successful + */ + private static boolean createKeyspace(String keyspace, Map<String, Map<String, List<String>>> cassndraMetadata, + Session session) { + List<Configuration.CassandrConfig.KeyspaceConfig> keyspaceConfigList = ConfigurationManager + .getConfigurationManager().getConfiguration().getCassandraConfig().getKeySpaces(); + log.info("creating keyspace:{}.", keyspace); + if (!cassndraMetadata.keySet().contains(keyspace)) { + Optional<Configuration.CassandrConfig.KeyspaceConfig> keyspaceConfig = keyspaceConfigList.stream() + .filter(keyspaceInfo -> keyspace.equalsIgnoreCase(keyspaceInfo.getName())).findFirst(); + if (keyspaceConfig.isPresent()) { + Configuration.CassandrConfig.KeyspaceConfig keyspaceInfo = keyspaceConfig.get(); + String createKeyspaceQuery = createKeyspaceQuereyString(keyspace, keyspaceInfo); + if (createKeyspaceQuery != null) { + log.trace("exacuting: {}", createKeyspaceQuery); + session.execute(createKeyspaceQuery); + log.info("keyspace:{} created.", keyspace); + return true; + } else { + return false; + } + } else { + log.info( + "keyspace:{} not present in configuration, no info on replications is available. operation failed.", + keyspace); + return false; + } + } else { + log.info("keyspace:{} already exists skipping.", keyspace); + return true; + } + } + + /** + * 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() { + Map<String, List<ITableDescription>> tablesByKeyspace = new HashMap<String, List<ITableDescription>>(); + Table[] tables = Table.values(); + for (Table table : tables) { + String keyspace = table.getTableDescription().getKeyspace().toLowerCase(); + List<ITableDescription> list = tablesByKeyspace.get(keyspace); + if (list == null) { + list = new ArrayList<>(); + } + list.add(table.getTableDescription()); + tablesByKeyspace.put(keyspace, list); + } + return tablesByKeyspace; + } + + /** + * 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 + * configuration info regurding the replication of the keyspace + * @return a querey string for the creation of the keyspace + */ + private static String createKeyspaceQuereyString(String keyspace, + Configuration.CassandrConfig.KeyspaceConfig keyspaceInfo) { + String query = null; + if (ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY.getName() + .equalsIgnoreCase(keyspaceInfo.getReplicationStrategy())) { + List<String> dcList = keyspaceInfo.getReplicationInfo(); + if (dcList.size() % 2 != 0) { + log.error("the supplied replication info is in valid expected dc1,2,dc2,2 etc received:{}", dcList); + return query; + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < dcList.size(); i = i + 2) { + sb.append("'").append(dcList.get(i)).append("'").append(" : ").append(dcList.get(i + 1)); + if (i + 2 < dcList.size()) { + sb.append(","); + } + } + + query = String.format(CREATE_KEYSPACE_NETWORK_TOPOLOGY_STRATEGY, keyspace, sb.toString()); + } else if (ReplicationStrategy.SIMPLE_STRATEGY.getName() + .equalsIgnoreCase(keyspaceInfo.getReplicationStrategy())) { + List<String> dcList = keyspaceInfo.getReplicationInfo(); + if (dcList.size() != 1) { + log.error("the supplied replication info is in valid expected <number> etc received:{}", dcList); + return query; + } + StringBuilder sb = new StringBuilder(); + sb.append("'replication_factor'").append(" : ").append(dcList.get(0)); + query = String.format(CREATE_KEYSPACE_SIMPLE_STRATEGY, keyspace, sb.toString()); + + } else { + log.error("the suplied replication Strategy is in valide expacted {}/{} etc recived:{}", + ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY.getName(), + ReplicationStrategy.SIMPLE_STRATEGY.getName(), keyspaceInfo.getReplicationStrategy()); + } + return query; + } + + public enum ReplicationStrategy { + NETWORK_TOPOLOGY_STRATEGY("NetworkTopologyStrategy"), SIMPLE_STRATEGY("SimpleStrategy"); + + public String name; + + private ReplicationStrategy(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + +} 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 new file mode 100644 index 0000000000..6de40a7117 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java @@ -0,0 +1,71 @@ +/*- + * ============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; + +import org.openecomp.sdc.be.dao.cassandra.schema.tables.ArtifactTableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.AuthEventTableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.CategoryEventTableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.ComponentCacheTableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.ConsumerEventTableDefinition; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.DistribDeployEventTableDesc; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.DistribDownloadEventTableDesc; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.DistribEngineEventTableDesc; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.DistribNotifEventTableDesc; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.DistribStatusEventTableDesc; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.ExternalApiEventTableDesc; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.GetCatHierEventTableDesc; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.GetUebClusterEventTableDesc; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.GetUsersListEventTableDesc; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.ResAdminEventTableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.UserAccessEventTableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.UserAdminEventTableDescription; + +public enum Table { + + ARTIFACT(new ArtifactTableDescription()), + USER_ADMIN_EVENT(new UserAdminEventTableDescription()), + USER_ACCESS_EVENT(new UserAccessEventTableDescription()), + RESOURCE_ADMIN_EVENT(new ResAdminEventTableDescription()), + DISTRIBUTION_DOWNLOAD_EVENT(new DistribDownloadEventTableDesc()), + DISTRIBUTION_ENGINE_EVENT(new DistribEngineEventTableDesc()), + DISTRIBUTION_NOTIFICATION_EVENT(new DistribNotifEventTableDesc()), + DISTRIBUTION_STATUS_EVENT(new DistribStatusEventTableDesc()), + 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()), + EXTERNAL_API_EVENT(new ExternalApiEventTableDesc()), + COMPONENT_CACHE(new ComponentCacheTableDescription()); + + ITableDescription tableDescription; + + Table(ITableDescription tableDescription) { + this.tableDescription = tableDescription; + } + + public ITableDescription getTableDescription() { + return tableDescription; + } + +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ArtifactTableDescription.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ArtifactTableDescription.java new file mode 100644 index 0000000000..2e26bd2675 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ArtifactTableDescription.java @@ -0,0 +1,95 @@ +/*- + * ============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 java.util.*; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.Configuration; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; + +public class ArtifactTableDescription implements ITableDescription { + + private static final String keyspaceType = "artifact"; + + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(ID_FIELD, DataType.varchar())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (ArtifactFieldsDescription field : ArtifactFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.ARTIFACT_KEYSPACE; + } + + @Override + public String getTableName() { + return "resources"; + } + + enum ArtifactFieldsDescription { + DATA("data", DataType.blob(), false); + + private String name; + private DataType type; + private boolean indexed; + + ArtifactFieldsDescription(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; + } + } + + @Override + public List<ImmutablePair<String, DataType>> clusteringKeys() { + return null; + } +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/AuthEventTableDescription.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/AuthEventTableDescription.java new file mode 100644 index 0000000000..ef7be5deb7 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/AuthEventTableDescription.java @@ -0,0 +1,103 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.UserAdminEventTableDescription.UAEFieldsDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; +import com.datastax.driver.mapping.annotations.Column; + +public class AuthEventTableDescription implements ITableDescription { + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(TIMESTAMP_FIELD, DataType.timestamp())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (AEFieldsDescription field : AEFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.AUTH_EVENT_TYPE; + } + + enum AEFieldsDescription { + + URL("url", DataType.varchar(), false), REQUEST_ID("request_id", DataType.varchar(), true), USER("user", + DataType.varchar(), false), AUTH_STATUS("auth_status", DataType.varchar(), false), REALM("realm", + DataType.varchar(), false), ACTION("action", DataType.varchar(), true), STATUS("status", + DataType.varchar(), false), DESC("description", DataType.varchar(), false); + + private String name; + private DataType type; + private boolean indexed; + + AEFieldsDescription(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/CategoryEventTableDescription.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/CategoryEventTableDescription.java new file mode 100644 index 0000000000..efefac57b6 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/CategoryEventTableDescription.java @@ -0,0 +1,105 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; +import com.datastax.driver.mapping.annotations.Column; + +public class CategoryEventTableDescription implements ITableDescription { + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(TIMESTAMP_FIELD, DataType.timestamp())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (CEFieldsDescription field : CEFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.CATEGORY_EVENT_TYPE; + } + + enum CEFieldsDescription { + + ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), false), DESC("description", + DataType.varchar(), false), CATEGORY_NAME("category_Name", DataType.varchar(), + false), SUB_CATEGORY_NAME("sub_Category_Name", DataType.varchar(), false), GROUPING_NAME( + "grouping_name", DataType.varchar(), false), MODIFIER("modifier", DataType.varchar(), + false), REQUEST_ID("request_id", DataType.varchar(), false), RESOURCE_TYPE( + "resource_type", DataType.varchar(), false), SERVICE_INSTANCE_ID( + "service_instance_id", DataType.varchar(), false); + + private String name; + private DataType type; + private boolean indexed; + + CEFieldsDescription(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/ComponentCacheTableDescription.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ComponentCacheTableDescription.java new file mode 100644 index 0000000000..6396da5c32 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ComponentCacheTableDescription.java @@ -0,0 +1,95 @@ +/*- + * ============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 java.util.*; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.Configuration; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; + +public class ComponentCacheTableDescription implements ITableDescription { + + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(ID_FIELD, DataType.varchar())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (PartialComponentFieldsDescription field : PartialComponentFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.COMPONENT_KEYSPACE; + } + + @Override + public String getTableName() { + return "componentcache"; + } + + enum PartialComponentFieldsDescription { + DATA("data", DataType.blob(), false), MODIFICATION_TIME("modification_time", DataType.timestamp(), false), TYPE( + "type", DataType.varchar(), false), IS_DIRTY("is_dirty", DataType.cboolean(), + false), IS_ZIPPED("is_zipped", DataType.cboolean(), false),; + + private String name; + private DataType type; + private boolean indexed; + + PartialComponentFieldsDescription(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; + } + } + + @Override + public List<ImmutablePair<String, DataType>> clusteringKeys() { + return null; + } +} 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 new file mode 100644 index 0000000000..554a7a7a51 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ConsumerEventTableDefinition.java @@ -0,0 +1,101 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.GetUebClusterEventTableDesc.DEEFieldsDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; + +public class ConsumerEventTableDefinition implements ITableDescription { + + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(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<DataType, Boolean>(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/DistribDeployEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribDeployEventTableDesc.java new file mode 100644 index 0000000000..5fc1dc8bd4 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribDeployEventTableDesc.java @@ -0,0 +1,104 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.DistribDownloadEventTableDesc.DSEFieldsDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; + +public class DistribDeployEventTableDesc implements ITableDescription { + + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(TIMESTAMP_FIELD, DataType.timestamp())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (DSEFieldsDescription field : DSEFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.DISTRIBUTION_DEPLOY_EVENT_TYPE; + } + + enum DSEFieldsDescription { + ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), true), DESCRIPTION( + "description", DataType.varchar(), false), REQUEST_ID("request_id", DataType.varchar(), + false), SERVICE_INST_ID("service_instance_id", DataType.varchar(), true), MODIFIER("modifier", + DataType.varchar(), false), CURR_VERSION("curr_version", DataType.varchar(), + false), DID("did", DataType.varchar(), true), RESOURCE_NAME("resource_name", + DataType.varchar(), + false), RESOURCE_TYPE("resource_type", DataType.varchar(), false); + + private String name; + private DataType type; + private boolean indexed; + + DSEFieldsDescription(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/DistribDownloadEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribDownloadEventTableDesc.java new file mode 100644 index 0000000000..0ed4f55a7b --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribDownloadEventTableDesc.java @@ -0,0 +1,100 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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 com.datastax.driver.core.DataType; + +public class DistribDownloadEventTableDesc implements ITableDescription { + + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(TIMESTAMP_FIELD, DataType.timestamp())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (DSEFieldsDescription field : DSEFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.DISTRIBUTION_DOWNLOAD_EVENT_TYPE; + } + + enum DSEFieldsDescription { + REQUEST_ID("request_Id", DataType.varchar(), false), SERVICE_INST_ID("service_Instance_Id", DataType.varchar(), + false), ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), + false), DESCRIPTION("description", DataType.varchar(), false), CONSUMER_ID("consumer_Id", + DataType.varchar(), false), RESOURCE_URL("resource_URL", DataType.varchar(), false); + + private String name; + private DataType type; + private boolean indexed; + + DSEFieldsDescription(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/DistribEngineEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribEngineEventTableDesc.java new file mode 100644 index 0000000000..5ce5bffb7c --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribEngineEventTableDesc.java @@ -0,0 +1,103 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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 com.datastax.driver.core.DataType; + +public class DistribEngineEventTableDesc implements ITableDescription { + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(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<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.DISTRIBUTION_ENGINE_EVENT_TYPE; + } + + enum DEEFieldsDescription { + ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), false), DESCRIPTION( + "description", DataType.varchar(), + false), CONSUMER_ID("consumer_id", DataType.varchar(), false), REQUEST_ID("request_id", + DataType.varchar(), true), SERVICE_INST_ID("service_instance_id", DataType.varchar(), + false), ROLE("role", DataType.varchar(), false), D_ENV("d_env", DataType.varchar(), + false), API_KEY("api_key", DataType.varchar(), false), DSTATUS_TOPIC( + "dstatus_topic", DataType.varchar(), + false), DNOTIF_TOPIC("dnotif_topic", 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/DistribNotifEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribNotifEventTableDesc.java new file mode 100644 index 0000000000..96fab66701 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribNotifEventTableDesc.java @@ -0,0 +1,104 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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 com.datastax.driver.core.DataType; + +public class DistribNotifEventTableDesc implements ITableDescription { + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(TIMESTAMP_FIELD, DataType.timestamp())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (DNEFieldsDescription field : DNEFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.DISTRIBUTION_NOTIFICATION_EVENT_TYPE; + } + + enum DNEFieldsDescription { + ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), false), DESCRIPTION( + "description", DataType.varchar(), + false), REQUEST_ID("request_id", DataType.varchar(), false), SERVICE_INST_ID("service_instance_id", + DataType.varchar(), true), TOPIC_NAME("topic_name", DataType.varchar(), false), MODIFIER( + "modifier", DataType.varchar(), false), CURR_STATE("curr_state", DataType.varchar(), + false), CURR_VERSION("curr_version", DataType.varchar(), false), DID("did", + DataType.varchar(), true), RESOURCE_NAME("resource_name", + DataType.varchar(), false), RESOURCE_TYPE("resource_type", + DataType.varchar(), false); + + private String name; + private DataType type; + private boolean indexed; + + DNEFieldsDescription(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/DistribStatusEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribStatusEventTableDesc.java new file mode 100644 index 0000000000..bc564e3743 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribStatusEventTableDesc.java @@ -0,0 +1,102 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; + +public class DistribStatusEventTableDesc implements ITableDescription { + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(TIMESTAMP_FIELD, DataType.timestamp())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (DSEFieldsDescription field : DSEFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.DISTRIBUTION_STATUS_EVENT_TYPE; + } + + enum DSEFieldsDescription { + ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), false), DESCRIPTION( + "description", DataType.varchar(), + false), DID("did", DataType.varchar(), true), CONSUMER_ID("consumer_id", DataType.varchar(), + false), REQUEST_ID("request_id", DataType.varchar(), false), RESOURCE_URL("resoure_URL", + DataType.varchar(), false), SERVICE_INST_ID("service_instance_id", DataType.varchar(), + false), TOPIC_NAME("topic_name", DataType.varchar(), + false), STATUS_TIME("status_time", DataType.varchar(), false); + + private String name; + private DataType type; + private boolean indexed; + + DSEFieldsDescription(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/ExternalApiEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ExternalApiEventTableDesc.java new file mode 100644 index 0000000000..a67c9ef4ef --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ExternalApiEventTableDesc.java @@ -0,0 +1,104 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +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 com.datastax.driver.core.DataType; + +public class ExternalApiEventTableDesc implements ITableDescription { + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(TIMESTAMP_FIELD, DataType.timestamp())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (EGAEFieldsDescription field : EGAEFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.EXTERNAL_API_EVENT_TYPE; + } + + enum EGAEFieldsDescription { + ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), false), DESCRIPTION( + "description", DataType.varchar(), false), CONSUMER_ID("consumer_id", DataType.varchar(), + false), RESOURCE_URL("resource_URL", DataType.varchar(), false), RESOURCE_NAME("resource_name", + DataType.varchar(), + false), RESOURCE_TYPE("resource_type", DataType.varchar(), false), SERVICE_INST_ID( + "service_instance_id", DataType.varchar(), + true), MODIFIER("modifier", DataType.varchar(), false), PREV_ARTIFACT_UUID( + "prev_artifact_uuid", DataType.varchar(), false), CURR_ARTIFACT_UUID( + "curr_artifact_uuid", DataType.varchar(), false), ARTIFACT_DATA( + "artifact_data", DataType.varchar(), false); + + private String name; + private DataType type; + private boolean indexed; + + EGAEFieldsDescription(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/GetCatHierEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/GetCatHierEventTableDesc.java new file mode 100644 index 0000000000..2d1a5c3c75 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/GetCatHierEventTableDesc.java @@ -0,0 +1,99 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.GetUsersListEventTableDesc.DEEFieldsDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; + +public class GetCatHierEventTableDesc implements ITableDescription { + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(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<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.GET_CATEGORY_HIERARCHY_EVENT_TYPE; + } + + enum DEEFieldsDescription { + ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), false), DESCRIPTION( + "description", DataType.varchar(), false), DETAILS("details", DataType.varchar(), false), REQUEST_ID( + "request_id", DataType.varchar(), false), MODIFIER("modifier", 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/GetUebClusterEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/GetUebClusterEventTableDesc.java new file mode 100644 index 0000000000..8ef1f01186 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/GetUebClusterEventTableDesc.java @@ -0,0 +1,101 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.DistribEngineEventTableDesc.DEEFieldsDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; + +public class GetUebClusterEventTableDesc implements ITableDescription { + + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(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<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.DISTRIBUTION_GET_UEB_CLUSTER_EVENT_TYPE; + } + + enum DEEFieldsDescription { + ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), false), DESCRIPTION( + "description", DataType.varchar(), + false), CONSUMER_ID("consumer_Id", DataType.varchar(), false), REQUEST_ID("request_Id", + DataType.varchar(), false), SERVICE_INST_ID("service_Instance_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/GetUsersListEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/GetUsersListEventTableDesc.java new file mode 100644 index 0000000000..5d94bd3f4d --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/GetUsersListEventTableDesc.java @@ -0,0 +1,99 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.dao.cassandra.schema.tables.GetUebClusterEventTableDesc.DEEFieldsDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; + +public class GetUsersListEventTableDesc implements ITableDescription { + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(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<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.GET_USERS_LIST_EVENT_TYPE; + } + + enum DEEFieldsDescription { + ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), false), DESCRIPTION( + "description", DataType.varchar(), false), DETAILS("details", DataType.varchar(), false), REQUEST_ID( + "request_id", DataType.varchar(), false), MODIFIER("modifier", 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/ResAdminEventTableDescription.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ResAdminEventTableDescription.java new file mode 100644 index 0000000000..a6f0ba905d --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ResAdminEventTableDescription.java @@ -0,0 +1,132 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; +import com.datastax.driver.mapping.annotations.Column; + +public class ResAdminEventTableDescription implements ITableDescription { + + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(TIMESTAMP_FIELD, DataType.timestamp())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (AEFieldsDescription field : AEFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.RESOURCE_ADMIN_EVENT_TYPE; + } + + enum AEFieldsDescription { + REQUEST_ID("request_id", DataType.varchar(), false), SERVICE_INST_ID("service_instance_id", DataType.varchar(), + true), INVARIANT_UUID("invariant_UUID", DataType.varchar(), true), ACTION("action", DataType.varchar(), + true), STATUS("status", DataType.varchar(), false), DESCRIPTION("description", + DataType.varchar(), + false), RESOURCE_TYPE("resource_type", DataType.varchar(), false), PREV_VERSION( + "prev_version", DataType.varchar(), + true), PREV_STATE("prev_state", DataType.varchar(), true), CURR_STATE( + "curr_state", DataType.varchar(), false), RESOURCE_NAME("resource_name", + DataType.varchar(), false), CURR_VERSION("curr_version", + DataType.varchar(), true), MODIFIER("modifier", + DataType.varchar(), + false), PREV_ARTIFACT_UUID("prev_artifact_UUID", + DataType.varchar(), + false), CURR__ARTIFACT_UUID( + "curr_artifact_UUID", + DataType.varchar(), + false), ARTIFACT_DATA( + "artifact_data", + DataType.varchar(), + false), DID("did", + DataType.varchar(), + true), DPREV_STATUS( + "dprev_status", + DataType.varchar(), + false), DCURR_STATUS( + "dcurr_status", + DataType.varchar(), + false), TOSCA_NODE_TYPE( + "tosca_node_type", + DataType.varchar(), + false), COMMENT( + "comment", + DataType.varchar(), + false); + + private String name; + private DataType type; + private boolean indexed; + + AEFieldsDescription(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/UserAccessEventTableDescription.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/UserAccessEventTableDescription.java new file mode 100644 index 0000000000..7f482ae3ac --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/UserAccessEventTableDescription.java @@ -0,0 +1,104 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; +import com.datastax.driver.mapping.annotations.Column; + +public class UserAccessEventTableDescription implements ITableDescription { + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(TIMESTAMP_FIELD, DataType.timestamp())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (UAEFieldsDescription field : UAEFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.USER_ACCESS_EVENT_TYPE; + } + + enum UAEFieldsDescription { + REQUEST_ID("request_Id", DataType.varchar(), false), USER("USER", DataType.varchar(), false), ACTION("action", + DataType.varchar(), true), STATUS("status", DataType.varchar(), false), DESCRIPTION("description", + DataType.varchar(), + false), SERVICE_INSTANCE_ID("service_instance_id", DataType.varchar(), false); + + @Column + private String modifier; + + private String name; + private DataType type; + private boolean indexed; + + UAEFieldsDescription(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/UserAdminEventTableDescription.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/UserAdminEventTableDescription.java new file mode 100644 index 0000000000..dd8df08cdd --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/UserAdminEventTableDescription.java @@ -0,0 +1,102 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; + +import com.datastax.driver.core.DataType; + +public class UserAdminEventTableDescription implements ITableDescription { + + @Override + public List<ImmutablePair<String, DataType>> primaryKeys() { + List<ImmutablePair<String, DataType>> keys = new ArrayList<>(); + keys.add(new ImmutablePair<String, DataType>(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<String, DataType>(TIMESTAMP_FIELD, DataType.timestamp())); + return keys; + } + + @Override + public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() { + Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>(); + + for (UAEFieldsDescription field : UAEFieldsDescription.values()) { + columns.put(field.getName(), new ImmutablePair<DataType, Boolean>(field.type, field.indexed)); + } + + return columns; + } + + @Override + public String getKeyspace() { + return AuditingTypesConstants.AUDIT_KEYSPACE; + } + + @Override + public String getTableName() { + return AuditingTypesConstants.USER_ADMIN_EVENT_TYPE; + } + + enum UAEFieldsDescription { + REQUEST_ID("request_id", DataType.varchar(), false), SERVICE_INST_ID("service_instance_id", DataType.varchar(), + false), ACTION("action", DataType.varchar(), true), STATUS("status", DataType.varchar(), + false), DESCRIPTION("description", DataType.varchar(), false), MODIFIER("modifier", + DataType.varchar(), false), USER_BEFORE("user_before", DataType.varchar(), + false), USER_AFTER("user_after", DataType.varchar(), false); + + private String name; + private DataType type; + private boolean indexed; + + UAEFieldsDescription(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; + } + } + +} |