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 2019/10/28 11:33:32 UTC

[incubator-dlab] branch DLAB-1036 created (now 8da35a2)

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

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


      at 8da35a2  [DLAB-1036] Pass user/project/endpoint/custom tags to FE on Billing Report page

This branch includes the following new commits:

     new 8da35a2  [DLAB-1036] Pass user/project/endpoint/custom tags to FE on Billing Report page

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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


[incubator-dlab] 01/01: [DLAB-1036] Pass user/project/endpoint/custom tags to FE on Billing Report page

Posted by of...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8da35a2f60ba5da0da5e8d8f2b40bef94ff50066
Author: Oleh Fuks <ol...@gmail.com>
AuthorDate: Mon Oct 28 13:33:01 2019 +0200

    [DLAB-1036] Pass user/project/endpoint/custom tags to FE on Billing Report page
---
 .../epam/dlab/backendapi/dao/BaseBillingDAO.java   | 24 ++++++++++++++++++----
 .../epam/dlab/backendapi/dao/ComputationalDAO.java | 16 +++++++++++++++
 .../epam/dlab/backendapi/dao/ExploratoryDAO.java   | 16 +++++++++++++++
 3 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/BaseBillingDAO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/BaseBillingDAO.java
index 0799b90..368791a 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/BaseBillingDAO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/BaseBillingDAO.java
@@ -86,6 +86,7 @@ public abstract class BaseBillingDAO<T extends BillingFilter> extends BaseDAO im
 	protected static final String FIELD_PROJECT = "project";
 	private static final String EDGE_FORMAT = "%s-%s-%s-edge";
 	private static final String PROJECT_COLLECTION = "projects";
+	private static final String TAGS = "tags";
 
 	@Inject
 	protected SettingsDAO settings;
@@ -93,6 +94,10 @@ public abstract class BaseBillingDAO<T extends BillingFilter> extends BaseDAO im
 	private UserSettingsDAO userSettingsDAO;
 	@Inject
 	private ProjectDAO projectDAO;
+	@Inject
+	private ExploratoryDAO exploratoryDAO;
+	@Inject
+	private ComputationalDAO computationalDAO;
 
 	@Override
 	public Document getReport(UserInfo userInfo, T filter) {
@@ -144,16 +149,18 @@ public abstract class BaseBillingDAO<T extends BillingFilter> extends BaseDAO im
 
 			costTotal += d.getDouble(MongoKeyWords.COST);
 
+			final String dlabResourceType = id.getString("dlab_resource_type");
 			final String statusString = Optional
 					.ofNullable(status)
 					.map(UserInstanceStatus::toString)
 					.orElse(StringUtils.EMPTY);
+
 			Document item = new Document()
 					.append(MongoKeyWords.DLAB_USER, getUserOrDefault(id.getString(USER)))
 					.append(dlabIdFieldName(), resourceId)
 					.append(shapeFieldName(), generateShapeName(shape))
-					.append("dlab_resource_type", DlabResourceType.getResourceTypeName(id.getString(
-							"dlab_resource_type"))) //todo check on azure!!!
+					.append("dlab_resource_type", DlabResourceType
+							.getResourceTypeName(dlabResourceType)) //todo check on azure!!!
 					.append(STATUS, statusString)
 					.append(FIELD_RESOURCE_TYPE, resourceType(id))
 					.append(productFieldName(), id.getString(productFieldName()))
@@ -163,8 +170,8 @@ public abstract class BaseBillingDAO<T extends BillingFilter> extends BaseDAO im
 							.COST)))
 					.append(currencyCodeFieldName(), id.getString(currencyCodeFieldName()))
 					.append(usageDateFromFieldName(), dateStart)
-					.append(usageDateToFieldName(), dateEnd);
-
+					.append(usageDateToFieldName(), dateEnd)
+					.append(TAGS, getExploratoryTags(resourceId, dlabResourceType));
 
 			reportItems.add(item);
 		}
@@ -405,6 +412,15 @@ public abstract class BaseBillingDAO<T extends BillingFilter> extends BaseDAO im
 		return shapeNames == null || shapeNames.isEmpty() || Arrays.stream(shapes).anyMatch(shapeNames::contains);
 	}
 
+	private Map<String, String> getExploratoryTags(String resourceId, String dlabResourceType) {
+		if (DlabResourceType.EXPLORATORY.name().equals(dlabResourceType)) {
+			return exploratoryDAO.findTagsById(resourceId);
+		} else if (DlabResourceType.COMPUTATIONAL.name().equals(dlabResourceType)) {
+			return computationalDAO.findTagsById(resourceId);
+		}
+		return Collections.emptyMap();
+	}
+
 	protected void appendSsnAndEdgeNodeType(List<String> shapeNames, Map<String, ShapeInfo> shapes) {
 		final String ssnShape = getSsnShape();
 		if (shapeNames == null || shapeNames.isEmpty() || shapeNames.contains(ssnShape)) {
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ComputationalDAO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ComputationalDAO.java
index 311158a..7c271c7 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ComputationalDAO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ComputationalDAO.java
@@ -65,6 +65,7 @@ public class ComputationalDAO extends BaseDAO {
 	private static final String COMPUTATIONAL_URL_URL = "url";
 	private static final String COMPUTATIONAL_LAST_ACTIVITY = "last_activity";
 	private static final String CONFIG = "config";
+	private static final String TAGS = "tags";
 
 	private static String computationalFieldFilter(String fieldName) {
 		return COMPUTATIONAL_RESOURCES + FIELD_SET_DELIMETER + fieldName;
@@ -130,6 +131,21 @@ public class ComputationalDAO extends BaseDAO {
 	}
 
 	/**
+	 * Finds and returns tags of computational resource.
+	 *
+	 * @param computationalId id of computational resource.
+	 * @return map of tags or empty map.
+	 */
+	@SuppressWarnings("unchecked")
+	public Map<String, String> findTagsById(String computationalId) {
+		return findOne(USER_INSTANCES, elemMatch(COMPUTATIONAL_RESOURCES, eq(COMPUTATIONAL_ID, computationalId)),
+				fields(include(COMPUTATIONAL_RESOURCES + "." + TAGS), excludeId()))
+				.map(d -> ((List<Document>) d.get(COMPUTATIONAL_RESOURCES)).get(0))
+				.map(d -> ((Map<String, String>) d.get(TAGS)))
+				.orElse(Collections.emptyMap());
+	}
+
+	/**
 	 * Updates the status of computational resource in Mongo database.
 	 *
 	 * @param dto object of computational resource status.
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryDAO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryDAO.java
index ca11b9d..63cb211 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryDAO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryDAO.java
@@ -42,6 +42,7 @@ import static com.epam.dlab.backendapi.dao.MongoCollections.USER_INSTANCES;
 import static com.epam.dlab.backendapi.dao.SchedulerJobDAO.SCHEDULER_DATA;
 import static com.mongodb.client.model.Filters.*;
 import static com.mongodb.client.model.Projections.*;
+import static com.mongodb.client.model.Projections.excludeId;
 import static com.mongodb.client.model.Updates.set;
 import static java.util.stream.Collectors.toList;
 import static org.apache.commons.lang3.StringUtils.EMPTY;
@@ -68,6 +69,7 @@ public class ExploratoryDAO extends BaseDAO {
 	public static final String EXPLORATORY_NOT_FOUND_MSG = "Exploratory for user %s with name %s not found";
 	private static final String EXPLORATORY_LAST_ACTIVITY = "last_activity";
 	private static final String PROJECT = "project";
+	private static final String TAGS = "tags";
 
 	public ExploratoryDAO() {
 		log.info("{} is initialized", getClass().getSimpleName());
@@ -108,6 +110,20 @@ public class ExploratoryDAO extends BaseDAO {
 	}
 
 	/**
+	 * Finds and returns exploratory tags.
+	 *
+	 * @param exploratoryId id of computational resource.
+	 * @return map of tags or empty map.
+	 */
+	@SuppressWarnings("unchecked")
+	public Map<String, String> findTagsById(String exploratoryId) {
+		return findOne(USER_INSTANCES, eq(EXPLORATORY_ID, exploratoryId),
+				fields(include("tags"), excludeId()))
+				.map(d -> ((Map<String, String>) d.get(TAGS)))
+				.orElse(Collections.emptyMap());
+	}
+
+	/**
 	 * Finds and returns the unique id for exploratory.
 	 *
 	 * @param user            user name.


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