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 <sd378r@intl.att.com>
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 7abb692..a74f4c7 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 @@
* 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 b1243dc..8dfa190 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 @@
* 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 5e35b89..8d497cb 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 @@
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 @@
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<String>("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 0c39952..d01016a 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 @@
$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(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 c7f7ec3..e84c686 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 @@
<simple> ${exchangeProperty.actionCd} == 'DELETE'</simple>
<to uri="bean:org.onap.clamp.clds.client.TcaPolicyDeleteDelegate" />
<to uri="bean:org.onap.clamp.clds.client.HolmesPolicyDeleteDelegate" />
- <to uri="bean:org.onap.clamp.clds.client.ModelDeleteDelegate" />
<delay>
<constant>30000</constant>
</delay>
<to
uri="bean:org.onap.clamp.clds.client.OperationalPolicyDeleteDelegate" />
<to uri="bean:org.onap.clamp.clds.client.GuardPolicyDeleteDelegate" />
+ <to uri="bean:org.onap.clamp.clds.client.ModelDeleteDelegate" />
+ <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate" />
</when>
<when>
<simple> ${exchangeProperty.actionCd} == 'UPDATE'</simple>