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