Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Enviroment parameter added to named subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvp8510 committed Oct 19, 2017
1 parent d166765 commit e0dc488
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 3 deletions.
@@ -0,0 +1,107 @@
package org.rhq.modules.plugins.wildfly10;

import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;

import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.modules.plugins.wildfly10.json.Operation;
import org.rhq.modules.plugins.wildfly10.json.Result;
import org.rhq.modules.plugins.wildfly10.json.ReadAttribute;
import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.modules.plugins.wildfly10.json.Address;
import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.modules.plugins.wildfly10.ConfigurationWriteDelegate;
import org.rhq.modules.plugins.wildfly10.json.CompositeOperation;
import org.rhq.core.domain.configuration.Property;
import org.rhq.modules.plugins.wildfly10.json.WriteAttribute;

/**
* Component for the naming subsystem
* @author Ruben Vargas
*/
public class NamingBindingComponent extends BaseComponent<BaseComponent<?>> {

private static final String ENVIRONMENT = "environment";

class BindingConfigurationWriteDelegate extends ConfigurationWriteDelegate {


public BindingConfigurationWriteDelegate(ConfigurationDefinition configDef, ASConnection connection, Address
address) {
super(configDef.copy(), connection, address);
this.configurationDefinition.getPropertyDefinitions().remove(ENVIRONMENT);
}

@Override
protected CompositeOperation updateGenerateOperationFromProperties(Configuration conf, Address address) {
CompositeOperation cop = super.updateGenerateOperationFromProperties(conf, address);
/* Update special enviroment var */
PropertyList prop = (PropertyList)conf.get(ENVIRONMENT);
List<Object> values = new ArrayList<Object>();
List<Property> embeddedProps = prop.getList();
Map<String, Object> results = new HashMap<String, Object>();
for (Property inner : embeddedProps) {
PropertyMap propMap = (PropertyMap) inner;
PropertySimple propName = ((PropertySimple) propMap.get("name"));
PropertySimple propValue = ((PropertySimple) propMap.get("value"));
results.put(propName.getStringValue(), propValue.getStringValue());
}
WriteAttribute writeAttribute = new WriteAttribute(address, ENVIRONMENT, results);
cop.addStep(writeAttribute);
return cop;
}
}

@Override
public void updateResourceConfiguration(ConfigurationUpdateReport report) {
ConfigurationDefinition configDef = context.getResourceType().getResourceConfigurationDefinition().copy();
ConfigurationWriteDelegate delegate = new BindingConfigurationWriteDelegate(configDef, getASConnection(), address);
delegate.updateResourceConfiguration(report);
}

@Override
public Configuration loadResourceConfiguration() throws Exception {
ConfigurationDefinition configDef = context.getResourceType().getResourceConfigurationDefinition().copy();
/* Get and remove enviroment property */
configDef.getPropertyDefinitions().remove(ENVIRONMENT);

/* Load other properties*/
ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(configDef, getASConnection(), address,
includeRuntime);
Configuration configuration = delegate.loadResourceConfiguration();

Operation op = new Operation("whoami", getAddress());
Result res = getASConnection().execute(op);

if (!res.isSuccess()) {
op = new Operation("read-resource", getAddress());
res = getASConnection().execute(op);
}
includeOOBMessages(res, configuration);

/* Load environment property*/
ReadAttribute readAttributeOp = new ReadAttribute(address, ENVIRONMENT);
PropertyList list = new PropertyList(ENVIRONMENT);
configuration.put(list);
Result envOpResult = getASConnection().execute(readAttributeOp);

if (envOpResult.isSuccess()) {
Map<String, Object> results = (Map<String, Object>)envOpResult.getResult();
if (results != null) {
for(Map.Entry<String, Object> entry: results.entrySet()) {
PropertyMap map = new PropertyMap(ENVIRONMENT);
map.put(new PropertySimple("name", entry.getKey()));
map.put(new PropertySimple("value", entry.getValue()));
list.add(map);
}
}
}
return configuration;
}

}
24 changes: 21 additions & 3 deletions modules/plugins/wfly-10/src/main/resources/META-INF/rhq-plugin.xml
Expand Up @@ -2165,7 +2165,7 @@
</operation>

<service name="Binding (Managed Server)"
class="BaseComponent"
class="NamingBindingComponent"
discovery="SubsystemDiscovery"
description="JNDI bindings for primitive types">

Expand All @@ -2186,6 +2186,12 @@
<c:simple-property name="module" required="false" type="string" readOnly="true" description="The module to load the object factory from for object factory bindings"/>
<c:simple-property name="type" required="false" type="string" readOnly="true" description="The type of the value to bind for simple bindings, this must be a primitive type"/>
<c:simple-property name="value" required="false" type="string" readOnly="true" description="The value to bind for simple bindings"/>
<c:list-property name="environment" readOnly="true" description="A list of The environment to use on object factory instance retrieval." required="false">
<c:map-property name="environment" readOnly="true" displayName="Environment">
<c:simple-property name="name" type="string" displayName="Name" required="true"/>
<c:simple-property name="value" type="string" displayName="Value" required="true"/>
</c:map-property>
</c:list-property>
</resource-configuration>
</service>
</service>
Expand Down Expand Up @@ -6704,7 +6710,7 @@
</plugin-configuration>

<service name="Binding (Profile)"
class="BaseComponent"
class="NamingBindingComponent"
discovery="SubsystemDiscovery"
description="JNDI bindings for primitive types"
createDeletePolicy="both">
Expand All @@ -6726,6 +6732,12 @@
<c:simple-property name="module" required="false" type="string" readOnly="false" description="The module to load the object factory from for object factory bindings"/>
<c:simple-property name="type" required="false" type="string" readOnly="false" description="The type of the value to bind for simple bindings, this must be a primitive type"/>
<c:simple-property name="value" required="false" type="string" readOnly="false" description="The value to bind for simple bindings"/>
<c:list-property name="environment" description="A list of The environment to use on object factory instance retrieval." required="false">
<c:map-property name="environment" displayName="Environment">
<c:simple-property name="name" type="string" displayName="Name" required="true"/>
<c:simple-property name="value" type="string" displayName="Value" required="true"/>
</c:map-property>
</c:list-property>
</resource-configuration>
</service>
</service>
Expand Down Expand Up @@ -10841,7 +10853,7 @@
</operation>

<service name="Binding"
class="BaseComponent"
class="NamingBindingComponent"
discovery="SubsystemDiscovery"
description="JNDI bindings for primitive types"
createDeletePolicy="both">
Expand All @@ -10863,6 +10875,12 @@
<c:simple-property name="module" required="false" type="string" readOnly="false" description="The module to load the object factory from for object factory bindings"/>
<c:simple-property name="type" required="false" type="string" readOnly="false" description="The type of the value to bind for simple bindings, this must be a primitive type"/>
<c:simple-property name="value" required="false" type="string" readOnly="false" description="The value to bind for simple bindings"/>
<c:list-property name="environment" description="A list of The environment to use on object factory instance retrieval." required="false">
<c:map-property name="environment" displayName="Environment">
<c:simple-property name="name" type="string" displayName="Name" required="true"/>
<c:simple-property name="value" type="string" displayName="Value" required="true"/>
</c:map-property>
</c:list-property>
</resource-configuration>
</service>

Expand Down

0 comments on commit e0dc488

Please sign in to comment.