diff options
Diffstat (limited to 'grToolkit')
4 files changed, 329 insertions, 401 deletions
diff --git a/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/GrToolkitProvider.java b/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/GrToolkitProvider.java index f0a104de..dc8534be 100755 --- a/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/GrToolkitProvider.java +++ b/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/GrToolkitProvider.java @@ -35,16 +35,15 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Map; import java.util.Properties; import java.util.List; -import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Nonnull; -import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -60,8 +59,6 @@ import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterfa import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.AdminHealthInput; @@ -99,18 +96,19 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataTreeChangeListener { + private static final String APP_NAME = "gr-toolkit"; private static final String PROPERTIES_FILE = System.getenv("SDNC_CONFIG_DIR") + "/gr-toolkit.properties"; private static final String HEALTHY = "HEALTHY"; private static final String FAULTY = "FAULTY"; - private static String AKKA_CONFIG; - private static String JOLOKIA_CLUSTER_PATH; - private static String SHARD_MANAGER_PATH; - private static String SHARD_PATH_TEMPLATE; - private static String CREDENTIALS; - private static String HTTP_PROTOCOL; - private static String SITE_IDENTIFIER = System.getenv("SITE_NAME"); + private static final String VALUE = "value"; + private String akkaConfig; + private String jolokiaClusterPath; + private String shardManagerPath; + private String shardPathTemplate; + private String credentials; + private String httpProtocol; + private String siteIdentifier = System.getenv("SITE_NAME"); private final Logger log = LoggerFactory.getLogger(GrToolkitProvider.class); - private final String appName = "gr-toolkit"; private final ExecutorService executor; protected DataBroker dataBroker; protected NotificationPublishService notificationService; @@ -119,7 +117,7 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT protected DbLibService dbLib; private String member; private ClusterActor self; - private HashMap<String, ClusterActor> members; + private HashMap<String, ClusterActor> memberMap; private SiteConfiguration siteConfiguration; private Properties properties; private DistributedDataStoreInterface configDatastore; @@ -128,7 +126,7 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT RpcProviderRegistry rpcProviderRegistry, DistributedDataStoreInterface configDatastore, DbLibService dbLibService) { - this.log.info("Creating provider for " + appName); + this.log.info("Creating provider for {}", APP_NAME); this.executor = Executors.newFixedThreadPool(1); this.dataBroker = dataBroker; this.notificationService = notificationProviderService; @@ -138,25 +136,19 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT initialize(); } - public void initialize() { - log.info("Initializing provider for " + appName); + private void initialize() { + log.info("Initializing provider for {}", APP_NAME); // Create the top level containers createContainers(); - try { - GrToolkitUtil.loadProperties(); - } catch (Exception e) { - log.error("Caught Exception while trying to load properties file.", e); - } - setProperties(); defineMembers(); rpcRegistration = rpcRegistry.addRpcImplementation(GrToolkitService.class, this); - log.info("Initialization complete for " + appName); + log.info("Initialization complete for {}", APP_NAME); } private void setProperties() { - log.info("Loading properties from " + PROPERTIES_FILE); + log.info("Loading properties from {}", PROPERTIES_FILE); properties = new Properties(); File propertiesFile = new File(PROPERTIES_FILE); if(!propertiesFile.exists()) { @@ -165,19 +157,19 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT } try(FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { properties.load(fileInputStream); - if(!properties.containsKey("site.identifier")) { - properties.put("site.identifier", "Unknown Site"); + if(!properties.containsKey(PropertyKeys.SITE_IDENTIFIER)) { + properties.put(PropertyKeys.SITE_IDENTIFIER, "Unknown Site"); } - String port = "true".equals(properties.getProperty("controller.useSsl").trim()) ? properties.getProperty("controller.port.ssl").trim() : properties.getProperty("controller.port.http").trim(); - HTTP_PROTOCOL = "true".equals(properties.getProperty("controller.useSsl").trim()) ? "https://" : "http://"; - AKKA_CONFIG = properties.getProperty("akka.conf.location").trim(); - JOLOKIA_CLUSTER_PATH = ":" + port + properties.getProperty("mbean.cluster").trim(); - SHARD_MANAGER_PATH = ":" + port + properties.getProperty("mbean.shardManager").trim(); - SHARD_PATH_TEMPLATE = ":" + port + properties.getProperty("mbean.shard.config").trim(); - if(SITE_IDENTIFIER == null || SITE_IDENTIFIER.isEmpty()) { - SITE_IDENTIFIER = properties.getProperty("site.identifier").trim(); + String port = "true".equals(properties.getProperty(PropertyKeys.CONTROLLER_USE_SSL).trim()) ? properties.getProperty(PropertyKeys.CONTROLLER_PORT_SSL).trim() : properties.getProperty(PropertyKeys.CONTROLLER_PORT_HTTP).trim(); + httpProtocol = "true".equals(properties.getProperty(PropertyKeys.CONTROLLER_USE_SSL).trim()) ? "https://" : "http://"; + akkaConfig = properties.getProperty(PropertyKeys.AKKA_CONF_LOCATION).trim(); + jolokiaClusterPath = ":" + port + properties.getProperty(PropertyKeys.MBEAN_CLUSTER).trim(); + shardManagerPath = ":" + port + properties.getProperty(PropertyKeys.MBEAN_SHARD_MANAGER).trim(); + shardPathTemplate = ":" + port + properties.getProperty(PropertyKeys.MBEAN_SHARD_CONFIG).trim(); + if(siteIdentifier == null || siteIdentifier.isEmpty()) { + siteIdentifier = properties.getProperty(PropertyKeys.SITE_IDENTIFIER).trim(); } - CREDENTIALS = properties.getProperty("controller.credentials").trim(); + credentials = properties.getProperty(PropertyKeys.CONTROLLER_CREDENTIALS).trim(); log.info("Loaded properties."); } catch(IOException e) { log.error("Error loading properties.", e); @@ -186,38 +178,29 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT private void defineMembers() { member = configDatastore.getActorContext().getCurrentMemberName().getName(); - log.info("Cluster member: " + member); + log.info("Cluster member: {}", member); - log.info("Parsing akka.conf for cluster members..."); + log.info("Parsing akka.conf for cluster memberMap..."); try { - File akkaConfig = new File(AKKA_CONFIG); - FileReader fileReader = new FileReader(akkaConfig); - BufferedReader bufferedReader = new BufferedReader(fileReader); - String line; - while((line = bufferedReader.readLine()) != null) { - if(line.contains("seed-nodes =")) { - parseSeedNodes(line); - break; + File akkaConfigFile = new File(this.akkaConfig); + try(FileReader fileReader = new FileReader(akkaConfigFile); + BufferedReader bufferedReader = new BufferedReader(fileReader)) { + String line; + while((line = bufferedReader.readLine()) != null) { + if(line.contains("seed-nodes =")) { + parseSeedNodes(line); + break; + } } } - bufferedReader.close(); - fileReader.close(); } catch(IOException e) { log.error("Couldn't load akka", e); } - log.info("self:\n{}", self.toString()); + log.info("self:\n{}", self); } private void createContainers() { - final WriteTransaction t = dataBroker.newReadWriteTransaction(); - try { - CheckedFuture<Void, TransactionCommitFailedException>checkedFuture = t.submit(); - checkedFuture.get(); - log.info("Create Containers succeeded!"); - } catch (InterruptedException | ExecutionException e) { - log.error("Create Containers Failed: " + e); - log.error("context", e); - } + // Replace with MD-SAL write for FailoverStatus } protected void initializeChild() { @@ -226,10 +209,10 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT @Override public void close() throws Exception { - log.info("Closing provider for " + appName); + log.info("Closing provider for {}", APP_NAME); executor.shutdown(); rpcRegistration.close(); - log.info("Successfully closed provider for " + appName); + log.info("Successfully closed provider for {}", APP_NAME); } @Override @@ -239,21 +222,21 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT @Override public ListenableFuture<RpcResult<ClusterHealthOutput>> clusterHealth(ClusterHealthInput input) { - log.info(appName + ":cluster-health invoked."); + log.info("{}:cluster-health invoked.", APP_NAME); getControllerHealth(); return buildClusterHealthOutput("200"); } @Override public ListenableFuture<RpcResult<SiteHealthOutput>> siteHealth(SiteHealthInput input) { - log.info(appName + ":site-health invoked."); + log.info("{}:site-health invoked.", APP_NAME); getControllerHealth(); return buildSiteHealthOutput("200", getAdminHealth(), getDatabaseHealth()); } @Override public ListenableFuture<RpcResult<DatabaseHealthOutput>> databaseHealth(DatabaseHealthInput input) { - log.info(appName + ":database-health invoked."); + log.info("{}:database-health invoked.", APP_NAME); DatabaseHealthOutputBuilder outputBuilder = new DatabaseHealthOutputBuilder(); outputBuilder.setStatus("200"); outputBuilder.setHealth(getDatabaseHealth()); @@ -263,7 +246,7 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT @Override public ListenableFuture<RpcResult<AdminHealthOutput>> adminHealth(AdminHealthInput input) { - log.info(appName + ":admin-health invoked."); + log.info("{}:admin-health invoked.", APP_NAME); AdminHealthOutputBuilder outputBuilder = new AdminHealthOutputBuilder(); outputBuilder.setStatus("200"); outputBuilder.setHealth(getAdminHealth()); @@ -273,41 +256,41 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT @Override public ListenableFuture<RpcResult<HaltAkkaTrafficOutput>> haltAkkaTraffic(HaltAkkaTrafficInput input) { - log.info(appName + ":halt-akka-traffic invoked."); + log.info("{}:halt-akka-traffic invoked.", APP_NAME); HaltAkkaTrafficOutputBuilder outputBuilder = new HaltAkkaTrafficOutputBuilder(); outputBuilder.setStatus("200"); - modifyIpTables(IpTables.Add, input.getNodeInfo().toArray()); + modifyIpTables(IpTables.ADD, input.getNodeInfo().toArray()); return Futures.immediateFuture(RpcResultBuilder.<HaltAkkaTrafficOutput>status(true).withResult(outputBuilder.build()).build()); } @Override public ListenableFuture<RpcResult<ResumeAkkaTrafficOutput>> resumeAkkaTraffic(ResumeAkkaTrafficInput input) { - log.info(appName + ":resume-akka-traffic invoked."); + log.info("{}:resume-akka-traffic invoked.", APP_NAME); ResumeAkkaTrafficOutputBuilder outputBuilder = new ResumeAkkaTrafficOutputBuilder(); outputBuilder.setStatus("200"); - modifyIpTables(IpTables.Delete, input.getNodeInfo().toArray()); + modifyIpTables(IpTables.DELETE, input.getNodeInfo().toArray()); return Futures.immediateFuture(RpcResultBuilder.<ResumeAkkaTrafficOutput>status(true).withResult(outputBuilder.build()).build()); } @Override public ListenableFuture<RpcResult<SiteIdentifierOutput>> siteIdentifier(SiteIdentifierInput input) { - log.info(appName + ":site-identifier invoked."); + log.info("{}:site-identifier invoked.", APP_NAME); SiteIdentifierOutputBuilder outputBuilder = new SiteIdentifierOutputBuilder(); outputBuilder.setStatus("200"); - outputBuilder.setId(SITE_IDENTIFIER); + outputBuilder.setId(siteIdentifier); return Futures.immediateFuture(RpcResultBuilder.<SiteIdentifierOutput>status(true).withResult(outputBuilder.build()).build()); } @Override public ListenableFuture<RpcResult<FailoverOutput>> failover(FailoverInput input) { - log.info(appName + ":failover invoked."); + log.info("{}:failover invoked.", APP_NAME); FailoverOutputBuilder outputBuilder = new FailoverOutputBuilder(); - if(siteConfiguration != SiteConfiguration.Geo) { - log.info("Cannot failover non-Geo site."); - outputBuilder.setMessage("Failover aborted. This is not a Geo configuration."); + if(siteConfiguration != SiteConfiguration.GEO) { + log.info("Cannot failover non-GEO site."); + outputBuilder.setMessage("Failover aborted. This is not a GEO configuration."); outputBuilder.setStatus("400"); return Futures.immediateFuture(RpcResultBuilder.<FailoverOutput>status(true).withResult(outputBuilder.build()).build()); } @@ -319,41 +302,91 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT getControllerHealth(); log.info("Determining active site..."); - for(String key : members.keySet()) { - if(members.get(key).isVoting()) { - activeSite.add(members.get(key)); - log.debug("Active Site member: " + key); + for(Map.Entry<String, ClusterActor> entry : memberMap.entrySet()) { + String key = entry.getKey(); + ClusterActor clusterActor = entry.getValue(); + if(clusterActor.isVoting()) { + activeSite.add(clusterActor); + log.debug("Active Site member: {}", key); } else { - standbySite.add(members.get(key)); - log.debug("Standby Site member: " + key); + standbySite.add(clusterActor); + log.debug("Standby Site member: {}", key); } } - String port = "true".equals(properties.getProperty("controller.useSsl")) ? properties.getProperty("controller.port.ssl") : properties.getProperty("controller.port.http"); + String port = "true".equals(properties.getProperty(PropertyKeys.CONTROLLER_USE_SSL)) ? properties.getProperty(PropertyKeys.CONTROLLER_PORT_SSL) : properties.getProperty(PropertyKeys.CONTROLLER_PORT_HTTP); if(Boolean.parseBoolean(input.getBackupData())) { - log.info("Backing up data..."); - for(ClusterActor actor : activeSite) { - try { - // Schedule backup - log.info("Scheduling backup for: " + actor.getNode()); - getRequestContent(HTTP_PROTOCOL + actor.getNode() + ":" + port + "/restconf/operations/data-export-import:schedule-export", HttpMethod.Post, ""); - try { - // Move data offsite - log.info("Backing up data for: " + actor.getNode()); - getRequestContent(HTTP_PROTOCOL + actor.getNode() + ":" + port + "/restconf/operations/daexim-offsite-backup:backup-data", HttpMethod.Post); - } catch(IOException e) { - log.error("Error backing up data.", e); - throw e; - } - } - catch(IOException e) { - log.error("Error exporting MD-SAL data.", e); + backupMdSal(activeSite, port); + } + + if(!changeClusterVoting(outputBuilder, activeSite, standbySite, port)) + return Futures.immediateFuture(RpcResultBuilder.<FailoverOutput>status(true).withResult(outputBuilder.build()).build()); + + if(Boolean.parseBoolean(input.getIsolate())) { + isolateSiteFromCluster(activeSite, standbySite, port); + + if(Boolean.parseBoolean(input.getDownUnreachable())) { + downUnreachableNodes(activeSite, standbySite, port); + } + } + + log.info("{}:failover complete.", APP_NAME); + + outputBuilder.setMessage("Failover complete."); + outputBuilder.setStatus("200"); + return Futures.immediateFuture(RpcResultBuilder.<FailoverOutput>status(true).withResult(outputBuilder.build()).build()); + } + + private void isolateSiteFromCluster(ArrayList<ClusterActor> activeSite, ArrayList<ClusterActor> standbySite, String port) { + log.info("Halting Akka traffic..."); + for(ClusterActor actor : standbySite) { + try { + log.info("Halting Akka traffic for: {}", actor.getNode()); + // Build JSON with activeSite actor Node and actor AkkaPort + JSONObject akkaInput = new JSONObject(); + JSONObject inputBlock = new JSONObject(); + JSONArray votingStateArray = new JSONArray(); + JSONObject nodeInfo; + for(ClusterActor node : activeSite) { + nodeInfo = new JSONObject(); + nodeInfo.put("node", node.getNode()); + nodeInfo.put("port", node.getAkkaPort()); + votingStateArray.put(nodeInfo); } + inputBlock.put("node-info", votingStateArray); + akkaInput.put("input", inputBlock); + getRequestContent(httpProtocol + actor.getNode() + ":" + port + "/restconf/operations/gr-toolkit:halt-akka-traffic", HttpMethod.POST, akkaInput.toString()); + } catch(IOException e) { + log.error("Could not halt Akka traffic for: " + actor.getNode(), e); } } + } + private void downUnreachableNodes(ArrayList<ClusterActor> activeSite, ArrayList<ClusterActor> standbySite, String port) { + log.info("Setting site unreachable..."); + JSONObject jolokiaInput = new JSONObject(); + jolokiaInput.put("type", "EXEC"); + jolokiaInput.put("mbean", "akka:type=Cluster"); + jolokiaInput.put("operation", "down"); + JSONArray arguments = new JSONArray(); + for(ClusterActor actor : activeSite) { + // Build Jolokia input + // May need to change from akka port to actor.getAkkaPort() + arguments.put("akka.tcp://opendaylight-cluster-data@" + actor.getNode() + ":" + properties.getProperty(PropertyKeys.CONTROLLER_PORT_AKKA)); + } + jolokiaInput.put("arguments", arguments); + log.debug("{}", jolokiaInput); + try { + log.info("Setting nodes unreachable"); + getRequestContent(httpProtocol + standbySite.get(0).getNode() + ":" + port + "/jolokia", HttpMethod.POST, jolokiaInput.toString()); + } catch(IOException e) { + log.error("Error setting nodes unreachable", e); + } + } + + private boolean changeClusterVoting(FailoverOutputBuilder outputBuilder, ArrayList<ClusterActor> activeSite, ArrayList<ClusterActor> standbySite, String port) { log.info("Changing voting for all shards to standby site..."); try { JSONObject votingInput = new JSONObject(); @@ -374,68 +407,35 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT } inputBlock.put("member-voting-state", votingStateArray); votingInput.put("input", inputBlock); - log.debug(votingInput.toString(2)); + log.debug("{}", votingInput); // Change voting all shards - getRequestContent(HTTP_PROTOCOL + self.getNode() + ":" + port + "/restconf/operations/cluster-admin:change-member-voting-states-for-all-shards", HttpMethod.Post, votingInput.toString()); + getRequestContent(httpProtocol + self.getNode() + ":" + port + "/restconf/operations/cluster-admin:change-member-voting-states-for-all-shards", HttpMethod.POST, votingInput.toString()); } catch(IOException e) { log.error("Changing voting", e); outputBuilder.setMessage("Failover aborted. Failed to change voting."); outputBuilder.setStatus("500"); - return Futures.immediateFuture(RpcResultBuilder.<FailoverOutput>status(true).withResult(outputBuilder.build()).build()); + return false; } + return true; + } - if(Boolean.parseBoolean(input.getIsolate())) { - log.info("Halting Akka traffic..."); - for(ClusterActor actor : standbySite) { - try { - log.info("Halting Akka traffic for: " + actor.getNode()); - // Build JSON with activeSite actor.getNode() and actor.getAkkaPort(); - JSONObject akkaInput = new JSONObject(); - JSONObject inputBlock = new JSONObject(); - JSONArray votingStateArray = new JSONArray(); - JSONObject nodeInfo; - for(ClusterActor node : activeSite) { - nodeInfo = new JSONObject(); - nodeInfo.put("node", node.getNode()); - nodeInfo.put("port", node.getAkkaPort()); - votingStateArray.put(nodeInfo); - } - inputBlock.put("node-info", votingStateArray); - akkaInput.put("input", inputBlock); - getRequestContent(HTTP_PROTOCOL + actor.getNode() + ":" + port + "/restconf/operations/gr-toolkit:halt-akka-traffic", HttpMethod.Post, akkaInput.toString()); - } catch(IOException e) { - log.error("Could not halt Akka traffic for: " + actor.getNode(), e); - } - } - - if(Boolean.parseBoolean(input.getDownUnreachable())) { - log.info("Setting site unreachable..."); - JSONObject jolokiaInput = new JSONObject(); - jolokiaInput.put("type", "EXEC"); - jolokiaInput.put("mbean", "akka:type=Cluster"); - jolokiaInput.put("operation", "down"); - JSONArray arguments = new JSONArray(); - for(ClusterActor actor : activeSite) { - // Build Jolokia input - //TODO: May need to change from akka port to actor.getAkkaPort() - arguments.put("akka.tcp://opendaylight-cluster-data@" + actor.getNode() + ":" + properties.getProperty("controller.port.akka")); - } - jolokiaInput.put("arguments", arguments); - log.debug(jolokiaInput.toString(2)); - try { - log.info("Setting nodes unreachable"); - getRequestContent(HTTP_PROTOCOL + standbySite.get(0).getNode() + ":" + port + "/jolokia", HttpMethod.Post, jolokiaInput.toString()); - } catch(IOException e) { - log.error("Error setting nodes unreachable", e); - } + private void backupMdSal(ArrayList<ClusterActor> activeSite, String port) { + log.info("Backing up data..."); + try { + log.info("Scheduling backup for: {}", activeSite.get(0).getNode()); + getRequestContent(httpProtocol + activeSite.get(0).getNode() + ":" + port + "/restconf/operations/data-export-import:schedule-export", HttpMethod.POST, "{ \"input\": { \"run-at\": \"30\" } }"); + } catch(IOException e) { + log.error("Error backing up MD-SAL", e); + } + for(ClusterActor actor : activeSite) { + try { + // Move data offsite + log.info("Backing up data for: {}", actor.getNode()); + getRequestContent(httpProtocol + actor.getNode() + ":" + port + "/restconf/operations/daexim-offsite-backup:backup-data", HttpMethod.POST); + } catch(IOException e) { + log.error("Error backing up data.", e); } } - - log.info(appName + ":failover complete."); - - outputBuilder.setMessage("Failover complete."); - outputBuilder.setStatus("200"); - return Futures.immediateFuture(RpcResultBuilder.<FailoverOutput>status(true).withResult(outputBuilder.build()).build()); } private ListenableFuture<RpcResult<ClusterHealthOutput>> buildClusterHealthOutput(String statusCode) { @@ -445,33 +445,31 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT int site1Health = 0; int site2Health = 0; - for(String key : members.keySet()) { - if(members.get(key).isUp() && !members.get(key).isUnreachable()) { - if(ClusterActor.SITE_1.equals(members.get(key).getSite())) + for(Map.Entry<String, ClusterActor> entry : memberMap.entrySet()) { + ClusterActor clusterActor = entry.getValue(); + if(clusterActor.isUp() && !clusterActor.isUnreachable()) { + if(ClusterActor.SITE_1.equals(clusterActor.getSite())) site1Health++; - else if(ClusterActor.SITE_2.equals(members.get(key).getSite())) + else if(ClusterActor.SITE_2.equals(clusterActor.getSite())) site2Health++; } - outputBuilder.getMembers().add(new MemberBuilder(members.get(key)).build()); + outputBuilder.getMembers().add(new MemberBuilder(clusterActor).build()); } - if(siteConfiguration == SiteConfiguration.Solo) { + if(siteConfiguration == SiteConfiguration.SOLO) { + outputBuilder.setSite1Health(HEALTHY); + } + else if(site1Health > 1) { outputBuilder.setSite1Health(HEALTHY); } else { - if(site1Health > 1) { - outputBuilder.setSite1Health(HEALTHY); - } - else { - outputBuilder.setSite1Health(FAULTY); - } + outputBuilder.setSite1Health(FAULTY); } - if(siteConfiguration == SiteConfiguration.Geo) { - if(site2Health > 1) { - outputBuilder.setSite2Health(HEALTHY); - } - else { - outputBuilder.setSite2Health(FAULTY); - } + + if(siteConfiguration == SiteConfiguration.GEO && site2Health > 1) { + outputBuilder.setSite2Health(HEALTHY); + } + else if(siteConfiguration == SiteConfiguration.GEO) { + outputBuilder.setSite2Health(FAULTY); } RpcResult<ClusterHealthOutput> rpcResult = RpcResultBuilder.<ClusterHealthOutput>status(true).withResult(outputBuilder.build()).build(); @@ -483,21 +481,22 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT outputBuilder.setStatus(statusCode); outputBuilder.setSites((List) new ArrayList<Site>()); - if(siteConfiguration != SiteConfiguration.Geo) { + if(siteConfiguration != SiteConfiguration.GEO) { int healthyODLs = 0; SitesBuilder builder = new SitesBuilder(); - for(String key : members.keySet()) { - if(members.get(key).isUp() && !members.get(key).isUnreachable()) { + for(Map.Entry<String, ClusterActor> entry : memberMap.entrySet()) { + ClusterActor clusterActor = entry.getValue(); + if(clusterActor.isUp() && !clusterActor.isUnreachable()) { healthyODLs++; } } - if(siteConfiguration != SiteConfiguration.Solo) { + if(siteConfiguration != SiteConfiguration.SOLO) { builder.setHealth(HEALTHY); builder.setRole("ACTIVE"); - builder.setId(SITE_IDENTIFIER); + builder.setId(siteIdentifier); } else { - builder = getSitesBuilder(healthyODLs, true, HEALTHY.equals(adminHealth), HEALTHY.equals(databaseHealth), SITE_IDENTIFIER); + builder = getSitesBuilder(healthyODLs, true, HEALTHY.equals(adminHealth), HEALTHY.equals(databaseHealth), siteIdentifier); } outputBuilder.getSites().add(builder.build()); } @@ -510,65 +509,69 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT boolean crossSiteAdminHealthy = false; boolean crossSiteDbHealthy = false; String crossSiteIdentifier = "UNKNOWN_SITE"; - String port = "true".equals(properties.getProperty("controller.useSsl")) ? properties.getProperty("controller.port.ssl") : properties.getProperty("controller.port.http"); + String port = "true".equals(properties.getProperty(PropertyKeys.CONTROLLER_USE_SSL)) ? properties.getProperty(PropertyKeys.CONTROLLER_PORT_SSL) : properties.getProperty(PropertyKeys.CONTROLLER_PORT_HTTP); if(isSite1()) { // Make calls over to site 2 healthchecks - for(String key : members.keySet()) { - if(members.get(key).isUp() && !members.get(key).isUnreachable()) { - if(ClusterActor.SITE_1.equals(members.get(key).getSite())) { + for(Map.Entry<String, ClusterActor> entry : memberMap.entrySet()) { + ClusterActor clusterActor = entry.getValue(); + if(clusterActor.isUp() && !clusterActor.isUnreachable()) { + if(ClusterActor.SITE_1.equals(clusterActor.getSite())) { site1HealthyODLs++; - if(members.get(key).isVoting()) { + if(clusterActor.isVoting()) { site1Voting = true; } } else { site2HealthyODLs++; - if(members.get(key).isVoting()) { + if(clusterActor.isVoting()) { site2Voting = true; } if(!performedCrossSiteHealthCheck) { try { - String content = getRequestContent(HTTP_PROTOCOL + members.get(key).getNode() + ":" + port + "/restconf/operations/gr-toolkit:site-identifier", HttpMethod.Post); + String content = getRequestContent(httpProtocol + clusterActor.getNode() + ":" + port + "/restconf/operations/gr-toolkit:site-identifier", HttpMethod.POST); crossSiteIdentifier = new JSONObject(content).getJSONObject("output").getString("id"); - crossSiteDbHealthy = crossSiteHealthRequest(HTTP_PROTOCOL + members.get(key).getNode() + ":" + port + "/restconf/operations/gr-toolkit:database-health"); - crossSiteAdminHealthy = crossSiteHealthRequest(HTTP_PROTOCOL + members.get(key).getNode() + ":" + port + "/restconf/operations/gr-toolkit:admin-health"); + crossSiteDbHealthy = crossSiteHealthRequest(httpProtocol + clusterActor.getNode() + ":" + port + "/restconf/operations/gr-toolkit:database-health"); + crossSiteAdminHealthy = crossSiteHealthRequest(httpProtocol + clusterActor.getNode() + ":" + port + "/restconf/operations/gr-toolkit:admin-health"); performedCrossSiteHealthCheck = true; } catch(Exception e) { - log.error("Cannot get site identifier from " + members.get(key).getNode(), e); + log.info("Cannot get site identifier from {}", clusterActor.getNode()); + log.error("Site Health Error", e); } } } } } - SitesBuilder builder = getSitesBuilder(site1HealthyODLs, site1Voting, HEALTHY.equals(adminHealth), HEALTHY.equals(databaseHealth), SITE_IDENTIFIER); + SitesBuilder builder = getSitesBuilder(site1HealthyODLs, site1Voting, HEALTHY.equals(adminHealth), HEALTHY.equals(databaseHealth), siteIdentifier); outputBuilder.getSites().add(builder.build()); builder = getSitesBuilder(site2HealthyODLs, site2Voting, crossSiteAdminHealthy, crossSiteDbHealthy, crossSiteIdentifier); outputBuilder.getSites().add(builder.build()); } else { // Make calls over to site 1 healthchecks - for(String key : members.keySet()) { - if(members.get(key).isUp() && !members.get(key).isUnreachable()) { - if(ClusterActor.SITE_1.equals(members.get(key).getSite())) { + for(Map.Entry<String, ClusterActor> entry : memberMap.entrySet()) { + ClusterActor clusterActor = entry.getValue(); + if(clusterActor.isUp() && !clusterActor.isUnreachable()) { + if(ClusterActor.SITE_1.equals(clusterActor.getSite())) { site1HealthyODLs++; - if(members.get(key).isVoting()) { + if(clusterActor.isVoting()) { site1Voting = true; } if(!performedCrossSiteHealthCheck) { try { - String content = getRequestContent(HTTP_PROTOCOL + members.get(key).getNode() + ":" + port + "/restconf/operations/gr-toolkit:site-identifier", HttpMethod.Post); + String content = getRequestContent(httpProtocol + clusterActor.getNode() + ":" + port + "/restconf/operations/gr-toolkit:site-identifier", HttpMethod.POST); crossSiteIdentifier = new JSONObject(content).getJSONObject("output").getString("id"); - crossSiteDbHealthy = crossSiteHealthRequest(HTTP_PROTOCOL + members.get(key).getNode() + ":" + port + "/restconf/operations/gr-toolkit:database-health"); - crossSiteAdminHealthy = crossSiteHealthRequest(HTTP_PROTOCOL + members.get(key).getNode() + ":" + port + "/restconf/operations/gr-toolkit:admin-health"); + crossSiteDbHealthy = crossSiteHealthRequest(httpProtocol + clusterActor.getNode() + ":" + port + "/restconf/operations/gr-toolkit:database-health"); + crossSiteAdminHealthy = crossSiteHealthRequest(httpProtocol + clusterActor.getNode() + ":" + port + "/restconf/operations/gr-toolkit:admin-health"); performedCrossSiteHealthCheck = true; } catch(Exception e) { - log.error("Cannot get site identifier from " + members.get(key).getNode(), e); + log.info("Cannot get site identifier from {}", clusterActor.getNode()); + log.error("Site Health Error", e); } } } else { site2HealthyODLs++; - if(members.get(key).isVoting()) { + if(clusterActor.isVoting()) { site2Voting = true; } } @@ -577,7 +580,7 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT // Build Output SitesBuilder builder = getSitesBuilder(site1HealthyODLs, site1Voting, crossSiteAdminHealthy, crossSiteDbHealthy, crossSiteIdentifier); outputBuilder.getSites().add(builder.build()); - builder = getSitesBuilder(site2HealthyODLs, site2Voting, HEALTHY.equals(adminHealth), HEALTHY.equals(databaseHealth), SITE_IDENTIFIER); + builder = getSitesBuilder(site2HealthyODLs, site2Voting, HEALTHY.equals(adminHealth), HEALTHY.equals(databaseHealth), siteIdentifier); outputBuilder.getSites().add(builder.build()); } } @@ -592,15 +595,15 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT builder.setHealth(HEALTHY); } else { - log.warn(siteIdentifier + " Healthy ODLs: " + siteHealthyODLs); + log.warn("{} Healthy ODLs: {}", siteIdentifier, siteHealthyODLs); builder.setHealth(FAULTY); } if(!adminHealthy) { - log.warn(siteIdentifier + " Admin Health: " + FAULTY); + log.warn("{} Admin Health: {}", siteIdentifier, FAULTY); builder.setHealth(FAULTY); } if(!dbHealthy) { - log.warn(siteIdentifier + " Database Health: " + FAULTY); + log.warn("{} Database Health: {}", siteIdentifier, FAULTY); builder.setHealth(FAULTY); } if(siteVoting) { @@ -616,21 +619,21 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT private boolean isSite1() { int memberNumber = Integer.parseInt(member.split("-")[1]); boolean isSite1 = memberNumber < 4; - log.info("isSite1(): " + isSite1); + log.info("isSite1(): {}", isSite1); return isSite1; } private void parseSeedNodes(String line) { - members = new HashMap<>(); - line = line.substring(line.indexOf("[\""), line.indexOf("]")); + memberMap = new HashMap<>(); + line = line.substring(line.indexOf("[\""), line.indexOf(']')); String[] splits = line.split(","); for(int ndx = 0; ndx < splits.length; ndx++) { String nodeName = splits[ndx]; - int delimLocation = nodeName.indexOf("@"); - String port = nodeName.substring(splits[ndx].indexOf(":", delimLocation) + 1, splits[ndx].indexOf("\"", splits[ndx].indexOf(":"))); - splits[ndx] = nodeName.substring(delimLocation + 1, splits[ndx].indexOf(":", delimLocation)); - log.info("Adding node: " + splits[ndx] + ":" + port); + int delimLocation = nodeName.indexOf('@'); + String port = nodeName.substring(splits[ndx].indexOf(':', delimLocation) + 1, splits[ndx].indexOf('"', splits[ndx].indexOf(':'))); + splits[ndx] = nodeName.substring(delimLocation + 1, splits[ndx].indexOf(':', delimLocation)); + log.info("Adding node: {}:{}", splits[ndx], port); ClusterActor clusterActor = new ClusterActor(); clusterActor.setNode(splits[ndx]); clusterActor.setAkkaPort(port); @@ -645,44 +648,44 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT if(member.equals(clusterActor.getMember())) { self = clusterActor; } - members.put(clusterActor.getNode(), clusterActor); - log.info(clusterActor.toString()); + memberMap.put(clusterActor.getNode(), clusterActor); + log.info("{}", clusterActor); } - if(members.size() == 1) { + if(memberMap.size() == 1) { log.info("1 member found. This is a solo environment."); - siteConfiguration = SiteConfiguration.Solo; + siteConfiguration = SiteConfiguration.SOLO; } - else if(members.size() == 3) { + else if(memberMap.size() == 3) { log.info("This is a single site."); - siteConfiguration = SiteConfiguration.Single; + siteConfiguration = SiteConfiguration.SINGLE; } - else if(members.size() == 6) { + else if(memberMap.size() == 6) { log.info("This is a georedundant site."); - siteConfiguration = SiteConfiguration.Geo; + siteConfiguration = SiteConfiguration.GEO; } } private void getMemberStatus(ClusterActor clusterActor) throws IOException { - log.info("Getting member status for " + clusterActor.getNode()); - String content = getRequestContent(HTTP_PROTOCOL + clusterActor.getNode() + JOLOKIA_CLUSTER_PATH, HttpMethod.Get); + log.info("Getting member status for {}", clusterActor.getNode()); + String content = getRequestContent(httpProtocol + clusterActor.getNode() + jolokiaClusterPath, HttpMethod.GET); try { JSONObject responseJson = new JSONObject(content); - JSONObject responseValue = responseJson.getJSONObject("value"); + JSONObject responseValue = responseJson.getJSONObject(VALUE); clusterActor.setUp("Up".equals(responseValue.getString("MemberStatus"))); clusterActor.setUnreachable(false); } catch(JSONException e) { - log.error("Error parsing response from " + clusterActor.getNode(), e); + log.error("Error parsing response from {}", clusterActor.getNode(), e); clusterActor.setUp(false); clusterActor.setUnreachable(true); } } private void getShardStatus(ClusterActor clusterActor) throws IOException { - log.info("Getting shard status for " + clusterActor.getNode()); - String content = getRequestContent(HTTP_PROTOCOL + clusterActor.getNode() + SHARD_MANAGER_PATH, HttpMethod.Get); + log.info("Getting shard status for {}", clusterActor.getNode()); + String content = getRequestContent(httpProtocol + clusterActor.getNode() + shardManagerPath, HttpMethod.GET); try { - JSONObject responseValue = new JSONObject(content).getJSONObject("value"); + JSONObject responseValue = new JSONObject(content).getJSONObject(VALUE); JSONArray shardList = responseValue.getJSONArray("LocalShards"); String pattern = "-config$"; @@ -692,8 +695,8 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT String configShardName = shardList.getString(ndx); m = r.matcher(configShardName); String operationalShardName = m.replaceFirst("-operational"); - String shardConfigPath = String.format(SHARD_PATH_TEMPLATE, configShardName); - String shardOperationalPath = String.format(SHARD_PATH_TEMPLATE, operationalShardName).replace("Config", "Operational"); + String shardConfigPath = String.format(shardPathTemplate, configShardName); + String shardOperationalPath = String.format(shardPathTemplate, operationalShardName).replace("Config", "Operational"); extractShardInfo(clusterActor, configShardName, shardConfigPath); extractShardInfo(clusterActor, operationalShardName, shardOperationalPath); } @@ -703,13 +706,13 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT } private void extractShardInfo(ClusterActor clusterActor, String shardName, String shardPath) throws IOException { - log.info("Extracting shard info for " + shardName); - log.debug("Pulling config info for " + shardName + " from: " + shardPath); - String content = getRequestContent(HTTP_PROTOCOL + clusterActor.getNode() + shardPath, HttpMethod.Get); - log.debug("Response: " + content); + log.info("Extracting shard info for {}", shardName); + log.debug("Pulling config info for {} from: {}", shardName, shardPath); + String content = getRequestContent(httpProtocol + clusterActor.getNode() + shardPath, HttpMethod.GET); + log.debug("Response: {}", content); try { - JSONObject shardValue = new JSONObject(content).getJSONObject("value"); + JSONObject shardValue = new JSONObject(content).getJSONObject(VALUE); clusterActor.setVoting(shardValue.getBoolean("Voting")); if(shardValue.getString("PeerAddresses").length() > 0) { clusterActor.getReplicaShards().add(shardName); @@ -735,74 +738,72 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT } private void getControllerHealth() { - ClusterActor clusterActor; - for(String key : members.keySet()) { + for(Map.Entry<String, ClusterActor> entry : memberMap.entrySet()) { + ClusterActor clusterActor = entry.getValue(); + String key = entry.getKey(); try { - clusterActor = members.get(key); // First flush out the old values clusterActor.flush(); - log.info("Gathering info for " + clusterActor.getNode()); + log.info("Gathering info for {}", clusterActor.getNode()); getMemberStatus(clusterActor); getShardStatus(clusterActor); - log.info("MemberInfo:\n" + clusterActor.toString()); + log.info("MemberInfo:\n{}", clusterActor); } catch(IOException e) { log.error("Connection Error", e); - members.get(key).setUnreachable(true); - members.get(key).setUp(false); - log.info("MemberInfo:\n" + members.get(key).toString()); + memberMap.get(key).setUnreachable(true); + memberMap.get(key).setUp(false); + log.info("MemberInfo:\n{}", memberMap.get(key)); } } } private void modifyIpTables(IpTables task, Object[] nodeInfo) { log.info("Modifying IPTables rules..."); - switch(task) - { - case Add: - for(Object node : nodeInfo) { - org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.halt.akka.traffic.input.NodeInfo n = - (org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.halt.akka.traffic.input.NodeInfo) node; - log.info("Isolating " + n.getNode()); - executeCommand(String.format("sudo /sbin/iptables -A INPUT -p tcp --destination-port %s -j DROP -s %s", properties.get("controller.port.akka"), n.getNode())); - executeCommand(String.format("sudo /sbin/iptables -A OUTPUT -p tcp --destination-port %s -j DROP -s %s", n.getPort(), n.getNode())); - } - break; - case Delete: - for(Object node : nodeInfo) { - org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.resume.akka.traffic.input.NodeInfo n = - (org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.resume.akka.traffic.input.NodeInfo) node; - log.info("De-isolating " + n.getNode()); - executeCommand(String.format("sudo /sbin/iptables -D INPUT -p tcp --destination-port %s -j DROP -s %s", properties.get("controller.port.akka"), n.getNode())); - executeCommand(String.format("sudo /sbin/iptables -D OUTPUT -p tcp --destination-port %s -j DROP -s %s", n.getPort(), n.getNode())); - } - break; + if(task == IpTables.ADD) { + for(Object node : nodeInfo) { + org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.halt.akka.traffic.input.NodeInfo n = + (org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.halt.akka.traffic.input.NodeInfo) node; + log.info("Isolating {}", n.getNode()); + executeCommand(String.format("sudo /sbin/iptables -A INPUT -p tcp --destination-port %s -j DROP -s %s", properties.get(PropertyKeys.CONTROLLER_PORT_AKKA), n.getNode())); + executeCommand(String.format("sudo /sbin/iptables -A OUTPUT -p tcp --destination-port %s -j DROP -s %s", n.getPort(), n.getNode())); + } + + } else if(task == IpTables.DELETE) { + for(Object node : nodeInfo) { + org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.resume.akka.traffic.input.NodeInfo n = + (org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.resume.akka.traffic.input.NodeInfo) node; + log.info("De-isolating {}", n.getNode()); + executeCommand(String.format("sudo /sbin/iptables -D INPUT -p tcp --destination-port %s -j DROP -s %s", properties.get(PropertyKeys.CONTROLLER_PORT_AKKA), n.getNode())); + executeCommand(String.format("sudo /sbin/iptables -D OUTPUT -p tcp --destination-port %s -j DROP -s %s", n.getPort(), n.getNode())); + } + } executeCommand("sudo /sbin/iptables -L"); } private void executeCommand(String command) { - log.info("Executing command: " + command); + log.info("Executing command: {}", command); String[] cmd = command.split(" "); try { Process p = Runtime.getRuntime().exec(cmd); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(p.getInputStream())); String inputLine; - StringBuffer content = new StringBuffer(); + StringBuilder content = new StringBuilder(); while((inputLine = bufferedReader.readLine()) != null) { content.append(inputLine); } bufferedReader.close(); - log.info(content.toString()); + log.info("{}", content); } catch(IOException e) { log.error("Error executing command", e); } } private boolean crossSiteHealthRequest(String path) throws IOException { - String content = getRequestContent(path, HttpMethod.Post); + String content = getRequestContent(path, HttpMethod.POST); try { JSONObject responseJson = new JSONObject(content); - JSONObject responseValue = responseJson.getJSONObject("value"); + JSONObject responseValue = responseJson.getJSONObject(VALUE); return HEALTHY.equals(responseValue.getString("health")); } catch(JSONException e) { log.error("Error parsing JSON", e); @@ -811,13 +812,13 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT } private String getAdminHealth() { - String protocol = "true".equals(properties.getProperty("adm.useSsl")) ? "https://" : "http://"; - String port = "true".equals(properties.getProperty("adm.useSsl")) ? properties.getProperty("adm.port.ssl") : properties.getProperty("adm.port.http"); - String path = protocol + properties.getProperty("adm.fqdn") + ":" + port + properties.getProperty("adm.healthcheck"); - log.info("Requesting healthcheck from " + path); + String protocol = "true".equals(properties.getProperty(PropertyKeys.ADM_USE_SSL)) ? "https://" : "http://"; + String port = "true".equals(properties.getProperty(PropertyKeys.ADM_USE_SSL)) ? properties.getProperty(PropertyKeys.ADM_PORT_SSL) : properties.getProperty(PropertyKeys.ADM_PORT_HTTP); + String path = protocol + properties.getProperty(PropertyKeys.ADM_FQDN) + ":" + port + properties.getProperty(PropertyKeys.ADM_HEALTHCHECK); + log.info("Requesting healthcheck from {}", path); try { - int response = getRequestStatus(path, HttpMethod.Get); - log.info("Response: " + response); + int response = getRequestStatus(path, HttpMethod.GET); + log.info("Response: {}", response); if(response == 200) return HEALTHY; return FAULTY; @@ -830,9 +831,9 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT private String getDatabaseHealth() { log.info("Determining database health..."); try { - log.info("DBLib isActive(): " + dbLib.isActive()); - log.info("DBLib isReadOnly(): " + dbLib.getConnection().isReadOnly()); - log.info("DBLib isClosed(): " + dbLib.getConnection().isClosed()); + log.info("DBLib isActive(): {}", dbLib.isActive()); + log.info("DBLib isReadOnly(): {}", dbLib.getConnection().isReadOnly()); + log.info("DBLib isClosed(): {}", dbLib.getConnection().isClosed()); if(!dbLib.isActive() || dbLib.getConnection().isClosed() || dbLib.getConnection().isReadOnly()) { log.warn("Database is FAULTY"); return FAULTY; @@ -862,7 +863,7 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; - StringBuffer content = new StringBuffer(); + StringBuilder content = new StringBuilder(); while((inputLine = bufferedReader.readLine()) != null) { content.append(inputLine); } @@ -884,7 +885,7 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT sendPayload(input, connection); } int response = connection.getResponseCode(); - log.info("Received " + response + " response code from " + path); + log.info("Received {} response code from {}", response, path); connection.disconnect(); return response; } @@ -903,9 +904,9 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT } private HttpURLConnection getConnection(String host) throws IOException { - log.info("Getting connection to: " + host); + log.info("Getting connection to: {}", host); URL url = new URL(host); - String auth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(CREDENTIALS.getBytes()); + String auth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(credentials.getBytes()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.addRequestProperty("Authorization", auth); connection.setRequestProperty("Connection", "keep-alive"); @@ -914,19 +915,19 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT } private enum IpTables { - Add, - Delete + ADD, + DELETE } private enum SiteConfiguration { - Solo, - Single, - Geo + SOLO, + SINGLE, + GEO } private enum HttpMethod { - Get("GET"), - Post("POST"); + GET("GET"), + POST("POST"); private String method; HttpMethod(String method) { @@ -936,4 +937,22 @@ public class GrToolkitProvider implements AutoCloseable, GrToolkitService, DataT return method; } } + + private class PropertyKeys { + static final String SITE_IDENTIFIER = "site.identifier"; + static final String CONTROLLER_USE_SSL = "controller.useSsl"; + static final String CONTROLLER_PORT_SSL = "controller.port.ssl"; + static final String CONTROLLER_PORT_HTTP = "controller.port.http"; + static final String CONTROLLER_PORT_AKKA = "controller.port.akka"; + static final String CONTROLLER_CREDENTIALS = "controller.credentials"; + static final String AKKA_CONF_LOCATION = "akka.conf.location"; + static final String MBEAN_CLUSTER = "mbean.cluster"; + static final String MBEAN_SHARD_MANAGER = "mbean.shardManager"; + static final String MBEAN_SHARD_CONFIG = "mbean.shard.config"; + static final String ADM_USE_SSL = "adm.useSsl"; + static final String ADM_PORT_SSL = "adm.port.ssl"; + static final String ADM_PORT_HTTP = "adm.port.http"; + static final String ADM_FQDN = "adm.fqdn"; + static final String ADM_HEALTHCHECK= "adm.healthcheck"; + } }
\ No newline at end of file diff --git a/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/GrToolkitUtil.java b/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/GrToolkitUtil.java deleted file mode 100755 index 7f91467a..00000000 --- a/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/GrToolkitUtil.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2018 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========================================================= - */ - -package org.onap.ccsdk.sli.plugins; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.ClusterHealthOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.SiteHealthOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.site.health.output.SitesBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.DatabaseHealthOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.AdminHealthOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.HaltAkkaTrafficOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.ResumeAkkaTrafficOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.SiteIdentifierOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.FailoverOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.FailoverInputBuilder; - - -import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class GrToolkitUtil extends MdsalHelper { - private static final Logger LOG = LoggerFactory.getLogger(GrToolkitUtil.class); - public static String PROPERTIES_FILE = "/opt/opendaylight/current/controller/configuration/gr-toolkit.properties"; - - public static void loadProperties() { - File file = new File(PROPERTIES_FILE); - Properties properties = new Properties(); - InputStream input = null; - if(file.isFile() && file.canRead()) { - try { - input = new FileInputStream(file); - properties.load(input); - LOG.info("Loaded properties from " + PROPERTIES_FILE); - setProperties(properties); - } catch (Exception e) { - LOG.error("Failed to load properties " + PROPERTIES_FILE + "\n", e); - } finally { - if(input != null) { - try { - input.close(); - } catch (IOException e) { - LOG.error("Failed to close properties file " + PROPERTIES_FILE + "\n", e); - } - } - } - } - } - - static { - // Trick class loader into loading builders. Some of - // these will be needed later by Reflection classes, but need - // to explicitly "new" them here to get class loader to load them. - - ClusterHealthOutputBuilder b1 = new ClusterHealthOutputBuilder(); - SiteHealthOutputBuilder b2 = new SiteHealthOutputBuilder(); - SitesBuilder b3 = new SitesBuilder(); - DatabaseHealthOutputBuilder b4 = new DatabaseHealthOutputBuilder(); - AdminHealthOutputBuilder b5 = new AdminHealthOutputBuilder(); - HaltAkkaTrafficOutputBuilder b6 = new HaltAkkaTrafficOutputBuilder(); - ResumeAkkaTrafficOutputBuilder b7 = new ResumeAkkaTrafficOutputBuilder(); - SiteIdentifierOutputBuilder b8 = new SiteIdentifierOutputBuilder(); - FailoverOutputBuilder b9 = new FailoverOutputBuilder(); - FailoverInputBuilder b10 = new FailoverInputBuilder(); - } -} diff --git a/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/data/ClusterActor.java b/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/data/ClusterActor.java index 34a51192..1c8faac0 100755 --- a/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/data/ClusterActor.java +++ b/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/data/ClusterActor.java @@ -23,6 +23,8 @@ package org.onap.ccsdk.sli.plugins.data; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; public class ClusterActor { private String node; @@ -109,36 +111,36 @@ public class ClusterActor { this.unreachable = unreachable; } - public ArrayList<String> getShardLeader() { + public List<String> getShardLeader() { return shardLeader; } - public void setShardLeader(ArrayList<String> shardLeader) { - this.shardLeader = shardLeader; + public void setShardLeader(List<String> shardLeader) { + this.shardLeader = (ArrayList<String>) shardLeader; } - public ArrayList<String> getReplicaShards() { + public List<String> getReplicaShards() { return replicaShards; } - public void setReplicaShards(ArrayList<String> replicaShards) { - this.replicaShards = replicaShards; + public void setReplicaShards(List<String> replicaShards) { + this.replicaShards = (ArrayList<String>) replicaShards; } - public ArrayList<String> getNonReplicaShards() { + public List<String> getNonReplicaShards() { return nonReplicaShards; } - public void setNonReplicaShards(ArrayList<String> nonReplicaShards) { - this.nonReplicaShards = nonReplicaShards; + public void setNonReplicaShards(List<String> nonReplicaShards) { + this.nonReplicaShards = (ArrayList<String>) nonReplicaShards; } - public HashMap<String, Integer> getCommits() { + public Map<String, Integer> getCommits() { return commits; } - public void setCommits(HashMap<String, Integer> commits) { - this.commits = commits; + public void setCommits(Map<String, Integer> commits) { + this.commits = (HashMap<String, Integer>) commits; } public void flush() { @@ -189,8 +191,9 @@ public class ClusterActor { builder.append("\n"); } - for(String key : commits.keySet()) { - int value = commits.get(key); + for(Map.Entry<String, Integer> entry : commits.entrySet()) { + String key = entry.getKey(); + int value = entry.getValue(); if(value > 0) { builder.append("\t"); builder.append(value); diff --git a/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/data/MemberBuilder.java b/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/data/MemberBuilder.java index 1eb0e75a..96dfa64a 100755 --- a/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/data/MemberBuilder.java +++ b/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/data/MemberBuilder.java @@ -23,16 +23,12 @@ package org.onap.ccsdk.sli.plugins.data; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.cluster.health.output.MembersBuilder; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.member.CommitStatusBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.member.CommitStatus; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.member.ReplicasBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.member.Replicas; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.member.LeaderBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.member.Leader; - -import java.util.HashMap; import java.util.ArrayList; import java.util.List; +import java.util.Map; public class MemberBuilder extends MembersBuilder { public MemberBuilder(ClusterActor actor) { @@ -45,12 +41,11 @@ public class MemberBuilder extends MembersBuilder { populateReplicas(actor.getReplicaShards()); populateCommits(actor.getCommits()); populateLeader(actor.getShardLeader()); - //actor.getNonReplicaShards(); } - private void populateLeader(ArrayList<String> shardLeader) { + private void populateLeader(List<String> shardLeader) { LeaderBuilder builder; - this.setLeader((List) new ArrayList<Leader>()); + this.setLeader(new ArrayList<>()); for(String leader : shardLeader) { builder = new LeaderBuilder(); builder.setShard(leader); @@ -58,22 +53,24 @@ public class MemberBuilder extends MembersBuilder { } } - private void populateCommits(HashMap<String, Integer> commits) { + private void populateCommits(Map<String, Integer> commits) { CommitStatusBuilder builder; - this.setCommitStatus((List) new ArrayList<CommitStatus>()); - for(String key : commits.keySet()) { - if(commits.get(key) != 0) { + this.setCommitStatus(new ArrayList<>()); + for(Map.Entry<String, Integer> entry : commits.entrySet()) { + String key = entry.getKey(); + Integer value = entry.getValue(); + if(value != 0) { builder = new CommitStatusBuilder(); builder.setShard(key); - builder.setDelta(commits.get(key)); + builder.setDelta(value); this.getCommitStatus().add(builder.build()); } } } - private void populateReplicas(ArrayList<String> replicaShards) { + private void populateReplicas(List<String> replicaShards) { ReplicasBuilder builder; - this.setReplicas((List) new ArrayList<Replicas>()); + this.setReplicas(new ArrayList<>()); for(String shard : replicaShards) { builder = new ReplicasBuilder(); builder.setShard(shard); |