From 822c98964b0a4f7b4da5dbe79669e54011a0778d Mon Sep 17 00:00:00 2001 From: "Paira, Saurav (sp694w) sp694w@att.com" Date: Mon, 20 Aug 2018 21:28:11 +0000 Subject: Add VlantagApi Functional Component to apps/ms Initial code contribution to add Vlantag Api microservice. It is developed as a Spring Boot application. Issue-ID: CCSDK-475 Change-Id: I0d5df398aae284cee181fcefeee9251e11ea8c26 Signed-off-by: Saurav Paira Signed-off-by: Paira, Saurav (sp694w) sp694w@att.com --- .../ccsdk/apps/ms/vlantagapi/core/Application.java | 34 ++ .../vlantagapi/core/ApplicationSecurityConfig.java | 97 ++++ .../ms/vlantagapi/core/JerseyConfiguration.java | 35 ++ .../core/ResourceAssignmentInitializer.java | 192 +++++++ .../core/exception/VlantagApiException.java | 47 ++ .../core/extinf/pm/model/AllowedRanges.java | 57 +++ .../vlantagapi/core/extinf/pm/model/Elements.java | 96 ++++ .../core/extinf/pm/model/PolicyConfig.java | 172 +++++++ .../core/extinf/pm/model/PolicyContent.java | 59 +++ .../core/extinf/pm/model/PolicyData.java | 20 + .../core/extinf/pm/model/PolicyEngineResponse.java | 141 ++++++ .../core/extinf/pm/model/RequestObject.java | 41 ++ .../core/extinf/pm/model/ResourceModel.java | 145 ++++++ .../core/model/AssignVlanTagRequest.java | 94 ++++ .../core/model/AssignVlanTagRequestInput.java | 186 +++++++ .../core/model/AssignVlanTagResponse.java | 135 +++++ .../core/model/AssignVlanTagResponseOutput.java | 153 ++++++ .../ms/vlantagapi/core/model/PingResponse.java | 39 ++ .../core/model/UnassignVlanTagRequest.java | 92 ++++ .../core/model/UnassignVlanTagRequestInput.java | 130 +++++ .../core/model/UnassignVlanTagResponse.java | 131 +++++ .../core/model/UnassignVlanTagResponseOutput.java | 131 +++++ .../apps/ms/vlantagapi/core/model/VlanTag.java | 149 ++++++ .../vlantagapi/core/service/VlantagApiService.java | 81 +++ .../core/service/VlantagApiServiceImpl.java | 561 +++++++++++++++++++++ .../extinf/pm/PolicyDataDeserializer.java | 111 ++++ .../vlantagapi/extinf/pm/PolicyManagerClient.java | 189 +++++++ 27 files changed, 3318 insertions(+) create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/Application.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ApplicationSecurityConfig.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/JerseyConfiguration.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ResourceAssignmentInitializer.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/exception/VlantagApiException.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/AllowedRanges.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/Elements.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyConfig.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyContent.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyData.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyEngineResponse.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/RequestObject.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/ResourceModel.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagRequest.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagRequestInput.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagResponse.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagResponseOutput.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/PingResponse.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagRequest.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagRequestInput.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagResponse.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagResponseOutput.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/VlanTag.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiService.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiServiceImpl.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/extinf/pm/PolicyDataDeserializer.java create mode 100644 ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/extinf/pm/PolicyManagerClient.java (limited to 'ms/vlantag-api/src/main/java/org') diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/Application.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/Application.java new file mode 100644 index 00000000..bd18a986 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/Application.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Application.java Purpose: Entry point for the micro-service -- it starts up the application. + * + * @author Saurav Paira + * @version 1.0 + */ +@SpringBootApplication(scanBasePackages={"org.onap.ccsdk.apps.ms.vlantagapi", "org.onap.ccsdk.sli.core", "org.onap.ccsdk.sli.adaptors"}) +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ApplicationSecurityConfig.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ApplicationSecurityConfig.java new file mode 100644 index 00000000..bd0abe6f --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ApplicationSecurityConfig.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core; + +import java.util.ArrayList; +import java.util.Base64; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +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.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.crypto.factory.PasswordEncoderFactories; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; + +/** + * ApplicationSecurityConfig.java Purpose: Configures and validates + * Application Security configurations + * + * @author Saurav Paira + * @version 1.0 + */ +@Configuration +public class ApplicationSecurityConfig extends WebSecurityConfigurerAdapter{ + private Logger logger = LoggerFactory.getLogger(ApplicationSecurityConfig.class); + + @Autowired + private Environment environment; + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + List userDetails = new ArrayList<>(); + + PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); + final User.UserBuilder userBuilder = User.builder().passwordEncoder(encoder::encode); + + String authString = environment.getProperty("application.authToken"); + String[] tokens = authString.split(";"); + for (int i = 0; i < tokens.length; i++) { + String token = tokens[i]; + String[] cred = token.split("~"); + String[] uidpwdarr = decode(cred[0]); + logger.info("------uid/pwd ----------------{}, {}",uidpwdarr[0],uidpwdarr[1]); + + UserDetails user = userBuilder + .username(uidpwdarr[0]) + .password(uidpwdarr[1]) + .roles(cred[1]) + .build(); + + userDetails.add(user); + } + + logger.info("-------------------------------{}",userDetails); + auth.userDetailsService(inMemoryUserDetailsManager(userDetails)); + } + + + public InMemoryUserDetailsManager inMemoryUserDetailsManager(List userDetails) { + return new InMemoryUserDetailsManager(userDetails); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests().anyRequest().fullyAuthenticated(); + http.httpBasic().and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); + http.csrf().disable(); + } + + private static String[] decode(String encoded) { + final byte[] decodedBytes + = Base64.getDecoder().decode(encoded.getBytes()); + final String pair = new String(decodedBytes); + return pair.split(":", 2); + } + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/JerseyConfiguration.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/JerseyConfiguration.java new file mode 100644 index 00000000..f4877233 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/JerseyConfiguration.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core; + +import org.glassfish.jersey.server.ResourceConfig; +import org.onap.ccsdk.apps.ms.vlantagapi.core.service.VlantagApiServiceImpl; +import org.springframework.stereotype.Component; + +/** + * JerseyConfiguration.java Purpose: Configuration of the REST framework. + * + * @author Saurav Paira + * @version 1.0 + */ +@Component +public class JerseyConfiguration extends ResourceConfig +{ + public JerseyConfiguration() + { + register(VlantagApiServiceImpl.class); + } +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ResourceAssignmentInitializer.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ResourceAssignmentInitializer.java new file mode 100644 index 00000000..3c845329 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ResourceAssignmentInitializer.java @@ -0,0 +1,192 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.sql.DataSource; + +import org.onap.ccsdk.sli.adaptors.lock.comp.LockHelper; +import org.onap.ccsdk.sli.adaptors.lock.comp.LockHelperImpl; +import org.onap.ccsdk.sli.adaptors.lock.dao.ResourceLockDao; +import org.onap.ccsdk.sli.adaptors.lock.dao.ResourceLockDaoImpl; +import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator; +import org.onap.ccsdk.sli.adaptors.ra.alloc.DbAllocationRule; +import org.onap.ccsdk.sli.adaptors.ra.comp.AllocationRule; +import org.onap.ccsdk.sli.adaptors.ra.comp.EndPointAllocator; +import org.onap.ccsdk.sli.adaptors.ra.comp.EndPointAllocatorImpl; +import org.onap.ccsdk.sli.adaptors.ra.rule.dao.RangeRuleDao; +import org.onap.ccsdk.sli.adaptors.ra.rule.dao.RangeRuleDaoImpl; +import org.onap.ccsdk.sli.adaptors.ra.rule.dao.ResourceRuleDao; +import org.onap.ccsdk.sli.adaptors.ra.rule.dao.ResourceRuleDaoImpl; +import org.onap.ccsdk.sli.adaptors.rm.comp.ResourceManager; +import org.onap.ccsdk.sli.adaptors.rm.comp.ResourceManagerImpl; +import org.onap.ccsdk.sli.adaptors.rm.dao.ResourceDao; +import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.AllocationItemJdbcDao; +import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.AllocationItemJdbcDaoImpl; +import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceDaoImpl; +import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceJdbcDao; +import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceJdbcDaoImpl; +import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceLoadJdbcDao; +import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceLoadJdbcDaoImpl; +import org.onap.ccsdk.sli.adaptors.util.db.CachedDataSourceWrap; +import org.onap.ccsdk.sli.adaptors.util.db.DataSourceWrap; +import org.onap.ccsdk.sli.adaptors.util.speed.SpeedUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.stereotype.Component; + +/** + * ResourceAssignmentInitializer.java Purpose: Represents and Initializes + * Resource Assignment Spring Module Beans + * + * @author Saurav Paira + * @version 1.0 + */ + +@Component +@Configuration +public class ResourceAssignmentInitializer { + + private static final Logger log = LoggerFactory.getLogger(ResourceAssignmentInitializer.class); + + + @Bean + public JdbcTemplate getJdbcTemplate(DataSource dataSource) { + return new JdbcTemplate(dataSource); + } + + @Bean + public ResourceLockDaoImpl getResourceLockDaoImpl(JdbcTemplate jdbcTemplate) { + ResourceLockDaoImpl resourceLockDaoImpl = new ResourceLockDaoImpl(); + resourceLockDaoImpl.setJdbcTemplate(jdbcTemplate); + + return resourceLockDaoImpl; + } + + @Bean + public LockHelperImpl getLockHelperImpl(ResourceLockDao resourceLockDao) { + LockHelperImpl lockHelperImpl = new LockHelperImpl(); + lockHelperImpl.setLockWait(5); + lockHelperImpl.setRetryCount(10); + lockHelperImpl.setResourceLockDao(resourceLockDao); + + return lockHelperImpl; + } + + @Bean + public ResourceJdbcDaoImpl getResourceJdbcDaoImpl(JdbcTemplate jdbcTemplate) { + ResourceJdbcDaoImpl resourceJdbcDaoImpl = new ResourceJdbcDaoImpl(); + resourceJdbcDaoImpl.setJdbcTemplate(jdbcTemplate); + return resourceJdbcDaoImpl; + } + + @Bean + public AllocationItemJdbcDaoImpl getAllocationItemJdbcDaoImpl(JdbcTemplate jdbcTemplate) { + AllocationItemJdbcDaoImpl allocationItemJdbcDaoImpl = new AllocationItemJdbcDaoImpl(); + allocationItemJdbcDaoImpl.setJdbcTemplate(jdbcTemplate); + return allocationItemJdbcDaoImpl; + } + + @Bean + public ResourceLoadJdbcDaoImpl getResourceLoadJdbcDaoImpl(JdbcTemplate jdbcTemplate) { + ResourceLoadJdbcDaoImpl resourceLoadJdbcDaoImpl = new ResourceLoadJdbcDaoImpl(); + resourceLoadJdbcDaoImpl.setJdbcTemplate(jdbcTemplate); + return resourceLoadJdbcDaoImpl; + } + + + @Bean + public ResourceDaoImpl getResourceDaoImpl(ResourceJdbcDao resourceJdbcDao, AllocationItemJdbcDao allocationItemJdbcDao, ResourceLoadJdbcDao resourceLoadJdbcDao) { + ResourceDaoImpl resourceDaoImpl = new ResourceDaoImpl(); + resourceDaoImpl.setAllocationItemJdbcDao(allocationItemJdbcDao); + resourceDaoImpl.setResourceJdbcDao(resourceJdbcDao); + resourceDaoImpl.setResourceLoadJdbcDao(resourceLoadJdbcDao); + + return resourceDaoImpl; + } + + @Bean + public ResourceManagerImpl getResourceManagerImpl(LockHelper lockHelper, ResourceDao resourceDao) { + ResourceManagerImpl resourceManagerImpl = new ResourceManagerImpl(); + resourceManagerImpl.setLockHelper(lockHelper); + resourceManagerImpl.setLockTimeout(600); + resourceManagerImpl.setResourceDao(resourceDao); + + return resourceManagerImpl; + } + + @Bean + public ResourceRuleDaoImpl getResourceRuleDaoImpl(JdbcTemplate jdbcTemplate) { + ResourceRuleDaoImpl resourceRuleDaoImpl = new ResourceRuleDaoImpl(); + resourceRuleDaoImpl.setJdbcTemplate(jdbcTemplate); + + return resourceRuleDaoImpl; + } + + @Bean + public RangeRuleDaoImpl getRangeRuleDaoImpl(JdbcTemplate jdbcTemplate) { + RangeRuleDaoImpl rangeRuleDaoImpl = new RangeRuleDaoImpl(); + rangeRuleDaoImpl.setJdbcTemplate(jdbcTemplate); + + return rangeRuleDaoImpl; + } + + @Bean + public ResourceAllocator getResourceAllocator(ResourceManager resourceManager, EndPointAllocator endPointAllocator, SpeedUtil speedUtil) { + ResourceAllocator resourceAllocator = new ResourceAllocator(); + resourceAllocator.setEndPointAllocator(endPointAllocator); + resourceAllocator.setResourceManager(resourceManager); + resourceAllocator.setSpeedUtil(speedUtil); + + return resourceAllocator; + } + + @Bean + public SpeedUtil getSpeedUtil() { + return new SpeedUtil(); + } + + @Bean + public EndPointAllocatorImpl getEndPointAllocatorImpl(ResourceManager resourceManager, DbAllocationRule dbAllocationRule) { + EndPointAllocatorImpl endPointAllocatorImpl = new EndPointAllocatorImpl(); + + Map> allocationRuleMap = new HashMap<>(); + allocationRuleMap.put("DEFAULT", Arrays.asList(dbAllocationRule)); + + endPointAllocatorImpl.setResourceManager(resourceManager); + endPointAllocatorImpl.setAllocationRuleMap(allocationRuleMap); + + return endPointAllocatorImpl; + } + + @Bean + public DbAllocationRule getDbAllocationRule(ResourceRuleDao resourceRuleDao, RangeRuleDao rangeRuleDao) { + DbAllocationRule dbAllocationRule = new DbAllocationRule(); + dbAllocationRule.setRangeRuleDao(rangeRuleDao); + dbAllocationRule.setResourceRuleDao(resourceRuleDao); + + return dbAllocationRule; + } +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/exception/VlantagApiException.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/exception/VlantagApiException.java new file mode 100644 index 00000000..32ce1844 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/exception/VlantagApiException.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.exception; + +/** + * VlantagApiException.java Purpose: Represents application exceptions generated by this micro-service. + * + * @author Saurav Paira + * @version 1.0 + */ +public class VlantagApiException extends Exception { + + private static final long serialVersionUID = 1L; + + public VlantagApiException() + { + super(); + } + + public VlantagApiException(String message) + { + super(message); + } + + public VlantagApiException(String message, Throwable t) + { + super(message, t); + } + + public VlantagApiException(Throwable arg0) { + super(arg0); + } + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/AllowedRanges.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/AllowedRanges.java new file mode 100644 index 00000000..70f19c0f --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/AllowedRanges.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * AllowedRanges.java Purpose: POJO representing policy manager + * get-config response AllowedRanges model defines Vlantag Range + * + * @author Saurav Paira + * @version 1.0 + */ +public class AllowedRanges { + + @JsonProperty("min") + String min; + + @JsonProperty("max") + String max; + + public String getMin() { + return min; + } + + public void setMin(String min) { + this.min = min; + } + + public String getMax() { + return max; + } + + public void setMax(String max) { + this.max = max; + } + + @Override + public String toString() { + return "AllowedRanges [min=" + min + ", max=" + max + "]"; + } + + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/Elements.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/Elements.java new file mode 100644 index 00000000..20604634 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/Elements.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Elements.java Purpose: POJO representing policy manager + * get-config response Element model within a Resource Model + * + * @author Saurav Paira + * @version 1.0 + */ +public class Elements { + + @JsonProperty("recycle-vlantag-range") + String recycleVlantagRange; + + @JsonProperty("overwrite") + String overwrite; + + @JsonProperty("vlantag-name") + String vlantagName; + + @JsonProperty("allowed-range") + private List allowedRanges; + + @JsonProperty("element-vlan-role") + String elementVlanRole; + + + public String getRecycleVlantagRange() { + return recycleVlantagRange; + } + + public void setRecycleVlantagRange(String recycleVlantagRange) { + this.recycleVlantagRange = recycleVlantagRange; + } + + public String getOverwrite() { + return overwrite; + } + + public void setOverwrite(String overwrite) { + this.overwrite = overwrite; + } + + public String getVlantagName() { + return vlantagName; + } + + public void setVlantagName(String vlantagName) { + this.vlantagName = vlantagName; + } + + public List getAllowedRanges() { + return allowedRanges; + } + + public void setAllowedRanges(List allowedRanges) { + this.allowedRanges = allowedRanges; + } + + public String getElementVlanRole() { + return elementVlanRole; + } + + public void setElementVlanRole(String elementVlanRole) { + this.elementVlanRole = elementVlanRole; + } + + @Override + public String toString() { + return "Elements [recycleVlantagRange=" + recycleVlantagRange + ", overwrite=" + overwrite + ", vlantagName=" + + vlantagName + ", allowedRanges=" + allowedRanges + ", elementVlanRole=" + elementVlanRole + "]"; + } + + + + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyConfig.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyConfig.java new file mode 100644 index 00000000..354f83a3 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyConfig.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * PolicyConfig.java Purpose: POJO representing policy manager + * get-config response + * + * @author Saurav Paira + * @version 1.0 + */ +public class PolicyConfig implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + @JsonProperty("configName") + private String configName; + + @JsonProperty("riskLevel") + private String riskLevel; + + @JsonProperty("policyName") + private String policyName; + + @JsonProperty("policyScope") + private String policyScope; + + @JsonProperty("guard") + private String guard; + + @JsonProperty("description") + private String description; + + @JsonProperty("priority") + private String priority; + + @JsonProperty("uuid") + private String uuid; + + @JsonProperty("version") + private String version; + + @JsonProperty("content") + private PolicyContent content; + + @JsonProperty("riskType") + private String riskType; + + @JsonProperty("service") + private String service; + + @JsonProperty("location") + private String location; + + @JsonProperty("templateVersion") + private String templateVersion; + + public String getConfigName() { + return configName; + } + public void setConfigName(String configName) { + this.configName = configName; + } + public String getRiskLevel() { + return riskLevel; + } + public void setRiskLevel(String riskLevel) { + this.riskLevel = riskLevel; + } + public String getPolicyName() { + return policyName; + } + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + public String getPolicyScope() { + return policyScope; + } + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + public String getGuard() { + return guard; + } + public void setGuard(String guard) { + this.guard = guard; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getPriority() { + return priority; + } + public void setPriority(String priority) { + this.priority = priority; + } + public String getUuid() { + return uuid; + } + public void setUuid(String uuid) { + this.uuid = uuid; + } + public String getVersion() { + return version; + } + public void setVersion(String version) { + this.version = version; + } + + public PolicyContent getContent() { + return content; + } + public void setContent(PolicyContent content) { + this.content = content; + } + public String getRiskType() { + return riskType; + } + public void setRiskType(String riskType) { + this.riskType = riskType; + } + public String getService() { + return service; + } + public void setService(String service) { + this.service = service; + } + public String getLocation() { + return location; + } + public void setLocation(String location) { + this.location = location; + } + public String getTemplateVersion() { + return templateVersion; + } + public void setTemplateVersion(String templateVersion) { + this.templateVersion = templateVersion; + } + @Override + public String toString() { + return "PolicyConfig [configName=" + configName + ", riskLevel=" + riskLevel + ", policyName=" + policyName + + ", policyScope=" + policyScope + ", guard=" + guard + ", description=" + description + ", priority=" + + priority + ", uuid=" + uuid + ", version=" + version + ", content=" + content + ", riskType=" + + riskType + ", service=" + service + ", location=" + location + ", templateVersion=" + templateVersion + + "]"; + } + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyContent.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyContent.java new file mode 100644 index 00000000..2f60d8f5 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyContent.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * PolicyContent.java Purpose: POJO representing policy manager + * get-config response contents + * + * @author Saurav Paira + * @version 1.0 + */ +public class PolicyContent { + + @JsonProperty("resource-models") + private List resourceModels; + + @JsonProperty("policy-instance-name") + private String policyInstanceName; + + public String getPolicyInstanceName() { + return policyInstanceName; + } + + public void setPolicyInstanceName(String policyInstanceName) { + this.policyInstanceName = policyInstanceName; + } + + public List getResourceModels() { + return resourceModels; + } + + public void setResourceModels(List resourceModels) { + this.resourceModels = resourceModels; + } + + @Override + public String toString() { + return "PolicyContent [resourceModels=" + resourceModels + ", policyInstanceName=" + policyInstanceName + "]"; + } + + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyData.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyData.java new file mode 100644 index 00000000..5c328423 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyData.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model; + +public interface PolicyData { + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyEngineResponse.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyEngineResponse.java new file mode 100644 index 00000000..0707cd34 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/PolicyEngineResponse.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model; + +import java.io.Serializable; +import java.util.HashMap; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * PolicyEngineResponse.java Purpose: POJO representing policy manager get-config response + * + * @author Saurav Paira + * @version 1.0 + */ +public class PolicyEngineResponse implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + @JsonProperty("policyConfigMessage") + private String policyConfigMessage; + + @JsonProperty("policyConfigStatus") + private String policyConfigStatus; + + @JsonProperty("type") + private String type; + + @JsonProperty("config") + private String config; + + @JsonProperty("policyName") + private String policyName; + + @JsonProperty("policyType") + private String policyType; + + @JsonProperty("policyVersion") + private String policyVersion; + + @JsonProperty("matchingConditions") + private HashMap matchingConditions; + + @JsonProperty("responseAttributes") + private HashMap responseAttributes; + + @JsonProperty("property") + private String property; + + public PolicyEngineResponse() { + + } + + public String getPolicyConfigMessage() { + return policyConfigMessage; + } + public void setPolicyConfigMessage(String policyConfigMessage) { + this.policyConfigMessage = policyConfigMessage; + } + public String getPolicyConfigStatus() { + return policyConfigStatus; + } + public void setPolicyConfigStatus(String policyConfigStatus) { + this.policyConfigStatus = policyConfigStatus; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getConfig() { + return config; + } + @JsonProperty("config") + public void setConfig(String config) { + this.config = config; + } + public String getPolicyName() { + return policyName; + } + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + public String getPolicyType() { + return policyType; + } + public void setPolicyType(String type) { + this.policyType = type; + } + public String getPolicyVersion() { + return policyVersion; + } + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + public HashMap getMatchingConditions() { + return matchingConditions; + } + @JsonProperty("matchingConditions") + public void setMatchingConditions(HashMap matchingConditions) { + this.matchingConditions = matchingConditions; + } + public HashMap getResponseAttributes() { + return responseAttributes; + } + public void setResponseAttributes(HashMap responseAttributes) { + this.responseAttributes = responseAttributes; + } + public String getProperty() { + return property; + } + public void setProperty(String property) { + this.property = property; + } + + @Override + public String toString() { + return "PolicyEngineResponse [policyConfigMessage=" + policyConfigMessage + ", policyConfigStatus=" + + policyConfigStatus + ", type=" + type + ", config=" + config + ", policyName=" + policyName + + ", policyType=" + policyType + ", policyVersion=" + policyVersion + ", matchingConditions=" + + matchingConditions + ", responseAttributes=" + responseAttributes + ", property=" + property + "]"; + } + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/RequestObject.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/RequestObject.java new file mode 100644 index 00000000..bd2fd6e0 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/RequestObject.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model; + +/** + * RequestObject.java Purpose: POJO representing policy manager get-config request + * + * @author Saurav Paira + * @version 1.0 + */ +public class RequestObject { + + private String policyName; + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + @Override + public String toString() { + return "RequestObject [policyName=" + policyName + "]"; + } + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/ResourceModel.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/ResourceModel.java new file mode 100644 index 00000000..8f865f9e --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/extinf/pm/model/ResourceModel.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * ResourceModel.java Purpose: POJO representing policy manager get-config response Resource Model + * + * @author Saurav Paira + * @version 1.0 + */ +@JsonDeserialize(as = ResourceModel.class) +public class ResourceModel implements PolicyData { + + @JsonProperty("key-type") + private String keyType; + + @JsonProperty("scope") + private String scope; + + @JsonProperty("resource-resolution-recipe") + private String resourceResolutionRecipe; + + @JsonProperty("resource-name") + private String resourceName; + + @JsonProperty("data-store-object") + private String dataStoreObject; + + @JsonProperty("data-store") + private String dataStore; + + @JsonProperty("elements") + private List elements; + + @JsonProperty("resource-vlan-role") + private String resourceVlanRole; + + @JsonProperty("vlan-type") + private String vlanType; + + + public String getKeyType() { + return keyType; + } + + public void setKeyType(String keyType) { + this.keyType = keyType; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getResourceResolutionRecipe() { + return resourceResolutionRecipe; + } + + public void setResourceResolutionRecipe(String resourceResolutionRecipe) { + this.resourceResolutionRecipe = resourceResolutionRecipe; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getDataStoreObject() { + return dataStoreObject; + } + + public void setDataStoreObject(String dataStoreObject) { + this.dataStoreObject = dataStoreObject; + } + + public String getDataStore() { + return dataStore; + } + + public void setDataStore(String dataStore) { + this.dataStore = dataStore; + } + + public List getElements() { + return elements; + } + + public void setElements(List elements) { + this.elements = elements; + } + + public String getResourceVlanRole() { + return resourceVlanRole; + } + + public void setResourceVlanRole(String resourceVlanRole) { + this.resourceVlanRole = resourceVlanRole; + } + + + public String getVlanType() { + return vlanType; + } + + public void setVlanType(String vlanType) { + this.vlanType = vlanType; + } + + @Override + public String toString() { + return "ResourceModel [keyType=" + keyType + ", scope=" + scope + ", resourceResolutionRecipe=" + + resourceResolutionRecipe + ", resourceName=" + resourceName + ", dataStoreObject=" + dataStoreObject + + ", dataStore=" + dataStore + ", elements=" + elements + ", resourceVlanRole=" + resourceVlanRole + + ", vlanType=" + vlanType + "]"; + } + + + + + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagRequest.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagRequest.java new file mode 100644 index 00000000..4b7a7146 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagRequest.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.validation.Valid; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.swagger.annotations.ApiModelProperty; + +/** + * AssignVlanTagRequest.java Purpose: Provide Assign VlanTag Request Model + * + * @author Saurav Paira + * @version 1.0 + */ +public class AssignVlanTagRequest { + + private @Valid List input = new ArrayList(); + + /** + **/ + public AssignVlanTagRequest input(List input) { + this.input = input; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("input") + public List getInput() { + return input; + } + public void setInput(List input) { + this.input = input; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AssignVlanTagRequest assignVlanTagRequest = (AssignVlanTagRequest) o; + return Objects.equals(input, assignVlanTagRequest.input); + } + + @Override + public int hashCode() { + return Objects.hash(input); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class AssignVlanTagRequest {\n"); + + sb.append(" input: ").append(toIndentedString(input)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagRequestInput.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagRequestInput.java new file mode 100644 index 00000000..682ba122 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagRequestInput.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.model; + +import javax.validation.Valid; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.swagger.annotations.ApiModelProperty; + +/** + * AssignVlanTagRequestInput.java Purpose: Provide Assign VlanTag Request Input Model + * + * @author Saurav Paira + * @version 1.0 + */ +public class AssignVlanTagRequestInput { + private @Valid String policyInstanceName = null; + private @Valid String resourceName = null; + private @Valid String resourceValue = null; + private @Valid String scopeId = null; + private @Valid String key = null; + private @Valid String vlanType = null; + + + public AssignVlanTagRequestInput policyInstanceName(String policyInstanceName) { + this.policyInstanceName = policyInstanceName; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("policy-instance-name") + public String getPolicyInstanceName() { + return policyInstanceName; + } + + public void setPolicyInstanceName(String policyInstanceName) { + this.policyInstanceName = policyInstanceName; + } + + /** + **/ + public AssignVlanTagRequestInput resourceName(String resourceName) { + this.resourceName = resourceName; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("resource-name") + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + /** + **/ + public AssignVlanTagRequestInput resourceValue(String resourceValue) { + this.resourceValue = resourceValue; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("resource-value") + public String getResourceValue() { + return resourceValue; + } + + public void setResourceValue(String resourceValue) { + this.resourceValue = resourceValue; + } + + /** + **/ + public AssignVlanTagRequestInput scopeId(String scopeId) { + this.scopeId = scopeId; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("scope-id") + public String getScopeId() { + return scopeId; + } + + public void setScopeId(String scopeId) { + this.scopeId = scopeId; + } + + /** + **/ + public AssignVlanTagRequestInput key(String key) { + this.key = key; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("key") + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + /** + **/ + public AssignVlanTagRequestInput vlanType(String vlanType) { + this.vlanType = vlanType; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("vlan-type") + public String getVlanType() { + return vlanType; + } + + public void setVlanType(String vlanType) { + this.vlanType = vlanType; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AssignVlanTagRequestInput assignVlanTagRequestInput = (AssignVlanTagRequestInput) o; + return Objects.equals(policyInstanceName, assignVlanTagRequestInput.policyInstanceName) + && Objects.equals(resourceName, assignVlanTagRequestInput.resourceName) + && Objects.equals(resourceValue, assignVlanTagRequestInput.resourceValue) + && Objects.equals(scopeId, assignVlanTagRequestInput.scopeId) + && Objects.equals(key, assignVlanTagRequestInput.key) + && Objects.equals(vlanType, assignVlanTagRequestInput.vlanType); + } + + @Override + public int hashCode() { + return Objects.hash(policyInstanceName, resourceName, resourceValue, scopeId, key, vlanType); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class AssignVlanTagRequestInput {\n"); + + sb.append(" policyInstanceName: ").append(toIndentedString(policyInstanceName)).append("\n"); + sb.append(" resourceName: ").append(toIndentedString(resourceName)).append("\n"); + sb.append(" resourceValue: ").append(toIndentedString(resourceValue)).append("\n"); + sb.append(" scopeId: ").append(toIndentedString(scopeId)).append("\n"); + sb.append(" key: ").append(toIndentedString(key)).append("\n"); + sb.append(" vlanType: ").append(toIndentedString(vlanType)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagResponse.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagResponse.java new file mode 100644 index 00000000..5b5ea5c4 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagResponse.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.validation.Valid; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.swagger.annotations.ApiModelProperty; + +/** + * AssignVlanTagResponse.java Purpose: Provide Assign VlanTag Response Model + * + * @author Saurav Paira + * @version 1.0 + */ +public class AssignVlanTagResponse { + + private @Valid List output = new ArrayList(); + private @Valid Integer errorCode = null; + private @Valid String errorMessage = null; + + public AssignVlanTagResponse() {} + + /** + **/ + public AssignVlanTagResponse output(List output) { + this.output = output; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("output") + public List getOutput() { + return output; + } + + public void setOutput(List output) { + this.output = output; + } + + /** + **/ + public AssignVlanTagResponse errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("error-code") + public Integer getErrorCode() { + return errorCode; + } + + public void setErrorCode(Integer errorCode) { + this.errorCode = errorCode; + } + + /** + **/ + public AssignVlanTagResponse errorMessage(String errorMessage) { + this.errorMessage = errorMessage; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("error-message") + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AssignVlanTagResponse assignVlanTagResponse = (AssignVlanTagResponse) o; + return Objects.equals(errorCode, assignVlanTagResponse.errorCode) + && Objects.equals(errorMessage, assignVlanTagResponse.errorMessage) + && Objects.equals(output, assignVlanTagResponse.output); + } + + @Override + public int hashCode() { + return Objects.hash(output, errorCode, errorMessage); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class AssignVlanTagResponse {\n"); + + sb.append(" output: ").append(toIndentedString(output)).append("\n"); + sb.append(" errorCode: ").append(toIndentedString(errorCode)).append("\n"); + sb.append(" errorMessage: ").append(toIndentedString(errorMessage)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagResponseOutput.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagResponseOutput.java new file mode 100644 index 00000000..b8b186b6 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/AssignVlanTagResponseOutput.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.validation.Valid; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.swagger.annotations.ApiModelProperty; + +/** + * AssignVlanTagResponseOutput.java Purpose: Provide Assign VlanTag Response Output Model + * + * @author Saurav Paira + * @version 1.0 + */ +public class AssignVlanTagResponseOutput { + + private @Valid String resourceName = null; + private @Valid String resourceValue = null; + private @Valid String resourceVlanRole = null; + private @Valid List storedElements = new ArrayList(); + + /** + **/ + public AssignVlanTagResponseOutput resourceName(String resourceName) { + this.resourceName = resourceName; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("resource-name") + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + /** + **/ + public AssignVlanTagResponseOutput resourceValue(String resourceValue) { + this.resourceValue = resourceValue; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("resource-value") + public String getResourceValue() { + return resourceValue; + } + + public void setResourceValue(String resourceValue) { + this.resourceValue = resourceValue; + } + + /** + **/ + public AssignVlanTagResponseOutput resourceVlanRole(String resourceVlanRole) { + this.resourceVlanRole = resourceVlanRole; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("resource-vlan-role") + public String getResourceVlanRole() { + return resourceVlanRole; + } + + public void setResourceVlanRole(String resourceVlanRole) { + this.resourceVlanRole = resourceVlanRole; + } + + /** + **/ + public AssignVlanTagResponseOutput storedElements(List storedElements) { + this.storedElements = storedElements; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("stored-elements") + public List getStoredElements() { + return storedElements; + } + + public void setStoredElements(List storedElements) { + this.storedElements = storedElements; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AssignVlanTagResponseOutput assignVlanTagResponseOutput = (AssignVlanTagResponseOutput) o; + return Objects.equals(resourceName, assignVlanTagResponseOutput.resourceName) + && Objects.equals(resourceValue, assignVlanTagResponseOutput.resourceValue) + && Objects.equals(resourceVlanRole, assignVlanTagResponseOutput.resourceVlanRole) + && Objects.equals(storedElements, assignVlanTagResponseOutput.storedElements); + } + + @Override + public int hashCode() { + return Objects.hash(resourceName, resourceValue, resourceVlanRole, storedElements); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class AssignVlanTagResponseOutput {\n"); + + sb.append(" resourceName: ").append(toIndentedString(resourceName)).append("\n"); + sb.append(" resourceValue: ").append(toIndentedString(resourceValue)).append("\n"); + sb.append(" resourceVlanRole: ").append(toIndentedString(resourceVlanRole)).append("\n"); + sb.append(" storedElements: ").append(toIndentedString(storedElements)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/PingResponse.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/PingResponse.java new file mode 100644 index 00000000..d8ea0ecf --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/PingResponse.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.model; + +/** + * PingResponse.java Purpose: Provide VlanTag API Ping Response Model + * + * @author Saurav Paira + * @version 1.0 + */ +public class PingResponse { + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + private String message; + + public PingResponse() { + + } + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagRequest.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagRequest.java new file mode 100644 index 00000000..aa2f0ef9 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagRequest.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.validation.Valid; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.swagger.annotations.ApiModelProperty; + +/** + * UnassignVlanTagRequest.java Purpose: Provide Unassign VlanTag Request Model + * + * @author Saurav Paira + * @version 1.0 + */ +public class UnassignVlanTagRequest { + + private @Valid List input = new ArrayList(); + + /** + **/ + public UnassignVlanTagRequest input(List input) { + this.input = input; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("input") + public List getInput() { + return input; + } + + public void setInput(List input) { + this.input = input; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + UnassignVlanTagRequest unassignVlanTagRequest = (UnassignVlanTagRequest) o; + return Objects.equals(input, unassignVlanTagRequest.input); + } + + @Override + public int hashCode() { + return Objects.hash(input); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class UnassignVlanTagRequest {\n"); + + sb.append(" input: ").append(toIndentedString(input)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagRequestInput.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagRequestInput.java new file mode 100644 index 00000000..64cc9113 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagRequestInput.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.model; + +import java.util.Objects; + +import javax.validation.Valid; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.swagger.annotations.ApiModelProperty; + +/** + * UnassignVlanTagRequestInput.java Purpose: Provide Unassign VlanTag Request Input Model + * + * @author Saurav Paira + * @version 1.0 + */ +public class UnassignVlanTagRequestInput { + + private @Valid String policyInstanceName = null; + private @Valid String vlanType = null; + private @Valid String key = null; + + /** + **/ + public UnassignVlanTagRequestInput policyInstanceName(String policyInstanceName) { + this.policyInstanceName = policyInstanceName; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("policy-instance-name") + public String getPolicyInstanceName() { + return policyInstanceName; + } + + public void setPolicyInstanceName(String policyInstanceName) { + this.policyInstanceName = policyInstanceName; + } + + /** + **/ + public UnassignVlanTagRequestInput vlanType(String vlanType) { + this.vlanType = vlanType; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("vlan-type") + public String getVlanType() { + return vlanType; + } + + public void setVlanType(String vlanType) { + this.vlanType = vlanType; + } + + /** + **/ + public UnassignVlanTagRequestInput key(String key) { + this.key = key; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("key") + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + UnassignVlanTagRequestInput unassignVlanTagRequestInput = (UnassignVlanTagRequestInput) o; + return Objects.equals(policyInstanceName, unassignVlanTagRequestInput.policyInstanceName) + && Objects.equals(vlanType, unassignVlanTagRequestInput.vlanType) + && Objects.equals(key, unassignVlanTagRequestInput.key); + } + + @Override + public int hashCode() { + return Objects.hash(policyInstanceName, vlanType, key); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class UnassignVlanTagRequestInput {\n"); + + sb.append(" policyInstanceName: ").append(toIndentedString(policyInstanceName)).append("\n"); + sb.append(" vlanType: ").append(toIndentedString(vlanType)).append("\n"); + sb.append(" key: ").append(toIndentedString(key)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagResponse.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagResponse.java new file mode 100644 index 00000000..2bc95daa --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagResponse.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.validation.Valid; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.swagger.annotations.ApiModelProperty; + +/** + * UnassignVlanTagResponse.java Purpose: Provide Unassign VlanTag Response Model + * + * @author Saurav Paira + * @version 1.0 + */ +public class UnassignVlanTagResponse { + private @Valid List output = new ArrayList(); + private @Valid Integer errorCode = null; + private @Valid String errorMessage = null; + + /** + **/ + public UnassignVlanTagResponse output(List output) { + this.output = output; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("output") + public List getOutput() { + return output; + } + + public void setOutput(List output) { + this.output = output; + } + + /** + **/ + public UnassignVlanTagResponse errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("error-code") + public Integer getErrorCode() { + return errorCode; + } + + public void setErrorCode(Integer errorCode) { + this.errorCode = errorCode; + } + + /** + **/ + public UnassignVlanTagResponse errorMessage(String errorMessage) { + this.errorMessage = errorMessage; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("error-message") + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + UnassignVlanTagResponse unassignVlanTagResponse = (UnassignVlanTagResponse) o; + return Objects.equals(output, unassignVlanTagResponse.output) + && Objects.equals(errorCode, unassignVlanTagResponse.errorCode) + && Objects.equals(errorMessage, unassignVlanTagResponse.errorMessage); + } + + @Override + public int hashCode() { + return Objects.hash(output, errorCode, errorMessage); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class UnassignVlanTagResponse {\n"); + + sb.append(" output: ").append(toIndentedString(output)).append("\n"); + sb.append(" errorCode: ").append(toIndentedString(errorCode)).append("\n"); + sb.append(" errorMessage: ").append(toIndentedString(errorMessage)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagResponseOutput.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagResponseOutput.java new file mode 100644 index 00000000..65420b94 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/UnassignVlanTagResponseOutput.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.model; + +import java.util.Objects; + +import javax.validation.Valid; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.swagger.annotations.ApiModelProperty; + +/** + * UnassignVlanTagResponseOutput.java Purpose: Provide Unassign VlanTag Response Output Model + * + * @author Saurav Paira + * @version 1.0 + */ +public class UnassignVlanTagResponseOutput { + private @Valid String vlanType = null; + private @Valid String key = null; + private @Valid String vlantagName = null; + + /** + **/ + public UnassignVlanTagResponseOutput vlanType(String vlanType) { + this.vlanType = vlanType; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("vlan-type") + public String getVlanType() { + return vlanType; + } + + public void setVlanType(String vlanType) { + this.vlanType = vlanType; + } + + /** + **/ + public UnassignVlanTagResponseOutput key(String key) { + this.key = key; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("key") + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + /** + **/ + public UnassignVlanTagResponseOutput vlantagName(String vlantagName) { + this.vlantagName = vlantagName; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("vlantag-name") + public String getVlantagName() { + return vlantagName; + } + + public void setVlantagName(String vlantagName) { + this.vlantagName = vlantagName; + } + + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + UnassignVlanTagResponseOutput unassignVlanTagResponseOutput = (UnassignVlanTagResponseOutput) o; + return Objects.equals(vlanType, unassignVlanTagResponseOutput.vlanType) + && Objects.equals(key, unassignVlanTagResponseOutput.key) + && Objects.equals(vlantagName, unassignVlanTagResponseOutput.vlantagName); + } + + @Override + public int hashCode() { + return Objects.hash(vlanType, key, vlantagName); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class UnassignVlanTagResponseOutput {\n"); + + sb.append(" vlanType: ").append(toIndentedString(vlanType)).append("\n"); + sb.append(" key: ").append(toIndentedString(key)).append("\n"); + sb.append(" vlantagName: ").append(toIndentedString(vlantagName)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/VlanTag.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/VlanTag.java new file mode 100644 index 00000000..1a207fd7 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/model/VlanTag.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.model; + +import java.util.Objects; + +import javax.validation.Valid; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import io.swagger.annotations.ApiModelProperty; + +/** + * VlanTag.java Purpose: Provide VlanTag Model for the Assign Response Output + * + * @author Saurav Paira + * @version 1.0 + */ +public class VlanTag { + + private @Valid String vlanUuid = null; + private @Valid String vlantagName = null; + private @Valid String vlantagValue = null; + private @Valid String elementVlanRole = null; + + /** + **/ + public VlanTag vlanUuid(String vlanUuid) { + this.vlanUuid = vlanUuid; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("vlan-uuid") + public String getVlanUuid() { + return vlanUuid; + } + + public void setVlanUuid(String vlanUuid) { + this.vlanUuid = vlanUuid; + } + + /** + **/ + public VlanTag vlantagName(String vlantagName) { + this.vlantagName = vlantagName; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("vlantag-name") + public String getVlantagName() { + return vlantagName; + } + + public void setVlantagName(String vlantagName) { + this.vlantagName = vlantagName; + } + + /** + **/ + public VlanTag vlantagValue(String vlantagValue) { + this.vlantagValue = vlantagValue; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("vlantag-value") + public String getVlantagValue() { + return vlantagValue; + } + + public void setVlantagValue(String vlantagValue) { + this.vlantagValue = vlantagValue; + } + + /** + **/ + public VlanTag elementVlanRole(String elementVlanRole) { + this.elementVlanRole = elementVlanRole; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("element-vlan-role") + public String getElementVlanRole() { + return elementVlanRole; + } + + public void setElementVlanRole(String elementVlanRole) { + this.elementVlanRole = elementVlanRole; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + VlanTag vlanTag = (VlanTag) o; + return Objects.equals(vlanUuid, vlanTag.vlanUuid) && Objects.equals(vlantagName, vlanTag.vlantagName) + && Objects.equals(vlantagValue, vlanTag.vlantagValue) + && Objects.equals(elementVlanRole, vlanTag.elementVlanRole); + } + + @Override + public int hashCode() { + return Objects.hash(vlanUuid, vlantagName, vlantagValue, elementVlanRole); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class VlanTag {\n"); + + sb.append(" vlanUuid: ").append(toIndentedString(vlanUuid)).append("\n"); + sb.append(" vlantagName: ").append(toIndentedString(vlantagName)).append("\n"); + sb.append(" vlantagValue: ").append(toIndentedString(vlantagValue)).append("\n"); + sb.append(" elementVlanRole: ").append(toIndentedString(elementVlanRole)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiService.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiService.java new file mode 100644 index 00000000..800346a7 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiService.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.service; + +import javax.validation.Valid; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.onap.ccsdk.apps.ms.vlantagapi.core.exception.VlantagApiException; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.AssignVlanTagRequest; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.AssignVlanTagResponse; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.PingResponse; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.UnassignVlanTagRequest; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.UnassignVlanTagResponse; + +/** + * VlantagApiService.java Purpose: Provide Vlantag Assignment & UnAssignment + * APIs interface for VNFs + * + * @author Saurav Paira + * @version 1.0 + */ +@Path("/") +public interface VlantagApiService { + + /** + * This is a assignVlanTag service to assign Vlantags based on the + * AssignVlanTagRequest and Policy instance. + * + * @param AssignVlanTagRequest + * @return AssignVlanTagResponse + */ + @POST + @Path("/v1/assign") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + AssignVlanTagResponse assignVlanTag(@Valid AssignVlanTagRequest body) throws VlantagApiException, Exception; + + /** + * This is a unassignVlanTag service to unassign Vlantags based on the + * UnassignVlanTagRequest and Policy instance. + * + * @param UnassignVlanTagRequest + * @return UnassignVlanTagResponse + */ + @POST + @Path("/v1/unassign") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + UnassignVlanTagResponse unassignVlanTag(@Valid UnassignVlanTagRequest body) throws VlantagApiException, Exception; + + /** + * This is a ping service to check the Vlantag Api is Up and running. + * + * @param name + * @return PingResponse + */ + @GET + @Path("/v1/ping/{name}") + @Produces(MediaType.APPLICATION_JSON) + PingResponse getPing(@PathParam("name") String name); + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiServiceImpl.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiServiceImpl.java new file mode 100644 index 00000000..3b79cdc1 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/service/VlantagApiServiceImpl.java @@ -0,0 +1,561 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.core.service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import org.onap.ccsdk.apps.ms.vlantagapi.core.exception.VlantagApiException; +import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.AllowedRanges; +import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.Elements; +import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.ResourceModel; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.AssignVlanTagRequest; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.AssignVlanTagRequestInput; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.AssignVlanTagResponse; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.AssignVlanTagResponseOutput; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.PingResponse; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.UnassignVlanTagRequest; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.UnassignVlanTagRequestInput; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.UnassignVlanTagResponse; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.UnassignVlanTagResponseOutput; +import org.onap.ccsdk.apps.ms.vlantagapi.core.model.VlanTag; +import org.onap.ccsdk.apps.ms.vlantagapi.extinf.pm.PolicyManagerClient; +import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator; +import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceEntity; +import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceRequest; +import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse; +import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceTarget; +import org.onap.ccsdk.sli.adaptors.rm.data.AllocationStatus; +import org.onap.ccsdk.sli.adaptors.rm.data.Range; +import org.onap.ccsdk.sli.adaptors.rm.data.ResourceType; +import org.onap.ccsdk.sli.adaptors.util.str.StrUtil; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * VlantagApiServiceImpl.java Purpose: Provide Vlantag Assignment & UnAssignment + * APIs service implementation for VNFs + * + * @author Saurav Paira + * @version 1.0 + */ +@Service +public class VlantagApiServiceImpl implements VlantagApiService { + + private static final VlantagApiService INSTANCE = new VlantagApiServiceImpl(); + private static final Logger log = LoggerFactory.getLogger(VlantagApiServiceImpl.class); + private static final String BEGIN_SQUAREBRACKET_RC = "#BSB#"; + private static final String END_SQUAREBRACKET_RC = "#ESB#"; + + @Autowired + private ResourceAllocator resourceAllocator; + @Autowired + private PolicyManagerClient policyClient; + + public static VlantagApiService getInstance() { + return INSTANCE; + } + + /** + * This is a assignVlanTag service implementation to assign Vlantags based on the + * AssignVlanTagRequest and Policy instance. + * + * @param AssignVlanTagRequest + * @return AssignVlanTagResponse + */ + @Override + public AssignVlanTagResponse assignVlanTag(AssignVlanTagRequest request) throws Exception { + List outputList = new ArrayList<>(); + + try { + validateRequest(request); + List vlanTagRequests = request.getInput(); + + List reservedResources = new ArrayList<>(); + + for (AssignVlanTagRequestInput input : vlanTagRequests) { + log.info("PolicyManagerClient called..for policy : {}", input.getPolicyInstanceName()); + + List resourceModels = policyClient.getPolicy(input.getPolicyInstanceName()); + ResourceModel model = validate(resourceModels, input); + List rl = new ArrayList<>(); + + for (Elements elements : model.getElements()) { + + ResourceEntity re = new ResourceEntity(); + ResourceTarget rt = new ResourceTarget(); + ResourceRequest rr = new ResourceRequest(); + List rsList = new ArrayList<>(); + + prepareResourceAllocatorObjects(input, model, elements, re, rt, rr); + + if (resourceAllocator != null) { + AllocationStatus status = resourceAllocator.reserve(re, rt, rr, rsList); + + if (AllocationStatus.Success.equals(status)) + rl.addAll(rsList); + else { + rollbackVlanTags(reservedResources); + throw new VlantagApiException( + "Failed to reserve VlanTags for Element : {}. " + elements.getVlantagName() + + ". Rolling back vlantags for other elements (if any)."); + } + } else + throw new VlantagApiException( + "ResourceAllocator not available. Failed to Assign VlanTags for Element : " + + elements.getVlantagName() + + ". Rolling back vlantags for other elements (if any)."); + + } + reservedResources.add(input); + outputList.add(prepareVlanTagResponse(input, model, rl)); + } + + } catch (Exception e) { + log.error("Exception : " + e.getMessage(), e); + + AssignVlanTagResponse response = new AssignVlanTagResponse(); + response.setErrorCode(500); + response.setErrorMessage(e.getMessage()); + return response; + } + + AssignVlanTagResponse response = new AssignVlanTagResponse(); + response.setErrorCode(200); + response.setErrorMessage("Success"); + response.setOutput(outputList); + return response; + } + + private void prepareResourceAllocatorObjects(AssignVlanTagRequestInput input, ResourceModel model, Elements element, + ResourceEntity re, ResourceTarget rt, ResourceRequest rr) throws VlantagApiException { + log.info("Preparing RA Objects for Vlan Type : " + input.getVlanType() + " and Element : " + + element.getVlantagName()); + re.resourceEntityId = input.getKey(); + re.resourceEntityType = model.getKeyType() == null ? "DEFAULT" : model.getKeyType(); + re.resourceEntityVersion = "1"; + + rt.resourceTargetId = input.getScopeId(); + rt.resourceTargetType = model.getScope() == null ? "DEFAULT" : model.getScope(); + + rr.resourceName = input.getVlanType(); + rr.serviceModel = input.getPolicyInstanceName(); + rr.endPointPosition = element.getVlantagName(); + rr.resourceType = ResourceType.Range; + rr.applicationId = "SDNC"; + rr.rangeMaxOverride = -1; + rr.rangeMinOverride = -1; + + List rangeList = new ArrayList<>(); + for (AllowedRanges allowedRange : element.getAllowedRanges()) { + Range range = new Range(); + + if (allowedRange.getMin() != null && !allowedRange.getMin().isEmpty()) + range.min = Integer.parseInt(allowedRange.getMin()); + + if (allowedRange.getMax() != null && !allowedRange.getMax().isEmpty()) + range.max = Integer.parseInt(allowedRange.getMax()); + + rangeList.add(range); + } + + rr.rangeOverrideList = rangeList; + + String resourceValue = resolveResourceElementValue(input, model, element); + if (resourceValue != null) { + rr.rangeRequestedNumbers = resourceValue; /* Manually provided values */ + + /* + * If the override flag is TRUE, then add the resource value also in the range, + * so it will ignore the current range min-max in the policy. Persist in the DB + * if available else Fail. + */ + if (element.getOverwrite() != null && element.getOverwrite().equalsIgnoreCase("TRUE")) { + Range range = new Range(); + range.min = Integer.parseInt(resourceValue); + rangeList.add(range); + } + } + + StrUtil.info(log, re); + StrUtil.info(log, rt); + StrUtil.info(log, rr); + + } + + protected String resolveResourceElementValue(AssignVlanTagRequestInput input, ResourceModel model, Elements element) + throws VlantagApiException { + String recipe = trimBrackets(model.getResourceResolutionRecipe().trim()); + + if (input.getResourceValue() != null && !input.getResourceValue().trim().isEmpty() + && !input.getResourceValue().contains("$")) { + log.info("Resource Value : " + input.getResourceValue()); + String resourceValue = trimBrackets(input.getResourceValue()); + + String[] vlantagNames = recipe.split(","); + String[] resourceValues = resourceValue.split(","); + + try { + for (int i = 0; i < vlantagNames.length; i++) { + if (vlantagNames[i].trim().equalsIgnoreCase(element.getVlantagName().trim())) + return resourceValues[i].trim(); + } + } catch (IndexOutOfBoundsException e) { + throw new VlantagApiException("No Matching Resource Value found from Recipe : \"" + + model.getResourceResolutionRecipe() + "\" for Vlantag Name : " + element.getVlantagName()); + } + + } + return null; + } + + ResourceModel validate(List resourceModels, AssignVlanTagRequestInput input) + throws VlantagApiException { + ResourceModel targetModel = null; + if (resourceModels != null && !resourceModels.isEmpty()) { + for (ResourceModel model : resourceModels) { + if (model.getVlanType().equals(input.getVlanType())) { + targetModel = model; + break; + } + } + validateModel(targetModel, input); + } else + throw new VlantagApiException("No Resource Models available in Policy Manager for Policy Instance Name : " + + input.getPolicyInstanceName()); + return targetModel; + } + + void validateModel(ResourceModel model, AssignVlanTagRequestInput input) throws VlantagApiException { + + if (model == null) + throw new VlantagApiException( + "No Matching Policy Resource Model found for Vlan Type : " + input.getVlanType()); + else { + if (model.getResourceResolutionRecipe() == null || model.getResourceResolutionRecipe().isEmpty()) + throw new VlantagApiException( + "Resource Resolution Recipe is null in Resource Model for Vlan Type : " + input.getVlanType()); + + if (model.getScope() == null || model.getScope().isEmpty()) + throw new VlantagApiException("Scope is null in Resource Model for Vlan Type : " + input.getVlanType()); + + List elements = model.getElements(); + validateElements(elements, input); + } + + } + + void validateElements(List elements, AssignVlanTagRequestInput input) throws VlantagApiException { + if (elements != null && !elements.isEmpty()) { + for (Elements element : elements) { + if (element.getVlantagName() == null) + throw new VlantagApiException( + "Vlantag Name missing for Element in Resource Model Policy for Vlan Type : " + + input.getVlanType()); + if (element.getAllowedRanges() == null || element.getAllowedRanges().isEmpty()) + throw new VlantagApiException( + "Allowed Ranges missing for Element in Resource Model Policy for Vlan Type : " + + input.getVlanType()); + } + } else + throw new VlantagApiException( + "No Vlantag Elements found in Resource Model Policy for Vlan Type : " + input.getVlanType()); + + } + + PolicyManagerClient getPolicyManagerClient() { + return new PolicyManagerClient(); + } + + void validateRequest(AssignVlanTagRequest request) throws VlantagApiException { + if (request == null) + throw new VlantagApiException("VlanTag Assign Request is null."); + + List inputList = request.getInput(); + + if (inputList == null || inputList.isEmpty()) + throw new VlantagApiException("VlanTag Assign Request Input is null or empty."); + + for (AssignVlanTagRequestInput input : inputList) { + if (input.getPolicyInstanceName() == null || input.getPolicyInstanceName().isEmpty()) + throw new VlantagApiException("VlanTag Assign Request policy-instance-name is null."); + + if (input.getVlanType() == null || input.getVlanType().isEmpty()) + throw new VlantagApiException("VlanTag Assign Request vlan-type is null."); + + if (input.getScopeId() == null || input.getScopeId().isEmpty()) + throw new VlantagApiException("VlanTag Assign Request scope-id is null."); + + if (input.getKey() == null || input.getKey().isEmpty()) + throw new VlantagApiException("VlanTag Assign Request key is null."); + } + + } + + private AssignVlanTagResponseOutput prepareVlanTagResponse(AssignVlanTagRequestInput input, ResourceModel model, + List rl) { + AssignVlanTagResponseOutput ro = new AssignVlanTagResponseOutput(); + List vlanTagList = new ArrayList<>(); + + if (rl != null && !rl.isEmpty()) { + ro.setResourceName(input.getResourceName()); + ro.setResourceValue(resolveRecipe(model, rl)); + ro.setResourceVlanRole(model.getResourceVlanRole()); + if (model.getDataStore() != null && !model.getDataStore().isEmpty()) { + for (ResourceResponse rr : rl) { + VlanTag tag = new VlanTag(); + Optional optionalElements = model.getElements().stream() + .filter(element -> element.getVlantagName().equalsIgnoreCase(rr.endPointPosition)) + .findFirst(); + optionalElements.ifPresent(element -> tag.setElementVlanRole(element.getElementVlanRole())); + + tag.setVlanUuid(UUID.randomUUID().toString()); + tag.setVlantagName(rr.endPointPosition); + tag.setVlantagValue(rr.resourceAllocated); + vlanTagList.add(tag); + } + + } + ro.setStoredElements(vlanTagList); + } + + return ro; + } + + protected String resolveRecipe(ResourceModel model, List rl) { + String recipe = model.getResourceResolutionRecipe().trim(); + String resourceValue = recipe; + + if (recipe.contains(BEGIN_SQUAREBRACKET_RC)) { + recipe = recipe.replace(BEGIN_SQUAREBRACKET_RC, ""); + resourceValue = resourceValue.replace(BEGIN_SQUAREBRACKET_RC, "[ "); + } + + if (recipe.contains(END_SQUAREBRACKET_RC)) { + recipe = recipe.replace(END_SQUAREBRACKET_RC, ""); + resourceValue = resourceValue.replace(END_SQUAREBRACKET_RC, " ]"); + } + + String[] vlantagNames = recipe.split(","); + + for (String vlantagName : vlantagNames) { + for (ResourceResponse rr : rl) { + if (vlantagName.trim().equalsIgnoreCase(rr.endPointPosition)) { + resourceValue = resourceValue.replace(vlantagName, " " + rr.resourceAllocated); + break; + } + } + } + + log.info(resourceValue); + + return resourceValue; + } + + private void rollbackVlanTags(List reservedResources) throws Exception { + UnassignVlanTagRequest unassignRequest = new UnassignVlanTagRequest(); + List inputList = new ArrayList<>(); + + if (reservedResources != null && !reservedResources.isEmpty()) { + reservedResources.forEach(assignReqInput -> { + + UnassignVlanTagRequestInput input = new UnassignVlanTagRequestInput(); + input.setVlanType(assignReqInput.getVlanType()); + input.setKey(assignReqInput.getKey()); + input.setPolicyInstanceName(assignReqInput.getPolicyInstanceName()); + inputList.add(input); + }); + unassignRequest.setInput(inputList); + unassignVlanTag(unassignRequest); + } + + } + + /** + * This is a unassignVlanTag service implementation to unassign Vlantags based on the + * UnassignVlanTagRequest and Policy instance. + * + * @param UnassignVlanTagRequest + * @return UnassignVlanTagResponse + */ + @Override + public UnassignVlanTagResponse unassignVlanTag(UnassignVlanTagRequest request) throws Exception { + UnassignVlanTagResponse response = new UnassignVlanTagResponse(); + List output = new ArrayList<>(); + + try { + validateRequest(request); + List vlanTagRequests = request.getInput(); + + for (UnassignVlanTagRequestInput input : vlanTagRequests) { + List resourceModels = policyClient.getPolicy(input.getPolicyInstanceName()); + ResourceModel model = validate(resourceModels, input); + + for (Elements elements : model.getElements()) { + + ResourceEntity re = new ResourceEntity(); + re.resourceEntityId = input.getKey(); + re.resourceEntityType = model.getKeyType() == null ? "DEFAULT" : model.getKeyType(); + re.resourceEntityVersion = "1"; + + ResourceRequest rr = new ResourceRequest(); + rr.endPointPosition = elements.getVlantagName(); + + if (resourceAllocator != null) { + AllocationStatus status = resourceAllocator.release(re, rr); + + if (AllocationStatus.Success.equals(status)) { + UnassignVlanTagResponseOutput ro = new UnassignVlanTagResponseOutput(); + ro.setKey(input.getKey()); + ro.setVlanType(input.getVlanType()); + ro.setVlantagName(elements.getVlantagName()); + output.add(ro); + } else { + throw new VlantagApiException( + "Failed to release VlanTags for Element : " + elements.getVlantagName() + "."); + } + } else + throw new VlantagApiException( + "ResourceAllocator not available. Failed to Unassign VlanTags for Element : " + + elements.getVlantagName() + + ". Rolling back vlantags for other elements (if any)."); + } + } + } catch (Exception e) { + log.error("Exception : " + e.getMessage(), e); + + response.setErrorCode(500); + response.setErrorMessage(e.getMessage()); + return response; + } + + response.setOutput(output); + response.setErrorCode(200); + response.setErrorMessage("Success"); + return response; + } + + ResourceModel validate(List resourceModels, UnassignVlanTagRequestInput input) + throws VlantagApiException { + ResourceModel targetModel = null; + if (resourceModels != null && !resourceModels.isEmpty()) { + for (ResourceModel model : resourceModels) { + if (model.getVlanType().equals(input.getVlanType())) { + targetModel = model; + break; + } + } + validateModel(targetModel, input); + } else + throw new VlantagApiException("No Resource Models available in Policy Manager for Policy Instance Name : " + + input.getPolicyInstanceName()); + return targetModel; + } + + void validateModel(ResourceModel model, UnassignVlanTagRequestInput input) throws VlantagApiException { + if (model == null) + throw new VlantagApiException( + "No Matching Policy Resource Model found for Vlan Type : " + input.getVlanType()); + else { + if (model.getResourceResolutionRecipe() == null || model.getResourceResolutionRecipe().isEmpty()) + throw new VlantagApiException( + "Resource Resolution Recipe is null in Resource Model for Vlan Type : " + input.getVlanType()); + + if (model.getScope() == null || model.getScope().isEmpty()) + throw new VlantagApiException("Scope is null in Resource Model for Vlan Type : " + input.getVlanType()); + + List elements = model.getElements(); + validateElements(elements, input); + } + + } + + protected void validateElements(List elements, UnassignVlanTagRequestInput input) + throws VlantagApiException { + if (elements != null && !elements.isEmpty()) { + for (Elements element : elements) { + if (element.getVlantagName() == null) + throw new VlantagApiException( + "Vlantag Name missing for Element in Resource Model Policy for Vlan Type : " + + input.getVlanType()); + } + } else + throw new VlantagApiException( + "No Vlantag Elements found in Resource Model Policy for Vlan Type : " + input.getVlanType()); + + } + + protected void validateRequest(UnassignVlanTagRequest request) throws VlantagApiException { + if (request == null) + throw new VlantagApiException("VlanTag Unassign Request is null."); + + List inputList = request.getInput(); + if (inputList == null || inputList.isEmpty()) + throw new VlantagApiException("VlanTag Unassign Request Input is null or empty."); + + for (UnassignVlanTagRequestInput input : inputList) { + if (input.getPolicyInstanceName() == null || input.getPolicyInstanceName().isEmpty()) + throw new VlantagApiException("VlanTag Unassign Request policy-instance-name is null."); + + if (input.getVlanType() == null || input.getVlanType().isEmpty()) + throw new VlantagApiException("VlanTag Unassign Request resource-name is null."); + + if (input.getKey() == null || input.getKey().isEmpty()) + throw new VlantagApiException("VlanTag Unassign Request key is null."); + } + + } + + /** + * This is a ping service implementation to check the Vlantag Api is Up and running. + * + * @param name + * @return PingResponse + */ + @Override + public PingResponse getPing(String name) { + PingResponse ping = new PingResponse(); + ping.setMessage("Ping response : " + name + " Time : " + new Date()); + return ping; + } + + + protected void setResourceAllocator(ResourceAllocator ra) { + this.resourceAllocator = ra; + } + + protected String trimBrackets(String recipe) { + if (recipe != null) { + if (recipe.contains(BEGIN_SQUAREBRACKET_RC)) + recipe = recipe.replace(BEGIN_SQUAREBRACKET_RC, ""); + if (recipe.contains(END_SQUAREBRACKET_RC)) + recipe = recipe.replace(END_SQUAREBRACKET_RC, ""); + if (recipe.contains("[")) + recipe = recipe.replace("[", ""); + if (recipe.contains("]")) + recipe = recipe.replace("]", ""); + } + return recipe; + } + +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/extinf/pm/PolicyDataDeserializer.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/extinf/pm/PolicyDataDeserializer.java new file mode 100644 index 00000000..ebb5b296 --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/extinf/pm/PolicyDataDeserializer.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.extinf.pm; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.PolicyData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * PolicyDataDeserializer.java Purpose: + * This is a custom deserializer for "policy-data" element of the response from the Policy management REST call + * to get Policy details based on a policy name. + * + * The response will have different "child tree"s ( policy data) for different policy names. + * Each type of child is structurally, syntactically, semantically unique. + * However, there is no explicit way to identify the right child type in the "policy-data" element itself + * Hence , the hack is : assuming there is a unique property in each type of child of Policy-data, + * look for that property to determine the correct target child type to deserialize to. + * These unique properties are stored in polymorphicsRegistry and looked up against to find a match + * If a match is found, use that child type is used. + */ +public class PolicyDataDeserializer extends StdDeserializer { + + /** + * + */ + private static final long serialVersionUID = 1L; + + private static Logger log = LoggerFactory.getLogger(PolicyDataDeserializer.class); + + /* + * Keep a register of all extensions of PolicyData type by a unique attribute that distringuishes + * them from one another + */ + private Map> polymorphicsRegistry = + new HashMap<>(); + + public PolicyDataDeserializer() { + super(PolicyData.class); + } + + /* + * Method to add to the registry of PolicyData extensions by their distinguishing attribure + */ + public void registerExtendersByUniqueness(String uniqueAttribute, Class policyDataClass) { + polymorphicsRegistry.put(uniqueAttribute, policyDataClass); + } + + @Override + public PolicyData deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException { + + PolicyData retVal = null; + Class policyDataClass = null; + + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); + ObjectNode root = mapper.readTree(jp); + + //Go through all the elements in this node. If a match is found in the registry of uniqueness, + // it means we identified what extension of PolicyData we are dealing with. If no match found, return null + Iterator> elementsIterator = root.fields(); + while (elementsIterator.hasNext()) + { + Entry element=elementsIterator.next(); + String name = element.getKey(); + + if (polymorphicsRegistry.containsKey(name)) + { + policyDataClass = polymorphicsRegistry.get(name); + break; + } + } + + //If we know what child type of PolicyData we are working on , use that class to deserialize this node + // from its root. If not, throw exception + if (policyDataClass != null) { + retVal = mapper.treeToValue(root, policyDataClass); + } + else { + log.info("No matching Child of PolicyData is present in this node tree"); + } + return retVal; + } +} + diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/extinf/pm/PolicyManagerClient.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/extinf/pm/PolicyManagerClient.java new file mode 100644 index 00000000..2378584e --- /dev/null +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/extinf/pm/PolicyManagerClient.java @@ -0,0 +1,189 @@ +/******************************************************************************* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + ******************************************************************************/ +package org.onap.ccsdk.apps.ms.vlantagapi.extinf.pm; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.onap.ccsdk.apps.ms.vlantagapi.core.exception.VlantagApiException; +import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.PolicyConfig; +import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.PolicyData; +import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.PolicyEngineResponse; +import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.RequestObject; +import org.onap.ccsdk.apps.ms.vlantagapi.core.extinf.pm.model.ResourceModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +import com.fasterxml.jackson.core.Version; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; + +/** + * PolicyManagerClient.java Purpose: Client for Policy Manager applications and + * gets policies from policy manager. + * + * @author Saurav Paira + * @version 1.0 + */ +@Component +public class PolicyManagerClient { + + private static Logger log = LoggerFactory.getLogger(PolicyManagerClient.class); + + private static final String CLIENT_AUTH = "ClientAuth"; + private static final String ENVIRONMENT = "Environment"; + + private static final String POLICYMGR_URL_PN = "intf.pdp.policyengine.url"; + private static final String POLICYMGR_AUTHORIZATION_PN = "intf.pdp.policyengine.http.headers.authorization"; + private static final String POLICYMGR_CLIENTAUTH_PN = "intf.pdp.policyengine.http.headers.clientauth"; + private static final String POLICYMGR_ENVIRONMENT_PN = "intf.pdp.policyengine.http.headers.environment"; + + @Autowired + Environment env; + /* + * Main method to call to get the vlan tag selection policy data + */ + + public synchronized List getPolicy(final String policyName) throws VlantagApiException { + return getPolicyFromPDP(policyName); + } + + /* + * REST call to Policy Manager + */ + public PolicyEngineResponse[] getConfigUsingPost(RequestObject requestObject) throws VlantagApiException { + + PolicyEngineResponse[] result = null; + + String url = env.getProperty(POLICYMGR_URL_PN); + log.info("url si : {}", url); + HttpHeaders headers = getRequestHeaders(); + HttpEntity request = new HttpEntity<>(requestObject, headers); + RestTemplate restTemplate = getRestTemplate(); + + try { + ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, request, PolicyEngineResponse[].class); + result = response.getBody(); + + } catch (RestClientException rce) { + throw new VlantagApiException(rce.getLocalizedMessage()); + } + return result; + } + + private HttpHeaders getRequestHeaders() { + HttpHeaders headers = new HttpHeaders(); + //Read from application environment with appropriate profile + headers.add(HttpHeaders.AUTHORIZATION, env.getProperty(POLICYMGR_AUTHORIZATION_PN)); + headers.add(CLIENT_AUTH, env.getProperty(POLICYMGR_CLIENTAUTH_PN)); + headers.add(ENVIRONMENT, env.getProperty(POLICYMGR_ENVIRONMENT_PN)); + headers.add(HttpHeaders.ACCEPT, "application/json"); + headers.add(HttpHeaders.CONTENT_TYPE, "application/json"); + return headers; + } + + public List getPolicyFromPDP(String policyName) throws VlantagApiException { + + List retVal = null; + + try { + RequestObject requestObject = new RequestObject(); + requestObject.setPolicyName(policyName); + retVal = extractResourceModelsFromResponse(getConfigUsingPost(requestObject)); + } catch (IOException e) { + throw new VlantagApiException(e); + } + return retVal; + } + + public List extractResourceModelsFromResponse(PolicyEngineResponse[] result) + throws IOException { + + List retVal = null; + if (null != result && result.length > 0) { + + //There will be only one element in the result - confirmed with PDP developer + //Also, due to escaped duble quoted strings in the JSON, the config element will be deserialized + //as a String rather than as PolicyConfig. Which is good anyway for our processing, but FYI + // So , get the String and separately pass it through a new ObjectMapper + String configValue = result[0].getConfig(); + ObjectMapper om = getConfigDeserializerObjectMapper(); + PolicyConfig config = om.readValue(configValue, PolicyConfig.class); + retVal = config.getContent().getResourceModels(); + } + return retVal; + } + + private ObjectMapper getConfigDeserializerObjectMapper() { + + /// We need a special deserializer for Policy data. Depending on policy name sent as input, the policy data returned + // differs not only in content, but in structure too. In other words, Polymorphism!!! There will be a(n) abstract + // PolicyData and one child each for each policy. The SOLID ASSUMPTION here is that there is one unique attribute in each + // policy to distinguish it from one another. + // If that turns out to be wrong, we will need another desrialization policy and corresponding new deserializer + + PolicyDataDeserializer deserializer = new PolicyDataDeserializer(); + deserializer.registerExtendersByUniqueness("key-type", ResourceModel.class); + + SimpleModule module = new SimpleModule("PolymorphicPolicyDataDeserializerModule", + new Version(1, 0, 0, null, null, null)); + module.addDeserializer(PolicyData.class, deserializer); + + ObjectMapper om = new ObjectMapper(); + om.registerModule(module); + om.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + return om; + } + + /* + * Get appropriately decorated REST template + */ + private RestTemplate getRestTemplate() { + RestTemplate restTemplate = new RestTemplate( + new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())); + + ObjectMapper om = new ObjectMapper(); + om.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true); + om.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, true); + om.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + + MappingJackson2HttpMessageConverter convertor = new MappingJackson2HttpMessageConverter(om); + List> messageConvertors = new ArrayList<>(); + messageConvertors.add(convertor); + restTemplate.setMessageConverters(messageConvertors); + return restTemplate; + } + + public void setEnv(Environment env) { + this.env = env; + } + +} -- cgit 1.2.3-korg