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: I0827f5984d630db540f2415e32c1e8e685996b38 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, 52 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/32/12032/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 dca1ff2..e76222c 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 @@ -1506,7 +1506,7 @@ parameterType: Host signatures: - mandatoryArguments: {} - optionalArguments: {host.name: 'xs:string', host.address: 'xs:string', host.root_password: 'xs:string', host.display.address: 'xs:string', host.cluster.id: 'xs:string', + optionalArguments: {host.name: 'xs:string', host.address: 'xs:string', host.root_password: 'xs:string', host.display.address: '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 f092b32..2b04700 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 @@ -73,9 +73,12 @@ 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.getVdsGroupId())) { - performAction(VdcActionType.ChangeVDSCluster, - new ChangeVDSClusterParameters(asGuid(incoming.getCluster().getId()), guid)); + if (incoming.isSetCluster() && (incoming.getCluster().isSetId() || incoming.getCluster().isSetName())) { + Guid clusterId = lookupClusterId(incoming); + if (!clusterId.equals(entity.getVdsGroupId())) { + performAction(VdcActionType.ChangeVDSCluster, + new ChangeVDSClusterParameters(clusterId, guid)); + } } return performUpdate(incoming, entity, @@ -132,6 +135,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..566e808 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,43 @@ } @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/12032 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0827f5984d630db540f2415e32c1e8e685996b38 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Ravi Nori <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
