You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by of...@apache.org on 2020/09/10 11:29:58 UTC

[incubator-dlab] branch develop updated: [DLAB-2024] Fixed bug with AWS billing

This is an automated email from the ASF dual-hosted git repository.

ofuks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/develop by this push:
     new bf1a5db  [DLAB-2024] Fixed bug with AWS billing
bf1a5db is described below

commit bf1a5db0676c9579b764590953e1c7c6b5ebc215
Author: Oleh Fuks <ol...@gmail.com>
AuthorDate: Thu Sep 10 14:08:16 2020 +0300

    [DLAB-2024] Fixed bug with AWS billing
---
 .../java/com/epam/dlab/BillingServiceImpl.java     |   1 -
 .../main/java/com/epam/dlab/core/ModuleData.java   |   3 +-
 .../com/epam/dlab/core/parser/ParserByLine.java    | 100 +++++++++------------
 .../java/com/epam/dlab/module/AdapterConsole.java  |   4 +-
 .../com/epam/dlab/module/aws/AdapterS3File.java    |   2 -
 .../java/com/epam/dlab/module/aws/FilterAWS.java   |   8 +-
 .../java/com/epam/dlab/mongo/AdapterMongoDb.java   |   3 +-
 7 files changed, 49 insertions(+), 72 deletions(-)

diff --git a/services/billing-aws/src/main/java/com/epam/dlab/BillingServiceImpl.java b/services/billing-aws/src/main/java/com/epam/dlab/BillingServiceImpl.java
index 8ac6c48..393a1be 100644
--- a/services/billing-aws/src/main/java/com/epam/dlab/BillingServiceImpl.java
+++ b/services/billing-aws/src/main/java/com/epam/dlab/BillingServiceImpl.java
@@ -54,7 +54,6 @@ public class BillingServiceImpl implements BillingService {
 		try {
 			ParserBase parser = configuration.build();
 
-			LOGGER.info("Try to load billing report for configuration: {}", configuration);
 			List<BillingData> billingData = parser.parse()
 					.stream()
 					.map(this::toBillingData)
diff --git a/services/billing-aws/src/main/java/com/epam/dlab/core/ModuleData.java b/services/billing-aws/src/main/java/com/epam/dlab/core/ModuleData.java
index cc60bd3..256ab1b 100644
--- a/services/billing-aws/src/main/java/com/epam/dlab/core/ModuleData.java
+++ b/services/billing-aws/src/main/java/com/epam/dlab/core/ModuleData.java
@@ -143,8 +143,7 @@ public class ModuleData {
 	}
 
 	public void store() {
-		final Document document = new Document().append(ID_FIELD, id).append(MODIFICATION_DATE,
-				modificationDate).append(ENTRIES_FIELD, entries);
+		final Document document = new Document().append(ID_FIELD, id).append(MODIFICATION_DATE, modificationDate).append(ENTRIES_FIELD, entries);
 		connection.getCollection(MongoConstants.BILLING_DATA_COLLECTION)
 				.updateOne(eq(ID_FIELD, id), new Document("$set", document), new UpdateOptions().upsert(true));
 		modified = false;
diff --git a/services/billing-aws/src/main/java/com/epam/dlab/core/parser/ParserByLine.java b/services/billing-aws/src/main/java/com/epam/dlab/core/parser/ParserByLine.java
index 6ebac03..0fbdc5f 100644
--- a/services/billing-aws/src/main/java/com/epam/dlab/core/parser/ParserByLine.java
+++ b/services/billing-aws/src/main/java/com/epam/dlab/core/parser/ParserByLine.java
@@ -171,76 +171,60 @@ public abstract class ParserByLine extends ParserBase {
 				String line;
 				List<String> row;
 				ReportLine reportLine;
-				do {
-					while ((line = getNextRow()) != null) {
-						if (getFilter() != null && (line = getFilter().canParse(line)) == null) {
-							getCurrentStatistics().incrRowFiltered();
-							continue;
-						}
+				LOGGER.info("Parsing {}", getAdapterIn().getEntryName());
 
-						row = parseRow(line);
-						if ((getFilter() != null && (row = getFilter().canTransform(row)) == null)) {
-							getCurrentStatistics().incrRowFiltered();
-							continue;
-						}
-						try {
-							if (getCondition() != null && !getCondition().evaluate(row)) {
-								getCurrentStatistics().incrRowFiltered();
-								continue;
-							}
-						} catch (ParseException e) {
-							throw new ParseException(e.getLocalizedMessage() + ENTRY_NAME + getCurrentStatistics
-									().getEntryName() +
-									SOURCE_LINE +
-									getCurrentStatistics().getRowReaded() + "]: " + line, e);
-						} catch (Exception e) {
-							throw new ParseException("Cannot evaluate condition " + getWhereCondition() + ". " +
-									e.getLocalizedMessage() + ENTRY_NAME + getCurrentStatistics().getEntryName()
-									+ SOURCE_LINE + getCurrentStatistics().getRowReaded() + "]: " + line, e);
-						}
+				while ((line = getNextRow()) != null) {
+					if (getFilter() != null && (line = getFilter().canParse(line)) == null) {
+						getCurrentStatistics().incrRowFiltered();
+						continue;
+					}
 
-						try {
-							reportLine = getCommonFormat().toCommonFormat(row);
-						} catch (ParseException e) {
-							throw new ParseException("Cannot cast row to common format. " +
-									e.getLocalizedMessage() + ENTRY_NAME + getCurrentStatistics().getEntryName
-									() +
-									SOURCE_LINE + getCurrentStatistics().getRowReaded() + "]: " + line, e);
-						}
-						if (getFilter() != null && (reportLine = getFilter().canAccept(reportLine)) == null) {
+					row = parseRow(line);
+					if ((getFilter() != null && (row = getFilter().canTransform(row)) == null)) {
+						getCurrentStatistics().incrRowFiltered();
+						continue;
+					}
+					try {
+						if (getCondition() != null && !getCondition().evaluate(row)) {
 							getCurrentStatistics().incrRowFiltered();
 							continue;
 						}
+					} catch (ParseException e) {
+						throw new ParseException(e.getLocalizedMessage() + ENTRY_NAME + getCurrentStatistics().getEntryName() +
+								SOURCE_LINE + getCurrentStatistics().getRowReaded() + "]: " + line, e);
+					} catch (Exception e) {
+						throw new ParseException("Cannot evaluate condition " + getWhereCondition() + ". " +
+								e.getLocalizedMessage() + ENTRY_NAME + getCurrentStatistics().getEntryName() +
+								SOURCE_LINE + getCurrentStatistics().getRowReaded() + "]: " + line, e);
+					}
 
-						getCurrentStatistics().incrRowParsed();
-						if (getAggregate() != AggregateGranularity.NONE) {
-							getAggregator().append(reportLine);
-						} else {
-							billingData.add(getAdapterOut().writeRow(reportLine));
-							getCurrentStatistics().incrRowWritten();
-						}
+					try {
+						reportLine = getCommonFormat().toCommonFormat(row);
+					} catch (ParseException e) {
+						throw new ParseException("Cannot cast row to common format. " +
+								e.getLocalizedMessage() + ENTRY_NAME + getCurrentStatistics().getEntryName() +
+								SOURCE_LINE + getCurrentStatistics().getRowReaded() + "]: " + line, e);
+					}
+					if (getFilter() != null && (reportLine = getFilter().canAccept(reportLine)) == null) {
+						getCurrentStatistics().incrRowFiltered();
+						continue;
 					}
 
+					getCurrentStatistics().incrRowParsed();
 					if (getAggregate() != AggregateGranularity.NONE) {
-						for (int i = 0; i < getAggregator().size(); i++) {
-							billingData.add(getAdapterOut().writeRow(getAggregator().get(i)));
-							getCurrentStatistics().incrRowWritten();
-						}
+						getAggregator().append(reportLine);
+					} else {
+						billingData.add(getAdapterOut().writeRow(reportLine));
+						getCurrentStatistics().incrRowWritten();
 					}
+				}
 
-					if (getAdapterIn().hasMultyEntry()) {
-						if (getAdapterIn().openNextEntry()) {
-							// Search entry with data
-							while (!initEntry()) {
-								if (!getAdapterIn().openNextEntry()) {
-									break;
-								}
-							}
-						} else {
-							break;
-						}
+				if (getAggregate() != AggregateGranularity.NONE) {
+					for (int i = 0; i < getAggregator().size(); i++) {
+						billingData.add(getAdapterOut().writeRow(getAggregator().get(i)));
+						getCurrentStatistics().incrRowWritten();
 					}
-				} while (getAdapterIn().hasMultyEntry() && getAdapterIn().hasEntryData());
+				}
 			}
 		} catch (GenericException e) {
 			close(true);
diff --git a/services/billing-aws/src/main/java/com/epam/dlab/module/AdapterConsole.java b/services/billing-aws/src/main/java/com/epam/dlab/module/AdapterConsole.java
index 3bffa79..bb92e9b 100644
--- a/services/billing-aws/src/main/java/com/epam/dlab/module/AdapterConsole.java
+++ b/services/billing-aws/src/main/java/com/epam/dlab/module/AdapterConsole.java
@@ -80,12 +80,12 @@ public class AdapterConsole extends AdapterBase {
 	}
 
 	@Override
-	public void writeHeader(List<String> header) throws AdapterException {
+	public void writeHeader(List<String> header) {
 		System.out.println(CommonFormat.rowToString(header));
 	}
 
 	@Override
-	public Document writeRow(ReportLine row) throws AdapterException {
+	public Document writeRow(ReportLine row) {
 		System.out.println(CommonFormat.rowToString(row));
 		return null;
 	}
diff --git a/services/billing-aws/src/main/java/com/epam/dlab/module/aws/AdapterS3File.java b/services/billing-aws/src/main/java/com/epam/dlab/module/aws/AdapterS3File.java
index cf1ef5c..68a5d41 100644
--- a/services/billing-aws/src/main/java/com/epam/dlab/module/aws/AdapterS3File.java
+++ b/services/billing-aws/src/main/java/com/epam/dlab/module/aws/AdapterS3File.java
@@ -303,7 +303,6 @@ public class AdapterS3File extends AdapterBase {
 		throw new AdapterException("Unimplemented method.");
 	}
 
-
 	/**
 	 * Return the current file name.
 	 */
@@ -377,7 +376,6 @@ public class AdapterS3File extends AdapterBase {
 		}
 	}
 
-
 	@Override
 	public ToStringHelper toStringHelper(Object self) {
 		return super.toStringHelper(self)
diff --git a/services/billing-aws/src/main/java/com/epam/dlab/module/aws/FilterAWS.java b/services/billing-aws/src/main/java/com/epam/dlab/module/aws/FilterAWS.java
index a72502d..66d3cb9 100644
--- a/services/billing-aws/src/main/java/com/epam/dlab/module/aws/FilterAWS.java
+++ b/services/billing-aws/src/main/java/com/epam/dlab/module/aws/FilterAWS.java
@@ -21,7 +21,6 @@ package com.epam.dlab.module.aws;
 
 import com.epam.dlab.core.FilterBase;
 import com.epam.dlab.exceptions.InitializationException;
-import com.epam.dlab.exceptions.ParseException;
 import com.epam.dlab.model.aws.ReportLine;
 import com.epam.dlab.module.ModuleName;
 import com.fasterxml.jackson.annotation.JsonClassDescription;
@@ -121,12 +120,12 @@ public class FilterAWS extends FilterBase {
 	}
 
 	@Override
-	public String canParse(String line) throws ParseException {
+	public String canParse(String line) {
 		return line;
 	}
 
 	@Override
-	public List<String> canTransform(List<String> row) throws ParseException {
+	public List<String> canTransform(List<String> row) {
 		if (dlabIdIndex != -1 &&
 				(row.size() <= dlabIdIndex ||
 						!row.get(dlabIdIndex).startsWith(dlabPrefix))) {
@@ -136,12 +135,11 @@ public class FilterAWS extends FilterBase {
 	}
 
 	@Override
-	public ReportLine canAccept(ReportLine row) throws ParseException {
+	public ReportLine canAccept(ReportLine row) {
 		row.setCurrencyCode(currencyCode);
 		return row;
 	}
 
-
 	@Override
 	public ToStringHelper toStringHelper(Object self) {
 		return super.toStringHelper(self)
diff --git a/services/billing-aws/src/main/java/com/epam/dlab/mongo/AdapterMongoDb.java b/services/billing-aws/src/main/java/com/epam/dlab/mongo/AdapterMongoDb.java
index 94c361e..7feca95 100644
--- a/services/billing-aws/src/main/java/com/epam/dlab/mongo/AdapterMongoDb.java
+++ b/services/billing-aws/src/main/java/com/epam/dlab/mongo/AdapterMongoDb.java
@@ -156,8 +156,7 @@ public class AdapterMongoDb extends DBAdapterBase {
 			try {
 				resourceTypeDAO = new DlabResourceTypeDAO(connection);
 			} catch (InitializationException e) {
-				throw new AdapterException("Cannot initialize billing transformer to DLab format. " + e
-						.getLocalizedMessage(), e);
+				throw new AdapterException("Cannot initialize billing transformer to DLab format. " + e.getLocalizedMessage(), e);
 			}
 
 			connection.createBillingIndexes();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org