885a7a7ce3d6e319f4ce25da417d4e49ac17170c
[sdc.git] /
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         DESCRIPTION("description", DataType.varchar(), false),
58         EXECUTION_TIME("execution_time", DataType.cdouble(), false);
59
60         private String fieldName;
61         private boolean isIndexed;
62         private DataType fieldType;
63
64         SdcRepoFieldsDescription(String fieldName, DataType dataType, boolean indexed ) {
65             this.fieldName = fieldName;
66             this.fieldType = dataType;
67             this.isIndexed = indexed;
68         }
69
70         public String getFieldName() {
71             return fieldName;
72         }
73
74         public boolean isIndexed() {
75             return isIndexed;
76         }
77
78         public DataType getFieldType() {
79             return fieldType;
80         }
81     }
82 }