diff options
Diffstat (limited to 'auth/auth-cass')
-rw-r--r-- | auth/auth-cass/cass_init/cmd.sh | 6 | ||||
-rw-r--r-- | auth/auth-cass/docker/dinstall.sh | 4 | ||||
-rw-r--r-- | auth/auth-cass/docker/drun.sh | 6 | ||||
-rw-r--r-- | auth/auth-cass/pom.xml | 2 | ||||
-rw-r--r-- | auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java | 4 | ||||
-rw-r--r-- | auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java | 18 | ||||
-rw-r--r-- | auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java | 137 |
7 files changed, 102 insertions, 75 deletions
diff --git a/auth/auth-cass/cass_init/cmd.sh b/auth/auth-cass/cass_init/cmd.sh index 98194e08..ffaf182d 100644 --- a/auth/auth-cass/cass_init/cmd.sh +++ b/auth/auth-cass/cass_init/cmd.sh @@ -37,7 +37,7 @@ fi function status { echo "$@" - echo "$@" > $DIR/aaf_cass + echo "$@" > $DIR/aaf-cass } function wait_start { @@ -69,7 +69,7 @@ function wait_cql { function wait_ready { status wait for cassandra to be fully ready for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do - STATUS="$(cat $DIR/aaf_cass)" + STATUS="$(cat $DIR/aaf-cass)" if [ "$STATUS" = "ready" ]; then break else @@ -88,7 +88,7 @@ function install_cql { if [ -z "`/usr/bin/cqlsh -e 'describe keyspaces' | grep authz`" ]; then status install echo "Initializing Cassandra DB" - echo "Docker Installed Basic Cassandra on aaf_cass. Executing the following " + echo "Docker Installed Basic Cassandra on aaf.cass. Executing the following " echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently" echo "" echo " cd /opt/app/aaf/cass_init" diff --git a/auth/auth-cass/docker/dinstall.sh b/auth/auth-cass/docker/dinstall.sh index 83fb060e..e6da5e4b 100644 --- a/auth/auth-cass/docker/dinstall.sh +++ b/auth/auth-cass/docker/dinstall.sh @@ -24,12 +24,12 @@ echo "Waiting for Cass to be initialized" for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do - $DOCKER exec -it aaf_cass bash aaf_cmd wait 2> /dev/null + $DOCKER exec -it aaf-cass bash aaf_cmd wait 2> /dev/null if [ "$?" -ne "0" ]; then echo "Container not ready... Sleep 10" sleep 10 else - echo "aaf_cass is ready" + echo "aaf-cass is ready" break fi done diff --git a/auth/auth-cass/docker/drun.sh b/auth/auth-cass/docker/drun.sh index a412296b..778947eb 100644 --- a/auth/auth-cass/docker/drun.sh +++ b/auth/auth-cass/docker/drun.sh @@ -35,11 +35,11 @@ fi # Optional mount instead of v # --mount 'type=volume,src=aaf_cass_data,dst=/var/lib/cassandra,volume-driver=local' \ -if [ "`$DOCKER ps -a | grep aaf_cass`" == "" ]; then +if [ "`$DOCKER ps -a | grep aaf-cass`" == "" ]; then echo "starting Cass from 'run'" # NOTE: These HEAP Sizes are minimal. Not set for full organizations. $DOCKER run \ - --name aaf_cass \ + --name aaf-cass \ -e HEAP_NEWSIZE=512M \ -e MAX_HEAP_SIZE=1024M \ -e CASSANDRA_DC=dc1 \ @@ -49,5 +49,5 @@ if [ "`$DOCKER ps -a | grep aaf_cass`" == "" ]; then $PUBLISH \ -d ${PREFIX}${ORG}/${PROJECT}/aaf_cass:${VERSION} "onap" else - $DOCKER start aaf_cass + $DOCKER start aaf-cass fi diff --git a/auth/auth-cass/pom.xml b/auth/auth-cass/pom.xml index cfff8f7c..c43a6965 100644 --- a/auth/auth-cass/pom.xml +++ b/auth/auth-cass/pom.xml @@ -17,7 +17,7 @@ <parent> <groupId>org.onap.aaf.authz</groupId> <artifactId>authparent</artifactId> - <version>2.1.9-SNAPSHOT</version> + <version>2.1.10-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java index 48131860..6fe9bde5 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java @@ -102,9 +102,9 @@ public class CassAccess { } str = env.getProperty(Config.CADI_LATITUDE); - Double lat = str!=null?Double.parseDouble(str):null; + Double lat = str!=null && !str.isEmpty()?Double.parseDouble(str):null; str = env.getProperty(Config.CADI_LONGITUDE); - Double lon = str!=null?Double.parseDouble(str):null; + Double lon = str!=null && !str.isEmpty()?Double.parseDouble(str):null; if (lat == null || lon == null) { throw new APIException(Config.CADI_LATITUDE + " and/or " + Config.CADI_LONGITUDE + " are not set"); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java index 757efa5f..085f4199 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java @@ -99,6 +99,24 @@ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { public void reconstitute(ByteBuffer bb) throws IOException { LocateLoader.deflt.unmarshal(this, toDIS(bb)); } + + public Data copy() { + Data out = new Data(); + out.name = name; + out.hostname = hostname; + out.port = port; + out.major = major; + out.minor = minor; + out.patch = patch; + out.pkg = pkg; + out.latitude = latitude; + out.longitude = longitude; + out.protocol = protocol; + out.subprotocol = new HashSet<>(); + out.subprotocol.addAll(subprotocol); + out.port_key = port_key; + return out; + } } private static class LocateLoader extends Loader<Data> implements Streamer<Data>{ diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java index 9eea77e3..ec5449df 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java @@ -21,77 +21,74 @@ package org.onap.aaf.auth.direct; -import java.net.Inet4Address; -import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; import org.onap.aaf.auth.dao.cass.LocateDAO; -import org.onap.aaf.auth.dao.cass.LocateDAO.Data; import org.onap.aaf.auth.env.AuthzEnv; +import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.cadi.Access; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.client.Result; -import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.register.Registrant; -import org.onap.aaf.cadi.util.Split; +import org.onap.aaf.cadi.register.RegistrationCreator; + +import locate.v1_0.MgmtEndpoint; +import locate.v1_0.MgmtEndpoints; public class DirectRegistrar implements Registrant<AuthzEnv> { - private Data locate; + private LocateDAO ldao; - public DirectRegistrar(Access access, LocateDAO ldao, String name, String version, int port) throws CadiException { - this.ldao = ldao; - locate = new LocateDAO.Data(); - locate.name = name; - locate.port = port; - - try { - String latitude = access.getProperty(Config.CADI_LATITUDE, null); - if (latitude==null) { - latitude = access.getProperty("AFT_LATITUDE", null); - } - String longitude = access.getProperty(Config.CADI_LONGITUDE, null); - if (longitude==null) { - longitude = access.getProperty("AFT_LONGITUDE", null); - } - if (latitude==null || longitude==null) { - throw new CadiException(Config.CADI_LATITUDE + " and " + Config.CADI_LONGITUDE + " is required"); - } else { - locate.latitude = Float.parseFloat(latitude); - locate.longitude = Float.parseFloat(longitude); - } - String split[] = Split.splitTrim('.', version); - locate.pkg = split.length>3?Integer.parseInt(split[3]):0; - locate.patch = split.length>2?Integer.parseInt(split[2]):0; - locate.minor = split.length>1?Integer.parseInt(split[1]):0; - locate.major = split.length>0?Integer.parseInt(split[0]):0; - locate.hostname = access.getProperty(Config.AAF_REGISTER_AS, null); - if (locate.hostname==null) { - locate.hostname = access.getProperty(Config.HOSTNAME, null); - } - if (locate.hostname==null) { - locate.hostname = Inet4Address.getLocalHost().getHostName(); - } - String subprotocols = access.getProperty(Config.CADI_PROTOCOLS, null); - if (subprotocols==null) { - locate.protocol="http"; - } else { - locate.protocol="https"; - for (String s : Split.split(',', subprotocols)) { - locate.subprotocol(true).add(s); - } - } - } catch (NumberFormatException | UnknownHostException e) { - throw new CadiException("Error extracting Data from Properties for Registrar",e); + private List<LocateDAO.Data> ldd; + public DirectRegistrar(Access access, LocateDAO ldao, int port) throws CadiException { + this.ldao = ldao; + ldd = new ArrayList<>(); + RegistrationCreator rc = new RegistrationCreator(access); + MgmtEndpoints mes = rc.create(port); + for(MgmtEndpoint me : mes.getMgmtEndpoint()) { + ldd.add(convert(me)); } } - @Override + private LocateDAO.Data convert(MgmtEndpoint me) { + LocateDAO.Data out = new LocateDAO.Data(); + out.name=me.getName(); + out.hostname=me.getHostname(); + out.latitude=me.getLatitude(); + out.longitude=me.getLongitude(); + out.major=me.getMajor(); + out.minor=me.getMinor(); + out.pkg=me.getPkg(); + out.patch=me.getPatch(); + out.port=me.getPort(); + out.protocol=me.getProtocol(); + out.subprotocol(true).addAll(me.getSubprotocol()); +// out.port_key = UUID.randomUUID(); + return out; + } + + @Override + public Result<Void> update(AuthzEnv env) { - org.onap.aaf.auth.layer.Result<Void> dr = ldao.update(env.newTransNoAvg(), locate); - if (dr.isOK()) { - return Result.ok(200, null); - } else { - return Result.err(503, dr.errorString()); - } + AuthzTrans trans = env.newTransNoAvg(); + StringBuilder sb = null; + for(LocateDAO.Data ld : ldd) { + org.onap.aaf.auth.layer.Result<Void> dr = ldao.update(trans, ld); + if (dr.notOK()) { + if(sb == null) { + sb = new StringBuilder(dr.errorString()); + } else { + sb.append(';'); + sb.append(dr.errorString()); + } + } + } + + if(sb==null) { + return Result.ok(200, null); + } else { + return Result.err(503, sb.toString()); + } } /* (non-Javadoc) @@ -99,13 +96,25 @@ public class DirectRegistrar implements Registrant<AuthzEnv> { */ @Override public Result<Void> cancel(AuthzEnv env) { - org.onap.aaf.auth.layer.Result<Void> dr = ldao.delete(env.newTransNoAvg(), locate, false); - if (dr.isOK()) { - return Result.ok(200, null); - } else { - return Result.err(503, dr.errorString()); - } - + AuthzTrans trans = env.newTransNoAvg(); + StringBuilder sb = null; + for(LocateDAO.Data ld : ldd) { + org.onap.aaf.auth.layer.Result<Void> dr = ldao.delete(trans, ld, false); + if (dr.notOK()) { + if(sb == null) { + sb = new StringBuilder(dr.errorString()); + } else { + sb.append(';'); + sb.append(dr.errorString()); + } + } + } + + if(sb==null) { + return Result.ok(200, null); + } else { + return Result.err(503, sb.toString()); + } } } |