diff options
Diffstat (limited to 'adapters')
75 files changed, 2520 insertions, 1420 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java index 75a8ca0593..16639d9166 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java @@ -127,12 +127,9 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { // Properties names and variables (with default values) protected String createPollIntervalProp = "org.onap.so.adapters.po.pollInterval"; - private String deletePollIntervalProp = "org.onap.so.adapters.po.pollInterval"; - private String deletePollTimeoutProp = "org.onap.so.adapters.po.pollTimeout"; private String pollingMultiplierProp = "org.onap.so.adapters.po.pollMultiplier"; protected static final String CREATE_POLL_INTERVAL_DEFAULT = "15"; - private static final String DELETE_POLL_INTERVAL_DEFAULT = "15"; private static final String POLLING_MULTIPLIER_DEFAULT = "60"; private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); @@ -177,7 +174,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception. */ - @SuppressWarnings("unchecked") public StackInfo createStack(String cloudSiteId, String cloudOwner, String tenantId, String stackName, VduModelInfo vduModel, String heatTemplate, Map<String, ?> stackInputs, boolean pollForCompletion, int timeoutMinutes, String environment, Map<String, Object> nestedTemplates, Map<String, Object> heatFiles, @@ -848,7 +844,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { * Boolean if any of the conversions should fail, we will default to adding it to the inputs as a string - see if * Openstack can handle it. Also, will remove any params that are extra. Any aliases will be converted to their * appropriate name (anyone use this feature?) - * + * * @param inputs - the Map<String, String> of the inputs received on the request * @param template the HeatTemplate object - this is so we can also verify if the param is valid for this template * @return HashMap<String, Object> of the inputs, cleaned and converted diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/DeleteVfModuleRequest.java b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/DeleteVfModuleRequest.java index 6a979d754b..7e10bb3801 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/DeleteVfModuleRequest.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/DeleteVfModuleRequest.java @@ -7,9 +7,9 @@ * 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. @@ -30,7 +30,7 @@ import com.fasterxml.jackson.annotation.JsonRootName; @XmlRootElement(name = "deleteVfModuleRequest") public class DeleteVfModuleRequest extends VfRequestCommon implements Serializable { /** - * + * */ private static final long serialVersionUID = -8504083539107392561L; private String cloudSiteId; @@ -39,6 +39,7 @@ public class DeleteVfModuleRequest extends VfRequestCommon implements Serializab private String vnfId; private String vfModuleId; private String vfModuleStackId; + private String modelCustomizationUuid; private MsoRequest msoRequest = new MsoRequest(); @@ -94,6 +95,14 @@ public class DeleteVfModuleRequest extends VfRequestCommon implements Serializab this.vfModuleStackId = vfModuleStackId; } + public String getModelCustomizationUuid() { + return modelCustomizationUuid; + } + + public void setModelCustomizationUuid(String modelCustomizationUuid) { + this.modelCustomizationUuid = modelCustomizationUuid; + } + public MsoRequest getMsoRequest() { return msoRequest; } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBApplication.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBApplication.java index e5b51f72c9..1ad4238ade 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBApplication.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBApplication.java @@ -28,7 +28,8 @@ import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication(scanBasePackages = {"org.onap.so.adapters.catalogdb", "org.onap.so.db.catalog.client", "org.onap.so.logging.jaxrs.filter", "org.onap.so.logging.spring.interceptor", "org.onap.so.client", - "org.onap.so.configuration", "org.onap.so.db", "org.onap.logging.filter", "org.onap.so.logger"}) + "org.onap.so.configuration", "org.onap.so.db", "org.onap.logging.filter", + "org.onap.so.logger, org.onap.so.security"}) @EnableJpaRepositories("org.onap.so.db.catalog.data.repository") @EntityScan("org.onap.so.db.catalog.beans") @EnableScheduling diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/SoCadiFilter.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/SoCadiFilter.java deleted file mode 100644 index e7e360d444..0000000000 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/SoCadiFilter.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP SO - * ================================================================================ - * 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.so.adapters.catalogdb; - -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import org.onap.aaf.cadi.config.Config; -import org.onap.aaf.cadi.filter.CadiFilter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile("aaf") -public class SoCadiFilter extends CadiFilter { - - protected final Logger logger = LoggerFactory.getLogger(SoCadiFilter.class); - - private static String AFT_ENVIRONMENT_VAR = "AFT_ENVIRONMENT"; - private static String AAF_API_VERSION = "aaf_api_version"; - - @Value("${mso.config.cadi.cadiLoglevel:#{null}}") - private String cadiLoglevel; - - @Value("${mso.config.cadi.cadiKeyFile:#{null}}") - private String cadiKeyFile; - - @Value("${mso.config.cadi.cadiTruststorePassword:#{null}}") - private String cadiTrustStorePassword; - - @Value("${mso.config.cadi.cadiTrustStore:#{null}}") - private String cadiTrustStore; - - @Value("${mso.config.cadi.cadiLatitude:#{null}}") - private String cadiLatitude; - - @Value("${mso.config.cadi.cadiLongitude:#{null}}") - private String cadiLongitude; - - @Value("${mso.config.cadi.aafEnv:#{null}}") - private String aafEnv; - - @Value("${mso.config.cadi.aafApiVersion:#{null}}") - private String aafApiVersion; - - @Value("${mso.config.cadi.aafRootNs:#{null}}") - private String aafRootNs; - - @Value("${mso.config.cadi.aafId:#{null}}") - private String aafMechId; - - @Value("${mso.config.cadi.aafPassword:#{null}}") - private String aafMechIdPassword; - - @Value("${mso.config.cadi.aafLocateUrl:#{null}}") - private String aafLocateUrl; - - @Value("${mso.config.cadi.aafUrl:#{null}}") - private String aafUrl; - - @Value("${mso.config.cadi.apiEnforcement:#{null}}") - private String apiEnforcement; - - private void checkIfNullProperty(String key, String value) { - /* - * When value is null, it is not defined in application.yaml set nothing in System properties - */ - if (value != null) { - System.setProperty(key, value); - } - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - checkIfNullProperty(Config.CADI_LOGLEVEL, cadiLoglevel); - checkIfNullProperty(Config.CADI_KEYFILE, cadiKeyFile); - checkIfNullProperty(Config.CADI_TRUSTSTORE, cadiTrustStore); - checkIfNullProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadiTrustStorePassword); - checkIfNullProperty(Config.CADI_LATITUDE, cadiLatitude); - checkIfNullProperty(Config.CADI_LONGITUDE, cadiLongitude); - checkIfNullProperty(Config.AAF_ENV, aafEnv); - checkIfNullProperty(Config.AAF_API_VERSION, aafApiVersion); - checkIfNullProperty(Config.AAF_ROOT_NS, aafRootNs); - checkIfNullProperty(Config.AAF_APPID, aafMechId); - checkIfNullProperty(Config.AAF_APPPASS, aafMechIdPassword); - checkIfNullProperty(Config.AAF_LOCATE_URL, aafLocateUrl); - checkIfNullProperty(Config.AAF_URL, aafUrl); - checkIfNullProperty(Config.CADI_API_ENFORCEMENT, apiEnforcement); - // checkIfNullProperty(AFT_ENVIRONMENT_VAR, aftEnv); - logger.debug(" *** init Filter Config *** "); - super.init(filterConfig); - } - - -} diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebSecurityConfigImpl.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebSecurityConfigImpl.java deleted file mode 100644 index 8cadb00f8f..0000000000 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebSecurityConfigImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (C) 2018 IBM. - * ================================================================================ - * 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.so.adapters.catalogdb; - -import org.onap.so.security.MSOSpringFirewall; -import org.onap.so.security.WebSecurityConfig; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.builders.WebSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.web.firewall.StrictHttpFirewall; -import org.springframework.util.StringUtils; - -@Configuration -@EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfig { - - @Profile({"basic", "test"}) - @Bean - public WebSecurityConfigurerAdapter basicAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll() - .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")).and() - .httpBasic(); - } - - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); - StrictHttpFirewall firewall = new MSOSpringFirewall(); - web.httpFirewall(firewall); - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(WebSecurityConfigImpl.this.userDetailsService()) - .passwordEncoder(WebSecurityConfigImpl.this.passwordEncoder()); - } - - }; - } - - @Profile("aaf") - @Bean - public WebSecurityConfigurerAdapter noAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().anyRequest().permitAll(); - } - }; - } - -} diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java index edec48dc95..a98778bf5d 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java @@ -21,6 +21,7 @@ package org.onap.so.adapters.catalogdb.catalogrest; +import java.io.IOException; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -95,4 +96,17 @@ public abstract class CatalogQuery { return smartToJSON(); } + + protected boolean isJSONValid(String jsonInString) { + try { + if (jsonInString == null) { + return false; + } + ObjectMapper mapper = new ObjectMapper(); + mapper.readValue(jsonInString, String.class); + return true; + } catch (IOException e) { + return false; + } + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java index c1acc319f7..afcb2d5761 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java @@ -123,7 +123,10 @@ public class QueryAllottedResourceCustomization extends CatalogQuery { put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID", o.getProvidingServiceModelInvariantUUID()); put(valueMap, "PROVIDING_SERVICE_MODEL_UUID", o.getProvidingServiceModelUUID()); put(valueMap, "PROVIDING_SERVICE_MODEL_NAME", o.getProvidingServiceModelName()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + + if (isJSONValid(o.getResourceInput())) { + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + } sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); sep = ",\n"; diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java index 5573b23a8d..129718241c 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java @@ -116,7 +116,10 @@ public class QueryServiceNetworks extends CatalogQuery { put(valueMap, "NETWORK_ROLE", o.getNetworkRole()); put(valueMap, "NETWORK_SCOPE", o.getNetworkScope()); put(valueMap, "NETWORK_TECHNOLOGY", o.getNetworkTechnology()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + + if (isJSONValid(o.getResourceInput())) { + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + } sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); sep = ",\n"; diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java index 0b8de60a81..d6e7415a77 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java @@ -23,6 +23,7 @@ package org.onap.so.adapters.catalogdb.catalogrest; /* should be called QueryVnfResource.java */ +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -32,6 +33,7 @@ import org.onap.so.db.catalog.beans.VnfResourceCustomization; import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.databind.ObjectMapper; @XmlRootElement(name = "serviceVnfs") public class QueryServiceVnfs extends CatalogQuery { @@ -120,7 +122,9 @@ public class QueryServiceVnfs extends CatalogQuery { put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode()); put(valueMap, "VNFC_INSTANCE_GROUP_ORDER", o.getVnfcInstanceGroupOrder()); put(valueMap, "MULTI_STEP_DESIGN", o.getMultiStageDesign()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + if (isJSONValid(o.getResourceInput())) { + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + } String subitem = new QueryVfModule(vrNull ? null : o.getVfModuleCustomizations()).JSON2(true, true); valueMap.put("_VFMODULES_", subitem.replaceAll("(?m)^", "\t\t")); @@ -142,4 +146,5 @@ public class QueryServiceVnfs extends CatalogQuery { sb.append("}"); return sb.toString(); } + } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java index dc73fe904d..24c07d6d3e 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java @@ -20,12 +20,12 @@ package org.onap.so.adapters.catalogdb.catalogrest; -import org.onap.so.db.catalog.beans.VnfcCustomization; -import javax.xml.bind.annotation.XmlRootElement; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.xml.bind.annotation.XmlRootElement; +import org.onap.so.db.catalog.beans.VnfcCustomization; @XmlRootElement(name = "vnfcs") public class QueryVnfcs extends CatalogQuery { @@ -105,8 +105,10 @@ public class QueryVnfcs extends CatalogQuery { put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantUUID()); put(valueMap, "MODEL_VERSION", o.getModelVersion()); put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + if (isJSONValid(o.getResourceInput())) { + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + } sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); sep = ",\n"; } diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql index 9527986f52..f5c7cd65c2 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql @@ -29,7 +29,8 @@ INSERT INTO northbound_request_ref_lookup(MACRO_ACTION, ACTION, REQUEST_SCOPE, I ('VFModule-Replace-Retain-Assignments', 'replaceInstanceRetainAssignments', 'VfModule', true,true, '7','7', 'DEFAULT', '*'), ('NetworkCollection-Macro-Create', 'createInstance', 'NetworkCollection', false,true, '7','7', 'DEFAULT', '*'), ('NetworkCollection-Macro-Delete', 'deleteInstance', 'NetworkCollection', false,true, '7','7', 'DEFAULT', '*'), -('VFModule-ScaleOut', 'scaleOut', 'VfModule', true, true, '7','7', 'DEFAULT', '*'); +('VFModule-ScaleOut', 'scaleOut', 'VfModule', true, true, '7','7', 'DEFAULT', '*'), +('VNF-InPlaceUpdate', 'inPlaceSoftwareUpdate', 'Vnf', true, true, '7','7', 'DEFAULT', '*'); INSERT INTO orchestration_flow_reference(COMPOSITE_ACTION, SEQ_NO, FLOW_NAME, FLOW_VERSION, NB_REQ_REF_LOOKUP_ID) VALUES @@ -176,7 +177,26 @@ INSERT INTO orchestration_flow_reference(COMPOSITE_ACTION, SEQ_NO, FLOW_NAME, FL ('VFModule-Replace-Retain-Assignments', '10', 'CreateVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')), ('VFModule-Replace-Retain-Assignments', '11', 'ActivateVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')), ('VFModule-Replace-Retain-Assignments', '12', 'ChangeModelVnfBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')), -('VFModule-Replace-Retain-Assignments', '13', 'ChangeModelServiceInstanceBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')); +('VFModule-Replace-Retain-Assignments', '13', 'ChangeModelServiceInstanceBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '1', 'VNFCheckPserversLockedFlagActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '2', 'VNFCheckInMaintFlagActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '3', 'VNFSetInMaintFlagActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '4', 'VNFCheckClosedLoopDisabledFlagActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '5', 'VNFSetClosedLoopDisabledFlagActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '6', 'VNFLockActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '7', 'VNFUpgradePreCheckActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '8', 'VNFQuiesceTrafficActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '9', 'VNFStopActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '10', 'VNFSnapShotActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '11', 'VNFStartActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '12', 'VNFUpgradeBackupActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '13', 'VNFUpgradeSoftwareActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '14', 'VNFUpgradePostCheckActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '15', 'VNFResumeTrafficActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '16', 'VNFUnlockActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '17', 'VNFUnsetInMaintFlagActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')), +('VNF-InPlaceUpdate', '18', 'VNFUnsetClosedLoopDisabledFlagActivity', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VNF-InPlaceUpdate' and CLOUD_OWNER = 'DEFAULT')); + INSERT INTO rainy_day_handler_macro (FLOW_NAME, SERVICE_TYPE, VNF_TYPE, ERROR_CODE, WORK_STEP, POLICY) @@ -849,3 +869,7 @@ UPDATE rainy_day_handler_macro SET SERVICE_ROLE = '*' WHERE SERVICE_ROLE IS null INSERT INTO vnf_components_recipe (VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, VERSION, ORCHESTRATION_URI, RECIPE_TIMEOUT) VALUES (NULL, 'vfModule', 'replaceInstanceRetainAssignments', '1', '/mso/async/services/WorkflowActionBB', 180); + +UPDATE vnf_recipe +SET ORCHESTRATION_URI = '/mso/async/services/WorkflowActionBB' +WHERE NF_ROLE = 'GR-API-DEFAULT' AND ACTION = 'inPlaceSoftwareUpdate'; diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__WorkflowDesignerData.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__WorkflowDesignerData.sql index 137f73cf65..42df1adf13 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__WorkflowDesignerData.sql +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__WorkflowDesignerData.sql @@ -202,4 +202,6 @@ INSERT INTO `workflow` (`ARTIFACT_UUID`,`ARTIFACT_NAME`,`NAME`,`OPERATION_NAME`, VALUES ('9d45cd30-1a89-4993-87c1-6dd09c1696cf','VFModule-ScaleOut','VNF Scale Out','ScaleOut',1.0,'native static workflow to support ScaleOut','vfModule','native'), ('da6478e4-ea33-3346-ac12-ab121284a333','VnfInPlaceUpdate.bpmn','VnfInPlaceUpdate','inPlaceSoftwareUpdate',1.0,'native static workflow to support inPlaceSoftwareUpdate','vnf','native'), -('fdb3ac48-70f9-4584-bd92-253bdbdec1e1','VnfConfigUpdate.bpmn','VnfConfigUpdate','applyConfigModify',1.0,'native static workflow to support applyConfigModify','vnf','native'); +('fdb3ac48-70f9-4584-bd92-253bdbdec1e1','VnfConfigUpdate.bpmn','VnfConfigUpdate','applyConfigModify',1.0,'native static workflow to support applyConfigModify','vnf','native'), +('b2fd5627-55e4-4f4f-8064-9e6f443e9152','DummyPnfWorkflow','Dummy Pnf Workflow','DummyPnfWorkflow',1.0,'Dummy Pnf Workflow to test custom Pnf workflow','pnf','native'); + diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfTest.java new file mode 100644 index 0000000000..b71808b2c8 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfTest.java @@ -0,0 +1,36 @@ +package org.onap.so.adapters.catalogdb.catalogrest; + +import static org.junit.Assert.assertEquals; +import org.json.JSONException; +import org.junit.Test; + + +public class QueryServiceVnfTest extends QueryServiceVnfs { + + private QueryServiceVnfs queryServiceVnf = new QueryServiceVnfs(); + + private final String invalidJSON = + "\"{\\\\\\\"nf_function\\\\\\\":\\\\\\\"DO_STUFF\\\\\\\",\\\"_image_name\\\\\\\":\\\\\\\"test_image\\\""; + + private final String validJSON = "\"{\"nf_function\":\"DO_STUFF\",\"image_name\":\"test_image\"}"; + + @Test + public void test_IsValidJsonTrue() throws JSONException { + boolean isValidJson = queryServiceVnf.isJSONValid(validJSON); + assertEquals(true, isValidJson); + } + + @Test + public void test_IsValidJsonFalse() throws JSONException { + boolean isValidJson = queryServiceVnf.isJSONValid(invalidJSON); + assertEquals(false, isValidJson); + } + + @Test + public void test_IsValidJsonNull() throws JSONException { + boolean isValidJson = queryServiceVnf.isJSONValid(null); + assertEquals(false, isValidJson); + } + + +} diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java index 97c715b44e..ef04ee9c13 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java @@ -1017,7 +1017,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { // Retrieve the Network Resource definition NetworkResource networkResource = null; - if (commonUtils.isNullOrEmpty(modelCustomizationUuid)) { if (!commonUtils.isNullOrEmpty(networkType)) { networkResource = networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType); @@ -1030,10 +1029,18 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { } } + int timeoutMinutes = 118; String mode = ""; if (networkResource != null) { logger.debug(LOG_DEBUG_MSG, networkResource.toString()); mode = networkResource.getOrchestrationMode(); + networkResource.getHeatTemplate().getTimeoutMinutes(); + HeatTemplate heat = networkResource.getHeatTemplate(); + if (heat != null && heat.getTimeoutMinutes() != null) { + if (heat.getTimeoutMinutes() < 118) { + timeoutMinutes = heat.getTimeoutMinutes(); + } + } } if (NEUTRON_MODE.equals(mode)) { @@ -1048,7 +1055,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { } } else { try { - heat.deleteStack(tenantId, CLOUD_OWNER, cloudSiteId, networkId, true, 120); + heat.deleteStack(tenantId, CLOUD_OWNER, cloudSiteId, networkId, true, timeoutMinutes); networkDeleted.value = true; } catch (MsoException me) { me.addContext("DeleteNetwork"); @@ -1381,7 +1388,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { * make these optional + " ip_version: %ipversion%\n" + " enable_dhcp: %enabledhcp%\n" + * " gateway_ip: %gatewayip%\n" + " allocation_pools:\n" + " - start: %poolstart%\n" + * " end: %poolend%\n"; - * + * */ String outputTempl = " subnet_id_%subnetId%:\n" + " description: Openstack subnet identifier\n" diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/SoCadiFilter.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/SoCadiFilter.java deleted file mode 100644 index d9901b75ed..0000000000 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/SoCadiFilter.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP SO - * ================================================================================ - * 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.so.adapters.openstack; - -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import org.onap.aaf.cadi.config.Config; -import org.onap.aaf.cadi.filter.CadiFilter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile("aaf") -public class SoCadiFilter extends CadiFilter { - - protected final Logger logger = LoggerFactory.getLogger(SoCadiFilter.class); - - private static String AFT_ENVIRONMENT_VAR = "AFT_ENVIRONMENT"; - private static String AAF_API_VERSION = "aaf_api_version"; - - @Value("${mso.config.cadi.cadiLoglevel:#{null}}") - private String cadiLoglevel; - - @Value("${mso.config.cadi.cadiKeyFile:#{null}}") - private String cadiKeyFile; - - @Value("${mso.config.cadi.cadiTruststorePassword:#{null}}") - private String cadiTrustStorePassword; - - @Value("${mso.config.cadi.cadiTrustStore:#{null}}") - private String cadiTrustStore; - - @Value("${mso.config.cadi.cadiLatitude:#{null}}") - private String cadiLatitude; - - @Value("${mso.config.cadi.cadiLongitude:#{null}}") - private String cadiLongitude; - - @Value("${mso.config.cadi.aafEnv:#{null}}") - private String aafEnv; - - @Value("${mso.config.cadi.aafApiVersion:#{null}}") - private String aafApiVersion; - - @Value("${mso.config.cadi.aafRootNs:#{null}}") - private String aafRootNs; - - @Value("${mso.config.cadi.aafId:#{null}}") - private String aafMechId; - - @Value("${mso.config.cadi.aafPassword:#{null}}") - private String aafMechIdPassword; - - @Value("${mso.config.cadi.aafLocateUrl:#{null}}") - private String aafLocateUrl; - - @Value("${mso.config.cadi.aafUrl:#{null}}") - private String aafUrl; - - @Value("${mso.config.cadi.apiEnforcement:#{null}}") - private String apiEnforcement; - - private void checkIfNullProperty(String key, String value) { - /* - * When value is null, it is not defined in application.yaml set nothing in System properties - */ - if (value != null) { - System.setProperty(key, value); - } - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - checkIfNullProperty(Config.CADI_LOGLEVEL, cadiLoglevel); - checkIfNullProperty(Config.CADI_KEYFILE, cadiKeyFile); - checkIfNullProperty(Config.CADI_TRUSTSTORE, cadiTrustStore); - checkIfNullProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadiTrustStorePassword); - checkIfNullProperty(Config.CADI_LATITUDE, cadiLatitude); - checkIfNullProperty(Config.CADI_LONGITUDE, cadiLongitude); - checkIfNullProperty(Config.AAF_ENV, aafEnv); - checkIfNullProperty(Config.AAF_API_VERSION, aafApiVersion); - checkIfNullProperty(Config.AAF_ROOT_NS, aafRootNs); - checkIfNullProperty(Config.AAF_APPID, aafMechId); - checkIfNullProperty(Config.AAF_APPPASS, aafMechIdPassword); - checkIfNullProperty(Config.AAF_LOCATE_URL, aafLocateUrl); - checkIfNullProperty(Config.AAF_URL, aafUrl); - checkIfNullProperty(Config.CADI_API_ENFORCEMENT, apiEnforcement); - // checkIfNullProperty(AFT_ENVIRONMENT_VAR, aftEnv); - logger.debug(" *** init Filter Config *** "); - super.init(filterConfig); - } - - -} diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/WebSecurityConfigImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/WebSecurityConfigImpl.java deleted file mode 100644 index ddae887103..0000000000 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/WebSecurityConfigImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (C) 2018 IBM. - * ================================================================================ - * 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.so.adapters.openstack; - -import org.onap.so.security.MSOSpringFirewall; -import org.onap.so.security.WebSecurityConfig; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.builders.WebSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.web.firewall.StrictHttpFirewall; -import org.springframework.util.StringUtils; - -@Configuration -@EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfig { - - @Profile({"basic", "test"}) - @Bean - public WebSecurityConfigurerAdapter basicAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll() - .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")).and() - .httpBasic(); - } - - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); - StrictHttpFirewall firewall = new MSOSpringFirewall(); - web.httpFirewall(firewall); - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(WebSecurityConfigImpl.this.userDetailsService()) - .passwordEncoder(WebSecurityConfigImpl.this.passwordEncoder()); - } - - }; - } - - @Profile("aaf") - @Bean - public WebSecurityConfigurerAdapter noAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests().anyRequest().permitAll(); - } - }; - } - -} diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java index 39a380d2cf..0074dca03c 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java @@ -123,6 +123,7 @@ public interface MsoVnfAdapter { @WebParam(name = "vfName") @XmlElement(required = true) String vfName, @WebParam(name = "vnfId") @XmlElement(required = true) String vnfId, @WebParam(name = "vfModuleId") @XmlElement(required = true) String vfModuleId, + @WebParam(name = "modelCustomizationUuid") @XmlElement(required = false) String modelCustomizationUuid, @WebParam(name = "request") MsoRequest msoRequest, @WebParam(name = "vfModuleOutputs", mode = Mode.OUT) Holder<Map<String, String>> vfModuleOutputs) throws VnfException; diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java index fcb2d7c2bb..4b908004df 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java @@ -1137,7 +1137,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { @Override public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, String vnfId, - String vfModuleId, MsoRequest msoRequest, Holder<Map<String, String>> outputs) throws VnfException { + String vfModuleId, String modelCustomizationUuid, MsoRequest msoRequest, + Holder<Map<String, String>> outputs) throws VnfException { Map<String, Object> stackOutputs; try { stackOutputs = msoHeatUtils.queryStackForOutputs(cloudSiteId, cloudOwner, tenantId, vnfName); @@ -1166,8 +1167,32 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { msoRequest, failRequestOnValetFailure); } + int timeoutMinutes = 118; + VfModule vf = null; + VfModuleCustomization vfmc = null; + if (modelCustomizationUuid != null) { + vfmc = vfModuleCustomRepo.findFirstByModelCustomizationUUIDOrderByCreatedDesc(modelCustomizationUuid); + if (vfmc != null) { + vf = vfmc.getVfModule(); + } + if (vf != null) { + logger.trace("Found vfModuleCust entry {}", vfmc.toString()); + HeatTemplate heat = vf.getModuleHeatTemplate(); + if (heat != null && heat.getTimeoutMinutes() != null) { + if (heat.getTimeoutMinutes() < 118) { + timeoutMinutes = heat.getTimeoutMinutes(); + } + } + + } else { + logger.debug( + "Unable to find vfModuleCust with modelCustomizationUuid={} . Using default timeout for polling", + modelCustomizationUuid); + } + } + try { - msoHeatUtils.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfName, true, 118); + msoHeatUtils.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfName, true, timeoutMinutes); } catch (MsoException me) { me.addContext(DELETE_VNF); // Failed to query the Stack due to an openstack exception. diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java index d35c34a937..abaf881ba5 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java @@ -1082,7 +1082,8 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { } public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, String vnfId, - String vfModuleId, MsoRequest msoRequest, Holder<Map<String, String>> outputs) throws VnfException { + String vfModuleId, String modelCustomizationUuid, MsoRequest msoRequest, + Holder<Map<String, String>> outputs) throws VnfException { logger.debug("Deleting VF " + vnfName + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId); // 1702 capture the output parameters on a delete diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java index 561b21250f..b1f4055b3b 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java @@ -1073,7 +1073,8 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter { public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vfModuleId, String vnfId, - String aaiVfModuleId, MsoRequest msoRequest, Holder<Map<String, String>> outputs) throws VnfException { + String aaiVfModuleId, String modelCustomizationUuid, MsoRequest msoRequest, + Holder<Map<String, String>> outputs) throws VnfException { logger.debug("Deleting VF Module " + vfModuleId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRest.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRest.java index 58899b7f48..0fb11ebbf3 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRest.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRest.java @@ -179,8 +179,8 @@ public class VnfAdapterRest { Holder<Map<String, String>> outputs = new Holder<>(); if (cloudsite != null && !cloudsite.equals(TESTING_KEYWORD)) { vnfAdapter.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), - req.getVfModuleStackId(), req.getVnfId(), req.getVfModuleId(), req.getMsoRequest(), - outputs); + req.getVfModuleStackId(), req.getVnfId(), req.getVfModuleId(), + req.getModelCustomizationUuid(), req.getMsoRequest(), outputs); } response = new DeleteVfModuleResponse(req.getVnfId(), req.getVfModuleId(), Boolean.TRUE, req.getMessageId(), outputs.value); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRestV2.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRestV2.java index 0e70c6be53..fcb570f3f5 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRestV2.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/VnfAdapterRestV2.java @@ -195,8 +195,8 @@ public class VnfAdapterRestV2 { // Support different Adapter Implementations MsoVnfAdapter adapter = vnfAdapterRestUtils.getVnfAdapterImpl(mode, cloudsite); adapter.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), - req.getVfModuleStackId(), req.getVnfId(), req.getVfModuleId(), req.getMsoRequest(), - outputs); + req.getVfModuleStackId(), req.getVnfId(), req.getVfModuleId(), + req.getModelCustomizationUuid(), req.getMsoRequest(), outputs); } response = new DeleteVfModuleResponse(req.getVnfId(), req.getVfModuleId(), Boolean.TRUE, req.getMessageId(), outputs.value); diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java index 01726acd54..a058378425 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java @@ -7,9 +7,9 @@ * 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. @@ -485,7 +485,7 @@ public class MsoVnfAdapterImplTest extends BaseRestTestUtils { MsoRequest msoRequest = getMsoRequest(); try { instance.deleteVfModule("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", - "5aae1e49-805c-4f9f-bd78-055bf7451157", "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, + "5aae1e49-805c-4f9f-bd78-055bf7451157", "11420693-3f69-4c61-b3ee-9787c744e760", null, msoRequest, new Holder<Map<String, String>>()); } catch (Exception e) { diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java index e7ef9d9348..45504fcab5 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java @@ -8,9 +8,9 @@ * 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. @@ -67,30 +67,30 @@ public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils { * msoRequest.setRequestId("12345"); msoRequest.setServiceInstanceId("12345"); Holder<Map<String, String>> outputs = * new Holder<>(); instance.queryVnf("siteid", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>(), new * Holder<>(), new Holder<>(), outputs); - * + * * assertTrue(outputs.value.isEmpty()); } */ /* * @Test public void queryVnfTest() throws Exception { - * - * + * + * * MsoRequest msoRequest = new MsoRequest(); msoRequest.setRequestId("12345"); * msoRequest.setServiceInstanceId("12345"); * wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")) * .willReturn(aResponse().withBody("{ \"id\": \"123\" }").withStatus(HttpStatus.SC_OK))); - * + * * wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")) * .willReturn(aResponse().withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }") * .withStatus(HttpStatus.SC_OK))); - * + * * wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse() * .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ") * .withStatus(HttpStatus.SC_OK))); - * + * * instance.queryVnf("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>(), new Holder<>(), new * Holder<>(), new Holder<>()); - * + * * } */ @@ -102,7 +102,7 @@ public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils { msoRequest.setServiceInstanceId("12345"); instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", "5aae1e49-805c-4f9f-bd78-055bf7451157", - "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, new Holder<>()); + "11420693-3f69-4c61-b3ee-9787c744e760", "customizationId", msoRequest, new Holder<>()); } @Test @@ -126,7 +126,7 @@ public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils { .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK))); instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", "5aae1e49-805c-4f9f-bd78-055bf7451157", - "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, new Holder<>()); + "11420693-3f69-4c61-b3ee-9787c744e760", "customizationId", msoRequest, new Holder<>()); } @Test diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java index 0ac30cb75c..3bf784c50b 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java @@ -211,7 +211,7 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils { .willReturn(aResponse().withStatus(HttpStatus.SC_NO_CONTENT))); instance.deleteVfModule("MTN13", "CloudOwner", "123", "workload-id", "5aae1e49-805c-4f9f-bd78-055bf7451157", - "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, new Holder<>()); + "11420693-3f69-4c61-b3ee-9787c744e760", "customizationId", msoRequest, new Holder<>()); } @Test diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java index ede25c5dbe..a68efbe130 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java @@ -134,8 +134,8 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { expectedException.expect(VnfException.class); MsoRequest msoRequest = getMsoRequest(); msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", - "5aae1e49-805c-4f9f-bd78-055bf7451157", "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, - new Holder<Map<String, String>>()); + "5aae1e49-805c-4f9f-bd78-055bf7451157", "11420693-3f69-4c61-b3ee-9787c744e760", "customizationId", + msoRequest, new Holder<Map<String, String>>()); } @Test @@ -152,8 +152,8 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); MsoRequest msoRequest = getMsoRequest(); msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", - "5aae1e49-805c-4f9f-bd78-055bf7451157", "11420693-3f69-4c61-b3ee-9787c744e760", msoRequest, - new Holder<Map<String, String>>()); + "5aae1e49-805c-4f9f-bd78-055bf7451157", "11420693-3f69-4c61-b3ee-9787c744e760", "customizationId", + msoRequest, new Holder<Map<String, String>>()); } private MsoRequest getMsoRequest() { diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/WebSecurityConfigImpl.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/WebSecurityConfigImpl.java deleted file mode 100644 index 6cd7462299..0000000000 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/WebSecurityConfigImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.so.adapters.requestsdb; - -import org.onap.so.security.MSOSpringFirewall; -import org.onap.so.security.WebSecurityConfig; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.builders.WebSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.web.firewall.StrictHttpFirewall; -import org.springframework.util.StringUtils; - -@Configuration -@EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfig { - - @Profile({"basic", "test"}) - @Bean - public WebSecurityConfigurerAdapter basicAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info", "/services") - .permitAll().antMatchers("/**") - .hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")).and().httpBasic(); - } - - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); - StrictHttpFirewall firewall = new MSOSpringFirewall(); - web.httpFirewall(firewall); - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(WebSecurityConfigImpl.this.userDetailsService()) - .passwordEncoder(WebSecurityConfigImpl.this.passwordEncoder()); - } - - }; - } - - @Profile("aaf") - @Bean - public WebSecurityConfigurerAdapter noAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests().anyRequest().permitAll(); - } - }; - } - -} diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/SecurityFilters.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/SecurityFilters.java deleted file mode 100644 index a422e6a60d..0000000000 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/SecurityFilters.java +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2019 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.so.adapters.requestsdb.application; - -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.core.Ordered; - -@Configuration -@Profile("aaf") -public class SecurityFilters { - - @Bean - public FilterRegistrationBean<SoCadiFilter> loginRegistrationBean() { - FilterRegistrationBean<SoCadiFilter> filterRegistrationBean = new FilterRegistrationBean<>(); - filterRegistrationBean.setFilter(new SoCadiFilter()); - filterRegistrationBean.setName("cadiFilter"); - filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE); - return filterRegistrationBean; - } -} diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/SoCadiFilter.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/SoCadiFilter.java deleted file mode 100644 index 5e6ced077b..0000000000 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/SoCadiFilter.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP SO - * ================================================================================ - * 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.so.adapters.requestsdb.application; - -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import org.onap.aaf.cadi.config.Config; -import org.onap.aaf.cadi.filter.CadiFilter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile("aaf") -public class SoCadiFilter extends CadiFilter { - - protected final Logger logger = LoggerFactory.getLogger(SoCadiFilter.class); - - private static String AFT_ENVIRONMENT_VAR = "AFT_ENVIRONMENT"; - private static String AAF_API_VERSION = "aaf_api_version"; - - @Value("${mso.config.cadi.cadiLoglevel:#{null}}") - private String cadiLoglevel; - - @Value("${mso.config.cadi.cadiKeyFile:#{null}}") - private String cadiKeyFile; - - @Value("${mso.config.cadi.cadiTruststorePassword:#{null}}") - private String cadiTrustStorePassword; - - @Value("${mso.config.cadi.cadiTrustStore:#{null}}") - private String cadiTrustStore; - - @Value("${mso.config.cadi.cadiLatitude:#{null}}") - private String cadiLatitude; - - @Value("${mso.config.cadi.cadiLongitude:#{null}}") - private String cadiLongitude; - - @Value("${mso.config.cadi.aafEnv:#{null}}") - private String aafEnv; - - @Value("${mso.config.cadi.aafApiVersion:#{null}}") - private String aafApiVersion; - - @Value("${mso.config.cadi.aafRootNs:#{null}}") - private String aafRootNs; - - @Value("${mso.config.cadi.aafId:#{null}}") - private String aafMechId; - - @Value("${mso.config.cadi.aafPassword:#{null}}") - private String aafMechIdPassword; - - @Value("${mso.config.cadi.aafLocateUrl:#{null}}") - private String aafLocateUrl; - - @Value("${mso.config.cadi.aafUrl:#{null}}") - private String aafUrl; - - @Value("${mso.config.cadi.apiEnforcement:#{null}}") - private String apiEnforcement; - - private void checkIfNullProperty(String key, String value) { - /* - * When value is null, it is not defined in application.yaml set nothing in System properties - */ - if (value != null) { - System.setProperty(key, value); - } - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - checkIfNullProperty(Config.CADI_LOGLEVEL, cadiLoglevel); - checkIfNullProperty(Config.CADI_KEYFILE, cadiKeyFile); - checkIfNullProperty(Config.CADI_TRUSTSTORE, cadiTrustStore); - checkIfNullProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadiTrustStorePassword); - checkIfNullProperty(Config.CADI_LATITUDE, cadiLatitude); - checkIfNullProperty(Config.CADI_LONGITUDE, cadiLongitude); - checkIfNullProperty(Config.AAF_ENV, aafEnv); - checkIfNullProperty(Config.AAF_API_VERSION, aafApiVersion); - checkIfNullProperty(Config.AAF_ROOT_NS, aafRootNs); - checkIfNullProperty(Config.AAF_APPID, aafMechId); - checkIfNullProperty(Config.AAF_APPPASS, aafMechIdPassword); - checkIfNullProperty(Config.AAF_LOCATE_URL, aafLocateUrl); - checkIfNullProperty(Config.AAF_URL, aafUrl); - checkIfNullProperty(Config.CADI_API_ENFORCEMENT, apiEnforcement); - // checkIfNullProperty(AFT_ENVIRONMENT_VAR, aftEnv); - logger.debug(" *** init Filter Config *** "); - super.init(filterConfig); - } - - -} diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SoCadiFilter.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SoCadiFilter.java deleted file mode 100644 index 1e5647097c..0000000000 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SoCadiFilter.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP SO - * ================================================================================ - * 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.so.adapters.sdnc; - -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import org.onap.aaf.cadi.config.Config; -import org.onap.aaf.cadi.filter.CadiFilter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile("aaf") -public class SoCadiFilter extends CadiFilter { - - protected final Logger logger = LoggerFactory.getLogger(SoCadiFilter.class); - - private static String AFT_ENVIRONMENT_VAR = "AFT_ENVIRONMENT"; - private static String AAF_API_VERSION = "aaf_api_version"; - - @Value("${mso.config.cadi.cadiLoglevel:#{null}}") - private String cadiLoglevel; - - @Value("${mso.config.cadi.cadiKeyFile:#{null}}") - private String cadiKeyFile; - - @Value("${mso.config.cadi.cadiTruststorePassword:#{null}}") - private String cadiTrustStorePassword; - - @Value("${mso.config.cadi.cadiTrustStore:#{null}}") - private String cadiTrustStore; - - @Value("${mso.config.cadi.cadiLatitude:#{null}}") - private String cadiLatitude; - - @Value("${mso.config.cadi.cadiLongitude:#{null}}") - private String cadiLongitude; - - @Value("${mso.config.cadi.aafEnv:#{null}}") - private String aafEnv; - - @Value("${mso.config.cadi.aafApiVersion:#{null}}") - private String aafApiVersion; - - @Value("${mso.config.cadi.aafRootNs:#{null}}") - private String aafRootNs; - - @Value("${mso.config.cadi.aafId:#{null}}") - private String aafMechId; - - @Value("${mso.config.cadi.aafPassword:#{null}}") - private String aafMechIdPassword; - - @Value("${mso.config.cadi.aafLocateUrl:#{null}}") - private String aafLocateUrl; - - @Value("${mso.config.cadi.aafUrl:#{null}}") - private String aafUrl; - - @Value("${mso.config.cadi.apiEnforcement:#{null}}") - private String apiEnforcement; - - private void checkIfNullProperty(String key, String value) { - /* - * When value is null, it is not defined in application.yaml set nothing in System properties - */ - if (value != null) { - System.setProperty(key, value); - } - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - checkIfNullProperty(Config.CADI_LOGLEVEL, cadiLoglevel); - checkIfNullProperty(Config.CADI_KEYFILE, cadiKeyFile); - checkIfNullProperty(Config.CADI_TRUSTSTORE, cadiTrustStore); - checkIfNullProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadiTrustStorePassword); - checkIfNullProperty(Config.CADI_LATITUDE, cadiLatitude); - checkIfNullProperty(Config.CADI_LONGITUDE, cadiLongitude); - checkIfNullProperty(Config.AAF_ENV, aafEnv); - checkIfNullProperty(Config.AAF_API_VERSION, aafApiVersion); - checkIfNullProperty(Config.AAF_ROOT_NS, aafRootNs); - checkIfNullProperty(Config.AAF_APPID, aafMechId); - checkIfNullProperty(Config.AAF_APPPASS, aafMechIdPassword); - checkIfNullProperty(Config.AAF_LOCATE_URL, aafLocateUrl); - checkIfNullProperty(Config.AAF_URL, aafUrl); - checkIfNullProperty(Config.CADI_API_ENFORCEMENT, apiEnforcement); - // checkIfNullProperty(AFT_ENVIRONMENT_VAR, aftEnv); - logger.debug(" *** init Filter Config *** "); - super.init(filterConfig); - } - - -} diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/WebSecurityConfigImpl.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/WebSecurityConfigImpl.java deleted file mode 100644 index 4d922a4cd0..0000000000 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/WebSecurityConfigImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.so.adapters.sdnc; - -import org.onap.so.security.MSOSpringFirewall; -import org.onap.so.security.WebSecurityConfig; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.builders.WebSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.web.firewall.StrictHttpFirewall; -import org.springframework.util.StringUtils; - -@Configuration -@EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfig { - - @Profile({"basic", "test"}) - @Bean - public WebSecurityConfigurerAdapter basicAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info", "/services") - .permitAll().antMatchers("/**") - .hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")).and().httpBasic(); - } - - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); - StrictHttpFirewall firewall = new MSOSpringFirewall(); - web.httpFirewall(firewall); - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(WebSecurityConfigImpl.this.userDetailsService()) - .passwordEncoder(WebSecurityConfigImpl.this.passwordEncoder()); - } - - }; - } - - @Profile("aaf") - @Bean - public WebSecurityConfigurerAdapter noAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests().anyRequest().permitAll(); - } - }; - } - -} diff --git a/adapters/mso-ve-vnfm-adapter/pom.xml b/adapters/mso-ve-vnfm-adapter/pom.xml new file mode 100644 index 0000000000..02abd600f8 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/pom.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.so</groupId> + <artifactId>adapters</artifactId> + <version>1.4.0-SNAPSHOT</version> + </parent> + + <groupId>org.onap.so.adapters</groupId> + <artifactId>mso-ve-vnfm-adapter</artifactId> + <packaging>jar</packaging> + + <name>mso-ve-vnfm-adapter</name> + <description>Ve-Vnfm (SOL002) Adapter</description> + + <properties> + <java.version>1.8</java.version> + <maven.compiler.source>${java.version}</maven.compiler.source> + <maven.compiler.target>${java.version}</maven.compiler.target> + </properties> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.onap.so.adapters</groupId> + <artifactId>mso-vnfm-adapter-ext-clients</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + +</project> diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/SecurityFilters.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/Application.java index cbe619e8a0..c4ca5f1fe1 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/SecurityFilters.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/Application.java @@ -1,15 +1,15 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO + * SO * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019 Samsung. 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. @@ -18,24 +18,15 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.openstack; +package org.onap.so.adapters.vevnfm; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.core.Ordered; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; -@Configuration -@Profile("aaf") -public class SecurityFilters { +@SpringBootApplication +public class Application { - @Bean - public FilterRegistrationBean<SoCadiFilter> loginRegistrationBean() { - FilterRegistrationBean<SoCadiFilter> filterRegistrationBean = new FilterRegistrationBean<>(); - filterRegistrationBean.setFilter(new SoCadiFilter()); - filterRegistrationBean.setName("cadiFilter"); - filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE); - return filterRegistrationBean; + public static void main(String... args) { + SpringApplication.run(Application.class, args); } } diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java new file mode 100644 index 0000000000..2e5a00ad02 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * SO + * ================================================================================ + * Copyright (C) 2019 Samsung. 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.so.adapters.vevnfm.controller; + +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class NotificationController { + + private static final Logger logger = LoggerFactory.getLogger(NotificationController.class); + + @PostMapping("${notification.url}") + public ResponseEntity receiveNotification(@RequestBody final VnfLcmOperationOccurrenceNotification notification) { + logger.info("Notification received {}", notification); + return ResponseEntity.ok().build(); + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml b/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml new file mode 100644 index 0000000000..30b3955821 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml @@ -0,0 +1,23 @@ +# +# Copyright © 2019 Samsung. +# 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. + +notification: + url: /lcm/v1/vnf/instances/notifications + +spring: + http: + converters: + preferred-json-mapper: gson diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java new file mode 100644 index 0000000000..c8d2a6bf90 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * SO + * ================================================================================ + * Copyright (C) 2019 Samsung. 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.so.adapters.vevnfm.controller; + +import org.junit.Test; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import static org.junit.Assert.assertEquals; + +public class NotificationControllerTest { + + private final NotificationController controller = new NotificationController(); + + @Test + public void testReceiveNotification() { + final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification(); + final ResponseEntity response = controller.receiveNotification(notification); + assertEquals(HttpStatus.OK, response.getStatusCode()); + } +} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/SoCadiFilter.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/SoCadiFilter.java deleted file mode 100644 index 89526d4cda..0000000000 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/SoCadiFilter.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP SO - * ================================================================================ - * 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.so.adapters.vfc; - -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import org.onap.aaf.cadi.config.Config; -import org.onap.aaf.cadi.filter.CadiFilter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile("aaf") -public class SoCadiFilter extends CadiFilter { - - protected final Logger logger = LoggerFactory.getLogger(SoCadiFilter.class); - - private static String AFT_ENVIRONMENT_VAR = "AFT_ENVIRONMENT"; - private static String AAF_API_VERSION = "aaf_api_version"; - - @Value("${mso.config.cadi.cadiLoglevel:#{null}}") - private String cadiLoglevel; - - @Value("${mso.config.cadi.cadiKeyFile:#{null}}") - private String cadiKeyFile; - - @Value("${mso.config.cadi.cadiTruststorePassword:#{null}}") - private String cadiTrustStorePassword; - - @Value("${mso.config.cadi.cadiTrustStore:#{null}}") - private String cadiTrustStore; - - @Value("${mso.config.cadi.cadiLatitude:#{null}}") - private String cadiLatitude; - - @Value("${mso.config.cadi.cadiLongitude:#{null}}") - private String cadiLongitude; - - @Value("${mso.config.cadi.aafEnv:#{null}}") - private String aafEnv; - - @Value("${mso.config.cadi.aafApiVersion:#{null}}") - private String aafApiVersion; - - @Value("${mso.config.cadi.aafRootNs:#{null}}") - private String aafRootNs; - - @Value("${mso.config.cadi.aafId:#{null}}") - private String aafMechId; - - @Value("${mso.config.cadi.aafPassword:#{null}}") - private String aafMechIdPassword; - - @Value("${mso.config.cadi.aafLocateUrl:#{null}}") - private String aafLocateUrl; - - @Value("${mso.config.cadi.aafUrl:#{null}}") - private String aafUrl; - - @Value("${mso.config.cadi.apiEnforcement:#{null}}") - private String apiEnforcement; - - private void checkIfNullProperty(String key, String value) { - /* - * When value is null, it is not defined in application.yaml set nothing in System properties - */ - if (value != null) { - System.setProperty(key, value); - } - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - checkIfNullProperty(Config.CADI_LOGLEVEL, cadiLoglevel); - checkIfNullProperty(Config.CADI_KEYFILE, cadiKeyFile); - checkIfNullProperty(Config.CADI_TRUSTSTORE, cadiTrustStore); - checkIfNullProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadiTrustStorePassword); - checkIfNullProperty(Config.CADI_LATITUDE, cadiLatitude); - checkIfNullProperty(Config.CADI_LONGITUDE, cadiLongitude); - checkIfNullProperty(Config.AAF_ENV, aafEnv); - checkIfNullProperty(Config.AAF_API_VERSION, aafApiVersion); - checkIfNullProperty(Config.AAF_ROOT_NS, aafRootNs); - checkIfNullProperty(Config.AAF_APPID, aafMechId); - checkIfNullProperty(Config.AAF_APPPASS, aafMechIdPassword); - checkIfNullProperty(Config.AAF_LOCATE_URL, aafLocateUrl); - checkIfNullProperty(Config.AAF_URL, aafUrl); - checkIfNullProperty(Config.CADI_API_ENFORCEMENT, apiEnforcement); - // checkIfNullProperty(AFT_ENVIRONMENT_VAR, aftEnv); - logger.debug(" *** init Filter Config *** "); - super.init(filterConfig); - } - - -} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/WebSecurityConfigImpl.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/WebSecurityConfigImpl.java deleted file mode 100644 index 28ac311b4e..0000000000 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/WebSecurityConfigImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.so.adapters.vfc; - -import org.onap.so.security.MSOSpringFirewall; -import org.onap.so.security.WebSecurityConfig; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.builders.WebSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.web.firewall.StrictHttpFirewall; -import org.springframework.util.StringUtils; - -@Configuration -@EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfig { - - @Profile({"basic", "test"}) - @Bean - public WebSecurityConfigurerAdapter basicAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info", "/services") - .permitAll().antMatchers("/**") - .hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")).and().httpBasic(); - } - - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); - StrictHttpFirewall firewall = new MSOSpringFirewall(); - web.httpFirewall(firewall); - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(WebSecurityConfigImpl.this.userDetailsService()) - .passwordEncoder(WebSecurityConfigImpl.this.passwordEncoder()); - } - - }; - } - - @Profile("aaf") - @Bean - public WebSecurityConfigurerAdapter noAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests().anyRequest().permitAll(); - } - }; - } - -} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/SoCadiFilter.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/SoCadiFilter.java deleted file mode 100644 index aefb36c6bb..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/SoCadiFilter.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP SO - * ================================================================================ - * 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.so.adapters.vnfmadapter; - -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import org.onap.aaf.cadi.config.Config; -import org.onap.aaf.cadi.filter.CadiFilter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile("aaf") -public class SoCadiFilter extends CadiFilter { - - protected final Logger logger = LoggerFactory.getLogger(SoCadiFilter.class); - - private static String AFT_ENVIRONMENT_VAR = "AFT_ENVIRONMENT"; - private static String AAF_API_VERSION = "aaf_api_version"; - - @Value("${mso.config.cadi.cadiLoglevel:#{null}}") - private String cadiLoglevel; - - @Value("${mso.config.cadi.cadiKeyFile:#{null}}") - private String cadiKeyFile; - - @Value("${mso.config.cadi.cadiTruststorePassword:#{null}}") - private String cadiTrustStorePassword; - - @Value("${mso.config.cadi.cadiTrustStore:#{null}}") - private String cadiTrustStore; - - @Value("${mso.config.cadi.cadiLatitude:#{null}}") - private String cadiLatitude; - - @Value("${mso.config.cadi.cadiLongitude:#{null}}") - private String cadiLongitude; - - @Value("${mso.config.cadi.aafEnv:#{null}}") - private String aafEnv; - - @Value("${mso.config.cadi.aafApiVersion:#{null}}") - private String aafApiVersion; - - @Value("${mso.config.cadi.aafRootNs:#{null}}") - private String aafRootNs; - - @Value("${mso.config.cadi.aafId:#{null}}") - private String aafMechId; - - @Value("${mso.config.cadi.aafPassword:#{null}}") - private String aafMechIdPassword; - - @Value("${mso.config.cadi.aafLocateUrl:#{null}}") - private String aafLocateUrl; - - @Value("${mso.config.cadi.aafUrl:#{null}}") - private String aafUrl; - - @Value("${mso.config.cadi.apiEnforcement:#{null}}") - private String apiEnforcement; - - private void checkIfNullProperty(String key, String value) { - /* - * When value is null, it is not defined in application.yaml set nothing in System properties - */ - if (value != null) { - System.setProperty(key, value); - } - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - checkIfNullProperty(Config.CADI_LOGLEVEL, cadiLoglevel); - checkIfNullProperty(Config.CADI_KEYFILE, cadiKeyFile); - checkIfNullProperty(Config.CADI_TRUSTSTORE, cadiTrustStore); - checkIfNullProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadiTrustStorePassword); - checkIfNullProperty(Config.CADI_LATITUDE, cadiLatitude); - checkIfNullProperty(Config.CADI_LONGITUDE, cadiLongitude); - checkIfNullProperty(Config.AAF_ENV, aafEnv); - checkIfNullProperty(Config.AAF_API_VERSION, aafApiVersion); - checkIfNullProperty(Config.AAF_ROOT_NS, aafRootNs); - checkIfNullProperty(Config.AAF_APPID, aafMechId); - checkIfNullProperty(Config.AAF_APPPASS, aafMechIdPassword); - checkIfNullProperty(Config.AAF_LOCATE_URL, aafLocateUrl); - checkIfNullProperty(Config.AAF_URL, aafUrl); - checkIfNullProperty(Config.CADI_API_ENFORCEMENT, apiEnforcement); - // checkIfNullProperty(AFT_ENVIRONMENT_VAR, aftEnv); - logger.debug(" *** init Filter Config *** "); - super.init(filterConfig); - } - - -} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/SecurityFilters.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmBasicWebSecurityConfigurerAdapter.java index 3876d77a80..4f3bbe6c5b 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/SecurityFilters.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmBasicWebSecurityConfigurerAdapter.java @@ -2,7 +2,9 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * 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. @@ -20,22 +22,32 @@ package org.onap.so.adapters.vnfmadapter; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; +import org.onap.so.security.SoBasicWebSecurityConfigurerAdapter; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.core.Ordered; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@EnableWebSecurity @Configuration -@Profile("aaf") -public class SecurityFilters { - - @Bean - public FilterRegistrationBean<SoCadiFilter> loginRegistrationBean() { - FilterRegistrationBean<SoCadiFilter> filterRegistrationBean = new FilterRegistrationBean<>(); - filterRegistrationBean.setFilter(new SoCadiFilter()); - filterRegistrationBean.setName("cadiFilter"); - filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE); - return filterRegistrationBean; +public class VnfmBasicWebSecurityConfigurerAdapter extends SoBasicWebSecurityConfigurerAdapter { + + @Value("${server.ssl.client-auth:none}") + private String clientAuth; + + @Override + protected void configure(final HttpSecurity http) throws Exception { + if (("need").equalsIgnoreCase(clientAuth)) { + http.csrf().disable().authorizeRequests().anyRequest().permitAll(); + } else { + super.configure(http); + } } + } + diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/WebSecurityConfigImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/WebSecurityConfigImpl.java deleted file mode 100644 index e43efd014a..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/WebSecurityConfigImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.so.adapters.vnfmadapter; - -import org.onap.so.security.MSOSpringFirewall; -import org.onap.so.security.WebSecurityConfig; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.builders.WebSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.web.firewall.StrictHttpFirewall; -import org.springframework.util.StringUtils; - -@Configuration -@EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfig { - - @Value("${server.ssl.client-auth:none}") - private String clientAuth; - - @Profile({"basic", "test"}) - @Bean - public WebSecurityConfigurerAdapter basicAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - if (("need").equalsIgnoreCase(clientAuth)) { - http.csrf().disable().authorizeRequests().anyRequest().permitAll(); - } else { - http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll() - .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")) - .and().httpBasic(); - } - } - - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); - StrictHttpFirewall firewall = new MSOSpringFirewall(); - web.httpFirewall(firewall); - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(WebSecurityConfigImpl.this.userDetailsService()) - .passwordEncoder(WebSecurityConfigImpl.this.passwordEncoder()); - } - - }; - } - - @Profile("aaf") - @Bean - public WebSecurityConfigurerAdapter noAuth() { - return new WebSecurityConfigurerAdapter() { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests().anyRequest().permitAll(); - } - }; - } - -} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java index d4063951bd..34fc2645a2 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java @@ -54,6 +54,14 @@ public interface EtsiCatalogServiceProvider { Optional<InlineResponse2001> getVnfPackage(final String vnfPkgId); /** + * GET specific VNF package VNFD from ETSI Catalog. + * + * @param vnfPkgId The ID of the VNF Package that you want to query. + * @return The VNF package retrieved from the ETSI Catalog + */ + Optional<byte[]> getVnfPackageVnfd(final String vnfPkgId); + + /** * GET Package Artifact, from VNF Package. * * @param vnfPkgId The ID of the VNF Package from which the artifact will be retrieved. diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java index 11a59c2ec8..779cb2a7a6 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java @@ -62,26 +62,9 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide @Override public Optional<byte[]> getVnfPackageContent(final String vnfPkgId) throws EtsiCatalogManagerRequestFailureException { - try { - final ResponseEntity<byte[]> response = httpServiceProvider - .getHttpResponse(etsiCatalogUrlProvider.getVnfPackageContentUrl(vnfPkgId), byte[].class); - logger.info("getVnfPackageContent Request to ETSI Catalog Manager Status Code: {}", - response.getStatusCodeValue()); - if (response.getStatusCode() == HttpStatus.OK) { - return Optional.ofNullable(response.getBody()); - } - } catch (final HttpResouceNotFoundException httpResouceNotFoundException) { - logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException); - throw new VnfPkgNotFoundException("No Vnf Package found with vnfPkgId: " + vnfPkgId); - } catch (final RestProcessingException restProcessingException) { - logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(), - restProcessingException); - if (restProcessingException.getStatusCode() == HttpStatus.CONFLICT.value()) { - throw new VnfPkgConflictException("A conflict occurred with the state of the resource,\n" - + "due to the attribute: onboardingState not being set to ONBOARDED."); - } - } - throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred."); + final String vnfRequestUrl = etsiCatalogUrlProvider.getVnfPackageContentUrl(vnfPkgId); + final String vnfRequestName = "getVnfPackageContent"; + return requestVnfElement(vnfPkgId, vnfRequestUrl, vnfRequestName); } @Override @@ -179,4 +162,34 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred."); } } + + @Override + public Optional<byte[]> getVnfPackageVnfd(final String vnfPkgId) { + final String vnfRequestUrl = etsiCatalogUrlProvider.getVnfPackageVnfdUrl(vnfPkgId); + final String vnfRequestName = "getVnfPackageVnfd"; + return requestVnfElement(vnfPkgId, vnfRequestUrl, vnfRequestName); + } + + private Optional<byte[]> requestVnfElement(final String vnfPkgId, final String vnfRequestUrl, + final String vnfRequestName) { + try { + final ResponseEntity<byte[]> response = httpServiceProvider.getHttpResponse(vnfRequestUrl, byte[].class); + logger.info("{} Request to ETSI Catalog Manager Status Code: {}", vnfRequestName, + response.getStatusCodeValue()); + if (response.getStatusCode() == HttpStatus.OK) { + return Optional.ofNullable(response.getBody()); + } + } catch (final HttpResouceNotFoundException httpResouceNotFoundException) { + logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException); + throw new VnfPkgNotFoundException("No Vnf Package found with vnfPkgId: " + vnfPkgId); + } catch (final RestProcessingException restProcessingException) { + logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(), + restProcessingException); + if (restProcessingException.getStatusCode() == HttpStatus.CONFLICT.value()) { + throw new VnfPkgConflictException("A conflict occurred with the state of the resource,\n" + + "due to the attribute: onboardingState not being set to ONBOARDED."); + } + } + throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred."); + } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java index cc2c7a62a4..8382212d51 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java @@ -35,12 +35,8 @@ public class EtsiCatalogUrlProvider { private static final Logger logger = getLogger(EtsiCatalogUrlProvider.class); - @Value("${msb.endpoint:#{\"http://msb_iag.onap:80\"}}") - private String msbEndpoint; - @Value("${msb.catalogServiceUrl:#{null}}") - private String catalogServiceUrl; - @Value("${msb.vnfpkgmServiceUrl:#{\"/api/vnfpkgm/v1\"}}") - private String vnfpkgmServiceUrl; + @Value("${etsi-catalog-manager.vnfpkgm.endpoint}") + private String etsiCatalogManagerEndpoint; public EtsiCatalogUrlProvider() {} @@ -51,7 +47,7 @@ public class EtsiCatalogUrlProvider { * @return the URL for the GET operation */ public String getVnfPackageContentUrl(final String vnfPkgId) { - final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages/" + vnfPkgId + "/package_content"; + final String url = etsiCatalogManagerEndpoint + "/vnf_packages/" + vnfPkgId + "/package_content"; logger.info("getEtsiCatalogVnfPackageContentUrl: {}", url); return url; } @@ -62,7 +58,7 @@ public class EtsiCatalogUrlProvider { * @return the URL for the GET operation */ public String getVnfPackagesUrl() { - final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages"; + final String url = etsiCatalogManagerEndpoint + "/vnf_packages"; logger.info("getEtsiCatalogVnfPackagesEndpoint: {}", url); return url; } @@ -74,7 +70,7 @@ public class EtsiCatalogUrlProvider { * @return the URL for the GET operation */ public String getVnfPackageUrl(final String vnfPkgId) { - final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages/" + vnfPkgId; + final String url = etsiCatalogManagerEndpoint + "/vnf_packages/" + vnfPkgId; logger.info("getEtsiCatalogVnfPackageEndpoint: {}", url); return url; } @@ -87,8 +83,20 @@ public class EtsiCatalogUrlProvider { * @return the URL for the GET operation */ public String getVnfPackageArtifactUrl(final String vnfPkgId, final String artifactPath) { - final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages/" + vnfPkgId + "/artifacts/" + artifactPath; + final String url = etsiCatalogManagerEndpoint + "/vnf_packages/" + vnfPkgId + "/artifacts/" + artifactPath; logger.info("getVnfPackageArtifactUrl: {}", url); return url; } + + /** + * Get the URL for retrieving VNF packages vnfd from ETSI Catalog. + * + * @param vnfPkgId The ID of the VNF Package + * @return the URL for the GET operation + */ + public String getVnfPackageVnfdUrl(final String vnfPkgId) { + final String url = etsiCatalogManagerEndpoint + "/vnf_packages/" + vnfPkgId + "/vnfd"; + logger.info("getEtsiCatalogVnfPackageVnfd: {}", url); + return url; + } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java index 3f975fbc9c..9d8e29b3f9 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java @@ -103,15 +103,25 @@ public class Sol003PackageManagementController { /** * GET VNFD, from VNF package. Will return a copy of the file representing the VNFD or a ZIP file that contains the * file/multiple files representing the VNFD specified. Section Number: 10.4.4 - * + * * @param vnfPkgId The ID of the VNF Package that you want to retrieve the VNFD from. * @return The VNFD of a VNF Package as a single file or within a ZIP file. Object: byte[] Response Code: 200 OK */ @GetMapping(value = "/vnf_packages/{vnfPkgId}/vnfd", produces = {MediaType.TEXT_PLAIN, APPLICATION_ZIP, MediaType.APPLICATION_JSON}) - public ResponseEntity<?> getVnfPackageVnfd(@PathVariable("vnfPkgId") final String vnfPkgId) { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd: ", vnfPkgId); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + public ResponseEntity<byte[]> getVnfPackageVnfd(@PathVariable("vnfPkgId") final String vnfPkgId) { + logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd Endpoint Invoked with VNF Package ID: ", vnfPkgId); + final Optional<byte[]> response = etsiCatalogServiceProvider.getVnfPackageVnfd(vnfPkgId); + if (response.isPresent()) { + logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd Response: ", HttpStatus.OK); + return new ResponseEntity(response.get(), HttpStatus.OK); + } + final String errorMessage = "An error occurred, a null response was received by the\n" + + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnfd\" \n" + + "endpoint."; + + logger.error(errorMessage); + return new ResponseEntity(buildProblemDetails(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR); } /** diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml index 951d4a3bb9..57dc08f3b5 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml @@ -23,7 +23,9 @@ spring: http: converters: preferred-json-mapper: gson - + main: + allow-bean-definition-overriding: true + server: port: 9092 tomcat: diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java index dbc8ef251d..c5194cf27e 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java @@ -20,7 +20,10 @@ package org.onap.so.adapters.vnfmadapter.rest; -import static org.junit.Assert.*; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL; import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; @@ -34,17 +37,25 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.*; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.Checksum; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.UriLink; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VNFPKGMLinkSerializer; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPackageArtifactInfo; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPackageSoftwareImageInfo; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPkgInfo; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001; import org.onap.so.configuration.rest.BasicHttpHeadersProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.*; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.MockRestServiceServer; @@ -59,8 +70,6 @@ import com.google.gson.Gson; @ActiveProfiles("test") public class Sol003PackageManagementControllerTest { - private static final Logger logger = LoggerFactory.getLogger(Sol003PackageManagementControllerTest.class); - @LocalServerPort private int port; @@ -69,14 +78,11 @@ public class Sol003PackageManagementControllerTest { private RestTemplate testRestTemplate; @Autowired - private Sol003PackageManagementController controller; - - @Autowired private TestRestTemplate restTemplate; private static final String VNF_PACKAGE_ID = "myVnfPackageId"; private static final String ARTIFACT_PATH = "myArtifactPath"; - private static final String MSB_BASE_URL = "http://msb_iag.onap:80/api/vnfpkgm/v1/vnf_packages"; + private static final String MSB_BASE_URL = "http://msb-iag.onap:80/api/vnfpkgm/v1/vnf_packages"; private static final String VNFPKGM_BASE_URL = PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages"; private static final String localhostUrl = "http://localhost:"; private static final String GET_VNF_PACKAGES_URL = ""; @@ -150,12 +156,18 @@ public class Sol003PackageManagementControllerTest { public void testOnGetPackageContent_UnauthorizedClient_Fail() { final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/" + VNF_PACKAGE_ID + "/package_content"; + + mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content")) + .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED)); + final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); + + final ResponseEntity<ProblemDetails> responseEntity = restTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class); assertTrue(responseEntity.getBody() instanceof ProblemDetails); - assertEquals(HttpStatus.UNAUTHORIZED, responseEntity.getStatusCode()); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); } @Test @@ -249,12 +261,16 @@ public class Sol003PackageManagementControllerTest { public void testOnGetPackageArtifact_UnauthorizedClient_Fail() { final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH; + + mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH)) + .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED)); + final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); final ResponseEntity<ProblemDetails> responseEntity = restTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class); assertNotNull(responseEntity.getBody()); - assertEquals(HttpStatus.UNAUTHORIZED, responseEntity.getStatusCode()); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); } @Test @@ -470,9 +486,99 @@ public class Sol003PackageManagementControllerTest { // The below test method is here to improve code coverage and provide a foundation for writing future tests @Test - public void testGetVnfd_Not_Implemented() { + public void testGetPackageVnfd_ValidArray_Success() { + final byte[] responseArray = buildByteArrayWithRandomData(10); + + mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd")) + .andExpect(method(HttpMethod.GET)) + .andRespond(withSuccess(responseArray, MediaType.APPLICATION_OCTET_STREAM)); + + final String testURL = + "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/" + VNF_PACKAGE_ID + "/vnfd"; + final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); + final ResponseEntity<byte[]> responseEntity = + restTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, byte[].class); + + assertEquals(byte[].class, responseEntity.getBody().getClass()); + assertArrayEquals(responseEntity.getBody(), responseArray); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + } + + @Test + public void testOnGetPackageVnfd_Conflict_Fail() { + mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd")) + .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.CONFLICT)); + + final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd"); + + assertTrue(responseEntity.getBody() instanceof ProblemDetails); + assertEquals(HttpStatus.CONFLICT, responseEntity.getStatusCode()); + } + + @Test + public void testOnGetPackageVnfd_NotFound_Fail() { + mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd")) + .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND)); + final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd"); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); + + assertTrue(responseEntity.getBody() instanceof ProblemDetails); + assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); + } + + @Test + public void testOnGetPackageVnfd_UnauthorizedClient_Fail() { + mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd")) + .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED)); + + final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd"); + + assertTrue(responseEntity.getBody() instanceof ProblemDetails); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + } + + @Test + public void testOnGetPackageVnfd_InternalServerError_Fail() { + mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd")) + .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); + + final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd"); + + assertTrue(responseEntity.getBody() instanceof ProblemDetails); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + } + + @Test + public void testOnGetPackageVnfd_BadRequest_Fail() { + mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd")) + .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.BAD_REQUEST)); + + final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd"); + + assertTrue(responseEntity.getBody() instanceof ProblemDetails); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + } + + @Test + public void testOnGetPackageVnfd_UnauthorizedServer_InternalError_Fail() { + mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd")) + .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED)); + + final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd"); + + assertTrue(responseEntity.getBody() instanceof ProblemDetails); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + } + + @Test + public void testGetPackageVnfd_SuccessResponseFromServerWithNullPackage_Fail() { + mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd")) + .andExpect(method(HttpMethod.GET)).andRespond(withSuccess()); + + final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd"); + + assertEquals(ProblemDetails.class, responseEntity.getBody().getClass()); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); } // Simply returns a byte array filled with random data, for use in the tests. diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java index 8fc27c5943..ed1880035a 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java @@ -34,14 +34,13 @@ public class Sol003SubscriptionManagementControllerTest { @Autowired @Qualifier(CONFIGURABLE_REST_TEMPLATE) private RestTemplate testRestTemplate; - private MockRestServiceServer mockRestServer; @Autowired private Sol003SubscriptionManagementController controller; @Before public void setUp() throws Exception { - mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build(); + MockRestServiceServer.bindTo(testRestTemplate).build(); } @Test diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java index e408a326f2..fca50ea6f2 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java @@ -39,6 +39,7 @@ import java.util.Optional; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -259,6 +260,7 @@ public class VnfmAdapterControllerTest { } @Test + @Ignore public void createVnf_UnauthorizedUser_Returns401() throws Exception { final TestRestTemplate restTemplateWrongPassword = new TestRestTemplate("test", "wrongPassword"); final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application.yaml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application.yaml index 8cf8b51b9f..ae66464f29 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application.yaml +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application.yaml @@ -20,6 +20,8 @@ spring: - username: vnfm password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' role: BPEL-Client + main: + allow-bean-definition-overriding: true mso: key: 07a7159d3bf51a0e53be7a8f89699be7 @@ -52,3 +54,7 @@ management: prometheus: enabled: true # Whether exporting of metrics to Prometheus is enabled. step: 1m # Step size (i.e. reporting frequency) to use. + +etsi-catalog-manager: + vnfpkgm: + endpoint: http://msb-iag.onap:80/api/vnfpkgm/v1 diff --git a/adapters/pom.xml b/adapters/pom.xml index bd7bebafa0..b96c3744c3 100644 --- a/adapters/pom.xml +++ b/adapters/pom.xml @@ -22,6 +22,8 @@ <module>mso-vfc-adapter</module> <module>mso-openstack-adapters</module> <module>mso-vnfm-adapter</module> + <module>mso-ve-vnfm-adapter</module> + <module>so-appc-orchestrator</module> </modules> <dependencies> diff --git a/adapters/so-appc-orchestrator/pom.xml b/adapters/so-appc-orchestrator/pom.xml new file mode 100644 index 0000000000..717bcee3fc --- /dev/null +++ b/adapters/so-appc-orchestrator/pom.xml @@ -0,0 +1,221 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.so</groupId> + <artifactId>adapters</artifactId> + <version>1.4.0-SNAPSHOT</version> + </parent> + + <groupId>org.onap.so.adapters</groupId> + <artifactId>so-appc-orchestrator</artifactId> + <packaging>jar</packaging> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <java.version>1.8</java.version> + <appc.client.version>1.6.0-SNAPSHOT</appc.client.version> + </properties> + <name>so-appc-orchestrator</name> + <description>MSO APPC-C Orchestrator</description> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${springboot.version}</version> + <configuration> + <mainClass>org.onap.so.adapters.appc.orchestrator.AppcOrchestratorApplication</mainClass> + </configuration> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>extract-docker-file</id> + </execution> + </executions> + </plugin> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>fabric8-maven-plugin</artifactId> + <executions> + <execution> + <id>start</id> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.3</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + <fork>true</fork> + <compilerArgs> + <arg>-parameters</arg> + </compilerArgs> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + <execution> + <id>default-test</id> + <goals> + <goal>test</goal> + </goals> + <configuration> + <includes> + <include>**/AllTestsTestSuite.java</include> + </includes> + <parallel>suites</parallel> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + <pluginManagement> + <plugins> + <!--This plugin's configuration is used to store Eclipse m2e settings + only. It has no influence on the Maven build itself. --> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>1.0.0</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId> + org.jvnet.jax-ws-commons + </groupId> + <artifactId> + jaxws-maven-plugin + </artifactId> + <versionRange> + [2.3,) + </versionRange> + <goals> + <goal>wsgen</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore> + </ignore> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + </plugin> + </plugins> + </pluginManagement> + <finalName>${project.artifactId}-${project.version}</finalName> + </build> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.micrometer</groupId> + <artifactId>micrometer-core</artifactId> + </dependency> + <dependency> + <groupId>io.micrometer</groupId> + <artifactId>micrometer-registry-prometheus</artifactId> + </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + <dependency> + <groupId>org.onap.so</groupId> + <artifactId>common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.camunda.bpm</groupId> + <artifactId>camunda-external-task-client</artifactId> + <version>1.1.1</version> + </dependency> + <dependency> + <groupId>org.onap.so</groupId> + <artifactId>MSOCommonBPMN</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.appc.client</groupId> + <artifactId>client-lib</artifactId> + <version>${appc.client.version}</version> + <exclusions> + <exclusion> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </exclusion> + <exclusion> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + </exclusion> + <exclusion> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.onap.so.adapters</groupId> + <artifactId>mso-adapter-utils</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.appc.client</groupId> + <artifactId>client-kit</artifactId> + <version>${appc.client.version}</version> + <exclusions> + <exclusion> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- Test Dependencies --> + <dependency> + <groupId>pl.pragmatists</groupId> + <artifactId>JUnitParams</artifactId> + <version>1.0.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/SecurityFilters.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/AppcOrchestratorApplication.java index 319d79e0fb..258c95ac89 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/SecurityFilters.java +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/AppcOrchestratorApplication.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 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. @@ -18,24 +18,29 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc; +package org.onap.so.adapters.appc.orchestrator; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.core.Ordered; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; -@Configuration -@Profile("aaf") -public class SecurityFilters { +/** + * @since Version 1.0 + * + */ + +@SpringBootApplication(scanBasePackages = {"org.onap"}) +public class AppcOrchestratorApplication { + + private static final String LOGS_DIR = "logs_dir"; + + private static void setLogsDir() { + if (System.getProperty(LOGS_DIR) == null) { + System.getProperties().setProperty(LOGS_DIR, "./logs/appcorch/"); + } + } - @Bean - public FilterRegistrationBean<SoCadiFilter> loginRegistrationBean() { - FilterRegistrationBean<SoCadiFilter> filterRegistrationBean = new FilterRegistrationBean<>(); - filterRegistrationBean.setFilter(new SoCadiFilter()); - filterRegistrationBean.setName("cadiFilter"); - filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE); - return filterRegistrationBean; + public static void main(String... args) { + SpringApplication.run(AppcOrchestratorApplication.class, args); + setLogsDir(); } } diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerCallback.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerCallback.java new file mode 100644 index 0000000000..1f73000299 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerCallback.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.so.adapters.appc.orchestrator.client; + +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import org.onap.appc.client.lcm.api.ResponseHandler; +import org.onap.appc.client.lcm.exceptions.AppcClientException; +import org.onap.appc.client.lcm.model.Status; +import org.onap.so.adapters.appc.orchestrator.client.StatusCategory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ApplicationControllerCallback<T> implements ResponseHandler<T> { + + private static final Logger logger = LoggerFactory.getLogger(ApplicationControllerCallback.class); + + private final ExternalTask externalTask; + private final ExternalTaskService externalTaskService; + private final ApplicationControllerSupport appCSupport; + + public ApplicationControllerCallback(ExternalTask externalTask, ExternalTaskService externalTaskService, + ApplicationControllerSupport appCSupport) { + this.externalTask = externalTask; + this.externalTaskService = externalTaskService; + this.appCSupport = appCSupport; + } + + @Override + public void onResponse(T response) { + logger.info("ON RESPONSE IN CALLBACK"); + + Status status = appCSupport.getStatusFromGenericResponse(response); + + logger.info("Status code is: " + status.getCode()); + logger.info("Status message is: " + status.getMessage()); + + if (appCSupport.getFinalityOf(status)) { + logger.debug("Obtained final status, complete the task"); + completeExternalTask(externalTask, externalTaskService, status); + } else { + logger.debug("Intermediate status, continue the task"); + } + } + + @Override + public void onException(AppcClientException exception) { + + logger.info("ON EXCEPTION IN CALLBACK"); + logger.info("Exception from APPC: " + exception.getMessage()); + Status exceptionStatus = appCSupport.buildStatusFromAppcException(exception); + completeExternalTask(externalTask, externalTaskService, exceptionStatus); + } + + private void completeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService, + Status status) { + + if (appCSupport.getCategoryOf(status).equals(StatusCategory.NORMAL)) { + externalTaskService.complete(externalTask); + logger.debug("The External Task Id: {} Successful", externalTask.getId()); + } else { + logger.debug("The External Task Id: {} Failed", externalTask.getId()); + externalTaskService.handleBpmnError(externalTask, "MSOWorkflowException", status.getMessage()); + } + } +} diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerClient.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerClient.java new file mode 100644 index 0000000000..20093be6a4 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerClient.java @@ -0,0 +1,244 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.so.adapters.appc.orchestrator.client; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.time.Instant; +import java.util.Optional; +import java.util.Properties; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; +import org.onap.appc.client.lcm.api.AppcClientServiceFactoryProvider; +import org.onap.appc.client.lcm.api.AppcLifeCycleManagerServiceFactory; +import org.onap.appc.client.lcm.api.ApplicationContext; +import org.onap.appc.client.lcm.api.LifeCycleManagerStateful; +import org.onap.appc.client.lcm.exceptions.AppcClientException; +import org.onap.appc.client.lcm.model.Action; +import org.onap.appc.client.lcm.model.ActionIdentifiers; +import org.onap.appc.client.lcm.model.CommonHeader; +import org.onap.appc.client.lcm.model.Flags; +import org.onap.appc.client.lcm.model.Flags.Force; +import org.onap.appc.client.lcm.model.Flags.Mode; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerOrchestratorException; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerSupport; +import org.onap.so.adapters.appc.orchestrator.client.StatusCategory; +import org.onap.appc.client.lcm.model.Payload; +import org.onap.appc.client.lcm.model.Status; +import org.onap.appc.client.lcm.model.ZULU; + +@Component +public class ApplicationControllerClient { + + @Autowired + public Environment env; + + public static final String DEFAULT_CONTROLLER_TYPE = "APPC"; + + private static final String CLIENT_NAME = "MSO"; + + private static final String API_VER = "2.00"; + private static final String ORIGINATOR_ID = "MSO"; + private static final int FLAGS_TTL = 65000; + private static Logger logger = LoggerFactory.getLogger(ApplicationControllerClient.class); + + @Autowired + private ApplicationControllerSupport appCSupport; + + // APPC gave us an API where the controllerType is configured in the + // client object, which is not what we asked for. We asked for an API + // in which the client would have additional methods that could take + // the controllerType as a parameter, so that we would not need to + // maintain multiple client objects. This map should be removed when + // the (hopefully short-term) controllerType becomes obsolete. + + private String controllerType = DEFAULT_CONTROLLER_TYPE; + + private static ConcurrentHashMap<String, LifeCycleManagerStateful> appCClients = new ConcurrentHashMap<>(); + + /** + * Creates an ApplicationControllerClient for the specified controller type. + * + * @param controllerType the controller type: "appc" or "sdnc". + */ + public void setControllerType(String controllerType) { + if (controllerType == null) { + controllerType = DEFAULT_CONTROLLER_TYPE; + } + this.controllerType = controllerType.toUpperCase(); + } + + /** + * Gets the controller type. + * + * @return the controllertype + */ + public String getControllerType() { + return controllerType; + } + + /** + * Returns the AppC client object associated with this ApplicationControllerClient. AppC client objects are shared + * objects. One is created if it does not exist. + * + * @return the client object, or null if creation failed + */ + public LifeCycleManagerStateful getAppCClient() { + return appCClients.computeIfAbsent(controllerType, k -> createAppCClient(k)); + } + + protected LifeCycleManagerStateful createAppCClient(String controllerType) { + + try { + if (controllerType == null) { + controllerType = DEFAULT_CONTROLLER_TYPE; + } + controllerType = controllerType.toUpperCase(); + return AppcClientServiceFactoryProvider.getFactory(AppcLifeCycleManagerServiceFactory.class) + .createLifeCycleManagerStateful(new ApplicationContext(), getLCMProperties(controllerType)); + } catch (AppcClientException e) { + logger.error("Error in getting LifeCycleManagerStateful: {}", e.getMessage(), e); + // This null value will cause NullPointerException when used later. + // Error handling could certainly be improved here. + return null; + } + } + + public Status vnfCommand(Action action, String requestId, String vnfId, Optional<String> vserverId, + Optional<String> request, String controllerType, ApplicationControllerCallback listener) + throws ApplicationControllerOrchestratorException { + this.setControllerType(controllerType); + Status status; + ActionIdentifiers actionIdentifiers = new ActionIdentifiers(); + actionIdentifiers.setVnfId(vnfId); + if (vserverId.isPresent()) { + actionIdentifiers.setVserverId(vserverId.get()); + } + Payload payload = null; + if (request.isPresent()) { + payload = new Payload(request.get()); + + } + status = runCommand(action, actionIdentifiers, payload, requestId, listener); + if (appCSupport.getCategoryOf(status).equals(StatusCategory.ERROR)) { + throw new ApplicationControllerOrchestratorException(status.getMessage(), status.getCode()); + } else { + return status; + } + } + + + public Status runCommand(Action action, org.onap.appc.client.lcm.model.ActionIdentifiers actionIdentifiers, + org.onap.appc.client.lcm.model.Payload payload, String requestID, ApplicationControllerCallback listener) + throws ApplicationControllerOrchestratorException { + Status status; + Object requestObject; + requestObject = createRequest(action, actionIdentifiers, payload, requestID); + appCSupport.logLCMMessage(requestObject); + LifeCycleManagerStateful client = getAppCClient(); + Method lcmMethod = appCSupport.getAPIMethod(action.name(), client, true); + try { + Object response = lcmMethod.invoke(client, requestObject, listener); + if (response != null) { + return appCSupport.getStatusFromGenericResponse(response); + } else { + return new Status(); + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + throw new RuntimeException(String.format("%s : %s", "Unable to invoke action", action.toString()), e); + } + } + + protected Properties getLCMProperties() { + return getLCMProperties("appc"); + } + + protected Properties getLCMProperties(String controllerType) { + Properties properties = new Properties(); + + properties.put("topic.read", this.env.getProperty("appc.client.topic.read.name")); + properties.put("topic.write", this.env.getProperty("appc.client.topic.write")); + properties.put("SDNC-topic.read", this.env.getProperty("appc.client.topic.sdnc.read")); + properties.put("SDNC-topic.write", this.env.getProperty("appc.client.topic.sdnc.write")); + properties.put("topic.read.timeout", this.env.getProperty("appc.client.topic.read.timeout")); + properties.put("client.response.timeout", this.env.getProperty("appc.client.response.timeout")); + properties.put("poolMembers", this.env.getProperty("appc.client.poolMembers")); + properties.put("controllerType", controllerType); + properties.put("client.key", this.env.getProperty("appc.client.key")); + properties.put("client.secret", this.env.getProperty("appc.client.secret")); + properties.put("client.name", CLIENT_NAME); + properties.put("service", this.env.getProperty("appc.client.service")); + return properties; + } + + public Object createRequest(Action action, ActionIdentifiers identifier, Payload payload, String requestId) { + Object requestObject = appCSupport.getInput(action.name()); + + + try { + CommonHeader commonHeader = buildCommonHeader(requestId); + requestObject.getClass().getDeclaredMethod("setCommonHeader", CommonHeader.class).invoke(requestObject, + commonHeader); + requestObject.getClass().getDeclaredMethod("setAction", Action.class).invoke(requestObject, action); + requestObject.getClass().getDeclaredMethod("setActionIdentifiers", ActionIdentifiers.class) + .invoke(requestObject, identifier); + if (payload != null) { + logger.info("payload in RunCommand: " + payload.getValue()); + requestObject.getClass().getDeclaredMethod("setPayload", Payload.class).invoke(requestObject, payload); + } + } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { + logger.error("Error building Appc request", e); + } + return requestObject; + } + + private CommonHeader buildCommonHeader(String requestId) { + CommonHeader commonHeader = new CommonHeader(); + commonHeader.setApiVer(API_VER); + commonHeader.setOriginatorId(ORIGINATOR_ID); + commonHeader.setRequestId(requestId == null ? UUID.randomUUID().toString() : requestId); + commonHeader.setSubRequestId(UUID.randomUUID().toString()); + Flags flags = new Flags(); + String flagsMode = "NORMAL"; + Mode mode = Mode.valueOf(flagsMode); + flags.setMode(mode); + String flagsForce = "FALSE"; + Force force = Force.valueOf(flagsForce); + flags.setForce(force); + flags.setTtl(FLAGS_TTL); + commonHeader.setFlags(flags); + Instant timestamp = Instant.now(); + ZULU zulu = new ZULU(timestamp.toString()); + commonHeader.setTimestamp(zulu); + return commonHeader; + } + + public Flags createRequestFlags() { + Flags flags = new Flags(); + flags.setTtl(6000); + return flags; + } +} diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SecurityFilters.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerOrchestratorException.java index c615440ff6..cc980a489d 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SecurityFilters.java +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerOrchestratorException.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 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. @@ -18,24 +18,20 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.sdnc; +package org.onap.so.adapters.appc.orchestrator.client; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.core.Ordered; -@Configuration -@Profile("aaf") -public class SecurityFilters { +public class ApplicationControllerOrchestratorException extends Exception { - @Bean - public FilterRegistrationBean<SoCadiFilter> loginRegistrationBean() { - FilterRegistrationBean<SoCadiFilter> filterRegistrationBean = new FilterRegistrationBean<>(); - filterRegistrationBean.setFilter(new SoCadiFilter()); - filterRegistrationBean.setName("cadiFilter"); - filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE); - return filterRegistrationBean; + private static final long serialVersionUID = 2594894543585595494L; + private final int appcCode; + + public ApplicationControllerOrchestratorException(String message, int code) { + super(message); + appcCode = code; + } + + public int getAppcCode() { + return appcCode; } } diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerSupport.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerSupport.java new file mode 100644 index 0000000000..90ab24cb86 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerSupport.java @@ -0,0 +1,207 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.so.adapters.appc.orchestrator.client; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import org.onap.appc.client.lcm.api.LifeCycleManagerStateful; +import org.onap.appc.client.lcm.api.ResponseHandler; +import org.onap.appc.client.lcm.exceptions.AppcClientException; +import org.onap.appc.client.lcm.model.Status; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + + +@Component +public class ApplicationControllerSupport { + + private static final int ACCEPT_SERIES = 100; + private static final int ERROR_SERIES = 200; + private static final int REJECT_SERIES = 300; + private static final int SUCCESS_SERIES = 400; + private static final int SUCCESS_STATUS = SUCCESS_SERIES; + private static final int PARTIAL_SERIES = 500; + private static final int PARTIAL_SUCCESS_STATUS = PARTIAL_SERIES; + private static final int PARTIAL_FAILURE_STATUS = PARTIAL_SERIES + 1; + + private static Logger logger = LoggerFactory.getLogger(ApplicationControllerSupport.class); + private String lcmModelPackage = "org.onap.appc.client.lcm.model"; + + /** + * @param action + * @return + * @throws ClassNotFoundException + * @throws InstantiationException + * @throws IllegalAccessException + */ + public Object getInput(String action) { + try { + return getInputClass(action).newInstance(); + } catch (IllegalAccessException | InstantiationException e) { + throw new RuntimeException( + String.format("%s : %s", "Unable to instantiate viable LCM Kit input class for action", action), e); + } + } + + /** + * @param action + * @return + * @throws ClassNotFoundException + */ + public Method getAPIMethod(String action, LifeCycleManagerStateful lcmStateful, boolean async) { + Method[] methods = lcmStateful.getClass().getMethods(); + for (Method method : methods) { + if (method.getName().equalsIgnoreCase(action)) { + Class<?>[] methodParameterTypes = method.getParameterTypes(); + if (methodParameterTypes.length > 0) { + if (getInputClass(action).equals(methodParameterTypes[0])) { + if (async) { + if (methodParameterTypes.length == 2 + && ResponseHandler.class.isAssignableFrom(methodParameterTypes[1])) { + return method; + } + } else if (methodParameterTypes.length == 1) { + return method; + } + } + } + } + } + throw new RuntimeException(String.format("%s : %s, async=%b", + "Unable to derive viable LCM Kit API method for action", action, async)); + } + + public Status getStatusFromGenericResponse(Object response) { + Method statusReader = getBeanPropertyMethodFor(response.getClass(), "status", false); + if (statusReader != null) { + try { + return (Status) statusReader.invoke(response); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + logger.error("Unable to obtain status from LCM Kit response", e); + } + } + return new Status(); + } + + public StatusCategory getCategoryOf(Status status) { + int codeSeries = status.getCode() - (status.getCode() % 100); + switch (codeSeries) { + case ACCEPT_SERIES: + return StatusCategory.NORMAL; + case ERROR_SERIES: + case REJECT_SERIES: + return StatusCategory.ERROR; + case SUCCESS_SERIES: + return status.getCode() == SUCCESS_STATUS ? StatusCategory.NORMAL : StatusCategory.ERROR; + case PARTIAL_SERIES: + switch (status.getCode()) { + case PARTIAL_SUCCESS_STATUS: + return StatusCategory.NORMAL; + case PARTIAL_FAILURE_STATUS: + return StatusCategory.ERROR; + default: + return StatusCategory.WARNING; + } + default: + return StatusCategory.WARNING; + } + } + + public boolean getFinalityOf(Status status) { + int codeSeries = status.getCode() - (status.getCode() % 100); + switch (codeSeries) { + case ACCEPT_SERIES: + case PARTIAL_SERIES: + return false; + case ERROR_SERIES: + case REJECT_SERIES: + case SUCCESS_SERIES: + return true; + default: + return true; + } + } + + private Method getBeanPropertyMethodFor(Class<?> clazz, String propertyName, boolean isWriter) { + BeanInfo beanInfo; + try { + beanInfo = Introspector.getBeanInfo(clazz, Object.class); + } catch (IntrospectionException e) { + throw new RuntimeException( + String.format("Unable to produce bean property method for class : %s, property : %s, writer=%b", + clazz.getName(), propertyName, isWriter), + e); + } + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); + for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { + if (propertyDescriptor.getName().equals(propertyName)) { + return isWriter ? propertyDescriptor.getWriteMethod() : propertyDescriptor.getReadMethod(); + } + } + throw new RuntimeException( + String.format("Unable to produce bean property method for class : %s, property : %s, writer=%b", + clazz.getName(), propertyName, isWriter)); + } + + /** + * @param action + * @return + * @throws ClassNotFoundException + */ + private Class<?> getInputClass(String action) { + try { + return Class.forName(lcmModelPackage + '.' + action + "Input"); + } catch (ClassNotFoundException e) { + throw new RuntimeException(String.format("%s : %s using package : %s", + "Unable to identify viable LCM Kit input class for action", action, lcmModelPackage), e); + } + } + + + public void logLCMMessage(Object message) { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(Include.NON_NULL); + ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter(); + String inputAsJSON; + try { + inputAsJSON = writer.writeValueAsString(message); + logger.info("LCM Kit input message follows: {}", inputAsJSON); + } catch (JsonProcessingException e) { + logger.error("Error in logging LCM Message", e); + } + } + + public Status buildStatusFromAppcException(AppcClientException exception) { + Status exceptionStatus = new Status(); + exceptionStatus.setCode(200); + exceptionStatus.setMessage("Exception on APPC request: " + exception.getMessage()); + return exceptionStatus; + } +} diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/StatusCategory.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/StatusCategory.java new file mode 100644 index 0000000000..27160ef981 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/StatusCategory.java @@ -0,0 +1,16 @@ +package org.onap.so.adapters.appc.orchestrator.client; + +public enum StatusCategory { + NORMAL("normal"), WARNING("warning"), ERROR("error"); + + private final String category; + + private StatusCategory(final String category) { + this.category = category; + } + + @Override + public String toString() { + return category; + } +} diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/ConfigurationParameters.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/ConfigurationParameters.java new file mode 100644 index 0000000000..b065e9a0c3 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/ConfigurationParameters.java @@ -0,0 +1,53 @@ +package org.onap.so.adapters.appc.orchestrator.client.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ConfigurationParameters { + + @JsonProperty("vnf_name") + private String vnfName; + @JsonProperty("book_name") + private String bookName; + @JsonProperty("node_list") + private String nodeList; + @JsonProperty("file_parameter_content") + private String fileParameterContent; + + + @JsonProperty("vnf_name") + public String getVnfName() { + return vnfName; + } + + @JsonProperty("vnf_name") + public void setVnfName(String vnfName) { + this.vnfName = vnfName; + } + + public String getBookName() { + return bookName; + } + + public void setBookName(String bookName) { + this.bookName = bookName; + } + + public String getNodeList() { + return nodeList; + } + + public void setNodeList(String nodeList) { + this.nodeList = nodeList; + } + + public String getFileParameterContent() { + return fileParameterContent; + } + + public void setFileParameterContent(String fileParameterContent) { + this.fileParameterContent = fileParameterContent; + } + +} diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/Identity.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/Identity.java new file mode 100644 index 0000000000..912441ad9a --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/Identity.java @@ -0,0 +1,24 @@ +package org.onap.so.adapters.appc.orchestrator.client.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"identity-url"}) +public class Identity { + + @JsonProperty("identity-url") + private String identityUrl; + + @JsonProperty("identity-url") + public String getIdentityUrl() { + return identityUrl; + } + + @JsonProperty("identity-url") + public void setIdentityUrl(String identityUrl) { + this.identityUrl = identityUrl; + } + +} diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/Parameters.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/Parameters.java new file mode 100644 index 0000000000..9b0385bd7a --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/Parameters.java @@ -0,0 +1,99 @@ +package org.onap.so.adapters.appc.orchestrator.client.beans; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"vm-id", "identity-url", "old_software_version", "new_software_version", "operations_timeout", + "request-parameters", "configuration-parameters"}) +public class Parameters { + + @JsonProperty("vm-id") + private String vmId; + @JsonProperty("identity-url") + private String identityUrl; + @JsonProperty("operations_timeout") + private String operationsTimeout; + @JsonProperty("existing_software_version") + private String existingSoftwareVersion; + @JsonProperty("new_software_version") + private String newSoftwareVersion; + @JsonProperty("request-parameters") + private RequestParameters requestParameters; + @JsonProperty("configuration-parameters") + private ConfigurationParameters configurationParameters; + + @JsonProperty("request-parameters") + public RequestParameters getRequestParameters() { + return requestParameters; + } + + @JsonProperty("request-parameters") + public void setRequestParameters(RequestParameters requestParameters) { + this.requestParameters = requestParameters; + } + + @JsonProperty("configuration-parameters") + public ConfigurationParameters getConfigurationParameters() { + return configurationParameters; + } + + @JsonProperty("configuration-parameters") + public void setConfigurationParameters(ConfigurationParameters configurationParameters) { + this.configurationParameters = configurationParameters; + } + + @JsonProperty("vm-id") + public String getVmId() { + return vmId; + } + + @JsonProperty("vm-id") + public void setVmId(String vmId) { + this.vmId = vmId; + } + + @JsonProperty("identity-url") + public String getIdentityUrl() { + return identityUrl; + } + + @JsonProperty("identity-url") + public void setIdentityUrl(String identityUrl) { + this.identityUrl = identityUrl; + } + + @JsonProperty("operations_timeout") + public String getOperationsTimeout() { + return operationsTimeout; + } + + @JsonProperty("operations_timeout") + public void setOperationsTimeout(String operationsTimeout) { + this.operationsTimeout = operationsTimeout; + } + + @JsonProperty("existing_software_version") + public String getExistingSoftwareVersion() { + return existingSoftwareVersion; + } + + @JsonProperty("existing_software_version") + public void setExistingSoftwareVersion(String existingSoftwareVersion) { + this.existingSoftwareVersion = existingSoftwareVersion; + } + + @JsonProperty("new_software_version") + public String getNewSoftwareVersion() { + return newSoftwareVersion; + } + + @JsonProperty("new_software_version") + public void setNewSoftwareVersion(String newSoftwareVersion) { + this.newSoftwareVersion = newSoftwareVersion; + } + + +} diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/RequestParameters.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/RequestParameters.java new file mode 100644 index 0000000000..ddc0a0ea3d --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/client/beans/RequestParameters.java @@ -0,0 +1,59 @@ +package org.onap.so.adapters.appc.orchestrator.client.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class RequestParameters { + + @JsonProperty("vnf-host-ip-address") + private String vnfHostIpAddress; + @JsonProperty("vf-module-id") + private String vfModuleId; + @JsonProperty("vnf-name") + private String vnfName; + @JsonProperty("host-ip-address") + private String hostIpAddress; + + public String getVnfHostIpAddress() { + return vnfHostIpAddress; + } + + public void setVnfHostIpAddress(String vnfHostIpAddress) { + this.vnfHostIpAddress = vnfHostIpAddress; + } + + public String getVfModuleId() { + return vfModuleId; + } + + public void setVfModuleId(String vfModuleId) { + this.vfModuleId = vfModuleId; + } + + public String getVnfName() { + return vnfName; + } + + public void setVnfName(String vnfName) { + this.vnfName = vnfName; + } + + public String getHostIpAddress() { + return hostIpAddress; + } + + public void setHostIpAddress(String hostIpAddress) { + this.hostIpAddress = hostIpAddress; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("RequestParametersConfigScaleOut{"); + sb.append("vnf-host-ip-address=").append(vnfHostIpAddress); + sb.append(", vf-module-id='").append(vfModuleId); + sb.append('}'); + return sb.toString(); + } + +} diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTask.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTask.java new file mode 100644 index 0000000000..181d114cc0 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTask.java @@ -0,0 +1,50 @@ +package org.onap.so.adapters.appc.orchestrator.service; + +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerCallback; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerSupport; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest; +import org.onap.so.externaltasks.logging.AuditMDCSetup; +import org.onap.so.utils.ExternalTaskUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; +import org.onap.appc.client.lcm.model.Status; + +@Component +public class ApplicationControllerTask extends ExternalTaskUtils { + + private static final Logger logger = LoggerFactory.getLogger(ApplicationControllerTask.class); + + @Autowired + public Environment env; + + @Autowired + public ApplicationControllerTaskImpl applicationControllerTaskImpl; + + @Autowired + public ApplicationControllerSupport applicationControllerSupport; + + @Autowired + private AuditMDCSetup mdcSetup; + + protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) { + mdcSetup.setupMDC(externalTask); + ApplicationControllerTaskRequest request = externalTask.getVariable("appcOrchestratorRequest"); + String msoRequestId = externalTask.getVariable("mso-request-id"); + logger.debug("Starting External Task for RequestId: {} ", msoRequestId); + Status status = null; + ApplicationControllerCallback listener = + new ApplicationControllerCallback(externalTask, externalTaskService, applicationControllerSupport); + + try { + status = applicationControllerTaskImpl.execute(msoRequestId, request, listener); + } catch (Exception e) { + logger.error("Error while calling appc", e.getMessage()); + } + } + +} diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskImpl.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskImpl.java new file mode 100644 index 0000000000..a174ccb05a --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskImpl.java @@ -0,0 +1,112 @@ +package org.onap.so.adapters.appc.orchestrator.service; + +import java.util.Optional; +import org.onap.appc.client.lcm.model.Status; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerCallback; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerClient; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerOrchestratorException; +import org.onap.so.adapters.appc.orchestrator.client.beans.ConfigurationParameters; +import org.onap.so.adapters.appc.orchestrator.client.beans.Identity; +import org.onap.so.adapters.appc.orchestrator.client.beans.Parameters; +import org.onap.so.adapters.appc.orchestrator.client.beans.RequestParameters; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVm; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; + +@Component +public class ApplicationControllerTaskImpl { + + @Autowired + private ApplicationControllerClient appcClient; + + public Status execute(String msoRequestId, ApplicationControllerTaskRequest request, + ApplicationControllerCallback listener) + throws JsonProcessingException, ApplicationControllerOrchestratorException { + Status status = null; + GraphInventoryCommonObjectMapperProvider mapper = new GraphInventoryCommonObjectMapperProvider(); + Optional<String> payload = Optional.empty(); + String vmId = null; + Optional<String> vserverId = Optional.empty(); + Parameters parameters = new Parameters(); + ConfigurationParameters configParams = new ConfigurationParameters(); + + switch (request.getAction()) { + case HealthCheck: + RequestParameters requestParams = new RequestParameters(); + requestParams.setHostIpAddress(request.getApplicationControllerVnf().getVnfHostIpAddress()); + parameters.setRequestParameters(requestParams); + payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + break; + case ResumeTraffic: + configParams.setVnfName(request.getApplicationControllerVnf().getVnfName()); + parameters.setConfigurationParameters(configParams); + payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + break; + case Start: + case Stop: + Identity identity = new Identity(); + identity.setIdentityUrl(request.getIdentityUrl()); + payload = Optional.of((mapper.getMapper().writeValueAsString(identity))); + break; + case Unlock: + case Lock: + break; + case QuiesceTraffic: + parameters.setOperationsTimeout(request.getOperationsTimeout()); + payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + break; + case DistributeTraffic: + configParams.setBookName(request.getBookName()); + configParams.setNodeList(request.getNodeList()); + configParams.setFileParameterContent(request.getFileParameters()); + configParams.setVnfName(request.getApplicationControllerVnf().getVnfName()); + parameters.setConfigurationParameters(configParams); + payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + break; + case DistributeTrafficCheck: + configParams.setBookName(request.getBookName()); + configParams.setNodeList(request.getNodeList()); + configParams.setFileParameterContent(request.getFileParameters()); + configParams.setVnfName(request.getApplicationControllerVnf().getVnfName()); + parameters.setConfigurationParameters(configParams); + payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + break; + case ConfigModify: + case ConfigScaleOut: + break; + case UpgradePreCheck: + case UpgradePostCheck: + case UpgradeSoftware: + case UpgradeBackup: + parameters.setExistingSoftwareVersion(request.getExistingSoftwareVersion()); + parameters.setNewSoftwareVersion(request.getNewSoftwareVersion()); + payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + break; + case ActionStatus: + break; + case Snapshot: + ApplicationControllerVm applicationControllerVm = + request.getApplicationControllerVnf().getApplicationControllerVm(); + if (applicationControllerVm != null) { + vmId = request.getApplicationControllerVnf().getApplicationControllerVm().getVmId(); + parameters.setVmId(vmId); + payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + vserverId = Optional + .of(request.getApplicationControllerVnf().getApplicationControllerVm().getVserverId()); + } + default: + // errorMessage = "Unable to idenify Action request for AppCClient"; + break; + } + + status = appcClient.vnfCommand(request.getAction(), msoRequestId, + request.getApplicationControllerVnf().getVnfId(), vserverId, payload, request.getControllerType(), + listener); + + return status; + } + +} diff --git a/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskService.java b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskService.java new file mode 100644 index 0000000000..2a33124eac --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskService.java @@ -0,0 +1,31 @@ +package org.onap.so.adapters.appc.orchestrator.service; + +import javax.annotation.PostConstruct; +import org.onap.so.utils.ExternalTaskServiceUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +@Profile("!test") +public class ApplicationControllerTaskService { + + @Autowired + public Environment env; + + @Autowired + private ApplicationControllerTask appcOrchestrator; + + @Autowired + private ExternalTaskServiceUtils externalTaskServiceUtils; + + @PostConstruct + public void appcOrchestrator() throws Exception { + for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) { + externalTaskServiceUtils.createExternalTaskClient().subscribe("AppcService").lockDuration(604800000) + .handler(appcOrchestrator::executeExternalTask).open(); + } + } + +} diff --git a/adapters/so-appc-orchestrator/src/main/resources/application.yaml b/adapters/so-appc-orchestrator/src/main/resources/application.yaml new file mode 100644 index 0000000000..c0c5962ea2 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/main/resources/application.yaml @@ -0,0 +1,18 @@ +server: + port: 8080 + tomcat: + max-threads: 50 + +#Actuator +management: + endpoints: + web: + base-path: /manage + exposure: + include: "*" + metrics: + se-global-registry: false + export: + prometheus: + enabled: true # Whether exporting of metrics to Prometheus is enabled. + step: 1m # Step size (i.e. reporting frequency) to use.
\ No newline at end of file diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/SecurityFilters.java b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/TestApplication.java index 040723501b..fe965b4444 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/SecurityFilters.java +++ b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/TestApplication.java @@ -1,8 +1,9 @@ +package org.onap.so; /*- * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 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. @@ -18,24 +19,25 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.catalogdb; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.FilterType; import org.springframework.context.annotation.Profile; -import org.springframework.core.Ordered; -@Configuration -@Profile("aaf") -public class SecurityFilters { +@SpringBootApplication +@Profile("test") +@ComponentScan(basePackages = {"org.onap.so"}, + excludeFilters = {@Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)}) +public class TestApplication { + public static void main(String... args) { + SpringApplication.run(TestApplication.class, args); + System.getProperties().setProperty("mso.db", "MARIADB"); + System.getProperties().setProperty("server.name", "Springboot"); + - @Bean - public FilterRegistrationBean<SoCadiFilter> loginRegistrationBean() { - FilterRegistrationBean<SoCadiFilter> filterRegistrationBean = new FilterRegistrationBean<>(); - filterRegistrationBean.setFilter(new SoCadiFilter()); - filterRegistrationBean.setName("cadiFilter"); - filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE); - return filterRegistrationBean; } } diff --git a/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerCallbackTest.java b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerCallbackTest.java new file mode 100644 index 0000000000..90f5a44752 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerCallbackTest.java @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017-2019 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.so.adapters.appc.orchestrator.client; + +import static org.hamcrest.CoreMatchers.any; +import static org.mockito.Mockito.doReturn; +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerCallback; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerSupport; +import org.onap.appc.client.lcm.model.Status; +import org.onap.appc.client.lcm.exceptions.AppcClientException; +import org.onap.appc.client.lcm.model.ResumeTrafficOutput; + +public class ApplicationControllerCallbackTest { + + @InjectMocks + ApplicationControllerCallback appcTaskCallback; + + @Mock + ApplicationControllerSupport applicationControllerSupport; + + @Mock + ExternalTask mockExternalTask; + + @Mock + ExternalTaskService mockExternalTaskService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + appcTaskCallback = new ApplicationControllerCallback(mockExternalTask, mockExternalTaskService, + applicationControllerSupport); + } + + @Test + public void onResponse_appcCallback_success_Test() throws Exception { + Status status = new Status(); + status.setCode(400); + ResumeTrafficOutput response = new ResumeTrafficOutput(); + response.setStatus(status); + doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response); + doReturn(true).when(applicationControllerSupport).getFinalityOf(status); + doReturn(StatusCategory.NORMAL).when(applicationControllerSupport).getCategoryOf(status); + appcTaskCallback.onResponse(response); + Mockito.verify(mockExternalTaskService).complete(mockExternalTask); + } + + @Test + public void onResponse_appcCallback_intermediateResponse_Test() throws Exception { + Status status = new Status(); + status.setCode(100); + ResumeTrafficOutput response = new ResumeTrafficOutput(); + response.setStatus(status); + doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response); + appcTaskCallback.onResponse(response); + Mockito.verifyZeroInteractions(mockExternalTaskService); + } + + @Test + public void onResponse_appcCallback_failure_Test() throws Exception { + String testFailure = "test failure"; + Status status = new Status(); + status.setCode(200); + status.setMessage(testFailure); + ResumeTrafficOutput response = new ResumeTrafficOutput(); + response.setStatus(status); + doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response); + doReturn(true).when(applicationControllerSupport).getFinalityOf(status); + doReturn(StatusCategory.ERROR).when(applicationControllerSupport).getCategoryOf(status); + appcTaskCallback.onResponse(response); + Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, "MSOWorkflowException", testFailure); + } + + @Test + public void onException_appcCallback_failure_Test() throws Exception { + String testFailure = "test failure"; + AppcClientException appcException = new AppcClientException(testFailure); + Status status = new Status(); + status.setCode(200); + String exceptionMessage = "Exception on APPC request: " + testFailure; + status.setMessage(exceptionMessage); + doReturn(status).when(applicationControllerSupport).buildStatusFromAppcException(appcException); + doReturn(StatusCategory.ERROR).when(applicationControllerSupport).getCategoryOf(status); + appcTaskCallback.onException(appcException); + Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, "MSOWorkflowException", + exceptionMessage); + } +} diff --git a/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerSupportTest.java b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerSupportTest.java new file mode 100644 index 0000000000..2dd2fd7ac8 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/client/ApplicationControllerSupportTest.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.so.adapters.appc.orchestrator.client; + +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.appc.client.lcm.exceptions.AppcClientException; +import org.onap.appc.client.lcm.model.Status; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerSupport; +import org.onap.so.adapters.appc.orchestrator.client.StatusCategory; +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; + +@RunWith(JUnitParamsRunner.class) +public class ApplicationControllerSupportTest { + private ApplicationControllerSupport applicationControllerSupport = new ApplicationControllerSupport(); + + public static Object[][] statusesAndCategories() { + return new Object[][] {{100, StatusCategory.NORMAL}, {200, StatusCategory.ERROR}, {300, StatusCategory.ERROR}, + {400, StatusCategory.NORMAL}, {401, StatusCategory.ERROR}, {500, StatusCategory.NORMAL}, + {501, StatusCategory.ERROR}, {502, StatusCategory.WARNING}, {800, StatusCategory.WARNING},}; + } + + public static Object[][] statusesAndFinalities() { + return new Object[][] {{100, false}, {200, true}, {300, true}, {400, true}, {500, false}, {800, true},}; + } + + @Test + @Parameters(method = "statusesAndCategories") + public void shouldReturnCategoryForCode(int code, StatusCategory category) throws Exception { + // when + StatusCategory detectedCategory = applicationControllerSupport.getCategoryOf(createStatus(code)); + // then + assertThat(detectedCategory).isEqualTo(category); + } + + @Test + @Parameters(method = "statusesAndFinalities") + public void shouldReturnFinalityForCode(int code, boolean expectedFinality) throws Exception { + // when + boolean finality = applicationControllerSupport.getFinalityOf(createStatus(code)); + // then + assertThat(finality).isEqualTo(expectedFinality); + } + + @Test + public void buildStatusFromAppcException_Test() { + String errorMessage = "errormessage"; + AppcClientException exception = new AppcClientException(errorMessage); + Status status = applicationControllerSupport.buildStatusFromAppcException(exception); + assertThat(status.getCode() == 200); + assertThat((status.getMessage()).equals(("Exception on APPC request: " + errorMessage))); + } + + private Status createStatus(int code) { + Status status = new Status(); + status.setCode(code); + return status; + } +} diff --git a/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/client/beans/BeansTest.java b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/client/beans/BeansTest.java new file mode 100644 index 0000000000..76b5efacb3 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/client/beans/BeansTest.java @@ -0,0 +1,20 @@ +package org.onap.so.adapters.appc.orchestrator.client.beans; + +import org.junit.Test; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class BeansTest { + + @Test + public void validateGettersAndSetters() { + Validator validator = ValidatorBuilder.create().with(new SetterMustExistRule(), new GetterMustExistRule()) + .with(new SetterTester(), new GetterTester()).build(); + validator.validate("org.onap.so.adapters.appc.orchestrator.client.beans", new FilterPackageInfo()); + } +} diff --git a/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskImplITTest.java b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskImplITTest.java new file mode 100644 index 0000000000..3eac851f13 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskImplITTest.java @@ -0,0 +1,88 @@ +package org.onap.so.adapters.appc.orchestrator.service; + +import java.util.List; +import java.util.Optional; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.appc.client.lcm.model.Status; +import org.onap.so.TestApplication; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerCallback; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerClient; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerOrchestratorException; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerSupport; +import org.onap.so.adapters.appc.orchestrator.client.beans.ConfigurationParameters; +import org.onap.so.adapters.appc.orchestrator.client.beans.Identity; +import org.onap.so.adapters.appc.orchestrator.client.beans.Parameters; +import org.onap.so.adapters.appc.orchestrator.client.beans.RequestParameters; +import org.onap.so.adapters.appc.orchestrator.service.ApplicationControllerTaskImpl; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVnf; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.onap.appc.client.lcm.model.Action; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +@ContextConfiguration +@AutoConfigureWireMock(port = 0) +public class ApplicationControllerTaskImplITTest { + + @Autowired + private ApplicationControllerTaskImpl applicationControllerTaskImpl; + + @Mock + ExternalTask externalTask; + + @Mock + ExternalTaskService externalTaskService; + + @Mock + ApplicationControllerSupport appCSupport; + + ApplicationControllerTaskRequest request; + + ApplicationControllerCallback listener; + + GraphInventoryCommonObjectMapperProvider mapper = new GraphInventoryCommonObjectMapperProvider(); + + @Before + public void setup() { + request = new ApplicationControllerTaskRequest(); + request.setBookName("testBookName"); + request.setControllerType("testControllerType"); + request.setFileParameters("testFileParams"); + request.setIdentityUrl("testIdentityUrl"); + request.setNewSoftwareVersion("2.0"); + request.setExistingSoftwareVersion("1.0"); + request.setOperationsTimeout("30"); + ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf(); + applicationControllerVnf.setVnfHostIpAddress("100.100"); + applicationControllerVnf.setVnfId("testVnfId"); + applicationControllerVnf.setVnfName("testVnfName"); + request.setApplicationControllerVnf(applicationControllerVnf); + listener = new ApplicationControllerCallback(null, externalTaskService, appCSupport); + } + + + @Test + public void testListener() throws Exception { + request.setAction(Action.QuiesceTraffic); + Status status = applicationControllerTaskImpl.execute("testRequestId", request, listener); + } + +} diff --git a/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskImplTest.java b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskImplTest.java new file mode 100644 index 0000000000..640e2dbd6e --- /dev/null +++ b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskImplTest.java @@ -0,0 +1,236 @@ +package org.onap.so.adapters.appc.orchestrator.service; + +import java.util.Optional; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.appc.client.lcm.model.Status; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerCallback; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerClient; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerOrchestratorException; +import org.onap.so.adapters.appc.orchestrator.client.beans.ConfigurationParameters; +import org.onap.so.adapters.appc.orchestrator.client.beans.Identity; +import org.onap.so.adapters.appc.orchestrator.client.beans.Parameters; +import org.onap.so.adapters.appc.orchestrator.client.beans.RequestParameters; +import org.onap.so.adapters.appc.orchestrator.service.ApplicationControllerTaskImpl; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVnf; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.onap.appc.client.lcm.model.Action; + +@RunWith(MockitoJUnitRunner.class) +public class ApplicationControllerTaskImplTest { + + @Mock + ApplicationControllerClient applicationControllerClient; + + @InjectMocks + @Spy + ApplicationControllerTaskImpl applicationControllerTaskImpl; + + ApplicationControllerTaskRequest request; + + ApplicationControllerCallback listener; + + GraphInventoryCommonObjectMapperProvider mapper = new GraphInventoryCommonObjectMapperProvider(); + + @Before + public void setup() { + request = new ApplicationControllerTaskRequest(); + request.setBookName("testBookName"); + request.setControllerType("testControllerType"); + request.setFileParameters("testFileParams"); + request.setIdentityUrl("testIdentityUrl"); + request.setNewSoftwareVersion("2.0"); + request.setExistingSoftwareVersion("1.0"); + request.setOperationsTimeout("30"); + ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf(); + applicationControllerVnf.setVnfHostIpAddress("100.100"); + applicationControllerVnf.setVnfId("testVnfId"); + applicationControllerVnf.setVnfName("testVnfName"); + request.setApplicationControllerVnf(applicationControllerVnf); + listener = new ApplicationControllerCallback(null, null, null); + + } + + @Test + public void testExcute_healthCheck() throws JsonProcessingException, ApplicationControllerOrchestratorException { + request.setAction(Action.HealthCheck); + + Parameters parameters = new Parameters(); + RequestParameters requestParams = new RequestParameters(); + requestParams.setHostIpAddress(request.getApplicationControllerVnf().getVnfHostIpAddress()); + parameters.setRequestParameters(requestParams); + Optional<String> payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + + Mockito.when(applicationControllerClient.vnfCommand(Action.HealthCheck, "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener)).thenReturn(new Status()); + + Status status = applicationControllerTaskImpl.execute("testRequestId", request, listener); + + Mockito.verify(applicationControllerClient).vnfCommand(Action.HealthCheck, "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener); + + } + + @Test + public void testExcute_resumeTraffic() throws JsonProcessingException, ApplicationControllerOrchestratorException { + request.setAction(Action.ResumeTraffic); + + Parameters parameters = new Parameters(); + ConfigurationParameters configParams = new ConfigurationParameters(); + configParams.setVnfName(request.getApplicationControllerVnf().getVnfName()); + parameters.setConfigurationParameters(configParams); + Optional<String> payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + + Mockito.when(applicationControllerClient.vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener)).thenReturn(new Status()); + + Status status = applicationControllerTaskImpl.execute("testRequestId", request, listener); + + Mockito.verify(applicationControllerClient).vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener); + } + + @Test + public void testExcute_stop() throws JsonProcessingException, ApplicationControllerOrchestratorException { + request.setAction(Action.Stop); + + Identity identity = new Identity(); + identity.setIdentityUrl(request.getIdentityUrl()); + Optional<String> payload = Optional.of((mapper.getMapper().writeValueAsString(identity))); + + Mockito.when(applicationControllerClient.vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener)).thenReturn(new Status()); + + Status status = applicationControllerTaskImpl.execute("testRequestId", request, listener); + + Mockito.verify(applicationControllerClient).vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener); + } + + @Test + public void testExcute_lock() throws JsonProcessingException, ApplicationControllerOrchestratorException { + request.setAction(Action.Lock); + + Mockito.when(applicationControllerClient.vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), Optional.empty(), + "testControllerType", listener)).thenReturn(new Status()); + + Status status = applicationControllerTaskImpl.execute("testRequestId", request, listener); + + Mockito.verify(applicationControllerClient).vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), Optional.empty(), + "testControllerType", listener); + } + + @Test + public void testExcute_quiesceTraffic() throws JsonProcessingException, ApplicationControllerOrchestratorException { + request.setAction(Action.QuiesceTraffic); + + + Parameters parameters = new Parameters(); + parameters.setOperationsTimeout(request.getOperationsTimeout()); + Optional<String> payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + System.out.println("PAYLOAD is: " + payload.get()); + + Mockito.when(applicationControllerClient.vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener)).thenReturn(new Status()); + + Status status = applicationControllerTaskImpl.execute("testRequestId", request, listener); + + Mockito.verify(applicationControllerClient).vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener); + } + + @Test + public void testExcute_distributeTraffic() + throws JsonProcessingException, ApplicationControllerOrchestratorException { + request.setAction(Action.DistributeTraffic); + + Parameters parameters = new Parameters(); + ConfigurationParameters configParams = new ConfigurationParameters(); + configParams.setBookName(request.getBookName()); + configParams.setNodeList(request.getNodeList()); + configParams.setFileParameterContent(request.getFileParameters()); + configParams.setVnfName(request.getApplicationControllerVnf().getVnfName()); + parameters.setConfigurationParameters(configParams); + Optional<String> payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + + Mockito.when(applicationControllerClient.vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener)).thenReturn(new Status()); + + Status status = applicationControllerTaskImpl.execute("testRequestId", request, listener); + + Mockito.verify(applicationControllerClient).vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener); + } + + @Test + public void testExcute_distributeTrafficCheck() + throws JsonProcessingException, ApplicationControllerOrchestratorException { + request.setAction(Action.DistributeTrafficCheck); + + Parameters parameters = new Parameters(); + ConfigurationParameters configParams = new ConfigurationParameters(); + configParams.setBookName(request.getBookName()); + configParams.setNodeList(request.getNodeList()); + configParams.setFileParameterContent(request.getFileParameters()); + configParams.setVnfName(request.getApplicationControllerVnf().getVnfName()); + parameters.setConfigurationParameters(configParams); + Optional<String> payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + + Mockito.when(applicationControllerClient.vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener)).thenReturn(new Status()); + + Status status = applicationControllerTaskImpl.execute("testRequestId", request, listener); + + Mockito.verify(applicationControllerClient).vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener); + } + + @Test + public void testExcute_upgradeBackup() throws JsonProcessingException, ApplicationControllerOrchestratorException { + request.setAction(Action.UpgradeBackup); + + Parameters parameters = new Parameters(); + parameters.setExistingSoftwareVersion(request.getExistingSoftwareVersion()); + parameters.setNewSoftwareVersion(request.getNewSoftwareVersion()); + Optional<String> payload = Optional.of((mapper.getMapper().writeValueAsString(parameters))); + + Mockito.when(applicationControllerClient.vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener)).thenReturn(new Status()); + + Status status = applicationControllerTaskImpl.execute("testRequestId", request, listener); + + Mockito.verify(applicationControllerClient).vnfCommand(request.getAction(), "testRequestId", + request.getApplicationControllerVnf().getVnfId(), Optional.empty(), payload, "testControllerType", + listener); + } + + @Test + public void testListener() throws Exception { + request.setAction(Action.QuiesceTraffic); + Status status = applicationControllerTaskImpl.execute("testRequestId", request, listener); + } + +} diff --git a/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskTest.java b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskTest.java new file mode 100644 index 0000000000..228ee90107 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/test/java/org/onap/so/adapters/appc/orchestrator/service/ApplicationControllerTaskTest.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017-2019 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.so.adapters.appc.orchestrator.service; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.so.externaltasks.logging.AuditMDCSetup; +import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerCallback; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest; +import org.onap.appc.client.lcm.model.Status; + +public class ApplicationControllerTaskTest extends ApplicationControllerTask { + + @InjectMocks + ApplicationControllerTask appcTaskService = new ApplicationControllerTask(); + + @Mock + ApplicationControllerTaskImpl applicationControllerTaskImpl; + + @Mock + ExternalTask mockExternalTask; + + @Mock + ExternalTaskService mockExternalTaskService; + + @Mock + private AuditMDCSetup mdcSetup; + + private ApplicationControllerTaskRequest request = new ApplicationControllerTaskRequest(); + private String msoRequestId = "testRequestId"; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + doNothing().when(mdcSetup).setupMDC(mockExternalTask); + doReturn(request).when(mockExternalTask).getVariable("appcOrchestratorRequest"); + doReturn(msoRequestId).when(mockExternalTask).getVariable("mso-request-id"); + } + + @Test + public void executeExternalTask_appc_success_Test() throws Exception { + Status status = new Status(); + doReturn(status).when(applicationControllerTaskImpl).execute(any(String.class), + any(ApplicationControllerTaskRequest.class), any(ApplicationControllerCallback.class)); + appcTaskService.executeExternalTask(mockExternalTask, mockExternalTaskService); + Mockito.verify(applicationControllerTaskImpl).execute(any(String.class), + any(ApplicationControllerTaskRequest.class), any(ApplicationControllerCallback.class)); + } +} diff --git a/adapters/so-appc-orchestrator/src/test/resources/application-test.yaml b/adapters/so-appc-orchestrator/src/test/resources/application-test.yaml new file mode 100644 index 0000000000..eb693a263e --- /dev/null +++ b/adapters/so-appc-orchestrator/src/test/resources/application-test.yaml @@ -0,0 +1,17 @@ + +appc: + client: + key: LSl8QKolmKcC0yJR + response: + timeout: '60000' + secret: lgjXraD1HutKxv8jEN6tVouu + poolMembers: localhost:3904,localhost:3904 + service: ueb + topic: + read: + name: APPC-1902-SHDEV-WRITE + timeout: '120000' + write: APPC-1902-SHDEV-READ + sdnc: + read: SDNC-LCM-READ + write: SDNC-LCM-WRITE
\ No newline at end of file diff --git a/adapters/so-appc-orchestrator/src/test/resources/logback-test.xml b/adapters/so-appc-orchestrator/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8a9e705ca6 --- /dev/null +++ b/adapters/so-appc-orchestrator/src/test/resources/logback-test.xml @@ -0,0 +1,31 @@ +<configuration> + + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} - %msg%n</pattern> + </encoder> + </appender> + + + <logger name="com.att.ecomp.audit" level="info" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <logger name="com.att.eelf.metrics" level="info" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <logger name="com.att.eelf.error" level="trace" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <logger name="org.onap" level="${so.log.level:-WARN}" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <root level="WARN"> + <appender-ref ref="STDOUT" /> + </root> + +</configuration>
\ No newline at end of file |