ing
This commit is contained in:
parent
88cd40bc05
commit
2fccbc85bb
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -13,7 +13,7 @@
|
||||||
"stopOnEntry": false,
|
"stopOnEntry": false,
|
||||||
"mainClass": "com.loafle.overflow.container.general.GeneralContainer",
|
"mainClass": "com.loafle.overflow.container.general.GeneralContainer",
|
||||||
"projectName": "container_general",
|
"projectName": "container_general",
|
||||||
"args": "${workspaceFolder}/general.pid"
|
"args": "60000"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "java",
|
"type": "java",
|
||||||
|
|
8
pom.xml
8
pom.xml
|
@ -26,7 +26,7 @@
|
||||||
<overflow.container-java.version>1.0.0-SNAPSHOT</overflow.container-java.version>
|
<overflow.container-java.version>1.0.0-SNAPSHOT</overflow.container-java.version>
|
||||||
|
|
||||||
<netty.version>4.1.17.Final</netty.version>
|
<netty.version>4.1.17.Final</netty.version>
|
||||||
<gson.version>2.8.2</gson.version>
|
<jackson.mapper.version>1.9.13</jackson.mapper.version>
|
||||||
<spring.version>5.0.5.RELEASE</spring.version>
|
<spring.version>5.0.5.RELEASE</spring.version>
|
||||||
|
|
||||||
<mysql-connector-java.version>6.0.6</mysql-connector-java.version>
|
<mysql-connector-java.version>6.0.6</mysql-connector-java.version>
|
||||||
|
@ -76,9 +76,9 @@
|
||||||
<version>${netty.version}</version>
|
<version>${netty.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>jackson-mapper-asl</artifactId>
|
||||||
<version>${gson.version}</version>
|
<version>${jackson.mapper.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
|
|
|
@ -2,8 +2,8 @@ package com.loafle.overflow.container.general;
|
||||||
|
|
||||||
import com.loafle.overflow.container.Container;
|
import com.loafle.overflow.container.Container;
|
||||||
import com.loafle.overflow.container.configuration.ContainerConfiguration;
|
import com.loafle.overflow.container.configuration.ContainerConfiguration;
|
||||||
import com.loafle.overflow.container.general.server.GeneralContainerConfiguration;
|
import com.loafle.overflow.container.general.client.GeneralContainerClient;
|
||||||
import com.loafle.overflow.container.general.server.GeneralContainerServer;
|
import com.loafle.overflow.container.general.client.GeneralContainerConfiguration;
|
||||||
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
|
||||||
|
@ -17,12 +17,22 @@ public class GeneralContainer {
|
||||||
String pidFilePath = args[0];
|
String pidFilePath = args[0];
|
||||||
|
|
||||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||||
context.getBeanFactory().registerSingleton(Container.PIDFILE_PATH, pidFilePath);
|
context.getBeanFactory().registerSingleton(Container.PORT_NUMBER, pidFilePath);
|
||||||
context.register(ContainerConfiguration.class, GeneralContainerConfiguration.class);
|
context.register(GeneralContainerConfiguration.class, ContainerConfiguration.class);
|
||||||
context.refresh();
|
context.refresh();
|
||||||
context.registerShutdownHook();
|
context.registerShutdownHook();
|
||||||
GeneralContainerServer server = context.getBean(GeneralContainerServer.class);
|
GeneralContainerClient client = context.getBean(GeneralContainerClient.class);
|
||||||
server.start();
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
client.stop();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
client.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.loafle.overflow.container.general.server;
|
package com.loafle.overflow.container.general.client;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.loafle.overflow.container.general.service.Service;
|
import com.loafle.overflow.container.general.service.Service;
|
||||||
import com.loafle.overflow.container.server.ContainerServer;
|
import com.loafle.overflow.container.client.ContainerClient;
|
||||||
import com.loafle.overflow.core.annotation.RPCService;
|
import com.loafle.overflow.core.annotation.RPCService;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -14,17 +14,17 @@ import org.springframework.stereotype.Component;
|
||||||
import static com.loafle.overflow.core.interfaces.Service.execServices;
|
import static com.loafle.overflow.core.interfaces.Service.execServices;
|
||||||
import static com.loafle.overflow.core.interfaces.Service.ServiceMethodType;
|
import static com.loafle.overflow.core.interfaces.Service.ServiceMethodType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GeneralContainerClient
|
||||||
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class GeneralContainerServer extends ContainerServer {
|
public class GeneralContainerClient extends ContainerClient {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
private Map<Class<?>, Object> services;
|
private Map<Class<?>, Object> services;
|
||||||
|
|
||||||
public GeneralContainerServer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() throws Exception {
|
protected void init() throws Exception {
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
|
@ -39,26 +39,21 @@ public class GeneralContainerServer extends ContainerServer {
|
||||||
});
|
});
|
||||||
|
|
||||||
execServices(this.services, ServiceMethodType.INIT, Service.OrderedServices, false);
|
execServices(this.services, ServiceMethodType.INIT, Service.OrderedServices, false);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
}
|
||||||
protected void onStart() throws Exception {
|
protected void onStart() throws Exception {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
||||||
execServices(this.services, ServiceMethodType.START, Service.OrderedServices, false);
|
execServices(this.services, ServiceMethodType.START, Service.OrderedServices, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() throws Exception {
|
protected void onStop() throws Exception {
|
||||||
execServices(this.services, ServiceMethodType.STOP, Service.OrderedServices, true);
|
execServices(this.services, ServiceMethodType.STOP, Service.OrderedServices, true);
|
||||||
|
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void destroy() throws Exception {
|
protected void destroy() throws Exception {
|
||||||
execServices(this.services, ServiceMethodType.DESTROY, Service.OrderedServices, true);
|
execServices(this.services, ServiceMethodType.DESTROY, Service.OrderedServices, true);
|
||||||
|
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.loafle.overflow.container.general.client;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.loafle.commons.server.websocket.client.Client;
|
||||||
|
import com.loafle.overflow.config.container.ContainerProtocol;
|
||||||
|
import com.loafle.overflow.config.probe.ContainerType;
|
||||||
|
import com.loafle.overflow.container.Container;
|
||||||
|
import com.loafle.overflow.container.general.crawler.Crawlers;
|
||||||
|
import com.loafle.overflow.crawler.Crawler;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.map.DeserializationConfig;
|
||||||
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import io.netty.handler.codec.http.DefaultHttpHeaders;
|
||||||
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
|
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
|
||||||
|
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
|
||||||
|
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GeneralContainerConfiguration
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan(basePackages = { "com.loafle.overflow" })
|
||||||
|
public class GeneralContainerConfiguration {
|
||||||
|
@Autowired
|
||||||
|
@Qualifier(Client.SERVER_URI)
|
||||||
|
protected URI serverURI;
|
||||||
|
|
||||||
|
@Bean(Client.HANDSHAKER)
|
||||||
|
public WebSocketClientHandshaker handshaker() {
|
||||||
|
HttpHeaders customHeaders = new DefaultHttpHeaders();
|
||||||
|
customHeaders.add(ContainerProtocol.HTTPRequestHeaderKey_Container_Method, ContainerProtocol.HTTPRequestHeaderValue_Container_Method_Connect);
|
||||||
|
customHeaders.add(ContainerProtocol.HTTPRequestHeaderKey_Container_Type, ContainerType.GENERNAL.toString());
|
||||||
|
|
||||||
|
return WebSocketClientHandshakerFactory.newHandshaker(serverURI, WebSocketVersion.V13, null, false, customHeaders);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(Container.CRAWLERS)
|
||||||
|
public Map<String, Crawler> crawlers() {
|
||||||
|
return Crawlers.getCrawlers();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ObjectMapper objectMapper() {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
return objectMapper;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +1,16 @@
|
||||||
package com.loafle.overflow.container.general.crawler.impl.wmi;
|
package com.loafle.overflow.container.general.crawler.impl.wmi;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.crawler.Crawler;
|
import com.loafle.overflow.crawler.Crawler;
|
||||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.map.DeserializationConfig;
|
||||||
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -17,10 +18,11 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class WMICrawler implements Crawler {
|
public class WMICrawler implements Crawler {
|
||||||
private Gson gson;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
public WMICrawler() {
|
public WMICrawler() {
|
||||||
this.gson = new Gson();
|
this.objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,7 +89,7 @@ public class WMICrawler implements Crawler {
|
||||||
SensorConfig metaConfig = null;
|
SensorConfig metaConfig = null;
|
||||||
for (String fi : metaFiles) {
|
for (String fi : metaFiles) {
|
||||||
if (fi.indexOf("meta_") > -1) {
|
if (fi.indexOf("meta_") > -1) {
|
||||||
metaConfig = new Gson().fromJson(new InputStreamReader(new FileInputStream(new File(path + "/" + fi))), SensorConfig.class);
|
metaConfig = this.objectMapper.readValue(new FileInputStream(new File(path + "/" + fi)), SensorConfig.class);
|
||||||
if (metaConfig != null) {
|
if (metaConfig != null) {
|
||||||
retList.add(metaConfig);
|
retList.add(metaConfig);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
package com.loafle.overflow.container.general.server;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.loafle.overflow.container.Container;
|
|
||||||
import com.loafle.overflow.container.general.crawler.Crawlers;
|
|
||||||
import com.loafle.overflow.crawler.Crawler;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GeneralContainerConfiguration
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan(basePackages = { "com.loafle.overflow" })
|
|
||||||
public class GeneralContainerConfiguration {
|
|
||||||
|
|
||||||
@Bean(Container.PIPELINE_CHANNEL_HANDLERS)
|
|
||||||
public List<ChannelHandler> pipelineChannelHandlers() {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(Container.CRAWLERS)
|
|
||||||
public Map<String, Crawler> crawlers() {
|
|
||||||
return Crawlers.getCrawlers();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,10 +1,16 @@
|
||||||
package com.loafle.overflow.container.general.crawler;
|
package com.loafle.overflow.container.general.crawler;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.map.DeserializationConfig;
|
||||||
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
public abstract class CrawlerTest {
|
public abstract class CrawlerTest {
|
||||||
|
protected ObjectMapper objectMapper;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
this.objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.loafle.overflow.container.general.crawler.impl.database;
|
package com.loafle.overflow.container.general.crawler.impl.database;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||||
|
|
||||||
|
@ -38,9 +37,8 @@ public abstract class DatabaseCrawlerTest extends CrawlerTest {
|
||||||
protected SensorConfig getSensorConfig(String path) throws IOException {
|
protected SensorConfig getSensorConfig(String path) throws IOException {
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
String filePath = classLoader.getResource(path).getFile();
|
String filePath = classLoader.getResource(path).getFile();
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
SensorConfig c = this.objectMapper.readValue(new FileInputStream(new File(filePath)), SensorConfig.class);
|
||||||
|
|
||||||
SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.loafle.overflow.container.general.crawler.impl.jmx.tomcat;
|
package com.loafle.overflow.container.general.crawler.impl.jmx.tomcat;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.container.general.crawler.impl.jmx.JMXCrawler;
|
import com.loafle.overflow.container.general.crawler.impl.jmx.JMXCrawler;
|
||||||
import com.loafle.overflow.container.general.crawler.impl.jmx.JMXCrawlerTest;
|
import com.loafle.overflow.container.general.crawler.impl.jmx.JMXCrawlerTest;
|
||||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||||
|
@ -10,7 +9,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -30,10 +28,7 @@ public class TomcatCrawlerTest extends JMXCrawlerTest {
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
URL url = classLoader.getResource("config/tomcat/");
|
URL url = classLoader.getResource("config/tomcat/");
|
||||||
String filePath = classLoader.getResource("config/tomcat/example1.json").getFile();
|
String filePath = classLoader.getResource("config/tomcat/example1.json").getFile();
|
||||||
|
SensorConfig c = this.objectMapper.readValue(new FileInputStream(new File(filePath)), SensorConfig.class);
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
|
||||||
|
|
||||||
SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
|
|
||||||
JMXCrawler cr = new JMXCrawler();
|
JMXCrawler cr = new JMXCrawler();
|
||||||
Map<String, String> result = cr.get(c);
|
Map<String, String> result = cr.get(c);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.loafle.overflow.container.general.crawler.impl.mongodb;
|
package com.loafle.overflow.container.general.crawler.impl.mongodb;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||||
|
|
||||||
|
@ -9,7 +8,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
@ -23,9 +21,7 @@ public class MongoDBCrawlerTest extends CrawlerTest {
|
||||||
// read test resources config/example.json
|
// read test resources config/example.json
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
String filePath = classLoader.getResource("config/mongodb/example.json").getFile();
|
String filePath = classLoader.getResource("config/mongodb/example.json").getFile();
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
SensorConfig c = this.objectMapper.readValue(new FileInputStream(new File(filePath)), SensorConfig.class);
|
||||||
|
|
||||||
SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
|
|
||||||
MongoDBCrawler cr = new MongoDBCrawler();
|
MongoDBCrawler cr = new MongoDBCrawler();
|
||||||
Map<String, String> m = cr.get(c);
|
Map<String, String> m = cr.get(c);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.loafle.overflow.container.general.crawler.impl.redis;
|
package com.loafle.overflow.container.general.crawler.impl.redis;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||||
|
|
||||||
|
@ -9,7 +8,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
@ -21,10 +19,7 @@ public class RedisCralwerTest extends CrawlerTest {
|
||||||
public void collectMetric() throws Exception {
|
public void collectMetric() throws Exception {
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
String filePath = classLoader.getResource("config/redis/example.json").getFile();
|
String filePath = classLoader.getResource("config/redis/example.json").getFile();
|
||||||
|
SensorConfig c = this.objectMapper.readValue(new FileInputStream(new File(filePath)), SensorConfig.class);
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
|
||||||
|
|
||||||
SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
|
|
||||||
RedisCralwer rc = new RedisCralwer();
|
RedisCralwer rc = new RedisCralwer();
|
||||||
print("", rc.get(c));
|
print("", rc.get(c));
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.loafle.overflow.container.general.crawler.impl.snmp;
|
package com.loafle.overflow.container.general.crawler.impl.snmp;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||||
|
|
||||||
|
@ -34,10 +33,7 @@ public class SNMPCrawlerTest extends CrawlerTest {
|
||||||
SNMPCrawler c = new SNMPCrawler();
|
SNMPCrawler c = new SNMPCrawler();
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
String filePath = classLoader.getResource("config/snmp/examplev3.json").getFile();
|
String filePath = classLoader.getResource("config/snmp/examplev3.json").getFile();
|
||||||
|
SensorConfig config = this.objectMapper.readValue(new FileInputStream(new File(filePath)), SensorConfig.class);
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
|
||||||
|
|
||||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
|
|
||||||
Map<String, String> result = c.get(config);
|
Map<String, String> result = c.get(config);
|
||||||
|
|
||||||
|
@ -52,10 +48,7 @@ public class SNMPCrawlerTest extends CrawlerTest {
|
||||||
|
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
String filePath = classLoader.getResource("config/snmp/examplev2.json").getFile();
|
String filePath = classLoader.getResource("config/snmp/examplev2.json").getFile();
|
||||||
|
SensorConfig config = this.objectMapper.readValue(new FileInputStream(new File(filePath)), SensorConfig.class);
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
|
||||||
|
|
||||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
|
|
||||||
Map<String, String> result = c.get(config);
|
Map<String, String> result = c.get(config);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.loafle.overflow.container.general.crawler.impl.wmi;
|
package com.loafle.overflow.container.general.crawler.impl.wmi;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||||
|
@ -13,7 +12,6 @@ import org.junit.Test;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -74,9 +72,7 @@ public class WMICrawlerTest extends CrawlerTest {
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
String filePath = classLoader.getResource("config/wmi").getFile();
|
String filePath = classLoader.getResource("config/wmi").getFile();
|
||||||
System.out.println(filePath);
|
System.out.println(filePath);
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
SensorConfig config = this.objectMapper.readValue(new FileInputStream(new File(filePath)), SensorConfig.class);
|
||||||
|
|
||||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
|
|
||||||
// Config c = mapper.readValue(new File(classLoader.getResource("config").getFile()),Config.class);
|
// Config c = mapper.readValue(new File(classLoader.getResource("config").getFile()),Config.class);
|
||||||
|
|
||||||
|
@ -104,9 +100,7 @@ public class WMICrawlerTest extends CrawlerTest {
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
String filePath = classLoader.getResource("config/wmi/example.json").getFile();
|
String filePath = classLoader.getResource("config/wmi/example.json").getFile();
|
||||||
System.out.println(filePath);
|
System.out.println(filePath);
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
SensorConfig config = this.objectMapper.readValue(new FileInputStream(new File(filePath)), SensorConfig.class);
|
||||||
|
|
||||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
|
|
||||||
System.out.println(config);
|
System.out.println(config);
|
||||||
}
|
}
|
||||||
|
@ -117,8 +111,7 @@ public class WMICrawlerTest extends CrawlerTest {
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
String filePath = classLoader.getResource("config/wmi/meta/meta_network.json").getFile();
|
String filePath = classLoader.getResource("config/wmi/meta/meta_network.json").getFile();
|
||||||
|
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
SensorConfig config = this.objectMapper.readValue(new FileInputStream(new File(filePath)), SensorConfig.class);
|
||||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
|
|
||||||
// Map<String, Object> map = new HashMap<>();
|
// Map<String, Object> map = new HashMap<>();
|
||||||
// map.put("id", "administrator");
|
// map.put("id", "administrator");
|
||||||
|
@ -159,8 +152,7 @@ public class WMICrawlerTest extends CrawlerTest {
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
String filePath = classLoader.getResource("config/wmi/test.json").getFile();
|
String filePath = classLoader.getResource("config/wmi/test.json").getFile();
|
||||||
|
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
SensorConfig config = this.objectMapper.readValue(new FileInputStream(new File(filePath)), SensorConfig.class);
|
||||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
|
|
||||||
List<SensorConfig> metaConfigList = loadMetaConfig();
|
List<SensorConfig> metaConfigList = loadMetaConfig();
|
||||||
|
|
||||||
|
@ -198,8 +190,7 @@ public class WMICrawlerTest extends CrawlerTest {
|
||||||
|
|
||||||
for (String fi : metaFiles) {
|
for (String fi : metaFiles) {
|
||||||
if (fi.indexOf("meta_") > -1) {
|
if (fi.indexOf("meta_") > -1) {
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(path + "/" + fi)));
|
SensorConfig config = this.objectMapper.readValue(new FileInputStream(new File(path + "/" + fi)), SensorConfig.class);
|
||||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
retList.add(config);
|
retList.add(config);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user