Commit dcc59bb1 by Eli Ben Baruch

mde - phase 1 : traffic and parking support

parent bb23f01d
......@@ -34,6 +34,10 @@
}, {
"name": "q",
"value": "location-type:PARKING_SPOT"
},
{
"name": "size",
"value": "30"
}],
"headers": [],
"content": null
......
......@@ -2,7 +2,7 @@
"config": {
"metaDataConfig": "logic.adapter.HttpAdapter.model.HttpAdapterConfig",
"configHttpRequestParams": {
"baseUrl": "ie-parking.run.aws-usw02-pr.ice.predix.io/",
"baseUrl": "ie-traffic.run.aws-usw02-pr.ice.predix.io/",
"basePath": "v1/",
"headers": [{
"name": "predix-zone-id",
......@@ -21,20 +21,19 @@
}
}
},
"flows": [{
"flows": [
{
"action": {
"metaDataActionClass": "logic.adapter.HttpAdapter.action.SimpleHttpAction",
"params": {
"id": "GetAllTrafficLanes",
"id": "subscribe",
"httpMethod": "GET",
"path": "locations/search",
"path": "assets/$mdeKey/live-events",
"queryParams": [{
"name": "bbox",
"value": "32.123:-117,32.723179:-117.172655"
}, {
"name": "q",
"value": "location-type:TRAFFIC_LANES"
}],
"name": "event-types",
"value": "TFEVT"
}
],
"headers": [],
"content": null
}
......@@ -45,104 +44,19 @@
"actions": [{
"metaDataActionClass": "logic.adapter.action.ExtractValueAction",
"params": {
"path": "/_embedded/locations",
"valueType": "ARRAY-NODE"
}
}, {
"metaDataActionClass": "logic.adapter.action.JsonConvertAction",
"params": {
"intermediateOperations": [{
"metaDataOperationClass": "logic.adapter.HttpAdapter.model.MapJsonToStringOperation",
"operationParams": {
"action": {
"metaDataActionClass": "logic.adapter.action.ExtractValueAction",
"params": {
"path": "/_links/self/href",
"path": "/url",
"valueType": "STRING"
}
}
}
}, {
"metaDataOperationClass": "logic.adapter.HttpAdapter.model.MapStringToJsonOperation",
"operationParams": {
"action": {
"metaDataActionClass": "logic.adapter.HttpAdapter.action.SimpleHttpAction",
"params": {
"id": "getLocationDetails",
"httpMethod": "GET",
"path": "locations/$id",
"queryParams": null,
"headers": [],
"content": null
}
},
"id": "lastToken"
}
}, {
"metaDataOperationClass": "logic.adapter.HttpAdapter.model.MapJsonToJsonOperation",
"operationParams": {
"action": {
"metaDataActionClass": "logic.adapter.action.JsonPatchAction",
"params": {
"fileInput": null,
"filePatch": "trafficLaneJsonPatch.json"
}
}
}
}],
"terminateOperation": null
}
}]
},
"onError": {
"actionsInput": "CONTENT",
"actions": []
}
}
}, {
"action": {
"metaDataActionClass": "logic.adapter.HttpAdapter.action.SimpleHttpAction",
"params": {
"id": "getLocationDetails",
"httpMethod": "GET",
"path": "locations/$id",
"queryParams": [],
"headers": [],
"content": null
}
},
"onResponse": {
"onSuccess": {
"actionsInput": "CONTENT",
"actions": []
},
"onError": {
"actionsInput": "CONTENT",
"actions": []
}
}
},
{
"action": {
"metaDataActionClass": "logic.adapter.HttpAdapter.action.SimpleHttpAction",
"metaDataActionClass": "logic.adapter.HttpAdapter.action.WebSocketAction",
"params": {
"id": "subscribe",
"httpMethod": "GET",
"path": "assets/$id/live-events",
"queryParams": [{
"name": "event-types",
"value": "TFEVT"
}
],
"headers": [],
"content": null
"headers":[{
"name": "predix-zone-id",
"value": "b6fc22b6-ad71-423e-867b-a1b197f6cfc2"
}]
}
},
"onResponse": {
"onSuccess": {
"actionsInput": "CONTENT",
"actions": []
}]
},
"onError": {
"actionsInput": "CONTENT",
......
......@@ -2,5 +2,9 @@
"adapters": [{
"id": "adapter.ge.parking",
"type": "HttpAdapter"
},
{
"id": "adapter.ge.traffic",
"type": "HttpAdapter"
}]
}
\ No newline at end of file
{
"apiList": [
{
"apiIn": "subscribe/$mde-id/$uid",
"method": "POST",
"actions": [{
"adapterId": "adapter.ge.traffic",
"apiOut": "subscribe"
}]
}
]
}
{
"services": [ { "id": "ge.parking" } ]
"services": [ { "id": "ge.parking" } , { "id": "ge.traffic" } ]
}
\ No newline at end of file
......@@ -8,4 +8,5 @@ mde:
- "8200:8000"
- "50040:50040"
extra_hosts:
- "transportation:172.16.1.151"
- "parking:172.16.1.244"
\ No newline at end of file
......@@ -14,7 +14,7 @@ import java.lang.reflect.TypeVariable;
*/
public abstract class BaseAdapter<T extends BaseFlow, TypeIn/*must be as TypeIn of BaseFlow*/,
TypeOut/*must be as TypeOut of BaseFlow*/> {
private String adapterId = null;
protected String adapterId = null;
private AdapterModel<T> model;
public ILogger getLogger() {
......
......@@ -57,13 +57,25 @@ public class HttpAdapter extends BaseAdapter<HttpFlow, RequestParams, SimpleHttp
httpClient = new SimpleHttpClient();
httpClient.Initialize(100);
//parking
List<NameValueParam> headers= new ArrayList<>();
NameValueParam header = new NameValueParam();
if (this.adapterId.equals("adapter.ge.parking")) {
//parking
header.setName("predix-zone-id");
header.setValue("c54e3e63-8dc6-425e-a533-64e061f64023");
headers.add(header);
this.webSocketManager = new WebSocketManager(authClient,headers);
}
//traffic
else if (this.adapterId.equals("adapter.ge.traffic")){
header.setName("predix-zone-id");
header.setValue("b6fc22b6-ad71-423e-867b-a1b197f6cfc2");
headers.add(header);
}
this.webSocketManager = new WebSocketManager(authClient,headers,adapterId);
this.setModelReferences();
......@@ -150,9 +162,6 @@ public class HttpAdapter extends BaseAdapter<HttpFlow, RequestParams, SimpleHttp
}
}
}
// this.setHttpActionsReferences(actionsListOnSuccess.getActions());
// actionsListOnError = onHttpResponse.getOnError();
// this.setHttpActionsReferences(actionsListOnError.getActions());
}
}
}
......@@ -176,12 +185,6 @@ public class HttpAdapter extends BaseAdapter<HttpFlow, RequestParams, SimpleHttp
operation.getOperationParams().setAdapterReferences(config.getConfigHttpRequestParams(),
httpClient,
authClient);
// if (operation.getOperationParams().getClass().isInstance(MapOperationParams.class)){
// BaseAction baseAction = ((MapOperationParams)operation.getOperationParams()).getAction();
// if (baseAction.getType().equals(SimpleHttpAction.TYPE))
// ((SimpleHttpAction)baseAction).setAdapterReferences(config.getConfigHttpRequestParams(),
// httpClient,
// authClient);
}
}
......
......@@ -15,6 +15,7 @@ import java.util.List;
* Created by eli on 12/4/16.
*/
public class WebSocketConnection extends Thread {
private final String adapterId;
private final String uid;
private final OnEventDetails details;
private final String connectionId;
......@@ -33,13 +34,14 @@ public class WebSocketConnection extends Thread {
private boolean dontStop;
public WebSocketConnection(String connectionId,
public WebSocketConnection(String adapterId, String connectionId,
String uid,
String webSocketUrl,
final OAuth2Client auth2Client,
List<NameValueParam> httpHeaders,
OnEventDetails details) throws IOException, ErrorLoginException, WebSocketException {
super();
this.adapterId=adapterId;
this.dontStop=true;
this.factory = new WebSocketFactory();
this.connectionId = connectionId;
......@@ -75,7 +77,7 @@ public class WebSocketConnection extends Thread {
webSocket.addHeader(header.getName(), header.getValue());
}
}
this.eventListener = new WebSocketEventListener(connectionId, this.uid, details,null);
this.eventListener = new WebSocketEventListener(adapterId,connectionId, this.uid, details,null);
webSocket.addListener(eventListener);
webSocket.setPingInterval(50*1000);
......
......@@ -17,12 +17,14 @@ import java.util.Map;
*/
public class WebSocketManager {
private String adapterId;
private Map<String, WebSocketConnection> webSocketConnections;
private List<NameValueParam> defaultHeaders;
private OAuth2Client auth2Client;
public WebSocketManager(OAuth2Client oAuth2Client, List<NameValueParam> defaultHeaders)
public WebSocketManager(OAuth2Client oAuth2Client, List<NameValueParam> defaultHeaders, String adapterId)
{
this.adapterId=adapterId;
this.webSocketConnections = new HashMap<>();
this.defaultHeaders = defaultHeaders;
this.auth2Client = oAuth2Client;
......@@ -50,7 +52,7 @@ public class WebSocketManager {
String key = sb.toString();
WebSocketConnection webSocketConnection;
if (!webSocketConnections.containsKey(connectionId)) {
webSocketConnection = new WebSocketConnection(connectionId, uid, webSocketUrl, auth2Client, defaultHeaders, details);
webSocketConnection = new WebSocketConnection(adapterId,connectionId, uid, webSocketUrl, auth2Client, defaultHeaders, details);
synchronized (webSocketConnection){
webSocketConnection.start();
webSocketConnection.wait();
......@@ -61,7 +63,6 @@ public class WebSocketManager {
System.out.println("websocket created successfully: "+ connectionId+" "+ "uid="+uid+" "+ details.toString());
}
}
}
else{
webSocketConnection = webSocketConnections.get(connectionId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment