1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.rhq.plugin;
25
26 import java.util.Collection;
27 import java.util.HashSet;
28 import java.util.Set;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.jboss.managed.api.ComponentType;
33 import org.jboss.managed.api.ManagedComponent;
34 import org.jboss.metatype.api.values.CollectionValueSupport;
35 import org.jboss.metatype.api.values.CompositeValueSupport;
36 import org.jboss.metatype.api.values.MetaValue;
37 import org.jboss.metatype.api.values.MetaValueFactory;
38 import org.modeshape.jboss.managed.ManagedEngine;
39 import org.modeshape.jboss.managed.ManagedRepository;
40 import org.modeshape.rhq.plugin.util.ModeShapeManagementView;
41 import org.modeshape.rhq.plugin.util.PluginConstants;
42 import org.modeshape.rhq.plugin.util.ProfileServiceUtil;
43 import org.rhq.core.domain.configuration.Configuration;
44 import org.rhq.core.domain.configuration.PropertyList;
45 import org.rhq.core.domain.configuration.PropertyMap;
46 import org.rhq.core.domain.configuration.PropertySimple;
47 import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
48 import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
49 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
50 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
51
52
53
54
55 public class RepositoryDiscoveryComponent implements
56 ResourceDiscoveryComponent<EngineComponent> {
57
58 private final Log log = LogFactory
59 .getLog(PluginConstants.DEFAULT_LOGGER_CATEGORY);
60
61
62
63
64
65
66 public Set<DiscoveredResourceDetails> discoverResources(
67 ResourceDiscoveryContext discoveryContext)
68 throws InvalidPluginConfigurationException, Exception {
69
70 Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>();
71
72 ManagedComponent mc = ProfileServiceUtil
73 .getManagedComponent(
74 ((EngineComponent) discoveryContext
75 .getParentResourceComponent()).getConnection(),
76 new ComponentType(
77 PluginConstants.ComponentType.Engine.MODESHAPE_TYPE,
78 PluginConstants.ComponentType.Engine.MODESHAPE_SUB_TYPE),
79 PluginConstants.ComponentType.Engine.MODESHAPE_ENGINE);
80
81 String operation = "getRepositories";
82
83 MetaValue repositories = ModeShapeManagementView
84 .executeManagedOperation(mc, operation,
85 new MetaValue[] { null });
86
87 if (repositories == null) {
88 return discoveredResources;
89 }
90
91 Collection<ManagedRepository> repositoryCollection = ModeShapeManagementView
92 .getRepositoryCollectionValue(repositories);
93
94 for (ManagedRepository managedRepository : repositoryCollection) {
95
96 String name = managedRepository.getName();
97 MetaValue version = ModeShapeManagementView
98 .executeManagedOperation(mc, "getRepositoryVersion",
99 MetaValueFactory.getInstance().create(name));
100
101
102
103
104
105
106 DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
107 discoveryContext.getResourceType(),
108 name,
109 name,
110 ProfileServiceUtil.stringValue(version),
111 PluginConstants.ComponentType.Repository.MODESHAPE_REPOSITORY_DESC,
112 discoveryContext.getDefaultPluginConfiguration(),
113 null
114 );
115
116 Configuration c = detail.getPluginConfiguration();
117
118 operation = "getRepositoryProperties";
119
120 MetaValue[] args = new MetaValue[] {
121 MetaValueFactory.getInstance().create(name)};
122
123 MetaValue properties = ModeShapeManagementView
124 .executeManagedOperation(mc, operation, args);
125
126 MetaValue[] propertyArray = ((CollectionValueSupport) properties)
127 .getElements();
128
129 PropertyList list = new PropertyList("propertyList");
130 PropertyMap propMap = null;
131 c.put(list);
132
133 for (MetaValue property : propertyArray) {
134
135 CompositeValueSupport proCvs = (CompositeValueSupport) property;
136 propMap = new PropertyMap("map");
137 propMap.put(new PropertySimple("label", ProfileServiceUtil
138 .stringValue(proCvs.get("label"))));
139 propMap.put(new PropertySimple("value", ProfileServiceUtil
140 .stringValue(proCvs.get("value"))));
141 list.add(propMap);
142 }
143
144
145
146
147 discoveredResources.add(detail);
148 log.debug("Discovered ModeShape Repository: " + name);
149 }
150
151 return discoveredResources;
152
153 }
154 }