2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright (C) 2018 IBM.
8 * ===========================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END====================================================
24 package org.onap.aaf.auth.batch.helpers;
26 import java.nio.ByteBuffer;
27 import java.util.Iterator;
28 import java.util.UUID;
30 import org.onap.aaf.misc.env.Env;
31 import org.onap.aaf.misc.env.TimeTaken;
32 import org.onap.aaf.misc.env.Trans;
34 import com.datastax.driver.core.ResultSet;
35 import com.datastax.driver.core.Row;
36 import com.datastax.driver.core.Session;
37 import com.datastax.driver.core.SimpleStatement;
38 import com.datastax.driver.core.Statement;
40 public class History {
42 public final String action;
43 public final String memo;
44 public final String reconstruct;
45 public final String subject;
46 public final String target;
47 public final String user;
48 public final int yrMon;
50 public static Creator<History> sansConstruct = new Creator<History> () {
52 public History create(Row row) {
64 public String select() {
65 return "SELECT id, action, memo, subject, target, user, yr_mon from authz.history LIMIT 10000000 ";
69 public static Creator<History> avecConstruct = new Creator<History> () {
70 private final StringBuilder sb = new StringBuilder();
73 public History create(Row row) {
74 ByteBuffer bb = row.getBytes(3);
77 if (bb!=null && bb.hasRemaining()) {
79 while (bb.hasRemaining()) {
80 sb.append(String.format("%02x",bb.get()));
96 public String select() {
97 return "SELECT id, action, memo, reconstruct, subject, target, user, yr_mon from authz.history LIMIT 10000000 ";
101 public History(UUID id, String action, String memo, String subject, String target, String user, int yrMon) {
103 this.action = action;
105 this.reconstruct = null;
106 this.subject = subject;
107 this.target = target;
112 public History(UUID id, String action, String memo, String reconstruct, String subject, String target, String user, int yrMon) {
114 this.action = action;
116 this.reconstruct = reconstruct;
117 this.subject = subject;
118 this.target = target;
123 public static void load(Trans trans, Session session, Creator<History> creator, Loader<History> loader) {
124 trans.info().log( "query: " + creator.select() );
125 TimeTaken tt = trans.start("Read History", Env.REMOTE);
129 Statement stmt = new SimpleStatement( creator.select() ).setReadTimeoutMillis(240000);
130 results = session.execute(stmt);
136 Iterator<Row> iter = results.iterator();
138 tt = trans.start("Load History", Env.SUB);
140 while (iter.hasNext()) {
143 loader.exec(creator.create(row));
149 trans.info().log("Found",count,"histories");
153 public String toString() {
154 return String.format("%s %d %s, %s, %s, %s, %s",
165 * @see java.lang.Object#hashCode()
168 public int hashCode() {
169 return id.hashCode();
173 * @see java.lang.Object#equals(java.lang.Object)
176 public boolean equals(Object obj) {
177 return id.equals(obj);