Search in sources :

Example 1 with RequestPacket

use of com.emc.nas.vnxfile.xmlapi.RequestPacket in project coprhd-controller by CoprHD.

the class VNXFileInputRequestBuilder method getSingleQueryStatsPacket.

/**
 * Marshal the RequestPacket java object for the given QueryStats
 * argument. This will be used when client wants to use QueryStats to retrieve information.
 *
 * @param stats : QueryStats
 * @return : Stream of Input XML generated.
 * @throws JAXBException
 */
public InputStream getSingleQueryStatsPacket(QueryStats stats) throws JAXBException {
    InputStream inputStream = null;
    List<Request> requests = new ArrayList<Request>(1);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    RequestPacket requestPacket = new RequestPacket();
    try {
        Request request = new Request();
        request.setQueryStats(stats);
        requests.add(request);
        requestPacket.getRequestOrRequestEx().addAll(requests);
        _marshaller.marshal(requestPacket, outputStream);
        inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    } finally {
        try {
            outputStream.close();
        } catch (IOException e) {
            _logger.error("Exception occurred while closing the stream due to ", e);
        }
    }
    return inputStream;
}
Also used : RequestPacket(com.emc.nas.vnxfile.xmlapi.RequestPacket) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.emc.nas.vnxfile.xmlapi.Request) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with RequestPacket

use of com.emc.nas.vnxfile.xmlapi.RequestPacket in project coprhd-controller by CoprHD.

the class VNXFileInputRequestBuilder method getQueryExParamPacket.

public InputStream getQueryExParamPacket(Object queryParam) throws JAXBException {
    InputStream inputStream = null;
    List<RequestEx> requests = new ArrayList<RequestEx>(1);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    RequestPacket requestPacket = new RequestPacket();
    try {
        QueryEx query = new QueryEx();
        query.getQueryRequestChoiceEx().add(queryParam);
        RequestEx request = new RequestEx();
        request.setQuery(query);
        requests.add(request);
        APIVersion apiVer = APIVersion.V_1_1;
        requestPacket.setApiVersion(apiVer);
        requestPacket.getRequestOrRequestEx().addAll(requests);
        _marshaller.marshal(requestPacket, outputStream);
        inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    } finally {
        try {
            outputStream.close();
        } catch (IOException e) {
            _logger.error("Exception occurred while closing the stream due to ", e);
        }
    }
    return inputStream;
}
Also used : RequestPacket(com.emc.nas.vnxfile.xmlapi.RequestPacket) APIVersion(com.emc.nas.vnxfile.xmlapi.APIVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RequestEx(com.emc.nas.vnxfile.xmlapi.RequestEx) QueryEx(com.emc.nas.vnxfile.xmlapi.QueryEx)

Example 3 with RequestPacket

use of com.emc.nas.vnxfile.xmlapi.RequestPacket in project coprhd-controller by CoprHD.

the class VNXFileInputRequestBuilder method getQueryParamPacket.

/**
 * Marshal the generated XML for a given QueryParam.
 *
 * @param queryParam : queryParam object.
 * @return
 */
public InputStream getQueryParamPacket(Object queryParam, boolean is_1_2_VerionToSet) throws JAXBException {
    InputStream inputStream = null;
    List<Request> requests = new ArrayList<Request>(1);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    RequestPacket requestPacket = new RequestPacket();
    try {
        Query query = new Query();
        query.getQueryRequestChoice().add(queryParam);
        Request request = new Request();
        request.setQuery(query);
        requests.add(request);
        _logger.info("API Version to set {}", is_1_2_VerionToSet);
        if (is_1_2_VerionToSet) {
            _logger.info("Setting the API Version on Request Packet");
            APIVersion apiVer = APIVersion.V_1_2;
            requestPacket.setApiVersion(apiVer);
        }
        requestPacket.getRequestOrRequestEx().addAll(requests);
        _marshaller.marshal(requestPacket, outputStream);
        inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    } finally {
        try {
            outputStream.close();
        } catch (IOException e) {
            _logger.error("Exception occurred while closing the stream due to ", e);
        }
    }
    return inputStream;
}
Also used : RequestPacket(com.emc.nas.vnxfile.xmlapi.RequestPacket) Query(com.emc.nas.vnxfile.xmlapi.Query) APIVersion(com.emc.nas.vnxfile.xmlapi.APIVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.emc.nas.vnxfile.xmlapi.Request) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 4 with RequestPacket

use of com.emc.nas.vnxfile.xmlapi.RequestPacket in project coprhd-controller by CoprHD.

the class VNXFileInputRequestBuilder method getMultiRequestQueryStatsPacket.

/**
 * This method responsible to generate a multiple request packets
 * for the given list of QueryStats.
 *
 * @param stats : list of QueryStats.
 * @return : stream
 */
public InputStream getMultiRequestQueryStatsPacket(List<QueryStats> stats) throws JAXBException {
    InputStream inputStream = null;
    List<Request> requests = new ArrayList<Request>(stats.size());
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    RequestPacket requestPacket = new RequestPacket();
    try {
        // Create a new Request object for each QueryStat
        for (QueryStats querStat : stats) {
            Request request = new Request();
            request.setQueryStats(querStat);
            requests.add(request);
        }
        requestPacket.getRequestOrRequestEx().addAll(requests);
        _marshaller.marshal(requestPacket, outputStream);
        inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    } finally {
        try {
            outputStream.close();
        } catch (IOException e) {
            _logger.error("IOException occurred while querying due to ", e);
        }
    }
    return inputStream;
}
Also used : RequestPacket(com.emc.nas.vnxfile.xmlapi.RequestPacket) QueryStats(com.emc.nas.vnxfile.xmlapi.QueryStats) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.emc.nas.vnxfile.xmlapi.Request) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 5 with RequestPacket

use of com.emc.nas.vnxfile.xmlapi.RequestPacket in project coprhd-controller by CoprHD.

the class VNXFileInputRequestBuilder method getTaskParamPacket.

public InputStream getTaskParamPacket(Object taskParam, boolean setApiVersion) throws JAXBException {
    InputStream inputStream = null;
    List<Request> requests = new ArrayList<Request>(1);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    RequestPacket reqPacket = new RequestPacket();
    try {
        Task task = (Task) taskParam;
        Long timeout = 3000L;
        String timeoutStr = getTimeout();
        _logger.info("Time out value " + timeoutStr);
        if (timeoutStr != null && !timeoutStr.isEmpty()) {
            timeout = Long.parseLong(timeoutStr);
        }
        task.setTimeout(timeout);
        Request request = new Request();
        request.setStartTask(task);
        requests.add(request);
        if (setApiVersion) {
            APIVersion apiVer = APIVersion.V_1_1;
            reqPacket.setApiVersion(apiVer);
        }
        reqPacket.getRequestOrRequestEx().addAll(requests);
        _marshaller.marshal(reqPacket, outputStream);
        inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    } finally {
        try {
            outputStream.close();
        } catch (IOException e) {
            _logger.error("Exception occurred while closing the stream due to ", e);
        }
    }
    return inputStream;
}
Also used : Task(com.emc.nas.vnxfile.xmlapi.Task) RequestPacket(com.emc.nas.vnxfile.xmlapi.RequestPacket) APIVersion(com.emc.nas.vnxfile.xmlapi.APIVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.emc.nas.vnxfile.xmlapi.Request) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

RequestPacket (com.emc.nas.vnxfile.xmlapi.RequestPacket)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 Request (com.emc.nas.vnxfile.xmlapi.Request)4 APIVersion (com.emc.nas.vnxfile.xmlapi.APIVersion)3 Query (com.emc.nas.vnxfile.xmlapi.Query)1 QueryEx (com.emc.nas.vnxfile.xmlapi.QueryEx)1 QueryStats (com.emc.nas.vnxfile.xmlapi.QueryStats)1 RequestEx (com.emc.nas.vnxfile.xmlapi.RequestEx)1 Task (com.emc.nas.vnxfile.xmlapi.Task)1