diff options
author | sebdet <sebastien.determe@intl.att.com> | 2018-11-08 17:11:10 +0100 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2018-11-09 10:32:54 +0100 |
commit | 2579386298fc4862a87073f8c719986925d77424 (patch) | |
tree | 58e8cff333a1d3c4b6eb4958b3457b22c39e41b4 /src | |
parent | ac4958ae6d30e60c5cf0bd66ce8f3c79191c6726 (diff) |
Fix DCAE status refresh
Fix the DCAE status refresh that was not done during the loading of the
model in Clamp
Issue-ID: CLAMP-246
Change-Id: I61ec1de74d46879ba638833bcab5143966d37228
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src')
9 files changed, 264 insertions, 298 deletions
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 8dfa190e..8ae10b27 100644 --- a/src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/CldsEventDelegate.java @@ -27,7 +27,6 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import org.apache.camel.Exchange; -import org.apache.camel.Handler; import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.model.CldsEvent; import org.springframework.beans.factory.annotation.Autowired; @@ -49,23 +48,26 @@ public class CldsEventDelegate { * * @param camelExchange * The Camel Exchange object containing the properties + * @param actionState + * The action state that is used instead of the one in exchange property */ - @Handler - public void execute(Exchange camelExchange) { + + public void addEvent(Exchange camelExchange, String actionState) { String controlName = (String) camelExchange.getProperty("controlName"); String actionCd = (String) camelExchange.getProperty("actionCd"); - String actionStateCd = ((String) camelExchange.getProperty("actionStateCd")) != null + String actionStateCd = (actionState != null) ? actionState : CldsEvent.ACTION_STATE_COMPLETED; + 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()); - } + : 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()); + } } } diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java index d3e89fb6..121114b3 100644 --- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java +++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java @@ -86,6 +86,7 @@ public class CldsDao { private SimpleJdbcCall procInsertDictionaryElement; private static final String DATE_FORMAT = "MM-dd-yyyy HH:mm:ss"; + /** * Log message when instantiating */ @@ -184,6 +185,7 @@ public class CldsDao { .addValue("v_model_prop_text", model.getPropText()) .addValue("v_model_blueprint_text", model.getBlueprintText()) .addValue("v_service_type_id", model.getTypeId()).addValue("v_deployment_id", model.getDeploymentId()) + .addValue("v_deployment_status_url", model.getDeploymentStatusUrl()) .addValue("v_control_name_prefix", model.getControlNamePrefix()) .addValue(V_CONTROL_NAME_UUID, model.getControlNameUuid()); Map<String, Object> out = logSqlExecution(procSetModel, in); @@ -475,6 +477,7 @@ public class CldsDao { model.getEvent().setUserid((String) out.get("v_event_user_id")); model.setTypeId((String) out.get("v_service_type_id")); model.setDeploymentId((String) out.get("v_deployment_id")); + model.setDeploymentStatusUrl((String) out.get("v_deployment_status_url")); } /** @@ -525,18 +528,19 @@ public class CldsDao { } toscaModelSql += " AND tmr.version = (select max(version) from tosca_model_revision st where tmr.tosca_model_id=st.tosca_model_id)"; - Optional.ofNullable(jdbcTemplateObject.queryForList(toscaModelSql, params)).orElse(Collections.emptyList()).forEach(row -> { - CldsToscaModel cldsToscaModel = new CldsToscaModel(); - cldsToscaModel.setId((String) row.get("tosca_model_id")); - cldsToscaModel.setPolicyType((String) row.get("policy_type")); - cldsToscaModel.setToscaModelName((String) row.get("tosca_model_name")); - cldsToscaModel.setUserId((String) row.get("user_id")); - cldsToscaModel.setRevisionId((String) row.get("tosca_model_revision_id")); - cldsToscaModel.setVersion(((Double) row.get("version"))); - cldsToscaModel.setCreatedDate(sdf.format(row.get("createdTimestamp"))); - cldsToscaModel.setToscaModelYaml((String) row.get("tosca_model_yaml")); - cldsToscaModels.add(cldsToscaModel); - }); + Optional.ofNullable(jdbcTemplateObject.queryForList(toscaModelSql, params)).orElse(Collections.emptyList()) + .forEach(row -> { + CldsToscaModel cldsToscaModel = new CldsToscaModel(); + cldsToscaModel.setId((String) row.get("tosca_model_id")); + cldsToscaModel.setPolicyType((String) row.get("policy_type")); + cldsToscaModel.setToscaModelName((String) row.get("tosca_model_name")); + cldsToscaModel.setUserId((String) row.get("user_id")); + cldsToscaModel.setRevisionId((String) row.get("tosca_model_revision_id")); + cldsToscaModel.setVersion(((Double) row.get("version"))); + cldsToscaModel.setCreatedDate(sdf.format(row.get("createdTimestamp"))); + cldsToscaModel.setToscaModelYaml((String) row.get("tosca_model_yaml")); + cldsToscaModels.add(cldsToscaModel); + }); return cldsToscaModels; } @@ -626,15 +630,16 @@ public class CldsDao { .map(Arrays::stream).map(s -> s.map(param -> param + " = :" + param).collect(Collectors.joining(" AND "))) .orElse("1"); - Optional.ofNullable(jdbcTemplateObject.queryForList(dictionarySql, namedParameters)).orElse(Collections.emptyList()).forEach(row -> { - CldsDictionary cldsDictionary = new CldsDictionary(); - cldsDictionary.setDictionaryId((String) row.get("dictionary_id")); - cldsDictionary.setDictionaryName((String) row.get("dictionary_name")); - cldsDictionary.setCreatedBy((String) row.get("created_by")); - cldsDictionary.setUpdatedBy((String) row.get("modified_by")); - cldsDictionary.setLastUpdatedDate(sdf.format(row.get("timestamp"))); - dictionaries.add(cldsDictionary); - }); + Optional.ofNullable(jdbcTemplateObject.queryForList(dictionarySql, namedParameters)) + .orElse(Collections.emptyList()).forEach(row -> { + CldsDictionary cldsDictionary = new CldsDictionary(); + cldsDictionary.setDictionaryId((String) row.get("dictionary_id")); + cldsDictionary.setDictionaryName((String) row.get("dictionary_name")); + cldsDictionary.setCreatedBy((String) row.get("created_by")); + cldsDictionary.setUpdatedBy((String) row.get("modified_by")); + cldsDictionary.setLastUpdatedDate(sdf.format(row.get("timestamp"))); + dictionaries.add(cldsDictionary); + }); return dictionaries; } @@ -671,8 +676,7 @@ public class CldsDao { .addValue("dict_element_name", cldsDictionaryItem.getDictElementName()) .addValue("dict_element_short_name", cldsDictionaryItem.getDictElementShortName()) .addValue("dict_element_description", cldsDictionaryItem.getDictElementDesc()) - .addValue("dict_element_type", cldsDictionaryItem.getDictElementType()) - .addValue("modified_by", userId) + .addValue("dict_element_type", cldsDictionaryItem.getDictElementType()).addValue("modified_by", userId) .addValue("dict_element_id", dictionaryElementId); jdbcTemplateObject.update(dictionarySql, namedParameters); cldsDictionaryItem.setUpdatedBy(userId); @@ -695,31 +699,32 @@ public class CldsDao { String dictionarySql = "SELECT de.dict_element_id, de.dictionary_id, de.dict_element_name, de.dict_element_short_name, de.dict_element_description, de.dict_element_type, de.created_by, de.modified_by, de.timestamp " + "FROM dictionary_elements de, dictionary d WHERE de.dictionary_id = d.dictionary_id "; if (dictionaryId != null) { - dictionarySql+=" AND d.dictionary_id = :dictionaryId"; + dictionarySql += " AND d.dictionary_id = :dictionaryId"; namedParameters.addValue("dictionaryId", dictionaryId); } - if (dictElementShortName!=null) { - dictionarySql+=" AND de.dict_element_short_name = :dictElementShortName"; + if (dictElementShortName != null) { + dictionarySql += " AND de.dict_element_short_name = :dictElementShortName"; namedParameters.addValue("dictElementShortName", dictElementShortName); } - if (dictionaryName!=null) { - dictionarySql+=" AND dictionary_name = :dictionaryName"; + if (dictionaryName != null) { + dictionarySql += " AND dictionary_name = :dictionaryName"; namedParameters.addValue("dictionaryName", dictionaryName); } - Optional.ofNullable(jdbcTemplateObject.queryForList(dictionarySql,namedParameters)).orElse(Collections.emptyList()).forEach(row -> { - CldsDictionaryItem dictionaryItem = new CldsDictionaryItem(); - dictionaryItem.setDictElementId((String) row.get("dict_element_id")); - dictionaryItem.setDictionaryId((String) row.get("dictionary_id")); - dictionaryItem.setDictElementName((String) row.get("dict_element_name")); - dictionaryItem.setDictElementShortName((String) row.get("dict_element_short_name")); - dictionaryItem.setDictElementDesc((String) row.get("dict_element_description")); - dictionaryItem.setDictElementType((String) row.get("dict_element_type")); - dictionaryItem.setCreatedBy((String) row.get("created_by")); - dictionaryItem.setUpdatedBy((String) row.get("modified_by")); - dictionaryItem.setLastUpdatedDate(sdf.format(row.get("timestamp"))); - dictionaryItems.add(dictionaryItem); - }); + Optional.ofNullable(jdbcTemplateObject.queryForList(dictionarySql, namedParameters)) + .orElse(Collections.emptyList()).forEach(row -> { + CldsDictionaryItem dictionaryItem = new CldsDictionaryItem(); + dictionaryItem.setDictElementId((String) row.get("dict_element_id")); + dictionaryItem.setDictionaryId((String) row.get("dictionary_id")); + dictionaryItem.setDictElementName((String) row.get("dict_element_name")); + dictionaryItem.setDictElementShortName((String) row.get("dict_element_short_name")); + dictionaryItem.setDictElementDesc((String) row.get("dict_element_description")); + dictionaryItem.setDictElementType((String) row.get("dict_element_type")); + dictionaryItem.setCreatedBy((String) row.get("created_by")); + dictionaryItem.setUpdatedBy((String) row.get("modified_by")); + dictionaryItem.setLastUpdatedDate(sdf.format(row.get("timestamp"))); + dictionaryItems.add(dictionaryItem); + }); return dictionaryItems; } } diff --git a/src/main/java/org/onap/clamp/clds/model/CldsEvent.java b/src/main/java/org/onap/clamp/clds/model/CldsEvent.java index 8d3807b7..90dc996c 100644 --- a/src/main/java/org/onap/clamp/clds/model/CldsEvent.java +++ b/src/main/java/org/onap/clamp/clds/model/CldsEvent.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * + * */ package org.onap.clamp.clds.model; @@ -31,7 +31,6 @@ import org.onap.clamp.clds.dao.CldsDao; public class CldsEvent { public static final String ACTION_TEST = "TEST"; public static final String ACTION_CREATE = "CREATE"; - public static final String ACTION_MODIFY = "MODIFY"; public static final String ACTION_SUBMIT = "SUBMIT"; // an update before model is active public static final String ACTION_RESUBMIT = "RESUBMIT"; @@ -80,15 +79,15 @@ public class CldsEvent { * @return */ public static CldsEvent insEvent(CldsDao cldsDao, String controlName, String userid, String actionCd, - String actionStateCd, String processInstanceId) { + String actionStateCd, String processInstanceId) { CldsModel model = CldsModel.createUsingControlName(controlName); return insEvent(cldsDao, model, userid, actionCd, actionStateCd, processInstanceId); } /** - * Insert event using controlNameUuid to find the model. This method meant - * for processing events from dcae. - * + * Insert event using controlNameUuid to find the model. This method meant for + * processing events from dcae. + * * @param cldsDao * @param model * @param userId @@ -98,7 +97,7 @@ public class CldsEvent { * @return */ public static CldsEvent insEvent(CldsDao cldsDao, CldsModel model, String userId, String actionCd, - String actionStateCd, String processInstanceId) { + String actionStateCd, String processInstanceId) { CldsEvent event = new CldsEvent(); event.setUserid(userId); event.setActionCd(actionCd); @@ -109,9 +108,9 @@ public class CldsEvent { } /** - * Check if actionCd is equal to the supplied checkActionCd checkActionCd - * should not be null. - * + * Check if actionCd is equal to the supplied checkActionCd checkActionCd should + * not be null. + * * @param checkActionCd * @return */ @@ -123,9 +122,9 @@ public class CldsEvent { } /** - * Check if actionCd and actionStateCd are equal to the supplied - * checkActionCd and checkActionStateCd. Treat checkActionStateCd == null as - * a wildcard checkActionCd should not be null. + * Check if actionCd and actionStateCd are equal to the supplied checkActionCd + * and checkActionStateCd. Treat checkActionStateCd == null as a wildcard + * checkActionCd should not be null. * * @param checkActionCd * @param checkActionStateCd @@ -163,7 +162,7 @@ public class CldsEvent { /** * @param actionCd - * the actionCd to set + * the actionCd to set */ public void setActionCd(String actionCd) { this.actionCd = actionCd; @@ -178,7 +177,7 @@ public class CldsEvent { /** * @param actionStateCd - * the actionStateCd to set + * the actionStateCd to set */ public void setActionStateCd(String actionStateCd) { this.actionStateCd = actionStateCd; @@ -193,7 +192,7 @@ public class CldsEvent { /** * @param processInstanceId - * the processInstanceId to set + * the processInstanceId to set */ public void setProcessInstanceId(String processInstanceId) { this.processInstanceId = processInstanceId; @@ -208,7 +207,7 @@ public class CldsEvent { /** * @param userid - * the userid to set + * the userid to set */ public void setUserid(String userid) { this.userid = userid; diff --git a/src/main/java/org/onap/clamp/clds/model/CldsModel.java b/src/main/java/org/onap/clamp/clds/model/CldsModel.java index 1d145625..14fe4439 100644 --- a/src/main/java/org/onap/clamp/clds/model/CldsModel.java +++ b/src/main/java/org/onap/clamp/clds/model/CldsModel.java @@ -75,6 +75,7 @@ public class CldsModel { private String typeId; private String typeName; private String deploymentId; + private String deploymentStatusUrl; /** * Construct empty model. @@ -97,7 +98,7 @@ public class CldsModel { return model; } - public boolean canInventoryCall() { + public boolean canDcaeInventoryCall() { boolean canCall = false; /* Below checks the clds event is submit/resubmit/distribute */ if (event.isActionCd(CldsEvent.ACTION_SUBMIT) || event.isActionCd(CldsEvent.ACTION_RESUBMIT) @@ -120,31 +121,27 @@ public class CldsModel { /** * set the status in the model */ - private void determineStatus() { + public void determineStatus() { status = STATUS_UNKNOWN; if (event == null || event.getActionCd() == null) { status = STATUS_DESIGN; } else if (event.isActionStateCd(CldsEvent.ACTION_STATE_ERROR)) { status = STATUS_ERROR; - } else if (event.isActionAndStateCd(CldsEvent.ACTION_CREATE, CldsEvent.ACTION_STATE_ANY) - || event.isActionAndStateCd(CldsEvent.ACTION_SUBMIT, CldsEvent.ACTION_STATE_ANY) - || event.isActionAndStateCd(CldsEvent.ACTION_RESUBMIT, CldsEvent.ACTION_STATE_ANY) - || event.isActionAndStateCd(CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_STATE_ANY) - || event.isActionAndStateCd(CldsEvent.ACTION_DELETE, CldsEvent.ACTION_STATE_RECEIVED) - || event.isActionAndStateCd(CldsEvent.ACTION_MODIFY, CldsEvent.ACTION_STATE_ANY)) { + } else if (event.isActionAndStateCd(CldsEvent.ACTION_CREATE, CldsEvent.ACTION_STATE_ANY)) { status = STATUS_DESIGN; } else if (event.isActionAndStateCd(CldsEvent.ACTION_DISTRIBUTE, CldsEvent.ACTION_STATE_RECEIVED) - || event.isActionAndStateCd(CldsEvent.ACTION_UNDEPLOY, CldsEvent.ACTION_STATE_RECEIVED)) { + || event.isActionAndStateCd(CldsEvent.ACTION_UNDEPLOY, CldsEvent.ACTION_STATE_COMPLETED) + || event.isActionAndStateCd(CldsEvent.ACTION_SUBMIT, CldsEvent.ACTION_STATE_COMPLETED) + || event.isActionAndStateCd(CldsEvent.ACTION_RESUBMIT, CldsEvent.ACTION_STATE_COMPLETED)) { status = STATUS_DISTRIBUTED; } else if (event.isActionAndStateCd(CldsEvent.ACTION_DELETE, CldsEvent.ACTION_STATE_SENT)) { status = STATUS_DELETING; - } else if (event.isActionAndStateCd(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_STATE_RECEIVED) - || event.isActionAndStateCd(CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_ANY) - || event.isActionAndStateCd(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STATE_ANY) - || event.isActionAndStateCd(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_STATE_ANY) + } else if (event.isActionAndStateCd(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_STATE_COMPLETED) + || event.isActionAndStateCd(CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_COMPLETED) + || event.isActionAndStateCd(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STATE_COMPLETED) || event.isActionAndStateCd(CldsEvent.ACTION_SUBMITPOLICY, CldsEvent.ACTION_STATE_ANY)) { status = STATUS_ACTIVE; - } else if (event.isActionAndStateCd(CldsEvent.ACTION_STOP, CldsEvent.ACTION_STATE_ANY)) { + } else if (event.isActionAndStateCd(CldsEvent.ACTION_STOP, CldsEvent.ACTION_STATE_COMPLETED)) { status = STATUS_STOPPED; } } @@ -176,39 +173,23 @@ public class CldsModel { } /** - * Determine permittedActionCd list using the actionCd from the current - * event. It's a states graph, given the next action that can be executed - * from the one that has been executed (described in the event object). - * ACTION_CREATE being the first one. + * Determine permittedActionCd list using the actionCd from the current event. + * It's a states graph, given the next action that can be executed from the one + * that has been executed (described in the event object). ACTION_CREATE being + * the first one. */ - private void determinePermittedActionCd() { + public void determinePermittedActionCd() { String actionCd = getCurrentActionCd(); switch (actionCd) { case CldsEvent.ACTION_CREATE: - permittedActionCd = Arrays.asList(CldsEvent.ACTION_SUBMIT, CldsEvent.ACTION_TEST, - CldsEvent.ACTION_DELETE); + permittedActionCd = Arrays.asList(CldsEvent.ACTION_SUBMIT, CldsEvent.ACTION_TEST, CldsEvent.ACTION_DELETE); if (isSimplifiedModel()) { permittedActionCd = Arrays.asList(CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_SUBMITPOLICY, CldsEvent.ACTION_TEST, CldsEvent.ACTION_DELETE); } break; - case CldsEvent.ACTION_MODIFY: - permittedActionCd = Arrays.asList(CldsEvent.ACTION_RESUBMIT, CldsEvent.ACTION_DELETE); - if (isSimplifiedModel()) { - permittedActionCd = Arrays.asList(CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_SUBMITPOLICY, - CldsEvent.ACTION_DELETE); - } - break; case CldsEvent.ACTION_SUBMIT: case CldsEvent.ACTION_RESUBMIT: - permittedActionCd = Arrays.asList(CldsEvent.ACTION_RESUBMIT, CldsEvent.ACTION_DELETE); - break; - case CldsEvent.ACTION_SUBMITDCAE: - permittedActionCd = Arrays.asList(CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_DELETE); - break; - case CldsEvent.ACTION_SUBMITPOLICY: - permittedActionCd = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP); - break; case CldsEvent.ACTION_DISTRIBUTE: permittedActionCd = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_RESUBMIT, CldsEvent.ACTION_DELETE); @@ -217,6 +198,12 @@ public class CldsModel { CldsEvent.ACTION_DELETE); } break; + case CldsEvent.ACTION_SUBMITDCAE: + permittedActionCd = Arrays.asList(CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_DELETE); + break; + case CldsEvent.ACTION_SUBMITPOLICY: + permittedActionCd = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP); + break; case CldsEvent.ACTION_UNDEPLOY: permittedActionCd = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_RESUBMIT, CldsEvent.ACTION_DELETE); @@ -226,13 +213,13 @@ public class CldsModel { } break; case CldsEvent.ACTION_DEPLOY: - permittedActionCd = Arrays.asList(CldsEvent.ACTION_UNDEPLOY, - CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP); + permittedActionCd = Arrays.asList(CldsEvent.ACTION_UNDEPLOY, CldsEvent.ACTION_UPDATE, + CldsEvent.ACTION_STOP); break; case CldsEvent.ACTION_RESTART: case CldsEvent.ACTION_UPDATE: - permittedActionCd = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_UPDATE, - CldsEvent.ACTION_STOP, CldsEvent.ACTION_UNDEPLOY); + permittedActionCd = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP, + CldsEvent.ACTION_UNDEPLOY); if (isPolicyOnly()) { permittedActionCd = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP); } @@ -283,30 +270,30 @@ public class CldsModel { } /** - * Validate requestedActionCd - determine permittedActionCd and then check - * if contained in permittedActionCd Throw IllegalArgumentException if - * requested actionCd is not permitted. + * Validate requestedActionCd - determine permittedActionCd and then check if + * contained in permittedActionCd Throw IllegalArgumentException if requested + * actionCd is not permitted. */ public void validateAction(String requestedActionCd) { determinePermittedActionCd(); if (!permittedActionCd.contains(requestedActionCd)) { throw new IllegalArgumentException( - "Invalid requestedActionCd: " + requestedActionCd + ". Given current actionCd: " - + getCurrentActionCd() + ", the permittedActionCd: " + permittedActionCd); + "Invalid requestedActionCd: " + requestedActionCd + ". Given current actionCd: " + getCurrentActionCd() + + ", the permittedActionCd: " + permittedActionCd); } } /** - * Extract the UUID portion of a given full control name (controlNamePrefix - * + controlNameUuid). No fields are populated other than controlNamePrefix - * and controlNameUuid. Throws BadRequestException if length of given - * control name is less than UUID_LENGTH. + * Extract the UUID portion of a given full control name (controlNamePrefix + + * controlNameUuid). No fields are populated other than controlNamePrefix and + * controlNameUuid. Throws BadRequestException if length of given control name + * is less than UUID_LENGTH. */ public static CldsModel createUsingControlName(String fullControlName) { if (fullControlName == null || fullControlName.length() < UUID_LENGTH) { throw new BadRequestException( "closed loop id / control name length, " + (fullControlName != null ? fullControlName.length() : 0) - + ", less than the minimum of: " + UUID_LENGTH); + + ", less than the minimum of: " + UUID_LENGTH); } CldsModel model = new CldsModel(); model.setControlNamePrefix(fullControlName.substring(0, fullControlName.length() - UUID_LENGTH)); @@ -329,9 +316,9 @@ public class CldsModel { CldsModel cldsModel = createUsingControlName(controlName); cldsModel = cldsDao.getModelByUuid(cldsModel.getControlNameUuid()); cldsModel.determineStatus(); - if (dcaeEvent.getCldsActionCd().equals(CldsEvent.ACTION_UNDEPLOY) || (dcaeEvent.getCldsActionCd() - .equals(CldsEvent.ACTION_DEPLOY) - && (cldsModel.getStatus().equals(STATUS_DISTRIBUTED) || cldsModel.getStatus().equals(STATUS_DESIGN)))) { + if (dcaeEvent.getCldsActionCd().equals(CldsEvent.ACTION_UNDEPLOY) + || (dcaeEvent.getCldsActionCd().equals(CldsEvent.ACTION_DEPLOY) + && (cldsModel.getStatus().equals(STATUS_DISTRIBUTED) || cldsModel.getStatus().equals(STATUS_DESIGN)))) { CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userid, dcaeEvent.getCldsActionCd(), CldsEvent.ACTION_STATE_RECEIVED, null); } @@ -348,7 +335,7 @@ public class CldsModel { /** * @param name - * the name to set + * the name to set */ public void setName(String name) { this.name = name; @@ -382,7 +369,7 @@ public class CldsModel { /** * @param controlNamePrefix - * the controlNamePrefix to set + * the controlNamePrefix to set */ public void setControlNamePrefix(String controlNamePrefix) { this.controlNamePrefix = controlNamePrefix; @@ -397,7 +384,7 @@ public class CldsModel { /** * @param controlNameUuid - * the controlNameUuid to set + * the controlNameUuid to set */ public void setControlNameUuid(String controlNameUuid) { this.controlNameUuid = controlNameUuid; @@ -412,7 +399,7 @@ public class CldsModel { /** * @param propText - * the propText to set + * the propText to set */ public void setPropText(String propText) { this.propText = propText; @@ -443,7 +430,7 @@ public class CldsModel { /** * @param event - * the event to set + * the event to set */ public void setEvent(CldsEvent event) { this.event = event; @@ -458,7 +445,7 @@ public class CldsModel { /** * @param status - * the status to set + * the status to set */ public void setStatus(String status) { this.status = status; @@ -530,4 +517,12 @@ public class CldsModel { public void setErrorMessageForUi(String errorMessageForUi) { this.errorMessageForUi = errorMessageForUi; } + + public String getDeploymentStatusUrl() { + return deploymentStatusUrl; + } + + public void setDeploymentStatusUrl(String deploymentStatusUrl) { + this.deploymentStatusUrl = deploymentStatusUrl; + } } diff --git a/src/main/java/org/onap/clamp/clds/model/DcaeEvent.java b/src/main/java/org/onap/clamp/clds/model/DcaeEvent.java index d5737119..7c76af2e 100644 --- a/src/main/java/org/onap/clamp/clds/model/DcaeEvent.java +++ b/src/main/java/org/onap/clamp/clds/model/DcaeEvent.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * + * */ package org.onap.clamp.clds.model; @@ -32,16 +32,16 @@ import javax.ws.rs.BadRequestException; */ public class DcaeEvent { // this is an event we (clds) sends to dcae - public static final String EVENT_CREATED = "created"; - public static final String EVENT_DISTRIBUTION = "distribute"; - public static final String EVENT_DEPLOYMENT = "deployment"; - public static final String EVENT_UNDEPLOYMENT = "undeployment"; - public static final String ARTIFACT_NAME_SUFFIX = ".yml"; - - private String event; - private String serviceUUID; - private String resourceUUID; - private String artifactName; // controlName.yml + public static final String EVENT_CREATED = "created"; + public static final String EVENT_DISTRIBUTION = "distribute"; + public static final String EVENT_DEPLOYMENT = "deployment"; + public static final String EVENT_UNDEPLOYMENT = "undeployment"; + public static final String ARTIFACT_NAME_SUFFIX = ".yml"; + + private String event; + private String serviceUUID; + private String resourceUUID; + private String artifactName; // controlName.yml private List<CldsModelInstance> instances; /** @@ -56,7 +56,7 @@ public class DcaeEvent { return CldsEvent.ACTION_CREATE; } else if (event.equalsIgnoreCase(EVENT_DISTRIBUTION)) { return CldsEvent.ACTION_DISTRIBUTE; - } else if (event.equalsIgnoreCase(EVENT_DEPLOYMENT) && (instances == null || instances.size() == 0)) { + } else if (event.equalsIgnoreCase(EVENT_DEPLOYMENT) && (instances == null || instances.isEmpty())) { return CldsEvent.ACTION_DEPLOY; } else if (event.equalsIgnoreCase(EVENT_DEPLOYMENT)) { return CldsEvent.ACTION_DEPLOY; @@ -83,7 +83,7 @@ public class DcaeEvent { return artifactName.substring(0, artifactName.length() - ARTIFACT_NAME_SUFFIX.length()); } else { throw new BadRequestException("artifactName value not valid (expecting it to end with " - + ARTIFACT_NAME_SUFFIX + "): " + artifactName); + + ARTIFACT_NAME_SUFFIX + "): " + artifactName); } } @@ -96,7 +96,7 @@ public class DcaeEvent { /** * @param event - * the event to set + * the event to set */ public void setEvent(String event) { this.event = event; @@ -111,7 +111,7 @@ public class DcaeEvent { /** * @param serviceUUID - * the serviceUUID to set + * the serviceUUID to set */ public void setServiceUUID(String serviceUUID) { this.serviceUUID = serviceUUID; @@ -126,7 +126,7 @@ public class DcaeEvent { /** * @param resourceUUID - * the resourceUUID to set + * the resourceUUID to set */ public void setResourceUUID(String resourceUUID) { this.resourceUUID = resourceUUID; @@ -141,7 +141,7 @@ public class DcaeEvent { /** * @param artifactName - * the artifactName to set + * the artifactName to set */ public void setArtifactName(String artifactName) { this.artifactName = artifactName; @@ -154,5 +154,4 @@ public class DcaeEvent { public void setInstances(List<CldsModelInstance> instances) { this.instances = instances; } - } diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java index 56f9ee67..36947aa9 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java @@ -93,8 +93,8 @@ public class CsarInstallerImpl implements CsarInstaller { @PostConstruct public void loadConfiguration() throws IOException { BlueprintParserMappingConfiguration - .createFromJson(appContext.getResource(blueprintMappingFile).getInputStream()).stream() - .forEach(e -> bpmnMapping.put(e.getBlueprintKey(), e.getFiles())); + .createFromJson(appContext.getResource(blueprintMappingFile).getInputStream()).stream() + .forEach(e -> bpmnMapping.put(e.getBlueprintKey(), e.getFiles())); } @Override @@ -102,8 +102,7 @@ public class CsarInstallerImpl implements CsarInstaller { boolean alreadyInstalled = true; for (Entry<String, BlueprintArtifact> blueprint : csar.getMapOfBlueprints().entrySet()) { alreadyInstalled = alreadyInstalled - && (CldsModel.retrieve(cldsDao, buildModelName(csar, blueprint.getKey()), true).getId() != null) - ? true + && (CldsModel.retrieve(cldsDao, buildModelName(csar, blueprint.getKey()), true).getId() != null) ? true : false; } return alreadyInstalled; @@ -120,8 +119,8 @@ public class CsarInstallerImpl implements CsarInstaller { policyScopePrefix = MODEL_NAME_PREFIX; } return policyScopePrefix + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v" - + csar.getSdcNotification().getServiceVersion().replace('.', '_') + "_" - + resourceInstanceName.replaceAll(" ", ""); + + csar.getSdcNotification().getServiceVersion().replace('.', '_') + "_" + + resourceInstanceName.replaceAll(" ", ""); } @Override @@ -218,9 +217,8 @@ public class CsarInstallerImpl implements CsarInstaller { } /** - * This call must be done when deploying the SDC notification as this call - * get the latest version of the artifact (version can be specified to DCAE - * call) + * This call must be done when deploying the SDC notification as this call get + * the latest version of the artifact (version can be specified to DCAE call) * * @param blueprintArtifact * @return The DcaeInventoryResponse object containing the dcae values @@ -239,23 +237,22 @@ public class CsarInstallerImpl implements CsarInstaller { BlueprintParserFilesConfiguration configFiles) throws IOException, SdcArtifactInstallerException { CldsTemplate template = new CldsTemplate(); template.setBpmnId("Sdc-Generated"); - template.setBpmnText( - IOUtils.toString(appContext.getResource(configFiles.getBpmnXmlFilePath()).getInputStream())); + template + .setBpmnText(IOUtils.toString(appContext.getResource(configFiles.getBpmnXmlFilePath()).getInputStream())); template.setPropText( "{\"global\":[{\"name\":\"service\",\"value\":[\"" + blueprintArtifact.getDcaeBlueprint() + "\"]}]}"); - template.setImageText( - IOUtils.toString(appContext.getResource(configFiles.getSvgXmlFilePath()).getInputStream())); + template + .setImageText(IOUtils.toString(appContext.getResource(configFiles.getSvgXmlFilePath()).getInputStream())); template.setName(TEMPLATE_NAME_PREFIX + buildModelName(csar, blueprintArtifact.getResourceAttached().getResourceInstanceName())); template.save(cldsDao, null); logger.info("Fake Clds Template created for blueprint " + blueprintArtifact.getBlueprintArtifactName() - + " with name " + template.getName()); + + " with name " + template.getName()); return template; } private CldsModel createFakeCldsModel(CsarHandler csar, BlueprintArtifact blueprintArtifact, - CldsTemplate cldsTemplate, DcaeInventoryResponse dcaeInventoryResponse) - throws SdcArtifactInstallerException { + CldsTemplate cldsTemplate, DcaeInventoryResponse dcaeInventoryResponse) throws SdcArtifactInstallerException { try { CldsModel cldsModel = new CldsModel(); cldsModel.setName(buildModelName(csar, blueprintArtifact.getResourceAttached().getResourceInstanceName())); @@ -274,7 +271,7 @@ public class CsarInstallerImpl implements CsarInstaller { cldsModel = cldsModel.save(cldsDao, null); cldsModel = setModelPropText(cldsModel, blueprintArtifact, cldsTemplate); logger.info("Fake Clds Model created for blueprint " + blueprintArtifact.getBlueprintArtifactName() - + " with name " + cldsModel.getName()); + + " with name " + cldsModel.getName()); return cldsModel; } catch (TransformerException e) { throw new SdcArtifactInstallerException("TransformerException when decoding the BpmnText", e); 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 2342e89c..8e7785d6 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -248,15 +248,25 @@ public class CldsService extends SecureServiceBase { logger.debug("GET model for modelName={}", modelName); CldsModel cldsModel = CldsModel.retrieve(cldsDao, modelName, false); isAuthorizedForVf(cldsModel); + // Try an update for DCAE status // Checking condition whether our CLDS model can call Inventory Method - if (cldsModel.canInventoryCall()) { - try { - // Method to call dcae inventory and invoke insert event method + try { + // Method to call dcae inventory and invoke insert event method + if (cldsModel.canDcaeInventoryCall() + && !cldsModel.getTemplateName().startsWith(CsarInstallerImpl.TEMPLATE_NAME_PREFIX)) { dcaeInventoryServices.setEventInventory(cldsModel, getUserId()); - } catch (Exception e) { - LoggingUtils.setErrorContext("900", "Set event inventory error"); - logger.error("getModel set event Inventory error:" + e); } + // This is a blocking call + if (cldsModel.getEvent().isActionCd(CldsEvent.ACTION_DEPLOY) + && !CldsModel.STATUS_ACTIVE.equals(cldsModel.getStatus()) && cldsModel.getDeploymentId() != null + && cldsModel.getDeploymentStatusUrl() != null) { + checkDcaeDeploymentStatus(cldsModel, CldsEvent.ACTION_DEPLOY, false); + // refresh because new event may have been added + cldsModel = CldsModel.retrieve(cldsDao, modelName, false); + } + } catch (Exception e) { + LoggingUtils.setErrorContext("900", "Set event inventory error"); + logger.error("getModel set event Inventory error:" + e); } // audit log LoggingUtils.setTimeContext(startTime, new Date()); @@ -279,11 +289,9 @@ public class CldsService extends SecureServiceBase { logger.info("PUT bpmnText={}", cldsModel.getBpmnText()); logger.info("PUT propText={}", cldsModel.getPropText()); logger.info("PUT imageText={}", cldsModel.getImageText()); - cldsModel.setName(modelName); fillInCldsModel(cldsModel); - updateAndInsertNewEvent(cldsModel.getName(), cldsModel.getControlNamePrefix(), cldsModel.getEvent(), - CldsEvent.ACTION_MODIFY); cldsModel.save(cldsDao, getUserId()); + // audit log LoggingUtils.setTimeContext(startTime, new Date()); auditLogger.info("PUT model completed"); @@ -344,10 +352,10 @@ public class CldsService extends SecureServiceBase { throws TransformerException, ParseException { util.entering(request, "CldsService: Process model action"); Date startTime = new Date(); - CldsModel retrievedModel = null; String errorMessage = ""; + String actionCd = ""; try { - String actionCd = action.toUpperCase(); + actionCd = action.toUpperCase(); SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage, cldsPermissionInstance, actionCd); isAuthorized(permisionManage); @@ -362,9 +370,9 @@ public class CldsService extends SecureServiceBase { logger.info("PUT getTypeId={}", model.getTypeId()); logger.info("PUT deploymentId={}", model.getDeploymentId()); this.fillInCldsModel(model); - // save model to db - updateAndInsertNewEvent(modelName, model.getControlNamePrefix(), model.getEvent(), CldsEvent.ACTION_MODIFY); + // save model to db just in case model.save(cldsDao, getUserId()); + // get vars and format if necessary String prop = model.getPropText(); String bpmn = model.getBpmnText(); @@ -388,54 +396,32 @@ public class CldsService extends SecureServiceBase { logger.info("Starting Camel flow on request, result is: ", result); } catch (SdcCommunicationException | PolicyClientException | BadRequestException e) { logger.error("Exception occured during invoking Camel process", e); - errorMessage=e.getMessage(); - } - 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 (!isTest && errorMessage.isEmpty() - && (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()); + errorMessage = e.getMessage(); } // audit log LoggingUtils.setTimeContext(startTime, new Date()); auditLogger.info("Process model action completed"); - } catch (Exception e) { logger.error("Exception occured during putModelAndProcessAction", e); - errorMessage=e.getMessage(); + errorMessage = e.getMessage(); } + if (!errorMessage.isEmpty()) { - if (retrievedModel != null) { - retrievedModel.setErrorMessageForUi(errorMessage); - } + CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), actionCd, CldsEvent.ACTION_STATE_ERROR, + null); + // Need a refresh as new events have been inserted + model = CldsModel.retrieve(cldsDao, modelName, false); + model.setErrorMessageForUi(errorMessage); util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "putModelAndProcessAction failed", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); - return new ResponseEntity<>(retrievedModel, HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(model, HttpStatus.INTERNAL_SERVER_ERROR); + } else { + // Need a refresh as new events have been inserted, could have been deleted so + // not blocking call + model = CldsModel.retrieve(cldsDao, modelName, true); + util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); + return new ResponseEntity<>(model, HttpStatus.OK); } - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return new ResponseEntity<>(retrievedModel, HttpStatus.OK); } /** @@ -464,8 +450,8 @@ public class CldsService extends SecureServiceBase { instanceCount = dcaeEvent.getInstances().size(); } String msgInfo = "event=" + dcaeEvent.getEvent() + " serviceUUID=" + dcaeEvent.getServiceUUID() - + " resourceUUID=" + dcaeEvent.getResourceUUID() + " artifactName=" + dcaeEvent.getArtifactName() - + " instance count=" + instanceCount + " isTest=" + isTest; + + " resourceUUID=" + dcaeEvent.getResourceUUID() + " artifactName=" + dcaeEvent.getArtifactName() + + " instance count=" + instanceCount + " isTest=" + isTest; logger.info("POST dcae event {}", msgInfo); if (isTest) { logger.warn("Ignorning test event from DCAE"); @@ -728,7 +714,7 @@ public class CldsService extends SecureServiceBase { public ResponseEntity<CldsModel> deployModel(String modelName, CldsModel model) { util.entering(request, "CldsService: Deploy model"); Date startTime = new Date(); - String errorMessage=""; + String errorMessage = ""; try { fillInCldsModel(model); String bpmnJson = cldsBpmnTransformer.doXslTransformToString(model.getBpmnText()); @@ -745,37 +731,21 @@ public class CldsService extends SecureServiceBase { if (model.getDeploymentId() != null && !model.getDeploymentId().isEmpty()) { deploymentId = model.getDeploymentId(); } else { - deploymentId = "closedLoop_" + UUID.randomUUID() + "_deploymentId"; + model.setDeploymentId(deploymentId = "closedLoop_" + UUID.randomUUID() + "_deploymentId"); } - String createNewDeploymentStatusUrl = dcaeDispatcherServices.createNewDeployment(deploymentId, - model.getTypeId(), modelProp.getGlobal().getDeployParameters()); - String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(createNewDeploymentStatusUrl); - if ("succeeded".equalsIgnoreCase(operationStatus)) { - String artifactName = model.getControlName(); - if (artifactName != null) { - artifactName = artifactName + ".yml"; - } - DcaeEvent dcaeEvent = new DcaeEvent(); - /* set dcae events */ - dcaeEvent.setArtifactName(artifactName); - dcaeEvent.setEvent(DcaeEvent.EVENT_DEPLOYMENT); - CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), getUserId(), dcaeEvent.getCldsActionCd(), - CldsEvent.ACTION_STATE_RECEIVED, null); - model.setDeploymentId(deploymentId); - model.save(cldsDao, getUserId()); - } else { - logger.info("Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus); - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "DeployModel failed", Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, - "Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus); - } - logger.info("Deploy model (" + modelName + ") succeeded...Deployment Id is - " + deploymentId); + model.setDeploymentStatusUrl(dcaeDispatcherServices.createNewDeployment(deploymentId, model.getTypeId(), + modelProp.getGlobal().getDeployParameters())); + CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), CldsEvent.ACTION_DEPLOY, + CldsEvent.ACTION_STATE_INITIATED, null); + // This is a blocking call + checkDcaeDeploymentStatus(model, CldsEvent.ACTION_DEPLOY, true); + + model.save(cldsDao, getUserId()); // audit log LoggingUtils.setTimeContext(startTime, new Date()); auditLogger.info("Deploy model completed"); } catch (Exception e) { - errorMessage=e.getMessage(); + errorMessage = e.getMessage(); logger.error("Exception occured during deployModel", e); } if (!errorMessage.isEmpty()) { @@ -783,9 +753,10 @@ public class CldsService extends SecureServiceBase { util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "DeployModel failed", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); return new ResponseEntity<>(model, HttpStatus.INTERNAL_SERVER_ERROR); + } else { + util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); + return new ResponseEntity<>(model, HttpStatus.OK); } - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return new ResponseEntity<>(model, HttpStatus.OK); } public ResponseEntity<CldsModel> unDeployModel(String modelName, CldsModel model) { @@ -797,30 +768,15 @@ public class CldsService extends SecureServiceBase { cldsPermissionInstance, CldsEvent.ACTION_UNDEPLOY); isAuthorized(permisionManage); isAuthorizedForVf(model); - String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(), - model.getTypeId()); - String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(operationStatusUndeployUrl); - if ("succeeded".equalsIgnoreCase(operationStatus)) { - String artifactName = model.getControlName(); - if (artifactName != null) { - artifactName = artifactName + ".yml"; - } - DcaeEvent dcaeEvent = new DcaeEvent(); - // set dcae events - dcaeEvent.setArtifactName(artifactName); - dcaeEvent.setEvent(DcaeEvent.EVENT_UNDEPLOYMENT); - CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), dcaeEvent.getCldsActionCd(), - CldsEvent.ACTION_STATE_RECEIVED, null); - model.setDeploymentId(null); - model.save(cldsDao, getUserId()); - } else { - logger.info("Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus); - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "UndeployModel failed", Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, - "Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus); - } - logger.info("Undeploy model (" + modelName + ") succeeded."); + model.setDeploymentStatusUrl( + dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(), model.getTypeId())); + CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), CldsEvent.ACTION_UNDEPLOY, + CldsEvent.ACTION_STATE_INITIATED, null); + // This is a blocking call + checkDcaeDeploymentStatus(model, CldsEvent.ACTION_UNDEPLOY, true); + // clean the deployment ID + model.setDeploymentId(null); + model.save(cldsDao, getUserId()); // audit log LoggingUtils.setTimeContext(startTime, new Date()); auditLogger.info("Undeploy model completed"); @@ -833,9 +789,32 @@ public class CldsService extends SecureServiceBase { util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "UndeployModel failed", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); return new ResponseEntity<>(model, HttpStatus.INTERNAL_SERVER_ERROR); + } else { + util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); + return new ResponseEntity<>(model, HttpStatus.OK); + } + } + + private void checkDcaeDeploymentStatus(CldsModel model, String cldsEvent, boolean withRetry) + throws InterruptedException { + String operationStatus = withRetry + ? dcaeDispatcherServices.getOperationStatusWithRetry(model.getDeploymentStatusUrl()) + : dcaeDispatcherServices.getOperationStatus(model.getDeploymentStatusUrl()); + if ("succeeded".equalsIgnoreCase(operationStatus)) { + logger.info(cldsEvent + " model (" + model.getName() + ") succeeded...Deployment Id is - " + + model.getDeploymentId()); + CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), cldsEvent, + CldsEvent.ACTION_STATE_COMPLETED, null); + } else { + String info = "DCAE " + cldsEvent + " (" + model.getName() + ") failed...Operation Status is - " + + operationStatus; + logger.info(info); + CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), cldsEvent, CldsEvent.ACTION_STATE_ERROR, + null); + util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "DCAE operation(" + cldsEvent + ") failed", + Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); + throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, info); } - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return new ResponseEntity<>(model, HttpStatus.OK); } private void checkForDuplicateServiceVf(String modelName, String modelPropText) throws IOException { @@ -853,28 +832,13 @@ public class CldsService extends SecureServiceBase { if (!modelName.equalsIgnoreCase(cldsModelProp.getName()) && service.equalsIgnoreCase(currentService) && resourceVf.get(0).equalsIgnoreCase(currentVf.get(0))) { throw new BadRequestException("Same Service/VF already exists in " + cldsModelProp.getName() - + " model, please select different Service/VF."); + + " model, please select different Service/VF."); } } } } } - private void updateAndInsertNewEvent(String cldsModelName, String cldsControlNamePrfx, CldsEvent event, - String newAction) { - // If model action is in submit/resubmit/distributed and user try - // to save then we are changing action back to create. - if (event != null && (CldsEvent.ACTION_SUBMIT.equalsIgnoreCase(event.getActionCd()) - || CldsEvent.ACTION_RESUBMIT.equalsIgnoreCase(event.getActionCd()) - || CldsEvent.ACTION_DISTRIBUTE.equalsIgnoreCase(event.getActionCd()))) { - CldsEvent newEvent = new CldsEvent(); - newEvent.setUserid(getUserId()); - newEvent.setActionCd(newAction); - newEvent.setActionStateCd(CldsEvent.ACTION_STATE_COMPLETED); - cldsDao.insEvent(cldsModelName, cldsControlNamePrfx, null, newEvent); - } - } - // Created for the integration test public void setLoggingUtil(LoggingUtils utilP) { util = utilP; diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml index e84c6861..2103b4ac 100644 --- a/src/main/resources/clds/camel/routes/flexible-flow.xml +++ b/src/main/resources/clds/camel/routes/flexible-flow.xml @@ -4,6 +4,7 @@ <choice> <when> <simple> ${exchangeProperty.actionCd} == 'SUBMIT' || ${exchangeProperty.actionCd} == 'RESUBMIT'</simple> + <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" /> <to uri="bean:org.onap.clamp.clds.client.TcaPolicyDelegate" /> <to uri="bean:org.onap.clamp.clds.client.HolmesPolicyDelegate" /> <delay> @@ -11,10 +12,11 @@ </delay> <to uri="bean:org.onap.clamp.clds.client.OperationalPolicyDelegate" /> <to uri="bean:org.onap.clamp.clds.client.GuardPolicyDelegate" /> - <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate" /> + <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'COMPLETED')" /> </when> <when> <simple> ${exchangeProperty.actionCd} == 'DELETE'</simple> + <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" /> <to uri="bean:org.onap.clamp.clds.client.TcaPolicyDeleteDelegate" /> <to uri="bean:org.onap.clamp.clds.client.HolmesPolicyDeleteDelegate" /> <delay> @@ -24,10 +26,11 @@ 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" /> + <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'COMPLETED')" /> </when> <when> <simple> ${exchangeProperty.actionCd} == 'UPDATE'</simple> + <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" /> <to uri="bean:org.onap.clamp.clds.client.TcaPolicyDelegate" /> <to uri="bean:org.onap.clamp.clds.client.HolmesPolicyDelegate" /> <delay> @@ -35,20 +38,22 @@ </delay> <to uri="bean:org.onap.clamp.clds.client.OperationalPolicyDelegate" /> <to uri="bean:org.onap.clamp.clds.client.GuardPolicyDelegate" /> - <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate" /> + <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'COMPLETED')" /> </when> <when> <simple> ${exchangeProperty.actionCd} == 'STOP'</simple> + <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" /> <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.CldsEventDelegate" /> + <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'COMPLETED')" /> </when> <when> <simple> ${exchangeProperty.actionCd} == 'RESTART'</simple> + <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" /> <to uri="bean:org.onap.clamp.clds.client.GuardPolicyDelegate" /> <to uri="bean:org.onap.clamp.clds.client.OperationalPolicyDelegate" /> - <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate" /> + <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'COMPLETED')" /> </when> </choice> </route> diff --git a/src/test/java/org/onap/clamp/clds/model/CldsModelTest.java b/src/test/java/org/onap/clamp/clds/model/CldsModelTest.java index 6ebdc4bb..0a601854 100644 --- a/src/test/java/org/onap/clamp/clds/model/CldsModelTest.java +++ b/src/test/java/org/onap/clamp/clds/model/CldsModelTest.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * + * */ package org.onap.clamp.clds.model; @@ -78,14 +78,14 @@ public class CldsModelTest { cldsModel.getEvent().setActionCd(CldsEvent.ACTION_SUBMIT); cldsModel.validateAction(CldsEvent.ACTION_RESUBMIT); try { - cldsModel.validateAction(CldsEvent.ACTION_DEPLOY); + cldsModel.validateAction(CldsEvent.ACTION_RESTART); fail("Exception should have been sent"); } catch (IllegalArgumentException e) { logger.error("Exception caught IllegalArgumentException as expected", e); } cldsModel.getEvent().setActionCd(CldsEvent.ACTION_RESUBMIT); cldsModel.validateAction(CldsEvent.ACTION_RESUBMIT); - cldsModel.validateAction(CldsEvent.ACTION_DEPLOY); + cldsModel.validateAction(CldsEvent.ACTION_RESTART); fail("Exception should have been sent"); } |