aboutsummaryrefslogtreecommitdiffstats
path: root/mdbc-server/src/main/java/org/onap/music/mdbc/tools/TxDigestDecompression.java
blob: 6b7b7bed3129290599e5f83c089b6480939087b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * ============LICENSE_START====================================================
 * org.onap.music.mdbc
 * =============================================================================
 * Copyright (C) 2019 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.onap.music.mdbc.tools;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
import org.onap.music.exceptions.MDBCServiceException;
import org.onap.music.logging.EELFLoggerDelegate;
import org.onap.music.mdbc.mixins.MusicInterface;
import org.onap.music.mdbc.mixins.MusicMixin;
import org.onap.music.mdbc.mixins.MySQLMixin;
import org.onap.music.mdbc.tables.MusicRangeInformationRow;
import org.onap.music.mdbc.tables.MusicTxDigestId;
import org.onap.music.mdbc.tables.Operation;
import org.onap.music.mdbc.tables.StagingTable;

/**
 * This function outputs the tx digest, decompressing the information and making it human readable.
 * It is intended to help debug and allow users to see what is happening inside the tx digest.
 *
 */

public class TxDigestDecompression {
    public static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(TxDigestDecompression.class);
    MusicMixin mi;
    MySQLMixin ms;
    
    public TxDigestDecompression(MusicInterface _mi) {
        mi = (MusicMixin) _mi;
        ms = new MySQLMixin();
    }
    
    public TxDigestDecompression() {
        Properties prop = new Properties();
        try {
            prop.load(this.getClass().getClassLoader().getResourceAsStream("music.properties"));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        try {
            mi = new MusicMixin(null, "mdbcservername", prop);
            ms = new MySQLMixin();
        } catch (MDBCServiceException e) {
            e.printStackTrace();
            return;
        }
    }
    
    public void decodeTxDigest() {
        // Print out the tx digest
        try {
            List<MusicRangeInformationRow> rows = mi.getAllMriRows();
            for (MusicRangeInformationRow row: rows) {
                UUID mriId = row.getPartitionIndex();
                extractedRedoLog(row);
            }
        } catch (MDBCServiceException e) {
            e.printStackTrace();
            return;
        }
        System.exit(0);
    }

    public void extractedRedoLog(MusicRangeInformationRow row) throws MDBCServiceException {
        for (MusicTxDigestId id: row.getRedoLog()) {
            StagingTable st = mi.getTxDigest(id);
            System.out.print(id.transactionId + ": [");
            String sep = ", ";
            for (Operation op: st.getOperationList()) {
                
                ArrayList<String> cols = new ArrayList<String>();
                ArrayList<Object> vals = new ArrayList<Object>();
                ms.constructColValues(op.getVal(), cols, vals);
                StringBuilder sql = ms.constructSQL(op, cols, vals);
                
                System.out.print(sql + sep);
                
            }
            System.out.println("]");
        }
    }
    
    public static void main(String[] args) {
        TxDigestDecompression txDecompress = new TxDigestDecompression();
        txDecompress.decodeTxDigest();
    }
}