From ac3eeb30f40a225372c67cb33fe3396cf44770e4 Mon Sep 17 00:00:00 2001 From: sebdet Date: Fri, 21 Sep 2018 17:46:12 +0200 Subject: Add delete test Add a test and fix the delete model code that was not working Issue-ID: CLAMP-217 Change-Id: I235200ee0e7dc25ed759b88568333882bfb90c50 Signed-off-by: sebdet --- extra/sql/bulkload/clds-stored-procedures.sql | 5 +- .../java/org/onap/clamp/clds/camel/CamelProxy.java | 2 +- .../onap/clamp/clds/client/CldsEventDelegate.java | 28 +++---- .../org/onap/clamp/clds/service/CldsService.java | 88 +++++++++------------- .../META-INF/resources/designer/scripts/app.js | 22 +----- .../resources/clds/camel/routes/flexible-flow.xml | 3 +- .../org/onap/clamp/clds/it/CldsServiceItCase.java | 39 ++++++++++ 7 files changed, 98 insertions(+), 89 deletions(-) diff --git a/extra/sql/bulkload/clds-stored-procedures.sql b/extra/sql/bulkload/clds-stored-procedures.sql index 107717451..aa8edb81a 100644 --- a/extra/sql/bulkload/clds-stored-procedures.sql +++ b/extra/sql/bulkload/clds-stored-procedures.sql @@ -450,7 +450,8 @@ BEGIN SET process_instance_id = v_process_instance_id WHERE event_id = v_event_id; END; -CREATE PROCEDURE del_model (IN v_model_name VARCHAR(80)) +CREATE PROCEDURE del_model +(IN v_model_name VARCHAR(80)) BEGIN DECLARE v_model_id VARCHAR(36); SELECT model_id INTO v_model_id from model where model_name = v_model_name; @@ -459,7 +460,7 @@ BEGIN DELETE from model_blueprint where model_id = v_model_id; DELETE from model_properties where model_id = v_model_id; DELETE from model where model_id = v_model_id; -END +END; CREATE PROCEDURE set_new_tosca_model_version (IN v_tosca_model_id VARCHAR(36), diff --git a/src/main/java/org/onap/clamp/clds/camel/CamelProxy.java b/src/main/java/org/onap/clamp/clds/camel/CamelProxy.java index 7abb69286..a74f4c702 100644 --- a/src/main/java/org/onap/clamp/clds/camel/CamelProxy.java +++ b/src/main/java/org/onap/clamp/clds/camel/CamelProxy.java @@ -59,7 +59,7 @@ public interface CamelProxy { * The latest event action in database (like CREATE, SUBMIT, ...) * @return A string containing the result of the Camel flow execution */ - String submit(@ExchangeProperty("actionCd") String actionCommand, + String executeAction(@ExchangeProperty("actionCd") String actionCommand, @ExchangeProperty("modelProp") String modelProperties, @ExchangeProperty("modelBpmnProp") String modelBpmnProperties, @ExchangeProperty("modelName") String modelName, @ExchangeProperty("controlName") String controlName, diff --git a/src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java b/src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java index b1243dc22..8dfa190ed 100644 --- a/src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * + * */ package org.onap.clamp.clds.client; @@ -48,22 +48,24 @@ public class CldsEventDelegate { * Insert event using process variables. * * @param camelExchange - * The Camel Exchange object containing the properties + * The Camel Exchange object containing the properties */ @Handler public void execute(Exchange camelExchange) { String controlName = (String) camelExchange.getProperty("controlName"); String actionCd = (String) camelExchange.getProperty("actionCd"); - String actionStateCd = (String) camelExchange.getProperty("actionStateCd"); - // Flag indicate whether it is triggered by Validation Test button from - // UI - boolean isTest = (boolean) camelExchange.getProperty("isTest"); - boolean isInsertTestEvent = (boolean) camelExchange.getProperty("isInsertTestEvent"); - String userid = (String) camelExchange.getProperty("userid"); - // do not insert events for test actions unless flag set to insert them - if (!isTest || isInsertTestEvent) { - // won't really have userid here... - CldsEvent.insEvent(cldsDao, controlName, userid, actionCd, actionStateCd, camelExchange.getExchangeId()); - } + String actionStateCd = ((String) camelExchange.getProperty("actionStateCd")) != null + ? ((String) camelExchange.getProperty("actionStateCd")) + : CldsEvent.ACTION_STATE_COMPLETED; + // Flag indicate whether it is triggered by Validation Test button from + // UI + boolean isTest = (boolean) camelExchange.getProperty("isTest"); + boolean isInsertTestEvent = (boolean) camelExchange.getProperty("isInsertTestEvent"); + String userid = (String) camelExchange.getProperty("userid"); + // do not insert events for test actions unless flag set to insert them + if (!isTest || isInsertTestEvent) { + // won't really have userid here... + CldsEvent.insEvent(cldsDao, controlName, userid, actionCd, actionStateCd, camelExchange.getExchangeId()); + } } } diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index 5e35b8954..8d497cbcc 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -363,8 +363,7 @@ public class CldsService extends SecureServiceBase { logger.info("PUT deploymentId={}", model.getDeploymentId()); this.fillInCldsModel(model); // save model to db - model.setName(modelName); - updateAndInsertNewEvent(modelName, model.getControlNamePrefix(), model.getEvent(), CldsEvent.ACTION_SUBMIT); + updateAndInsertNewEvent(modelName, model.getControlNamePrefix(), model.getEvent(), CldsEvent.ACTION_MODIFY); model.save(cldsDao, getUserId()); // get vars and format if necessary String prop = model.getPropText(); @@ -373,73 +372,56 @@ public class CldsService extends SecureServiceBase { String controlName = model.getControlName(); String bpmnJson = cldsBpmnTransformer.doXslTransformToString(bpmn); logger.info("PUT bpmnJson={}", bpmnJson); - // Flag indicates whether it is triggered by Validation Test button - // from - // UI - boolean isTest = Boolean.parseBoolean(test); - if (!isTest) { - String actionTestOverride = refProp.getStringValue("action.test.override"); - if (Boolean.parseBoolean(actionTestOverride)) { - logger.info("PUT actionTestOverride={}", actionTestOverride); - logger.info("PUT override test indicator and setting it to true"); - isTest = true; - } - } + // Test flag coming from UI or from Clamp config + boolean isTest = Boolean.parseBoolean(test) + || Boolean.parseBoolean(refProp.getStringValue("action.test.override")); logger.info("PUT isTest={}", isTest); - String insertTestEvent = refProp.getStringValue("action.insert.test.event"); - boolean isInsertTestEvent = Boolean.parseBoolean(insertTestEvent); - + boolean isInsertTestEvent = Boolean.parseBoolean(refProp.getStringValue("action.insert.test.event")); logger.info("PUT isInsertTestEvent={}", isInsertTestEvent); // determine if requested action is permitted model.validateAction(actionCd); logger.info("modelProp - " + prop); logger.info("docText - " + docText); try { - String result = camelProxy.submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest, - userId, isInsertTestEvent, model.getEvent().getActionCd()); + String result = camelProxy.executeAction(actionCd, prop, bpmnJson, modelName, controlName, docText, + isTest, userId, isInsertTestEvent, model.getEvent().getActionCd()); logger.info("Starting Camel flow on request, result is: ", result); } catch (SdcCommunicationException | PolicyClientException | BadRequestException e) { errorCase = true; logger.error("Exception occured during invoking Camel process", e); } - if (!actionCd.equalsIgnoreCase(CldsEvent.ACTION_DELETE)) { - // refresh model info from db (get fresh event info) + if (actionCd.equalsIgnoreCase(CldsEvent.ACTION_DELETE)) { + util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, + ONAPLogConstants.ResponseStatus.COMPLETED); + return new ResponseEntity<>("", HttpStatus.OK); + } else { retrievedModel = CldsModel.retrieve(cldsDao, modelName, false); } - if (retrievedModel != null) { - if (!isTest && !errorCase - && (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT) - || actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT) - || actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) { - if (retrievedModel.getTemplateName().startsWith(CsarInstallerImpl.TEMPLATE_NAME_PREFIX)) { - // SDC artifact case - logger - .info("Skipping DCAE inventory call as closed loop has been created from SDC notification"); - DcaeEvent dcaeEvent = new DcaeEvent(); - dcaeEvent.setArtifactName(retrievedModel.getControlName() + ".yml"); - dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION); - CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(), - CldsEvent.ACTION_STATE_RECEIVED, null); - } else { - // This should be done only when the call to DCAE - // has not yet been done. When CL comes from SDC - // this is not required as the DCAE inventory call is done - // during the CL deployment. - dcaeInventoryServices.setEventInventory(retrievedModel, getUserId()); - } - retrievedModel.save(cldsDao, getUserId()); + if (!isTest && !errorCase + && (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT) + || actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT) + || actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) { + if (retrievedModel.getTemplateName().startsWith(CsarInstallerImpl.TEMPLATE_NAME_PREFIX)) { + // SDC artifact case + logger.info("Skipping DCAE inventory call as closed loop has been created from SDC notification"); + DcaeEvent dcaeEvent = new DcaeEvent(); + dcaeEvent.setArtifactName(retrievedModel.getControlName() + ".yml"); + dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION); + CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(), + CldsEvent.ACTION_STATE_RECEIVED, null); + } else { + // This should be done only when the call to DCAE + // has not yet been done. When CL comes from SDC + // this is not required as the DCAE inventory call is done + // during the CL deployment. + dcaeInventoryServices.setEventInventory(retrievedModel, getUserId()); } - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Process model action completed"); - } else { - logger.error("CldsModel not found in database with modelName: " + modelName); - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), - "CldsModel not found in database with modelName " + "modelName", Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - return new ResponseEntity("CldsModel not found in database with modelName: \" + modelName", - HttpStatus.INTERNAL_SERVER_ERROR); + retrievedModel.save(cldsDao, getUserId()); } + // audit log + LoggingUtils.setTimeContext(startTime, new Date()); + auditLogger.info("Process model action completed"); + } catch (Exception e) { errorCase = true; logger.error("Exception occured during putModelAndProcessAction", e); diff --git a/src/main/resources/META-INF/resources/designer/scripts/app.js b/src/main/resources/META-INF/resources/designer/scripts/app.js index 0c3995280..d01016aef 100644 --- a/src/main/resources/META-INF/resources/designer/scripts/app.js +++ b/src/main/resources/META-INF/resources/designer/scripts/app.js @@ -259,8 +259,8 @@ function($scope, $rootScope, $timeout, dialogs, $location, MenuService, $scope.cldsConfirmPerformAction("RESUBMIT"); } else if (name == "Update") { $scope.cldsConfirmPerformAction("UPDATE"); - } else if (name.toLowerCase() == "delete") { - $scope.manageConfirmPerformAction("DELETE"); + } else if (name == "Delete") { + $scope.cldsConfirmPerformAction("DELETE"); } else if (name == "Stop") { $scope.cldsConfirmPerformAction("STOP"); } else if (name == "Restart") { @@ -670,23 +670,7 @@ function($scope, $rootScope, $timeout, dialogs, $location, MenuService, }, function(data) { }); } - $scope.managePerformAction = function(action) { - if (action.toLowerCase() === "delete") { - cldsModelService.manageAction(selected_model, - "805b9f83-261f-48d9-98c7-8011fc2cc8e8", "ClosedLoop-ABCD-0000.yml") - .then(function(pars) { - }, function(data) { - }); - } - }; - $scope.manageConfirmPerformAction = function(uiAction) { - var dlg = dialogs.confirm('Message', 'Do you want to ' - + uiAction.toLowerCase() + ' the closed loop?'); - dlg.result.then(function(btn) { - $scope.managePerformAction(uiAction); - }, function(btn) { - }); - }; + $scope.VesCollectorWindow = function(vesCollector) { var dlg = dialogs.create( 'partials/portfolios/vesCollector_properties.html', 'ImportSchemaCtrl', diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml index c7f7ec3b7..e84c68614 100644 --- a/src/main/resources/clds/camel/routes/flexible-flow.xml +++ b/src/main/resources/clds/camel/routes/flexible-flow.xml @@ -17,13 +17,14 @@ ${exchangeProperty.actionCd} == 'DELETE' - 30000 + + ${exchangeProperty.actionCd} == 'UPDATE' diff --git a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java index 9cca936c8..7a37a9dc2 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils; @@ -39,6 +40,7 @@ import java.util.List; import java.util.Properties; import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.NotFoundException; import javax.xml.transform.TransformerException; import org.apache.commons.codec.DecoderException; @@ -214,6 +216,27 @@ public class CldsServiceItCase { assertTrue(CldsModel.STATUS_ACTIVE.equals(((CldsModel) responseEntity.getBody()).getStatus())); assertTrue(CldsModel.STATUS_ACTIVE.equals(cldsService.getModel(randomNameModel).getStatus())); + responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_STOP, + randomNameModel, "false", cldsService.getModel(randomNameModel)); + assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); + assertNotNull(responseEntity.getBody()); + assertTrue(CldsModel.STATUS_STOPPED.equals(((CldsModel) responseEntity.getBody()).getStatus())); + assertTrue(CldsModel.STATUS_STOPPED.equals(cldsService.getModel(randomNameModel).getStatus())); + + responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_RESTART, + randomNameModel, "false", cldsService.getModel(randomNameModel)); + assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); + assertNotNull(responseEntity.getBody()); + assertTrue(CldsModel.STATUS_ACTIVE.equals(((CldsModel) responseEntity.getBody()).getStatus())); + assertTrue(CldsModel.STATUS_ACTIVE.equals(cldsService.getModel(randomNameModel).getStatus())); + + responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_UPDATE, + randomNameModel, "false", cldsService.getModel(randomNameModel)); + assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); + assertNotNull(responseEntity.getBody()); + assertTrue(CldsModel.STATUS_ACTIVE.equals(((CldsModel) responseEntity.getBody()).getStatus())); + assertTrue(CldsModel.STATUS_ACTIVE.equals(cldsService.getModel(randomNameModel).getStatus())); + responseEntity = cldsService.unDeployModel(randomNameModel, cldsService.getModel(randomNameModel)); assertNotNull(responseEntity); assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); @@ -221,6 +244,22 @@ public class CldsServiceItCase { assertTrue(CldsModel.STATUS_DISTRIBUTED.equals(((CldsModel) responseEntity.getBody()).getStatus())); assertTrue(CldsModel.STATUS_DISTRIBUTED.equals(cldsService.getModel(randomNameModel).getStatus())); + responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_DELETE, + randomNameModel, "false", cldsService.getModel(randomNameModel)); + assertNotNull(responseEntity); + assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); + assertNotNull(responseEntity.getBody()); + try { + cldsService.getModel(randomNameModel); + fail("Should have raised an NotFoundException exception"); + } catch(NotFoundException ne) { + + } + + } + + @Test + public void testDcaePost() { DcaeEvent dcaeEvent = new DcaeEvent(); dcaeEvent.setArtifactName("ClosedLoop_with-enough-characters_TestArtifact.yml"); dcaeEvent.setEvent(DcaeEvent.EVENT_CREATED); -- cgit 1.2.3-korg