Search in sources :

Example 36 with NXCPMessage

use of org.netxms.base.NXCPMessage in project netxms by netxms.

the class NXCSession method sendFileStream.

/**
 * Send binary message, data loaded from provided input stream and splitted
 * into chunks of {@value FILE_BUFFER_SIZE} bytes
 *
 * @param requestId request ID
 * @param inputStream data input stream
 * @param listener progress listener
 * @param allowStreamCompression true if data stream compression is allowed
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
private void sendFileStream(final long requestId, final InputStream inputStream, ProgressListener listener, boolean allowStreamCompression) throws IOException, NXCException {
    NXCPMessage msg = new NXCPMessage(NXCPCodes.CMD_FILE_DATA, requestId);
    msg.setBinaryMessage(true);
    Deflater compressor = allowStreamCompression ? new Deflater(9) : null;
    msg.setStream(true, allowStreamCompression);
    boolean success = false;
    final byte[] buffer = new byte[FILE_BUFFER_SIZE];
    long bytesSent = 0;
    while (true) {
        final int bytesRead = inputStream.read(buffer);
        if (bytesRead < FILE_BUFFER_SIZE) {
            msg.setEndOfFile(true);
        }
        if ((compressor != null) && (bytesRead > 0)) {
            byte[] compressedData = new byte[compressor.deflateBound(bytesRead) + 4];
            compressor.setInput(buffer, 0, bytesRead, false);
            compressor.setOutput(compressedData, 4, compressedData.length - 4);
            if (compressor.deflate(JZlib.Z_SYNC_FLUSH) != JZlib.Z_OK)
                throw new NXCException(RCC.IO_ERROR);
            int length = compressedData.length - compressor.getAvailOut();
            byte[] payload = Arrays.copyOf(compressedData, length);
            // DEFLATE method
            payload[0] = 2;
            // reserved
            payload[1] = 0;
            // uncompressed length, high bits
            payload[2] = (byte) ((bytesRead >> 8) & 0xFF);
            // uncompressed length, low bits
            payload[3] = (byte) (bytesRead & 0xFF);
            msg.setBinaryData(payload);
        } else {
            msg.setBinaryData((bytesRead == -1) ? new byte[0] : Arrays.copyOf(buffer, bytesRead));
        }
        sendMessage(msg);
        bytesSent += (bytesRead == -1) ? 0 : bytesRead;
        if (listener != null)
            listener.markProgress(bytesSent);
        if (bytesRead < FILE_BUFFER_SIZE) {
            success = true;
            break;
        }
    }
    if (compressor != null)
        compressor.deflateEnd();
    if (!success) {
        NXCPMessage abortMessage = new NXCPMessage(NXCPCodes.CMD_ABORT_FILE_TRANSFER, requestId);
        abortMessage.setBinaryMessage(true);
        sendMessage(abortMessage);
        waitForRCC(abortMessage.getMessageId());
    }
}
Also used : Deflater(com.jcraft.jzlib.Deflater) NXCPMessage(org.netxms.base.NXCPMessage) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 37 with NXCPMessage

use of org.netxms.base.NXCPMessage in project netxms by netxms.

the class NXCSession method getNodeSoftwarePackages.

/**
 * Get list of software packages installed on node.
 *
 * @param nodeId node object identifier
 * @return root component
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<SoftwarePackage> getNodeSoftwarePackages(long nodeId) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_NODE_SOFTWARE);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_ELEMENTS);
    List<SoftwarePackage> packages = new ArrayList<SoftwarePackage>(count);
    long varId = NXCPCodes.VID_ELEMENT_LIST_BASE;
    for (int i = 0; i < count; i++) {
        packages.add(new SoftwarePackage(response, varId));
        varId += 10;
    }
    return packages;
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 38 with NXCPMessage

use of org.netxms.base.NXCPMessage in project netxms by netxms.

the class NXCSession method deleteDciSummaryTable.

/**
 * Delete DCI summary table.
 *
 * @param id The ID of the summary table
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void deleteDciSummaryTable(int id) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_DELETE_SUMMARY_TABLE);
    msg.setFieldInt32(NXCPCodes.VID_SUMMARY_TABLE_ID, id);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage)

Example 39 with NXCPMessage

use of org.netxms.base.NXCPMessage in project netxms by netxms.

the class NXCSession method deleteMappingTable.

/**
 * Delete mapping table
 *
 * @param id mapping table ID
 * @throws IOException if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void deleteMappingTable(int id) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_DELETE_MAPPING_TABLE);
    msg.setFieldInt32(NXCPCodes.VID_MAPPING_TABLE_ID, id);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage)

Example 40 with NXCPMessage

use of org.netxms.base.NXCPMessage in project netxms by netxms.

the class NXCSession method compileScript.

/**
 * Compile NXSL script on server. Field *success* in compilation result object will indicate compilation status.
 * If compilation fails, field *errorMessage* will contain compilation error message.
 *
 * @param source script source
 * @param serialize flag to indicate if compiled script should be serialized and sent back to client
 * @return script compilation result object
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public ScriptCompilationResult compileScript(String source, boolean serialize) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_COMPILE_SCRIPT);
    msg.setField(NXCPCodes.VID_SCRIPT, source);
    msg.setField(NXCPCodes.VID_SERIALIZE, serialize);
    sendMessage(msg);
    return new ScriptCompilationResult(waitForRCC(msg.getMessageId()));
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage)

Aggregations

NXCPMessage (org.netxms.base.NXCPMessage)274 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)69 AccessPoint (org.netxms.client.objects.AccessPoint)66 ArrayList (java.util.ArrayList)44 IOException (java.io.IOException)8 HashMap (java.util.HashMap)7 DciSummaryTable (org.netxms.client.datacollection.DciSummaryTable)7 MappingTable (org.netxms.client.mt.MappingTable)7 NXCPException (org.netxms.base.NXCPException)5 UnknownHostException (java.net.UnknownHostException)3 GeneralSecurityException (java.security.GeneralSecurityException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 UUID (java.util.UUID)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 MessageProcessingResult (com.radensolutions.reporting.service.MessageProcessingResult)2 FileInputStream (java.io.FileInputStream)2 Socket (java.net.Socket)2 SignatureException (java.security.SignatureException)2 Date (java.util.Date)2 List (java.util.List)2