Skip to content

Commit

Permalink
#7 start websocket API
Browse files Browse the repository at this point in the history
  • Loading branch information
obriensystems committed Jul 26, 2017
1 parent cda34e3 commit 557933a
Show file tree
Hide file tree
Showing 12 changed files with 440 additions and 92 deletions.
4 changes: 2 additions & 2 deletions onap-demo.web/.project
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Expand Down
32 changes: 32 additions & 0 deletions onap-demo.web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@
<artifactId>genson</artifactId>
<version>1.1</version>
</dependency>

<!-- websocket -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>sockjs-client</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>stomp-websocket</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.1.0</version>
</dependency>

</dependencies>

<properties>
Expand Down
36 changes: 30 additions & 6 deletions onap-demo.web/src/main/java/org/onap/demo/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.concurrent.atomic.AtomicLong;

import org.onap.demo.integration.JAXRSClient;
import org.onap.demo.sbi.ExternalProcessEndpoint;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -16,22 +17,20 @@ public class ApiController {
private final AtomicLong counter = new AtomicLong();

@RequestMapping(method=RequestMethod.GET)
public @ResponseBody Api sayHello(@RequestParam(value="name", required=true, defaultValue="undefined") String name) {
public @ResponseBody Api process(@RequestParam(value="name", required=true, defaultValue="undefined") String name) {
String message = null;
// external call
message = getState(name);
message = externalAPICall(name);
Api api = new Api(
counter.incrementAndGet(), //String.format(template, name));
message);
return api;
}

private String getState(String id) {
private String externalAPICall(String id) {
String content = null;
JAXRSClient client = new JAXRSClient();
//String sec = client.run(false, "http://" + Configuration.get("coll-ip") + ":3904/events/unauthenticated.SEC_MEASUREMENT_OUTPUT/group3/sub1?timeout=9000","","");



switch(id) {
case "sec_mo":
content = client.run(false, Configuration.get("iad", "coll-ip"), "3904", "events/unauthenticated.SEC_MEASUREMENT_OUTPUT/group3/sub1?timeout=9000", null, null, null);
Expand All @@ -40,6 +39,31 @@ private String getState(String id) {
// will get a 4000 on customers/customer but not customers at demo init state
content = client.run(true, Configuration.get("iad", "aai-ip"), "8443", "aai/v8/business/customers/customer", "AAI", "AAI", "AAI");
break;
case "initial-config":
ExternalProcessEndpoint ep_ic = new ExternalProcessEndpoint();
content = ep_ic.runExternal("openstack_port_list.sh","network", "list");
break;
case "service-creation":
ExternalProcessEndpoint ep_sc = new ExternalProcessEndpoint();
content = ep_sc.runExternal("openstack_port_list.sh","network", "list");
break;
case "vnf-creation":
ExternalProcessEndpoint ep_vc = new ExternalProcessEndpoint();
content = ep_vc.runExternal("openstack_port_list.sh","network", "list");
break;
case "vfm-preload":
ExternalProcessEndpoint ep_mp = new ExternalProcessEndpoint();
content = ep_mp.runExternal("openstack_port_list.sh","network", "list");
break;
case "vfm-creation":
ExternalProcessEndpoint ep_mc = new ExternalProcessEndpoint();
content = ep_mc.runExternal("openstack_port_list.sh","network", "list");
break;
case "closed-loop":
ExternalProcessEndpoint ep_cl = new ExternalProcessEndpoint();
content = ep_cl.runExternal("openstack_port_list.sh","network", "list");
break;

}

return content;
Expand Down
64 changes: 43 additions & 21 deletions onap-demo.web/src/main/java/org/onap/demo/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,34 @@
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;

//@PropertySource(ignoreResourceNotFound=true, value="classpath:jdbc-${spring.profiles.active}.properties")
@PropertySource(ignoreResourceNotFound=true, value="classpath:onap-dev.properties")
public class Configuration {

public static final String DDC = "dfw";
public static final String VDC = "iad";
public static final String LOCAL = "local";

@Value("${script.dir}") // TODO: use typesafe
private String scriptDir;

public String getScriptDir() {
return scriptDir;
}


private static Map<String, Map<String, String>> map = new HashMap<>();

static {
map.put("dfw", new HashMap<>());
map.put("iad", new HashMap<>());
Map<String, String> dMap = map.get("dfw");
Map<String, String> iMap = map.get("iad");
map.put(DDC, new HashMap<>());
map.put(VDC, new HashMap<>());
map.put(LOCAL, new HashMap<>());
Map<String, String> dMap = map.get(DDC);
Map<String, String> vMap = map.get(VDC);
Map<String, String> iMap = map.get(LOCAL);
dMap.put("robot-ip", "23.253.125.166");
dMap.put("aai-ip", "172.99.115.238");
dMap.put("appc-ip", "67.192.246.90");
Expand All @@ -29,22 +48,25 @@ public class Configuration {
dMap.put("coll-ip", "162.242.235.75");
dMap.put("pstg-ip", "104.239.240.7");

iMap.put("robot-ip", "104.130.13.93");
iMap.put("aai-ip", "146.20.65.216");
iMap.put("appc-ip", "162.242.219.48");
iMap.put("dcae-ip", "172.99.67.156");
iMap.put("message-router-ip", "162.209.124.37");
iMap.put("mso-ip", "162.242.218.100");
iMap.put("policy-ip", "104.239.234.15");
iMap.put("portal-ip", "104.130.31.44");
iMap.put("sdc-ip", "104.239.234.11");
iMap.put("sdnc-ip", "162.242.218.219");
iMap.put("vid-ip", "104.130.169.38");
iMap.put("cdap0-ip", "104.239.175.196");
iMap.put("cdap1-ip", "104.130.239.149");
iMap.put("cdap2-ip", "172.99.68.155");
iMap.put("coll-ip", "162.242.235.75");
iMap.put("pstg-ip", "104.239.168.49");
vMap.put("robot-ip", "104.130.13.93");
vMap.put("aai-ip", "146.20.65.216");
vMap.put("appc-ip", "162.242.219.48");
vMap.put("dcae-ip", "172.99.67.156");
vMap.put("message-router-ip", "162.209.124.37");
vMap.put("mso-ip", "162.242.218.100");
vMap.put("policy-ip", "104.239.234.15");
vMap.put("portal-ip", "104.130.31.44");
vMap.put("sdc-ip", "104.239.234.11");
vMap.put("sdnc-ip", "162.242.218.219");
vMap.put("vid-ip", "104.130.169.38");
vMap.put("cdap0-ip", "104.239.175.196");
vMap.put("cdap1-ip", "104.130.239.149");
vMap.put("cdap2-ip", "172.99.68.155");
vMap.put("coll-ip", "162.242.235.75");
vMap.put("pstg-ip", "104.239.168.49");

// local config
iMap.put("script-dir","/opt/");
}

public static String get(String region, String key) {
Expand All @@ -55,5 +77,5 @@ public static void put(String region, String key, String value) {
map.get(region).put(key, value);
}


// curl http://healthcheck:zb\!XztG34@policy:6969/healthcheck
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package org.onap.demo.integration;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.SslConfigurator;
import org.onap.demo.oss.Authenticator;
Expand Down Expand Up @@ -59,25 +51,5 @@ record = rootTarget.request()
}
return record;
}

//public static void main(String[] args) {
//JAXRSClient client = new JAXRSClient();
//client.run(false, "http://67.192.246.187:8080/asdc/properties/encrypt/ecomp-dev/", "", "aa3871669d893c7fb8abbcda31b88b4f");
// https://developer.openstack.org/api-guide/quick-start/api-quick-start.html
/*try {
ProcessBuilder processBuilder = new ProcessBuilder("/Users/michaelobrien/wse_onap/onap/openstack_port_list.sh","network", "list");
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
InputStreamReader isr = new InputStreamReader(process.getInputStream());
BufferedReader buff = new BufferedReader (isr);
String line;
while((line = buff.readLine()) != null) {
System.out.print(line);
}
} catch (Exception e) {
e.printStackTrace();
}*/
//}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.onap.demo.integration;

public class WSContent {

private String content;

public WSContent() {
}

public WSContent(String content) {
this.content = content;
}

public String getContent() {
return content;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.onap.demo.integration;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

@Controller
public class WSController {

@MessageMapping("/ws")
@SendTo("/topic/content")
public WSContent greeting(WSMessage message) throws Exception {
Thread.sleep(1000); // simulated delay
return new WSContent("Hello, " + message.getName() + "!");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.onap.demo.integration;

public class WSMessage {

private String name;

public WSMessage() {
}

public WSMessage(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.onap.demo.integration;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/gs-guide-websocket").withSockJS();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.onap.demo.sbi;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.concurrent.TimeUnit;

import org.onap.demo.Configuration;

public class ExternalProcessEndpoint {

public String runExternal(String sh, String op0, String op1) {
// https://developer.openstack.org/api-guide/quick-start/api-quick-start.html
StringBuffer buffer = new StringBuffer();
try {
ProcessBuilder processBuilder = new ProcessBuilder(
Configuration.get(Configuration.LOCAL, "script-dir") + sh, op0, op1);
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
InputStreamReader isr = new InputStreamReader(process.getInputStream());
BufferedReader buff = new BufferedReader (isr);
String line;
//int lineCount = 0;
while((line = buff.readLine()) != null) {
System.out.println(line);
buffer.append(line);
//if(lineCount > 2) {
// break;
//}
//lineCount+=1;
}
} catch (Exception e) {
e.printStackTrace();
}
// simulate
try { TimeUnit.SECONDS.sleep(35); } catch (InterruptedException ie) { ie.printStackTrace(); }
return buffer.toString();
}
public static void main(String[] args) {
ExternalProcessEndpoint ep = new ExternalProcessEndpoint();
System.out.println(ep.runExternal("openstack_port_list.sh","network", "list"));

}

}
4 changes: 4 additions & 0 deletions onap-demo.web/src/main/openstack_port_list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ping vid
#cd /Users/michaelobrien/wse_onap/onap
#source admin.rc
#openstack port list
Loading

0 comments on commit 557933a

Please sign in to comment.