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.HashSet;
27 import java.util.Set;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.jboss.managed.api.ComponentType;
32 import org.jboss.managed.api.ManagedComponent;
33 import org.jboss.metatype.api.types.EnumMetaType;
34 import org.jboss.metatype.api.values.CollectionValueSupport;
35 import org.jboss.metatype.api.values.CompositeValueSupport;
36 import org.jboss.metatype.api.values.EnumValueSupport;
37 import org.jboss.metatype.api.values.MetaValue;
38 import org.modeshape.jboss.managed.ManagedEngine;
39 import org.modeshape.rhq.plugin.util.ModeShapeManagementView;
40 import org.modeshape.rhq.plugin.util.PluginConstants;
41 import org.modeshape.rhq.plugin.util.ProfileServiceUtil;
42 import org.rhq.core.domain.configuration.Configuration;
43 import org.rhq.core.domain.configuration.PropertyList;
44 import org.rhq.core.domain.configuration.PropertyMap;
45 import org.rhq.core.domain.configuration.PropertySimple;
46 import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
47 import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
48 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
49 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
50
51
52
53
54 public class SequencingServiceDiscoveryComponent implements
55 ResourceDiscoveryComponent<SequencingServiceComponent> {
56
57 private final Log log = LogFactory
58 .getLog(PluginConstants.DEFAULT_LOGGER_CATEGORY);
59
60
61
62
63
64
65 public Set<DiscoveredResourceDetails> discoverResources(
66 ResourceDiscoveryContext discoveryContext)
67 throws InvalidPluginConfigurationException, Exception {
68
69 Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>();
70
71 ManagedComponent mc = ProfileServiceUtil
72 .getManagedComponent( ((EngineComponent) discoveryContext
73 .getParentResourceComponent()).getConnection(),
74 new ComponentType(
75 PluginConstants.ComponentType.SequencingService.MODESHAPE_TYPE,
76 PluginConstants.ComponentType.SequencingService.MODESHAPE_SUB_TYPE),
77 PluginConstants.ComponentType.SequencingService.NAME);
78
79 if (mc == null) {
80 return discoveredResources;
81 }
82
83
84
85
86
87
88 DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
89 discoveryContext.getResourceType(),
90 PluginConstants.ComponentType.SequencingService.NAME,
91 PluginConstants.ComponentType.SequencingService.DISPLAY_NAME,
92 null,
93 PluginConstants.ComponentType.SequencingService.DESC,
94 discoveryContext.getDefaultPluginConfiguration(),
95 null
96 );
97 Configuration c = detail.getPluginConfiguration();
98
99
100 String operation = "getProperties";
101
102 EnumValueSupport enumVs = new EnumValueSupport(new EnumMetaType(ManagedEngine.Component.values()), ManagedEngine.Component.SEQUENCINGSERVICE);
103 MetaValue[] args = new MetaValue[] {
104 null,
105 enumVs };
106
107 MetaValue properties = ModeShapeManagementView
108 .executeManagedOperation(mc, operation, args);
109
110 MetaValue[] propertyArray = ((CollectionValueSupport) properties)
111 .getElements();
112
113 PropertyList list = new PropertyList("propertyList");
114 c.put(list);
115 loadProperties(propertyArray, list);
116
117
118 discoveredResources.add(detail);
119 log.debug("Discovered ModeShape Sequencing Service: " + mc.getName());
120
121 return discoveredResources;
122
123 }
124
125
126
127
128
129
130 private void loadProperties(MetaValue[] propertyArray, PropertyList list)
131 throws Exception {
132 PropertyMap propMap;
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 propMap.put(new PropertySimple("description", ProfileServiceUtil
142 .stringValue(proCvs.get("description"))));
143 list.add(propMap);
144 }
145 }
146 }