Skip to content

Commit

Permalink
Merge pull request #10 from AO-StreetArt/dev
Browse files Browse the repository at this point in the history
DvsManager refactored into Dao
  • Loading branch information
AO-StreetArt committed Oct 15, 2017
2 parents 36cc2e4 + 2becd68 commit 0370251
Show file tree
Hide file tree
Showing 14 changed files with 744 additions and 576 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ install:
- gradle assemble
script:
- gradle check
after_failure:
- docker logs --tail 150 crazyivan
- cat testModel_transform.txt
- cat testModel_device.txt
- cat testModel_scene.txt
- cat testModel_sceneList.txt
- cat testSceneCrudApi.txt
- cat testSceneQueryApi.txt
- tail logs/adrestia.log
notifications:
slack:
secure: AfMTl+Si4xHctYyrB8GaV5a5fJYEuX18Ow5/NRwpZuRoGfcFU/CkX/SKNHNMSpUyXdMDiTXuylnt3KtscwSTn2pJdfqlx91n5wuIcx7uO+Hv0pLsxKhHJ/3WLYVrPK9GKEVHbsKpR+gxw8Bu/HTGqLBL8k9TAjGl97m1h39k3ovIbAjxzKhSlUSVlxcdqmD18CEnD2szH1qSZ4IlsIraYJ0F7rZtr8mdAESPPU9Q9BAWSVNF2wQ40c3PPYZb6l/zaKEYN3BqHsBGEJHRzH+Aa+ZXtFfgtj6voqiigMVw3FTPl66jPaDx7TI8mJFFBWUGOOImrwNYliIiGyo/b+q3N4OYVWADHp1RaLQEZqwQzCqRfoqgIUCagDF5wjOP6hQCobBT61o2wDSE2xHT73yKnr03AHp7An0flD0+/SYl9J2OOIe9vLgluVUEPa/jyiApldpKoH+JH0ZhvdMhz40Eu3iV9XtBdl0emT9gSeY5cKu3LSuA1AHIaGQz4VpsEokF14ebVSbxKx6rYjaNOViM56vwpBOT0eS9lD/NNduu5OBcijoifpBc5oAAUuK1t4VuoXDtBMaMdoqcxExRcfuRK/H63pUgDt1RkXKRysvg68EJMPLZosCrBwit5jsVbyWn9svLH7D1Kew437rHccD6KXsFjUOrp2Vc+0ppuDAvSCk=
6 changes: 4 additions & 2 deletions docs/pages/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Building from Source
--------------------

Building Adrestia from source is quite simple, but it will require several running services
to exist on the machine prior to startup. Please see `The Aesel Component List <http://aesel.readthedocs.io/en/latest/pages/components.html>`__
to exist on the machine prior to running integration tests or executing any transactions.
Please see `The Aesel Component List <http://aesel.readthedocs.io/en/latest/pages/components.html>`__
for a full list to all required services, and documentation for each.

Connections to CLyman and Ceph are not yet implemented, so are not yet required.
Expand All @@ -19,7 +20,8 @@ Once you've got the required backend services started, clone the Adrestia reposi

``git clone https://github.com/AO-StreetArt/Adrestia.git``

Build and execute the tests for the repository:
Build and execute the tests for the repository. Please note that integration tests
will fail unless you have instances of the required backend services running:

``cd adrestia && gradle check``

Expand Down
47 changes: 15 additions & 32 deletions src/main/java/adrestia/controller/scene/RegistrationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,58 +52,41 @@
@RequestMapping(path = "/v1/scene")
public class RegistrationController {

// DVS Manager, DAO Object allowing access to dependent services
// DAO Object allowing us access to scene data
@Autowired
DvsManager serviceManager;
SceneDao scnData;

// Utility Provider, providing us with basic utility methods
@Autowired
UtilityProvider utils;
UtilityProviderInterface utils;

// Scene Controller Logger
private static final Logger logger =
LogManager.getLogger("adrestia.RegistrationController");

// Execute a registration transaction with Crazy Ivan
private SceneList ivanRegistrationTransaction(String sceneName,
String deviceId, Transform inpTransform, int registerMsgType) {
logger.debug("Scene Registration Name: " + sceneName);
logger.debug("Scene Registration Device " + deviceId);

// Construct a User Device array
UserDevice ud = new UserDevice();
ud.setKey(deviceId);
// Pass the transform to the user device, if one is passed in
if (inpTransform != null) {
logger.debug("Input Transform detected");
ud.setTransform(inpTransform);
}
UserDevice[] devices = {ud};
// Construct a scene array
Scene scn = new Scene();
scn.setName(sceneName);
scn.setDevices(devices);
Scene[] scnArray = {scn};
// Construct a Scene List, which we will then convert to JSON
SceneList inpSceneList = new SceneList(registerMsgType, scnArray);
// Send the Scene List to Crazy Ivan and get the response
return serviceManager.ivanTransaction(inpSceneList);
}

// Process a registration request
private ResponseEntity<Scene> processRegistration(String name,
String device, Transform inpTransform, int registrationMsgType) {
Scene returnScn = new Scene();
HttpStatus returnCode = HttpStatus.OK;

SceneList ivanResponse = ivanRegistrationTransaction(
name, device, inpTransform, registrationMsgType);
// Get a response based on the msg type we've been passed in
SceneList ivanResponse = null;
switch (registrationMsgType) {
case 4: ivanResponse = scnData.register(name, device, inpTransform);
break;
case 5: ivanResponse = scnData.deregister(name, device);
break;
case 6: ivanResponse = scnData.synchronize(name, device, inpTransform);
break;
default: ivanResponse = null;
}

// If we have a successful response, then we pull the first value
if (ivanResponse.getNumRecords() > 0
&& ivanResponse.getErrorCode() == 100) {
returnScn = ivanResponse.getSceneList()[0];
returnCode = utils.translateIvanError(ivanResponse.getErrorCode());
returnCode = utils.translateDvsError(ivanResponse.getErrorCode());
} else {
returnCode = HttpStatus.INTERNAL_SERVER_ERROR;
logger.debug("Failure Registered. Ivan Response Error Code and Length:");
Expand Down
62 changes: 16 additions & 46 deletions src/main/java/adrestia/controller/scene/SceneController.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,50 +54,22 @@ public class SceneController {

// DVS Manager, DAO Object allowing access to dependent services
@Autowired
DvsManager serviceManager;
SceneDao scnData;

// Utility Provider, providing us with basic utility methods
@Autowired
UtilityProvider utils;
UtilityProviderInterface utils;

// Scene Controller Logger
private static final Logger logger =
LogManager.getLogger("adrestia.SceneController");

// Get a Scene from Crazy Ivan
private SceneList retrieveScene(String name) {
// Construct a Scene List, which we will then convert to JSON
Scene scn = new Scene();
scn.setName(name);
Scene[] scnArray = {scn};
SceneList inpSceneList = new SceneList(2, scnArray);
// Send the Scene List to Crazy Ivan and get the response
return serviceManager.ivanTransaction(inpSceneList);
}

// Save a scene to Crazy Ivan
private SceneList saveScene(Scene inpScene, boolean sceneExists) {
// Construct a Scene List, which we will then convert to JSON
Scene[] baseInpScns = {inpScene};
int msgType = 0;
if (sceneExists) {
msgType = 1;
return scnData.update(inpScene);
}
SceneList inpSceneList = new SceneList(msgType, baseInpScns);
// Send the Scene List to Crazy Ivan and get the response
return serviceManager.ivanTransaction(inpSceneList);
}

// Delete a scene from Crazy Ivan
private SceneList removeScene(String key) {
// Construct a Scene List, which we will then convert to JSON
Scene scn = new Scene();
scn.setKey(key);
Scene[] scnArray = new Scene[1];
scnArray[0] = scn;
SceneList inpSceneList = new SceneList(3, scnArray);
// Send the Scene List to Crazy Ivan and get the response
return serviceManager.ivanTransaction(inpSceneList);
return scnData.create(inpScene);
}

/**
Expand All @@ -110,14 +82,14 @@ public ResponseEntity<Scene> getScene(@PathVariable("name") String name) {
Scene returnScn = new Scene();
HttpStatus returnCode = HttpStatus.OK;

SceneList ivanResponse = retrieveScene(name);
SceneList ivanResponse = scnData.get(name);

// If we have a successful response, then we pull the first value and
// the error code
if (ivanResponse.getNumRecords() > 0
&& ivanResponse.getErrorCode() == 100) {
returnScn = ivanResponse.getSceneList()[0];
returnCode = utils.translateIvanError(ivanResponse.getErrorCode());
returnCode = utils.translateDvsError(ivanResponse.getErrorCode());
} else {
returnCode = HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE;
logger.debug("Failure Registered. Ivan Response Error Code and Length:");
Expand Down Expand Up @@ -149,7 +121,7 @@ public ResponseEntity<Scene> updateScene(
HttpStatus returnCode = HttpStatus.OK;

// See if we can find the scene requested
SceneList ivanResponse = retrieveScene(name);
SceneList ivanResponse = scnData.get(name);

// If we have a successful response, then the scene exists
boolean sceneExists = false;
Expand All @@ -173,7 +145,7 @@ public ResponseEntity<Scene> updateScene(
if (updateResponse.getNumRecords() > 0
&& updateResponse.getErrorCode() == 100) {
returnScn = updateResponse.getSceneList()[0];
returnCode = utils.translateIvanError(updateResponse.getErrorCode());
returnCode = utils.translateDvsError(updateResponse.getErrorCode());
} else {
returnCode = HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE;
logger.debug("Failure Registered. Ivan Response Error Code and Length:");
Expand All @@ -200,7 +172,8 @@ public ResponseEntity<Scene> deleteScene(@PathVariable("name") String name) {
HttpStatus returnCode = HttpStatus.OK;

// See if we can find the scene requested
SceneList ivanResponse = retrieveScene(name);
// We need to find the key in order to delete the scene
SceneList ivanResponse = scnData.get(name);

// If we have a successful response, then the scene exists
boolean sceneExists = false;
Expand All @@ -210,7 +183,7 @@ public ResponseEntity<Scene> deleteScene(@PathVariable("name") String name) {
sceneExists = true;
// Set the key on the input scene to the key from the response
ivanRespKey = ivanResponse.getSceneList()[0].getKey();
returnCode = utils.translateIvanError(ivanResponse.getErrorCode());
returnCode = utils.translateDvsError(ivanResponse.getErrorCode());
if (ivanRespKey != null && !ivanRespKey.isEmpty()) {
sceneExists = true;
logger.debug("Existing Scene found in Crazy Ivan");
Expand All @@ -220,7 +193,7 @@ public ResponseEntity<Scene> deleteScene(@PathVariable("name") String name) {
// Delete the scene
SceneList deleteResponse = null;
if (sceneExists) {
deleteResponse = removeScene(ivanRespKey);
deleteResponse = scnData.destroy(ivanRespKey);
}

// If we have a successful response, then we pull the first value
Expand Down Expand Up @@ -257,21 +230,18 @@ public ResponseEntity<SceneList> queryScene(@RequestBody Scene inpScene) {
Scene returnScn = new Scene();
HttpStatus returnCode = HttpStatus.OK;

// Construct a Scene List, which we will then convert to JSON
Scene[] scnArray = {inpScene};
SceneList inpSceneList = new SceneList(2, scnArray);
// Send the Scene List to Crazy Ivan and get the response
SceneList ivanResponse = serviceManager.ivanTransaction(inpSceneList);
// Send the Scene to Crazy Ivan and get the response
SceneList ivanResponse = scnData.query(inpScene);

// If we have a failure response, then return a failure error code
if (ivanResponse.getNumRecords() == 0
|| ivanResponse.getErrorCode() > 100) {
returnCode = HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE;
logger.debug("Failure Registered. Ivan Response Error Code and Length:");
logger.debug("Failure Registered. Response Error Code and Length:");
logger.debug(ivanResponse.getNumRecords());
logger.debug(ivanResponse.getErrorCode());
} else {
returnCode = utils.translateIvanError(ivanResponse.getErrorCode());
returnCode = utils.translateDvsError(ivanResponse.getErrorCode());
}

// Set up a response header to return a valid HTTP Response
Expand Down

0 comments on commit 0370251

Please sign in to comment.