aboutsummaryrefslogtreecommitdiffstats
path: root/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/InMemorySvcLogicStore.java
blob: ddf464fe79d888f19a0da220517ae12725e580f0 (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
package org.onap.ccsdk.sli.core.sli.provider.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class InMemorySvcLogicStore implements SvcLogicStore {
    private static final Logger logger = LoggerFactory.getLogger(InMemorySvcLogicStore.class);
    public Map<String, SvcLogicGraph> graphStore;

    public InMemorySvcLogicStore() {
        graphStore = new HashMap<String, SvcLogicGraph>();
    }

    @Override
    public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
        String storeId = new String(module + ":" + rpc);
        return graphStore.containsKey(storeId);
    }

    @Override
    public SvcLogicGraph fetch(String module, String rpc, String version, String mode) throws SvcLogicException {
        String storeId = new String(module + ":" + rpc);
        return graphStore.get(storeId);
    }

    @Override
    public void store(SvcLogicGraph graph) throws SvcLogicException {
        if (graph != null) {
            String storeId = new String(graph.getModule() + ":" + graph.getRpc());
            graphStore.put(storeId, graph);
            logger.info(graph.toString() + " stored in InMemorySvcLogicStore.");
        }
    }

    @Override
    public void init(Properties props) throws SvcLogicException {
        // noop
    }

    @Override
    public void delete(String module, String rpc, String version, String mode) throws SvcLogicException {
        String storeId = new String(module + ":" + rpc);
        if (graphStore.containsKey(storeId)) {
            graphStore.remove(storeId);
        }
    }

    @Override
    public void activate(SvcLogicGraph graph) throws SvcLogicException {
        // noop
    }

    @Override
    public void activate(String module, String rpc, String version, String mode) throws SvcLogicException {
        // noop
    }

}