This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enviroment parameter added to named subsystem
- Loading branch information
1 parent
d166765
commit e0dc488
Showing
2 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
...ugins/wfly-10/src/main/java/org/rhq/modules/plugins/wildfly10/NamingBindingComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters