summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/feeder/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'components/datalake-handler/feeder/src/main')
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/ApplicationConfiguration.java4
-rwxr-xr-xcomponents/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java121
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java11
-rw-r--r--components/datalake-handler/feeder/src/main/resources/application.properties7
4 files changed, 102 insertions, 41 deletions
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/ApplicationConfiguration.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/ApplicationConfiguration.java
index 05d6e887..b93924c4 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/ApplicationConfiguration.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/ApplicationConfiguration.java
@@ -69,4 +69,8 @@ public class ApplicationConfiguration {
//Kibana
private String kibanaDashboardImportApi;
private Integer kibanaPort;
+
+ //Elasticsearch
+ private String esTemplateMappingApi;
+ private Integer esPort;
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java
index 83120482..d0940baa 100755
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java
@@ -57,6 +57,8 @@ public class DesignService {
private static String POST_FLAG;
+ private static String URL_FlAG;
+
@Autowired
private DesignRepository designRepository;
@@ -150,57 +152,44 @@ public class DesignService {
switch (designTypeEnum) {
case KIBANA_DB:
- resultMap = deployKibanaImport(design);
- if (!resultMap.isEmpty()) {
- Iterator<Map.Entry<Integer, Boolean>> it = resultMap.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<Integer, Boolean> entry = it.next();
- if (entry.getValue()) {
- design.setSubmitted(true);
- designRepository.save(design);
- }
- }
- }
+ log.info("Deploy kibana dashboard");
+ resultMap = deployKibanaDashboardImport(design);
+ deploySave(resultMap, design);
+ break;
case ES_MAPPING:
- //FIXME
- //return postEsMappingTemplate(design, design.getTopicName().getId().toLowerCase());
+ log.info("Deploy elasticsearch mapping template");
+ resultMap = postEsMappingTemplate(design, design.getTopicName().getId().toLowerCase());
+ deploySave(resultMap, design);
+ break;
default:
log.error("Not implemented {}", designTypeEnum);
+ break;
}
+ log.info("Response resultMap: " + resultMap);
return resultMap;
}
- private Map<Integer, Boolean> deployKibanaImport(Design design) {
+ private Map<Integer, Boolean> deployKibanaDashboardImport(Design design) {
+ URL_FlAG = "Kibana";
POST_FLAG = "KibanaDashboardImport";
String requestBody = design.getBody();
Set<Db> dbs = design.getDbs();
- Map<Integer, Boolean> deployMap = new HashMap<>();
+ Map<Integer, Boolean> deployKibanaMap = new HashMap<>();
if (!dbs.isEmpty()) {
- Map<Integer, String> map = new HashMap<>();
- for (Db item : dbs) {
- if (item.isEnabled()) {
- map.put(item.getId(), kibanaImportUrl(item.getHost(), item.getPort()));
- }
- }
+ Map<Integer, String> map = urlMap(dbs, URL_FlAG);
+ log.info("Deploy kibana dashboard url map: " + map);
if (!map.isEmpty()) {
Iterator<Map.Entry<Integer, String>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Integer, String> entry = it.next();
- deployMap.put(entry.getKey(), HttpClientUtil.sendPostKibana(entry.getValue(), requestBody, POST_FLAG));
+ deployKibanaMap.put(entry.getKey(), HttpClientUtil.sendHttpClientPost(entry.getValue(), requestBody, POST_FLAG, URL_FlAG));
}
}
- return deployMap;
+ return deployKibanaMap;
} else {
- return deployMap;
- }
- }
-
- private String kibanaImportUrl(String host, Integer port) {
- if (port == null) {
- port = applicationConfiguration.getKibanaPort();
+ return deployKibanaMap;
}
- return "http://" + host + ":" + port + applicationConfiguration.getKibanaDashboardImportApi();
}
/**
@@ -210,16 +199,74 @@ public class DesignService {
* @param templateName
* @return flag
*/
- public boolean postEsMappingTemplate(Design design, String templateName) {
+ public Map<Integer, Boolean> postEsMappingTemplate(Design design, String templateName) {
+ URL_FlAG = "Elasticsearch";
POST_FLAG = "ElasticsearchMappingTemplate";
String requestBody = design.getBody();
-
- //FIXME
Set<Db> dbs = design.getDbs();
- //submit to each ES in dbs
+ Map<Integer, Boolean> deployEsMap = new HashMap<>();
- //return HttpClientUtil.sendPostHttpClient("http://"+dbService.getElasticsearch().getHost()+":9200/_template/"+templateName, requestBody, POST_FLAG);
- return false;
+ if (!dbs.isEmpty()) {
+ Map<Integer, String> map = urlMap(dbs, URL_FlAG);
+ log.info("Deploy elasticsearch url map: " + map);
+ if (!map.isEmpty()) {
+ Iterator<Map.Entry<Integer, String>> it = map.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry<Integer, String> entry = it.next();
+ deployEsMap.put(entry.getKey(), HttpClientUtil.sendHttpClientPost(entry.getValue()+templateName, requestBody, POST_FLAG, URL_FlAG));
+ }
+ }
+ return deployEsMap;
+ } else {
+ return deployEsMap;
+ }
+ }
+
+ private Map<Integer, String> urlMap (Set<Db> dbs, String flag) {
+ Map<Integer, String> map = new HashMap<>();
+ for (Db item : dbs) {
+ if (item.isEnabled()) {
+ map.put(item.getId(), httpRequestUrl(item.getHost(), item.getPort(), flag));
+ }
+ }
+ return map;
+ }
+
+ private String httpRequestUrl(String host, Integer port, String urlFlag) {
+ String url = "";
+ switch (urlFlag) {
+ case "Kibana":
+ if (port == null) {
+ port = applicationConfiguration.getKibanaPort();
+ }
+ url = "http://" + host + ":" + port + applicationConfiguration.getKibanaDashboardImportApi();
+ log.info("Kibana url: " + url);
+ break;
+ case "Elasticsearch":
+ if (port == null) {
+ port = applicationConfiguration.getEsPort();
+ }
+ url = "http://" + host + ":" + port + applicationConfiguration.getEsTemplateMappingApi();
+ log.info("Elasticsearch url: " + url);
+ break;
+ default:
+ break;
+ }
+ return url;
+ }
+
+ private void deploySave(Map<Integer, Boolean> map, Design design) {
+ if (!map.isEmpty()) {
+ Iterator<Map.Entry<Integer, Boolean>> it = map.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry<Integer, Boolean> entry = it.next();
+ if (entry.getValue()) {
+ design.setSubmitted(true);
+ designRepository.save(design);
+ log.info("Status was modified");
+ }
+ }
+ }
}
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java
index 3ef0648d..64b643ac 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java
@@ -44,6 +44,8 @@ public class HttpClientUtil {
private static final Logger log = LoggerFactory.getLogger(HttpClientUtil.class);
+ private static final String KIBANA = "Kibana";
+
private static final String KIBANA_DASHBOARD_IMPORT = "KibanaDashboardImport";
private static final String ELASTICSEARCH_MAPPING_TEMPLATE = "ElasticsearchMappingTemplate";
@@ -52,11 +54,14 @@ public class HttpClientUtil {
throw new IllegalStateException("Utility class");
}
- public static boolean sendPostKibana(String url, String json, String postFlag) {
+ public static boolean sendHttpClientPost(String url, String json, String postFlag, String urlFlag) {
boolean flag = false;
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
- headers.add("kbn-xsrf","true");
+ if (urlFlag.equals(KIBANA)) {
+ log.info("urlFlag is Kibana, add header");
+ headers.add("kbn-xsrf","true");
+ }
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity<String> request = new HttpEntity<>(json, headers);
ResponseEntity<String> responseEntity = null;
@@ -78,7 +83,7 @@ public class HttpClientUtil {
break;
}
} catch (Exception e) {
- log.debug(e.getMessage());
+ log.debug("Resquest failed: " + e.getMessage());
}
return flag;
}
diff --git a/components/datalake-handler/feeder/src/main/resources/application.properties b/components/datalake-handler/feeder/src/main/resources/application.properties
index aadd3e8d..72fc1ccd 100644
--- a/components/datalake-handler/feeder/src/main/resources/application.properties
+++ b/components/datalake-handler/feeder/src/main/resources/application.properties
@@ -65,4 +65,9 @@ kibanaDashboardImportApi=/api/kibana/dashboards/import?exclude=index-pattern
#####################KibanaPort
kibanaPort=5601
-
+
+#####################Elasticsearch Template API
+esTemplateMappingApi=/_template/
+
+#####################Elasticsearch port
+esPort=9200 \ No newline at end of file