[ovirt-devel] FW: add a ***Command for a button

力波 王 wlbleaboy at 126.com
Fri Aug 8 08:17:15 UTC 2014



发件人:  力波 王 <wlbleaboy at 126.com>
日期:  Fri, 08 Aug 2014 16:10:48 +0800
至:  <devel at ovirt.org>
主题:  [ovirt-devel] add a ***Command for a button

Hi, everyone:
I added a button on the Template Tab, in the client side, It’s OK,

Added the button’s callback like this:
=======================================================================
 private void backup()
    {
        BackupInfoParameters param = new BackupInfoParameters();
        Frontend.RunAction(VdcActionType.Unknown, param, new
IFrontendActionAsyncCallback() {
            @Override
            public void executed(FrontendActionAsyncResult result) {

            }
        });
    }
=======================================================================

The BackupInfoCommand.java is :
=======================================================================
package org.ovirt.engine.core.bll;

import org.ovirt.engine.core.bll.utils.PermissionSubject;
import org.ovirt.engine.core.common.action.BackupInfoParameters;


import java.io.IOException;
import java.util.Collections;
import java.util.List;

/**
 * Created by leaboy on 8/7/14.
 */
public class BackupInfoCommand <T extends BackupInfoParameters> extends
CommandBase<T>{
    public BackupInfoCommand(T parameters){
        super(parameters);
    }

    @Override
    public List<PermissionSubject> getPermissionCheckSubjects() {
        return Collections.emptyList();
    }

    @Override
    protected boolean canDoAction() {
        return true;
    }


    @Override
    protected void executeCommand() {
        int a;
        a = 1;
        try{
            Runtime.getRuntime().exec("touch /tmp/tmp.txt");
        }catch (IOException e){
            e.printStackTrace();
        }

    }
}
=======================================================================

And the BackupInfoParameters.java is:
=======================================================================
package org.ovirt.engine.core.common.action;

/**
 * Created by leaboy on 8/7/14.
 */
public class BackupInfoParameters extends VdcActionParametersBase implements
java.io.Serializable{
    private static final long serialVersionUID = -1363077467684414051L;
    private VdcActionType _actionType;

    //public BackupInfoParameters(){}

    public BackupInfoParameters(){_actionType = VdcActionType.Unknown;}

    public VdcActionType getActionType() {
        return _actionType;
    }
}
=======================================================================

Built the code success, but when I clicked the button, got a dialog with the
error info:

Error while executing action: A Request to the Server failed with the
following Status Code: 500

I debug it , find the error is raised at :

protected VdcReturnValueBase evaluateCorrelationId(CommandBase<?>
commandBase) {
        VdcReturnValueBase returnValue = null;

        // Evaluate and set the correlationId on the parameters, fails on
invalid correlation id
        returnValue =
ExecutionHandler.evaluateCorrelationId(commandBase.getParameters());
        if (returnValue != null) {
            log.warnFormat("CanDoAction of action {0} failed. Reasons: {1}",
commandBase.getActionType(),
                    StringUtils.join(returnValue.getCanDoActionMessages(),
','));

        }
        // Set the correlation-id on the command
        
commandBase.setCorrelationId(commandBase.getParameters().getCorrelationId())
;
        return returnValue;
    }
_______________________________________________ Devel mailing list
Devel at ovirt.org http://lists.ovirt.org/mailman/listinfo/devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/devel/attachments/20140808/7393e352/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 871E2E8A-B375-456F-B2CF-9E25AB718A23.png
Type: image/png
Size: 13614 bytes
Desc: not available
URL: <http://lists.ovirt.org/pipermail/devel/attachments/20140808/7393e352/attachment-0001.png>


More information about the Devel mailing list