-
1. Re: reading attribute value
ctomc Nov 11, 2014 7:52 PM (in response to ckg007)Not sure what the context is but problem is probably related that you pass "operation" instead of "model" to resolveModelAttribute()
something along the lines
String location = DatabaseResourceDefinition.LOCATION.resolveModelAttribute(context, model).asString();
-
2. Re: reading attribute value
ckg007 Nov 12, 2014 11:01 AM (in response to ctomc)Thanks,
Following is the output of CLI
/profile=full-ha-osgi/subsystem=hajdbc/configuration=mycluster/clusterconfig=cluster/database=db3/:read-resource
{
"outcome" => "success",
"result" => {
"local" => undefined,
"location" => "'jdbc:postgresql://127.0.1.4/test'",
"weight" => undefined,
"property" => undefined
}
}
I would like to read location attribute value inside my handler code..
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException
{
if (context.isNormalServer()) {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException
{
String location =
DatabaseResourceDefinition.LOCATION.resolveModelAttribute(context, operation).asString();
context.stepCompleted();
}
}, OperationContext.Stage.RUNTIME);
}
else {
context.getResult().set("");
}
context.stepCompleted();
}
when tried to debug, I see the value is 'undefined'
-
3. Re: reading attribute value
ctomc Nov 12, 2014 11:09 AM (in response to ckg007)you would need something like this
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException{
// get the model for current resource, that is one on which operation was called on
ModelNode model = context.readResource(PathAddress.EMPTY).getModel()
String location = DatabaseResourceDefinition.LOCATION.resolveModelAttribute(context, model).asString();
context.getResult().set(location); //or do what ever you want with location
context.stepCompleted();
}
no need to complicate with nested steps etc...