aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2018-02-14 15:30:07 +0100
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2018-02-14 15:30:07 +0100
commit9ebb9c1aa320e49c581ba1a66202cc2f2bda0c5a (patch)
tree658398df111f90c19fe158c7c9abe040a850d49d /src/main/java
parent454936e900890e77adc9a1450e5bcb01d0c90823 (diff)
Rework the SDC cache
Rework the SDC cache that was broken and add unit tests to validate it Issue-ID: CLAMP-85 Change-Id: I43503702733d8f8f0ddbf391f94fb4e5416be98f Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/clamp/clds/dao/CldsDao.java22
-rw-r--r--src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java24
-rw-r--r--src/main/java/org/onap/clamp/clds/model/CldsDBServiceCache.java16
-rw-r--r--src/main/java/org/onap/clamp/clds/model/CldsServiceData.java27
4 files changed, 49 insertions, 40 deletions
diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java
index 088d47332..5946416ad 100644
--- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java
+++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java
@@ -354,19 +354,31 @@ public class CldsDao {
return template;
}
+ public void clearServiceCache() {
+ String clearCldsServiceCacheSql = "TRUNCATE clds_service_cache";
+ jdbcTemplateObject.execute(clearCldsServiceCacheSql);
+ }
+
public CldsServiceData getCldsServiceCache(String invariantUUID) {
CldsServiceData cldsServiceData = null;
- List<CldsServiceData> cldsServiceDataList = new ArrayList<>();
try {
String getCldsServiceSQL = "SELECT * , TIMESTAMPDIFF(SECOND, timestamp, CURRENT_TIMESTAMP()) FROM clds_service_cache where invariant_service_id = ? ";
cldsServiceData = jdbcTemplateObject.queryForObject(getCldsServiceSQL, new Object[] {
invariantUUID
}, new CldsServiceDataMapper());
- logger.info("value of cldsServiceDataList: {}", cldsServiceDataList);
+ if (cldsServiceData != null) {
+ logger.info("CldsServiceData found in cache for Service Invariant ID:"
+ + cldsServiceData.getServiceInvariantUUID());
+ return cldsServiceData;
+ } else {
+ logger.warn("CldsServiceData not found in cache for Service Invariant ID:" + invariantUUID);
+ return null;
+ }
} catch (EmptyResultDataAccessException e) {
- logger.warn("cache row not found for invariantUUID: " + invariantUUID, e);
+ logger.info("CldsServiceData not found in cache for Service Invariant ID: " + invariantUUID);
+ logger.debug("CldsServiceData not found in cache for Service Invariant ID: " + invariantUUID, e);
+ return null;
}
- return cldsServiceData;
}
public void setCldsServiceCache(CldsDBServiceCache cldsDBServiceCache) {
@@ -401,7 +413,7 @@ public class CldsDao {
* @return list of CldsModelProp
*/
public List<CldsModelProp> getDeployedModelProperties() {
- List<CldsModelProp> cldsModelPropList = new ArrayList<CldsModelProp>();
+ List<CldsModelProp> cldsModelPropList = new ArrayList<>();
String modelsSql = "select m.model_id, m.model_name, mp.model_prop_id, mp.model_prop_text FROM model m, model_properties mp, event e "
+ "WHERE m.model_prop_id = mp.model_prop_id and m.event_id = e.event_id and e.action_cd = 'DEPLOY'";
List<Map<String, Object>> rows = jdbcTemplateObject.queryForList(modelsSql);
diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java b/src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java
index 91d895054..470354a73 100644
--- a/src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java
+++ b/src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,35 +27,33 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import org.apache.commons.io.serialization.ValidatingObjectInputStream;
-import java.sql.Blob;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
+import org.apache.commons.io.serialization.ValidatingObjectInputStream;
import org.onap.clamp.clds.model.CldsServiceData;
+import org.onap.clamp.clds.model.CldsVfData;
+import org.onap.clamp.clds.model.CldsVfcData;
import org.springframework.jdbc.core.RowMapper;
/**
* Generic mapper for CldsDBServiceCache
*/
public final class CldsServiceDataMapper implements RowMapper<CldsServiceData> {
+
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDao.class);
@Override
public CldsServiceData mapRow(ResultSet rs, int rowNum) throws SQLException {
CldsServiceData cldsServiceData = new CldsServiceData();
- long age;
- age = rs.getLong(5);
- Blob blob = rs.getBlob(4);
- InputStream is = blob.getBinaryStream();
- try (ValidatingObjectInputStream oip = new ValidatingObjectInputStream(is)) {
- oip.accept(CldsServiceData.class);
+ try (ValidatingObjectInputStream oip = new ValidatingObjectInputStream(rs.getBlob(4).getBinaryStream())) {
+ oip.accept(CldsServiceData.class, ArrayList.class, CldsVfData.class, CldsVfcData.class);
cldsServiceData = (CldsServiceData) oip.readObject();
- cldsServiceData.setAgeOfRecord(age);
+ cldsServiceData.setAgeOfRecord(rs.getLong(5));
} catch (IOException | ClassNotFoundException e) {
- logger.error("Error caught while retrieving cldsServiceData from database", e);
+ logger.error("Error caught while deserializing cldsServiceData from database", e);
+ return null;
}
return cldsServiceData;
}
diff --git a/src/main/java/org/onap/clamp/clds/model/CldsDBServiceCache.java b/src/main/java/org/onap/clamp/clds/model/CldsDBServiceCache.java
index f9a760b77..80e8d8538 100644
--- a/src/main/java/org/onap/clamp/clds/model/CldsDBServiceCache.java
+++ b/src/main/java/org/onap/clamp/clds/model/CldsDBServiceCache.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,10 +31,16 @@ import java.io.ObjectOutputStream;
public class CldsDBServiceCache {
- private String invariantId;
- private String serviceId;
+ private String invariantId;
+ private String serviceId;
private InputStream cldsDataInstream;
+ public CldsDBServiceCache(CldsServiceData cldsServiceData) throws IOException {
+ setCldsDataInstream(cldsServiceData);
+ setInvariantId(cldsServiceData.getServiceInvariantUUID());
+ setServiceId(cldsServiceData.getServiceUUID());
+ }
+
public String getInvariantId() {
return invariantId;
}
@@ -55,6 +61,10 @@ public class CldsDBServiceCache {
return cldsDataInstream;
}
+ public void setCldsDataInstream(InputStream cldsDataInputstream) {
+ this.cldsDataInstream = cldsDataInputstream;
+ }
+
public void setCldsDataInstream(CldsServiceData cldsServiceData) throws IOException {
this.cldsDataInstream = getInstreamFromObject(cldsServiceData);
}
diff --git a/src/main/java/org/onap/clamp/clds/model/CldsServiceData.java b/src/main/java/org/onap/clamp/clds/model/CldsServiceData.java
index 943532f02..1a4b4dcf9 100644
--- a/src/main/java/org/onap/clamp/clds/model/CldsServiceData.java
+++ b/src/main/java/org/onap/clamp/clds/model/CldsServiceData.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,20 +32,17 @@ import java.util.List;
import javax.ws.rs.NotAuthorizedException;
-import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.service.CldsService;
public class CldsServiceData implements Serializable {
- private static final long serialVersionUID = -9153372664377279423L;
-
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsServiceData.class);
- protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
-
- private String serviceInvariantUUID;
- private String serviceUUID;
- private Long ageOfRecord;
- private List<CldsVfData> cldsVfs;
+ private static final long serialVersionUID = -9153372664377279423L;
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsServiceData.class);
+ protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+ private String serviceInvariantUUID;
+ private String serviceUUID;
+ private Long ageOfRecord;
+ private List<CldsVfData> cldsVfs;
public String getServiceInvariantUUID() {
return serviceInvariantUUID;
@@ -71,14 +68,6 @@ public class CldsServiceData implements Serializable {
this.serviceUUID = serviceUUID;
}
- public CldsServiceData getCldsServiceCache(CldsDao cldsDao, String invariantServiceUUID) {
- return cldsDao.getCldsServiceCache(invariantServiceUUID);
- }
-
- public void setCldsServiceCache(CldsDao cldsDao, CldsDBServiceCache cldsDBServiceCache) {
- cldsDao.setCldsServiceCache(cldsDBServiceCache);
- }
-
public Long getAgeOfRecord() {
return ageOfRecord;
}