ing
This commit is contained in:
commit
82719958f9
88
.gitignore
vendored
Normal file
88
.gitignore
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
### Maven template
|
||||
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
|
||||
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
|
||||
!/.mvn/wrapper/maven-wrapper.jar
|
||||
### Java template
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
14
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
.idea/
|
||||
*.iml
|
||||
/target/
|
||||
.settings/
|
||||
.classpath
|
||||
.project
|
27
.vscode/launch.json
vendored
Normal file
27
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Debug",
|
||||
"request": "launch",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "internalConsole",
|
||||
"stopOnEntry": false,
|
||||
"mainClass": "com.loafle.overflow.central.Central",
|
||||
"projectName": "central",
|
||||
"args": "50006"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Debug (Attach)",
|
||||
"request": "attach",
|
||||
"hostName": "localhost",
|
||||
"port": 0
|
||||
}
|
||||
]
|
||||
}
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic"
|
||||
}
|
53
pom.xml
Normal file
53
pom.xml
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.loafle</groupId>
|
||||
<artifactId>maven_parent_jar</artifactId>
|
||||
<version>1.0.0-RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>container-java</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>com.loafle.overflow.container-java</name>
|
||||
|
||||
<properties>
|
||||
<commons.server-java.version>1.0.0-SNAPSHOT</commons.server-java.version>
|
||||
<overflow.commons-java.version>1.0.0-SNAPSHOT</overflow.commons-java.version>
|
||||
<overflow.crawler-java.version>1.0.0-SNAPSHOT</overflow.crawler-java.version>
|
||||
|
||||
<spring.version>5.0.5.RELEASE</spring.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.loafle.commons</groupId>
|
||||
<artifactId>server-java</artifactId>
|
||||
<version>${commons.server-java.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>commons-java</artifactId>
|
||||
<version>${overflow.commons-java.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>crawler-java</artifactId>
|
||||
<version>${overflow.crawler-java.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,9 @@
|
|||
package com.loafle.overflow.container;
|
||||
|
||||
/**
|
||||
* Container
|
||||
*/
|
||||
public class Container {
|
||||
public static final String CONTAINER_CRAWLERS = "CONTAINER_CRAWLERS";
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.loafle.overflow.container.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.loafle.overflow.container.Container;
|
||||
import com.loafle.overflow.crawler.Crawler;
|
||||
import com.loafle.overflow.module.core.exception.OverflowException;
|
||||
import com.loafle.overflow.module.core.interfaces.Service;
|
||||
import com.loafle.overflow.module.sensorconfig.model.SensorConfig;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* CrawlerService
|
||||
*/
|
||||
@org.springframework.stereotype.Service("CrawlerService")
|
||||
public class CrawlerService implements Service {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CrawlerService.class);
|
||||
|
||||
@Autowired
|
||||
private SensorConfigService sensorConfigService;
|
||||
|
||||
@Resource(name=Container.CONTAINER_CRAWLERS)
|
||||
private Map<String, Crawler> crawlers;
|
||||
|
||||
@Override
|
||||
public void initService() throws Exception {
|
||||
if (null == this.crawlers) {
|
||||
throw new Exception("Crawlers is not set");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startService() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopService() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyService() {
|
||||
|
||||
}
|
||||
|
||||
public void Auth(String crawlerName, Map<String, Object> authInfoMap) throws OverflowException {
|
||||
Crawler crawler = this.crawlers.get(crawlerName);
|
||||
if (null == crawler) {
|
||||
throw new OverflowException(String.format("There is no crawler[%s]", crawlerName), null);
|
||||
}
|
||||
|
||||
crawler.auth(authInfoMap);
|
||||
}
|
||||
|
||||
public Map<String, String> Get(String sensorConfigID) throws OverflowException {
|
||||
SensorConfig sensorConfig = this.sensorConfigService.getSensorConfig(sensorConfigID);
|
||||
if (null == sensorConfig) {
|
||||
throw new OverflowException(String.format("There is no sensor config for id[%s]", sensorConfigID), null);
|
||||
}
|
||||
|
||||
String crawlerName = sensorConfig.getCrawler().getName();
|
||||
Crawler crawler = this.crawlers.get(crawlerName);
|
||||
if (null == crawler) {
|
||||
throw new OverflowException(String.format("There is no crawler[%s] for id[%s]", crawlerName, sensorConfigID), null);
|
||||
}
|
||||
|
||||
return crawler.get(sensorConfig);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.loafle.overflow.container.service;
|
||||
|
||||
import com.loafle.overflow.module.core.exception.OverflowException;
|
||||
import com.loafle.overflow.module.core.interfaces.Service;
|
||||
|
||||
/**
|
||||
* ProbeService
|
||||
*/
|
||||
@org.springframework.stereotype.Service("ProbeService")
|
||||
public class ProbeService implements Service {
|
||||
|
||||
@Override
|
||||
public void initService() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startService() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopService() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyService() {
|
||||
|
||||
}
|
||||
|
||||
public void send(String method, Object... params) throws OverflowException {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package com.loafle.overflow.container.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.loafle.overflow.module.core.exception.OverflowException;
|
||||
import com.loafle.overflow.module.core.interfaces.Service;
|
||||
import com.loafle.overflow.module.sensorconfig.model.SensorConfig;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* SensorConfigService
|
||||
*/
|
||||
@org.springframework.stereotype.Service("SensorConfigService")
|
||||
public class SensorConfigService implements Service {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SensorConfigService.class);
|
||||
|
||||
private Map<String, SensorConfig> sensorConfigs;
|
||||
|
||||
@Override
|
||||
public void initService() throws Exception {
|
||||
this.sensorConfigs = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startService() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopService() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyService() {
|
||||
|
||||
}
|
||||
|
||||
SensorConfig getSensorConfig(String configID) {
|
||||
return this.sensorConfigs.get(configID);
|
||||
}
|
||||
|
||||
public void InitConfig(List<SensorConfig> sensorConfigs) throws OverflowException {
|
||||
if (null == sensorConfigs || 0 == sensorConfigs.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (SensorConfig sensorConfig : sensorConfigs) {
|
||||
this.sensorConfigs.put(sensorConfig.getConfigID(), sensorConfig);
|
||||
}
|
||||
logger.debug("Sensor configs[%d] were added", sensorConfigs.size());
|
||||
}
|
||||
|
||||
public void AddConfig(SensorConfig sensorConfig) throws OverflowException {
|
||||
if (null == sensorConfig) {
|
||||
throw new OverflowException("Sensor config is not valid", null);
|
||||
}
|
||||
|
||||
String configID = sensorConfig.getConfigID();
|
||||
if (this.sensorConfigs.containsKey(configID)) {
|
||||
throw new OverflowException(String.format("Sensor config[%s] is exist already", configID), null);
|
||||
}
|
||||
|
||||
this.sensorConfigs.put(configID, sensorConfig);
|
||||
|
||||
logger.debug("Sensor config[%s] was added", configID);
|
||||
}
|
||||
|
||||
public void UddConfig(SensorConfig sensorConfig) throws OverflowException {
|
||||
if (null == sensorConfig) {
|
||||
throw new OverflowException("Sensor config is not valid", null);
|
||||
}
|
||||
|
||||
String configID = sensorConfig.getConfigID();
|
||||
if (!this.sensorConfigs.containsKey(configID)) {
|
||||
throw new OverflowException(String.format("Sensor config[%s] is not exist", configID), null);
|
||||
}
|
||||
|
||||
this.sensorConfigs.remove(configID);
|
||||
this.sensorConfigs.put(configID, sensorConfig);
|
||||
|
||||
logger.debug("Sensor config[%s] was updated", configID);
|
||||
}
|
||||
|
||||
public void RddConfig(String configID) throws OverflowException {
|
||||
if (!this.sensorConfigs.containsKey(configID)) {
|
||||
throw new OverflowException(String.format("Sensor config[%s] is not exist", configID), null);
|
||||
}
|
||||
|
||||
this.sensorConfigs.remove(configID);
|
||||
|
||||
logger.debug("Sensor config[%s] was removed", configID);
|
||||
}
|
||||
}
|
0
src/main/resources/_
Normal file
0
src/main/resources/_
Normal file
17
src/test/resources/logback.xml
Normal file
17
src/test/resources/logback.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="3 seconds">
|
||||
<contextName>commons_java</contextName>
|
||||
<!-- TRACE > DEBUG > INFO > WARN > ERROR -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>
|
||||
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
<logger name="com.loafle.overflow" level="ALL" />
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user