Skip to content

Commit

Permalink
Merge pull request #70 from kmgowda/kmg-logger
Browse files Browse the repository at this point in the history
Global logger and Banner Implementation
  • Loading branch information
kmgowda authored May 2, 2020
2 parents 62fb8b0 + c0a05b0 commit 5370008
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.sbk.api.CallbackReader;
import io.sbk.api.Parameters;
import io.sbk.api.Callback;
import io.sbk.api.impl.SbkLogger;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException;
import org.apache.activemq.artemis.api.core.RoutingType;
Expand Down Expand Up @@ -56,7 +57,7 @@ public void start(Callback callback) throws IOException {
try {
message.acknowledge();
} catch (ActiveMQException e) {
System.out.println("ArtemisCallbackReader : Message acknowledge failed");
SbkLogger.log.error("ArtemisCallbackReader : Message acknowledge failed");
}
});
} catch (ActiveMQException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.nats.streaming.AckHandler;
import io.nats.streaming.NatsStreaming;
import io.nats.streaming.StreamingConnection;
import io.sbk.api.impl.SbkLogger;

/**
* Class for NATS Stream Writer.
Expand All @@ -44,7 +45,7 @@ public long recordWrite(byte[] data, int size, RecordTime record, int id) {
final String[] guid = new String[1];
final AckHandler acb = (s, e) -> {
if ((e != null) || !guid[0].equals(s)) {
System.out.println("NAT Streaming Writer failed !");
SbkLogger.log.error("NAT Streaming Writer failed !");
} else {
final long endTime = System.currentTimeMillis();
record.accept(id, time, endTime, size, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.pravega.client.stream.impl.StreamImpl;
import io.pravega.client.ClientConfig;
import io.pravega.client.stream.Stream;
import io.sbk.api.impl.SbkLogger;

/**
* Class for Pravega stream and segments.
Expand Down Expand Up @@ -77,13 +78,13 @@ public boolean create() {
public void scale() throws InterruptedException, ExecutionException, TimeoutException {
StreamSegments segments = controller.getCurrentSegments(scope, stream).join();
final int nseg = segments.getSegments().size();
System.out.println("Current segments of the stream: " + stream + " = " + nseg);
SbkLogger.log.info("Current segments of the stream: " + stream + " = " + nseg);

if (nseg == segCount) {
return;
}

System.out.println("The stream: " + stream + " will be manually scaling to " + segCount + " segments");
SbkLogger.log.info("The stream: " + stream + " will be manually scaling to " + segCount + " segments");

/*
* Note that the Upgrade stream API does not change the number of segments;
Expand Down Expand Up @@ -115,13 +116,13 @@ public void scale() throws InterruptedException, ExecutionException, TimeoutExce
throw new TimeoutException("ERROR : Scale operation on stream " + stream + " did not complete");
}

System.out.println("Number of Segments after manual scale: " +
SbkLogger.log.info("Number of Segments after manual scale: " +
controller.getCurrentSegments(scope, stream)
.get().getSegments().size());
}

public void recreate() throws InterruptedException, ExecutionException, TimeoutException {
System.out.println("Sealing and Deleteing the stream : " + stream + " and then recreating the same");
SbkLogger.log.info("Sealing and Deleteing the stream : " + stream + " and then recreating the same");
CompletableFuture<Boolean> sealStatus = controller.sealStream(scope, stream);
if (!sealStatus.get(timeout, TimeUnit.SECONDS)) {
throw new TimeoutException("ERROR : Segment sealing operation on stream " + stream + " did not complete");
Expand Down Expand Up @@ -156,7 +157,7 @@ public void deleteReaderGroup() {
try {
readerGroupManager.deleteReaderGroup(rdGrpName);
} catch (RuntimeException e) {
System.out.println("Cannot delete reader group " + rdGrpName + " because it is already deleted");
SbkLogger.log.error("Cannot delete reader group " + rdGrpName + " because it is already deleted");
}
}
}
5 changes: 3 additions & 2 deletions sbk-api/src/main/java/io/sbk/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
package io.sbk.api;

public class Config {
final public static String NAME = "sbk";
final public static String DESC = "Storage Benchmark Kit";

final public static int NS_PER_MICRO = 1000;
final public static int MICROS_PER_MS = 1000;
final public static int MS_PER_SEC = 1000;
Expand All @@ -23,8 +26,6 @@ public class Config {
final public static int DEFAULT_WINDOW_LATENCY = MS_PER_MIN;
final public static int DEFAULT_MAX_LATENCY = MS_PER_MIN * 15;

public String name;
public String description;
public String packageName;
public boolean fork;
public int reportingMS;
Expand Down
5 changes: 0 additions & 5 deletions sbk-api/src/main/java/io/sbk/api/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ public interface Parameters {
*/
void printHelp();

/**
* Print the -version output.
*/
void printVersion();

/**
* Parse the command line arguments.
* @param args list of command line arguments.
Expand Down
18 changes: 18 additions & 0 deletions sbk-api/src/main/java/io/sbk/api/impl/SbkLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) KMG. 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
*/
package io.sbk.api.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final public class SbkLogger {
final private static String LOGGER_NAME = "SBK";
final public static Logger log = LoggerFactory.getLogger(LOGGER_NAME);
}
16 changes: 1 addition & 15 deletions sbk-api/src/main/java/io/sbk/api/impl/SbkParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ final public class SbkParameters implements Parameters {
final private String benchmarkName;
final private String className;
final private String desc;
final private String version;
final private Options options;
final private HelpFormatter formatter;
final private CommandLineParser parser;
Expand Down Expand Up @@ -65,14 +64,13 @@ final public class SbkParameters implements Parameters {
private double throughput;
private CommandLine commandline;

public SbkParameters(String name, String desc, String version, String className, List<String> driversList, long startTime) {
public SbkParameters(String name, String desc, String className, List<String> driversList, long startTime) {
this.options = new Options();
this.formatter = new HelpFormatter();
this.parser = new DefaultParser();
this.benchmarkName = name;
this.desc = desc;
this.className = className;
this.version = version;
this.timeout = TIMEOUT;
this.driversList = driversList;
this.startTime = startTime;
Expand All @@ -94,7 +92,6 @@ public SbkParameters(String name, String desc, String version, String className,
"if 0 , writes 'records'\n" +
"if -1, get the maximum throughput");
options.addOption("help", false, "Help message");
options.addOption("version", false, "Version");
}

@Override
Expand All @@ -116,12 +113,6 @@ public void printHelp() {
}
}

@Override
public void printVersion() {
System.out.println(desc + ", " + benchmarkName +" version: " + version);
}


@Override
public boolean hasOption(String name) {
if (commandline != null) {
Expand Down Expand Up @@ -156,11 +147,6 @@ public void parseArgs(String[] args) throws ParseException, IllegalArgumentExcep
printHelp();
return;
}
if (commandline.hasOption("version")) {
printVersion();
return;
}

writersCount = Integer.parseInt(commandline.getOptionValue("writers", "0"));
readersCount = Integer.parseInt(commandline.getOptionValue("readers", "0"));

Expand Down
32 changes: 11 additions & 21 deletions sbk-api/src/main/java/io/sbk/main/SbkMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import io.micrometer.core.instrument.util.IOUtils;
import io.micrometer.jmx.JmxConfig;
import io.micrometer.jmx.JmxMeterRegistry;
import io.sbk.api.Benchmark;
Expand All @@ -28,6 +29,7 @@
import io.sbk.api.impl.MetricImpl;
import io.sbk.api.impl.MetricsLogger;
import io.sbk.api.impl.SbkBenchmark;
import io.sbk.api.impl.SbkLogger;
import io.sbk.api.impl.SbkParameters;
import io.sbk.api.impl.SystemResultLogger;
import org.apache.commons.cli.CommandLine;
Expand All @@ -48,6 +50,7 @@
*/
public class SbkMain {
final static String CONFIGFILE = "sbk.properties";
final static String BANNERFILE = "banner.txt";

public static void main(final String[] args) {
long startTime = System.currentTimeMillis();
Expand All @@ -63,6 +66,9 @@ public static void main(final String[] args) {
Config config = null;
CompletableFuture<Void> ret = null;

SbkLogger.log.info(IOUtils.toString(SbkMain.class.getClassLoader().getResourceAsStream(BANNERFILE)));
SbkLogger.log.info(Config.NAME.toUpperCase() +" version: "+version);

final ObjectMapper mapper = new ObjectMapper(new JavaPropsFactory())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

Expand All @@ -74,19 +80,6 @@ public static void main(final String[] args) {
System.exit(0);
}

try {
commandline = new DefaultParser().parse(new Options()
.addOption("version", false, "Version"),
args, true);
} catch (ParseException ex) {
ex.printStackTrace();
System.exit(0);
}
if (commandline.hasOption("version")) {
System.out.println(config.description + ", " + config.name + " version: " + version);
System.exit(0);
}

try {
commandline = new DefaultParser().parse(new Options()
.addOption("class", true, "Benchmark Class"),
Expand All @@ -99,14 +92,14 @@ public static void main(final String[] args) {
driversList = getClassNames(config.packageName);
className = commandline.getOptionValue("class", null);
if (className == null) {
Parameters paramsHelp = new SbkParameters(config.name, config.description, version, "", driversList, startTime);
Parameters paramsHelp = new SbkParameters(config.NAME, config.DESC, "", driversList, startTime);
metric.addArgs(paramsHelp);
paramsHelp.printHelp();
System.exit(0);
}
final String name = searchDriver(driversList, className);
if (name == null) {
System.out.printf("storage driver : %s not found in the SBK, run with -help to see the supported drivers\n", className);
SbkLogger.log.error("storage driver: " + className+ " not found in the SBK, run with -help to see the supported drivers");
System.exit(0);
}
try {
Expand All @@ -118,10 +111,10 @@ public static void main(final String[] args) {

final Storage storage = obj;
if (storage == null) {
System.out.println("Failure to create Benchmark object");
SbkLogger.log.error("Failure to create Benchmark object");
System.exit(0);
}
params = new SbkParameters(config.name, config.description, version, name, driversList, startTime);
params = new SbkParameters(config.NAME, config.DESC, name, driversList, startTime);
storage.addArgs(params);
metric.addArgs(params);
try {
Expand All @@ -131,9 +124,6 @@ public static void main(final String[] args) {
params.printHelp();
System.exit(0);
}
if (params.hasOption("version")) {
System.exit(0);
}
if (params.hasOption("help")) {
System.exit(0);
}
Expand All @@ -160,7 +150,7 @@ public static void main(final String[] args) {
metricsLogger = logger;
} else {
final CompositeMeterRegistry compositeLogger = Metrics.globalRegistry;
final String prefix = config.name.toUpperCase() + "_" + name + "_" + action + "_";
final String prefix = config.NAME.toUpperCase() + "_" + name + "_" + action + "_";
compositeLogger.add(new JmxMeterRegistry(JmxConfig.DEFAULT, Clock.SYSTEM));
compositeLogger.add(metricRegistry);
metricsLogger = new MetricsLogger(
Expand Down
7 changes: 7 additions & 0 deletions sbk-api/src/main/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

_____ ____ _ __
/ ____| | _ \ | | / /
| (___ | |_) | | |/ /
\___ \ | _ < | <
____) | | |_) | | |\ \
|_____/ |____/ |_| \_\
6 changes: 0 additions & 6 deletions sbk-api/src/main/resources/sbk.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
#
# http://www.apache.org/licenses/LICENSE-2.0

# Name of the Framework
name=sbk

# Description
description=Storage Benchmark Kit

# Package Name to fetch the storage drivers
packageName=io.sbk

Expand Down

0 comments on commit 5370008

Please sign in to comment.