Frank Kobzik has uploaded a new change for review. Change subject: engine: Adjust console ticket commands ......................................................................
engine: Adjust console ticket commands This patch makes it possible to set console ticket for multiple graphics devices (new approach uses updateDevice command). For older VDSMs, setTicket command is used. TODO FOR WHOLE TOPIC: - (db persistence of GraphicsInfo - so far problematic) - ui for configuring graphics - SetVmTicket adjustments - restapi - cleanup (remove unused atts from entities and their refs, cleanup db tables) Change-Id: Ib62c9e29349a58156cddba1ca039cf9b7f14e610 Signed-off-by: Frantisek Kobzik <[email protected]> Bug-Url: https://bugzilla.redhat.com/1033547 --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetVmTicketCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/SetVmTicketParameters.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/SetVmTicketVDSCommandParameters.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SetVmTicketVDSCommand.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java 8 files changed, 122 insertions(+), 87 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/74/28574/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetVmTicketCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetVmTicketCommand.java index 918e084..bf336d7 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetVmTicketCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetVmTicketCommand.java @@ -28,7 +28,6 @@ private static final Log log = LogFactory.getLog(SetVmTicketCommand.class); private String mTicket; - private final int mValidTime; // This flag is calculated during the authorization phase and indicates if // the user needed additional permission in order to connect to the console @@ -38,7 +37,6 @@ public SetVmTicketCommand(T parameters) { super(parameters); mTicket = parameters.getTicket(); - mValidTime = parameters.getValidTime(); } @Override @@ -198,7 +196,8 @@ .getInstance() .getResourceManager() .RunVdsCommand(VDSCommandType.SetVmTicket, - new SetVmTicketVDSCommandParameters(getVdsId(), getVmId(), mTicket, mValidTime, user.getLoginName(), user.getId())).getSucceeded(); + new SetVmTicketVDSCommandParameters(getVdsId(), getVmId(), mTicket, getParameters().getValidTime(), + user.getLoginName(), user.getId(), getParameters().getGraphicsType())).getSucceeded(); // Return the ticket only if sending it to the virtual machine succeeded: if (sent) { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java index 73c6a15..19595aa 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java @@ -31,6 +31,7 @@ import org.ovirt.engine.core.common.action.VdcReturnValueBase; import org.ovirt.engine.core.common.action.VdsActionParameters; import org.ovirt.engine.core.common.businessentities.FenceActionType; +import org.ovirt.engine.core.common.businessentities.GraphicsType; import org.ovirt.engine.core.common.businessentities.IVdsAsyncCommand; import org.ovirt.engine.core.common.businessentities.IVdsEventListener; import org.ovirt.engine.core.common.businessentities.NonOperationalReason; @@ -263,7 +264,7 @@ Backend.getInstance() .getResourceManager() .RunVdsCommand(VDSCommandType.SetVmTicket, - new SetVmTicketVDSCommandParameters(vds_id, vmid, otp64, 60, "", Guid.Empty)); + new SetVmTicketVDSCommandParameters(vds_id, vmid, otp64, 60, "", Guid.Empty, GraphicsType.SPICE)); // todo verify this log.infoFormat( "VdsEventListener.ProcessOnVmPoweringUp - Auto start logic, starting spice to vm - {0} ", vmid); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/SetVmTicketParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/SetVmTicketParameters.java index 4e96e5f..55a7859 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/SetVmTicketParameters.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/SetVmTicketParameters.java @@ -1,41 +1,46 @@ package org.ovirt.engine.core.common.action; +import org.ovirt.engine.core.common.businessentities.GraphicsType; import org.ovirt.engine.core.compat.Guid; public class SetVmTicketParameters extends VmOperationParameterBase { + private static final long serialVersionUID = 7066467049851637162L; - private String _ticket; - - private int _validTime; - - private String _clientIp; - - public SetVmTicketParameters(Guid vmId, String ticket, int validTime) { - super(vmId); - _ticket = ticket; - _validTime = validTime; - } - - public SetVmTicketParameters(Guid vmId, String ticket, int validTime, String clientIp) { - this(vmId, ticket, validTime); - _clientIp = clientIp; - _ticket = ticket; - _validTime = validTime; - } - - public String getTicket() { - return _ticket; - } - - public int getValidTime() { - return _validTime; - } - - public String getClientIp() { - return _clientIp; - } + private String ticket; + private int validTime; + private String clientIp; + private GraphicsType graphicsType; public SetVmTicketParameters() { } + + public SetVmTicketParameters(Guid vmId, String ticket, int validTime, GraphicsType graphicsType) { + super(vmId); + this.graphicsType = graphicsType; + this.ticket = ticket; + this.validTime = validTime; + } + + public SetVmTicketParameters(Guid vmId, String ticket, int validTime, GraphicsType graphicsType, String clientIp) { + this(vmId, ticket, validTime, graphicsType); + this.clientIp = clientIp; + } + + public String getTicket() { + return ticket; + } + + public int getValidTime() { + return validTime; + } + + public String getClientIp() { + return clientIp; + } + + public GraphicsType getGraphicsType() { + return graphicsType; + } + } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/SetVmTicketVDSCommandParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/SetVmTicketVDSCommandParameters.java index 6851320..2ca8184 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/SetVmTicketVDSCommandParameters.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/SetVmTicketVDSCommandParameters.java @@ -1,5 +1,6 @@ package org.ovirt.engine.core.common.vdscommands; +import org.ovirt.engine.core.common.businessentities.GraphicsType; import org.ovirt.engine.core.compat.Guid; public class SetVmTicketVDSCommandParameters extends VdsAndVmIDVDSParametersBase { @@ -7,13 +8,20 @@ private int validTime; private String userName; private Guid userId; + private GraphicsType graphicsType; - public SetVmTicketVDSCommandParameters(Guid vdsId, Guid vmId, String ticket, int validTime, String userName, Guid userId) { + public SetVmTicketVDSCommandParameters() { + } + + public SetVmTicketVDSCommandParameters(Guid vdsId, Guid vmId, String ticket, int validTime, String userName, + Guid userId, GraphicsType graphicsType) + { super(vdsId, vmId); this.ticket = ticket; this.validTime = validTime; this.userName = userName; this.userId = userId; + this.graphicsType = graphicsType; } public String getTicket() { @@ -32,7 +40,8 @@ return userName; } - public SetVmTicketVDSCommandParameters() { + public GraphicsType getGraphicsType() { + return graphicsType; } @Override diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java index 1f4880d..3bd8e06 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java @@ -63,6 +63,7 @@ import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VmManagementParametersBase; import org.ovirt.engine.core.common.action.VmOperationParameterBase; +import org.ovirt.engine.core.common.businessentities.GraphicsType; import org.ovirt.engine.core.common.businessentities.HaMaintenanceMode; import org.ovirt.engine.core.common.businessentities.InitializationType; import org.ovirt.engine.core.common.businessentities.SnapshotActionEnum; @@ -399,8 +400,9 @@ public Response ticket(Action action) { final Response response = doAction(VdcActionType.SetVmTicket, new SetVmTicketParameters(guid, - getTicketValue(action), - getTicketExpiry(action)), + getTicketValue(action), + getTicketExpiry(action), + GraphicsType.SPICE), action); final Action actionResponse = (Action) response.getEntity(); diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SetVmTicketVDSCommand.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SetVmTicketVDSCommand.java index db5e202..46a548d 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SetVmTicketVDSCommand.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SetVmTicketVDSCommand.java @@ -2,40 +2,57 @@ import java.util.HashMap; import java.util.Map; - import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.vdscommands.SetVmTicketVDSCommandParameters; -import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.dal.dbbroker.DbFacade; public class SetVmTicketVDSCommand<P extends SetVmTicketVDSCommandParameters> extends VdsBrokerCommand<P> { - private Guid mVmId = Guid.Empty; - private String mTicket; - private int mValidTime; // in seconds + private String connectionAction = "disconnect"; + private static final Version TICKET_USING_UPDATE_DEVICE = Version.v3_5; // todo configurability could be nice public SetVmTicketVDSCommand(P parameters) { super(parameters, DbFacade.getInstance().getVdsDao().get(parameters.getVdsId())); - mVmId = parameters.getVmId(); - mTicket = parameters.getTicket(); - mValidTime = parameters.getValidTime(); } @Override protected void executeVdsBrokerCommand() { - if (Config.<Boolean> getValue(ConfigValues.SendVmTicketUID, - getVds().getVdsGroupCompatibilityVersion().toString())) { - Map<String, String> params = new HashMap<String, String>(); - params.put("userName", getParameters().getUserName()); - params.put("userId", getParameters().getUserId().toString()); - status = getBroker().setVmTicket(mVmId.toString(), mTicket, String.valueOf(mValidTime), - connectionAction, params); - } - else { - status = getBroker().setVmTicket(mVmId.toString(), mTicket, String.valueOf(mValidTime)); + if (TICKET_USING_UPDATE_DEVICE.compareTo(getVds().getVdsGroupCompatibilityVersion()) <= 0) { + setTicketUsingUpdateDevice(); + } else if (Config.<Boolean> getValue(ConfigValues.SendVmTicketUID, getVds().getVdsGroupCompatibilityVersion().toString())) { + setTicketWithUID(); + } else { + status = getBroker().setVmTicket(getParameters().getVmId().toString(), getParameters().getTicket(), + String.valueOf(getParameters().getValidTime())); } proceedProxyReturnValue(); } + + /** + * Sets console ticket using updateDevice command. This is used in VDSMs that support graphics framebuffer + * as a device. + */ + private void setTicketUsingUpdateDevice() { + Map<String, Object> devStruct = new HashMap<>(); + + devStruct.put("deviceType", "graphics"); + devStruct.put("graphicsType", getParameters().getGraphicsType().name().toLowerCase()); + devStruct.put("password", getParameters().getTicket()); + devStruct.put("ttl", getParameters().getValidTime()); + devStruct.put("existingConnAction", connectionAction); + + status = getBroker().vmUpdateDevice(getParameters().getVmId().toString(), devStruct); + } + + private void setTicketWithUID() { + Map<String, String> params = new HashMap<String, String>(); + params.put("userName", getParameters().getUserName()); + params.put("userId", getParameters().getUserId().toString()); + status = getBroker().setVmTicket(getParameters().getVmId().toString(), getParameters().getTicket(), + String.valueOf(getParameters().getValidTime()), connectionAction, params); + } + } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java index f35a015..17db6ef 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java @@ -526,7 +526,8 @@ private void setVmTicket() { // Create ticket for single sign on. - Frontend.getInstance().runAction(VdcActionType.SetVmTicket, new SetVmTicketParameters(getEntity().getId(), null, TICKET_VALIDITY_SECONDS), + Frontend.getInstance().runAction(VdcActionType.SetVmTicket, + new SetVmTicketParameters(getEntity().getId(), null, TICKET_VALIDITY_SECONDS, GraphicsType.SPICE), new IFrontendActionAsyncCallback() { @Override public void executed(FrontendActionAsyncResult result) { diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java index a39e967..771e273 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java @@ -105,40 +105,41 @@ } private void setVmTicket() { - Frontend.getInstance().runAction(VdcActionType.SetVmTicket, new SetVmTicketParameters(getEntity().getId(), - null, - TICKET_VALIDITY_SECONDS), new IFrontendActionAsyncCallback() { + Frontend.getInstance().runAction(VdcActionType.SetVmTicket, + new SetVmTicketParameters(getEntity().getId(), + null, + TICKET_VALIDITY_SECONDS, + GraphicsType.VNC), + new IFrontendActionAsyncCallback() { + @Override + public void executed(FrontendActionAsyncResult result) { - @Override - public void executed(FrontendActionAsyncResult result) { + VdcReturnValueBase ticketReturnValue = result.getReturnValue(); + if (ticketReturnValue != null && ticketReturnValue.getActionReturnValue() != null) { + otp64 = (String) ticketReturnValue.getActionReturnValue(); + // Determine the display IP. + if (StringHelper.isNullOrEmpty(getEntity().getDisplayIp()) + || "0".equals(getEntity().getDisplayIp())) //$NON-NLS-1$ + { + AsyncQuery _asyncQuery = new AsyncQuery(); + _asyncQuery.setModel(this); + _asyncQuery.asyncCallback = new INewAsyncCallback() { + @Override + public void onSuccess(Object model, Object ReturnValue) { + VncConsoleModel.this.host = (String) ((VdcQueryReturnValue) ReturnValue).getReturnValue(); + VncConsoleModel.this.setAndInvokeClient(); + } + }; - VdcReturnValueBase ticketReturnValue = result.getReturnValue(); - if (ticketReturnValue != null && ticketReturnValue.getActionReturnValue() != null) { - otp64 = (String) ticketReturnValue.getActionReturnValue(); - // Determine the display IP. - if (StringHelper.isNullOrEmpty(getEntity().getDisplayIp()) - || "0".equals(getEntity().getDisplayIp())) //$NON-NLS-1$ - { - AsyncQuery _asyncQuery = new AsyncQuery(); - _asyncQuery.setModel(this); - _asyncQuery.asyncCallback = new INewAsyncCallback() { - @Override - public void onSuccess(Object model, Object ReturnValue) { - VncConsoleModel consoleModel = (VncConsoleModel) model; - VncConsoleModel.this.host = (String) ((VdcQueryReturnValue) ReturnValue).getReturnValue(); - consoleModel.setAndInvokeClient(); + Frontend.getInstance().runQuery(VdcQueryType.GetManagementInterfaceAddressByVmId, + new IdQueryParameters(getEntity().getId()), _asyncQuery); + } else { + VncConsoleModel.this.host = getEntity().getDisplayIp(); + setAndInvokeClient(); } - }; - - Frontend.getInstance().runQuery(VdcQueryType.GetManagementInterfaceAddressByVmId, - new IdQueryParameters(getEntity().getId()), _asyncQuery); - } else { - VncConsoleModel.this.host = getEntity().getDisplayIp(); - setAndInvokeClient(); + } } - } - } - }); + }); } private void setAndInvokeClient() { -- To view, visit http://gerrit.ovirt.org/28574 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib62c9e29349a58156cddba1ca039cf9b7f14e610 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Frank Kobzik <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
