3 Replies Latest reply on Nov 12, 2014 11:09 AM by Tomaz Cerar

    reading attribute value

    CK Nathan Newbie

      I am working on developing an extension - created an operationHandler called activate - I would like to read the attribute value within handler code. I tried following under execute procedure:

       

      String location = DatabaseResourceDefinition.LOCATION.resolveModelAttribute(context, operation).asString();

       

      The value returned is 'undefined' instead of actual value. I am able to read the value using CLI commands.

       

      any help? Thanks,

        • 1. Re: reading attribute value
          Tomaz Cerar Master

          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
            CK Nathan Newbie

            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
              Tomaz Cerar Master

              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...