This is an automated email from the ASF dual-hosted git repository.
bhliva 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 704904d DLAB-978 added project field to billing
704904d is described below
commit 704904df95f585c4392a0c1acc36cad2e9e022e7
Author: bhliva <[email protected]>
AuthorDate: Mon Aug 5 12:51:12 2019 +0300
DLAB-978 added project field to billing
---
.../com/epam/dlab/mongo/DlabResourceTypeDAO.java | 62 +++++++-------
.../java/com/epam/dlab/mongo/MongoConstants.java | 42 +++++-----
.../java/com/epam/dlab/mongo/ResourceItem.java | 98 ++++++++++++++--------
.../java/com/epam/dlab/mongo/ResourceItemList.java | 90 ++++++++++++--------
.../com/epam/dlab/mongo/ResourceItemListTest.java | 4 +-
5 files changed, 170 insertions(+), 126 deletions(-)
diff --git
a/services/billing-aws/src/main/java/com/epam/dlab/mongo/DlabResourceTypeDAO.java
b/services/billing-aws/src/main/java/com/epam/dlab/mongo/DlabResourceTypeDAO.java
index 7ef6660..9572892 100644
---
a/services/billing-aws/src/main/java/com/epam/dlab/mongo/DlabResourceTypeDAO.java
+++
b/services/billing-aws/src/main/java/com/epam/dlab/mongo/DlabResourceTypeDAO.java
@@ -119,15 +119,6 @@ public class DlabResourceTypeDAO implements MongoConstants
{
}
/**
- * Return the name of bucket.
- *
- * @param name the name of bucket.
- */
- private String getBucketName(String name) {
- return name.replace('_', '-').toLowerCase();
- }
-
- /**
* Load and return DLab resources from Mongo DB.
*
* @throws InitializationException
@@ -137,14 +128,13 @@ public class DlabResourceTypeDAO implements
MongoConstants {
// Add SSN
String sbName = getServiceBaseName();
- resourceList.append(sbName + "-ssn", "SSN",
DlabResourceType.SSN, null, null);
- resourceList.append(sbName + "-ssn-volume-primary", "SSN
volume", DlabResourceType.VOLUME, null, null);
- resourceList.append(sbName + "-ssn-bucket", "SSN bucket",
DlabResourceType.SSN_BUCKET, null,
- null);
+ resourceList.append(sbName + "-ssn", "SSN",
DlabResourceType.SSN);
+ resourceList.append(sbName + "-ssn-volume-primary", "SSN
volume", DlabResourceType.VOLUME);
+ resourceList.append(sbName + "-ssn-bucket", "SSN bucket",
DlabResourceType.SSN_BUCKET);
// collaboration bucket
resourceList.append(sbName + "-shared-bucket", "Collaboration
bucket", DlabResourceType
- .COLLABORATION_BUCKET, null, null);
+ .COLLABORATION_BUCKET);
// Add PROJECTS
Bson projection = fields(include("name"));
@@ -152,17 +142,18 @@ public class DlabResourceTypeDAO implements
MongoConstants {
for (Document d : docs) {
String projectName = d.getString("name");
resourceList.append(sbName + "-" + projectName +
"-edge", "EDGE Node",
- DlabResourceType.EDGE, null, null);
+ DlabResourceType.EDGE, null, null,
projectName);
resourceList.append(sbName + "-" + projectName +
"-bucket", "Project bucket",
- DlabResourceType.COLLABORATION_BUCKET,
null, null);
+ DlabResourceType.COLLABORATION_BUCKET,
null, null, projectName);
resourceList.append(sbName + "-" + projectName +
"-edge-volume-primary",
- "EDGE Volume", DlabResourceType.VOLUME,
null, null);
+ "EDGE Volume", DlabResourceType.VOLUME,
null, null, projectName);
}
// Add exploratory
projection = fields(include(FIELD_USER,
FIELD_EXPLORATORY_NAME,
FIELD_EXPLORATORY_ID,
+ FIELD_PROJECT,
FIELD_COMPUTATIONAL_RESOURCES + "." +
FIELD_COMPUTATIONAL_ID,
FIELD_COMPUTATIONAL_RESOURCES + "." +
FIELD_COMPUTATIONAL_NAME,
FIELD_COMPUTATIONAL_RESOURCES + "." +
FIELD_IMAGE,
@@ -173,9 +164,10 @@ public class DlabResourceTypeDAO implements MongoConstants
{
String username = exp.getString(FIELD_USER);
String exploratoryName =
exp.getString(FIELD_EXPLORATORY_NAME);
String exploratoryId =
exp.getString(FIELD_EXPLORATORY_ID);
+ String project = exp.getString(FIELD_PROJECT);
resourceList.append(exploratoryId, exploratoryName,
DlabResourceType.EXPLORATORY, username,
- exploratoryName);
- appendExploratoryVolumes(username, exploratoryName,
exploratoryId);
+ exploratoryName, project);
+ appendExploratoryVolumes(username, exploratoryName,
exploratoryId, project);
// Add computational
@SuppressWarnings("unchecked")
@@ -188,46 +180,49 @@ public class DlabResourceTypeDAO implements
MongoConstants {
String computationalName =
comp.getString(FIELD_COMPUTATIONAL_NAME);
final DataEngineType dataEngineType =
DataEngineType.fromDockerImageName(comp.getString(FIELD_IMAGE));
resourceList.append(computationalId,
computationalName, DlabResourceType.COMPUTATIONAL, username,
- exploratoryName);
+ exploratoryName, project);
if (DataEngineType.CLOUD_SERVICE ==
dataEngineType) {
-
appendDataengineServiceVolumes(username, exploratoryName, computationalId,
computationalName);
+
appendDataengineServiceVolumes(username, exploratoryName, computationalId,
computationalName,
+ project);
} else {
- appendDataengineVolumes(username,
exploratoryName, comp, computationalId, computationalName);
+ appendDataengineVolumes(username,
exploratoryName, comp, computationalId, computationalName,
+ project);
}
}
}
LOGGER.debug("resourceList is {}", resourceList);
}
- private void appendExploratoryVolumes(String username, String
exploratoryName, String exploratoryId) {
+ private void appendExploratoryVolumes(String username, String
exploratoryName, String exploratoryId,
+
String project) {
resourceList.append(exploratoryId + VOLUME_PRIMARY_SUFFIX,
"Volume primary", DlabResourceType.VOLUME,
- username, exploratoryName);
+ username, exploratoryName, project);
resourceList.append(exploratoryId + VOLUME_SECONDARY_SUFFIX,
"Volume secondary", DlabResourceType.VOLUME,
- username, exploratoryName);
+ username, exploratoryName, project);
}
private void appendDataengineServiceVolumes(String username, String
exploratoryName, String computationalId,
-
String computationalName) {
+
String computationalName, String project) {
resourceList.append(computationalId + VOLUME_PRIMARY_SUFFIX,
computationalName + " volume primary",
- DlabResourceType.VOLUME, username,
exploratoryName);
+ DlabResourceType.VOLUME, username,
exploratoryName, project);
resourceList.append(computationalId + VOLUME_SECONDARY_SUFFIX,
computationalName + " volume secondary",
- DlabResourceType.VOLUME, username,
exploratoryName);
+ DlabResourceType.VOLUME, username,
exploratoryName, project);
}
private void appendDataengineVolumes(String username, String
exploratoryName, Document comp, String
- computationalId, String computationalName) {
+ computationalId, String computationalName, String
project) {
resourceList.append(computationalId + "-m-volume-primary",
computationalName + " master volume primary",
- DlabResourceType.VOLUME, username,
exploratoryName);
+ DlabResourceType.VOLUME, username,
exploratoryName, project);
resourceList.append(computationalId + "-m-volume-secondary",
computationalName + " master volume secondary",
- DlabResourceType.VOLUME, username,
exploratoryName);
+ DlabResourceType.VOLUME, username,
exploratoryName, project);
final Integer instanceCount =
Integer.valueOf(comp.getString(FIELD_DATAENGINE_INSTANCE_COUNT));
for (int i = instanceCount - 1; i > 0; i--) {
final String slaveId = computationalId + "-s" + i;
final String slaveName = computationalName + "-s" + i;
resourceList.append(slaveId + VOLUME_PRIMARY_SUFFIX,
slaveName + " volume primary", DlabResourceType
- .VOLUME, username, exploratoryName);
+ .VOLUME, username, exploratoryName,
project);
resourceList.append(slaveId + VOLUME_SECONDARY_SUFFIX,
slaveName + " volume secondary", DlabResourceType
- .VOLUME, username, exploratoryName);
+ .VOLUME, username, exploratoryName,
project);
}
}
@@ -259,6 +254,7 @@ public class DlabResourceTypeDAO implements MongoConstants {
d.put(FIELD_DLAB_RESOURCE_TYPE,
resource.getType().toString());
d.put(ReportLine.FIELD_USER_ID, resource.getUser());
d.put(FIELD_EXPLORATORY_NAME,
resource.getExploratoryName());
+ d.put(FIELD_PROJECT, resource.getProject());
}
return d.append(ReportLine.FIELD_USAGE_DATE, row.getUsageDate())
.append(ReportLine.FIELD_PRODUCT,
row.getProduct())
diff --git
a/services/billing-aws/src/main/java/com/epam/dlab/mongo/MongoConstants.java
b/services/billing-aws/src/main/java/com/epam/dlab/mongo/MongoConstants.java
index b7c49a4..4e9de76 100644
--- a/services/billing-aws/src/main/java/com/epam/dlab/mongo/MongoConstants.java
+++ b/services/billing-aws/src/main/java/com/epam/dlab/mongo/MongoConstants.java
@@ -23,37 +23,37 @@ package com.epam.dlab.mongo;
*/
public interface MongoConstants {
/** Name of ID field. */
- public static final String FIELD_ID = "_id";
+ String FIELD_ID = "_id";
/** Collection environment settings. */
- public static final String COLLECTION_SETTINGS = "settings";
- public static final String FIELD_SERIVICE_BASE_NAME =
"conf_service_base_name";
+ String COLLECTION_SETTINGS = "settings";
+ String FIELD_SERIVICE_BASE_NAME = "conf_service_base_name";
/** Collection user AWS credentials. */
- public static final String COLLECTION_USER_EDGE = "userCloudCredentials";
- public static final String FIELD_EDGE_BUCKET = "user_own_bicket_name";
+ String COLLECTION_USER_EDGE = "userCloudCredentials";
/** Collection user instances. */
- public static final String COLLECTION_USER_INSTANCES = "userInstances";
- public static final String FIELD_EXPLORATORY_NAME = "exploratory_name";
- public static final String FIELD_USER = "user";
- public static final String FIELD_IMAGE = "image";
- public static final String FIELD_EXPLORATORY_ID = "exploratory_id";
- public static final String FIELD_CURRENCY_CODE = "currency_code";
- public static final String FIELD_COMPUTATIONAL_RESOURCES =
"computational_resources";
- public static final String FIELD_COMPUTATIONAL_ID = "computational_id";
- public static final String FIELD_COMPUTATIONAL_NAME = "computational_name";
+ String COLLECTION_USER_INSTANCES = "userInstances";
+ String FIELD_EXPLORATORY_NAME = "exploratory_name";
+ String FIELD_USER = "user";
+ String FIELD_IMAGE = "image";
+ String FIELD_EXPLORATORY_ID = "exploratory_id";
+ String FIELD_CURRENCY_CODE = "currency_code";
+ String FIELD_COMPUTATIONAL_RESOURCES = "computational_resources";
+ String FIELD_COMPUTATIONAL_ID = "computational_id";
+ String FIELD_COMPUTATIONAL_NAME = "computational_name";
String FIELD_DATAENGINE_INSTANCE_COUNT = "dataengine_instance_count";
/** Collection billing. */
- public static final String COLLECTION_BILLING = "billing";
- public static final String FIELD_DLAB_RESOURCE_ID = "dlab_resource_id";
- public static final String FIELD_RESOURCE_NAME = "resource_name";
- public static final String FIELD_DLAB_RESOURCE_TYPE =
"dlab_resource_type";
+ String COLLECTION_BILLING = "billing";
+ String FIELD_DLAB_RESOURCE_ID = "dlab_resource_id";
+ String FIELD_RESOURCE_NAME = "resource_name";
+ String FIELD_PROJECT = "project";
+ String FIELD_DLAB_RESOURCE_TYPE = "dlab_resource_type";
/** Collection billingTotal. */
- public static final String COLLECTION_BILLING_TOTAL = "billingTotal";
- public static final String FIELD_USAGE_DATE_START = "usage_date_start";
- public static final String FIELD_USAGE_DATE_END = "usage_date_end";
+ String COLLECTION_BILLING_TOTAL = "billingTotal";
+ String FIELD_USAGE_DATE_START = "usage_date_start";
+ String FIELD_USAGE_DATE_END = "usage_date_end";
String BILLING_DATA_COLLECTION = "BillingData";
}
diff --git
a/services/billing-aws/src/main/java/com/epam/dlab/mongo/ResourceItem.java
b/services/billing-aws/src/main/java/com/epam/dlab/mongo/ResourceItem.java
index fb066d3..d92b2d6 100644
--- a/services/billing-aws/src/main/java/com/epam/dlab/mongo/ResourceItem.java
+++ b/services/billing-aws/src/main/java/com/epam/dlab/mongo/ResourceItem.java
@@ -20,43 +20,57 @@
package com.epam.dlab.mongo;
import com.epam.dlab.billing.DlabResourceType;
-import org.apache.commons.lang3.StringUtils;
-
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
+import org.apache.commons.lang3.StringUtils;
-/** The resource of DLab environment.
+/**
+ * The resource of DLab environment.
*/
public class ResourceItem implements Comparable<ResourceItem> {
-
- /** Resource ID. */
+
+ private final String project;
+ /**
+ * Resource ID.
+ */
String resourceId;
-
- /** User friendly name of resource.*/
+
+ /**
+ * User friendly name of resource.
+ */
String resourceName;
-
- /** Type of resource. */
+
+ /**
+ * Type of resource.
+ */
DlabResourceType type;
-
- /** Name of user. */
+
+ /**
+ * Name of user.
+ */
String user;
-
- /** Name of exploratory.*/
+
+ /**
+ * Name of exploratory.
+ */
String exploratoryName;
-
- /** Instantiate resource of DLab environment.
- * @param resourceId resource id.
- * @param type the type of resource.
- * @param user the name of user.
+
+ /**
+ * Instantiate resource of DLab environment.
+ *
+ * @param resourceId resource id.
+ * @param type the type of resource.
+ * @param user the name of user.
* @param exploratoryName the name of exploratory.
*/
public ResourceItem(String resourceId, String resourceName,
DlabResourceType type,
- String user, String exploratoryName) {
+ String user, String
exploratoryName, String project) {
this.resourceId = resourceId;
this.resourceName = resourceName;
this.type = type;
this.user = user;
this.exploratoryName = exploratoryName;
+ this.project = project;
}
@Override
@@ -78,44 +92,58 @@ public class ResourceItem implements
Comparable<ResourceItem> {
}
- /** Returns the resource id. */
+ /**
+ * Returns the resource id.
+ */
public String getResourceId() {
return resourceId;
}
- /** Return user friendly name of resource.*/
+ /**
+ * Return user friendly name of resource.
+ */
public String getResourceName() {
return resourceName;
}
-
- /** Returns the type of resource. */
+
+ /**
+ * Returns the type of resource.
+ */
public DlabResourceType getType() {
return type;
}
-
- /** Returns the name of user. */
+
+ /**
+ * Returns the name of user.
+ */
public String getUser() {
return user;
}
- /** Returns the name of exploratory. */
+ /**
+ * Returns the name of exploratory.
+ */
public String getExploratoryName() {
return exploratoryName;
}
+ public String getProject() {
+ return project;
+ }
-
- /** Returns a string representation of the object.
+ /**
+ * Returns a string representation of the object.
+ *
* @param self the object to generate the string for (typically this),
used only for its class name.
*/
public ToStringHelper toStringHelper(Object self) {
- return MoreObjects.toStringHelper(self)
- .add("resourceId", resourceId)
- .add("resourceName", resourceName)
- .add("type", type)
- .add("user", user)
- .add("exploratoryName", exploratoryName);
- }
+ return MoreObjects.toStringHelper(self)
+ .add("resourceId", resourceId)
+ .add("resourceName", resourceName)
+ .add("type", type)
+ .add("user", user)
+ .add("exploratoryName", exploratoryName);
+ }
@Override
public String toString() {
diff --git
a/services/billing-aws/src/main/java/com/epam/dlab/mongo/ResourceItemList.java
b/services/billing-aws/src/main/java/com/epam/dlab/mongo/ResourceItemList.java
index d364b7c..d5c0091 100644
---
a/services/billing-aws/src/main/java/com/epam/dlab/mongo/ResourceItemList.java
+++
b/services/billing-aws/src/main/java/com/epam/dlab/mongo/ResourceItemList.java
@@ -19,40 +19,46 @@
package com.epam.dlab.mongo;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Vector;
-
import com.epam.dlab.billing.DlabResourceType;
+import com.google.common.base.MoreObjects;
import org.apache.commons.lang3.StringUtils;
-import com.google.common.base.MoreObjects;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Vector;
-/** List of the DLab's resources.
+/**
+ * List of the DLab's resources.
*/
public class ResourceItemList {
- /** List of the resources. */
+ /**
+ * List of the resources.
+ */
private final Vector<ResourceItem> list;
-
-
- /** Constructs an empty list of resources.
- */
+
+
+ /**
+ * Constructs an empty list of resources.
+ */
public ResourceItemList() {
list = new Vector<>();
}
-
-
- /** Appends the resource to the list and returns it.
- * @param resourceId the resource id.
- * @param resourceName the user friendly name of resource.
- * @param type the type of resource.
- * @param user the name of user.
+
+
+ /**
+ * Appends the resource to the list and returns it.
+ *
+ * @param resourceId the resource id.
+ * @param resourceName the user friendly name of resource.
+ * @param type the type of resource.
+ * @param user the name of user.
* @param exploratoryName the name of exploratory.
* @return Instance of the resource.
*/
- public ResourceItem append(String resourceId, String resourceName,
DlabResourceType type, String user, String exploratoryName) {
- ResourceItem item = new ResourceItem(resourceId, resourceName,
type, user, exploratoryName);
- synchronized (this) {
+ public ResourceItem append(String resourceId, String resourceName,
DlabResourceType type, String user,
+ String
exploratoryName, String project) {
+ ResourceItem item = new ResourceItem(resourceId, resourceName,
type, user, exploratoryName, project);
+ synchronized (this) {
int index = Collections.binarySearch(list, item);
if (index < 0) {
index = -index;
@@ -64,51 +70,65 @@ public class ResourceItemList {
} else {
item = list.get(index);
}
- }
+ }
return item;
}
- /** Returns the number of the range in list. */
+ public ResourceItem append(String resourceId, String resourceName,
DlabResourceType type) {
+ return append(resourceId, resourceName, type, null, null, null);
+ }
+
+ /**
+ * Returns the number of the range in list.
+ */
public int size() {
return list.size();
}
- /** Returns the resource.
+ /**
+ * Returns the resource.
+ *
* @param index index of the resource.
*/
public ResourceItem get(int index) {
return list.get(index);
}
- /** Comparator for search resource item by resource id. */
- private final ResourceItem findItemById = new ResourceItem(null, null,
null, null, null);
+ /**
+ * Comparator for search resource item by resource id.
+ */
+ private final ResourceItem findItemById = new ResourceItem(null, null,
null, null, null, null);
private final ComparatorByName compareByName = new ComparatorByName();
+
private class ComparatorByName implements Comparator<ResourceItem> {
-
+
@Override
public int compare(ResourceItem o1, ResourceItem o2) {
return StringUtils.compare(o1.resourceId,
o2.resourceId);
}
-
+
}
-
- /** Find and return the resource by resource id.
- * @param index index of the resource.
+
+ /**
+ * Find and return the resource by resource id.
+ *
+ * @param resourceId index of the resource.
*/
public ResourceItem getById(String resourceId) {
findItemById.resourceId = resourceId;
int index = Collections.binarySearch(list, findItemById,
compareByName);
-
+
return (index < 0 ? null : list.get(index));
}
- /** Removes all of the elements from list.
+ /**
+ * Removes all of the elements from list.
*/
public void clear() {
list.clear();
}
-
-
+
+
@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("items",
list).toString();
diff --git
a/services/billing-aws/src/test/java/com/epam/dlab/mongo/ResourceItemListTest.java
b/services/billing-aws/src/test/java/com/epam/dlab/mongo/ResourceItemListTest.java
index 28769bd..1c90bb8 100644
---
a/services/billing-aws/src/test/java/com/epam/dlab/mongo/ResourceItemListTest.java
+++
b/services/billing-aws/src/test/java/com/epam/dlab/mongo/ResourceItemListTest.java
@@ -29,8 +29,8 @@ public class ResourceItemListTest {
@Test
public void append() {
ResourceItemList list = new ResourceItemList();
- list.append("tag-user-nb-exp", "exp",
DlabResourceType.EXPLORATORY, "user", "exp");
- list.append("tag-user-emr-exp-comp", "comp",
DlabResourceType.COMPUTATIONAL, "user", "exp");
+ list.append("tag-user-nb-exp", "exp",
DlabResourceType.EXPLORATORY, "user", "exp", "");
+ list.append("tag-user-emr-exp-comp", "comp",
DlabResourceType.COMPUTATIONAL, "user", "exp", "");
assertEquals(2, list.size());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]