Alissa Bonas has uploaded a new change for review. Change subject: restapi: add storage server connections resource ......................................................................
restapi: add storage server connections resource Add a new root resource for storage server connections. The new api is http://host:port/api/storageconnections. Also, add getAllServerConnections query class, dao method and stored procedure. Change-Id: If6bc32ead098390723825872f6fb292097d52835 Signed-off-by: Alissa Bonas <abo...@redhat.com> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllStorageServerConnectionsQuery.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageServerConnectionDAO.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageServerConnectionDAODbFacadeImpl.java A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StorageServerConnectionsResource.java M backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStorageServerConnectionsResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java M backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/StorageDomainMapper.java M packaging/dbscripts/storages_san_sp.sql 12 files changed, 182 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/17/16617/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllStorageServerConnectionsQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllStorageServerConnectionsQuery.java new file mode 100644 index 0000000..527af7c --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllStorageServerConnectionsQuery.java @@ -0,0 +1,16 @@ +package org.ovirt.engine.core.bll; + +import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; + +public class GetAllStorageServerConnectionsQuery <P extends VdcQueryParametersBase> extends QueriesCommandBase<P> { + + public GetAllStorageServerConnectionsQuery(P parameters) { + super(parameters); + } + + @Override + protected void executeQueryCommand() { + getQueryReturnValue().setReturnValue(getDbFacade().getStorageServerConnectionDao() + .getAll()); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java index 262e450..1d22c4a 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java @@ -175,6 +175,7 @@ // Storage GetStorageDomainById(VdcQueryAuthType.User), GetStorageServerConnectionById, + GetAllStorageServerConnections, GetStoragePoolById(VdcQueryAuthType.User), GetStorageDomainsByConnection, GetStorageDomainsByStoragePoolId(VdcQueryAuthType.User), diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageServerConnectionDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageServerConnectionDAO.java index 1926f1b..e339a4e 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageServerConnectionDAO.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageServerConnectionDAO.java @@ -12,6 +12,13 @@ * */ public interface StorageServerConnectionDAO extends DAO { + + /** + * Get all storage connections from db + * @return + */ + List<StorageServerConnections> getAll(); + /** * Retrieves the connection with the specified id. * diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageServerConnectionDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageServerConnectionDAODbFacadeImpl.java index 12e4f58..c634625 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageServerConnectionDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageServerConnectionDAODbFacadeImpl.java @@ -22,6 +22,12 @@ StorageServerConnectionDAO { @Override + public List<StorageServerConnections> getAll() { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource(); + return getCallsHandler().executeReadList("GetAllstorage_server_connections", mapper,parameterSource) ; + } + + @Override public StorageServerConnections get(String id) { return getCallsHandler().executeRead("Getstorage_server_connectionsByid", mapper, getIdParameterSource(id)); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StorageServerConnectionsResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StorageServerConnectionsResource.java new file mode 100644 index 0000000..61974ff --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StorageServerConnectionsResource.java @@ -0,0 +1,16 @@ +package org.ovirt.engine.api.resource; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.jboss.resteasy.annotations.providers.jaxb.Formatted; +import org.ovirt.engine.api.model.StorageConnections; + +@Path("/storageconnections") +@Produces({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) +public interface StorageServerConnectionsResource { + @GET + @Formatted + public StorageConnections list(); +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd index 0df3464..673cca2 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd @@ -1776,9 +1776,10 @@ <xs:element name="storage_domains" type="StorageDomains"/> + <xs:element name="storage_connections" type="StorageConnections"/> + <xs:group name="NfsStorage"> <xs:sequence> - <xs:element name="address" type="xs:string" minOccurs="0"/> <xs:element name="path" type="xs:string" minOccurs="0"/> <xs:element name="mount_options" type="xs:string" minOccurs="0"/> <xs:element name="vfs_type" type="xs:string" minOccurs="0"/> @@ -1848,6 +1849,16 @@ </xs:sequence> </xs:group> + <xs:group name="IscsiStorageConnection"> + <xs:sequence> + <xs:element name="port" type="xs:unsignedShort" minOccurs="0"/> + <xs:element name="iqn" type="xs:string" minOccurs="0"/> + <xs:element name="username" type="xs:string" minOccurs="0"/> + <xs:element name="password" type="xs:string" minOccurs="0"/> + <xs:element name="portal" type="xs:string" minOccurs="0"/> + </xs:sequence> + </xs:group> + <xs:element name="storage" type="Storage"/> <xs:complexType name="Storage"> @@ -1855,9 +1866,11 @@ <xs:extension base="BaseResource"> <xs:sequence> <xs:element name="type" type="xs:string" minOccurs="0" maxOccurs="1"/> + <xs:element name="address" type="xs:string" minOccurs="0" maxOccurs="1"/> <xs:choice> <xs:group ref="NfsStorage"/> <xs:group ref="IscsiStorage"/> + <xs:group ref="IscsiStorageConnection"/> </xs:choice> <xs:element ref="host" minOccurs="0"/> </xs:sequence> @@ -1917,6 +1930,21 @@ </xs:complexContent> </xs:complexType> + <xs:complexType name="StorageConnections"> + <xs:complexContent> + <xs:extension base="BaseResources"> + <xs:sequence> + <xs:annotation> + <xs:appinfo> + <jaxb:property name="StorageConnections"/> + </xs:appinfo> + </xs:annotation> + <xs:element ref="storage" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <!-- Virtual Machine Templates --> <xs:element name="templates" type="Templates"/> diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java index ff5649c..6bbb52f 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java @@ -49,6 +49,7 @@ import org.ovirt.engine.api.restapi.resource.BackendResource; import org.ovirt.engine.api.restapi.resource.BackendRolesResource; import org.ovirt.engine.api.restapi.resource.BackendStorageDomainsResource; +import org.ovirt.engine.api.restapi.resource.BackendStorageServerConnectionsResource; import org.ovirt.engine.api.restapi.resource.BackendTagsResource; import org.ovirt.engine.api.restapi.resource.BackendTemplatesResource; import org.ovirt.engine.api.restapi.resource.BackendUsersResource; @@ -128,6 +129,7 @@ addResource(new BackendUsersResource()); addResource(new BackendGroupsResource()); addResource(new BackendDomainsResource()); + addResource(new BackendStorageServerConnectionsResource()); // Authentication singletons: final BasicAuthorizationScheme scheme = new BasicAuthorizationScheme(); diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java index 147a766..53a8246 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java @@ -117,6 +117,7 @@ links.add(createLink("vmpools", LinkFlags.SEARCHABLE)); links.add(createLink("vms", LinkFlags.SEARCHABLE)); links.add(createLink("disks", LinkFlags.SEARCHABLE)); + links.add(createLink("storageconnections", LinkFlags.SEARCHABLE)); return links; } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStorageServerConnectionsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStorageServerConnectionsResource.java new file mode 100644 index 0000000..b9cb0ed --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStorageServerConnectionsResource.java @@ -0,0 +1,45 @@ +package org.ovirt.engine.api.restapi.resource; + +import org.ovirt.engine.api.model.Storage; +import org.ovirt.engine.api.model.StorageConnections; +import org.ovirt.engine.api.resource.StorageServerConnectionsResource; +import org.ovirt.engine.core.common.businessentities.StorageServerConnections; +import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +import javax.ws.rs.core.Response; +import java.util.List; + +public class BackendStorageServerConnectionsResource extends AbstractBackendCollectionResource<Storage, StorageServerConnections> implements StorageServerConnectionsResource { + + public BackendStorageServerConnectionsResource() { + super(Storage.class, org.ovirt.engine.core.common.businessentities.StorageServerConnections.class); + } + + @Override + public StorageConnections list() { + return mapCollection(getBackendCollection(VdcQueryType.GetAllStorageServerConnections, + new VdcQueryParametersBase())); + } + + @Override + protected Response performRemove(String id) { + return null; + } + + @Override + protected Storage doPopulate(Storage model, StorageServerConnections entity) { + return null; + } + + private StorageConnections mapCollection(List<StorageServerConnections> entities) { + StorageConnections collection = new StorageConnections(); + for (org.ovirt.engine.core.common.businessentities.StorageServerConnections entity : entities) { + Storage connection = map(entity); + if (connection!=null) { + collection.getStorageConnections().add(connection); + } + } + return collection; + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java index 8df4a21..47280d7 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java @@ -115,7 +115,9 @@ "vms", "vms/search", "disks", - "disks/search" + "disks/search", + "storageconnections", + "storageconnections/search", }; private static final String[] relationshipsGlusterOnly = { @@ -166,6 +168,8 @@ BASE_PATH + "/vms?search={query}", BASE_PATH + "/disks", BASE_PATH + "/disks?search={query}", + BASE_PATH + "/storageconnections", + BASE_PATH + "/storageconnections?search={query}", }; private static final String[] hrefsGlusterOnly = { diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/StorageDomainMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/StorageDomainMapper.java index 19927bd..dfb0fd6 100644 --- a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/StorageDomainMapper.java +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/StorageDomainMapper.java @@ -141,6 +141,50 @@ return model; } + @Mapping(from = org.ovirt.engine.core.common.businessentities.StorageServerConnections.class, to = org.ovirt.engine.api.model.Storage.class) + public static Storage map(StorageServerConnections entity, Storage template) { + Storage model = template != null ? template : new Storage(); + model.setId(entity.getid()); + model.setType(map(entity.getstorage_type(), null)); + if (entity.getstorage_type() == org.ovirt.engine.core.common.businessentities.StorageType.ISCSI) { + model.setAddress(entity.getconnection()); + model.setPort(Integer.parseInt(entity.getport())); + model.setUsername(entity.getuser_name()); + model.setIqn(entity.getiqn()); + } + if(entity.getstorage_type().isFileDomain()) { + setPath(entity,model); + } + if(entity.getstorage_type().equals(org.ovirt.engine.core.common.businessentities.StorageType.NFS)) { + if(entity.getNfsVersion()!=null) { + model.setNfsVersion(entity.getNfsVersion().toString()); + } + if(entity.getNfsRetrans()!=null) { + model.setNfsRetrans(entity.getNfsRetrans().intValue()); + } + if(entity.getNfsTimeo() !=null) { + model.setNfsTimeo(entity.getNfsTimeo().intValue()); + } + } + else if(entity.getstorage_type().equals(org.ovirt.engine.core.common.businessentities.StorageType.POSIXFS)) { + model.setMountOptions(entity.getMountOptions()); + model.setVfsType(entity.getVfsType()); + } + return model; + } + + private static void setPath(StorageServerConnections entity, Storage model) { + if (entity.getconnection().contains(":")) { + String[] parts = entity.getconnection().split(":"); + model.setAddress(parts[0]); + model.setPath(parts[1]); + } + else { + model.setPath(entity.getconnection()); + } + } + + @Mapping(from = StorageType.class, to = org.ovirt.engine.core.common.businessentities.StorageType.class) public static org.ovirt.engine.core.common.businessentities.StorageType map(StorageType storageType, org.ovirt.engine.core.common.businessentities.StorageType template) { diff --git a/packaging/dbscripts/storages_san_sp.sql b/packaging/dbscripts/storages_san_sp.sql index 3b00256..62b4277 100644 --- a/packaging/dbscripts/storages_san_sp.sql +++ b/packaging/dbscripts/storages_san_sp.sql @@ -485,6 +485,16 @@ LANGUAGE plpgsql; +Create or replace FUNCTION GetAllstorage_server_connections() +RETURNS SETOF storage_server_connections + AS $procedure$ +BEGIN + RETURN QUERY SELECT * + FROM storage_server_connections; +END; $procedure$ +LANGUAGE plpgsql; + + Create or replace FUNCTION Getstorage_server_connectionsByVolumeGroupId(v_volume_group_id VARCHAR(50)) RETURNS SETOF storage_server_connections -- To view, visit http://gerrit.ovirt.org/16617 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If6bc32ead098390723825872f6fb292097d52835 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alissa Bonas <abo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches