package com.boundary.sdk.event.service.db;

import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.boundary.camel.component.ping.PingConfiguration;
import com.boundary.camel.component.port.PortConfiguration;
import com.boundary.sdk.event.BoundaryEventRouteBuilder;
import com.boundary.sdk.event.service.ServiceCheckRequest;
import com.boundary.sdk.event.service.ServiceTest;

public class ServiceChecksDatabase implements Processor {
	
	private static Logger LOG = LoggerFactory.getLogger(ServiceChecksDatabase.class);


	public ServiceChecksDatabase() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void process(Exchange exchange) throws Exception {
		Message message = exchange.getIn();
		List<Map<String, Object>> list = message.getBody(List.class);
		for (Map<String,Object> row : list) {
			LOG.info(row.toString());
		}
		
		//ListIterator <Map<String,Object>> i = list.listIterator();
		
		
//		{serviceId=1, serviceName=SDN Director, serviceCheckName=SDN Director Service Check, serviceTestId=1, serviceTestName=Check SDN Director host status, serviceTypeName=ping, serviceTypeTableName=t_ping_config, configId=1}
//		{serviceId=1, serviceName=SDN Director, serviceCheckName=SDN Director Service Check, serviceTestId=2, serviceTestName=Check plumgrid process status, serviceTypeName=ssh, serviceTypeTableName=t_port_config, configId=1}
//		{serviceId=1, serviceName=SDN Director, serviceCheckName=SDN Director Service Check, serviceTestId=3, serviceTestName=Check plumgrid-sal process status, serviceTypeName=ssh, serviceTypeTableName=t_port_config, configId=2}
//		{serviceId=1, serviceName=SDN Director, serviceCheckName=SDN Director Service Check, serviceTestId=4, serviceTestName=Check nginx process status, serviceTypeName=ssh, serviceTypeTableName=t_port_config, configId=3}

		
		ServiceCheckRequest request = new ServiceCheckRequest();
		PingConfiguration pingConfig1 = new PingConfiguration();
//		PingConfiguration pingConfig2 = new PingConfiguration();
		PortConfiguration portConfig = new PortConfiguration();
		
		pingConfig1.setHost("184.169.202.188");
//		pingConfig2.setHost("google.com");
		portConfig.setHost("184.169.202.188");
		portConfig.setPort(10010);

		ServiceTest<PingConfiguration> serviceTest = new ServiceTest<PingConfiguration>("Ping AWS Node","ping","AWS Test Node",request.getRequestId(),pingConfig1);
		request.addServiceTest(serviceTest);
		ServiceTest<PortConfiguration> portTest = new ServiceTest<PortConfiguration>("Check port on SDN Directory","port","SDN Director",request.getRequestId(),portConfig);
		request.addServiceTest(portTest);
//		request.addServiceTest(new ServiceTest<PingConfiguration>("ping","Google Web Search",request.getRequestId(),pingConfig2));
		
		message.setBody(request);
	}
}

@@ -1061,75 +1061,8 @@
 %0A%09%09%7D
-%0A%09%09%0A%09%09//ListIterator %3CMap%3CString,Object%3E%3E i = list.listIterator();%0A
 %09%09%0A%09
@@ -2037,27 +2037,27 @@
 uration 
-pingConfig1
+sdnDirector
  = new P
@@ -2137,16 +2137,18 @@
 tion();%0A
+//
 %09%09PortCo
@@ -2202,27 +2202,27 @@
 );%0A%09%09%0A%09%09
-pingConfig1
+sdnDirector
 .setHost
@@ -2220,38 +2220,37 @@
 r.setHost(%221
-84.169.202.188
+92.168.137.11
 %22);%0A//%09%09ping
@@ -2276,24 +2276,26 @@
 ogle.com%22);%0A
+//
 %09%09portConfig
@@ -2323,16 +2323,18 @@
 .188%22);%0A
+//
 %09%09portCo
@@ -2388,27 +2388,31 @@
 ration%3E 
-serviceTest
+pingSDNDirector
  = new S
@@ -2451,39 +2451,47 @@
 ing 
-AWS Node%22,%22ping%22,%22AWS Test Node
+SDN Director Host%22,%22ping%22,%22SDN Director
 %22,re
@@ -2515,19 +2515,19 @@
 d(),
-pingConfig1
+sdnDirector
 );%0A%09
@@ -2554,22 +2554,31 @@
 est(
-serviceTest);%0A
+pingSDNDirector);%0A%09%09%0A//
 %09%09Se
@@ -2679,17 +2679,16 @@
 Director
-y
 %22,%22port%22
@@ -2739,16 +2739,18 @@
 onfig);%0A
+//
 %09%09reques
@@ -2907,16 +2907,17 @@
 2));%0A%09%09%0A
+%0A
 %09%09messag

Add configuration for ping SDN director