This is an automated email from the ASF dual-hosted git repository.
ofuks pushed a commit to branch DLAB-1571
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/DLAB-1571 by this push:
new 4cf9c06 [DLAB-1725, DLAB-1726] Fixed issues with billing export
4cf9c06 is described below
commit 4cf9c06a3893e9c2d4f97119fe45129f5bda43eb
Author: Oleh Fuks <[email protected]>
AuthorDate: Thu Apr 16 13:22:38 2020 +0300
[DLAB-1725, DLAB-1726] Fixed issues with billing export
---
.../backendapi/service/impl/BillingServiceImpl.java | 5 +++--
.../com/epam/dlab/backendapi/util/BillingUtils.java | 18 ++++++++++++------
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImpl.java
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImpl.java
index bddba04..8eae49b 100644
---
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImpl.java
+++
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImpl.java
@@ -122,11 +122,12 @@ public class BillingServiceImpl implements BillingService
{
@Override
public String downloadReport(UserInfo user, BillingFilter filter) {
+ boolean isFull = isFullReport(user);
BillingReport report = getBillingReport(user, filter);
StringBuilder builder = new
StringBuilder(BillingUtils.getFirstLine(report.getSbn(),
report.getUsageDateFrom(), report.getUsageDateTo()));
- builder.append(BillingUtils.getHeader());
+ builder.append(BillingUtils.getHeader(isFull));
try {
- report.getReportLines().forEach(r ->
builder.append(BillingUtils.printLine(r)));
+ report.getReportLines().forEach(r ->
builder.append(BillingUtils.printLine(r, isFull)));
builder.append(BillingUtils.getTotal(report.getTotalCost(),
report.getCurrency()));
return builder.toString();
} catch (Exception e) {
diff --git
a/services/self-service/src/main/java/com/epam/dlab/backendapi/util/BillingUtils.java
b/services/self-service/src/main/java/com/epam/dlab/backendapi/util/BillingUtils.java
index f971d1e..3494fbe 100644
---
a/services/self-service/src/main/java/com/epam/dlab/backendapi/util/BillingUtils.java
+++
b/services/self-service/src/main/java/com/epam/dlab/backendapi/util/BillingUtils.java
@@ -69,7 +69,7 @@ public class BillingUtils {
private static final String IMAGE_NAME = "Image";
private static final String DATAENGINE_NAME_FORMAT = "%d x %s";
- private static final String DATAENGINE_SERVICE_NAME_FORMAT = "Master:
%s%sSlave: %s";
+ private static final String DATAENGINE_SERVICE_NAME_FORMAT = "Master:
%sSlave: %s";
public static Stream<BillingReportLine> edgeBillingDataStream(String
project, String sbn, String endpoint) {
final String userEdgeId = String.format(EDGE_FORMAT, sbn, project,
endpoint).toLowerCase();
@@ -159,7 +159,7 @@ public class BillingUtils {
public static String getComputationalShape(UserComputationalResource
resource) {
return DataEngineType.fromDockerImageName(resource.getImageName()) ==
DataEngineType.SPARK_STANDALONE ?
String.format(DATAENGINE_NAME_FORMAT,
resource.getDataengineInstanceCount(), resource.getDataengineShape()) :
- String.format(DATAENGINE_SERVICE_NAME_FORMAT,
resource.getMasterNodeShape(), System.lineSeparator(),
resource.getSlaveNodeShape());
+ String.format(DATAENGINE_SERVICE_NAME_FORMAT,
resource.getMasterNodeShape(), resource.getSlaveNodeShape());
}
private static Stream<BillingReportLine>
standardImageBillingDataStream(String sbn, String endpoint) {
@@ -189,14 +189,20 @@ public class BillingUtils {
CSVFormatter.SEPARATOR, '\"');
}
- public static String getHeader() {
- return CSVFormatter.formatLine(new
ArrayList<>(Arrays.asList(BillingUtils.REPORT_HEADERS)),
CSVFormatter.SEPARATOR);
+ public static String getHeader(boolean isFull) {
+ List<String> headers = new
ArrayList<>(Arrays.asList(BillingUtils.REPORT_HEADERS));
+ if (!isFull) {
+ headers.remove(1);
+ }
+ return CSVFormatter.formatLine(headers, CSVFormatter.SEPARATOR);
}
- public static String printLine(BillingReportLine line) {
+ public static String printLine(BillingReportLine line, boolean isFull) {
List<String> lines = new ArrayList<>();
lines.add(getOrEmpty(line.getDlabId()));
- lines.add(getOrEmpty(line.getUser()));
+ if (isFull) {
+ lines.add(getOrEmpty(line.getUser()));
+ }
lines.add(getOrEmpty(line.getProject()));
lines.add(getOrEmpty(Optional.ofNullable(line.getResourceType()).map(r
-> StringUtils.capitalize(r.toString().toLowerCase())).orElse(null)));
lines.add(getOrEmpty(Optional.ofNullable(line.getStatus()).map(UserInstanceStatus::toString).orElse(null)));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]