Search in sources :

Example 1 with ResourcesResponse

use of com.emc.storageos.geomodel.ResourcesResponse in project coprhd-controller by CoprHD.

the class GeoServiceClient method queryByType.

/**
 * Get the GeoVisible resource IDs from the geosvc
 *
 * @param clazz the resource type to be queried
 * @param activeOnly
 * @return the ResourceIDsRespons response
 * @throws Exception
 */
public <T extends GeoVisibleResource> Iterator<URI> queryByType(Class<T> clazz, boolean activeOnly) throws Exception {
    WebResource rRoot = createRequest(GEOVISIBLE_URI + clazz.getName()).queryParam("active_only", Boolean.toString(activeOnly));
    rRoot.accept(MediaType.APPLICATION_OCTET_STREAM);
    ClientResponse resp = addSignature(rRoot).get(ClientResponse.class);
    InputStream input = resp.getEntityInputStream();
    ObjectInputStream objInputStream = new ObjectInputStream(input);
    @SuppressWarnings("rawtypes") ResourcesResponse resources = (ResourcesResponse) objInputStream.readObject();
    @SuppressWarnings("unchecked") List<URI> ids = resources.getObjects();
    return ids.iterator();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) WebResource(com.sun.jersey.api.client.WebResource) URI(java.net.URI) ResourcesResponse(com.emc.storageos.geomodel.ResourcesResponse) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with ResourcesResponse

use of com.emc.storageos.geomodel.ResourcesResponse in project coprhd-controller by CoprHD.

the class GeoServiceClient method queryObjects.

/**
 * Get the GeoVisible resources with given ids
 *
 * @param clazz the resource type to be queried
 * @param ids List of the resource IDs
 * @return list of resources
 * @throws Exception
 */
public <T extends GeoVisibleResource> Iterator<T> queryObjects(Class<T> clazz, List<URI> ids) throws Exception {
    BulkIdParam param = new BulkIdParam();
    param.setIds(ids);
    WebResource rRoot = createRequest(GEOVISIBLE_URI + clazz.getName() + "/objects");
    rRoot.accept(MediaType.APPLICATION_OCTET_STREAM);
    ClientResponse resp = addSignature(rRoot).post(ClientResponse.class, param);
    InputStream input = resp.getEntityInputStream();
    ObjectInputStream objInputStream = new ObjectInputStream(input);
    @SuppressWarnings("unchecked") ResourcesResponse<T> resources = (ResourcesResponse<T>) objInputStream.readObject();
    List<T> list = resources.getObjects();
    return list.iterator();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BulkIdParam(com.emc.storageos.model.BulkIdParam) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) WebResource(com.sun.jersey.api.client.WebResource) ResourcesResponse(com.emc.storageos.geomodel.ResourcesResponse) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with ResourcesResponse

use of com.emc.storageos.geomodel.ResourcesResponse in project coprhd-controller by CoprHD.

the class GeoServiceClient method queryByType.

/**
 * Query the GeoVisible resource IDs from the geosvc
 *
 * @param clazz the resource type to be queried
 * @param activeOnly
 * @param startId where the query starts, if it's null, start from the beginning
 * @param maxCount if maxCount>0, the max number of IDs returned, otherwise use the default setting on the server side
 * @return the ResourceIDsRespons response
 * @throws Exception
 */
public <T extends GeoVisibleResource> List<URI> queryByType(Class<T> clazz, boolean activeOnly, URI startId, int maxCount) throws Exception {
    WebResource rRoot = createRequest(GEOVISIBLE_URI + clazz.getName()).queryParam("active_only", Boolean.toString(activeOnly));
    if (startId != null) {
        rRoot = rRoot.queryParam("start_id", startId.toString());
    }
    if (maxCount > 0) {
        rRoot = rRoot.queryParam("max_count", Integer.toString(maxCount));
    }
    rRoot.accept(MediaType.APPLICATION_OCTET_STREAM);
    ClientResponse resp = addSignature(rRoot).get(ClientResponse.class);
    InputStream input = resp.getEntityInputStream();
    ObjectInputStream objInputStream = new ObjectInputStream(input);
    @SuppressWarnings("rawtypes") ResourcesResponse resources = (ResourcesResponse) objInputStream.readObject();
    @SuppressWarnings("unchecked") List<URI> ids = resources.getObjects();
    return ids;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) WebResource(com.sun.jersey.api.client.WebResource) URI(java.net.URI) ResourcesResponse(com.emc.storageos.geomodel.ResourcesResponse) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with ResourcesResponse

use of com.emc.storageos.geomodel.ResourcesResponse in project coprhd-controller by CoprHD.

the class GeoServiceClient method queryByConstraint.

/**
 * Query the GeoVisible resources by conditions
 *
 * @param constraint the query condition
 * @param result the query result
 * @return list of resources
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public <T> void queryByConstraint(Constraint constraint, QueryResultList<T> result) throws Exception {
    ConstraintDescriptor constrainDescriptor = constraint.toConstraintDescriptor();
    WebResource rRoot = createRequest(GEOVISIBLE_URI + "constraint/" + result.getClass().getName());
    rRoot.accept(MediaType.APPLICATION_OCTET_STREAM);
    ClientResponse resp = addSignature(rRoot).post(ClientResponse.class, constrainDescriptor);
    InputStream input = resp.getEntityInputStream();
    ObjectInputStream objInputStream = new ObjectInputStream(input);
    ResourcesResponse<?> resources = (ResourcesResponse<?>) objInputStream.readObject();
    List<Object> queryResult = (List<Object>) resources.getObjects();
    List<T> ret = new ArrayList<T>();
    for (Object obj : queryResult) {
        ret.add((T) obj);
    }
    result.setResult(ret.iterator());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) WebResource(com.sun.jersey.api.client.WebResource) ResourcesResponse(com.emc.storageos.geomodel.ResourcesResponse) ConstraintDescriptor(com.emc.storageos.db.client.constraint.ConstraintDescriptor) DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) QueryResultList(com.emc.storageos.db.client.constraint.QueryResultList) List(java.util.List) ObjectInputStream(java.io.ObjectInputStream)

Example 5 with ResourcesResponse

use of com.emc.storageos.geomodel.ResourcesResponse in project coprhd-controller by CoprHD.

the class GeoServiceClient method queryByConstraint.

/**
 * Query the GeoVisible resources by conditions
 *
 * @param constraint the query condition
 * @param result the query result
 * @param startId where the query starts, if it's null, query starts at the beginning
 * @param maxCount the max number of resources returned
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public <T> void queryByConstraint(Constraint constraint, QueryResultList<T> result, URI startId, int maxCount) throws Exception {
    ConstraintDescriptor constrainDescriptor = constraint.toConstraintDescriptor();
    WebResource rRoot = createRequest(GEOVISIBLE_URI + "constraint/" + result.getClass().getName());
    if (startId != null) {
        rRoot = rRoot.queryParam("start_id", startId.toString());
    }
    if (maxCount > 0) {
        rRoot = rRoot.queryParam("max_count", Integer.toString(maxCount));
    }
    rRoot.accept(MediaType.APPLICATION_OCTET_STREAM);
    ClientResponse resp = addSignature(rRoot).post(ClientResponse.class, constrainDescriptor);
    InputStream input = resp.getEntityInputStream();
    ObjectInputStream objInputStream = new ObjectInputStream(input);
    ResourcesResponse<?> resources = (ResourcesResponse<?>) objInputStream.readObject();
    List<Object> queryResult = (List<Object>) resources.getObjects();
    List<T> ret = new ArrayList<T>();
    for (Object obj : queryResult) {
        ret.add((T) obj);
    }
    result.setResult(ret.iterator());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) WebResource(com.sun.jersey.api.client.WebResource) ResourcesResponse(com.emc.storageos.geomodel.ResourcesResponse) ConstraintDescriptor(com.emc.storageos.db.client.constraint.ConstraintDescriptor) DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) QueryResultList(com.emc.storageos.db.client.constraint.QueryResultList) List(java.util.List) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ResourcesResponse (com.emc.storageos.geomodel.ResourcesResponse)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)6 WebResource (com.sun.jersey.api.client.WebResource)6 InputStream (java.io.InputStream)6 ObjectInputStream (java.io.ObjectInputStream)6 DataObject (com.emc.storageos.db.client.model.DataObject)3 Constraint (com.emc.storageos.db.client.constraint.Constraint)2 ConstraintDescriptor (com.emc.storageos.db.client.constraint.ConstraintDescriptor)2 QueryResultList (com.emc.storageos.db.client.constraint.QueryResultList)2 BulkIdParam (com.emc.storageos.model.BulkIdParam)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2