Commit 6a7e8284 by Adi Amir

support cisco login and parking

parent 4d6225d0
mde: mde:
environment: environment:
IPG_ENV_PARAMS: "-Dds.IpAddress=172.16.1.151:8012#\ IPG_ENV_PARAMS: "-Dds.IpAddress=172.16.1.151:8012#\
-Dredis.host=172.16.1.151" -Dredis.host=172.16.1.151#\
-Dmde.cisco.username=devoperator11@cdp.com#\
-Dmde.cisco.password=z9E+H=9$J#\
-Dmde.cisco.clientId=a27b18484c3c4e08a7c193e42c639347#\
-Dmde.cisco.clientSecret=b863de8f453c4a05A88126F45B958CF1"
USE_DEBUG: "yes" USE_DEBUG: "yes"
image: 172.16.1.212:5050/mcx/mde image: 172.16.1.212:5050/mcx/mde
ports: ports:
......
...@@ -77,7 +77,7 @@ public class GEManager { ...@@ -77,7 +77,7 @@ public class GEManager {
BaseRestResponse brr = new BaseRestResponse(false,null); BaseRestResponse brr = new BaseRestResponse(false,null);
long tStart = System.currentTimeMillis(); long tStart = System.currentTimeMillis();
logger.info("executeRequest() started: " + getApiIdString(apiIdAsParams)); logger.info("ge.executeRequest() started: " + getApiIdString(apiIdAsParams));
if (apiIdAsParams.length == 1 && apiIdAsParams[0].equals("cameras")) { if (apiIdAsParams.length == 1 && apiIdAsParams[0].equals("cameras")) {
brr = getCameraList(requestContext); brr = getCameraList(requestContext);
...@@ -98,24 +98,24 @@ public class GEManager { ...@@ -98,24 +98,24 @@ public class GEManager {
brr = getSensorLatestEvent(apiIdAsParams[1]/*sensorId*/, requestContext); brr = getSensorLatestEvent(apiIdAsParams[1]/*sensorId*/, requestContext);
} }
else { else {
String err = "executeRequest() failed. Unknown api: " + getApiIdString(apiIdAsParams); String err = "ge.executeRequest() failed. Unknown api: " + getApiIdString(apiIdAsParams);
brr = errorResponse(err); brr = errorResponse(err);
} }
// if the request failed due to invalid token - fetch a new one & try again // if the request failed due to invalid token - fetch a new one & try again
if (isAccessDenied(brr)) { if (isAccessDenied(brr)) {
logger.info("executeRequest() - access denied. fetch a new token & try again"); logger.info("ge.executeRequest() - access denied. fetch a new token & try again");
if (getNewAccessToken() == true) { if (getNewAccessToken() == true) {
brr = executeRequest(serviceId, apiIdAsParams, requestContext); brr = executeRequest(serviceId, apiIdAsParams, requestContext);
} }
else { else {
brr = errorResponse("executeRequest() failed to obtain access token"); brr = errorResponse("ge.executeRequest() failed to obtain access token");
} }
} }
long tEnd = System.currentTimeMillis(); long tEnd = System.currentTimeMillis();
double elapsedTime = ((double)(tEnd - tStart)) / 1000.0; double elapsedTime = ((double)(tEnd - tStart)) / 1000.0;
logger.info("executeRequest finished. time= " + elapsedTime + " success=" + brr.success + " api=" + getApiIdString(apiIdAsParams)); logger.info("ge.executeRequest finished. time= " + elapsedTime + " success=" + brr.success + " api=" + getApiIdString(apiIdAsParams));
return brr; return brr;
} }
...@@ -129,7 +129,7 @@ public class GEManager { ...@@ -129,7 +129,7 @@ public class GEManager {
BaseRestResponse brr = null; BaseRestResponse brr = null;
JsonNode contentObj = null; JsonNode contentObj = null;
logger.info("getLatestMediaFile() activated. camId=" + camId); logger.info("ge.getLatestMediaFile() activated. camId=" + camId);
// execute the request // execute the request
// example: ie-cities-media.run.asv-pr-pub.ice.predix.io/assets/{camId}/media/latest?mediaType=IMAGE // example: ie-cities-media.run.asv-pr-pub.ice.predix.io/assets/{camId}/media/latest?mediaType=IMAGE
...@@ -139,7 +139,7 @@ public class GEManager { ...@@ -139,7 +139,7 @@ public class GEManager {
SimpleHttpRequest httpRequest = buildLatestMediaFileUrlRequest(camId, mediaType); SimpleHttpRequest httpRequest = buildLatestMediaFileUrlRequest(camId, mediaType);
SimpleHttpResponse httpFileUrlResp = httpClient.processRequest(httpRequest); SimpleHttpResponse httpFileUrlResp = httpClient.processRequest(httpRequest);
if (httpFileUrlResp.getStatusCode() != 200) { if (httpFileUrlResp.getStatusCode() != 200) {
logHttpError("getLatestMediaFile/getLatestMediaURL", httpFileUrlResp); logHttpError("ge.getLatestMediaFile/getLatestMediaURL", httpFileUrlResp);
return errorHttpResponse(httpFileUrlResp); return errorHttpResponse(httpFileUrlResp);
} }
contentObj = objMapper.readTree(httpFileUrlResp.getContent()); contentObj = objMapper.readTree(httpFileUrlResp.getContent());
...@@ -150,7 +150,7 @@ public class GEManager { ...@@ -150,7 +150,7 @@ public class GEManager {
httpRequest = buildDownloadLatestMediaFileRequest(url); httpRequest = buildDownloadLatestMediaFileRequest(url);
SimpleHttpResponse httpFileDataResp = httpClient.processRequest(httpRequest); SimpleHttpResponse httpFileDataResp = httpClient.processRequest(httpRequest);
if (httpFileDataResp.getStatusCode() != 200) { if (httpFileDataResp.getStatusCode() != 200) {
logHttpError("getLatestMediaFile/downloadLatestMediaFile", httpFileDataResp); logHttpError("ge.getLatestMediaFile/downloadLatestMediaFile", httpFileDataResp);
return errorHttpResponse(httpFileDataResp); return errorHttpResponse(httpFileDataResp);
} }
String fileData = httpFileDataResp.getContent(); String fileData = httpFileDataResp.getContent();
...@@ -169,7 +169,7 @@ public class GEManager { ...@@ -169,7 +169,7 @@ public class GEManager {
brr = buildLatestMediaFileResp(fileData, url); brr = buildLatestMediaFileResp(fileData, url);
} catch (Exception e) { } catch (Exception e) {
String err = "getLatestMediaFile() failed with exception. camId=" + camId + " e=" + e.toString(); String err = "ge.getLatestMediaFile() failed with exception. camId=" + camId + " e=" + e.toString();
logger.error(err); logger.error(err);
return errorResponse(err); return errorResponse(err);
} }
...@@ -182,7 +182,7 @@ public class GEManager { ...@@ -182,7 +182,7 @@ public class GEManager {
SimpleHttpResponse httpResp = null; SimpleHttpResponse httpResp = null;
BaseRestResponse brr = new BaseRestResponse(false,null); BaseRestResponse brr = new BaseRestResponse(false,null);
logger.info("getCamerasList() activated."); logger.info("ge.getCamerasList() activated.");
// execute the request ... // execute the request ...
req = buildCameraListRequest(requestContext); req = buildCameraListRequest(requestContext);
...@@ -196,7 +196,7 @@ public class GEManager { ...@@ -196,7 +196,7 @@ public class GEManager {
} }
} catch (Exception e) { } catch (Exception e) {
String err = "getCameraList() failed with exception. e=" + e.toString(); String err = "ge.getCameraList() failed with exception. e=" + e.toString();
logger.error(err); logger.error(err);
return errorResponse(err); return errorResponse(err);
} }
...@@ -208,7 +208,7 @@ public class GEManager { ...@@ -208,7 +208,7 @@ public class GEManager {
SimpleHttpResponse httpResp = null; SimpleHttpResponse httpResp = null;
BaseRestResponse brr = new BaseRestResponse(false,null); BaseRestResponse brr = new BaseRestResponse(false,null);
logger.info("getCameraDetails() activated. camId=" + cameraId); logger.info("ge.getCameraDetails() activated. camId=" + cameraId);
// execute the request ... // execute the request ...
req = buildCameraDetailsRequest(cameraId); req = buildCameraDetailsRequest(cameraId);
...@@ -217,17 +217,17 @@ public class GEManager { ...@@ -217,17 +217,17 @@ public class GEManager {
if(httpResp.getStatusCode() == 200) if(httpResp.getStatusCode() == 200)
brr = buildCameraDetailsResp(httpResp); brr = buildCameraDetailsResp(httpResp);
else { else {
logHttpError("getCameraDetails", httpResp); logHttpError("ge.getCameraDetails", httpResp);
return errorHttpResponse(httpResp); return errorHttpResponse(httpResp);
} }
} catch (Exception e) { } catch (Exception e) {
String err = "getCameraDetails() failed with exception. e=" + e.toString(); String err = "ge.getCameraDetails() failed with exception. e=" + e.toString();
logger.error(err); logger.error(err);
return errorResponse(err); return errorResponse(err);
} }
logger.info("getCameraDetails() successfull. camId=" + cameraId); logger.info("ge.getCameraDetails() successfull. camId=" + cameraId);
return brr; return brr;
} }
private BaseRestResponse getSensorLatestEvent(String sensorId, RequestContext requestContext) { private BaseRestResponse getSensorLatestEvent(String sensorId, RequestContext requestContext) {
...@@ -235,7 +235,7 @@ public class GEManager { ...@@ -235,7 +235,7 @@ public class GEManager {
SimpleHttpResponse httpResp = null; SimpleHttpResponse httpResp = null;
BaseRestResponse brr = new BaseRestResponse(false,null); BaseRestResponse brr = new BaseRestResponse(false,null);
logger.info("getSensorLatestEvent() activated. camId=" + sensorId); logger.info("ge.getSensorLatestEvent() activated. camId=" + sensorId);
// execute the request ... // execute the request ...
// envType // envType
...@@ -264,12 +264,12 @@ public class GEManager { ...@@ -264,12 +264,12 @@ public class GEManager {
} }
} catch (Exception e) { } catch (Exception e) {
String err = "getSensorLatestEvent() failed with exception. e=" + e.toString(); String err = "ge.getSensorLatestEvent() failed with exception. e=" + e.toString();
logger.error(err); logger.error(err);
return errorResponse(err); return errorResponse(err);
} }
logger.info("getSensorLatestEvent() successfull. camId=" + sensorId); logger.info("ge.getSensorLatestEvent() successfull. camId=" + sensorId);
return brr; return brr;
} }
...@@ -318,7 +318,7 @@ public class GEManager { ...@@ -318,7 +318,7 @@ public class GEManager {
SimpleHttpRequest req = null; SimpleHttpRequest req = null;
SimpleHttpResponse httpResp = null; SimpleHttpResponse httpResp = null;
logger.info("getNewAccessToken() activated."); logger.info("ge.getNewAccessToken() activated.");
req = buildGetTokenRequest(); req = buildGetTokenRequest();
try { try {
...@@ -331,11 +331,11 @@ public class GEManager { ...@@ -331,11 +331,11 @@ public class GEManager {
return true; return true;
} }
else { else {
logHttpError("getNewAccessToken", httpResp); logHttpError("ge.getNewAccessToken", httpResp);
return false; return false;
} }
} catch(Exception e){ } catch(Exception e){
logger.error("getNewAccessToken() failed with exception. e: " + e.toString()); logger.error("ge.getNewAccessToken() failed with exception. e: " + e.toString());
return false; return false;
} }
...@@ -346,7 +346,7 @@ public class GEManager { ...@@ -346,7 +346,7 @@ public class GEManager {
SimpleHttpResponse httpResp = null; SimpleHttpResponse httpResp = null;
BaseRestResponse brr = new BaseRestResponse(false,null); BaseRestResponse brr = new BaseRestResponse(false,null);
logger.info("getSensorList() activated."); logger.info("ge.getSensorList() activated.");
// execute the request ... // execute the request ...
req = buildSensorListRequest(requestContext); req = buildSensorListRequest(requestContext);
...@@ -360,7 +360,7 @@ public class GEManager { ...@@ -360,7 +360,7 @@ public class GEManager {
} }
} catch (Exception e) { } catch (Exception e) {
String err = "getSensorList() failed with exception. e=" + e.toString(); String err = "ge.getSensorList() failed with exception. e=" + e.toString();
logger.error(err); logger.error(err);
return errorResponse(err); return errorResponse(err);
} }
...@@ -398,7 +398,7 @@ public class GEManager { ...@@ -398,7 +398,7 @@ public class GEManager {
// String[3]: fileName // String[3]: fileName
String[] urlParts = getMediaFileName(url, "latest"); String[] urlParts = getMediaFileName(url, "latest");
if (urlParts == null) { if (urlParts == null) {
String err = "buildLatestMediaFileResp() - failed to parse file url: " + url; String err = "ge.buildLatestMediaFileResp() - failed to parse file url: " + url;
logger.error(err); logger.error(err);
return new BaseRestResponse(false, err); return new BaseRestResponse(false, err);
} }
...@@ -410,7 +410,7 @@ public class GEManager { ...@@ -410,7 +410,7 @@ public class GEManager {
brr.objectNode = dataObj; brr.objectNode = dataObj;
} catch (Exception e) { } catch (Exception e) {
String err = "buildLatestMediaFileResp() failed with exception. e: " + e.toString(); String err = "ge.buildLatestMediaFileResp() failed with exception. e: " + e.toString();
logger.error(err); logger.error(err);
return new BaseRestResponse(false, err); return new BaseRestResponse(false, err);
} }
......
...@@ -36,6 +36,7 @@ public class MdeManager { ...@@ -36,6 +36,7 @@ public class MdeManager {
private ServicesRepository servicesRepository; private ServicesRepository servicesRepository;
private GEManager geManager = null; private GEManager geManager = null;
private CiscoManager ciscoManager = null;
public MdeManager(ILogger logger) throws Exception { public MdeManager(ILogger logger) throws Exception {
...@@ -45,6 +46,7 @@ public class MdeManager { ...@@ -45,6 +46,7 @@ public class MdeManager {
this.logger = logger; this.logger = logger;
geManager = new GEManager(logger); geManager = new GEManager(logger);
ciscoManager = new CiscoManager(logger);
LoadServices(logger); LoadServices(logger);
loadAdapters(logger); loadAdapters(logger);
ValidityCheck(); ValidityCheck();
...@@ -76,13 +78,15 @@ public class MdeManager { ...@@ -76,13 +78,15 @@ public class MdeManager {
serviceId = getServiceId(requestContext, offset); serviceId = getServiceId(requestContext, offset);
String[] apiIdAsParams = getApiIdAsParams(requestContext,offset); String[] apiIdAsParams = getApiIdAsParams(requestContext,offset);
String ver = serviceId.split("\\.")[0]; String[] idTokens = serviceId.split("\\.");
if (ver.equals("v2")) String verAndTenant = idTokens[0] + "." + idTokens[1];
if (verAndTenant.equals("v2.ge"))
brr = geManager.executeRequest(serviceId,apiIdAsParams,requestContext); brr = geManager.executeRequest(serviceId,apiIdAsParams,requestContext);
else if (verAndTenant.equals("v1.cisco"))
brr = ciscoManager.executeRequest(serviceId,apiIdAsParams,requestContext);
else else
brr = executeRequest(serviceId,apiIdAsParams,requestContext,null,isMaintenanceRequest); brr = executeRequest(serviceId,apiIdAsParams,requestContext,null,isMaintenanceRequest);
return brr; return brr;
} }
......
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