This commit is contained in:
crusader 2018-05-24 19:35:57 +09:00
parent 31fd84e984
commit 58bddae263
4 changed files with 379 additions and 363 deletions

28
.vscode/launch.test.json vendored Normal file
View File

@ -0,0 +1,28 @@
{
"run": {
"default": "",
"items": [
{
"name": "central",
"projectName": "central",
"workingDirectory": "/project/loafle/overflow/central",
"args": [],
"vmargs": [],
"preLaunchTask": ""
}
]
},
"debug": {
"default": "",
"items": [
{
"name": "central",
"projectName": "central",
"workingDirectory": "/project/loafle/overflow/central",
"args": [],
"vmargs": [],
"preLaunchTask": ""
}
]
}
}

View File

@ -122,8 +122,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1)); noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
this.noAuthProbeDAO.save(noAuthProbe); this.noAuthProbeDAO.save(noAuthProbe);
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept", messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept", probe.getProbeKey());
probe.getProbeKey());
return this.readAllByDomainID(noAuthProbe.getDomain().getId()); return this.readAllByDomainID(noAuthProbe.getDomain().getId());
} }

View File

@ -1,164 +1,154 @@
// package com.loafle.overflow.central.module.noauthprobe.service; package com.loafle.overflow.central.module.noauthprobe.service;
// import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.central.commons.service.MessagePublisher;
// import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.central.spring.AppConfigTest;
// import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
// import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.domain.Domain;
// import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus; import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
// import com.loafle.overflow.model.noauthprobe.NoAuthProbe; import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
// import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService; import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
// import org.junit.Assert; import org.junit.Assert;
// import org.junit.Ignore; import org.junit.Ignore;
// import org.junit.Test; import org.junit.Test;
// import org.junit.runner.RunWith; import org.junit.runner.RunWith;
// import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
// import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
// import java.io.IOException; import java.io.IOException;
// import java.util.ArrayList; import java.util.ArrayList;
// import java.util.List; import java.util.List;
// /** /**
// * Created by snoop on 17. 6. 28. * Created by snoop on 17. 6. 28.
// */ */
// @RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
// @ContextConfiguration(classes = {AppConfigTest.class}) @ContextConfiguration(classes = { AppConfigTest.class })
// public class NoAuthProbeServiceTest { public class NoAuthProbeServiceTest {
// @Autowired @Autowired
// private NoAuthProbeService noAuthProbeService; private CentralNoAuthProbeService noAuthProbeService;
// @Autowired @Autowired
// private MessagePublisher messagePublisher; private MessagePublisher messagePublisher;
// @Ignore @Ignore
// @Test @Test
// public void regist() throws Exception { public void regist() throws Exception {
// NoAuthProbe noAuthProbe = new NoAuthProbe(); NoAuthProbe noAuthProbe = new NoAuthProbe();
// noAuthProbe.setHostName("snoop");
// noAuthProbe.setIpAddress(3232235980L);
// noAuthProbe.setMacAddress(8796753988883L);
noAuthProbe.setDescription(
"{\"host\":{\"name\":\"snoop-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"DE60E4C3-347A-4D38-AEAB-1760471665EA\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
// // noAuthProbe.setHostName("snoop"); noAuthProbe.setApiKey("52abd6fd57e511e7ac52080027658d13");
// // noAuthProbe.setIpAddress(3232235980L);
// // noAuthProbe.setMacAddress(8796753988883L);
// noAuthProbe.setDescription("{\"host\":{\"name\":\"snoop-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"DE60E4C3-347A-4D38-AEAB-1760471665EA\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
// noAuthProbe.setApiKey("52abd6fd57e511e7ac52080027658d13"); MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
metaNoAuthProbeStatus.setId((short) 3);
// MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus(); noAuthProbe.setStatus(metaNoAuthProbeStatus);
// metaNoAuthProbeStatus.setId((short)3); noAuthProbe.setTempProbeKey("ac7f252b5bc811e784ad080027658d13");
// noAuthProbe.setStatus(metaNoAuthProbeStatus); Domain d = new Domain();
// noAuthProbe.setTempProbeKey("ac7f252b5bc811e784ad080027658d13"); d.setId(Long.valueOf(1));
noAuthProbe.setDomain(d);
// Domain d = new Domain(); this.noAuthProbeService.regist(noAuthProbe);
// d.setId(1);
// noAuthProbe.setDomain(d);
// this.noAuthProbeService.regist(noAuthProbe); Assert.assertNotEquals(noAuthProbe.getId().longValue(), 0);
// Assert.assertNotEquals(noAuthProbe.getId(), 0); }
// } @Ignore
@Test
public void registForNoAuthProbes() throws Exception {
// @Ignore NoAuthProbe noAuthProbe = new NoAuthProbe();
// @Test
// public void registForNoAuthProbes() throws Exception {
// NoAuthProbe noAuthProbe = new NoAuthProbe(); // noAuthProbe.setHostName("geek");
// noAuthProbe.setIpAddress(3232235980L);
// noAuthProbe.setMacAddress(8796753988883L);
noAuthProbe.setDescription(
"{\"host\":{\"name\":\"geek-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"03000200-0400-0500-0006-000700080009\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
noAuthProbe.setApiKey("521abd6fd57e511e7ac52080027658d13");
// // noAuthProbe.setHostName("geek"); MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
// // noAuthProbe.setIpAddress(3232235980L); metaNoAuthProbeStatus.setId((short) 3);
// // noAuthProbe.setMacAddress(8796753988883L);
// noAuthProbe.setDescription("{\"host\":{\"name\":\"geek-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"03000200-0400-0500-0006-000700080009\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
// noAuthProbe.setApiKey("521abd6fd57e511e7ac52080027658d13");
// MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus(); noAuthProbe.setStatus(metaNoAuthProbeStatus);
// metaNoAuthProbeStatus.setId((short)3); noAuthProbe.setTempProbeKey("a1c7f252b5bc811e784ad080027658d13");
// noAuthProbe.setStatus(metaNoAuthProbeStatus); Domain d = new Domain();
// noAuthProbe.setTempProbeKey("a1c7f252b5bc811e784ad080027658d13"); d.setId(Long.valueOf(1));
noAuthProbe.setDomain(d);
// Domain d = new Domain(); List<NoAuthProbe> noAuthProbes = new ArrayList<NoAuthProbe>();
// d.setId(1);
// noAuthProbe.setDomain(d);
// List<NoAuthProbe> noAuthProbes = new ArrayList<NoAuthProbe>(); noAuthProbes.add(noAuthProbe);
// List<NoAuthProbe> dd =
// this.noAuthProbeService.registForNoAuthProbes(noAuthProbes);
// noAuthProbes.add(noAuthProbe); // System.out.println(dd.get(0).getId());
// // List<NoAuthProbe> dd = this.noAuthProbeService.registForNoAuthProbes(noAuthProbes);
// // System.out.println(dd.get(0).getId()); Assert.assertNotEquals(noAuthProbes.size(), 2);
// Assert.assertNotEquals(noAuthProbes.size(), 2); }
// } @Ignore
@Test
public void readAllByDomainID() throws Exception {
List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomainID(Long.valueOf(1));
// @Ignore Assert.assertNotEquals(probes.size(), 0);
// @Test
// public void readAllByDomain() throws Exception {
// Domain domain = new Domain(); }
// domain.setId(1);
// List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomain(domain); @Ignore
@Test
public void read() throws Exception {
NoAuthProbe noAuthProbe = this.noAuthProbeService.read(Long.valueOf(1));
// Assert.assertNotEquals(probes.size(), 0); Assert.assertNotEquals(noAuthProbe, null);
}
// } @Ignore
@Test
public void acceptProbe() throws Exception {
// @Ignore this.noAuthProbeService.acceptNoAuthProbe(Long.valueOf(1));
// @Test
// public void read() throws Exception {
// NoAuthProbe noAuthProbe = this.noAuthProbeService.read(1); }
// Assert.assertNotEquals(noAuthProbe, null); @Ignore
// } @Test
public void ssss() {
String ss = "192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64";
// @Ignore String[] sss = ss.split("\\|");
// @Test
// public void acceptProbe() throws IOException {
// NoAuthProbe noAuthProbe = this.noAuthProbeService.read(1); System.out.println(sss[0]);
}
// this.noAuthProbeService.acceptNoAuthProbe(noAuthProbe); @Test
public void readByTempKey() throws Exception {
// } NoAuthProbe noAuthProbe = this.noAuthProbeService.readByTempProbeKey("1cf2555c57d511e79714080027658d15");
// @Ignore Assert.assertNotEquals(noAuthProbe, null);
// @Test
// public void ssss() {
// String ss = "192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64";
// String[] sss = ss.split("\\|"); }
// System.out.println(sss[0]); @Test
// } @Ignore
public void sendWeb() throws OverflowException {
List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomainID(Long.valueOf(1));
// @Test messagePublisher.publishToDomainMembers(Long.valueOf(1), "NoAuthProbeService.regist", probes);
// public void readByTempKey() {
// NoAuthProbe noAuthProbe = this.noAuthProbeService.readByTempKey("1cf2555c57d511e79714080027658d15"); }
// Assert.assertNotEquals(noAuthProbe, null); }
// }
// @Test
// @Ignore
// public void sendWeb() throws OverflowException {
// Domain domain = new Domain();
// domain.setId(1);
// List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomain(domain);
// messagePublisher.publishToDomainMembers(domain.getId(), "NoAuthProbeService.regist", probes);
// }
// }

View File

@ -1,41 +1,40 @@
package com.loafle.overflow.central.module.target.service; package com.loafle.overflow.central.module.target.service;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.model.discovery.Host; import com.loafle.overflow.model.discovery.Host;
import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.service.central.target.TargetDiscoveryService; import com.loafle.overflow.service.central.target.TargetDiscoveryService;
import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Date; import java.util.List;
import java.util.List;
/** /**
* Created by snoop on 17. 6. 28. * Created by snoop on 17. 6. 28.
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AppConfigTest.class}) @ContextConfiguration(classes = {AppConfigTest.class})
public class TargetDiscoveryServiceTest { public class TargetDiscoveryServiceTest {
@Autowired @Autowired
private ResourceLoader resourceLoader; private ResourceLoader resourceLoader;
@ -85,7 +84,7 @@
public void testParam() throws NoSuchMethodException { public void testParam() throws NoSuchMethodException {
Method m = this.targetDiscoveryService.getClass().getMethod("saveAllTarget", List.class, Probe.class); Method m = this.targetDiscoveryService.getClass().getMethod("saveAllTarget", List.class, Probe.class);
// Method m = TargetDiscoveryService.class.getMethod("saveAllTarget", List.class, Probe.class); // Method m = TargetDiscoveryService.class.getMethod("saveAllTarget", List.class, Probe.class);
Class<?> clazz = AopUtils.getTargetClass(this.targetDiscoveryService); Class<?> clazz = AopUtils.getTargetClass(this.targetDiscoveryService);
Method[] ms = clazz.getMethods(); Method[] ms = clazz.getMethods();
@ -143,4 +142,4 @@
} }
} }