From 0387f232b4a56e98092519ccc2e0ee7985f6701c Mon Sep 17 00:00:00 2001 From: sebdet Date: Mon, 9 Sep 2019 17:32:53 +0200 Subject: Remove dead code Removal of dead code not used anymore as part of the V1 interface + new swagger without old v1 interface Issue-ID: CLAMP-487 Change-Id: I56c80c26082b5119f14afc41e26bae1c52b1ba59 Signed-off-by: sebdet --- .../authorization/AuthorizationController.java | 2 +- .../spring/CldsSdcControllerConfiguration.java | 113 - .../config/spring/SdcControllerConfiguration.java | 8 +- src/main/java/org/onap/clamp/clds/dao/CldsDao.java | 299 +-- .../onap/clamp/clds/dao/CldsServiceDataMapper.java | 62 - .../clamp/clds/model/CldsMonitoringDetails.java | 113 - .../controller/installer/CsarInstallerImpl.java | 350 --- .../clamp/clds/service/CldsDictionaryService.java | 179 -- .../org/onap/clamp/clds/service/CldsService.java | 571 +--- .../clamp/clds/service/CldsTemplateService.java | 166 -- .../onap/clamp/clds/service/CldsToscaService.java | 166 -- src/main/resources/META-INF/resources/swagger.html | 2766 ++------------------ .../resources/clds/camel/rest/clds-services.xml | 153 -- .../java/org/onap/clamp/clds/it/CldsDaoItCase.java | 19 +- .../clamp/clds/it/CldsDictionaryServiceItCase.java | 177 -- .../org/onap/clamp/clds/it/CldsServiceItCase.java | 138 +- .../clamp/clds/it/CldsTemplateServiceItCase.java | 171 -- .../onap/clamp/clds/it/CldsToscaServiceItCase.java | 136 - .../config/SdcControllersConfigurationItCase.java | 12 +- .../sdc/controller/SdcSingleControllerItCase.java | 43 +- .../controller/installer/CsarInstallerItCase.java | 214 -- .../installer/LoopCsarInstallerTest.java | 167 -- 22 files changed, 437 insertions(+), 5588 deletions(-) delete mode 100644 src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java delete mode 100644 src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java delete mode 100644 src/main/java/org/onap/clamp/clds/model/CldsMonitoringDetails.java delete mode 100644 src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java delete mode 100644 src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java delete mode 100644 src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java delete mode 100644 src/main/java/org/onap/clamp/clds/service/CldsToscaService.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/sdc/controller/installer/LoopCsarInstallerTest.java (limited to 'src') diff --git a/src/main/java/org/onap/clamp/authorization/AuthorizationController.java b/src/main/java/org/onap/clamp/authorization/AuthorizationController.java index 2e43495b7..f9e618c83 100644 --- a/src/main/java/org/onap/clamp/authorization/AuthorizationController.java +++ b/src/main/java/org/onap/clamp/authorization/AuthorizationController.java @@ -44,7 +44,7 @@ import org.springframework.security.core.GrantedAuthority; import org.springframework.stereotype.Component; /** - * Create CLDS Event. + * Verify user has right permissions. */ @Component public class AuthorizationController { diff --git a/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java b/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java deleted file mode 100644 index bee0d4c05..000000000 --- a/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java +++ /dev/null @@ -1,113 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * * Modifications copyright (c) 2019 Nokia - * =================================================================== - * - */ - -package org.onap.clamp.clds.config.spring; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.onap.clamp.clds.config.ClampProperties; -import org.onap.clamp.clds.config.sdc.SdcControllersConfiguration; -import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException; -import org.onap.clamp.clds.sdc.controller.SdcSingleController; -import org.onap.clamp.clds.sdc.controller.SdcSingleControllerStatus; -import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.scheduling.annotation.Scheduled; - -@Configuration -@ComponentScan(basePackages = "org.onap.clamp.clds") -@Profile("clamp-sdc-controller") -public class CldsSdcControllerConfiguration { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSdcControllerConfiguration.class); - private List sdcControllersList = new ArrayList<>(); - private final ClampProperties clampProp; - private final CsarInstaller csarInstaller; - - public CldsSdcControllerConfiguration(ClampProperties clampProp, @Qualifier("oldModelInstaller") CsarInstaller csarInstaller) { - this.clampProp = clampProp; - this.csarInstaller = csarInstaller; - } - - /** - * Loads SDC controllers configuration. - */ - @PostConstruct - public void loadSdcControllers() { - SdcControllersConfiguration sdcControllersConfig = getSdcControllersConfiguration(); - sdcControllersConfig.getAllDefinedControllers().forEach((k, v) -> { - logger.info("Creating controller instance:" + k); - SdcSingleController sdcController = new SdcSingleController(clampProp, csarInstaller, v, null); - sdcControllersList.add(sdcController); - }); - } - - /** - * Checks whether all SDC controllers defined are up and running. - */ - @Scheduled(fixedRate = 120000) - public void checkAllSdcControllers() { - logger.info("Checking that all SDC Controllers defined are up and running"); - for (SdcSingleController controller : sdcControllersList) { - try { - if (SdcSingleControllerStatus.STOPPED.equals(controller.getControllerStatus())) { - controller.initSdc(); - } - } catch (SdcControllerException e) { - logger.error("Exception caught when booting sdc controller", e); - } - } - logger.info("SDC Controllers check completed"); - } - - /** - * Closes all SDC Controller and the SDC Client. - */ - @PreDestroy - public void killSdcControllers() { - sdcControllersList.forEach(e -> { - try { - e.closeSdc(); - } catch (SdcControllerException e1) { - logger.error("Exception caught when stopping sdc controller", e1); - } - }); - } - - @Bean(name = "sdcControllersConfiguration") - public SdcControllersConfiguration getSdcControllersConfiguration() { - return new SdcControllersConfiguration(); - } -} \ No newline at end of file diff --git a/src/main/java/org/onap/clamp/clds/config/spring/SdcControllerConfiguration.java b/src/main/java/org/onap/clamp/clds/config/spring/SdcControllerConfiguration.java index 8b8ee932b..b4794c940 100644 --- a/src/main/java/org/onap/clamp/clds/config/spring/SdcControllerConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/spring/SdcControllerConfiguration.java @@ -25,10 +25,13 @@ package org.onap.clamp.clds.config.spring; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; + import java.util.ArrayList; import java.util.List; + import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; + import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.config.sdc.SdcControllersConfiguration; import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException; @@ -44,7 +47,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.scheduling.annotation.Scheduled; @Configuration -@ComponentScan(basePackages = {"org.onap.clamp.loop", "org.onap.clamp.clds.config"}) +@ComponentScan(basePackages = { "org.onap.clamp.loop", "org.onap.clamp.clds.config" }) @Profile("clamp-sdc-controller-new") public class SdcControllerConfiguration { @@ -54,7 +57,8 @@ public class SdcControllerConfiguration { private final CsarInstaller csarInstaller; @Autowired - public SdcControllerConfiguration(ClampProperties clampProp, @Qualifier("loopInstaller") CsarInstaller csarInstaller) { + public SdcControllerConfiguration(ClampProperties clampProp, + @Qualifier("loopInstaller") CsarInstaller csarInstaller) { this.clampProp = clampProp; this.csarInstaller = csarInstaller; } 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 16a6a748c..91ddfc480 100644 --- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java +++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java @@ -42,7 +42,6 @@ import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsModel; import org.onap.clamp.clds.model.CldsModelInstance; import org.onap.clamp.clds.model.CldsModelProp; -import org.onap.clamp.clds.model.CldsMonitoringDetails; import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.model.CldsToscaModel; import org.onap.clamp.clds.model.ValueItem; @@ -95,8 +94,7 @@ public class CldsDao { /** * When dataSource is provided, instantiate spring jdbc objects. * - * @param dataSource - * the data source + * @param dataSource the data source */ public void setDataSource(DataSource dataSource) { this.jdbcTemplateObject = new JdbcTemplate(dataSource); @@ -112,7 +110,7 @@ public class CldsDao { this.procDeleteModel = new SimpleJdbcCall(dataSource).withProcedureName("del_model"); this.procInsertToscaModel = new SimpleJdbcCall(dataSource).withProcedureName("set_tosca_model"); this.procInsertNewToscaModelVersion = new SimpleJdbcCall(dataSource) - .withProcedureName("set_new_tosca_model_version"); + .withProcedureName("set_new_tosca_model_version"); this.procInsertDictionary = new SimpleJdbcCall(dataSource).withProcedureName("set_dictionary"); this.procInsertDictionaryElement = new SimpleJdbcCall(dataSource).withProcedureName("set_dictionary_elements"); } @@ -120,8 +118,7 @@ public class CldsDao { /** * Get a model from the database given the model name. * - * @param modelName - * the model name + * @param modelName the model name * @return the model */ public CldsModel getModel(String modelName) { @@ -133,7 +130,7 @@ public class CldsDao { CldsModel model = new CldsModel(); model.setName(modelName); SqlParameterSource in = new MapSqlParameterSource().addValue("v_model_name", modelName) - .addValue(V_CONTROL_NAME_UUID, controlNameUuid); + .addValue(V_CONTROL_NAME_UUID, controlNameUuid); Map out = logSqlExecution(procGetModel, in); populateModelProperties(model, out); return model; @@ -142,8 +139,7 @@ public class CldsDao { /** * Get a model from the database given the controlNameUuid. * - * @param controlNameUuid - * the control name uuid + * @param controlNameUuid the control name uuid * @return the model by uuid */ public CldsModel getModelByUuid(String controlNameUuid) { @@ -153,8 +149,7 @@ public class CldsDao { /** * Get a model and template information from the database given the model name. * - * @param modelName - * the model name + * @param modelName the model name * @return model model template */ @@ -186,21 +181,19 @@ public class CldsDao { * Update model in the database using parameter values and return updated model * object. * - * @param model - * the model - * @param userid - * the userid + * @param model the model + * @param userid the userid * @return model */ public CldsModel setModel(CldsModel model, String userid) { SqlParameterSource in = new MapSqlParameterSource().addValue("v_model_name", model.getName()) - .addValue("v_template_id", model.getTemplateId()).addValue("v_user_id", userid) - .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()); + .addValue("v_template_id", model.getTemplateId()).addValue("v_user_id", userid) + .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 out = logSqlExecution(procSetModel, in); model.setControlNamePrefix((String) out.get(V_CONTROL_NAME_PREFIX)); model.setControlNameUuid((String) out.get(V_CONTROL_NAME_UUID)); @@ -213,10 +206,8 @@ public class CldsDao { * Inserts new modelInstance in the database using parameter values and return * updated model object. * - * @param model - * the model - * @param modelInstancesList - * the model instances list + * @param model the model + * @param modelInstancesList the model instances list */ public void insModelInstance(CldsModel model, List modelInstancesList) { // Delete all existing model instances for given controlNameUUID @@ -230,9 +221,9 @@ public class CldsDao { logger.debug("v_vm_name={}", currModelInstance.getVmName()); logger.debug("v_location={}", currModelInstance.getLocation()); SqlParameterSource in = new MapSqlParameterSource() - .addValue(V_CONTROL_NAME_UUID, model.getControlNameUuid()) - .addValue("v_vm_name", currModelInstance.getVmName()) - .addValue("v_location", currModelInstance.getLocation()); + .addValue(V_CONTROL_NAME_UUID, model.getControlNameUuid()) + .addValue("v_vm_name", currModelInstance.getVmName()) + .addValue("v_location", currModelInstance.getLocation()); Map out = logSqlExecution(procInsModelInstance, in); model.setId((String) (out.get("v_model_id"))); CldsModelInstance modelInstance = new CldsModelInstance(); @@ -248,23 +239,19 @@ public class CldsDao { * Insert an event in the database - require either modelName or * controlNamePrefix/controlNameUuid. * - * @param modelName - * the model name - * @param controlNamePrefix - * the control name prefix - * @param controlNameUuid - * the control name uuid - * @param cldsEvent - * the clds event + * @param modelName the model name + * @param controlNamePrefix the control name prefix + * @param controlNameUuid the control name uuid + * @param cldsEvent the clds event * @return clds event */ public CldsEvent insEvent(String modelName, String controlNamePrefix, String controlNameUuid, CldsEvent cldsEvent) { CldsEvent event = new CldsEvent(); SqlParameterSource in = new MapSqlParameterSource().addValue("v_model_name", modelName) - .addValue(V_CONTROL_NAME_PREFIX, controlNamePrefix).addValue(V_CONTROL_NAME_UUID, controlNameUuid) - .addValue("v_user_id", cldsEvent.getUserid()).addValue("v_action_cd", cldsEvent.getActionCd()) - .addValue("v_action_state_cd", cldsEvent.getActionStateCd()) - .addValue("v_process_instance_id", cldsEvent.getProcessInstanceId()); + .addValue(V_CONTROL_NAME_PREFIX, controlNamePrefix).addValue(V_CONTROL_NAME_UUID, controlNameUuid) + .addValue("v_user_id", cldsEvent.getUserid()).addValue("v_action_cd", cldsEvent.getActionCd()) + .addValue("v_action_state_cd", cldsEvent.getActionStateCd()) + .addValue("v_process_instance_id", cldsEvent.getProcessInstanceId()); Map out = logSqlExecution(procInsEvent, in); event.setId((String) (out.get("v_event_id"))); return event; @@ -279,14 +266,12 @@ public class CldsDao { /** * Update event with process instance id. * - * @param eventId - * the event id - * @param processInstanceId - * the process instance id + * @param eventId the event id + * @param processInstanceId the process instance id */ public void updEvent(String eventId, String processInstanceId) { SqlParameterSource in = new MapSqlParameterSource().addValue("v_event_id", eventId) - .addValue("v_process_instance_id", processInstanceId); + .addValue("v_process_instance_id", processInstanceId); logSqlExecution(procUpdEvent, in); } @@ -304,16 +289,14 @@ public class CldsDao { * Update template in the database using parameter values and return updated * template object. * - * @param template - * the template - * @param userid - * the userid + * @param template the template + * @param userid the userid */ public void setTemplate(CldsTemplate template, String userid) { SqlParameterSource in = new MapSqlParameterSource().addValue("v_template_name", template.getName()) - .addValue("v_user_id", userid).addValue("v_template_bpmn_text", template.getBpmnText()) - .addValue("v_template_image_text", template.getImageText()) - .addValue("v_template_doc_text", template.getPropText()); + .addValue("v_user_id", userid).addValue("v_template_bpmn_text", template.getBpmnText()) + .addValue("v_template_image_text", template.getImageText()) + .addValue("v_template_doc_text", template.getPropText()); // properties to setup the template is return from the logSqlExecution method setTemplateBaseProp(template, logSqlExecution(procSetTemplate, in)); @@ -332,8 +315,7 @@ public class CldsDao { /** * Get a template from the database given the model name. * - * @param templateName - * the template name + * @param templateName the template name * @return model template */ public CldsTemplate getTemplate(String templateName) { @@ -354,10 +336,8 @@ public class CldsDao { /** * Helper method to setup the base template properties. * - * @param template - * the template - * @param prop - * collection with the properties + * @param template the template + * @param prop collection with the properties */ private void setTemplateBaseProp(CldsTemplate template, Map prop) { template.setId((String) prop.get("v_template_id")); @@ -393,8 +373,8 @@ public class CldsDao { public List getDeployedModelProperties() { List cldsModelPropList = new ArrayList<>(); String modelsSql = "select m.model_id, m.model_name, mp.model_prop_id, mp.model_prop_text FROM model m, " - + "model_properties mp, event e " - + "WHERE m.model_prop_id = mp.model_prop_id and m.event_id = e.event_id and e.action_cd = 'DEPLOY'"; + + "model_properties mp, event e " + + "WHERE m.model_prop_id = mp.model_prop_id and m.event_id = e.event_id and e.action_cd = 'DEPLOY'"; List> rows = jdbcTemplateObject.queryForList(modelsSql); CldsModelProp cldsModelProp = null; for (Map row : rows) { @@ -408,47 +388,10 @@ public class CldsDao { return cldsModelPropList; } - /** - * Method to get deployed/active models with model properties. - * - * @return list of CLDS-Monitoring-Details: CLOSELOOP_NAME | Close loop name - * used in the CLDS application (prefix: ClosedLoop- + unique ClosedLoop - * ID) MODEL_NAME | Model Name in CLDS application SERVICE_TYPE_ID | - * TypeId returned from the DCAE application when the ClosedLoop is - * submitted (DCAEServiceTypeRequest generated in DCAE application). - * DEPLOYMENT_ID | Id generated when the ClosedLoop is deployed in DCAE. - * TEMPLATE_NAME | Template used to generate the ClosedLoop model. - * ACTION_CD | Current state of the ClosedLoop in CLDS application. - */ - public List getCldsMonitoringDetails() { - SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); - List cldsMonitoringDetailsList = new ArrayList<>(); - String modelsSql = "SELECT CONCAT(M.CONTROL_NAME_PREFIX, M.CONTROL_NAME_UUID) AS CLOSELOOP_NAME , " - + "M.MODEL_NAME, M.SERVICE_TYPE_ID, M.DEPLOYMENT_ID, T.TEMPLATE_NAME, E.ACTION_CD, E.USER_ID, E.TIMESTAMP " - + "FROM MODEL M, TEMPLATE T, EVENT E " + "WHERE M.TEMPLATE_ID = T.TEMPLATE_ID AND M.EVENT_ID = E.EVENT_ID " - + "ORDER BY ACTION_CD"; - List> rows = jdbcTemplateObject.queryForList(modelsSql); - CldsMonitoringDetails cldsMonitoringDetails = null; - for (Map row : rows) { - cldsMonitoringDetails = new CldsMonitoringDetails(); - cldsMonitoringDetails.setCloseloopName((String) row.get("CLOSELOOP_NAME")); - cldsMonitoringDetails.setModelName((String) row.get("MODEL_NAME")); - cldsMonitoringDetails.setServiceTypeId((String) row.get("SERVICE_TYPE_ID")); - cldsMonitoringDetails.setDeploymentId((String) row.get("DEPLOYMENT_ID")); - cldsMonitoringDetails.setTemplateName((String) row.get("TEMPLATE_NAME")); - cldsMonitoringDetails.setAction((String) row.get("ACTION_CD")); - cldsMonitoringDetails.setUserid((String) row.get("USER_ID")); - cldsMonitoringDetails.setTimestamp(sdf.format(row.get("TIMESTAMP"))); - cldsMonitoringDetailsList.add(cldsMonitoringDetails); - } - return cldsMonitoringDetailsList; - } - /** * Method to delete model from database. * - * @param modelName - * the model name + * @param modelName the model name */ public void deleteModel(String modelName) { SqlParameterSource in = new MapSqlParameterSource().addValue("v_model_name", modelName); @@ -476,10 +419,8 @@ public class CldsDao { /** * Helper method to setup the event prop to the CldsEvent class. * - * @param event - * the clds event - * @param prop - * collection with the configuration + * @param event the clds event + * @param prop collection with the configuration */ private void setEventProp(CldsEvent event, Map prop) { event.setId((String) prop.get("v_event_id")); @@ -501,8 +442,7 @@ public class CldsDao { /** * Method to retrieve a tosca models by Policy Type from database. * - * @param policyType - * the policy type + * @param policyType the policy type * @return List of CldsToscaModel */ public List getToscaModelByPolicyType(String policyType) { @@ -512,8 +452,7 @@ public class CldsDao { /** * Method to retrieve a tosca models by toscaModelName, version from database. * - * @param toscaModelName - * the tosca model name + * @param toscaModelName the tosca model name * @return List of CldsToscaModel */ public List getToscaModelByName(String toscaModelName) { @@ -528,13 +467,13 @@ public class CldsDao { String toscaModelSql = new StringBuilder("SELECT tm.tosca_model_name, tm.tosca_model_id, tm.policy_type, " + "tmr.tosca_model_revision_id, tmr.tosca_model_json, tmr.version, tmr.user_id, tmr.createdTimestamp," - + "tmr.lastUpdatedTimestamp").append(toscaModelName != null ? (", tmr.tosca_model_yaml") : "") - .append(" FROM tosca_model tm, tosca_model_revision tmr WHERE tm.tosca_model_id = tmr.tosca_model_id") - .append(toscaModelName != null ? (" AND tm.tosca_model_name = '" + toscaModelName + "'") : "") - .append(policyType != null ? (" AND tm.policy_type = '" + policyType + "'") : "") - .append(" AND tmr.version = (select max(version) from tosca_model_revision st where tmr.tosca_model_id" - + "=st.tosca_model_id)") - .toString(); + + "tmr.lastUpdatedTimestamp").append(toscaModelName != null ? (", tmr.tosca_model_yaml") : "").append( + " FROM tosca_model tm, tosca_model_revision tmr WHERE tm.tosca_model_id = tmr.tosca_model_id") + .append(toscaModelName != null ? (" AND tm.tosca_model_name = '" + toscaModelName + "'") : "") + .append(policyType != null ? (" AND tm.policy_type = '" + policyType + "'") : "") + .append(" AND tmr.version = (select max(version) from tosca_model_revision st where tmr.tosca_model_id" + + "=st.tosca_model_id)") + .toString(); List> rows = jdbcTemplateObject.queryForList(toscaModelSql); @@ -562,17 +501,15 @@ public class CldsDao { /** * Method to upload a new version of Tosca Model Yaml in Database. * - * @param cldsToscaModel - * the clds tosca model - * @param userId - * the user id + * @param cldsToscaModel the clds tosca model + * @param userId the user id * @return CldsToscaModel clds tosca model */ public CldsToscaModel updateToscaModelWithNewVersion(CldsToscaModel cldsToscaModel, String userId) { SqlParameterSource in = new MapSqlParameterSource().addValue("v_tosca_model_id", cldsToscaModel.getId()) - .addValue("v_version", cldsToscaModel.getVersion()) - .addValue("v_tosca_model_yaml", cldsToscaModel.getToscaModelYaml()) - .addValue("v_tosca_model_json", cldsToscaModel.getToscaModelJson()).addValue("v_user_id", userId); + .addValue("v_version", cldsToscaModel.getVersion()) + .addValue("v_tosca_model_yaml", cldsToscaModel.getToscaModelYaml()) + .addValue("v_tosca_model_json", cldsToscaModel.getToscaModelJson()).addValue("v_user_id", userId); Map out = logSqlExecution(procInsertNewToscaModelVersion, in); cldsToscaModel.setRevisionId((String) out.get("v_revision_id")); return cldsToscaModel; @@ -581,19 +518,17 @@ public class CldsDao { /** * Method to upload a new Tosca model Yaml in DB. Default version is 1.0 * - * @param cldsToscaModel - * the clds tosca model - * @param userId - * the user id + * @param cldsToscaModel the clds tosca model + * @param userId the user id * @return CldsToscaModel clds tosca model */ public CldsToscaModel insToscaModel(CldsToscaModel cldsToscaModel, String userId) { SqlParameterSource in = new MapSqlParameterSource() - .addValue("v_tosca_model_name", cldsToscaModel.getToscaModelName()) - .addValue("v_policy_type", cldsToscaModel.getPolicyType()) - .addValue("v_tosca_model_yaml", cldsToscaModel.getToscaModelYaml()) - .addValue("v_tosca_model_json", cldsToscaModel.getToscaModelJson()) - .addValue("v_version", cldsToscaModel.getVersion()).addValue("v_user_id", userId); + .addValue("v_tosca_model_name", cldsToscaModel.getToscaModelName()) + .addValue("v_policy_type", cldsToscaModel.getPolicyType()) + .addValue("v_tosca_model_yaml", cldsToscaModel.getToscaModelYaml()) + .addValue("v_tosca_model_json", cldsToscaModel.getToscaModelJson()) + .addValue("v_version", cldsToscaModel.getVersion()).addValue("v_user_id", userId); Map out = logSqlExecution(procInsertToscaModel, in); cldsToscaModel.setId((String) (out.get("v_tosca_model_id"))); cldsToscaModel.setRevisionId((String) (out.get("v_revision_id"))); @@ -604,13 +539,12 @@ public class CldsDao { /** * Method to insert a new Dictionary in Database. * - * @param cldsDictionary - * the clds dictionary + * @param cldsDictionary the clds dictionary */ public void insDictionary(CldsDictionary cldsDictionary) { SqlParameterSource in = new MapSqlParameterSource() - .addValue("v_dictionary_name", cldsDictionary.getDictionaryName()) - .addValue("v_user_id", cldsDictionary.getCreatedBy()); + .addValue("v_dictionary_name", cldsDictionary.getDictionaryName()) + .addValue("v_user_id", cldsDictionary.getCreatedBy()); Map out = logSqlExecution(procInsertDictionary, in); cldsDictionary.setDictionaryId((String) out.get("v_dictionary_id")); } @@ -618,20 +552,15 @@ public class CldsDao { /** * Method to update Dictionary with new info in Database. * - * @param dictionaryId - * the dictionary id - * @param cldsDictionary - * the clds dictionary - * @param userId - * the user id + * @param dictionaryId the dictionary id + * @param cldsDictionary the clds dictionary + * @param userId the user id */ public void updateDictionary(String dictionaryId, CldsDictionary cldsDictionary, String userId) { String dictionarySql = new StringBuilder("UPDATE dictionary SET dictionary_name = '") - .append(cldsDictionary.getDictionaryName()) - .append("', modified_by = '").append(userId) - .append("'WHERE dictionary_id = '").append(dictionaryId).append("'") - .toString(); + .append(cldsDictionary.getDictionaryName()).append("', modified_by = '").append(userId) + .append("'WHERE dictionary_id = '").append(dictionaryId).append("'").toString(); jdbcTemplateObject.update(dictionarySql); cldsDictionary.setUpdatedBy(userId); } @@ -639,10 +568,8 @@ public class CldsDao { /** * Method to get list of Dictionaries from the Database. * - * @param dictionaryId - * the dictionary id - * @param dictionaryName - * the dictionary name + * @param dictionaryId the dictionary id + * @param dictionaryName the dictionary name * @return dictionary */ public List getDictionary(String dictionaryId, String dictionaryName) { @@ -660,9 +587,9 @@ public class CldsDao { } else { whereFilter = ""; } - String dictionarySql = new StringBuilder("SELECT dictionary_id, dictionary_name, created_by, " - + "modified_by, timestamp FROM dictionary") - .append(whereFilter).toString(); + String dictionarySql = new StringBuilder( + "SELECT dictionary_id, dictionary_name, created_by, " + "modified_by, timestamp FROM dictionary") + .append(whereFilter).toString(); List> rows = jdbcTemplateObject.queryForList(dictionarySql); @@ -683,18 +610,16 @@ public class CldsDao { /** * Method to insert a new Dictionary Element for given dictionary in Database. * - * @param cldsDictionaryItem - * the clds dictionary item - * @param userId - * the user id + * @param cldsDictionaryItem the clds dictionary item + * @param userId the user id */ public void insDictionarElements(CldsDictionaryItem cldsDictionaryItem, String userId) { SqlParameterSource in = new MapSqlParameterSource() - .addValue("v_dictionary_id", cldsDictionaryItem.getDictionaryId()) - .addValue("v_dict_element_name", cldsDictionaryItem.getDictElementName()) - .addValue("v_dict_element_short_name", cldsDictionaryItem.getDictElementShortName()) - .addValue("v_dict_element_description", cldsDictionaryItem.getDictElementDesc()) - .addValue("v_dict_element_type", cldsDictionaryItem.getDictElementType()).addValue("v_user_id", userId); + .addValue("v_dictionary_id", cldsDictionaryItem.getDictionaryId()) + .addValue("v_dict_element_name", cldsDictionaryItem.getDictElementName()) + .addValue("v_dict_element_short_name", cldsDictionaryItem.getDictElementShortName()) + .addValue("v_dict_element_description", cldsDictionaryItem.getDictElementDesc()) + .addValue("v_dict_element_type", cldsDictionaryItem.getDictElementType()).addValue("v_user_id", userId); Map out = logSqlExecution(procInsertDictionaryElement, in); cldsDictionaryItem.setDictElementId((String) out.get("v_dict_element_id")); } @@ -703,25 +628,19 @@ public class CldsDao { * Method to update Dictionary Elements with new info for a given dictionary in * Database. * - * @param dictionaryElementId - * the dictionary element id - * @param cldsDictionaryItem - * the clds dictionary item - * @param userId - * the user id + * @param dictionaryElementId the dictionary element id + * @param cldsDictionaryItem the clds dictionary item + * @param userId the user id */ public void updateDictionaryElements(String dictionaryElementId, CldsDictionaryItem cldsDictionaryItem, - String userId) { + String userId) { String dictionarySql = new StringBuilder().append("UPDATE dictionary_elements SET dict_element_name = '") - .append(cldsDictionaryItem.getDictElementName()) - .append("', dict_element_short_name = '").append(cldsDictionaryItem.getDictElementShortName()) - .append("', dict_element_description= '").append(cldsDictionaryItem.getDictElementDesc()) - .append("', dict_element_type = '").append(cldsDictionaryItem.getDictElementType()) - .append("', modified_by = '").append(userId).append("'") - .append(" WHERE dict_element_id = '") - .append(dictionaryElementId).append("'") - .toString(); + .append(cldsDictionaryItem.getDictElementName()).append("', dict_element_short_name = '") + .append(cldsDictionaryItem.getDictElementShortName()).append("', dict_element_description= '") + .append(cldsDictionaryItem.getDictElementDesc()).append("', dict_element_type = '") + .append(cldsDictionaryItem.getDictElementType()).append("', modified_by = '").append(userId).append("'") + .append(" WHERE dict_element_id = '").append(dictionaryElementId).append("'").toString(); jdbcTemplateObject.update(dictionarySql); cldsDictionaryItem.setUpdatedBy(userId); } @@ -730,26 +649,25 @@ public class CldsDao { * Method to get list of all dictionary elements for a given dictionary in the * Database. * - * @param dictionaryName - * the dictionary name - * @param dictionaryId - * the dictionary id - * @param dictElementShortName - * the dict element short name + * @param dictionaryName the dictionary name + * @param dictionaryId the dictionary id + * @param dictElementShortName the dict element short name * @return dictionary elements */ public List getDictionaryElements(String dictionaryName, String dictionaryId, - String dictElementShortName) { + String dictElementShortName) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); List dictionaryItems = new ArrayList<>(); String dictionarySql = new StringBuilder("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") - .append((dictionaryId != null) ? (" AND d.dictionary_id = '" + dictionaryId + "'") : "") - .append((dictElementShortName != null) ? (" AND de.dict_element_short_name = '" + dictElementShortName - + "'") : "") - .append((dictionaryName != null) ? (" AND dictionary_name = '" + dictionaryName + "'") : "").toString(); + .append((dictionaryId != null) ? (" AND d.dictionary_id = '" + dictionaryId + "'") : "") + .append((dictElementShortName != null) + ? (" AND de.dict_element_short_name = '" + dictElementShortName + "'") + : "") + .append((dictionaryName != null) ? (" AND dictionary_name = '" + dictionaryName + "'") : "") + .toString(); List> rows = jdbcTemplateObject.queryForList(dictionarySql); @@ -775,22 +693,21 @@ public class CldsDao { * Method to get Map of all dictionary elements with key as dictionary short * name and value as the full name. * - * @param dictionaryElementType - * the dictionary element type + * @param dictionaryElementType the dictionary element type * @return Map of dictionary elements as key value pair */ public Map getDictionaryElementsByType(String dictionaryElementType) { Map dictionaryItems = new HashMap<>(); String dictionarySql = new StringBuilder("SELECT dict_element_name, dict_element_short_name " - + "FROM dictionary_elements WHERE dict_element_type = '") - .append(dictionaryElementType).append("'").toString(); + + "FROM dictionary_elements WHERE dict_element_type = '").append(dictionaryElementType).append("'") + .toString(); List> rows = jdbcTemplateObject.queryForList(dictionarySql); if (rows != null) { rows.forEach(row -> { dictionaryItems.put(((String) row.get("dict_element_short_name")), - ((String) row.get("dict_element_name"))); + ((String) row.get("dict_element_name"))); }); } return dictionaryItems; diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java b/src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java deleted file mode 100644 index 2fc047813..000000000 --- a/src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.dao; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.io.IOException; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; - -import org.apache.commons.io.serialization.ValidatingObjectInputStream; -import org.onap.clamp.clds.model.CldsServiceData; -import org.onap.clamp.clds.model.CldsVfData; -import org.onap.clamp.clds.model.CldsVfKPIData; -import org.onap.clamp.clds.model.CldsVfcData; -import org.springframework.jdbc.core.RowMapper; - -/** - * Generic mapper for CldsDBServiceCache. - */ -public final class CldsServiceDataMapper implements RowMapper { - - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDao.class); - - @Override - public CldsServiceData mapRow(ResultSet rs, int rowNum) throws SQLException { - CldsServiceData cldsServiceData = new CldsServiceData(); - try (ValidatingObjectInputStream oip = new ValidatingObjectInputStream(rs.getBlob(4).getBinaryStream())) { - oip.accept(CldsServiceData.class, ArrayList.class, CldsVfData.class, CldsVfcData.class, - CldsVfKPIData.class); - cldsServiceData = (CldsServiceData) oip.readObject(); - cldsServiceData.setAgeOfRecord(rs.getLong(5)); - } catch (IOException | ClassNotFoundException e) { - logger.error("Error caught while deserializing cldsServiceData from database", e); - return null; - } - return cldsServiceData; - } -} diff --git a/src/main/java/org/onap/clamp/clds/model/CldsMonitoringDetails.java b/src/main/java/org/onap/clamp/clds/model/CldsMonitoringDetails.java deleted file mode 100644 index eb05fe406..000000000 --- a/src/main/java/org/onap/clamp/clds/model/CldsMonitoringDetails.java +++ /dev/null @@ -1,113 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.model; - -/** - * Maintains model and template details. - */ -public class CldsMonitoringDetails { - - private String closeloopName; - private String modelId; - private String modelName; - private String serviceTypeId; - private String deploymentId; - private String templateName; - private String action; - private String userid; - private String timestamp; - - public String getCloseloopName() { - return closeloopName; - } - - public void setCloseloopName(String closeloopName) { - this.closeloopName = closeloopName; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getServiceTypeId() { - return serviceTypeId; - } - - public void setServiceTypeId(String serviceTypeId) { - this.serviceTypeId = serviceTypeId; - } - - public String getDeploymentId() { - return deploymentId; - } - - public void setDeploymentId(String deploymentId) { - this.deploymentId = deploymentId; - } - - public String getTemplateName() { - return templateName; - } - - public void setTemplateName(String templateName) { - this.templateName = templateName; - } - - public String getAction() { - return action; - } - - public void setAction(String action) { - this.action = action; - } - - public String getUserid() { - return userid; - } - - public void setUserid(String userid) { - this.userid = userid; - } - - public String getTimestamp() { - return timestamp; - } - - public void setTimestamp(String time) { - this.timestamp = time; - } - -} 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 deleted file mode 100644 index 441a7ac11..000000000 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java +++ /dev/null @@ -1,350 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * Modifications copyright (c) 2019 Nokia - * =================================================================== - * - */ - -package org.onap.clamp.clds.sdc.controller.installer; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.gson.JsonObject; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import javax.annotation.PostConstruct; -import javax.xml.transform.TransformerException; -import org.apache.commons.io.IOUtils; -import org.json.simple.parser.ParseException; -import org.onap.clamp.clds.client.DcaeInventoryServices; -import org.onap.clamp.clds.config.sdc.BlueprintParserFilesConfiguration; -import org.onap.clamp.clds.config.sdc.BlueprintParserMappingConfiguration; -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.exception.policy.PolicyModelException; -import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; -import org.onap.clamp.clds.model.CldsModel; -import org.onap.clamp.clds.model.CldsTemplate; -import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse; -import org.onap.clamp.clds.model.properties.ModelProperties; -import org.onap.clamp.clds.service.CldsService; -import org.onap.clamp.clds.service.CldsTemplateService; -import org.onap.clamp.clds.transform.XslTransformer; -import org.onap.clamp.clds.util.JsonUtils; -import org.onap.clamp.clds.util.drawing.SvgFacade; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; -import org.yaml.snakeyaml.Yaml; - -/** - * This class will be instantiated by spring config, and used by Sdc Controller. - * There is no state kept by the bean. It's used to deploy the csar/notification - * received from SDC in DB. - */ -@Component -@Qualifier("oldModelInstaller") -public class CsarInstallerImpl implements CsarInstaller { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstallerImpl.class); - private Map bpmnMapping = new HashMap<>(); - public static final String TEMPLATE_NAME_PREFIX = "DCAE-Designer-Template-"; - public static final String CONTROL_NAME_PREFIX = "ClosedLoop-"; - public static final String GET_INPUT_BLUEPRINT_PARAM = "get_input"; - // This will be used later as the policy scope - public static final String MODEL_NAME_PREFIX = "CLAMP"; - /** - * The file name that will be loaded by Spring. - */ - @Value("${clamp.config.sdc.blueprint.parser.mapping:'classpath:/clds/blueprint-parser-mapping.json'}") - protected String blueprintMappingFile; - protected ApplicationContext appContext; - private CldsDao cldsDao; - CldsTemplateService cldsTemplateService; - CldsService cldsService; - DcaeInventoryServices dcaeInventoryService; - private XslTransformer cldsBpmnTransformer; - - @Autowired - public CsarInstallerImpl(ApplicationContext appContext, - CldsDao cldsDao, CldsTemplateService cldsTemplateService, CldsService cldsService, - DcaeInventoryServices dcaeInventoryService, XslTransformer cldsBpmnTransformer) { - this.appContext = appContext; - this.cldsDao = cldsDao; - this.cldsTemplateService = cldsTemplateService; - this.cldsService = cldsService; - this.dcaeInventoryService = dcaeInventoryService; - this.cldsBpmnTransformer = cldsBpmnTransformer; - } - - @Autowired - private BlueprintParser blueprintParser; - - @Autowired - private ChainGenerator chainGenerator; - - @Autowired - private SvgFacade svgFacade; - - @PostConstruct - public void loadConfiguration() throws IOException { - BlueprintParserMappingConfiguration - .createFromJson(appContext.getResource(blueprintMappingFile).getInputStream()).stream() - .forEach(e -> bpmnMapping.put(e.getBlueprintKey(), e.getFiles())); - } - - @Override - public boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException { - boolean alreadyInstalled = true; - for (Entry blueprint : csar.getMapOfBlueprints().entrySet()) { - alreadyInstalled = alreadyInstalled - && CldsModel.retrieve(cldsDao, buildModelName(csar, blueprint.getValue()), true).getId() != null; - } - return alreadyInstalled; - } - - public static String buildModelName(CsarHandler csar, BlueprintArtifact artifact) - throws SdcArtifactInstallerException { - String policyScopePrefix = searchForPolicyScopePrefix(artifact); - if (policyScopePrefix.contains("*")) { - // This is policy_filter type - policyScopePrefix = policyScopePrefix.replaceAll("\\*", ""); - } else { - // This is normally the get_input case - policyScopePrefix = MODEL_NAME_PREFIX; - } - return (policyScopePrefix + "_" + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v" - + csar.getSdcNotification().getServiceVersion() + "_" - + artifact.getResourceAttached().getResourceInstanceName().replaceAll(" ", "") + "_" - + artifact.getBlueprintArtifactName().replace(".yaml", "")).replace('.', '_'); - } - - @Override - @Transactional - public void installTheCsar(CsarHandler csar) - throws SdcArtifactInstallerException, InterruptedException, PolicyModelException { - try { - logger.info("Installing the CSAR " + csar.getFilePath()); - for (Entry blueprint : csar.getMapOfBlueprints().entrySet()) { - logger.info("Processing blueprint " + blueprint.getValue().getBlueprintArtifactName()); - createFakeCldsModel(csar, blueprint.getValue(), - createFakeCldsTemplate(csar, blueprint.getValue(), - this.searchForRightMapping(blueprint.getValue())), - queryDcaeToGetServiceTypeId(blueprint.getValue())); - } - createPolicyModel(csar); - logger.info("Successfully installed the CSAR " + csar.getFilePath()); - } catch (IOException e) { - throw new SdcArtifactInstallerException("Exception caught during the Csar installation in database", e); - } catch (ParseException e) { - throw new SdcArtifactInstallerException("Exception caught during the Dcae query to get ServiceTypeId", e); - } - } - - BlueprintParserFilesConfiguration searchForRightMapping(BlueprintArtifact blueprintArtifact) - throws SdcArtifactInstallerException { - List listConfig = new ArrayList<>(); - Yaml yaml = new Yaml(); - Map templateNodes = ((Map) ((Map) yaml - .load(blueprintArtifact.getDcaeBlueprint())).get("node_templates")); - bpmnMapping.entrySet().forEach(e -> { - if (templateNodes.keySet().stream().anyMatch(t -> t.contains(e.getKey()))) { - listConfig.add(e.getValue()); - } - }); - if (listConfig.size() > 1) { - throw new SdcArtifactInstallerException( - "The code does not currently support multiple MicroServices in the blueprint"); - } else if (listConfig.isEmpty()) { - throw new SdcArtifactInstallerException("There is no recognized MicroService found in the blueprint"); - } - logger.info("Mapping found for blueprint " + blueprintArtifact.getBlueprintArtifactName() + " is " - + listConfig.get(0).getBpmnXmlFilePath()); - return listConfig.get(0); - } - - String getAllBlueprintParametersInJson(BlueprintArtifact blueprintArtifact) { - JsonObject node = new JsonObject(); - Yaml yaml = new Yaml(); - Map inputsNodes = ((Map) ((Map) yaml - .load(blueprintArtifact.getDcaeBlueprint())).get("inputs")); - inputsNodes.entrySet().stream().filter(e -> !e.getKey().contains("policy_id")).forEach(elem -> { - Object defaultValue = ((Map) elem.getValue()).get("default"); - if (defaultValue != null) { - addPropertyToNode(node, elem.getKey(), defaultValue); - } else { - node.addProperty(elem.getKey(), ""); - } - }); - node.addProperty("policy_id", "AUTO_GENERATED_POLICY_ID_AT_SUBMIT"); - return node.toString(); - } - - private void createPolicyModel(CsarHandler csar) throws PolicyModelException { - try { - Optional policyModelYaml = csar.getPolicyModelYaml(); - // save policy model into the database - } catch (IOException e) { - throw new PolicyModelException("TransformerException when decoding the YamlText", e); - } - } - - private static String searchForPolicyScopePrefix(BlueprintArtifact blueprintArtifact) - throws SdcArtifactInstallerException { - String policyName = null; - Yaml yaml = new Yaml(); - List policyNameList = new ArrayList<>(); - Map templateNodes = ((Map) ((Map) yaml - .load(blueprintArtifact.getDcaeBlueprint())).get("node_templates")); - templateNodes.entrySet().stream().filter(e -> e.getKey().contains("policy")).forEach(ef -> { - String filteredPolicyName = (String) ((Map) ((Map) ef.getValue()) - .get("properties")).get("policy_filter"); - if (policyName != null) { - policyNameList.add(filteredPolicyName); - } else { - String inputPolicyName = (String) ((Map) ((Map) ((Map) - ef.getValue()).get("properties")).get("policy_id")).get(GET_INPUT_BLUEPRINT_PARAM); - if (inputPolicyName != null) { - policyNameList.add(GET_INPUT_BLUEPRINT_PARAM); - } - } - }); - if (policyNameList.size() > 1) { - throw new SdcArtifactInstallerException( - "The code does not currently support multiple Policy MicroServices in the blueprint"); - } else if (policyNameList.isEmpty()) { - throw new SdcArtifactInstallerException( - "There is no recognized Policy MicroService found in the blueprint"); - } - logger.info("policyName found in blueprint " + blueprintArtifact.getBlueprintArtifactName() + " is " - + policyNameList.get(0)); - return policyNameList.get(0); - } - - /** - * 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). - * - * @return The DcaeInventoryResponse object containing the dcae values - */ - private DcaeInventoryResponse queryDcaeToGetServiceTypeId(BlueprintArtifact blueprintArtifact) - throws IOException, ParseException, InterruptedException { - return dcaeInventoryService.getDcaeInformation(blueprintArtifact.getBlueprintArtifactName(), - blueprintArtifact.getBlueprintInvariantServiceUuid(), - blueprintArtifact.getResourceAttached().getResourceInvariantUUID()); - } - - private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintArtifact blueprintArtifact, - BlueprintParserFilesConfiguration configFiles) throws IOException, SdcArtifactInstallerException { - - Set microServicesFromBlueprint = blueprintParser.getMicroServices( - blueprintArtifact.getDcaeBlueprint()) ; - List microServicesChain = chainGenerator.getChainOfMicroServices(microServicesFromBlueprint); - if (microServicesChain.isEmpty()) { - microServicesChain = blueprintParser.fallbackToOneMicroService(blueprintArtifact.getDcaeBlueprint()); - } - String imageText = svgFacade.getSvgImage(microServicesChain); - - CldsTemplate template = new CldsTemplate(); - template.setBpmnId("Sdc-Generated"); - template.setBpmnText(IOUtils.toString(appContext.getResource(configFiles.getBpmnXmlFilePath()).getInputStream(), - StandardCharsets.UTF_8)); - template.setPropText( - "{\"global\":[{\"name\":\"service\",\"value\":[\"" + blueprintArtifact.getDcaeBlueprint() + "\"]}]}"); - template - .setImageText(imageText); - template.setName(TEMPLATE_NAME_PREFIX + buildModelName(csar, blueprintArtifact)); - template.save(cldsDao, null); - logger.info("Fake Clds Template created for blueprint " + blueprintArtifact.getBlueprintArtifactName() - + " with name " + template.getName()); - return template; - } - - private CldsModel createFakeCldsModel(CsarHandler csar, BlueprintArtifact blueprintArtifact, - CldsTemplate cldsTemplate, DcaeInventoryResponse dcaeInventoryResponse) throws SdcArtifactInstallerException { - - if (dcaeInventoryResponse == null) { - throw new SdcArtifactInstallerException( - "DCAE inventory response is NULL, query to DCAE fail to be answered properly, " - + "this is required to deploy CSAR properly !!!"); - } - try { - CldsModel cldsModel = new CldsModel(); - cldsModel.setName(buildModelName(csar, blueprintArtifact)); - cldsModel.setBlueprintText(blueprintArtifact.getDcaeBlueprint()); - cldsModel.setTemplateName(cldsTemplate.getName()); - cldsModel.setTemplateId(cldsTemplate.getId()); - cldsModel.setBpmnText(cldsTemplate.getBpmnText()); - cldsModel.setTypeId(dcaeInventoryResponse.getTypeId()); - cldsModel.setTypeName(dcaeInventoryResponse.getTypeName()); - cldsModel.setControlNamePrefix(CONTROL_NAME_PREFIX); - // We must save it otherwise object won't be created in db - // and proptext will always be null - cldsModel.setPropText("{\"global\":[]}"); - // Must save first to have the generated id available to generate - // the policyId - cldsModel = cldsModel.save(cldsDao, null); - cldsModel = setModelPropText(cldsModel, blueprintArtifact, cldsTemplate); - logger.info("Fake Clds Model created for blueprint " + blueprintArtifact.getBlueprintArtifactName() - + " with name " + cldsModel.getName()); - return cldsModel; - } catch (TransformerException e) { - throw new SdcArtifactInstallerException("TransformerException when decoding the BpmnText", e); - } - } - - private CldsModel setModelPropText(CldsModel cldsModel, BlueprintArtifact blueprintArtifact, - CldsTemplate cldsTemplate) throws TransformerException { - // Do a test to validate the BPMN - new ModelProperties(cldsModel.getName(), cldsModel.getControlName(), "PUT", false, - cldsBpmnTransformer.doXslTransformToString(cldsTemplate.getBpmnText()), "{}"); - String inputParams = "{\"name\":\"deployParameters\",\"value\":" - + getAllBlueprintParametersInJson(blueprintArtifact) + "}"; - cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" - + blueprintArtifact.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\"" - + blueprintArtifact.getResourceAttached().getResourceInvariantUUID() - + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]}," - + inputParams + "]}"); - return cldsModel.save(cldsDao, null); - } - - private void addPropertyToNode(JsonObject node, String key, Object value) { - if (value instanceof String) { - node.addProperty(key, (String) value); - } else if (value instanceof Number) { - node.addProperty(key, (Number) value); - } else if (value instanceof Boolean) { - node.addProperty(key, (Boolean) value); - } else if (value instanceof Character) { - node.addProperty(key, (Character) value); - } else { - node.addProperty(key, JsonUtils.GSON.toJson(value)); - } - } -} diff --git a/src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java b/src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java deleted file mode 100644 index 454056cd3..000000000 --- a/src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java +++ /dev/null @@ -1,179 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.service; - -import java.util.Date; -import java.util.List; - -import javax.annotation.PostConstruct; - -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsDictionary; -import org.onap.clamp.clds.model.CldsDictionaryItem; -import org.onap.clamp.clds.util.LoggingUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Component; - -/** - * REST services to manage dictionary and dictionary items for Tosca Model. - */ -@Component -public class CldsDictionaryService extends SecureServiceBase { - - @Value("${clamp.config.security.permission.type.tosca:permission-type-tosca}") - private String cldsPermissionTypeTosca; - @Value("${clamp.config.security.permission.instance:dev}") - private String cldsPermissionInstance; - private SecureServicePermission permissionReadTosca; - private SecureServicePermission permissionUpdateTosca; - - @Autowired - private CldsDao cldsDao; - - private LoggingUtils util = new LoggingUtils(logger); - - - @PostConstruct - private void initConstruct() { - permissionReadTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance, "read"); - permissionUpdateTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance, - "update"); - } - - /** - * REST Service that creates a Dictionary. - * - * @param dictionaryName dictionary name - * @return CldsDictionary that was created in DB. - */ - public CldsDictionary createDictionary(String dictionaryName) { - CldsDictionary cldsDictionary = new CldsDictionary(); - cldsDictionary.setDictionaryName(dictionaryName); - cldsDictionary.save(cldsDictionary.getDictionaryName(), cldsDao, getUserId()); - return cldsDictionary; - } - - /** - * REST Service that creates or Updates a Dictionary. - * Used in clds-services.xml - * - * @param cldsDictionary clds dictionary - * @return ResponseEntity with CldsDictionary that was created in DB. - */ - public ResponseEntity createOrUpdateDictionary(String dictionaryName, - CldsDictionary cldsDictionary) { - - Date startTime = new Date(); - LoggingUtils.setRequestContext("CldsDictionaryService: createOrUpdateDictionary", getPrincipalName()); - // TODO revisit based on new permissions - isAuthorized(permissionUpdateTosca); - - if (cldsDictionary == null) { - - cldsDictionary = createDictionary(dictionaryName); - } else { - - if (cldsDictionary.getDictionaryName() == null) { - cldsDictionary.setDictionaryName(dictionaryName); - } - - cldsDictionary.save(cldsDictionary.getDictionaryName(), cldsDao, getUserId()); - } - - LoggingUtils.setTimeContext(startTime, new Date()); - LoggingUtils.setResponseContext("0", "createOrUpdateDictionary success", this.getClass().getName()); - auditLogger.info("createOrUpdateDictionary completed"); - - return new ResponseEntity<>(cldsDictionary, HttpStatus.OK); - } - - /** - * REST Service that creates or Updates a Dictionary Elements for dictionary - * in DB. - * - * @param dictionaryName dictionary name - * @param dictionaryItem dictionary item - * @return CldsDictionaryItem A dictionary items that was created or updated - * in DB - */ - public ResponseEntity createOrUpdateDictionaryElements(String dictionaryName, - CldsDictionaryItem dictionaryItem) { - final Date startTime = new Date(); - LoggingUtils.setRequestContext("CldsDictionaryService: createOrUpdateDictionaryElements", - getPrincipalName()); - // TODO revisit based on new permissions - isAuthorized(permissionUpdateTosca); - dictionaryItem.save(dictionaryName, cldsDao, getUserId()); - auditLogInfo("createOrUpdateDictionaryElements", startTime); - return new ResponseEntity<>(dictionaryItem, HttpStatus.OK); - } - - /** - * Rest Service that retrieves all CLDS dictionary in DB. - * - * @return CldsDictionary List List of CldsDictionary available in DB - */ - public ResponseEntity> getAllDictionaryNames() { - final Date startTime = new Date(); - LoggingUtils.setRequestContext("CldsDictionaryService: getAllDictionaryNames", getPrincipalName()); - // TODO revisit based on new permissions - isAuthorized(permissionReadTosca); - List dictionaries = cldsDao.getDictionary(null, null); - auditLogInfo("getAllDictionaryNames", startTime); - return new ResponseEntity<>(dictionaries, HttpStatus.OK); - } - - /** - * Rest Service that retrieves all CLDS dictionary items in DB for a give - * dictionary name. - * - * @param dictionaryName dictionary name - * @return CldsDictionaryItem list List of CLDS Dictionary items for a given - * dictionary name - */ - public ResponseEntity> getDictionaryElementsByName(String dictionaryName) { - final Date startTime = new Date(); - LoggingUtils.setRequestContext("CldsDictionaryService: getDictionaryElementsByName", getPrincipalName()); - // TODO revisit based on new permissions - isAuthorized(permissionReadTosca); - List dictionaryItems = cldsDao.getDictionaryElements(dictionaryName, null, null); - auditLogInfo("getDictionaryElementsByName", startTime); - return new ResponseEntity<>(dictionaryItems, HttpStatus.OK); - } - - public ResponseEntity deleteDictionary() { - return null; - } - - // Created for the integration test - public void setLoggingUtil(LoggingUtils utilP) { - util = utilP; - } - -} \ No newline at end of file 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 d9956e3ad..3a2cb0926 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -28,48 +28,24 @@ package org.onap.clamp.clds.service; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; -import java.io.IOException; + import java.lang.reflect.Type; import java.util.Date; import java.util.List; -import java.util.UUID; + import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.BadRequestException; -import javax.xml.transform.TransformerException; + import org.apache.camel.Produce; -import org.json.simple.parser.ParseException; import org.onap.clamp.clds.camel.CamelProxy; -import org.onap.clamp.clds.client.DcaeDispatcherServices; -import org.onap.clamp.clds.client.DcaeInventoryServices; -import org.onap.clamp.clds.config.ClampProperties; -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.exception.policy.PolicyClientException; -import org.onap.clamp.clds.exception.sdc.SdcCommunicationException; -import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsInfo; -import org.onap.clamp.clds.model.CldsModel; -import org.onap.clamp.clds.model.CldsModelProp; -import org.onap.clamp.clds.model.CldsMonitoringDetails; -import org.onap.clamp.clds.model.CldsTemplate; -import org.onap.clamp.clds.model.DcaeEvent; -import org.onap.clamp.clds.model.ValueItem; -import org.onap.clamp.clds.model.properties.ModelProperties; import org.onap.clamp.clds.model.sdc.SdcServiceInfo; -import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller; -import org.onap.clamp.clds.transform.XslTransformer; -import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.clds.util.LoggingUtils; import org.onap.clamp.clds.util.ONAPLogConstants; import org.slf4j.event.Level; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; -import org.springframework.web.client.HttpClientErrorException; /** * Service to save and retrieve the CLDS model attributes. @@ -81,7 +57,7 @@ public class CldsService extends SecureServiceBase { * The constant LIST_OF_SDC_SERVICE_INFO_TYPE. */ public static final Type LIST_OF_SDC_SERVICE_INFO_TYPE = new TypeToken>() { - }.getType(); + }.getType(); @Produce(uri = "direct:processSubmit") private CamelProxy camelProxy; /** @@ -93,12 +69,6 @@ public class CldsService extends SecureServiceBase { */ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsService.class); - /** - * The constant GLOBAL_PROPERTIES_KEY. - */ - public static final String GLOBAL_PROPERTIES_KEY = "files.globalProperties"; - private final String cldsPermissionTypeClManage; - private final String cldsPermissionTypeClEvent; private final String cldsPermissionTypeFilterVf; private final String cldsPermissionInstance; /** @@ -126,11 +96,6 @@ public class CldsService extends SecureServiceBase { */ final SecureServicePermission permissionUpdateTosca; - private final CldsDao cldsDao; - private final XslTransformer cldsBpmnTransformer; - private final ClampProperties refProp; - private final DcaeDispatcherServices dcaeDispatcherServices; - private final DcaeInventoryServices dcaeInventoryServices; private LoggingUtils util = new LoggingUtils(logger); @Autowired @@ -139,11 +104,6 @@ public class CldsService extends SecureServiceBase { /** * Instantiates a new Clds service. * - * @param cldsDao the clds dao - * @param cldsBpmnTransformer the clds bpmn transformer - * @param refProp the ref prop - * @param dcaeDispatcherServices the dcae dispatcher services - * @param dcaeInventoryServices the dcae inventory services * @param cldsPersmissionTypeCl the clds persmission type cl * @param cldsPermissionTypeClManage the clds permission type cl manage * @param cldsPermissionTypeClEvent the clds permission type cl event @@ -153,72 +113,32 @@ public class CldsService extends SecureServiceBase { * @param cldsPermissionInstance the clds permission instance */ @Autowired - public CldsService(CldsDao cldsDao, XslTransformer cldsBpmnTransformer, ClampProperties refProp, - DcaeDispatcherServices dcaeDispatcherServices, - DcaeInventoryServices dcaeInventoryServices, - @Value("${clamp.config.security.permission.type.cl:permission-type-cl}") - String cldsPersmissionTypeCl, - @Value("${clamp.config.security.permission.type.cl.manage:permission-type-cl-manage}") - String cldsPermissionTypeClManage, - @Value("${clamp.config.security.permission.type.cl.event:permission-type-cl-event}") - String cldsPermissionTypeClEvent, - @Value("${clamp.config.security.permission.type.filter.vf:permission-type-filter-vf}") - String cldsPermissionTypeFilterVf, - @Value("${clamp.config.security.permission.type.template:permission-type-template}") - String cldsPermissionTypeTemplate, - @Value("${clamp.config.security.permission.type.tosca:permission-type-tosca}") - String cldsPermissionTypeTosca, - @Value("${clamp.config.security.permission.instance:dev}") - String cldsPermissionInstance) { - this.cldsDao = cldsDao; - this.cldsBpmnTransformer = cldsBpmnTransformer; - this.refProp = refProp; - this.dcaeDispatcherServices = dcaeDispatcherServices; - this.dcaeInventoryServices = dcaeInventoryServices; - this.cldsPermissionTypeClManage = cldsPermissionTypeClManage; - this.cldsPermissionTypeClEvent = cldsPermissionTypeClEvent; + public CldsService( + @Value("${clamp.config.security.permission.type.cl:permission-type-cl}") String cldsPersmissionTypeCl, + @Value("${clamp.config.security.permission.type.cl.manage:permission-type-cl-manage}") String cldsPermissionTypeClManage, + @Value("${clamp.config.security.permission.type.cl.event:permission-type-cl-event}") String cldsPermissionTypeClEvent, + @Value("${clamp.config.security.permission.type.filter.vf:permission-type-filter-vf}") String cldsPermissionTypeFilterVf, + @Value("${clamp.config.security.permission.type.template:permission-type-template}") String cldsPermissionTypeTemplate, + @Value("${clamp.config.security.permission.type.tosca:permission-type-tosca}") String cldsPermissionTypeTosca, + @Value("${clamp.config.security.permission.instance:dev}") String cldsPermissionInstance) { this.cldsPermissionTypeFilterVf = cldsPermissionTypeFilterVf; this.cldsPermissionInstance = cldsPermissionInstance; permissionReadCl = SecureServicePermission.create(cldsPersmissionTypeCl, cldsPermissionInstance, "read"); permissionUpdateCl = SecureServicePermission.create(cldsPersmissionTypeCl, cldsPermissionInstance, "update"); permissionReadTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance, - "read"); + "read"); permissionUpdateTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance, - "update"); + "update"); permissionReadTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance, "read"); permissionUpdateTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance, - "update"); - } - - /** - * Gets clds details. - * list of CLDS-Monitoring-Details: CLOSELOOP_NAME | Close loop name - * used in the CLDS application (prefix: ClosedLoop- + unique ClosedLoop ID) - * MODEL_NAME | Model Name in CLDS application SERVICE_TYPE_ID | TypeId returned - * from the DCAE application when the ClosedLoop is submitted - * (DCAEServiceTypeRequest generated in DCAE application). DEPLOYMENT_ID | Id - * generated when the ClosedLoop is deployed in DCAE. TEMPLATE_NAME | Template - * used to generate the ClosedLoop model. ACTION_CD | Current state of the - * ClosedLoop in CLDS application. - * @return the clds details - */ - public List getCldsDetails() { - util.entering(request, "CldsService: GET model details"); - - final Date startTime = new Date(); - List cldsMonitoringDetailsList = cldsDao.getCldsMonitoringDetails(); - - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("GET cldsDetails completed"); - util.exiting("200", "Get cldsDetails success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return cldsMonitoringDetailsList; + "update"); } /** - * Gets clds info. - * CLDS IFO service will return 3 things 1. User Name 2. CLDS code version that - * is currently installed from pom.xml file 3. User permissions + * Gets clds info. CLDS IFO service will return 3 things 1. User Name 2. CLDS + * code version that is currently installed from pom.xml file 3. User + * permissions + * * @return the clds info */ public CldsInfo getCldsInfo() { @@ -236,294 +156,6 @@ public class CldsService extends SecureServiceBase { return cldsInfo; } - /** - * REST service that retrieves BPMN for a CLDS model name from the database. - * This is subset of the json getModel. This is only expected to be used for - * testing purposes, not by the UI. - * - * @param modelName the model name - * @return bpmn xml text - content of bpmn given name - */ - public String getBpmnXml(String modelName) { - util.entering(request, "CldsService: GET model bpmn"); - final Date startTime = new Date(); - isAuthorized(permissionReadCl); - logger.info("GET bpmnText for modelName={}", modelName); - final CldsModel model = CldsModel.retrieve(cldsDao, modelName, false); - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("GET model bpmn completed"); - util.exiting("200", "Get model bpmn success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return model.getBpmnText(); - } - - /** - * REST service that retrieves image for a CLDS model name from the database. - * This is subset of the json getModel. This is only expected to be used for - * testing purposes, not by the UI. - * - * @param modelName the model name - * @return image xml text - content of image given name - */ - public String getImageXml(String modelName) { - util.entering(request, "CldsService: GET model image"); - final Date startTime = new Date(); - isAuthorized(permissionReadCl); - logger.info("GET imageText for modelName={}", modelName); - final CldsModel model = CldsModel.retrieve(cldsDao, modelName, false); - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("GET model image completed"); - util.exiting("200", "Get model image success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return model.getImageText(); - } - - /** - * REST service that retrieves a CLDS model by name from the database. - * - * @param modelName the model name - * @return clds model - clds model for the given model name - */ - public CldsModel getModel(String modelName) { - util.entering(request, "CldsService: GET model"); - final Date startTime = new Date(); - isAuthorized(permissionReadCl); - 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 - try { - // Method to call dcae inventory and invoke insert event method - if (cldsModel.canDcaeInventoryCall() - && !cldsModel.getTemplateName().startsWith(CsarInstaller.TEMPLATE_NAME_PREFIX)) { - dcaeInventoryServices.setEventInventory(cldsModel, getUserId()); - } - // 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 the model object in any cases for new event - cldsModel = CldsModel.retrieve(cldsDao, cldsModel.getName(), 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()); - auditLogger.info("GET model completed"); - util.exiting("200", "Get model success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return cldsModel; - } - - /** - * REST service that saves a CLDS model by name in the database. - * - * @param modelName the model name - * @param cldsModel the clds model - * @return the clds model - */ - public CldsModel putModel(String modelName, CldsModel cldsModel) { - util.entering(request, "CldsService: PUT model"); - final Date startTime = new Date(); - isAuthorized(permissionUpdateCl); - isAuthorizedForVf(cldsModel); - logger.info("PUT model for modelName={}", modelName); - logger.info("PUT bpmnText={}", cldsModel.getBpmnText()); - logger.info("PUT propText={}", cldsModel.getPropText()); - logger.info("PUT imageText={}", cldsModel.getImageText()); - fillInCldsModel(cldsModel); - cldsModel.save(cldsDao, getUserId()); - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("PUT model completed"); - util.exiting("200", "Put model success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return cldsModel; - } - - /** - * REST service that retrieves a list of CLDS model names. - * - * @return model names in JSON - */ - public List getModelNames() { - util.entering(request, "CldsService: GET model names"); - final Date startTime = new Date(); - isAuthorized(permissionReadCl); - logger.info("GET list of model names"); - final List names = cldsDao.getModelNames(); - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("GET model names completed"); - util.exiting("200", "Get model names success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return names; - } - - private void fillInCldsModel(CldsModel model) { - if (model.getTemplateName() != null) { - CldsTemplate template = cldsDao.getTemplate(model.getTemplateName()); - if (template != null) { - model.setTemplateId(template.getId()); - model.setDocText(template.getPropText()); - // This is to provide the Bpmn XML when Template part in UI - // is - // disabled - model.setBpmnText(template.getBpmnText()); - } - } - } - - /** - * REST service that saves and processes an action for a CLDS model by name. - * - * @param action the action - * @param modelName the model name - * @param test the test - * @param model the model - * @return response entity - * @throws TransformerException In case of issues when doing the XSLT of the BPMN flow - * @throws ParseException In case of issues when parsing the JSON - */ - public ResponseEntity putModelAndProcessAction(String action, String modelName, String test, CldsModel model) - throws TransformerException, ParseException { - util.entering(request, "CldsService: Process model action"); - final Date startTime = new Date(); - String errorMessage = ""; - String actionCd = ""; - try { - actionCd = action.toUpperCase(); - SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage, - cldsPermissionInstance, actionCd); - isAuthorized(permisionManage); - isAuthorizedForVf(model); - String userId = getUserId(); - logger.info("PUT actionCd={}", actionCd); - logger.info("PUT modelName={}", modelName); - logger.info("PUT test={}", test); - logger.info("PUT bpmnText={}", model.getBpmnText()); - logger.info("PUT propText={}", model.getPropText()); - logger.info("PUT userId={}", userId); - logger.info("PUT getTypeId={}", model.getTypeId()); - logger.info("PUT deploymentId={}", model.getDeploymentId()); - this.fillInCldsModel(model); - // save model to db just in case - model.save(cldsDao, getUserId()); - - // get vars and format if necessary - final String prop = model.getPropText(); - final String bpmn = model.getBpmnText(); - final String docText = model.getDocText(); - final String controlName = model.getControlName(); - final String bpmnJson = cldsBpmnTransformer.doXslTransformToString(bpmn); - logger.info("PUT bpmnJson={}", bpmnJson); - // 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); - 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.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) { - logger.error("Exception occured during invoking Camel process", e); - 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(); - } - - if (null == errorMessage || (null != errorMessage && !errorMessage.isEmpty())) { - 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); - if (null == errorMessage) { - errorMessage = "No response from Policy"; - } - model.setErrorMessageForUi(errorMessage); - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "putModelAndProcessAction failed", Level.INFO, - ONAPLogConstants.ResponseStatus.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); - } - } - - /** - * REST service that accepts events for a model. - * - * @param test the test - * @param dcaeEvent the dcae event - * @return the string - */ - public String postDcaeEvent(String test, DcaeEvent dcaeEvent) { - util.entering(request, "CldsService: Post dcae event"); - final Date startTime = new Date(); - String userid = null; - // TODO: allow auth checking to be turned off by removing the permission - // type property - if (cldsPermissionTypeClEvent != null && cldsPermissionTypeClEvent.length() > 0) { - SecureServicePermission permissionEvent = SecureServicePermission.create(cldsPermissionTypeClEvent, - cldsPermissionInstance, dcaeEvent.getEvent()); - isAuthorized(permissionEvent); - userid = getUserId(); - } - // Flag indicates whether it is triggered by Validation Test button from - // UI - boolean isTest = Boolean.parseBoolean(test); - int instanceCount = 0; - if (dcaeEvent.getInstances() != null) { - instanceCount = dcaeEvent.getInstances().size(); - } - String msgInfo = "event=" + dcaeEvent.getEvent() + " serviceUUID=" + dcaeEvent.getServiceUUID() - + " 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"); - } else { - if (DcaeEvent.EVENT_DEPLOYMENT.equalsIgnoreCase(dcaeEvent.getEvent())) { - CldsModel.insertModelInstance(cldsDao, dcaeEvent, userid); - } else { - CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userid, dcaeEvent.getCldsActionCd(), - CldsEvent.ACTION_STATE_RECEIVED, null); - } - } - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Post dcae event completed"); - util.exiting("200", "Post dcae event success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return msgInfo; - } - - /** - * REST service that retrieves total properties required by UI. - * - * @return the sdc properties - * @throws IOException In case of issues - */ - public String getSdcProperties() throws IOException { - return refProp.getJsonTemplate(GLOBAL_PROPERTIES_KEY).toString(); - } - - /** * Determine if the user is authorized for a particular VF by its invariant * UUID. @@ -534,7 +166,7 @@ public class CldsService extends SecureServiceBase { public boolean isAuthorizedForVf(String vfInvariantUuid) { if (cldsPermissionTypeFilterVf != null && !cldsPermissionTypeFilterVf.isEmpty()) { SecureServicePermission permission = SecureServicePermission.create(cldsPermissionTypeFilterVf, - cldsPermissionInstance, vfInvariantUuid); + cldsPermissionInstance, vfInvariantUuid); return isAuthorized(permission); } else { // if CLDS_PERMISSION_TYPE_FILTER_VF property is not provided, then @@ -544,169 +176,6 @@ public class CldsService extends SecureServiceBase { } } - /** - * Determine if the user is authorized for a particular VF by its invariant - * UUID. If not authorized, then NotAuthorizedException is thrown. - * - * @param model The clds model - * @return boolean or throws NotAuthorizedException - */ - private boolean isAuthorizedForVf(CldsModel model) { - String vf = ModelProperties.getVf(model); - if (vf == null || vf.length() == 0) { - logger.info("VF not found in model"); - return true; - } else { - return isAuthorizedForVf(vf); - } - } - - /** - * Deploy model response entity. - * - * @param modelName the model name - * @param model the model - * @return the response entity - */ - public ResponseEntity deployModel(String modelName, CldsModel model) { - util.entering(request, "CldsService: Deploy model"); - final Date startTime = new Date(); - String errorMessage = ""; - try { - fillInCldsModel(model); - String bpmnJson = cldsBpmnTransformer.doXslTransformToString(model.getBpmnText()); - logger.info("PUT bpmnJson={}", bpmnJson); - SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage, - cldsPermissionInstance, CldsEvent.ACTION_DEPLOY); - isAuthorized(permisionManage); - isAuthorizedForVf(model); - ModelProperties modelProp = new ModelProperties(modelName, model.getControlName(), CldsEvent.ACTION_DEPLOY, - false, bpmnJson, model.getPropText()); - checkForDuplicateServiceVf(modelName, model.getPropText()); - String deploymentId = ""; - // If model is already deployed then pass same deployment id - if (model.getDeploymentId() != null && !model.getDeploymentId().isEmpty()) { - deploymentId = model.getDeploymentId(); - } else { - model.setDeploymentId(deploymentId = "closedLoop_" + UUID.randomUUID() + "_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); - model.save(cldsDao, getUserId()); - // This is a blocking call - checkDcaeDeploymentStatus(model, CldsEvent.ACTION_DEPLOY, true); - // Refresh the model object in any cases for new event - model = CldsModel.retrieve(cldsDao, model.getName(), false); - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Deploy model completed"); - } catch (Exception e) { - errorMessage = e.getMessage(); - logger.error("Exception occured during deployModel", e); - } - if (!errorMessage.isEmpty()) { - model.setErrorMessageForUi(errorMessage); - 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); - } - } - - /** - * Un deploy model response entity. - * - * @param modelName the model name - * @param model the model - * @return the response entity - */ - public ResponseEntity unDeployModel(String modelName, CldsModel model) { - util.entering(request, "CldsService: Undeploy model"); - final Date startTime = new Date(); - String errorMessage = ""; - try { - SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage, - cldsPermissionInstance, CldsEvent.ACTION_UNDEPLOY); - isAuthorized(permisionManage); - isAuthorizedForVf(model); - model.setDeploymentStatusUrl( - dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(), model.getTypeId())); - CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), CldsEvent.ACTION_UNDEPLOY, - CldsEvent.ACTION_STATE_INITIATED, null); - // clean the deployment ID - model.setDeploymentId(null); - model.save(cldsDao, getUserId()); - // This is a blocking call - checkDcaeDeploymentStatus(model, CldsEvent.ACTION_UNDEPLOY, true); - // Refresh the model object in any cases for new event - model = CldsModel.retrieve(cldsDao, model.getName(), false); - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Undeploy model completed"); - } catch (Exception e) { - errorMessage = e.getMessage(); - logger.error("Exception occured during unDeployModel", e); - } - if (!errorMessage.isEmpty()) { - model.setErrorMessageForUi(errorMessage); - 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); - } - } - - private void checkForDuplicateServiceVf(String modelName, String modelPropText) throws IOException { - JsonElement globalNode = JsonUtils.GSON.fromJson(modelPropText, JsonObject.class).get("global"); - String service = JsonUtils.getStringValueByName(globalNode, "service"); - List resourceVf = JsonUtils.getStringValuesByName(globalNode, "vf"); - if (service != null && resourceVf != null && !resourceVf.isEmpty()) { - List cldsModelPropList = cldsDao.getDeployedModelProperties(); - for (CldsModelProp cldsModelProp : cldsModelPropList) { - JsonElement currentNode = JsonUtils.GSON - .fromJson(cldsModelProp.getPropText(), JsonObject.class) - .get("global"); - String currentService = JsonUtils.getStringValueByName(currentNode, "service"); - List currentVf = JsonUtils.getStringValuesByName(currentNode, "vf"); - if (currentVf != null && !currentVf.isEmpty()) { - 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."); - } - } - } - } - } - /** * Sets logging util. * diff --git a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java deleted file mode 100644 index 183db8bdb..000000000 --- a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java +++ /dev/null @@ -1,166 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.service; - -import java.util.Date; -import java.util.List; - -import javax.annotation.PostConstruct; -import javax.servlet.http.HttpServletRequest; - -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsTemplate; -import org.onap.clamp.clds.model.ValueItem; -import org.onap.clamp.clds.util.LoggingUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -/** - * Service to save and retrieve the CLDS model attributes. - */ -@Component -public class CldsTemplateService extends SecureServiceBase { - - @Value("${clamp.config.security.permission.type.template:permission-type-template}") - private String cldsPermissionTypeTemplate; - @Value("${clamp.config.security.permission.instance:dev}") - private String cldsPermissionInstance; - private SecureServicePermission permissionReadTemplate; - private SecureServicePermission permissionUpdateTemplate; - @Autowired - private HttpServletRequest request; - - @PostConstruct - private final void afterConstruction() { - permissionReadTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, - cldsPermissionInstance, "read"); - permissionUpdateTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, - cldsPermissionInstance, "update"); - } - - @Autowired - private CldsDao cldsDao; - private LoggingUtils util = new LoggingUtils(logger); - - /** - * REST service that retrieves BPMN for a CLDS template name from the - * database. This is subset of the json getModel. This is only expected to - * be used for testing purposes, not by the UI. - * - * @param templateName template name - * @return bpmn xml text - content of bpmn given name - */ - public String getBpmnTemplate(String templateName) { - util.entering(request, "CldsTemplateService: GET template bpmn"); - final Date startTime = new Date(); - isAuthorized(permissionReadTemplate); - logger.info("GET bpmnText for templateName=" + templateName); - - CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false); - auditLogInfo(util, "GET template bpmn", startTime); - return template.getBpmnText(); - } - - /** - * REST service that retrieves image for a CLDS template name from the - * database. This is subset of the json getModel. This is only expected to - * be used for testing purposes, not by the UI. - * - * @param templateName template name - * @return image xml text - content of image given name - */ - public String getImageXml(String templateName) { - util.entering(request, "CldsTemplateService: GET template image"); - final Date startTime = new Date(); - isAuthorized(permissionReadTemplate); - logger.info("GET imageText for templateName=" + templateName); - - CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false); - auditLogInfo(util, "GET template image", startTime); - return template.getImageText(); - } - - /** - * REST service that retrieves a CLDS template by name from the database. - * - * @param templateName template name - * @return clds template - clds template for the given template name - */ - public CldsTemplate getTemplate(String templateName) { - util.entering(request, "CldsTemplateService: GET template"); - final Date startTime = new Date(); - isAuthorized(permissionReadTemplate); - logger.info("GET model for templateName=" + templateName); - - CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false); - template.setUserAuthorizedToUpdate(isAuthorizedNoException(permissionUpdateTemplate)); - auditLogInfo(util, "GET template", startTime); - return template; - } - - /** - * REST service that saves a CLDS template by name in the database. - * - * @param templateName template name - * @param cldsTemplate clds template - * @return The CldsTemplate modified and saved in DB - */ - public CldsTemplate putTemplate(String templateName, CldsTemplate cldsTemplate) { - util.entering(request, "CldsTemplateService: PUT template"); - final Date startTime = new Date(); - isAuthorized(permissionUpdateTemplate); - logger.info("PUT Template for templateName=" + templateName); - logger.info("PUT bpmnText=" + cldsTemplate.getBpmnText()); - logger.info("PUT propText=" + cldsTemplate.getPropText()); - logger.info("PUT imageText=" + cldsTemplate.getImageText()); - cldsTemplate.setName(templateName); - cldsTemplate.save(cldsDao, null); - auditLogInfo(util, "PUT template", startTime); - return cldsTemplate; - } - - /** - * REST service that retrieves a list of CLDS template names. - * - * @return template names in JSON - */ - public List getTemplateNames() { - util.entering(request, "CldsTemplateService: GET template names"); - final Date startTime = new Date(); - isAuthorized(permissionReadTemplate); - logger.info("GET list of template names"); - - List names = cldsDao.getTemplateNames(); - auditLogInfo(util, "GET template names", startTime); - return names; - } - - // Created for the integration test - public void setLoggingUtil(LoggingUtils utilP) { - util = utilP; - } -} diff --git a/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java b/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java deleted file mode 100644 index 0d53e9155..000000000 --- a/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java +++ /dev/null @@ -1,166 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.service; - -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Optional; - -import javax.annotation.PostConstruct; - -import org.onap.clamp.clds.client.req.policy.PolicyClient; -import org.onap.clamp.clds.config.ClampProperties; -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsToscaModel; -import org.onap.clamp.clds.util.LoggingUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Component; - -/** - * REST services to manage Tosca Model. - */ -@Component -public class CldsToscaService extends SecureServiceBase { - - @Value("${clamp.config.security.permission.type.tosca:permission-type-tosca}") - private String cldsPermissionTypeTosca; - @Value("${clamp.config.security.permission.instance:dev}") - private String cldsPermissionInstance; - private SecureServicePermission permissionReadTosca; - private SecureServicePermission permissionUpdateTosca; - - @Autowired - private CldsDao cldsDao; - - @Autowired - private ClampProperties refProp; - - @Autowired - private PolicyClient policyClient; - private LoggingUtils util = new LoggingUtils(logger); - - @PostConstruct - private final void initConstruct() { - permissionReadTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance, "read"); - permissionUpdateTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance, - "update"); - } - - /** - * REST service to upload a new Tosca Model or update an existing Tosca - * model with new version. This API will parse the Tosca model yaml and - * generates a JSON schema out of it. - * - * @param toscaModelName - * Tosca model name to be used as a key - * @param cldsToscaModel - * Object containing the tosca model yaml - * - * @return clds tosca models - list of CLDS tosca models for a given policy - * type - */ - public ResponseEntity parseToscaModelAndSave(String toscaModelName, CldsToscaModel cldsToscaModel) { - final Date startTime = new Date(); - LoggingUtils.setRequestContext("CldsToscaService: Parse Tosca model and save", getPrincipalName()); - // TODO revisit based on new permissions - isAuthorized(permissionUpdateTosca); - cldsToscaModel.setToscaModelName(toscaModelName); - cldsToscaModel = cldsToscaModel.save(cldsDao, refProp, policyClient, getUserId()); - auditLogInfo("Parse Tosca model and save", startTime); - return new ResponseEntity<>(cldsToscaModel, HttpStatus.CREATED); - } - - /** - * REST service to retrieve all Tosca models from the CLDS database. - * - * @return clds tosca models - list of CLDS tosca models - */ - public List getAllToscaModels() { - // TODO revisit based on new permissions - final Date startTime = new Date(); - LoggingUtils.setRequestContext("CldsToscaService: Get All tosca models", getPrincipalName()); - isAuthorized(permissionReadTosca); - - Optional> cldsToscaModels = Optional.ofNullable(cldsDao.getAllToscaModels()); - auditLogInfo("Get All tosca models", startTime); - return cldsToscaModels.orElse(Collections.emptyList()); - } - - /** - * REST service that retrieves a CLDS Tosca model by model name from the - * database. - * - * @param toscaModelName - * Path param with tosca model name - * - * @return clds tosca model - CLDS tosca model for a given tosca model name - */ - public CldsToscaModel getToscaModel(String toscaModelName) { - final Date startTime = new Date(); - LoggingUtils.setRequestContext("CldsToscaService: Get tosca models by model name", getPrincipalName()); - // TODO revisit based on new permissions - isAuthorized(permissionReadTosca); - - Optional> cldsToscaModels = Optional.ofNullable( - cldsDao.getToscaModelByName(toscaModelName)); - auditLogInfo("Get tosca models by model name", startTime); - return cldsToscaModels.map(models -> models.get(0)).orElse(null); - } - - /** - * REST service that retrieves a CLDS Tosca model lists for a policy type - * from the database. - * @param policyType - * The type of the policy - * @return clds tosca model - CLDS tosca model for a given policy type - */ - public CldsToscaModel getToscaModelsByPolicyType(String policyType) { - final Date startTime = new Date(); - LoggingUtils.setRequestContext("CldsToscaService: Get tosca models by policyType", getPrincipalName()); - // TODO revisit based on new permissions - isAuthorized(permissionReadTosca); - - Optional> cldsToscaModels = Optional.ofNullable( - cldsDao.getToscaModelByPolicyType(policyType)); - auditLogInfo("Get tosca models by policyType", startTime); - return cldsToscaModels.map(models -> models.get(0)).orElse(null); - } - - public ResponseEntity deleteToscaModelById(String toscaModeId) { - // TODO - return null; - } - - // Created for the integration test - public void setLoggingUtil(LoggingUtils utilP) { - util = utilP; - } - -} diff --git a/src/main/resources/META-INF/resources/swagger.html b/src/main/resources/META-INF/resources/swagger.html index 0a0a877cd..d2ec96601 100644 --- a/src/main/resources/META-INF/resources/swagger.html +++ b/src/main/resources/META-INF/resources/swagger.html @@ -444,313 +444,132 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
  • 2. Paths
  • 3. Definitions
  • @@ -763,13 +582,13 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b

    1.1. Version information

    -

    Version : 4.1.1-SNAPSHOT

    +

    Version : 4.1.2-SNAPSHOT

    1.2. URI scheme

    -

    Host : localhost:43819
    +

    Host : localhost:40147
    BasePath : /restservices/clds/
    Schemes : HTTP

    @@ -780,77 +599,33 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b

    2. Paths

    -

    2.1. PUT /v1/clds/action/{action}/{modelName}?test={test}

    -
    -

    2.1.1. Parameters

    - ----- - - - - - - - - - - - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    action
    -required

    string

    Path

    modelName}?test={test
    -required

    string

    Body

    body
    -required

    CldsModel

    -
    +

    2.1. GET /v1/clds/cldsInfo

    -

    2.1.2. Responses

    +

    2.1.1. Responses

    --+++ + - + +
    HTTP CodeDescription Schema

    200

    No Content

    Output type

    CldsInfo

    -

    2.1.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.1.4. Produces

    +

    2.1.2. Produces

    • @@ -861,27 +636,24 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    2.2. GET /v1/clds/cldsDetails

    +

    2.2. GET /v1/healthcheck

    2.2.1. Responses

    ---++ - - - +
    HTTP CodeDescription Schema

    200

    Output type

    CldsMonitoringDetails

    No Content

    @@ -898,27 +670,24 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    2.3. GET /v1/clds/cldsInfo

    +

    2.3. GET /v1/user/getUser

    2.3.1. Responses

    ---++ - - - +
    HTTP CodeDescription Schema

    200

    Output type

    CldsInfo

    No Content

    @@ -928,16 +697,16 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    • -

      application/json

      +

      text/plain

    -

    2.4. POST /v1/clds/dcae/event?test={test}

    +

    2.4. PUT /v2/loop/delete/{loopName}

    -

    2.4.1. Parameters

    +

    2.4.1. Parameters

    @@ -953,10 +722,10 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - - + - +

    Body

    body
    +

    Path

    loopName
    required

    DcaeEvent

    string

    @@ -982,31 +751,11 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -
    -

    2.4.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.4.4. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -

    2.5. PUT /v1/clds/deploy/{modelName}

    +

    2.5. PUT /v2/loop/deploy/{loopName}

    -

    2.5.1. Parameters

    +

    2.5.1. Parameters

    @@ -1023,16 +772,10 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - - - - - -

    Path

    modelName
    +

    loopName
    required

    string

    Body

    body
    -required

    CldsModel

    @@ -1040,35 +783,28 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b

    2.5.2. Responses

    --+++ + - + +
    HTTP CodeDescription Schema

    200

    No Content

    Output type

    Loop

    -

    2.5.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.5.4. Produces

    +

    2.5.3. Produces

    • @@ -1079,7 +815,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    2.6. GET /v1/clds/model-names

    +

    2.6. GET /v2/loop/getAllNames

    2.6.1. Responses

    @@ -1099,13 +835,13 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - +

    200

    Output type

    ValueItem

    < string > array

    -

    2.6.2. Produces

    +

    2.6.2. Produces

    • @@ -1116,9 +852,9 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    2.7. GET /v1/clds/model/bpmn/{modelName}

    +

    2.7. GET /v2/loop/getstatus/{loopName}

    -

    2.7.1. Parameters

    +

    2.7.1. Parameters

    @@ -1135,7 +871,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - @@ -1146,38 +882,41 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b

    2.7.2. Responses

    Path

    modelName
    +

    loopName
    required

    string

    --+++ + - + +
    HTTP CodeDescription Schema

    200

    No Content

    Output type

    Loop

    -

    2.7.3. Produces

    +

    2.7.3. Produces

    • -

      text/xml

      +

      application/json

    -

    2.8. GET /v1/clds/model/image/{modelName}

    +

    2.8. PUT /v2/loop/restart/{loopName}

    -

    2.8.1. Parameters

    +

    2.8.1. Parameters

    @@ -1194,7 +933,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - @@ -1205,38 +944,41 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b

    2.8.2. Responses

    Path

    modelName
    +

    loopName
    required

    string

    --+++ + - + +
    HTTP CodeDescription Schema

    200

    No Content

    Output type

    Loop

    -

    2.8.3. Produces

    +

    2.8.3. Produces

    • -

      text/xml

      +

      application/json

    -

    2.9. GET /v1/clds/model/{modelName}

    +

    2.9. PUT /v2/loop/stop/{loopName}

    -

    2.9.1. Parameters

    +

    2.9.1. Parameters

    @@ -1253,7 +995,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - @@ -1279,13 +1021,13 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - +

    Path

    modelName
    +

    loopName
    required

    string

    200

    Output type

    CldsModel

    Loop

    -

    2.9.3. Produces

    +

    2.9.3. Produces

    • @@ -1296,9 +1038,9 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    2.10. PUT /v1/clds/model/{modelName}

    +

    2.10. PUT /v2/loop/submit/{loopName}

    -

    2.10.1. Parameters

    +

    2.10.1. Parameters

    @@ -1315,16 +1057,10 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - - - - - -

    Path

    modelName
    +

    loopName
    required

    string

    Body

    body
    -required

    CldsModel

    @@ -1347,23 +1083,13 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b

    200

    Output type

    -

    CldsModel

    +

    Loop

    -

    2.10.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.10.4. Produces

    +

    2.10.3. Produces

    • @@ -1374,118 +1100,34 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    2.11. GET /v1/clds/properties

    +

    2.11. GET /v2/loop/svgRepresentation/{loopName}

    -

    2.11.1. Responses

    +

    2.11.1. Parameters

    +-+ - + + - - + + +
    HTTP CodeTypeName Schema

    200

    No Content

    Path

    loopName
    +required

    string

    -

    2.11.2. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.12. PUT /v1/clds/undeploy/{modelName}

    -
    -

    2.12.1. Parameters

    - ----- - - - - - - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    modelName
    -required

    string

    Body

    body
    -required

    CldsModel

    -
    -
    -

    2.12.2. Responses

    - ---- - - - - - - - - - - - - -
    HTTP CodeSchema

    200

    No Content

    -
    -
    -

    2.12.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.12.4. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.13. GET /v1/cldsTempate/template-names

    -
    -

    2.13.1. Responses

    +

    2.11.2. Responses

    @@ -1503,144 +1145,26 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - - - -

    200

    Output type

    ValueItem

    -
    -
    -

    2.13.2. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.14. GET /v1/cldsTempate/template/bpmn/{templateName}

    -
    -

    2.14.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    templateName
    -required

    string

    -
    -
    -

    2.14.2. Responses

    - ---- - - - - - - - - - - - - -
    HTTP CodeSchema

    200

    No Content

    -
    -
    -

    2.14.3. Produces

    -
    -
      -
    • -

      text/xml

      -
    • -
    -
    -
    -
    -
    -

    2.15. GET /v1/cldsTempate/template/image/{templateName}

    -
    -

    2.15.1. Parameters

    - ----- - - - - - - - - - - -
    TypeNameSchema

    Path

    templateName
    -required

    string

    -

    2.15.2. Responses

    - ---- - - - - - - - - - - - - -
    HTTP CodeSchema

    200

    No Content

    -
    -
    -

    2.15.3. Produces

    +

    2.11.3. Produces

    • -

      text/xml

      +

      application/xml

    -

    2.16. GET /v1/cldsTempate/template/{templateName}

    +

    2.12. PUT /v2/loop/undeploy/{loopName}

    -

    2.16.1. Parameters

    +

    2.12.1. Parameters

    @@ -1657,7 +1181,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - @@ -1665,7 +1189,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b

    Path

    templateName
    +

    loopName
    required

    string

    -

    2.16.2. Responses

    +

    2.12.2. Responses

    @@ -1683,13 +1207,13 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - +

    200

    Output type

    CldsTemplate

    Loop

    -

    2.16.3. Produces

    +

    2.12.3. Produces

    • @@ -1700,9 +1224,9 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    2.17. PUT /v1/cldsTempate/template/{templateName}

    +

    2.13. POST /v2/loop/updateGlobalProperties/{loopName}

    -

    2.17.1. Parameters

    +

    2.13.1. Parameters

    @@ -1719,7 +1243,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - @@ -1727,13 +1251,13 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - +

    Path

    templateName
    +

    loopName
    required

    string

    Body

    body
    required

    CldsTemplate

    JsonObject

    -

    2.17.2. Responses

    +

    2.13.2. Responses

    @@ -1751,23 +1275,13 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - +

    200

    Output type

    CldsTemplate

    Loop

    -

    2.17.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.17.4. Produces

    +

    2.13.3. Consumes

    • @@ -1776,35 +1290,8 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -
    -
    -

    2.18. GET /v1/dictionary

    -
    -

    2.18.1. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    CldsDictionary

    -
    -

    2.18.2. Produces

    +

    2.13.4. Produces

    • @@ -1815,9 +1302,9 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    2.19. PUT /v1/dictionary/{dictionaryName}

    +

    2.14. POST /v2/loop/updateMicroservicePolicy/{loopName}

    -

    2.19.1. Parameters

    +

    2.14.1. Parameters

    @@ -1834,7 +1321,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - @@ -1842,13 +1329,13 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - +

    Path

    dictionaryName
    +

    loopName
    required

    string

    Body

    body
    required

    CldsDictionary

    MicroServicePolicy

    -

    2.19.2. Responses

    +

    2.14.2. Responses

    @@ -1866,13 +1353,13 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - +

    200

    Output type

    CldsDictionary

    MicroServicePolicy

    -

    2.19.3. Consumes

    +

    2.14.3. Consumes

    • @@ -1882,7 +1369,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    2.19.4. Produces

    +

    2.14.4. Produces

    • @@ -1893,9 +1380,9 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    2.20. GET /v1/dictionary/{dictionaryName}/items

    +

    2.15. POST /v2/loop/updateOperationalPolicies/{loopName}

    -

    2.20.1. Parameters

    +

    2.15.1. Parameters

    @@ -1904,1839 +1391,141 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - - - - - - - - - - - - -
    TypeNameSchema

    Path

    dictionaryName
    -required

    string

    -
    -
    -

    2.20.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    CldsDictionary

    -
    -
    -

    2.20.3. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.21. PUT /v1/dictionary/{dictionaryName}/items

    -
    -

    2.21.1. Parameters

    - ----- - - - - - - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    dictionaryName
    -required

    string

    Body

    body
    -required

    CldsDictionaryItem

    -
    -
    -

    2.21.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    CldsDictionaryItem

    -
    -
    -

    2.21.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.21.4. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.22. GET /v1/healthcheck

    -
    -

    2.22.1. Responses

    - ---- - - - - - - - - - - - - -
    HTTP CodeSchema

    200

    No Content

    -
    -
    -

    2.22.2. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.23. GET /v1/tosca/models

    -
    -

    2.23.1. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    CldsToscaModel

    -
    -
    -

    2.23.2. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.24. GET /v1/tosca/models/policyType/{policyType}

    -
    -

    2.24.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    policyType
    -required

    string

    -
    -
    -

    2.24.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    CldsToscaModel

    -
    -
    -

    2.24.3. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.25. GET /v1/tosca/models/{toscaModelName}

    -
    -

    2.25.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    toscaModelName
    -required

    string

    -
    -
    -

    2.25.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    CldsToscaModel

    -
    -
    -

    2.25.3. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.26. PUT /v1/tosca/models/{toscaModelName}

    -
    -

    2.26.1. Parameters

    - ----- - - - - - - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    toscaModelName
    -required

    string

    Body

    body
    -required

    CldsToscaModel

    -
    -
    -

    2.26.2. Responses

    - ---- - - - - - - - - - - - - -
    HTTP CodeSchema

    200

    No Content

    -
    -
    -

    2.26.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.26.4. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.27. GET /v1/user/getUser

    -
    -

    2.27.1. Responses

    - ---- - - - - - - - - - - - - -
    HTTP CodeSchema

    200

    No Content

    -
    -
    -

    2.27.2. Produces

    -
    -
      -
    • -

      text/plain

      -
    • -
    -
    -
    -
    -
    -

    2.28. PUT /v2/loop/delete/{loopName}

    -
    -

    2.28.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    -
    -
    -

    2.28.2. Responses

    - ---- - - - - - - - - - - - - -
    HTTP CodeSchema

    200

    No Content

    -
    -
    -
    -

    2.29. PUT /v2/loop/deploy/{loopName}

    -
    -

    2.29.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    -
    -
    -

    2.29.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    Loop

    -
    -
    -

    2.29.3. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.30. GET /v2/loop/getAllNames

    -
    -

    2.30.1. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    < string > array

    -
    -
    -

    2.30.2. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.31. GET /v2/loop/getstatus/{loopName}

    -
    -

    2.31.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    -
    -
    -

    2.31.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    Loop

    -
    -
    -

    2.31.3. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.32. PUT /v2/loop/restart/{loopName}

    -
    -

    2.32.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    -
    -
    -

    2.32.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    Loop

    -
    -
    -

    2.32.3. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.33. PUT /v2/loop/stop/{loopName}

    -
    -

    2.33.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    -
    -
    -

    2.33.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    Loop

    -
    -
    -

    2.33.3. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.34. PUT /v2/loop/submit/{loopName}

    -
    -

    2.34.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    -
    -
    -

    2.34.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    Loop

    -
    -
    -

    2.34.3. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.35. GET /v2/loop/svgRepresentation/{loopName}

    -
    -

    2.35.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    -
    -
    -

    2.35.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    string

    -
    -
    -

    2.35.3. Produces

    -
    -
      -
    • -

      application/xml

      -
    • -
    -
    -
    -
    -
    -

    2.36. PUT /v2/loop/undeploy/{loopName}

    -
    -

    2.36.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    -
    -
    -

    2.36.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    Loop

    -
    -
    -

    2.36.3. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.37. POST /v2/loop/updateGlobalProperties/{loopName}

    -
    -

    2.37.1. Parameters

    - ----- - - - - - - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    Body

    body
    -required

    JsonObject

    -
    -
    -

    2.37.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    Loop

    -
    -
    -

    2.37.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.37.4. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.38. POST /v2/loop/updateMicroservicePolicy/{loopName}

    -
    -

    2.38.1. Parameters

    - ----- - - - - - - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    Body

    body
    -required

    MicroServicePolicy

    -
    -
    -

    2.38.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    MicroServicePolicy

    -
    -
    -

    2.38.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.38.4. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.39. POST /v2/loop/updateOperationalPolicies/{loopName}

    -
    -

    2.39.1. Parameters

    - ----- - - - - - - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    Body

    body
    -required

    JsonArray

    -
    -
    -

    2.39.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    Loop

    -
    -
    -

    2.39.3. Consumes

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -

    2.39.4. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -

    2.40. GET /v2/loop/{loopName}

    -
    -

    2.40.1. Parameters

    - ----- - - - - - - - - - - - - - - -
    TypeNameSchema

    Path

    loopName
    -required

    string

    -
    -
    -

    2.40.2. Responses

    - ----- - - - - - - - - - - - - - - -
    HTTP CodeDescriptionSchema

    200

    Output type

    Loop

    -
    -
    -

    2.40.3. Produces

    -
    -
      -
    • -

      application/json

      -
    • -
    -
    -
    -
    -
    -
    -
    -

    3. Definitions

    -
    -
    -

    3.1. CldsDictionary

    - ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameSchema

    cldsDictionaryItems
    -optional

    < CldsDictionaryItem > array

    createdBy
    -optional

    string

    dictionaryId
    -optional

    string

    dictionaryName
    -optional

    string

    lastUpdatedDate
    -optional

    string

    updatedBy
    -optional

    string

    -
    -
    -

    3.2. CldsDictionaryItem

    - ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameSchema

    createdBy
    -optional

    string

    dictElementDesc
    -optional

    string

    dictElementId
    -optional

    string

    dictElementName
    -optional

    string

    dictElementShortName
    -optional

    string

    dictElementType
    -optional

    string

    dictionaryId
    -optional

    string

    lastUpdatedDate
    -optional

    string

    updatedBy
    -optional

    string

    -
    -
    -

    3.3. CldsEvent

    - ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameSchema

    actionCd
    -optional

    string

    actionStateCd
    -optional

    string

    id
    -optional

    string

    processInstanceId
    -optional

    string

    userid
    -optional

    string

    -
    -
    -

    3.4. CldsInfo

    - ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameSchema

    cldsVersion
    -optional

    string

    permissionReadCl
    -optional

    boolean

    permissionReadTemplate
    -optional

    boolean

    permissionReadTosca
    -optional

    boolean

    permissionUpdateCl
    -optional

    boolean

    permissionUpdateTemplate
    -optional

    boolean

    permissionUpdateTosca
    -optional

    boolean

    userName
    -optional

    string

    -
    -
    -

    3.5. CldsModel

    - ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    NameSchema

    blueprintText
    -optional

    string

    bpmnText
    -optional

    string

    cldsModelInstanceList
    -optional

    < CldsModelInstance > array

    controlName
    -optional

    string

    controlNamePrefix
    -optional

    string

    controlNameUuid
    -optional

    string

    deploymentId
    -optional

    string

    deploymentStatusUrl
    -optional

    string

    docText
    -optional

    string

    errorMessageForUi
    -optional

    string

    event
    -optional

    CldsEvent

    id
    -optional

    string

    imageText
    -optional

    string

    name
    -optional

    string

    permittedActionCd
    -optional

    < string > array

    propText
    -optional

    string

    status
    -optional

    string

    templateId
    -optional

    string

    templateName
    -optional

    string

    typeId
    -optional

    string

    typeName
    -optional

    string

    -
    -
    -

    3.6. CldsModelInstance

    - ---- - - + - - - - - + + - - + + +
    Type Name Schema

    location
    -optional

    string

    modelInstanceId
    -optional

    Path

    loopName
    +required

    string

    vmName
    -optional

    string

    Body

    body
    +required

    JsonArray

    -
    -

    3.7. CldsMonitoringDetails

    +
    +

    2.15.2. Responses

    --+++ - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +
    NameHTTP CodeDescription Schema

    action
    -optional

    string

    closeloopName
    -optional

    string

    deploymentId
    -optional

    string

    modelId
    -optional

    string

    modelName
    -optional

    string

    serviceTypeId
    -optional

    string

    templateName
    -optional

    string

    timestamp
    -optional

    string

    userid
    -optional

    string

    200

    Output type

    Loop

    +
    +

    2.15.3. Consumes

    +
    +
      +
    • +

      application/json

      +
    • +
    +
    +
    +
    +

    2.15.4. Produces

    +
    +
      +
    • +

      application/json

      +
    • +
    +
    +
    +
    -

    3.8. CldsTemplate

    +

    2.16. GET /v2/loop/{loopName}

    +
    +

    2.16.1. Parameters

    --+++ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - -
    Type Name Schema

    bpmnId
    -optional

    string

    bpmnText
    -optional

    string

    bpmnUserid
    -optional

    string

    controlNamePrefix
    -optional

    string

    controlNameUuid
    -optional

    string

    id
    -optional

    string

    imageId
    -optional

    string

    imageText
    -optional

    string

    imageUserid
    -optional

    string

    name
    -optional

    string

    propId
    -optional

    string

    propText
    -optional

    string

    propUserid
    -optional

    Path

    loopName
    +required

    string

    userAuthorizedToUpdate
    -optional

    boolean

    -
    -

    3.9. CldsToscaModel

    +
    +

    2.16.2. Responses

    --+++ - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +
    NameHTTP CodeDescription Schema

    createdDate
    -optional

    string

    id
    -optional

    string

    lastUpdatedDate
    -optional

    string

    policyType
    -optional

    string

    revisionId
    -optional

    string

    toscaModelJson
    -optional

    string

    toscaModelName
    -optional

    string

    toscaModelYaml
    -optional

    string

    userId
    -optional

    string

    version
    -optional

    number (double)

    200

    Output type

    Loop

    +
    +

    2.16.3. Produces

    +
    +
      +
    • +

      application/json

      +
    • +
    +
    +
    +
    +
    +
    +
    +

    3. Definitions

    +
    -

    3.10. DcaeEvent

    +

    3.1. CldsInfo

    @@ -3750,37 +1539,42 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b - - - + - - + - - + - - + - - + + + + + - @@ -3788,7 +1582,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b

    artifactName
    +

    cldsVersion
    optional

    string

    cldsActionCd
    +

    permissionReadCl
    optional

    string

    boolean

    controlName
    +

    permissionReadTemplate
    optional

    string

    boolean

    event
    +

    permissionReadTosca
    optional

    string

    boolean

    instances
    +

    permissionUpdateCl
    optional

    < CldsModelInstance > array

    boolean

    resourceUUID
    +

    permissionUpdateTemplate
    optional

    string

    boolean

    permissionUpdateTosca
    +optional

    boolean

    serviceUUID
    +

    userName
    optional

    string

    -

    3.11. ExternalComponent

    +

    3.2. ExternalComponent

    @@ -3815,7 +1609,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    3.12. ExternalComponentState

    +

    3.3. ExternalComponentState

    @@ -3847,7 +1641,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    3.13. JsonArray

    +

    3.4. JsonArray

    @@ -3964,7 +1758,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    3.14. JsonNull

    +

    3.5. JsonNull

    @@ -4081,7 +1875,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    3.15. JsonObject

    +

    3.6. JsonObject

    @@ -4198,7 +1992,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    3.16. JsonPrimitive

    +

    3.7. JsonPrimitive

    @@ -4330,7 +2124,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    3.17. Loop

    +

    3.8. Loop

    @@ -4412,7 +2206,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    3.18. LoopLog

    +

    3.9. LoopLog

    @@ -4459,7 +2253,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    3.19. MicroServicePolicy

    +

    3.10. MicroServicePolicy

    @@ -4511,13 +2305,13 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -

    3.20. Number

    +

    3.11. Number

    Type : object

    -

    3.21. OperationalPolicy

    +

    3.12. OperationalPolicy

    @@ -4553,28 +2347,6 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    -
    -

    3.22. ValueItem

    - ---- - - - - - - - - - - - - -
    NameSchema

    value
    -optional

    string

    -
    diff --git a/src/main/resources/clds/camel/rest/clds-services.xml b/src/main/resources/clds/camel/rest/clds-services.xml index d4baa09a9..b3061dc42 100644 --- a/src/main/resources/clds/camel/rest/clds-services.xml +++ b/src/main/resources/clds/camel/rest/clds-services.xml @@ -1,11 +1,5 @@ - - - @@ -16,153 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cldsMonitoringDetailsList = new ArrayList(); - cldsMonitoringDetailsList = cldsDao.getCldsMonitoringDetails(); - cldsMonitoringDetailsList.forEach(clName -> { - logger.info(clName.getCloseloopName()); - assertNotNull(clName.getCloseloopName()); - }); + "process-instance-id"); } } diff --git a/src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java deleted file mode 100644 index 5218c9255..000000000 --- a/src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java +++ /dev/null @@ -1,177 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.util.LinkedList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.onap.clamp.clds.model.CldsDictionary; -import org.onap.clamp.clds.model.CldsDictionaryItem; -import org.onap.clamp.clds.service.CldsDictionaryService; -import org.onap.clamp.clds.util.LoggingUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.ResponseEntity; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.userdetails.User; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Test CLDS Dictionary Service APIs. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class CldsDictionaryServiceItCase { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDictionaryServiceItCase.class); - @Autowired - private CldsDictionaryService cldsDictionaryService; - private CldsDictionary cldsDictionary; - private CldsDictionaryItem cldsDictionaryItem; - private List authList = new LinkedList<>(); - - private static final String DICTIONARY_NAME = "TestDictionary"; - - /** - * Setup the variable before the tests execution. - * - */ - @Before - public void setupBefore() { - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-filter-vf|dev|*")); - authList.add(new SimpleGrantedAuthority("permission-type-tosca|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-tosca|dev|update")); - - Authentication authentication = - new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList); - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); - - LoggingUtils util = Mockito.mock(LoggingUtils.class); - Mockito.doNothing().when(util).entering(Matchers.any(HttpServletRequest.class), Matchers.any(String.class)); - cldsDictionaryService.setLoggingUtil(util); - - cldsDictionaryService.setSecurityContext(securityContext); - - cldsDictionary = cldsDictionaryService.createDictionary(DICTIONARY_NAME); - - cldsDictionaryItem = new CldsDictionaryItem(); - cldsDictionaryItem.setDictElementShortName("TestDictionaryItemShortName"); - cldsDictionaryItem.setDictElementName("TestDictionaryItemName"); - cldsDictionaryItem.setDictElementType("string"); - cldsDictionaryItem.setDictionaryId(cldsDictionary.getDictionaryId()); - cldsDictionaryItem.setDictElementDesc("TestDictionaryItemDesc"); - cldsDictionaryService.createOrUpdateDictionaryElements(DICTIONARY_NAME, cldsDictionaryItem); - - logger.info("Initial Clds Dictionary uploaded in DB:" + cldsDictionaryItem); - } - - @Test - public void testCreateDictionaryFromString() { - String dictionaryName = "TestDefaultDictionary"; - CldsDictionary dictionary = cldsDictionaryService.createDictionary(dictionaryName); - assertNotNull(dictionary); - logger.info("CLDS Default Dictionary is:" + dictionary); - assertEquals(dictionaryName, dictionary.getDictionaryName()); - } - - @Test - public void testCreateOrUpdateDictionaryUsedByFrontend() { - ResponseEntity responseEntity = - cldsDictionaryService.createOrUpdateDictionary(DICTIONARY_NAME, null); - CldsDictionary dictionary1 = responseEntity.getBody(); - - responseEntity = cldsDictionaryService.createOrUpdateDictionary(DICTIONARY_NAME, cldsDictionary); - CldsDictionary dictionary2 = responseEntity.getBody(); - - responseEntity = cldsDictionaryService.createOrUpdateDictionary(DICTIONARY_NAME, new CldsDictionary()); - CldsDictionary dictionary3 = responseEntity.getBody(); - - assertNotNull(dictionary1); - assertNotNull(dictionary2); - assertNotNull(dictionary3); - assertEquals(DICTIONARY_NAME, dictionary1.getDictionaryName()); - assertEquals(DICTIONARY_NAME, dictionary2.getDictionaryName()); - assertNotNull(dictionary3.getDictionaryName()); - assertEquals(DICTIONARY_NAME, dictionary3.getDictionaryName()); - } - - @Test - public void testCreateOrUpdateDictionaryElements() { - cldsDictionaryItem = new CldsDictionaryItem(); - cldsDictionaryItem.setDictElementShortName("TestDictionaryItemShortName1"); - cldsDictionaryItem.setDictElementName("TestDictionaryItemName1"); - cldsDictionaryItem.setDictElementType("string"); - cldsDictionaryItem.setDictionaryId(cldsDictionary.getDictionaryId()); - cldsDictionaryItem.setDictElementDesc("TestDictionaryItemDesc1"); - - ResponseEntity responseEntity = cldsDictionaryService - .createOrUpdateDictionaryElements(DICTIONARY_NAME, cldsDictionaryItem); - CldsDictionaryItem dictionaryItem = responseEntity.getBody(); - assertNotNull(dictionaryItem); - logger.info("CLDS Dictionary Item is:" + dictionaryItem); - assertEquals("TestDictionaryItemName1", dictionaryItem.getDictElementName()); - } - - @Test - public void testGetAllDictionaryNames() { - ResponseEntity> responseEntity = cldsDictionaryService.getAllDictionaryNames(); - List dictionaries = responseEntity.getBody(); - assertNotNull(dictionaries); - logger.info("CLDS Dictionary List is:" + dictionaries); - } - - @Test - public void testGetDictionaryElementsByName() { - ResponseEntity> responseEntity = cldsDictionaryService - .getDictionaryElementsByName(DICTIONARY_NAME); - List dictionaryItems = responseEntity.getBody(); - assertNotNull(dictionaryItems); - logger.info("CLDS Dictionary Item LIst is:" + dictionaryItems); - } -} \ No newline at end of file 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 faeb04182..963f45bec 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java @@ -35,32 +35,20 @@ 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.lang3.RandomStringUtils; -import org.json.simple.parser.ParseException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mockito; import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsInfo; -import org.onap.clamp.clds.model.CldsModel; -import org.onap.clamp.clds.model.CldsMonitoringDetails; -import org.onap.clamp.clds.model.CldsTemplate; -import org.onap.clamp.clds.model.DcaeEvent; import org.onap.clamp.clds.service.CldsService; import org.onap.clamp.clds.util.LoggingUtils; import org.onap.clamp.clds.util.ResourceFileUtil; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; @@ -93,8 +81,7 @@ public class CldsServiceItCase { /** * Setup the variable before the tests execution. * - * @throws IOException - * In case of issues when opening the files + * @throws IOException In case of issues when opening the files */ @Before public void setupBefore() throws IOException { @@ -154,127 +141,4 @@ public class CldsServiceItCase { assertEquals(cldsInfo.getCldsVersion(), prop.getProperty("clds.version")); assertEquals(cldsInfo.getUserName(), "admin"); } - - @Test - public void testGetCldsDetails() throws IOException { - List cldsMonitoringDetailsList = cldsService.getCldsDetails(); - assertNotNull(cldsMonitoringDetailsList); - } - - @Test(expected = NotFoundException.class) - public void testCompleteFlow() throws TransformerException, ParseException { - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); - - cldsService.setSecurityContext(securityContext); - // Add the template first - CldsTemplate newTemplate = new CldsTemplate(); - String randomNameTemplate = RandomStringUtils.randomAlphanumeric(5); - newTemplate.setName(randomNameTemplate); - newTemplate.setBpmnText(bpmnText); - newTemplate.setImageText(imageText); - // Save the template in DB - cldsDao.setTemplate(newTemplate, "user"); - // Test if it's well there - CldsTemplate newTemplateRead = cldsDao.getTemplate(randomNameTemplate); - assertEquals(bpmnText, newTemplateRead.getBpmnText()); - assertEquals(imageText, newTemplateRead.getImageText()); - // Save the model - String randomNameModel = RandomStringUtils.randomAlphanumeric(5); - CldsModel newModel = new CldsModel(); - newModel.setName(randomNameModel); - newModel.setBpmnText(bpmnText); - newModel.setImageText(imageText); - newModel.setPropText(bpmnPropText); - newModel.setControlNamePrefix("ClosedLoop-"); - newModel.setTemplateName(randomNameTemplate); - newModel.setTemplateId(newTemplate.getId()); - newModel.setDocText(docText); - // Test the PutModel method - - cldsService.putModel(randomNameModel, newModel); - - assertEquals(bpmnText, cldsService.getBpmnXml(randomNameModel)); - assertEquals(imageText, cldsService.getImageXml(randomNameModel)); - - // Verify whether it has been added properly or not - assertNotNull(cldsDao.getModel(randomNameModel)); - - CldsModel model = cldsService.getModel(randomNameModel); - // Verify with GetModel - assertEquals(model.getTemplateName(), randomNameTemplate); - assertEquals(model.getName(), randomNameModel); - - assertTrue(cldsService.getModelNames().size() >= 1); - - // Should fail - ResponseEntity responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_SUBMIT, - randomNameModel, "false", cldsService.getModel(randomNameModel)); - assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); - assertNotNull(responseEntity.getBody()); - assertTrue(CldsModel.STATUS_DISTRIBUTED.equals(((CldsModel) responseEntity.getBody()).getStatus())); - assertTrue(CldsModel.STATUS_DISTRIBUTED.equals(cldsService.getModel(randomNameModel).getStatus())); - - responseEntity = cldsService.deployModel(randomNameModel, cldsService.getModel(randomNameModel)); - assertNotNull(responseEntity); - 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_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)); - assertNotNull(responseEntity.getBody()); - 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()); - // This will raise an exception - cldsService.getModel(randomNameModel); - } - - @Test - public void testDcaePost() { - DcaeEvent dcaeEvent = new DcaeEvent(); - dcaeEvent.setArtifactName("ClosedLoop_with-enough-characters_TestArtifact.yml"); - dcaeEvent.setEvent(DcaeEvent.EVENT_CREATED); - dcaeEvent.setResourceUUID("1"); - dcaeEvent.setServiceUUID("2"); - assertEquals(cldsService.postDcaeEvent("false", dcaeEvent), - "event=created serviceUUID=2 resourceUUID=1 artifactName=" - + "ClosedLoop_with-enough-characters_TestArtifact.yml instance count=0 isTest=false"); - } - - @Test - public void testGetSdcProperties() throws IOException { - JSONAssert.assertEquals( - ResourceFileUtil.getResourceAsString("example/sdc/expected-result/sdc-properties-global.json"), - cldsService.getSdcProperties(), true); - } } diff --git a/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java deleted file mode 100644 index ba8b0b79d..000000000 --- a/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.io.IOException; -import java.security.Principal; -import java.util.LinkedList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsTemplate; -import org.onap.clamp.clds.model.ValueItem; -import org.onap.clamp.clds.service.CldsTemplateService; -import org.onap.clamp.clds.util.LoggingUtils; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.User; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class CldsTemplateServiceItCase { - - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsTemplateServiceItCase.class); - @Autowired - private CldsTemplateService cldsTemplateService; - @Autowired - private CldsDao cldsDao; - private String bpmnText; - private String imageText; - private String bpmnPropText; - private CldsTemplate cldsTemplate; - private Authentication authentication; - private List authList = new LinkedList(); - private LoggingUtils util; - - /** - * Setup the variable before the tests execution. - * - * @throws IOException - * In case of issues when opening the files - */ - @Before - public void setupBefore() throws IOException { - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-filter-vf|dev|*")); - authentication = new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList); - - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); - - util = Mockito.mock(LoggingUtils.class); - Mockito.doNothing().when(util).entering(Matchers.any(HttpServletRequest.class), Matchers.any(String.class)); - cldsTemplateService.setLoggingUtil(util); - - cldsTemplateService.setSecurityContext(securityContext); - bpmnText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-template.xml"); - imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml"); - bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json"); - cldsTemplate = new CldsTemplate(); - cldsTemplate.setName("testModel"); - cldsTemplate.setBpmnText(bpmnText); - cldsTemplate.setImageText(imageText); - cldsTemplate.setPropText(bpmnPropText); - cldsTemplateService.putTemplate("testModel", cldsTemplate); - } - - @Test - public void testPutTemplate() throws Exception { - CldsTemplate savedTemplate = CldsTemplate.retrieve(cldsDao, "testModel", false); - assertNotNull(savedTemplate); - logger.info("saved template bpmn text is:" + savedTemplate.getBpmnText()); - assertEquals(bpmnText, savedTemplate.getBpmnText()); - assertEquals(imageText, savedTemplate.getImageText()); - assertEquals(bpmnPropText, savedTemplate.getPropText()); - assertEquals("testModel", savedTemplate.getName()); - } - - @Test - public void testGetTemplate() throws Exception { - CldsTemplate getTemplate = cldsTemplateService.getTemplate("testModel"); - assertNotNull(getTemplate); - assertEquals(bpmnText, getTemplate.getBpmnText()); - assertEquals(imageText, getTemplate.getImageText()); - assertEquals(bpmnPropText, getTemplate.getPropText()); - assertEquals("testModel", getTemplate.getName()); - } - - @Test - public void testGetImageXml() throws Exception { - String imageXml = cldsTemplateService.getImageXml("testModel"); - assertEquals(imageText, imageXml); - } - - @Test - public void testGetBpmnTemplate() throws Exception { - String bpmnTemplate = cldsTemplateService.getBpmnTemplate("testModel"); - assertEquals(bpmnText, bpmnTemplate); - } - - @Test - public void testGetTemplateNames() throws Exception { - CldsTemplate cldsTemplateNew = new CldsTemplate(); - cldsTemplateNew.setName("testModelNew"); - cldsTemplateNew.setBpmnText(bpmnText); - cldsTemplateNew.setImageText(imageText); - cldsTemplateNew.setPropText(bpmnPropText); - cldsTemplateService.putTemplate("testModelNew", cldsTemplateNew); - List templateNames = cldsTemplateService.getTemplateNames(); - boolean testModel = false; - boolean testModelNew = false; - for (ValueItem item : templateNames) { - if (item.getValue().equals("testModel")) { - testModel = true; - } - if (item.getValue().equals("testModelNew")) { - testModelNew = true; - } - } - assertTrue(testModel || testModelNew); - } -} diff --git a/src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java deleted file mode 100644 index 992c06e8c..000000000 --- a/src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java +++ /dev/null @@ -1,136 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.onap.clamp.clds.model.CldsToscaModel; -import org.onap.clamp.clds.service.CldsToscaService; -import org.onap.clamp.clds.util.LoggingUtils; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.ResponseEntity; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.userdetails.User; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Test CLDS Tosca Service APIs. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class CldsToscaServiceItCase { - - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsToscaServiceItCase.class); - @Autowired - private CldsToscaService cldsToscaService; - private String toscaModelYaml; - private Authentication authentication; - private CldsToscaModel cldsToscaModel; - private List authList = new LinkedList<>(); - private LoggingUtils util; - - /** - * Setup the variable before the tests execution. - * - * @throws IOException - * In case of issues when opening the files - */ - @Before - public void setupBefore() throws IOException { - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-filter-vf|dev|*")); - authList.add(new SimpleGrantedAuthority("permission-type-tosca|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-tosca|dev|update")); - authentication = new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList); - - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); - - util = Mockito.mock(LoggingUtils.class); - Mockito.doNothing().when(util).entering(Matchers.any(HttpServletRequest.class), Matchers.any(String.class)); - cldsToscaService.setLoggingUtil(util); - - cldsToscaService.setSecurityContext(securityContext); - - toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tca-policy-test.yaml"); - - cldsToscaModel = new CldsToscaModel(); - cldsToscaModel.setToscaModelName("tca-policy-test"); - cldsToscaModel.setToscaModelYaml(toscaModelYaml); - cldsToscaModel.setUserId("admin"); - cldsToscaModel.setPolicyType("tca"); - cldsToscaService.parseToscaModelAndSave("tca-policy-test", cldsToscaModel); - logger.info("Initial Tosca Model uploaded in DB:" + cldsToscaModel); - } - - @Test - public void testParseToscaModelAndSave() throws Exception { - ResponseEntity responseEntity = cldsToscaService.parseToscaModelAndSave("tca-policy-test", cldsToscaModel); - CldsToscaModel savedModel = (CldsToscaModel) responseEntity.getBody(); - assertNotNull(savedModel); - logger.info("Parsed Tosca Model is:" + savedModel); - assertEquals("tca-policy-test", savedModel.getToscaModelName()); - } - - @Test - public void testGetToscaModel() throws Exception { - CldsToscaModel savedModel = cldsToscaService.getToscaModel("tca-policy-test"); - assertNotNull(savedModel); - assertEquals("tca-policy-test", savedModel.getToscaModelName()); - } - - @Test - public void testGetToscaModelsByPolicyType() throws Exception { - CldsToscaModel savedModel = cldsToscaService.getToscaModelsByPolicyType("tca"); - assertNotNull(savedModel); - assertEquals("tca-policy-test", savedModel.getToscaModelName()); - assertEquals("tca", savedModel.getPolicyType()); - } - -} diff --git a/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java b/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java index 9b83e7216..7c520a252 100644 --- a/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java @@ -45,7 +45,7 @@ import org.springframework.test.util.ReflectionTestUtils; */ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller") +@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller-new") public class SdcControllersConfigurationItCase { @Autowired @@ -60,7 +60,7 @@ public class SdcControllersConfigurationItCase { public void testGetAllDefinedControllers() throws IOException { loadFile("classpath:/clds/sdc-controllers-config.json"); Map mapResult = sdcControllersConfiguration - .getAllDefinedControllers(); + .getAllDefinedControllers(); assertTrue(mapResult.size() == 2); assertEquals("sdc-controller1", mapResult.get("sdc-controller1").getSdcControllerName()); assertEquals("sdc-controller2", mapResult.get("sdc-controller2").getSdcControllerName()); @@ -69,10 +69,10 @@ public class SdcControllersConfigurationItCase { @Test public void testGetSdcSingleControllerConfiguration() throws IOException { loadFile("classpath:/clds/sdc-controllers-config.json"); - assertEquals("sdc-controller1", - sdcControllersConfiguration.getSdcSingleControllerConfiguration("sdc-controller1").getSdcControllerName()); - assertEquals("sdc-controller2", - sdcControllersConfiguration.getSdcSingleControllerConfiguration("sdc-controller2").getSdcControllerName()); + assertEquals("sdc-controller1", sdcControllersConfiguration + .getSdcSingleControllerConfiguration("sdc-controller1").getSdcControllerName()); + assertEquals("sdc-controller2", sdcControllersConfiguration + .getSdcSingleControllerConfiguration("sdc-controller2").getSdcControllerName()); } @Test(expected = JsonSyntaxException.class) diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java index 0f0ecaedc..695b85166 100644 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java @@ -27,11 +27,13 @@ package org.onap.clamp.clds.it.sdc.controller; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; + import org.assertj.core.api.Assertions; import org.junit.Before; import org.junit.Test; @@ -104,45 +106,48 @@ public class SdcSingleControllerItCase { */ @Before public void init() { - sdcSingleController = new SdcSingleController(clampProp, csarInstaller, - SdcSingleControllerConfigurationTest.loadControllerConfiguration("clds/sdc-controller-config-TLS.json", - "sdc-controller1"), - null) { + sdcSingleController = new SdcSingleController(clampProp, csarInstaller, SdcSingleControllerConfigurationTest + .loadControllerConfiguration("clds/sdc-controller-config-TLS.json", "sdc-controller1"), null) { }; } @Test public void testTreatNotification() { - //when + // when sdcSingleController.treatNotification(buildFakeSdcNotification()); - //then + // then Assertions.assertThat(sdcSingleController.getNbOfNotificationsOngoing()).isEqualTo(0); } @Test public void testCloseSdc() throws SdcControllerException { - //when + // when sdcSingleController.closeSdc(); - //then + // then assertThat(sdcSingleController.getControllerStatus()).isEqualTo(SdcSingleControllerStatus.STOPPED); } @Test - public void testActivateCallback() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException, ClassNotFoundException { - //given - MDCAdapter mdcAdapter = MDC.getMDCAdapter(); - Class innerClass = Class.forName("org.onap.clamp.clds.sdc.controller.SdcSingleController$SdcNotificationCallBack"); - Constructor constructor = innerClass.getDeclaredConstructor(SdcSingleController.class, SdcSingleController.class); + public void testActivateCallback() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, + InstantiationException, ClassNotFoundException { + // given + + Class innerClass = Class + .forName("org.onap.clamp.clds.sdc.controller.SdcSingleController$SdcNotificationCallBack"); + Constructor constructor = innerClass.getDeclaredConstructor(SdcSingleController.class, + SdcSingleController.class); constructor.setAccessible(true); - Object child = constructor.newInstance(sdcSingleController,sdcSingleController); - Method method = child.getClass().getDeclaredMethod("activateCallback",INotificationData.class); + Object child = constructor.newInstance(sdcSingleController, sdcSingleController); + Method method = child.getClass().getDeclaredMethod("activateCallback", INotificationData.class); method.setAccessible(true); - //when - method.invoke(child,buildFakeSdcNotification()); - //then + MDCAdapter mdcAdapter = MDC.getMDCAdapter(); + // when + method.invoke(child, buildFakeSdcNotification()); + // then assertThat(mdcAdapter.get("ResponseCode")).isEqualTo("0"); assertThat(mdcAdapter.get("StatusCode")).isEqualTo("COMPLETE"); - assertThat(mdcAdapter.get("ResponseDescription")).isEqualTo("SDC Notification received and processed successfully"); + assertThat(mdcAdapter.get("ResponseDescription")) + .isEqualTo("SDC Notification received and processed successfully"); assertThat(mdcAdapter.get("ClassName")).isEqualTo(child.getClass().getName()); } } diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java deleted file mode 100644 index e1b963cc4..000000000 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java +++ /dev/null @@ -1,214 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications copyright (c) 2019 Nokia - * =================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.it.sdc.controller.installer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.RandomStringUtils; -import org.json.JSONException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.exception.policy.PolicyModelException; -import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; -import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; -import org.onap.clamp.clds.model.CldsModel; -import org.onap.clamp.clds.model.CldsTemplate; -import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact; -import org.onap.clamp.clds.sdc.controller.installer.CsarHandler; -import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller; -import org.onap.clamp.clds.sdc.controller.installer.CsarInstallerImpl; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.onap.sdc.api.notification.INotificationData; -import org.onap.sdc.api.notification.IResourceInstance; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.onap.sdc.toscaparser.api.elements.Metadata; -import org.skyscreamer.jsonassert.JSONAssert; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller") -public class CsarInstallerItCase { - - private static final String INVARIANT_SERVICE_UUID = "4cc5b45a-1f63-4194-8100-cd8e14248c92"; - private static final String INVARIANT_RESOURCE1_UUID = "07e266fc-49ab-4cd7-8378-ca4676f1b9ec"; - private static final String INVARIANT_RESOURCE2_UUID = "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad"; - private static final String RESOURCE_INSTANCE_NAME_RESOURCE1 = "ResourceInstanceName1"; - private static final String RESOURCE_INSTANCE_NAME_RESOURCE2 = "ResourceInstanceName2"; - - @Autowired - @Qualifier("oldModelInstaller") - private CsarInstaller csarInstaller; - - @Autowired - private CldsDao cldsDao; - - @Test(expected = SdcArtifactInstallerException.class) - public void testInstallTheCsarFail() throws SdcArtifactInstallerException, SdcToscaParserException, - CsarHandlerException, IOException, InterruptedException, PolicyModelException { - CsarHandler csarHandler = Mockito.mock(CsarHandler.class); - BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); - Mockito.when(blueprintArtifact.getResourceAttached()).thenReturn(Mockito.mock(IResourceInstance.class)); - Map blueprintMap = new HashMap<>(); - blueprintMap.put("resourceid", blueprintArtifact); - Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); - Mockito.when(blueprintArtifact.getDcaeBlueprint()).thenReturn( - IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/not-recognized.yaml"), - StandardCharsets.UTF_8)); - csarInstaller.installTheCsar(csarHandler); - fail("Should have raised an SdcArtifactInstallerException"); - } - - private BlueprintArtifact buildFakeBuildprintArtifact(String instanceName, String invariantResourceUuid, - String blueprintFilePath, String artifactName, String invariantServiceUuid) throws IOException { - IResourceInstance resource = Mockito.mock(IResourceInstance.class); - Mockito.when(resource.getResourceInstanceName()).thenReturn(instanceName); - Mockito.when(resource.getResourceInvariantUUID()).thenReturn(invariantResourceUuid); - BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); - Mockito.when(blueprintArtifact.getDcaeBlueprint()) - .thenReturn(ResourceFileUtil.getResourceAsString(blueprintFilePath)); - Mockito.when(blueprintArtifact.getBlueprintArtifactName()).thenReturn(artifactName); - Mockito.when(blueprintArtifact.getBlueprintInvariantServiceUuid()).thenReturn(invariantServiceUuid); - Mockito.when(blueprintArtifact.getResourceAttached()).thenReturn(resource); - return blueprintArtifact; - } - - private CsarHandler buildFakeCsarHandler(String generatedName) throws IOException { - // Create fake notification - INotificationData notificationData = Mockito.mock(INotificationData.class); - Mockito.when(notificationData.getServiceVersion()).thenReturn("1.0"); - // Create fake resource in notification - CsarHandler csarHandler = Mockito.mock(CsarHandler.class); - List listResources = new ArrayList<>(); - Mockito.when(notificationData.getResources()).thenReturn(listResources); - Map blueprintMap = new HashMap<>(); - Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); - // Create fake blueprint artifact 1 on resource1 - BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, - INVARIANT_RESOURCE1_UUID, "example/sdc/blueprint-dcae/tca.yaml", "tca.yaml", INVARIANT_SERVICE_UUID); - listResources.add(blueprintArtifact.getResourceAttached()); - blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); - // Create fake blueprint artifact 2 on resource2 - blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE2, INVARIANT_RESOURCE2_UUID, - "example/sdc/blueprint-dcae/tca_2.yaml", "tca_2.yaml", INVARIANT_SERVICE_UUID); - listResources.add(blueprintArtifact.getResourceAttached()); - blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); - - // Create fake blueprint artifact 3 on resource 1 so that it's possible to - // test multiple CL deployment per Service/vnf - blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, INVARIANT_RESOURCE1_UUID, - "example/sdc/blueprint-dcae/tca_3.yaml", "tca_3.yaml", INVARIANT_SERVICE_UUID); - blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); - - // Build fake csarhandler - Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData); - // Build fake csar Helper - ISdcCsarHelper csarHelper = Mockito.mock(ISdcCsarHelper.class); - Metadata data = Mockito.mock(Metadata.class); - Mockito.when(data.getValue("name")).thenReturn(generatedName); - Mockito.when(csarHelper.getServiceMetadata()).thenReturn(data); - Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper); - return csarHandler; - } - - @Test - public void testIsCsarAlreadyDeployedTca() throws SdcArtifactInstallerException, SdcToscaParserException, - CsarHandlerException, IOException, InterruptedException, PolicyModelException { - String generatedName = RandomStringUtils.randomAlphanumeric(5); - CsarHandler csarHandler = buildFakeCsarHandler(generatedName); - assertFalse(csarInstaller.isCsarAlreadyDeployed(csarHandler)); - csarInstaller.installTheCsar(csarHandler); - assertTrue(csarInstaller.isCsarAlreadyDeployed(csarHandler)); - } - - @Test - public void testInstallTheCsarTca() throws SdcArtifactInstallerException, SdcToscaParserException, - CsarHandlerException, IOException, JSONException, InterruptedException, PolicyModelException { - String generatedName = RandomStringUtils.randomAlphanumeric(5); - CsarHandler csar = buildFakeCsarHandler(generatedName); - csarInstaller.installTheCsar(csar); - CldsModel cldsModel1 = verifyClosedLoopModelLoadedInDb(csar, "tca.yaml"); - JSONAssert.assertEquals( - IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json"), - StandardCharsets.UTF_8), - cldsModel1.getPropText(), true); - CldsModel cldsModel2 = verifyClosedLoopModelLoadedInDb(csar, "tca_2.yaml"); - JSONAssert.assertEquals(IOUtils.toString( - ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-2.json"), - StandardCharsets.UTF_8), cldsModel2.getPropText(), true); - CldsModel cldsModel3 = verifyClosedLoopModelLoadedInDb(csar, "tca_3.yaml"); - JSONAssert.assertEquals(IOUtils.toString( - ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-3.json"), - StandardCharsets.UTF_8), cldsModel3.getPropText(), true); - } - - private CldsModel verifyClosedLoopModelLoadedInDb(CsarHandler csar, String artifactName) - throws SdcArtifactInstallerException { - - // Get the template back from DB - CldsTemplate templateFromDb = CldsTemplate.retrieve(cldsDao, CsarInstallerImpl.TEMPLATE_NAME_PREFIX - + CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), false); - assertNotNull(templateFromDb); - assertNotNull(templateFromDb.getBpmnText()); - assertNotNull(templateFromDb.getImageText()); - assertNotNull(templateFromDb.getPropText()); - assertTrue(templateFromDb.getPropText().contains("global") - && templateFromDb.getPropText().contains("node_templates:")); - assertEquals(templateFromDb.getName(), CsarInstallerImpl.TEMPLATE_NAME_PREFIX - + CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName))); - // Get the Model back from DB - CldsModel modelFromDb = CldsModel.retrieve(cldsDao, - CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), true); - assertNotNull(modelFromDb); - assertNotNull(modelFromDb.getBpmnText()); - assertNotNull(modelFromDb.getImageText()); - assertNotNull(modelFromDb.getPropText()); - assertTrue(modelFromDb.getPropText().contains("policy_id")); - assertEquals(CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), - modelFromDb.getName()); - assertEquals(CsarInstallerImpl.CONTROL_NAME_PREFIX, modelFromDb.getControlNamePrefix()); - return modelFromDb; - } -} diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/LoopCsarInstallerTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/LoopCsarInstallerTest.java deleted file mode 100644 index e462455fd..000000000 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/LoopCsarInstallerTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * * Modifications copyright (c) 2019 Nokia - * =================================================================== - * - */ - -package org.onap.clamp.clds.sdc.controller.installer; - -import com.google.gson.JsonObject; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.commons.io.IOUtils; -import org.assertj.core.api.Assertions; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.clamp.clds.client.DcaeInventoryServices; -import org.onap.clamp.clds.config.sdc.BlueprintParserFilesConfiguration; -import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; -import org.onap.clamp.clds.service.CldsService; -import org.onap.clamp.clds.service.CldsTemplateService; -import org.onap.clamp.clds.transform.XslTransformer; -import org.onap.clamp.clds.util.JsonUtils; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.onap.sdc.api.notification.INotificationData; -import org.onap.sdc.api.notification.IResourceInstance; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.elements.Metadata; -import org.springframework.context.ApplicationContext; -import org.springframework.core.io.Resource; - -@RunWith(MockitoJUnitRunner.class) -public class LoopCsarInstallerTest { - - @Mock - private CsarHandler csarHandler; - - @Mock - private ApplicationContext applicationContext; - - @Mock - private DcaeInventoryServices dcaeInventoryServices; - - @Mock - private IResourceInstance resourceInstance; - - @Mock - private CldsService cldsService; - - @Mock - private INotificationData notificationData; - - @Mock - private Metadata metadata; - - @Mock - private ISdcCsarHelper sdcCsarHelper; - - private CsarInstallerImpl csarInstaller; - private BlueprintArtifact artifact; - - /** - * Set up method. throws: Exception - */ - @Before - public void setUp() throws Exception { - String dceaBlueprint = ResourceFileUtil.getResourceAsString("tosca/dcea_blueprint.yml"); - artifact = prepareBlueprintArtifact(dceaBlueprint); - csarInstaller = new CsarInstallerImpl(applicationContext, null, new CldsTemplateService(), cldsService, - dcaeInventoryServices, new XslTransformer()); - } - - @Test - public void shouldReturnInputParametersFromBlueprint() { - // given - String expectedBlueprintInputsText = "{\"aaiEnrichmentHost\":\"aai.onap.svc.cluster.local\"" - + ",\"aaiEnrichmentPort\":\"8443\"" + ",\"enableAAIEnrichment\":true" + ",\"dmaap_host\":\"message-router\"" - + ",\"dmaap_port\":\"3904\"" + ",\"enableRedisCaching\":false" + ",\"redisHosts\":\"dcae-redis:6379\"" - + ",\"tag_version\":" - + "\"nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.1.0\"" - + ",\"consul_host\":\"consul-server\"" + ",\"consul_port\":\"8500\",\"cbs_host\":\"{\\\"test\\\":" - + "{\\\"test\\\":\\\"test\\\"}}\",\"cbs_port\":\"10000\"" - + ",\"external_port\":\"32010\",\"policy_id\":\"AUTO_GENERATED_POLICY_ID_AT_SUBMIT\"}"; - - JsonObject expectedBlueprintInputs = JsonUtils.GSON.fromJson(expectedBlueprintInputsText, JsonObject.class); - // when - String parametersInJson = csarInstaller.getAllBlueprintParametersInJson(artifact); - // then - Assertions.assertThat(JsonUtils.GSON.fromJson(parametersInJson, JsonObject.class)) - .isEqualTo(expectedBlueprintInputs); - } - - @Test - public void shouldReturnBuildModelName() throws SdcArtifactInstallerException { - // given - String expectedModelName = "CLAMP_test_name_" + "vtest_service_version_" + "test_resource_instance_name_" - + "test_artifact_name"; - prepareMockCsarHandler("name", "test_name", "test_service_version"); - Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn("test_resource_instance_name"); - // when - String actualModelName = CsarInstallerImpl.buildModelName(csarHandler, artifact); - // then - Assertions.assertThat(actualModelName).isEqualTo(expectedModelName); - } - - @Test - public void shouldReturnRightMapping() throws SdcArtifactInstallerException, IOException { - // given - String input = "[{\"blueprintKey\":\"tca_k8s\"," + "\"dcaeDeployable\":false," - + "\"files\":{\"svgXmlFilePath\":\"samplePath\",\"bpmnXmlFilePath\":\"samplePath\"}}]"; - BlueprintParserFilesConfiguration filesConfiguration = new BlueprintParserFilesConfiguration(); - filesConfiguration.setBpmnXmlFilePath("samplePath"); - filesConfiguration.setSvgXmlFilePath("samplePath"); - Resource resource = Mockito.mock(Resource.class); - InputStream inputStream = IOUtils.toInputStream(input, "UTF-8"); - Mockito.when(applicationContext.getResource(Mockito.any(String.class))).thenReturn(resource); - Mockito.when(resource.getInputStream()).thenReturn(inputStream); - csarInstaller.loadConfiguration(); - // when - BlueprintParserFilesConfiguration configuration = csarInstaller.searchForRightMapping(artifact); - - // then - Assertions.assertThat(configuration.getBpmnXmlFilePath()).isEqualTo("samplePath"); - Assertions.assertThat(configuration.getSvgXmlFilePath()).isEqualTo("samplePath"); - } - - private BlueprintArtifact prepareBlueprintArtifact(String dceaBlueprint) { - artifact = new BlueprintArtifact(); - artifact.setBlueprintArtifactName("test_artifact_name"); - artifact.setBlueprintInvariantServiceUuid("test_inv_uuid"); - artifact.setResourceAttached(resourceInstance); - artifact.setDcaeBlueprint(dceaBlueprint); - return artifact; - } - - private void prepareMockCsarHandler(String metadataNameMockInput, String metadataNameMockOutput, - String serviceVersion) { - Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(sdcCsarHelper); - Mockito.when(sdcCsarHelper.getServiceMetadata()).thenReturn(metadata); - Mockito.when(metadata.getValue(metadataNameMockInput)).thenReturn(metadataNameMockOutput); - Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData); - Mockito.when(notificationData.getServiceVersion()).thenReturn(serviceVersion); - } -} \ No newline at end of file -- cgit 1.2.3-korg