Ravi Nori has uploaded a new change for review. Change subject: restapi : close api gaps for operation using id and name (#890329) ......................................................................
restapi : close api gaps for operation using id and name (#890329) Update host can use cluster id and not cluster name This patch lets the user specify cluster id or name for updating a vm. Change-Id: I93a423f01fd6b140482d17558e058604b6009a2a Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=890329 Signed-off-by: Ravi Nori <[email protected]> --- M backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java 3 files changed, 50 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/47/11947/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml index c9b0431..00dd826 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml @@ -1501,7 +1501,7 @@ parameterType: Host signatures: - mandatoryArguments: {} - optionalArguments: {host.name: 'xs:string', host.address: 'xs:string', host.root_password: 'xs:string', host.cluster.id: 'xs:string', + optionalArguments: {host.name: 'xs:string', host.address: 'xs:string', host.root_password: 'xs:string', host.cluster.id|name: 'xs:string', host.port: 'xs:int', host.storage_manager.priority: 'xs:int', host.power_management.type: 'xs:string', host.power_management.enabled: 'xs:boolean', host.power_management.address: 'xs:string', host.power_management.user_name: 'xs:string', host.power_management.password: 'xs:string', host.power_management.options.option--COLLECTION: {option.name: 'xs:string', option.value: 'xs:string'}, host.power_management.pm_proxy--COLLECTION: {propietary : 'xs:string'}, host.power_management.agents.agent--COLLECTION:{type: 'xs:string', address: 'xs:string', user_name: 'xs:string', password: 'xs:string', options.option--COLLECTION: {option.name: 'xs:string', option.value: 'xs:string'}}} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java index b88ec06..3752439 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostResource.java @@ -78,9 +78,10 @@ validateEnums(Host.class, incoming); QueryIdResolver<Guid> hostResolver = new QueryIdResolver<Guid>(VdcQueryType.GetVdsByVdsId, GetVdsByVdsIdParameters.class); VDS entity = getEntity(hostResolver, true); - if (incoming.isSetCluster() && incoming.getCluster().isSetId() && !asGuid(incoming.getCluster().getId()).equals(entity.getvds_group_id())) { + if (incoming.isSetCluster() && (incoming.getCluster().isSetId() || incoming.getCluster().isSetName())) { + Guid clusterId = lookupClusterId(incoming); performAction(VdcActionType.ChangeVDSCluster, - new ChangeVDSClusterParameters(asGuid(incoming.getCluster().getId()), guid)); + new ChangeVDSClusterParameters(clusterId, guid)); } return performUpdate(incoming, entity, @@ -137,6 +138,12 @@ return host; } + protected Guid lookupClusterId(Host host) { + return host.getCluster().isSetId() ? asGuid(host.getCluster().getId()) + : + lookupClusterByName(host.getCluster().getName()).getId(); + } + protected VDSGroup lookupClusterByName(String name) { return getEntity(VDSGroup.class, SearchType.Cluster, "Cluster: name=" + name); } diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java index f5130b9..728941f 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostResourceTest.java @@ -53,6 +53,8 @@ import static org.ovirt.engine.api.restapi.test.util.TestHelper.eqQueryParams; import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.verify; +import org.ovirt.engine.core.common.businessentities.VDSGroup; +import org.ovirt.engine.core.common.interfaces.SearchType; public class BackendHostResourceTest extends AbstractBackendSubResourceTest<Host, VDS, BackendHostResource> { @@ -185,6 +187,44 @@ } @Test + public void testUpdateWithClusterName() throws Exception { + String clusterName = "Default"; + setUpGetEntityExpectations(2); + setUpGetEntityExpectations( + "Cluster: name=" + clusterName, + SearchType.Cluster, + getVdsGroup(clusterName, GUIDS[1])); + setUriInfo(setUpActionExpectations(VdcActionType.ChangeVDSCluster, + ChangeVDSClusterParameters.class, + new String[] { "ClusterId", "VdsId" }, + new Object[] { GUIDS[1], GUIDS[0]}, + true, + true, + new VdcReturnValueBase(), + false)); + + setUriInfo(setUpActionExpectations(VdcActionType.UpdateVds, + UpdateVdsActionParameters.class, + new String[] { "RootPassword" }, + new Object[] { "" }, + true, + true)); + + Cluster cluster = new Cluster(); + cluster.setName(clusterName); + Host host = getModel(0); + host.setCluster(cluster); + verifyModel(resource.update(host), 0); + } + + private VDSGroup getVdsGroup(String name, Guid id) { + VDSGroup vdsGroup = control.createMock(VDSGroup.class); + expect(vdsGroup.getId()).andReturn(id).anyTimes(); + expect(vdsGroup.getname()).andReturn(name).anyTimes(); + return vdsGroup; + } + + @Test public void testUpdateCantDo() throws Exception { doTestBadUpdate(false, true, CANT_DO); } -- To view, visit http://gerrit.ovirt.org/11947 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I93a423f01fd6b140482d17558e058604b6009a2a Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: engine_3.2 Gerrit-Owner: Ravi Nori <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
