diff options
Diffstat (limited to 'auth/auth-cass')
-rw-r--r-- | auth/auth-cass/cass_init/authBatch.props | 26 | ||||
-rw-r--r-- | auth/auth-cass/cass_init/restore.sh | 52 | ||||
-rw-r--r-- | auth/auth-cass/docker/Dockerfile.cass | 2 | ||||
-rw-r--r-- | auth/auth-cass/docker/dbuild.sh | 2 | ||||
-rw-r--r-- | auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassDAOImpl.java | 37 |
5 files changed, 102 insertions, 17 deletions
diff --git a/auth/auth-cass/cass_init/authBatch.props b/auth/auth-cass/cass_init/authBatch.props new file mode 100644 index 00000000..90de4195 --- /dev/null +++ b/auth/auth-cass/cass_init/authBatch.props @@ -0,0 +1,26 @@ +aaf_data_dir=/opt/app/aaf/data +aaf_root_ns=org.osaaf.aaf +cadi_latitude=38.0 +cadi_longitude=-72.0 + +## Supported Plugin Organizational Units +Organization.att.com=org.onap.aaf.org.DefaultOrg + +DRY_RUN=false +CASS_ENV=DOCKER + +UNKNOWN.LOG_DIR=logs/DOCKER + +## Cassandra Configurations, when commented out, uses LocalHost (non authenticated) and default ports +DOCKER.cassandra.clusters=127.0.0.1 +DOCKER.cassandra.clusters.port=9042 +DOCKER.cassandra.clusters.user=cassandra +DOCKER.cassandra.clusters.password=cassandra +DOCKER.VERSION=3.1.0 +DOCKER.GUI_URL=https://mithrilcsp.sbc.com:8095/gui +DOCKER.punt=1 +DOCKER. +DOCKER.MAX_EMAILS=3 +DOCKER.SPECIAL_NAMES=aaf@aaf.osaaf.org + +cadi_loglevel=AUDIT diff --git a/auth/auth-cass/cass_init/restore.sh b/auth/auth-cass/cass_init/restore.sh new file mode 100644 index 00000000..768cf4c7 --- /dev/null +++ b/auth/auth-cass/cass_init/restore.sh @@ -0,0 +1,52 @@ +# echo -n "Password:" +# read -s PWD +# echo +echo `date` +ENV=DOCKER + +CQLSH="/usr/bin/cqlsh -k authz" + +cd dats +if [ "$*" = "" ]; then + DATA="" + for Tdat in `ls *.dat`; do + if [ -s "${Tdat}" ]; then + DATA="$DATA ${Tdat%.dat}" + fi + done +else + DATA="$*" +fi +cd - + +echo "You are about to REPLACE the data in the $ENV DB for the following tables:" +echo "$DATA" +echo -n 'If you are VERY sure, type "YES": ' +read YES + +if [ ! "$YES" = "YES" ]; then + echo 'Exiting ...' + exit +fi + +UPLOAD="" +for T in $DATA; do + if [ -s "dats/${T}.dat" ]; then + echo $T + case "$T" in + # 2.1.14 still has NULL problems for COPY. Fixed in 2.1.15+ + "approval"|"artifact"|"cred"|"ns"|"x509"|"role") + $CQLSH -e "truncate $T" + UPLOAD="$UPLOAD dats/"$T + ;; + *) + $CQLSH -e "truncate $T; COPY authz.${T} FROM 'dats/${T}.dat' WITH DELIMITER='|'" + ;; + esac + fi +done + +if [ ! "$UPLOAD" = "" ]; then + java -DCASS_ENV=$ENV -jar aaf-auth-batch-*-full.jar Upload $UPLOAD +fi +echo `date` diff --git a/auth/auth-cass/docker/Dockerfile.cass b/auth/auth-cass/docker/Dockerfile.cass index a540fb78..e79b33fc 100644 --- a/auth/auth-cass/docker/Dockerfile.cass +++ b/auth/auth-cass/docker/Dockerfile.cass @@ -26,6 +26,8 @@ LABEL version=${AAF_VERSION} COPY cass_init/*.cql /opt/app/aaf/cass_init/ COPY cass_init/*.sh /opt/app/aaf/cass_init/ +COPY cass_init/*.props /opt/app/aaf/cass_init/ +COPY aaf-auth-batch-${AAF_VERSION}-full.jar /opt/app/aaf/cass_init/ COPY cass_data/*.dat /opt/app/aaf/cass_init/dats/ ENTRYPOINT ["/bin/bash","/opt/app/aaf/cass_init/cmd.sh"] diff --git a/auth/auth-cass/docker/dbuild.sh b/auth/auth-cass/docker/dbuild.sh index 92f3e87c..100b8cb9 100644 --- a/auth/auth-cass/docker/dbuild.sh +++ b/auth/auth-cass/docker/dbuild.sh @@ -34,6 +34,7 @@ sed -e 's/${AAF_VERSION}/'${VERSION}'/g' $DIR/Dockerfile.cass > Dockerfile cd .. cp -Rf sample/cass_data auth-cass/cass_data cp sample/data/sample.identities.dat auth-cass +cp auth-batch/target/aaf-auth-batch-$VERSION-full.jar auth-cass echo $DOCKER build -t ${ORG}/${PROJECT}/aaf_cass:${VERSION} auth-cass $DOCKER build -t ${ORG}/${PROJECT}/aaf_cass:${VERSION} auth-cass @@ -44,5 +45,6 @@ cd - rm Dockerfile rm -Rf cass_data rm sample.identities.dat +rm aaf-auth-batch-$VERSION-full.jar cd $DIR diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassDAOImpl.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassDAOImpl.java index 58c4386b..72444c99 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassDAOImpl.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassDAOImpl.java @@ -48,10 +48,14 @@ import com.datastax.driver.core.ResultSetFuture; */ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS, DATA> implements DAO<TRANS,DATA> { public static final String USER_NAME = "__USER_NAME__"; + public static final String CASS_READ_CONSISTENCY="cassandra.readConsistency"; + public static final String CASS_WRITE_CONSISTENCY="cassandra.writeConsistency"; protected static final String CREATE_SP = "CREATE "; protected static final String UPDATE_SP = "UPDATE "; protected static final String DELETE_SP = "DELETE "; protected static final String SELECT_SP = "SELECT "; + private static final String WHERE = " WHERE "; + private static final String READ_IS_DISABLED = "Read is disabled for %s"; protected final String C_TEXT = getClass().getSimpleName() + " CREATE"; protected final String R_TEXT = getClass().getSimpleName() + " READ"; @@ -59,7 +63,14 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS protected final String D_TEXT = getClass().getSimpleName() + " DELETE"; private String table; - protected final ConsistencyLevel readConsistency,writeConsistency; + protected final ConsistencyLevel readConsistency; + protected final ConsistencyLevel writeConsistency; + + protected PSInfo createPS; + protected PSInfo readPS; + protected PSInfo updatePS; + protected PSInfo deletePS; + protected boolean async=false; // Setteable only by CachedDAO protected Cached<?, ?> cache; @@ -95,12 +106,6 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS writeConsistency = write; } - protected PSInfo createPS; - protected PSInfo readPS; - protected PSInfo updatePS; - protected PSInfo deletePS; - protected boolean async=false; - public void async(boolean bool) { async = bool; } @@ -111,7 +116,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS public final String[] setCRUD(TRANS trans, String table, Class<?> dc,Loader<DATA> loader, int max) { Field[] fields = dc.getDeclaredFields(); - int end = max>=0 & max<fields.length?max:fields.length; + int end = max>=0 && max<fields.length?max:fields.length; // get keylimit from a non-null Loader int keylimit = loader.keylimit(); @@ -146,16 +151,16 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS createPS = new PSInfo(trans, "INSERT INTO " + table + " ("+ sbfc +") VALUES ("+ sbq +");",loader,writeConsistency); - readPS = new PSInfo(trans, "SELECT " + sbfc + " FROM " + table + " WHERE " + sbwc + ';',loader,readConsistency); + readPS = new PSInfo(trans, SELECT_SP + sbfc + " FROM " + table + WHERE + sbwc + ';',loader,readConsistency); // Note: UPDATES can't compile if there are no fields besides keys... Use "Insert" if (sbup.length()==0) { updatePS = createPS; // the same as an insert } else { - updatePS = new PSInfo(trans, "UPDATE " + table + " SET " + sbup + " WHERE " + sbwc + ';',loader,writeConsistency); + updatePS = new PSInfo(trans, UPDATE_SP + table + " SET " + sbup + WHERE + sbwc + ';',loader,writeConsistency); } - deletePS = new PSInfo(trans, "DELETE FROM " + table + " WHERE " + sbwc + ';',loader,writeConsistency); + deletePS = new PSInfo(trans, "DELETE FROM " + table + WHERE + sbwc + ';',loader,writeConsistency); } return new String[] {sbfc.toString(), sbq.toString(), sbup.toString(), sbwc.toString()}; } @@ -207,21 +212,21 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS */ public Result<List<DATA>> read(TRANS trans, DATA data) { if (readPS==null) { - return Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName()); + return Result.err(Result.ERR_NotImplemented,READ_IS_DISABLED,getClass().getSimpleName()); } return readPS.read(trans, R_TEXT, data); } public Result<List<DATA>> read(TRANS trans, Object ... key) { if (readPS==null) { - return Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName()); + return Result.err(Result.ERR_NotImplemented,READ_IS_DISABLED,getClass().getSimpleName()); } return readPS.read(trans, R_TEXT, key); } public Result<DATA> readPrimKey(TRANS trans, Object ... key) { if (readPS==null) { - return Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName()); + return Result.err(Result.ERR_NotImplemented,READ_IS_DISABLED,getClass().getSimpleName()); } Result<List<DATA>> rld = readPS.read(trans, R_TEXT, key); if (rld.isOK()) { @@ -312,9 +317,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS public String table() { return table; } - - public static final String CASS_READ_CONSISTENCY="cassandra.readConsistency"; - public static final String CASS_WRITE_CONSISTENCY="cassandra.writeConsistency"; + protected static ConsistencyLevel readConsistency(AuthzTrans trans, String table) { String prop = trans.getProperty(CASS_READ_CONSISTENCY+'.'+table); if (prop==null) { |