2 * ============LICENSE_START==========================================
3 * Copyright (c) 2019 PANTHEON.tech s.r.o.
4 * ===================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
12 * OF ANY KIND, either express or implied. See the License for the specific language governing permissions and
13 * limitations under the License.
14 * ============LICENSE_END============================================
17 package org.onap.ccsdk.sli.adaptors.resource.lighty;
19 import io.lighty.core.controller.api.AbstractLightyModule;
20 import java.util.Collections;
21 import org.onap.ccsdk.sli.adaptors.lock.comp.LockHelperImpl;
22 import org.onap.ccsdk.sli.adaptors.lock.dao.ResourceLockDaoImpl;
23 import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
24 import org.onap.ccsdk.sli.adaptors.ra.ResourceLockNode;
25 import org.onap.ccsdk.sli.adaptors.ra.alloc.DbAllocationRule;
26 import org.onap.ccsdk.sli.adaptors.ra.comp.EndPointAllocatorImpl;
27 import org.onap.ccsdk.sli.adaptors.ra.rule.dao.RangeRuleDaoImpl;
28 import org.onap.ccsdk.sli.adaptors.ra.rule.dao.ResourceRuleDaoImpl;
29 import org.onap.ccsdk.sli.adaptors.rm.comp.ResourceManagerImpl;
30 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.AllocationItemJdbcDaoImpl;
31 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceDaoImpl;
32 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceJdbcDaoImpl;
33 import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceLoadJdbcDaoImpl;
34 import org.onap.ccsdk.sli.adaptors.util.db.CachedDataSourceWrap;
35 import org.onap.ccsdk.sli.adaptors.util.db.DataSourceWrap;
36 import org.onap.ccsdk.sli.adaptors.util.speed.SpeedUtil;
37 import org.onap.ccsdk.sli.core.dblib.DbLibService;
38 import org.springframework.jdbc.core.JdbcTemplate;
41 * The implementation of the {@link io.lighty.core.controller.api.LightyModule} that manages and provides services from
42 * the resource-assignment-provider artifact.
44 public class ResourceModule extends AbstractLightyModule {
46 private final DbLibService dbLibService;
48 private DataSourceWrap dataSourceWrap;
49 private CachedDataSourceWrap cachedDataSourceWrap;
50 private JdbcTemplate rmJdbcTemplate;
51 private JdbcTemplate lockJdbcTemplate;
52 private ResourceLockDaoImpl resourceLockDao;
53 private LockHelperImpl lockHelper;
54 private ResourceJdbcDaoImpl resourceJdbcDao;
55 private AllocationItemJdbcDaoImpl allocationItemJdbcDao;
56 private ResourceLoadJdbcDaoImpl resourceLoadJdbcDao;
57 private ResourceDaoImpl resourceDao;
58 private ResourceManagerImpl resourceManager;
59 private ResourceRuleDaoImpl resourceRuleDao;
60 private RangeRuleDaoImpl rangeRuleDao;
61 private ResourceAllocator resourceAllocator;
62 private ResourceLockNode resourceLockNode;
63 private SpeedUtil speedUtil;
64 private EndPointAllocatorImpl endPointAllocator;
65 private DbAllocationRule dbAllocationRule;
67 public ResourceModule(final DbLibService dbLibService) {
68 this.dbLibService = dbLibService;
72 protected boolean initProcedure() {
73 this.dataSourceWrap = new DataSourceWrap();
74 this.dataSourceWrap.setDataSource(dbLibService);
76 this.cachedDataSourceWrap = new CachedDataSourceWrap();
77 this.cachedDataSourceWrap.setDataSource(dataSourceWrap);
79 this.rmJdbcTemplate = new JdbcTemplate();
80 this.rmJdbcTemplate.setDataSource(dataSourceWrap);
82 this.lockJdbcTemplate = new JdbcTemplate();
83 this.lockJdbcTemplate.setDataSource(cachedDataSourceWrap);
85 this.resourceLockDao = new ResourceLockDaoImpl();
86 this.resourceLockDao.setJdbcTemplate(lockJdbcTemplate);
88 this.lockHelper = new LockHelperImpl();
89 this.lockHelper.setResourceLockDao(resourceLockDao);
90 this.lockHelper.setRetryCount(10);
91 this.lockHelper.setLockWait(5);
93 this.resourceJdbcDao = new ResourceJdbcDaoImpl();
94 this.resourceJdbcDao.setJdbcTemplate(rmJdbcTemplate);
96 this.allocationItemJdbcDao = new AllocationItemJdbcDaoImpl();
97 this.allocationItemJdbcDao.setJdbcTemplate(rmJdbcTemplate);
99 this.resourceLoadJdbcDao = new ResourceLoadJdbcDaoImpl();
100 this.resourceLoadJdbcDao.setJdbcTemplate(rmJdbcTemplate);
102 this.resourceDao = new ResourceDaoImpl();
103 this.resourceDao.setResourceJdbcDao(resourceJdbcDao);
104 this.resourceDao.setAllocationItemJdbcDao(allocationItemJdbcDao);
105 this.resourceDao.setResourceLoadJdbcDao(resourceLoadJdbcDao);
107 this.resourceManager = new ResourceManagerImpl();
108 this.resourceManager.setLockHelper(lockHelper);
109 this.resourceManager.setResourceDao(resourceDao);
110 this.resourceManager.setLockTimeout(600);
112 this.resourceRuleDao = new ResourceRuleDaoImpl();
113 this.resourceRuleDao.setJdbcTemplate(rmJdbcTemplate);
115 this.rangeRuleDao = new RangeRuleDaoImpl();
116 this.rangeRuleDao.setJdbcTemplate(rmJdbcTemplate);
118 this.resourceLockNode = new ResourceLockNode();
119 this.resourceLockNode.setLockHelper(lockHelper);
121 this.speedUtil = new SpeedUtil();
123 this.dbAllocationRule = new DbAllocationRule();
124 this.dbAllocationRule.setResourceRuleDao(resourceRuleDao);
125 this.dbAllocationRule.setRangeRuleDao(rangeRuleDao);
127 this.endPointAllocator = new EndPointAllocatorImpl();
128 this.endPointAllocator.setResourceManager(resourceManager);
129 this.endPointAllocator.setAllocationRuleMap(
130 Collections.singletonMap("DEFAULT", Collections.singletonList(dbAllocationRule)));
132 this.resourceAllocator = new ResourceAllocator();
133 this.resourceAllocator.setResourceManager(resourceManager);
134 this.resourceAllocator.setEndPointAllocator(endPointAllocator);
135 this.resourceAllocator.setSpeedUtil(speedUtil);
140 protected boolean stopProcedure() {
144 public ResourceAllocator getResourceAllocator() {
145 return resourceAllocator;
148 public ResourceLockNode getResourceLockNode() {
149 return resourceLockNode;