2e8c5ff024af1da175bb941f598632f9b52faf09
[sdc.git] /
1 package org.openecomp.sdc.be.dao.cassandra.schema.tables;
2
3 import static org.openecomp.sdc.be.dao.cassandra.schema.tables.MigrationTasksTableDescription.SdcRepoFieldsDescription.MAJOR_VERSION;
4 import static org.openecomp.sdc.be.dao.cassandra.schema.tables.MigrationTasksTableDescription.SdcRepoFieldsDescription.MINOR_VERSION;
5
6 import java.util.Arrays;
7 import java.util.Collections;
8 import java.util.HashMap;
9 import java.util.List;
10 import java.util.Map;
11
12 import org.apache.commons.lang3.tuple.ImmutablePair;
13 import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription;
14 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
15
16 import com.datastax.driver.core.DataType;
17
18 public class MigrationTasksTableDescription implements ITableDescription {
19
20     private static final String MIGRATION_TASKS_TABLE = "migrationTasks";
21
22     @Override
23     public List<ImmutablePair<String, DataType>> primaryKeys() {
24         return Collections.singletonList(ImmutablePair.of(MAJOR_VERSION.getFieldName(), MAJOR_VERSION.getFieldType()));
25     }
26
27     @Override
28     public List<ImmutablePair<String, DataType>> clusteringKeys() {
29         return Collections.singletonList(ImmutablePair.of(MINOR_VERSION.getFieldName(), MINOR_VERSION.getFieldType()));
30     }
31
32     @Override
33     public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() {
34         Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>();
35         Arrays.stream(SdcRepoFieldsDescription.values())
36                 .filter(column -> !column.equals(MAJOR_VERSION) && !column.equals(MINOR_VERSION))
37                 .forEach(column -> columns.put(column.getFieldName(), ImmutablePair.of(column.getFieldType(), column.isIndexed())));
38         return columns;
39     }
40
41     @Override
42     public String getKeyspace() {
43         return AuditingTypesConstants.REPO_KEYSPACE;
44     }
45
46     @Override
47     public String getTableName() {
48         return MIGRATION_TASKS_TABLE;
49     }
50
51     enum SdcRepoFieldsDescription {
52         MAJOR_VERSION("major_version", DataType.bigint(), true),
53         MINOR_VERSION("minor_version", DataType.bigint(), false),
54         TIMESTAMP("timestamp", DataType.timestamp(), false),
55         NAME("task_name", DataType.varchar(), false),
56         STATUS("task_status", DataType.varchar(), false),
57         MESSAGE("msg", DataType.varchar(), false),
58         DESCRIPTION("description", DataType.varchar(), false),
59         EXECUTION_TIME("execution_time", DataType.cdouble(), false);
60
61         private String fieldName;
62         private boolean isIndexed;
63         private DataType fieldType;
64
65         SdcRepoFieldsDescription(String fieldName, DataType dataType, boolean indexed ) {
66             this.fieldName = fieldName;
67             this.fieldType = dataType;
68             this.isIndexed = indexed;
69         }
70
71         public String getFieldName() {
72             return fieldName;
73         }
74
75         public boolean isIndexed() {
76             return isIndexed;
77         }
78
79         public DataType getFieldType() {
80             return fieldType;
81         }
82     }
83 }