Commit 6a7e8284 by Adi Amir

support cisco login and parking

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