1 /*******************************************************************************
\r
2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
15 ******************************************************************************/
\r
16 package org.onap.ccsdk.apps.ms.vlantagapi.core;
\r
18 import java.util.Arrays;
\r
19 import java.util.Collections;
\r
20 import java.util.HashMap;
\r
21 import java.util.List;
\r
22 import java.util.Map;
\r
24 import javax.sql.DataSource;
\r
26 import org.onap.ccsdk.sli.adaptors.lock.comp.LockHelper;
\r
27 import org.onap.ccsdk.sli.adaptors.lock.comp.LockHelperImpl;
\r
28 import org.onap.ccsdk.sli.adaptors.lock.dao.ResourceLockDao;
\r
29 import org.onap.ccsdk.sli.adaptors.lock.dao.ResourceLockDaoImpl;
\r
30 import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
\r
31 import org.onap.ccsdk.sli.adaptors.ra.alloc.DbAllocationRule;
\r
32 import org.onap.ccsdk.sli.adaptors.ra.comp.AllocationRule;
\r
33 import org.onap.ccsdk.sli.adaptors.ra.comp.EndPointAllocator;
\r
34 import org.onap.ccsdk.sli.adaptors.ra.comp.EndPointAllocatorImpl;
\r
35 import org.onap.ccsdk.sli.adaptors.ra.rule.dao.RangeRuleDao;
\r
36 import org.onap.ccsdk.sli.adaptors.ra.rule.dao.RangeRuleDaoImpl;
\r
37 import org.onap.ccsdk.sli.adaptors.ra.rule.dao.ResourceRuleDao;
\r
38 import org.onap.ccsdk.sli.adaptors.ra.rule.dao.ResourceRuleDaoImpl;
\r
39 import org.onap.ccsdk.sli.adaptors.rm.comp.ResourceManager;
\r
40 import org.onap.ccsdk.sli.adaptors.rm.comp.ResourceManagerImpl;
\r
41 import org.onap.ccsdk.sli.adaptors.rm.dao.ResourceDao;
\r
42 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.AllocationItemJdbcDao;
\r
43 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.AllocationItemJdbcDaoImpl;
\r
44 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceDaoImpl;
\r
45 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceJdbcDao;
\r
46 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceJdbcDaoImpl;
\r
47 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceLoadJdbcDao;
\r
48 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceLoadJdbcDaoImpl;
\r
49 import org.onap.ccsdk.sli.adaptors.util.db.CachedDataSourceWrap;
\r
50 import org.onap.ccsdk.sli.adaptors.util.db.DataSourceWrap;
\r
51 import org.onap.ccsdk.sli.adaptors.util.speed.SpeedUtil;
\r
52 import org.slf4j.Logger;
\r
53 import org.slf4j.LoggerFactory;
\r
54 import org.springframework.context.annotation.Bean;
\r
55 import org.springframework.context.annotation.Configuration;
\r
56 import org.springframework.jdbc.core.JdbcTemplate;
\r
57 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
\r
58 import org.springframework.stereotype.Component;
\r
61 * ResourceAssignmentInitializer.java Purpose: Represents and Initializes
\r
62 * Resource Assignment Spring Module Beans
\r
64 * @author Saurav Paira
\r
70 public class ResourceAssignmentInitializer {
\r
72 private static final Logger log = LoggerFactory.getLogger(ResourceAssignmentInitializer.class);
\r
76 public JdbcTemplate getJdbcTemplate(DataSource dataSource) {
\r
77 return new JdbcTemplate(dataSource);
\r
81 public ResourceLockDaoImpl getResourceLockDaoImpl(JdbcTemplate jdbcTemplate) {
\r
82 ResourceLockDaoImpl resourceLockDaoImpl = new ResourceLockDaoImpl();
\r
83 resourceLockDaoImpl.setJdbcTemplate(jdbcTemplate);
\r
85 return resourceLockDaoImpl;
\r
89 public LockHelperImpl getLockHelperImpl(ResourceLockDao resourceLockDao) {
\r
90 LockHelperImpl lockHelperImpl = new LockHelperImpl();
\r
91 lockHelperImpl.setLockWait(5);
\r
92 lockHelperImpl.setRetryCount(10);
\r
93 lockHelperImpl.setResourceLockDao(resourceLockDao);
\r
95 return lockHelperImpl;
\r
99 public ResourceJdbcDaoImpl getResourceJdbcDaoImpl(JdbcTemplate jdbcTemplate) {
\r
100 ResourceJdbcDaoImpl resourceJdbcDaoImpl = new ResourceJdbcDaoImpl();
\r
101 resourceJdbcDaoImpl.setJdbcTemplate(jdbcTemplate);
\r
102 return resourceJdbcDaoImpl;
\r
106 public AllocationItemJdbcDaoImpl getAllocationItemJdbcDaoImpl(JdbcTemplate jdbcTemplate) {
\r
107 AllocationItemJdbcDaoImpl allocationItemJdbcDaoImpl = new AllocationItemJdbcDaoImpl();
\r
108 allocationItemJdbcDaoImpl.setJdbcTemplate(jdbcTemplate);
\r
109 return allocationItemJdbcDaoImpl;
\r
113 public ResourceLoadJdbcDaoImpl getResourceLoadJdbcDaoImpl(JdbcTemplate jdbcTemplate) {
\r
114 ResourceLoadJdbcDaoImpl resourceLoadJdbcDaoImpl = new ResourceLoadJdbcDaoImpl();
\r
115 resourceLoadJdbcDaoImpl.setJdbcTemplate(jdbcTemplate);
\r
116 return resourceLoadJdbcDaoImpl;
\r
121 public ResourceDaoImpl getResourceDaoImpl(ResourceJdbcDao resourceJdbcDao, AllocationItemJdbcDao allocationItemJdbcDao, ResourceLoadJdbcDao resourceLoadJdbcDao) {
\r
122 ResourceDaoImpl resourceDaoImpl = new ResourceDaoImpl();
\r
123 resourceDaoImpl.setAllocationItemJdbcDao(allocationItemJdbcDao);
\r
124 resourceDaoImpl.setResourceJdbcDao(resourceJdbcDao);
\r
125 resourceDaoImpl.setResourceLoadJdbcDao(resourceLoadJdbcDao);
\r
127 return resourceDaoImpl;
\r
131 public ResourceManagerImpl getResourceManagerImpl(LockHelper lockHelper, ResourceDao resourceDao) {
\r
132 ResourceManagerImpl resourceManagerImpl = new ResourceManagerImpl();
\r
133 resourceManagerImpl.setLockHelper(lockHelper);
\r
134 resourceManagerImpl.setLockTimeout(600);
\r
135 resourceManagerImpl.setResourceDao(resourceDao);
\r
137 return resourceManagerImpl;
\r
141 public ResourceRuleDaoImpl getResourceRuleDaoImpl(JdbcTemplate jdbcTemplate) {
\r
142 ResourceRuleDaoImpl resourceRuleDaoImpl = new ResourceRuleDaoImpl();
\r
143 resourceRuleDaoImpl.setJdbcTemplate(jdbcTemplate);
\r
145 return resourceRuleDaoImpl;
\r
149 public RangeRuleDaoImpl getRangeRuleDaoImpl(JdbcTemplate jdbcTemplate) {
\r
150 RangeRuleDaoImpl rangeRuleDaoImpl = new RangeRuleDaoImpl();
\r
151 rangeRuleDaoImpl.setJdbcTemplate(jdbcTemplate);
\r
153 return rangeRuleDaoImpl;
\r
157 public ResourceAllocator getResourceAllocator(ResourceManager resourceManager, EndPointAllocator endPointAllocator, SpeedUtil speedUtil) {
\r
158 ResourceAllocator resourceAllocator = new ResourceAllocator();
\r
159 resourceAllocator.setEndPointAllocator(endPointAllocator);
\r
160 resourceAllocator.setResourceManager(resourceManager);
\r
161 resourceAllocator.setSpeedUtil(speedUtil);
\r
163 return resourceAllocator;
\r
167 public SpeedUtil getSpeedUtil() {
\r
168 return new SpeedUtil();
\r
172 public EndPointAllocatorImpl getEndPointAllocatorImpl(ResourceManager resourceManager, DbAllocationRule dbAllocationRule) {
\r
173 EndPointAllocatorImpl endPointAllocatorImpl = new EndPointAllocatorImpl();
\r
175 Map<String, List<AllocationRule>> allocationRuleMap = new HashMap<>();
\r
176 allocationRuleMap.put("DEFAULT", Arrays.asList(dbAllocationRule));
\r
178 endPointAllocatorImpl.setResourceManager(resourceManager);
\r
179 endPointAllocatorImpl.setAllocationRuleMap(allocationRuleMap);
\r
181 return endPointAllocatorImpl;
\r
185 public DbAllocationRule getDbAllocationRule(ResourceRuleDao resourceRuleDao, RangeRuleDao rangeRuleDao) {
\r
186 DbAllocationRule dbAllocationRule = new DbAllocationRule();
\r
187 dbAllocationRule.setRangeRuleDao(rangeRuleDao);
\r
188 dbAllocationRule.setResourceRuleDao(resourceRuleDao);
\r
190 return dbAllocationRule;
\r