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.ArrayList;
28 import java.util.Date;
29 import java.util.List;
31 import java.util.TreeMap;
32 import java.util.UUID;
34 import org.onap.aaf.auth.dao.cass.FutureDAO;
35 import org.onap.aaf.auth.env.AuthzTrans;
36 import org.onap.aaf.auth.layer.Result;
37 import org.onap.aaf.misc.env.Env;
38 import org.onap.aaf.misc.env.TimeTaken;
39 import org.onap.aaf.misc.env.Trans;
40 import org.onap.aaf.misc.env.util.Chrono;
42 import com.datastax.driver.core.ResultSet;
43 import com.datastax.driver.core.Row;
44 import com.datastax.driver.core.Session;
45 import com.datastax.driver.core.SimpleStatement;
46 import com.datastax.driver.core.Statement;
48 public class Future implements CacheChange.Data, Comparable<Future> {
49 public static final Map<UUID,Future> data = new TreeMap<>();
50 public static final Map<String,List<Future>> byRole = new TreeMap<>();
52 public final FutureDAO.Data fdd;
53 public final String role; // derived
54 private static final CacheChange<Future> cache = new CacheChange<>();
56 public static Creator<Future> v2_0_17 = new Creator<Future>() {
58 public Future create(Row row) {
59 return new Future(row.getUUID(0),row.getString(1),row.getString(2),
60 row.getTimestamp(3),row.getTimestamp(4), null);
64 public String select() {
65 return "select id,memo,target,start,expires from authz.future";
69 public static Creator<Future> withConstruct = new Creator<Future>() {
71 public String select() {
72 return "select id,memo,target,start,expires,construct from authz.future";
76 public Future create(Row row) {
77 return new Future(row.getUUID(0),row.getString(1),row.getString(2),
78 row.getTimestamp(3),row.getTimestamp(4), row.getBytes(5));
84 public Future(UUID id, String memo, String target, Date start, Date expires, ByteBuffer construct) {
85 fdd = new FutureDAO.Data();
90 fdd.expires = expires;
91 fdd.construct = construct;
92 role = Approval.roleFromMemo(memo);
95 public final UUID id() {
99 public final String memo() {
103 public final String target() {
107 public final Date start() {
111 public final Date expires() {
115 public static void load(Trans trans, Session session, Creator<Future> creator) {
116 trans.info().log( "query: " + creator.select() );
118 TimeTaken tt = trans.start("Load Futures", Env.REMOTE);
120 Statement stmt = new SimpleStatement(creator.select());
121 results = session.execute(stmt);
127 tt = trans.start("Process Futures", Env.SUB);
129 for (Row row : results.all()) {
131 Future f = creator.create(row);
132 data.put(f.fdd.id,f);
136 List<Future> lf = byRole.get(f.role);
138 lf = new ArrayList<>();
139 byRole.put(f.role,lf);
146 trans.info().log("Found",count,"Futures");
150 public Result<Void> delayedDelete(AuthzTrans trans, FutureDAO fd, boolean dryRun, String text) {
153 trans.info().log(text,"- Would Delete: ",fdd.id,fdd.memo,"expiring on",Chrono.dateOnlyStamp(fdd.expires));
156 rv = fd.delete(trans, fdd, true); // need to read for undelete
158 trans.info().log(text, "- Deleted:",fdd.id,fdd.memo,"expiring on",Chrono.dateOnlyStamp(fdd.expires));
159 cache.delayedDelete(this);
162 trans.info().log(text,"- Failed to Delete Future", fdd.id);
170 * @see org.onap.aaf.auth.helpers.CacheChange.Data#resetLocalData()
173 public void expunge() {
176 List<Future> lf = byRole.get(role);
184 public int compareTo(Future o) {
188 return fdd.id.compareTo(o.fdd.id);
191 public static void resetLocalData() {
192 cache.resetLocalData();
195 public static int sizeForDeletion() {
196 return cache.cacheSize();
199 public static boolean pendingDelete(Future f) {
200 return cache.contains(f);