X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdbcapi%2Fservice%2FDmaapService.java;h=3ea44ccc469f0d677a5578c0c42db95c8fdfb103;hb=ece3a625175df4d74d890d67f584560630e9ed33;hp=84368208305b2adab242c3ee0ac87934b3d257f1;hpb=a05efb7b7b3cfc77f5e3fda11e8434834829f56a;p=dmaap%2Fdbcapi.git diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java b/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java index 8436820..3ea44cc 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java @@ -3,6 +3,8 @@ * org.onap.dmaap * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2019 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,22 +23,13 @@ package org.onap.dmaap.dbcapi.service; import java.util.ArrayList; - - - - - - - - - - import org.onap.dmaap.dbcapi.aaf.AafService; import org.onap.dmaap.dbcapi.aaf.DmaapGrant; import org.onap.dmaap.dbcapi.aaf.DmaapPerm; import org.onap.dmaap.dbcapi.aaf.AafService.ServiceType; -import org.onap.dmaap.dbcapi.aaf.authentication.ApiPerms; -import org.onap.dmaap.dbcapi.aaf.database.DatabaseClass; +import org.onap.dmaap.dbcapi.authentication.ApiPerms; +import org.onap.dmaap.dbcapi.authentication.ApiPolicy; +import org.onap.dmaap.dbcapi.database.DatabaseClass; import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum; import org.onap.dmaap.dbcapi.model.ApiError; @@ -51,20 +44,30 @@ public class DmaapService extends BaseLoggingClass { private Singleton dmaapholder = DatabaseClass.getDmaap(); + private static String noEnvironmentPrefix; + - // TODO put these in properties file String topicFactory; // = "org.openecomp.dcae.dmaap.topicFactory"; String topicMgrRole; // = "org.openecomp.dmaapBC.TopicMgr"; - // TODO confirm this is equivalent to dmaap.getTopicNsRoot() so we can retire it - String dcaeTopicNs; // = "org.openecomp.dcae.dmaap"; + private boolean multiSite; public DmaapService() { DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); topicFactory = p.getProperty("MR.TopicFactoryNS", "MR.topicFactoryNS.not.set"); topicMgrRole = p.getProperty("MR.TopicMgrRole", "MR.TopicMgrRole.not.set" ); - dcaeTopicNs = dmaapholder.get().getTopicNsRoot(); + + multiSite = "true".equalsIgnoreCase(p.getProperty("MR.multisite", "true")); + noEnvironmentPrefix = p.getProperty( "AAF.NoEnvironmentPrefix", "org.onap"); + + logger.info( "DmaapService settings: " + + " topicFactory=" + topicFactory + + " topicMgrRole=" + topicMgrRole + + + " multisite=" + multiSite + + " noEnvironmentPrefix=" + noEnvironmentPrefix + ); } @@ -81,11 +84,18 @@ public class DmaapService extends BaseLoggingClass { nd.setLastMod(); dmaapholder.update(nd); - + AafService aaf = new AafService( ServiceType.AAF_Admin); - ApiPerms p = new ApiPerms(); - p.setEnvMap(); - boolean anythingWrong = setTopicMgtPerms( nd, aaf ) || createMmaTopic(); + ApiPolicy apiPolicy = new ApiPolicy(); + if ( apiPolicy.isPermissionClassSet() ) { + ApiPerms p = new ApiPerms(); + p.setEnvMap(); + } + boolean anythingWrong = false; + + if ( multiSite ) { + anythingWrong = setTopicMgtPerms( nd, aaf ) || createMmaTopic(); + } if ( anythingWrong ) { dmaap.setStatus(DmaapObject_Status.INVALID); @@ -118,10 +128,16 @@ public class DmaapService extends BaseLoggingClass { if ( ! dmaap.isStatusValid() || ! nd.getDmaapName().equals(dmaap.getDmaapName()) || dmaap.getVersion().equals( "0") ) { nd.setLastMod(); dmaapholder.update(nd); //need to set this so the following perms will pick up any new vals. - ApiPerms p = new ApiPerms(); - p.setEnvMap(); + //dcaeTopicNs = dmaapholder.get().getTopicNsRoot(); + ApiPolicy apiPolicy = new ApiPolicy(); + if ( apiPolicy.isPermissionClassSet()) { + ApiPerms p = new ApiPerms(); + p.setEnvMap(); + } AafService aaf = new AafService( ServiceType.AAF_Admin); - anythingWrong = setTopicMgtPerms( nd, aaf ) || createMmaTopic(); + if ( multiSite ) { + anythingWrong = setTopicMgtPerms( nd, aaf ) || createMmaTopic(); + } } if ( anythingWrong ) { @@ -142,7 +158,17 @@ public class DmaapService extends BaseLoggingClass { } public String getTopicPerm( String val ) { Dmaap dmaap = dmaapholder.get(); - return dmaap.getTopicNsRoot() + "." + val + ".mr.topic"; + String nsRoot = dmaap.getTopicNsRoot(); + if ( nsRoot == null ) { return null; } + + String t; + // in ONAP Casablanca, we assume no distinction of environments reflected in topic namespace + if ( nsRoot.startsWith(noEnvironmentPrefix) ) { + t = nsRoot + ".mr.topic"; + } else { + t = nsRoot + "." + val + ".mr.topic"; + } + return t; } public String getBridgeAdminFqtn(){ @@ -159,7 +185,7 @@ public class DmaapService extends BaseLoggingClass { private boolean setTopicMgtPerms( Dmaap nd, AafService aaf ){ String[] actions = { "create", "destroy" }; - String instance = ":" + dcaeTopicNs + "." + nd.getDmaapName() + ".mr.topic:" + dcaeTopicNs + "." + nd.getDmaapName(); + String instance = ":" + nd.getTopicNsRoot() + "." + nd.getDmaapName() + ".mr.topic:" + nd.getTopicNsRoot() + "." + nd.getDmaapName(); for( String action : actions ) { @@ -179,7 +205,7 @@ public class DmaapService extends BaseLoggingClass { } } - String t = dcaeTopicNs +"." + nd.getDmaapName() + ".mr.topic"; + String t = nd.getTopicNsRoot() +"." + nd.getDmaapName() + ".mr.topic"; String[] s = { "view", "pub", "sub" }; actions = s; instance = "*"; @@ -204,6 +230,16 @@ public class DmaapService extends BaseLoggingClass { } return false; } + + public boolean testCreateMmaTopic() { + + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + String unit_test = p.getProperty( "UnitTest", "No" ); + if ( unit_test.equals( "Yes" ) ) { + return createMmaTopic(); + } + return false; + } // create the special topic for MMA provisioning. // return true indicating a problem in topic creation, @@ -238,18 +274,20 @@ public class DmaapService extends BaseLoggingClass { clients.add( nClient ); // initialize Topic - Topic mmaTopic = new Topic(); + Topic mmaTopic = new Topic().init(); mmaTopic.setTopicName(dmaap.getBridgeAdminTopic()); mmaTopic.setClients(clients); mmaTopic.setOwner("BusController"); mmaTopic.setTopicDescription("topic reserved for MirrorMaker Administration"); mmaTopic.setTnxEnabled("false"); + mmaTopic.setPartitionCount("1"); // a single partition should guarantee message order + ApiError err = new ApiError(); TopicService svc = new TopicService(); try { @SuppressWarnings("unused") - Topic nTopic = svc.addTopic(mmaTopic, err); + Topic nTopic = svc.addTopic(mmaTopic, err, true); if ( err.is2xx() || err.getCode() == 409 ) { return false; }