54656cbe19a7e5a7e642d7566ff1db0e623894c9
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.dao.cassandra.schema.tables;
22
23 import com.datastax.driver.core.DataType;
24 import lombok.AllArgsConstructor;
25 import lombok.Getter;
26 import org.apache.commons.lang3.tuple.ImmutablePair;
27 import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription;
28 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
29
30 import java.util.*;
31
32 import static org.openecomp.sdc.be.dao.cassandra.schema.tables.MigrationTasksTableDescription.SdcRepoFieldsDescription.MAJOR_VERSION;
33 import static org.openecomp.sdc.be.dao.cassandra.schema.tables.MigrationTasksTableDescription.SdcRepoFieldsDescription.MINOR_VERSION;
34
35 public class MigrationTasksTableDescription implements ITableDescription {
36
37     private static final String MIGRATION_TASKS_TABLE = "migrationTasks";
38
39     @Override
40     public List<ImmutablePair<String, DataType>> primaryKeys() {
41         return Collections.singletonList(ImmutablePair.of(MAJOR_VERSION.getFieldName(), MAJOR_VERSION.getFieldType()));
42     }
43
44     @Override
45     public List<ImmutablePair<String, DataType>> clusteringKeys() {
46         return Collections.singletonList(ImmutablePair.of(MINOR_VERSION.getFieldName(), MINOR_VERSION.getFieldType()));
47     }
48
49     @Override
50     public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() {
51         Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>();
52         Arrays.stream(SdcRepoFieldsDescription.values())
53                 .filter(column -> !column.equals(MAJOR_VERSION) && !column.equals(MINOR_VERSION))
54                 .forEach(column -> columns.put(column.getFieldName(), ImmutablePair.of(column.getFieldType(), column.isIndexed())));
55         return columns;
56     }
57
58     @Override
59     public String getKeyspace() {
60         return AuditingTypesConstants.REPO_KEYSPACE;
61     }
62
63     @Override
64     public String getTableName() {
65         return MIGRATION_TASKS_TABLE;
66     }
67
68     @Getter
69     @AllArgsConstructor
70     enum SdcRepoFieldsDescription {
71         MAJOR_VERSION("major_version", DataType.bigint(), true),
72         MINOR_VERSION("minor_version", DataType.bigint(), false),
73         TIMESTAMP("timestamp", DataType.timestamp(), false),
74         NAME("task_name", DataType.varchar(), false),
75         STATUS("task_status", DataType.varchar(), false),
76         MESSAGE("msg", DataType.varchar(), false),
77         DESCRIPTION("description", DataType.varchar(), false),
78         EXECUTION_TIME("execution_time", DataType.cdouble(), false);
79
80         private final String fieldName;
81         private final DataType fieldType;
82         private final boolean isIndexed;
83
84     }
85 }