From: dglFromAtt Date: Tue, 19 Feb 2019 01:00:09 +0000 (-0500) Subject: Added new fields to dr_sub API X-Git-Tag: 1.0.26~46^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdbcapi.git;a=commitdiff_plain;h=7ecdac335b89831e5d9043434f05beb21dff640a Added new fields to dr_sub API for ONAP: privilegedSubscriber for AT&T: guaranteed_delivery, guaranteed_sequence also used this opportunity to move info about properties into README file patchset 2: increment version patchset 3: more try{}catch around reading fields from JSON . Boolean fields are fragile. Change-Id: Idc7353aaa660c180c1079f9ff61c7d55c41d4170 Signed-off-by: dglFromAtt Issue-ID: DMAAP-1033 Signed-off-by: dglFromAtt --- diff --git a/README.md b/README.md index 34a8952..235e0d0 100644 --- a/README.md +++ b/README.md @@ -46,165 +46,120 @@ mvn clean install javadoc:javadoc A description of the API is generated, and found in targets/generated-source/swagger.json. -### Configurable Parameters +### Properties File -Behavior of the API is controlled by settings in a properties file (typically etc/dmaapbc.properties). -The following describes these properties: - -``` - -# -# Configuration parameters fixed at startup for the DMaaP Bus Controller -# -# -# URI to retrieve dynamic DR configuration -# -ProvisioningURI: /internal/prov -# -# Allow http access to API -# -HttpAllowed: true -# -# The port number for http as seen within the server -# -IntHttpPort: 8080 -# -# The port number for https as seen within the server -# Set to 0 if no certificate is available yet... -# -IntHttpsPort: 8443 -# -# The external port number for https taking port mapping into account -# -ExtHttpsPort: 443 -# -# The type of keystore for https -# -KeyStoreType: jks -# -# The path to the keystore for https -# -KeyStoreFile: etc/keystore -# -# The password for the https keystore -# -KeyStorePassword: changeit -# -# The password for the private key in the https keystore -# -KeyPassword: changeit -# -# The type of truststore for https -# -TrustStoreType: jks -# -# The path to the truststore for https -# -TrustStoreFile: /opt/app/java/jdk/jdk180/jre/security/cacerts -# -# The password for the https truststore -# -TrustStorePassword: changeit -# -# The path to the file used to trigger an orderly shutdown -# -QuiesceFile: etc/SHUTDOWN -# -# Enable postgress -# -UsePGSQL: true -# -# The host for postgres access -# -DB.host: HostNotSet -# -# For postgres access -# -DB.cred: ValueNotSet -# -# Name of this environment -# -DmaapName: DeploymentEnvName -# -# Name of DR prov server -# -DR.provhost: dcae-drps.domain.notset.com -# -# The Role and credentials of the MirrorMaker Provisioner. This is used by DMaaP Bus Controller to pub to the provisioning topic -# Not part of 1701 -# -#MM.ProvRole: org.openecomp.dmaapBC.MMprov.prov -#MM.ProvUserMechId: idNotSet@namespaceNotSet -#MM.ProvUserPwd: enc:fMxh-hzYZldbtyXumQq9aJU08SslhbM6mXtt -# -# The Role of the MirrorMaker Agent. This is used by MM to sub to provisioning topic -# -MM.AgentRole: org.openecomp.dmaapBC.MMagent.agent -################# -# AAF Properties: -# -# regarding password encryption: -# In the dependencies that Maven retrieves (e.g., under dcae_dmaapbc/target/deps/ is a jar file cadi-core-version.jar. Generate the key file with: -# -# java \u2013jar wherever/cadi-core-*.jar keygen keyfilename -# chmod 400 keyfilename -# -# To encrypt a key: -# -# java \u2013jar wherever/cadi-core-*.jar digest password-to-encrypt keyfilename -# -# This will generate a string. Put \u201Cenc:\u201D on the front of the string, and put the result in this properties file. -# -# Location of the Codec Keyfile which is used to decrypt passwords in this properties file before they are passed to AAF -# -# REF: https://wiki.domain.notset.com/display/cadi/CADI+Deployment -# -CredentialCodecKeyfile: etc/LocalKey -# -# URL of AAF environment to use. -# -aaf.URL: https://authentication.simpledemo.openecomp.org:8095/proxy/ -# -# TopicMgr mechid@namespace -# -aaf.TopicMgrUser: idNotSet@namespaceNotSet -# -# TopicMgr password -# -aaf.TopicMgrPassword: enc:zyRL9zbI0py3rJAjMS0dFOnYfEw_mJhO -# -# Bus Controller Namespace Admin mechid@namespace -# -aaf.AdminUser: idNotSet@namespaceNotSet -# -# Bus Controller Namespace Admin password -# -aaf.AdminPassword: enc:YEaHwOJrwhDY8a6usetlhbB9mEjUq9m -# -# endof AAF Properties -################# -################# -# PolicyEngine Properties -# -# Flag to turn on/off Authentication -UsePE: false -# -# Argument to decisionAttributes.put("AAF_ENVIRONMENT", X); -# where X is: TEST= UAT, PROD = PROD, DEVL = TEST -# -PeAafEnvironment: DEVL -# -# Name of PolicyEngineApi properties file -PolicyEngineProperties: config/PolicyEngineApi.properties -# -# Namespace for URI values for API used to create AAF permissions -# e.g. if ApiNamespace is X.Y..dmaapBC.api then for URI /topics we create an AAF perm X.Y..dmaapBC.api.topics -ApiNamespace: org.onap.dmaap.dbcapi -# -# endof PolicyEngineProperties -################# - -``` +This section is intended to describe the behavior customization of Bus Controller that can be obtained via properties file used by the dbcapi library. +By default, this file is located in etc/dmaapbc.properties. +However, a java argument -DConfigFile can be set to a different path. (Our kubernetes deployment relies on this and points to a configmap, for example.) +The table below lists all the settings, default values (if not set), and shows any explicit setting in ONAP oom kubernetes deployment. +|-|-|-|-| +| Property | Description | Default | ONAP Kubernetes Setting | +|-|-|-|-| +|UseAAF | Flag for whether AAF authz API is to be used | false | false | +|-|-|-|-| +|csit | Flag for stubbing out many southbound calls in a CSIT environment | No | No | +|-|-|-|-| +|DR.provhost | FQDN of Data Router Provisioning Server (deprecated - now set via API) | notSet | dcae-drps.domain.not.set | +|-|-|-|-| +|ProvisioningURI | URI to retrieve dynamic DR configuration | /internal/prov | /internal/prov | +|-|-|-|-| +|Feed.deleteHandling | indicator for handling feed delete request | DeleteOnDR | SimulateDelete | +| | DeleteOnDR - means use the DR API to DELETE a feed. (default for backwards compatibility) | | | +| | SimulateDelete - means preserve the feed on DR (after cleaning it up), and mark as DELETED in DBCL. | | | +|-|-|-|-| +|UsePGSQL | flag indicates whether to retain data in Postgresql | false | true | +| | when false, objects will be kept in memory but will be | | | +| | lost on restart and not shared between instances | | | +|-|-|-|-| +|DB.host | FQDN or service name of Postresql host | dcae-pstg-write-ftl.domain.notset.com | dbc-pg-primary | +|-|-|-|-| +|DB.name | name of Postresql database | dmaap | | +|-|-|-|-| +|DB.schema | name of database schema | public | | +|-|-|-|-| +|DB.user | username for Postgresql access | dmaap_admin | | +|-|-|-|-| +|DB.cred | password for Postrgresql access | test234-ftl | onapdemodb | +|-|-|-|-| +|MR.multisite | Indicates if there can be multiple sites (locations) where MR is deployed | true | false | +|-|-|-|-| +|MR.CentralCname | FQDN or service name of MR (deployed in central if multilocation is true) | MRcname.not.set | message-router | +|-|-|-|-| +|MR ClientDeleteLevel | MR Client Delete thoroughness | 0 | 1 | +| | 0 = don't delete | | | +| | 1 = delete from persistent store (PG) | | | +| | 2 = delete from persistent store (PG) and authorization store (AAF) | | | +|-|-|-|-| +|MR.TopicFactoryNS | AAF namespace used to create perms for MR topics | MR.topicFactoryNS.not.set | org.onap.dmaap.mr.topicFactory | +|-|-|-|-| +|MR.TopicMgrRole | AAF Role used by Buscontroller to create topics on MR | MR.TopicMgrRole.not.set | org.onap.dmaap-bc-topic-mgr.client | +|-|-|-|-| +|MR.projectID | Value for some constructs of fully qualified topic names | 99999 | ONAP | +|-|-|-|-| +|cadi.properties | Path to CADI properties file | /opt/app/osaaf/local/org.onap.dmaap-bc.props | /opt/app/osaaf/lcoal/org.onap.dmaap-bc.props | +|-|-|-|-| +|aaf.URL | URL of the AAF server | https://authentication.domain.netset.com:8095/proxy/ | https://aaf-authz/ | +|-|-|-|-| +|aaf.TopicMgrUser | AAF Identity of Topic Mgr | noMechId@domain.netset.com | dmaap-bc-topic-mgr@dmaap-bc-topic-mgr.onap.org | +|-|-|-|-| +|aaf.TopicMgrPassword | AAF Credential for Topic Mgr | notSet | demo123456! | +|-|-|-|-| +|aaf.AdminUser | AAF Identity of user with Admin role for API namespace | noMechId@domain.netset.com | aaf_admin@people.osaaf.org | +|-|-|-|-| +|aaf.AdminPassword | AAF credential of AdminUser | notSet | demo123456! | +|-|-|-|-| +|aaf.NsOwnerIdentity | AAF Identity to be used as topic Namespace owner | notSet | aaf_admin@people.osaaf.org | +|topicNsRoot | AAF namespace value used to create FQTN | org.onap.dcae.dmaap | org.onap.dcae.dmaap | +|-|-|-|-| +|CredentialCodeKeyfile | location of the codec keyfile used to decrypt passwords | LocalKey | etc/LocalKey | +| | in this properties file before they are passed to AAF | LocalKey | etc/LocalKey | +|-|-|-|-| +|AafDecryption.Class | Specifies the Class to be used for decryption | org.onap.dmaap.dbcapi.aaf.ClearDecrypt | | +|-|-|-|-| +|ApiNamespace | Root namespace for AAF perms related to dbcapi access | apiNamespace.not.set | org.onap.dmaap-bc.api | +|-|-|-|-| +|ApiPermission.Class | the Class that determines if a call to API is authorized| allow | | +|-|-|-|-| +|MM.ProvRole | AAF Role of client publishing MM prov cmds | notSet | org.onap.dmaap-bc-mm-prov.prov | +|-|-|-|-| +|MM.ProvUserMechId | AAF Identity when publishing to MM command topic | notSet | dmaap-bc-mm-prov@dmaap-bc-mm-prov.onap.org| +|-|-|-|-| +|MM.ProvUserPwd | AAF credenital for ProvUserMechId | notSet | demo123456! | +|-|-|-|-| +|MM.AgentRole | AAF Role of client susbcribing to MM command topic | notSet | org.onal.dmaap-bc-mm-prov.agent | +|-|-|-|-| +|DR.provApi | Version name of DR API (ONAP or AT&T) | ONAP | ONAP | +|-|-|-|-| +|DR.onBehalfHeader | String for "On Behalf Of" HTTP Header in DR API | X-DR-ON-BEHALF-OF | X-DR-ON-BEHALF-OF | +|-|-|-|-| +|DR.feedContentType | Value for Content-Type Header in DR Feed API | application/vnd.dr.feed | application/vnd.dr.feed | +|-|-|-|-| +|DR subContentType | Value for Content-Type Header in DR Subscription API | application/vnd.dr.subscription | application/vnd.dr.subscription | +|-|-|-|-| +|HttpAllowed | flag indicating whether http is supported | false | true | +|-|-|-|-| +|IntHttpPort | Internal port for http service | 80 | 8080 | +|-|-|-|-| +|IntHttpsPort | Internal port for https service (0 if no cert is avail) | 443 | 8443 | +|-|-|-|-| +|ExtHttpsPort | Externally advertised port for https service (deprecated)| 443 | 443 | +|-|-|-|-| +|KeyStoreType | Format of Java keystore | jks | jks | +|-|-|-|-| +|KeyStoreFile | Path to java keystore | etc/keystore | etc/keystore | +|-|-|-|-| +|KeyStorePassword | Password for keystore | changeit | | +|-|-|-|-| +|KeyPassword | Password for private key in the https keystore | changeit | | +|-|-|-|-| +|TrustStoreType | Format of Trust Store file | jks | jks | +|-|-|-|-| +|TrustStoreFile | Path to Trust Store file | | etc/org.onap.dmaap-bc.trust.jks | +|-|-|-|-| +|TrustStorePassword | Password for Trust Store | | | +|-|-|-|-| +|QuiesceFile | Path to file which signals needs to queiesce | | etc/SHUTDOWN | +|-|-|-|-| diff --git a/pom.xml b/pom.xml index b735c48..8a27fa9 100644 --- a/pom.xml +++ b/pom.xml @@ -381,7 +381,7 @@ UTF-8 9.4.12.RC2 1.0.0 - 1.0.22-SNAPSHOT + 1.0.23-SNAPSHOT 0.7.7.201606060606 3.2 diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java index a5d9999..dd0b85d 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java @@ -42,6 +42,9 @@ public class DR_Sub extends DmaapObject { private boolean use100; private boolean suspended; private String owner; + private boolean guaranteedDelivery; + private boolean guaranteedSequence; + private boolean privilegedSubscriber; public DR_Sub() { @@ -81,13 +84,32 @@ public class DR_Sub extends DmaapObject { this.setOwner( (String) jsonObj.get("subscriber")); this.setSuspended( (boolean) jsonObj.get("suspend")); - JSONObject links = (JSONObject) jsonObj.get("links"); - String url = (String) links.get("feed"); - this.setFeedId( url.substring( url.lastIndexOf('/')+1, url.length() )); - url = (String) links.get("self"); - this.setSubId( url.substring( url.lastIndexOf('/')+1, url.length() )); - logger.info( "feedid="+ this.getFeedId() ); - this.setLogURL( (String) links.get("log") ); + try { + JSONObject links = (JSONObject) jsonObj.get("links"); + String url = (String) links.get("feed"); + this.setFeedId( url.substring( url.lastIndexOf('/')+1, url.length() )); + url = (String) links.get("self"); + this.setSubId( url.substring( url.lastIndexOf('/')+1, url.length() )); + logger.info( "feedid="+ this.getFeedId() ); + this.setLogURL( (String) links.get("log") ); + } catch (NullPointerException npe ) { + + } + try { + this.setGuaranteedDelivery( (boolean) jsonObj.get("guaranteed_delivery")); + } catch( NullPointerException npe ) { + this.setGuaranteedDelivery(false); + } + try { + this.setGuaranteedSequence( (boolean) jsonObj.get("guaranteed_sequence")); + } catch( NullPointerException npe ) { + this.setGuaranteedSequence(false); + } + try { + this.setPrivilegedSubscriber((boolean) jsonObj.get("privilegedSubscriber")); + } catch( NullPointerException npe ) { + this.setPrivilegedSubscriber(false); + } JSONObject del = (JSONObject) jsonObj.get("delivery"); this.setDeliveryURL( (String) del.get("url") ); @@ -95,6 +117,8 @@ public class DR_Sub extends DmaapObject { this.setUserpwd( (String) del.get( "password")); this.setUse100((boolean) del.get( "use100")); + + this.setStatus( DmaapObject_Status.VALID ); logger.info( "new DR_Sub returning"); @@ -183,6 +207,29 @@ public class DR_Sub extends DmaapObject { } + public boolean isGuaranteedDelivery() { + return guaranteedDelivery; + } + + public void setGuaranteedDelivery(boolean guaranteedDelivery) { + this.guaranteedDelivery = guaranteedDelivery; + } + + public boolean isGuaranteedSequence() { + return guaranteedSequence; + } + + public void setGuaranteedSequence(boolean guaranteedSequence) { + this.guaranteedSequence = guaranteedSequence; + } + + public boolean isPrivilegedSubscriber() { + return privilegedSubscriber; + } + + public void setPrivilegedSubscriber(boolean privilegedSubscriber) { + this.privilegedSubscriber = privilegedSubscriber; + } public byte[] getBytes(String provApi) { if ( "AT&T".equals(provApi)) { @@ -193,18 +240,21 @@ public class DR_Sub extends DmaapObject { // returns the DR_Sub object in JSON that conforms to ONAP DR Prov Server expectations public String toProvJSON() { // this is the original DR API that was contributed to ONAP - String postJSON = String.format("{\"suspend\": \"%s\", \"delivery\": " - + "{\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\": \"%s\"}" + String postJSON = String.format("{\"suspend\": %s, \"delivery\":" + + "{\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\": %s }" + ", \"metadataOnly\": %s, \"groupid\": \"%s\", \"follow_redirect\": %s " - + "}", - this.suspended, - this.getDeliveryURL(), - this.getUsername(), - this.getUserpwd(), - this.isUse100(), - "false", - "0", - "true"); + + ", \"privilegedSubscriber\": %s " + + "}" + ,this.suspended + ,this.getDeliveryURL() + ,this.getUsername() + ,this.getUserpwd() + ,this.isUse100() + ,"false" + ,"0" + ,"true" + ,this.isPrivilegedSubscriber() + ); logger.info( postJSON ); return postJSON; @@ -225,21 +275,22 @@ public class DR_Sub extends DmaapObject { // TODO: // - introduce Bus Controller API support for these attributes // - store the default values in the DB - String postJSON = String.format("{\"suspend\": \"%s\", \"delivery\": " - + "{\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\": \"%s\"}" + String postJSON = String.format("{\"suspend\": %s, \"delivery\":" + + "{\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\": %s}" + ", \"metadataOnly\": %s, \"groupid\": \"%s\", \"follow_redirect\": %s " - + ", \"guaranteed_delivery\": %s, \"guaranteed_sequence\": %s " - + "}", - this.suspended, - this.getDeliveryURL(), - this.getUsername(), - this.getUserpwd(), - this.isUse100(), - "false", - "0", - "true", - "false", - "false"); + + ", \"guaranteed_delivery\": %s, \"guaranteed_sequence\": %s" + + "}" + ,this.suspended + ,this.getDeliveryURL() + ,this.getUsername() + ,this.getUserpwd() + ,this.isUse100() + ,"false" + ,"0" + ,"true" + ,this.isGuaranteedDelivery() + ,this.isGuaranteedSequence() + ); logger.info( postJSON ); return postJSON; diff --git a/src/main/resources/schema_12.sql b/src/main/resources/schema_12.sql new file mode 100644 index 0000000..7aaab11 --- /dev/null +++ b/src/main/resources/schema_12.sql @@ -0,0 +1,30 @@ +--- +-- ============LICENSE_START======================================================= +-- OpenECOMP - org.onap.dbcapi +-- ================================================================================ +-- Copyright (C) 2017 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========================================================= +--- + + +@alter table dr_sub + + add column guaranteed_delivery boolean, + add column guaranteed_sequence boolean, + add column privileged_subscriber boolean +; + + +update dmaapbc_sch_ver set version = 12 where version = 11; diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java index e2e48cc..480ff07 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java @@ -66,6 +66,9 @@ public class DRSubTest { assertTrue( ! t.isUse100() ); assertTrue( ! t.isSuspended() ); assertTrue( t.getOwner() == null ); + assertTrue( t.isGuaranteedDelivery() == false ); + assertTrue( t.isGuaranteedSequence() == false ); + assertTrue( t.isPrivilegedSubscriber() == false ); } @@ -103,36 +106,48 @@ public class DRSubTest { assertTrue( du.equals( t.getDeliveryURL() ) ); t.setLogURL( lu ); assertTrue( lu.equals( t.getLogURL() ) ); - + boolean v = true; + t.setGuaranteedDelivery( v ); + assertTrue( t.isGuaranteedDelivery() == v ); + t.setGuaranteedSequence(v); + assertTrue( t.isGuaranteedSequence() == v ); + t.setPrivilegedSubscriber(v); + assertTrue( t.isPrivilegedSubscriber() == v ); } @Test - public void test3() { - String json = String.format( "{ \"%s\": \"%s\", \"%s\": false, \"%s\": { \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": \"%s\" }, \"%s\": { \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": true } }", - "subscriber", "owner", - "suspend", - "links", - "feed", "https://feed.onap.org/publish/22", - "self", "https://feed.onap.org/subscriber/44", - "log" , lu, - "delivery" , - "url", du, - "user", un, - "password", up, - "use100" - ); - - - DR_Sub t = new DR_Sub( json ); + public void testJSONfromONAP() { + + + DR_Sub s = new DR_Sub( d, un, up, f, du, lu, u100 ); + String j = s.toProvJSON(); + + DR_Sub t = new DR_Sub( j ); assertTrue( un.equals( t.getUsername() )); assertTrue( up.equals( t.getUserpwd() )); - assertTrue( f.equals( t.getFeedId() )); + //assertTrue( f.equals( t.getFeedId() )); assertTrue( du.equals( t.getDeliveryURL() ) ); - assertTrue( lu.equals( t.getLogURL() ) ); + //assertTrue( lu.equals( t.getLogURL() ) ); assertTrue( ! t.isSuspended() ); - String o = t.toString(); + } + + @Test + public void testJSONfromATT() { + + + DR_Sub s = new DR_Sub( d, un, up, f, du, lu, u100 ); + + DR_Sub t = new DR_Sub( s.toProvJSONforATT() ); + + assertTrue( un.equals( t.getUsername() )); + assertTrue( up.equals( t.getUserpwd() )); + //assertTrue( f.equals( t.getFeedId() )); + assertTrue( du.equals( t.getDeliveryURL() ) ); + // assertTrue( lu.equals( t.getLogURL() ) ); + assertTrue( ! t.isSuspended() ); } + } diff --git a/version.properties b/version.properties index 7674d90..c811740 100644 --- a/version.properties +++ b/version.properties @@ -27,7 +27,7 @@ major=1 minor=0 -patch=22 +patch=23 base_version=${major}.${minor}.${patch} # Release must be completed with git revision # in Jenkins