[SECIOTSRK-464] Merge old structure with new structure
authorYevhen Zozulia <y.zozulia@surc.local>
Tue, 22 Aug 2017 14:36:14 +0000 (17:36 +0300)
committerYevhen Zozulia <y.zozulia@surc.local>
Thu, 31 Aug 2017 09:41:50 +0000 (12:41 +0300)
13 files changed:
servers/commons/pom.xml
servers/dsm/src/main/resources/spring-database.xml
servers/dsm/src/test/resources/spring-database.xml
servers/mq/src/main/java/com/samsung/servermq/iotivity/KafkaConsumerWrapper.java
servers/mq/src/main/java/com/samsung/servermq/iotivity/extractor/impl/DeviceRegistrationPostDataExtractor.java
servers/mq/src/main/java/com/samsung/servermq/iotivity/extractor/impl/DeviceUnRegistrationPostDataExtractor.java
servers/mq/src/main/java/com/samsung/servermq/rest/DSMRestController.java
servers/mq/src/main/java/com/samsung/servermq/utils/rest/ServerSenderImpl.java
servers/mq/src/main/resources/iotivity.xml
servers/mq/src/main/resources/spring-database.xml
servers/mq/src/test/resources/iotivity.xml
servers/mq/src/test/resources/logback.xml
servers/mq/src/test/resources/spring-database.xml

index 8e467a0..323ac49 100644 (file)
@@ -11,7 +11,6 @@
     </parent>
 
     <artifactId>commons</artifactId>
-    <version>1.0.0-SNAPSHOT</version>
     <name>Common Components</name>
     <description>Common components for all modules</description>
 
index cb3fceb..ca1f2fd 100644 (file)
@@ -7,7 +7,7 @@
                            http://www.springframework.org/schema/data/jpa
                            http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
                            http://www.springframework.org/schema/tx
-                           http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
+                           http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
 
     <tx:annotation-driven transaction-manager="transactionManager"/>
 
index 12d03cb..97933c5 100644 (file)
@@ -4,8 +4,10 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
-       http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
-       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
+       http://www.springframework.org/schema/data/jpa 
+       http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
+       http://www.springframework.org/schema/tx 
+       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
 
 
     <tx:annotation-driven transaction-manager="transactionManager" />
index f63c682..d32eea6 100644 (file)
@@ -13,8 +13,8 @@ import org.I0Itec.zkclient.ZkClient;
 import org.I0Itec.zkclient.ZkConnection;
 import org.apache.log4j.Logger;
 import org.iotivity.cloud.mqserver.Constants;
+import org.iotivity.cloud.mqserver.kafka.KafkaCommonWrapper;
 import org.iotivity.cloud.mqserver.topic.Topic;
-
 import kafka.admin.AdminUtils;
 import kafka.api.FetchRequest;
 import kafka.api.FetchRequestBuilder;
@@ -243,10 +243,10 @@ public class KafkaConsumerWrapper {
     }
 
     private void createTopic() {
-//        KafkaCommonWrapper kafkaCommonWrapper = new KafkaCommonWrapper(mZookeeper, mBroker);
-//        if (kafkaCommonWrapper.createTopic(mTopicName)) {
-//            getMessages();
-//        }
+        KafkaCommonWrapper kafkaCommonWrapper = new KafkaCommonWrapper(mZookeeper, mBroker);
+        if (kafkaCommonWrapper.createTopic(mTopicName)) {
+            getMessages();
+        }
     }
 
     private Properties buildPropertiesForSubscribe() {
index 8372c2a..b687a09 100644 (file)
@@ -2,6 +2,7 @@ package com.samsung.servermq.iotivity.extractor.impl;
 
 import com.samsung.commons.domain.Device;
 import com.samsung.commons.domain.User;
+import com.samsung.commons.service.AgentService;
 import com.samsung.commons.service.DeviceService;
 import com.samsung.commons.service.IotCloudService;
 import org.apache.log4j.Logger;
@@ -19,6 +20,9 @@ public class DeviceRegistrationPostDataExtractor implements PostDataExtractor {
     DeviceService deviceService;
 
     @Autowired
+    AgentService agentService;
+
+    @Autowired
     IotCloudService iotCloudService;
 
     @Override
@@ -33,6 +37,11 @@ public class DeviceRegistrationPostDataExtractor implements PostDataExtractor {
             log.debug("New device with params : did = " + did + ", uid =  " + uid + ", device type = " + name + ", model = " + model + ", route = " + route);
             User user = iotCloudService.findAssociatedUserByUuid(uid);
             Device device = deviceService.init(did, name, type, model, 1, user, route);
+            //TODO: remove or update after Agent functionality implementation
+            //FIXME: test Agent registration for all new devices
+            String testAgentUuid = did + name.hashCode();
+            String testAgentName = "Test Agent";
+            agentService.init(testAgentUuid, testAgentName, device);
             log.info(" Registered device: " + device);
         } catch (Exception e) {
             log.error(e.getMessage(), e);
index 3b1d03f..92ac0a6 100644 (file)
@@ -34,7 +34,7 @@ public class DeviceUnRegistrationPostDataExtractor implements PostDataExtractor
                     Policy policy = policyService.findByDeviceId(device.getId());
                     policyService.remove(policy);
                     deviceService.remove(device);
-                    log.info("Unregistered device: " + device);
+                    log.info("Unregistered device with id: " + did);
                 }
                 if(action.equalsIgnoreCase(MessageQueueKeys.DELETE.getKey())){
                     device.setRemoved(true);
@@ -42,6 +42,7 @@ public class DeviceUnRegistrationPostDataExtractor implements PostDataExtractor
                     log.info("Device mark like removed: " + device);
                 }
             }
+            log.info("Unregistered device with id = " + did);
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }
index 82f141e..0f9833f 100644 (file)
@@ -40,6 +40,7 @@ public class DSMRestController {
     private static final String NOTIFICATION_MESSAGE = "message";
     private static final String NOTIFICATION_TITLE = "title";
     private static final String NOTIFICATION_CODE = "code";
+    private static final String NOTIFICATION_TYPE = "type";
     private static final String POLICY = "policy";
     private static final String DUID = "duid";
     private static final String AGENT = "agent";
@@ -62,7 +63,7 @@ public class DSMRestController {
             return new ResponseEntity<>(BAD_REQUEST);
         }
         Map<String, String> map = notification.getAdditionalMap();
-        map.put(NOTIFICATION_CODE, notification.getCode());
+        map.put(NOTIFICATION_TYPE, notification.getCode());
         map.put(NOTIFICATION_TITLE, notification.getTitle());
         map.put(NOTIFICATION_MESSAGE, notification.getMessage());
         map.put(NOTIFICATION_TIME, Long.toString(notification.getCurrentTime()));
index 3dce035..4280332 100644 (file)
@@ -70,12 +70,12 @@ public class ServerSenderImpl implements ServerSender {
     @Override
     public boolean requestPolicyForAgent(Long policyId, String agentId) {
         try {
-            log.info(format("Send request for policy %s", policyId));
+            log.debug(format("Send request for policy %s", policyId));
             URI url = new URI(host + REST_FOR_REQUEST_POLICY + policyId + "/agent/" + agentId);
-            log.info("Send to " + url);
+            log.debug("Send to " + url);
             @SuppressWarnings("rawtypes")
             ResponseEntity result = restTemplate.exchange(url, POST, null, ResponseEntity.class);
-            log.info("Response " + result);
+            log.debug("Response " + result);
             return result.getStatusCode() == OK;
         } catch (URISyntaxException e) {
             log.error(e.getMessage(), e);
index 43eef09..e50f29b 100644 (file)
@@ -6,6 +6,7 @@
                            http://www.springframework.org/schema/task
                            http://www.springframework.org/schema/task/spring-task-4.3.xsd">
 
+
 <!-- <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
 <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
   <property name="autodetect" value="true"/>
@@ -22,7 +23,7 @@
                 <entry key="Listener:name=unreg" value-ref="deviceUnRegListener" />
             </map>
         </property>
-    </bean> --> 
+    </bean>  -->
 
     <bean id="reportExtractor"
         class="com.samsung.servermq.iotivity.extractor.impl.ReportPostDataExtractor" />
@@ -36,7 +37,7 @@
     <task:scheduled-tasks scheduler="listenerScheduler">
         <task:scheduled ref="reportListener" method="getMessages"
             fixed-delay="${iotivity.listener_delay}" />
-        <task:scheduled ref="policytListener" method="getMessages"
+        <task:scheduled ref="policyListener" method="getMessages"
             fixed-delay="${iotivity.listener_delay}" />
         <task:scheduled ref="deviceRegListener" method="getMessages"
             fixed-delay="${iotivity.listener_delay}" />
@@ -55,7 +56,7 @@
         <constructor-arg name="listenerName" value="Report Listener" />
     </bean>
 
-    <bean id="policytListener" class="com.samsung.servermq.iotivity.MessageQueueListener">
+    <bean id="policyListener" class="com.samsung.servermq.iotivity.MessageQueueListener">
         <constructor-arg name="zookeperHost"
             value="${iotivity.zookeper_host}" />
         <constructor-arg name="kafkaHost" value="${iotivity.kafka_host}" />
index 363e690..ec174b9 100644 (file)
@@ -1,5 +1,6 @@
 <beans xmlns="http://www.springframework.org/schema/beans"
-    xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx"
+    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
+    xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
@@ -49,8 +50,7 @@
                 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                 <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                 <prop key="hibernate.hbm2ddl.import_files">${hibernate.hbm2ddl.import_files}</prop>
-                <prop key="hibernate.temp.use_jdbc_metadata_defaults">${hibernate.temp.use_jdbc_metadata_defaults}
-                </prop>
+                <prop key="hibernate.temp.use_jdbc_metadata_defaults">${hibernate.temp.use_jdbc_metadata_defaults}</prop>
             </props>
         </property>
     </bean>
index 3697333..aa60483 100644 (file)
@@ -1,8 +1,10 @@
 <beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+    xmlns:task="http://www.springframework.org/schema/task"
+    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
-       http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">
+       http://www.springframework.org/schema/task 
+       http://www.springframework.org/schema/task/spring-task-4.3.xsd">
 
 <bean id="reportExtractor"
                class="com.samsung.servermq.iotivity.extractor.impl.ReportPostDataExtractor" />
@@ -16,7 +18,7 @@
        <!-- <task:scheduled-tasks scheduler="listenerScheduler">
                <task:scheduled ref="reportListener" method="getMessages"
                        fixed-delay="5000" />
-               <task:scheduled ref="policytListener" method="getMessages"
+               <task:scheduled ref="policyListener" method="getMessages"
                        fixed-delay="5000" />
                <task:scheduled ref="deviceRegListener" method="getMessages"
                        fixed-delay="5000" />
@@ -34,7 +36,7 @@
                <constructor-arg name="listenerName" value="Report Listener" />
        </bean>
 
-       <bean id="policytListener" class="com.samsung.servermq.iotivity.MessageQueueListener">
+       <bean id="policyListener" class="com.samsung.servermq.iotivity.MessageQueueListener">
                <constructor-arg name="zookeperHost" value="106.125.46.44:2181" />
                <constructor-arg name="kafkaHost" value="106.125.46.44:9092" />
                <constructor-arg name="topicName" value="/oic/ps/srv/policy" />
index 5ae5407..b12dc76 100644 (file)
@@ -26,5 +26,4 @@
     <root level="error">
         <appender-ref ref="STDOUT" />
     </root>
-  <jmxConfigurator />
 </configuration>
\ No newline at end of file
index 918d2e2..e069843 100644 (file)
@@ -4,8 +4,10 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
-       http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
-       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
+       http://www.springframework.org/schema/data/jpa 
+       http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
+       http://www.springframework.org/schema/tx 
+       http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
 
 
     <tx:annotation-driven transaction-manager="transactionManager" />