summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/common')
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java71
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/PomFile.java4
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java3
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/JSONAssert.java2
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java14
5 files changed, 59 insertions, 35 deletions
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java
index cc7fafb76..b73d3eadc 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/IndicesEntry.java
@@ -22,8 +22,12 @@
package org.onap.ccsdk.features.sdnr.wt.common.database.data;
import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
/**
* @author Michael Dürre
@@ -34,14 +38,6 @@ import java.util.regex.Pattern;
*/
public class IndicesEntry {
- private static final String regex =
- "^(yellow|red|green)[\\ ]+([^\\ ]*)[\\ ]+([^\\ ]*)[\\ ]+([^\\ ]*)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([^\\ ]+)[\\ ]+([^\\ ]+)$";
- private static final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
- //for ES 2.2.0
- private static final String regexOld =
- "^(yellow|red|green)[\\ ]+([^\\ ]*)[\\ ]+([^\\ ]*)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([0-9]+)[\\ ]+([^\\ ]+)[\\ ]+([^\\ ]+)$";
- private static final Pattern patternOld = Pattern.compile(regexOld, Pattern.MULTILINE);
-
private final String status;
private final String status2;
private final String name;
@@ -108,33 +104,42 @@ public class IndicesEntry {
}
public IndicesEntry(String line) throws ParseException {
- Matcher matcher = pattern.matcher(line.trim());
- if (!matcher.find() || matcher.groupCount() < 10) {
- matcher = patternOld.matcher(line.trim());
- if (!matcher.find() || matcher.groupCount() < 9) {
+ List<String> allElem = Arrays.stream(line.split(" ")).filter(e -> !e.isEmpty()).collect(Collectors.toList());
+ List<String> possibleStatus = List.of("yellow","red","green");
+ if (allElem.isEmpty() || !possibleStatus.contains(allElem.get(0))) {
+ throw new ParseException("unable to parse status:" + line, 0);
+ }
+ try {
+ if (allElem.size() == 10) {
+ // new format
+ this.status = allElem.get(0);
+ this.status2 = allElem.get(1);
+ this.name = allElem.get(2);
+ this.hash = allElem.get(3);
+ this.shards = Integer.parseInt(allElem.get(4));
+ this.replicas = Integer.parseInt(allElem.get(5));
+ this.c1 = Integer.parseInt(allElem.get(6));
+ this.c2 = Integer.parseInt(allElem.get(7));
+ this.size1 = allElem.get(8);
+ this.size2 = allElem.get(9);
+ } else if (allElem.size() == 9) {
+ // old format without hash
+ //for ES 2.2.0
+ this.status = allElem.get(0);
+ this.status2 = allElem.get(1);
+ this.name = allElem.get(2);
+ this.hash = "";
+ this.shards = Integer.parseInt(allElem.get(3));
+ this.replicas = Integer.parseInt(allElem.get(4));
+ this.c1 = Integer.parseInt(allElem.get(5));
+ this.c2 = Integer.parseInt(allElem.get(6));
+ this.size1 = allElem.get(7);
+ this.size2 = allElem.get(8);
+ } else {
throw new ParseException("unable to parse string:" + line, 0);
}
- this.status = matcher.group(1);
- this.status2 = matcher.group(2);
- this.name = matcher.group(3);
- this.hash = "";
- this.shards = Integer.parseInt(matcher.group(4));
- this.replicas = Integer.parseInt(matcher.group(5));
- this.c1 = Integer.parseInt(matcher.group(6));
- this.c2 = Integer.parseInt(matcher.group(7));
- this.size1 = matcher.group(8);
- this.size2 = matcher.group(9);
- } else {
- this.status = matcher.group(1);
- this.status2 = matcher.group(2);
- this.name = matcher.group(3);
- this.hash = matcher.group(4);
- this.shards = Integer.parseInt(matcher.group(5));
- this.replicas = Integer.parseInt(matcher.group(6));
- this.c1 = Integer.parseInt(matcher.group(7));
- this.c2 = Integer.parseInt(matcher.group(8));
- this.size1 = matcher.group(9);
- this.size2 = matcher.group(10);
+ } catch (NumberFormatException e) {
+ throw new ParseException("unable to parse int:" + line, 0);
}
}
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/PomFile.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/PomFile.java
index 2e0701257..3e823061b 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/PomFile.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/file/PomFile.java
@@ -26,6 +26,7 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
+import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -44,7 +45,8 @@ public class PomFile {
// documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
// documentBuilderFactory.setFeature(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
// documentBuilderFactory.setFeature(XMLInputFactory.SUPPORT_DTD, false);
-
+ documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+ documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
this.xmlDoc = documentBuilder.parse(is);
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java
index de878a5d5..d149ae64c 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java
@@ -90,6 +90,9 @@ public class BaseHTTPClient {
}
public BaseHTTPClient(String base, boolean trustAllCerts, String certFilename, String passphrase, int sslCertType) {
+ if(base==null) {
+ throw new IllegalArgumentException("no baseUrl given");
+ }
if (!base.endsWith("/")) {
base += "/";
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/JSONAssert.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/JSONAssert.java
index 8b651cbe9..b207c3e00 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/JSONAssert.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/JSONAssert.java
@@ -170,7 +170,7 @@ public class JSONAssert {
};
public static void assertEquals(String def, String toTest, boolean strict) throws JSONException {
- assertEquals(null, def, toTest, strict);
+ assertEquals("", def, toTest, strict);
}
public static void assertEquals(String message, String def, String toTest, boolean strict) throws JSONException {
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java
index c2471f58e..09ec5204c 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java
@@ -68,9 +68,12 @@ public class TestEsData {
public void testIndices() {
IndicesEntryList list = new IndicesEntryList();
IndicesEntry entry = null;
+ IndicesEntry entryOld = null;
try {
entry = new IndicesEntry(
"yellow open inventoryequipment-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 2 3 1.2kb 2.4kb");
+ entryOld = new IndicesEntry(
+ "yellow open inventoryequipment-v1 5 1 2 3 1.2kb 2.4kb");
list.add(entry);
list.add(new IndicesEntry(
"yellow open networkelement-connection-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 0 0 1.2kb 1.2kb"));
@@ -94,6 +97,17 @@ public class TestEsData {
assertEquals("1.2kb", entry.getSize1());
assertEquals("2.4kb", entry.getSize2());
+ assertNotNull(entryOld);
+ assertEquals("yellow", entryOld.getStatus());
+ assertEquals("open", entryOld.getStatus2());
+ assertEquals("inventoryequipment-v1", entryOld.getName());
+ assertEquals("", entryOld.getHash());
+ assertEquals(5, entryOld.getShards());
+ assertEquals(1, entryOld.getReplicas());
+ assertEquals(2, entryOld.getC1());
+ assertEquals(3, entryOld.getC2());
+ assertEquals("1.2kb", entryOld.getSize1());
+ assertEquals("2.4kb", entryOld.getSize2());
}
@Test