/
TcaCollectionResource.java
161 lines (142 loc) · 4.97 KB
/
TcaCollectionResource.java
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
153
154
155
156
157
158
159
160
161
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2012 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/
package org.opennms.netmgt.collectd.tca;
import java.io.File;
import org.opennms.core.utils.DefaultTimeKeeper;
import org.opennms.core.utils.TimeKeeper;
import org.opennms.netmgt.collectd.AbstractCollectionResource;
import org.opennms.netmgt.collectd.CollectionAgent;
import org.opennms.netmgt.config.StorageStrategy;
import org.opennms.netmgt.dao.support.IndexStorageStrategy;
import org.opennms.netmgt.model.RrdRepository;
/**
* The Class TcaCollectionResource.
* <p>The resource type is fixed to <code>juniperTcaEntry</code></p>
* <p>This requires to define a datacollection-group like this:</p>
* <pre>
* <datacollection-group name="Juniper TCA">
* <resourceType name="juniperTcaEntry" label="Juniper TCA Entry" resourceLabel="Peer ${index}">
* <persistenceSelectorStrategy class="org.opennms.netmgt.collectd.PersistAllSelectorStrategy"/>
* <storageStrategy class="org.opennms.netmgt.dao.support.IndexStorageStrategy"/>
* </resourceType>
* </datacollection-group>
* </pre>
* <p>Note: the persistenceSelectorStrategy and storageStrategy won't be used by the collector.</p>
*
* @author Alejandro Galue <agalue@opennms.org>
*/
public class TcaCollectionResource extends AbstractCollectionResource {
/** The Constant RESOURCE_TYPE_NAME. */
public static final String RESOURCE_TYPE_NAME = "juniperTcaEntry";
/** The Time Keeper. */
private TimeKeeper m_timeKeeper = new DefaultTimeKeeper();
/** The m_peer address. */
private final String m_peerAddress;
/** The m_strategy. */
private final StorageStrategy m_strategy;
/**
* Instantiates a new TCA collection resource.
*
* @param agent the collection agent
* @param peerAddress the TCA peer address
*/
protected TcaCollectionResource(CollectionAgent agent, String peerAddress) {
super(agent);
m_peerAddress = peerAddress;
m_strategy = new IndexStorageStrategy();
m_strategy.setResourceTypeName(RESOURCE_TYPE_NAME);
}
/* (non-Javadoc)
* @see org.opennms.netmgt.config.collector.CollectionResource#getResourceTypeName()
*/
@Override
public String getResourceTypeName() {
return RESOURCE_TYPE_NAME;
}
/* (non-Javadoc)
* @see org.opennms.netmgt.config.collector.CollectionResource#getInstance()
*/
@Override
public String getInstance() {
return m_peerAddress;
}
/* (non-Javadoc)
* @see org.opennms.netmgt.collectd.AbstractCollectionResource#getLabel()
*/
@Override
public String getLabel() {
return m_peerAddress;
}
/* (non-Javadoc)
* @see org.opennms.netmgt.collectd.AbstractCollectionResource#getType()
*/
@Override
public int getType() {
return -1; // Is this right?
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "node[" + m_agent.getNodeId() + "]." + getResourceTypeName() + "[" + getLabel() +"]";
}
/* (non-Javadoc)
* @see org.opennms.netmgt.collectd.AbstractCollectionResource#getResourceDir(org.opennms.netmgt.model.RrdRepository)
*/
@Override
public File getResourceDir(RrdRepository repository) {
String resourcePath = m_strategy.getRelativePathForAttribute(getParent(), getLabel(), null);
return new File(repository.getRrdBaseDir(), resourcePath);
}
/* (non-Javadoc)
* @see org.opennms.netmgt.collectd.AbstractCollectionResource#getTimeKeeper()
*/
@Override
public TimeKeeper getTimeKeeper() {
return m_timeKeeper;
}
/**
* Sets the time keeper.
*
* @param timeKeeper the new time keeper
*/
public void setTimeKeeper(TimeKeeper timeKeeper) {
m_timeKeeper = timeKeeper;
}
/**
* Sets the attribute value.
*
* @param type the type
* @param value the value
*/
public void setAttributeValue(TcaCollectionAttributeType type, String value) {
TcaCollectionAttribute attr = new TcaCollectionAttribute(this, type, type.getName(), value);
addAttribute(attr);
}
}