X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdbcapi%2Fservice%2FMR_ClusterService.java;h=db6389ee0ae55e1e95c5be88a7a82e81088dcee5;hb=c52d9c91d54f7e8b0500cebba00255b3e6b08c13;hp=529723ed31fb25e65df449ab3fa4c2d01a88a96a;hpb=0bff051a842b164b680bc938f4a56db435dd5841;p=dmaap%2Fdbcapi.git diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java b/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java index 529723e..db6389e 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.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,21 +23,35 @@ package org.onap.dmaap.dbcapi.service; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import javax.ws.rs.core.Response.Status; +import org.onap.dmaap.dbcapi.client.MrProvConnection; import org.onap.dmaap.dbcapi.database.DatabaseClass; import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.model.ApiError; import org.onap.dmaap.dbcapi.model.DcaeLocation; import org.onap.dmaap.dbcapi.model.MR_Cluster; +import org.onap.dmaap.dbcapi.model.Topic; import org.onap.dmaap.dbcapi.model.DmaapObject.DmaapObject_Status; +import org.onap.dmaap.dbcapi.service.DcaeLocationService; +import org.onap.dmaap.dbcapi.util.DmaapConfig; public class MR_ClusterService extends BaseLoggingClass { private Map mr_clusters = DatabaseClass.getMr_clusters(); + private boolean multiSite; + + public MR_ClusterService() { + logger.info( "new ClusterService"); + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + multiSite = "true".equalsIgnoreCase(p.getProperty("MR.multisite", "true")); + + } public Map getMR_Clusters() { return mr_clusters; @@ -64,17 +80,39 @@ public class MR_ClusterService extends BaseLoggingClass { return null; } + public MR_Cluster getMr_ClusterByLoc( String loc ) { + return mr_clusters.get( loc ); + } + public List getCentralClusters() { DcaeLocationService locations = new DcaeLocationService(); List result = new ArrayList(); for( MR_Cluster c: mr_clusters.values() ) { - if ( locations.getDcaeLocation(c.getDcaeLocationName()).isCentral() ) { - result.add(c); + try { + if ( locations.getDcaeLocation(c.getDcaeLocationName()).isCentral() ) { + result.add(c); + } + } catch ( NullPointerException npe ) { + logger.warn( "Failed test isCentral for location:" + c.getDcaeLocationName() ); + } + } + return result; + } + + // builds the set of unique cluster groups + public Set getGroups() { + Set result = new HashSet(); + for( MR_Cluster c: mr_clusters.values() ) { + try { + result.add(c.getReplicationGroup()); + } catch ( NullPointerException npe ) { + logger.warn( "Failed to add Group for cluster:" + c.getDcaeLocationName() ); } } return result; } + public MR_Cluster addMr_Cluster( MR_Cluster cluster, ApiError apiError ) { logger.info( "Entry: addMr_Cluster"); MR_Cluster mrc = mr_clusters.get( cluster.getDcaeLocationName() ); @@ -85,11 +123,11 @@ public class MR_ClusterService extends BaseLoggingClass { return null; } cluster.setLastMod(); - cluster.setStatus(DmaapObject_Status.VALID); + cluster.setStatus( addTopicsToCluster( cluster, apiError ) ); mr_clusters.put( cluster.getDcaeLocationName(), cluster ); DcaeLocationService svc = new DcaeLocationService(); DcaeLocation loc = svc.getDcaeLocation( cluster.getDcaeLocationName() ); - if ( loc != null && loc.isCentral() ) { + if ( loc != null && loc.isCentral() && multiSite ) { ApiError resp = TopicService.setBridgeClientPerms( cluster ); if ( ! resp.is2xx() ) { logger.error( "Unable to provision Bridge to " + cluster.getDcaeLocationName() ); @@ -111,6 +149,7 @@ public class MR_ClusterService extends BaseLoggingClass { return null; } cluster.setLastMod(); + cluster.setStatus( addTopicsToCluster( cluster, apiError ) ); mr_clusters.put( cluster.getDcaeLocationName(), cluster ); DcaeLocationService svc = new DcaeLocationService(); DcaeLocation loc = svc.getDcaeLocation( cluster.getDcaeLocationName() ); @@ -119,7 +158,7 @@ public class MR_ClusterService extends BaseLoggingClass { cluster.setLastMod(); cluster.setStatus(DmaapObject_Status.INVALID); mr_clusters.put( cluster.getDcaeLocationName(), cluster ); - } else if ( loc.isCentral() ) { + } else if ( loc.isCentral() && multiSite ) { ApiError resp = TopicService.setBridgeClientPerms( cluster ); if ( ! resp.is2xx() ) { logger.error( "Unable to provision Bridge to " + cluster.getDcaeLocationName() ); @@ -128,6 +167,7 @@ public class MR_ClusterService extends BaseLoggingClass { mr_clusters.put( cluster.getDcaeLocationName(), cluster ); } } + apiError.setCode(200); return cluster; } @@ -144,5 +184,22 @@ public class MR_ClusterService extends BaseLoggingClass { return mr_clusters.remove(key); } - + private DmaapObject_Status addTopicsToCluster( MR_Cluster cluster, ApiError err ){ + + TopicService ts = new TopicService(); + MrProvConnection prov = new MrProvConnection(); + List topics = ts.getAllTopicsWithoutClients(); + for( Topic topic: topics ) { + logger.info( "POST topic " + topic.getFqtn() + " to cluster " + cluster.getFqdn() + " in loc " + cluster.getDcaeLocationName()); + if ( prov.makeTopicConnection(cluster)) { + String resp = prov.doPostTopic(topic, err); + logger.info( "response code: " + err.getCode() ); + if ( ! err.is2xx() && ! (err.getCode() == 409) ) { + return DmaapObject_Status.INVALID; + } + } + } + + return DmaapObject_Status.VALID; + } }