aboutsummaryrefslogtreecommitdiffstats
path: root/resource-assignment/lighty/src/main/java/org/onap/ccsdk/sli/adaptors/resource/lighty/ResourceModule.java
blob: b9090599568c84f9326f41cb5e843cd951a55bad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * ============LICENSE_START==========================================
 * Copyright (c) 2019 PANTHEON.tech s.r.o.
 * ===================================================================
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END============================================
 *
 */
package org.onap.ccsdk.sli.adaptors.resource.lighty;

import io.lighty.core.controller.api.AbstractLightyModule;
import java.util.Collections;
import org.onap.ccsdk.sli.adaptors.lock.comp.LockHelperImpl;
import org.onap.ccsdk.sli.adaptors.lock.dao.ResourceLockDaoImpl;
import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
import org.onap.ccsdk.sli.adaptors.ra.ResourceLockNode;
import org.onap.ccsdk.sli.adaptors.ra.alloc.DbAllocationRule;
import org.onap.ccsdk.sli.adaptors.ra.comp.EndPointAllocatorImpl;
import org.onap.ccsdk.sli.adaptors.ra.rule.dao.RangeRuleDaoImpl;
import org.onap.ccsdk.sli.adaptors.ra.rule.dao.ResourceRuleDaoImpl;
import org.onap.ccsdk.sli.adaptors.rm.comp.ResourceManagerImpl;
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.ResourceJdbcDaoImpl;
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.onap.ccsdk.sli.core.dblib.DbLibService;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * The implementation of the {@link io.lighty.core.controller.api.LightyModule} that manages and provides services from
 * the resource-assignment-provider artifact.
 */
public class ResourceModule extends AbstractLightyModule {

    private final DbLibService dbLibService;

    private DataSourceWrap dataSourceWrap;
    private CachedDataSourceWrap cachedDataSourceWrap;
    private JdbcTemplate rmJdbcTemplate;
    private JdbcTemplate lockJdbcTemplate;
    private ResourceLockDaoImpl resourceLockDao;
    private LockHelperImpl lockHelper;
    private ResourceJdbcDaoImpl resourceJdbcDao;
    private AllocationItemJdbcDaoImpl allocationItemJdbcDao;
    private ResourceLoadJdbcDaoImpl resourceLoadJdbcDao;
    private ResourceDaoImpl resourceDao;
    private ResourceManagerImpl resourceManager;
    private ResourceRuleDaoImpl resourceRuleDao;
    private RangeRuleDaoImpl rangeRuleDao;
    private ResourceAllocator resourceAllocator;
    private ResourceLockNode resourceLockNode;
    private SpeedUtil speedUtil;
    private EndPointAllocatorImpl endPointAllocator;
    private DbAllocationRule dbAllocationRule;

    public ResourceModule(final DbLibService dbLibService) {
        this.dbLibService = dbLibService;
    }

    @Override
    protected boolean initProcedure() {
        this.dataSourceWrap = new DataSourceWrap();
        this.dataSourceWrap.setDataSource(dbLibService);

        this.cachedDataSourceWrap = new CachedDataSourceWrap();
        this.cachedDataSourceWrap.setDataSource(dataSourceWrap);

        this.rmJdbcTemplate = new JdbcTemplate();
        this.rmJdbcTemplate.setDataSource(dataSourceWrap);

        this.lockJdbcTemplate = new JdbcTemplate();
        this.lockJdbcTemplate.setDataSource(cachedDataSourceWrap);

        this.resourceLockDao = new ResourceLockDaoImpl();
        this.resourceLockDao.setJdbcTemplate(lockJdbcTemplate);

        this.lockHelper = new LockHelperImpl();
        this.lockHelper.setResourceLockDao(resourceLockDao);
        this.lockHelper.setRetryCount(10);
        this.lockHelper.setLockWait(5);

        this.resourceJdbcDao = new ResourceJdbcDaoImpl();
        this.resourceJdbcDao.setJdbcTemplate(rmJdbcTemplate);

        this.allocationItemJdbcDao = new AllocationItemJdbcDaoImpl();
        this.allocationItemJdbcDao.setJdbcTemplate(rmJdbcTemplate);

        this.resourceLoadJdbcDao = new ResourceLoadJdbcDaoImpl();
        this.resourceLoadJdbcDao.setJdbcTemplate(rmJdbcTemplate);

        this.resourceDao = new ResourceDaoImpl();
        this.resourceDao.setResourceJdbcDao(resourceJdbcDao);
        this.resourceDao.setAllocationItemJdbcDao(allocationItemJdbcDao);
        this.resourceDao.setResourceLoadJdbcDao(resourceLoadJdbcDao);

        this.resourceManager = new ResourceManagerImpl();
        this.resourceManager.setLockHelper(lockHelper);
        this.resourceManager.setResourceDao(resourceDao);
        this.resourceManager.setLockTimeout(600);

        this.resourceRuleDao = new ResourceRuleDaoImpl();
        this.resourceRuleDao.setJdbcTemplate(rmJdbcTemplate);

        this.rangeRuleDao = new RangeRuleDaoImpl();
        this.rangeRuleDao.setJdbcTemplate(rmJdbcTemplate);

        this.resourceLockNode = new ResourceLockNode();
        this.resourceLockNode.setLockHelper(lockHelper);

        this.speedUtil = new SpeedUtil();

        this.dbAllocationRule = new DbAllocationRule();
        this.dbAllocationRule.setResourceRuleDao(resourceRuleDao);
        this.dbAllocationRule.setRangeRuleDao(rangeRuleDao);

        this.endPointAllocator = new EndPointAllocatorImpl();
        this.endPointAllocator.setResourceManager(resourceManager);
        this.endPointAllocator.setAllocationRuleMap(
                Collections.singletonMap("DEFAULT", Collections.singletonList(dbAllocationRule)));

        this.resourceAllocator = new ResourceAllocator();
        this.resourceAllocator.setResourceManager(resourceManager);
        this.resourceAllocator.setEndPointAllocator(endPointAllocator);
        this.resourceAllocator.setSpeedUtil(speedUtil);
        return true;
    }

    @Override
    protected boolean stopProcedure() {
        return true;
    }

    public ResourceAllocator getResourceAllocator() {
        return resourceAllocator;
    }

    public ResourceLockNode getResourceLockNode() {
        return resourceLockNode;
    }

}