Search in sources :

Example 1 with ClusterResource

use of org.netxms.client.objects.ClusterResource in project netxms by netxms.

the class NXCSession method modifyObject.

/**
 * Modify object (generic interface, in most cases wrapper functions should
 * be used instead).
 *
 * @param data     Object modification data
 * @param userData user-defined data for custom object modification
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void modifyObject(final NXCObjectModificationData data, final Object userData) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_MODIFY_OBJECT);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) data.getObjectId());
    // Object name
    if (data.isFieldSet(NXCObjectModificationData.NAME)) {
        msg.setField(NXCPCodes.VID_OBJECT_NAME, data.getName());
    }
    // Primary IP
    if (data.isFieldSet(NXCObjectModificationData.PRIMARY_IP)) {
        msg.setField(NXCPCodes.VID_IP_ADDRESS, data.getPrimaryIpAddress());
    }
    // Access control list
    if (data.isFieldSet(NXCObjectModificationData.ACL)) {
        final AccessListElement[] acl = data.getACL();
        msg.setFieldInt32(NXCPCodes.VID_ACL_SIZE, acl.length);
        msg.setFieldInt16(NXCPCodes.VID_INHERIT_RIGHTS, data.isInheritAccessRights() ? 1 : 0);
        long id1 = NXCPCodes.VID_ACL_USER_BASE;
        long id2 = NXCPCodes.VID_ACL_RIGHTS_BASE;
        for (int i = 0; i < acl.length; i++) {
            msg.setFieldInt32(id1++, (int) acl[i].getUserId());
            msg.setFieldInt32(id2++, acl[i].getAccessRights());
        }
    }
    if (data.isFieldSet(NXCObjectModificationData.CUSTOM_ATTRIBUTES)) {
        Map<String, String> attrList = data.getCustomAttributes();
        Iterator<String> it = attrList.keySet().iterator();
        long id = NXCPCodes.VID_CUSTOM_ATTRIBUTES_BASE;
        int count = 0;
        while (it.hasNext()) {
            String key = it.next();
            String value = attrList.get(key);
            msg.setField(id++, key);
            msg.setField(id++, value);
            count++;
        }
        msg.setFieldInt32(NXCPCodes.VID_NUM_CUSTOM_ATTRIBUTES, count);
    }
    if (data.isFieldSet(NXCObjectModificationData.AUTOBIND_FILTER)) {
        msg.setField(NXCPCodes.VID_AUTOBIND_FILTER, data.getAutoBindFilter());
    }
    if (data.isFieldSet(NXCObjectModificationData.FILTER)) {
        msg.setField(NXCPCodes.VID_FILTER, data.getFilter());
    }
    if (data.isFieldSet(NXCObjectModificationData.DESCRIPTION)) {
        msg.setField(NXCPCodes.VID_DESCRIPTION, data.getDescription());
    }
    if (data.isFieldSet(NXCObjectModificationData.VERSION)) {
        msg.setFieldInt32(NXCPCodes.VID_VERSION, data.getVersion());
    }
    // Configuration file
    if (data.isFieldSet(NXCObjectModificationData.POLICY_CONFIG)) {
        msg.setField(NXCPCodes.VID_CONFIG_FILE_DATA, data.getConfigFileContent());
    }
    if (data.isFieldSet(NXCObjectModificationData.AGENT_PORT)) {
        msg.setFieldInt16(NXCPCodes.VID_AGENT_PORT, data.getAgentPort());
    }
    if (data.isFieldSet(NXCObjectModificationData.AGENT_PROXY)) {
        msg.setFieldInt32(NXCPCodes.VID_AGENT_PROXY, (int) data.getAgentProxy());
    }
    if (data.isFieldSet(NXCObjectModificationData.AGENT_AUTH)) {
        msg.setFieldInt16(NXCPCodes.VID_AUTH_METHOD, data.getAgentAuthMethod());
        msg.setField(NXCPCodes.VID_SHARED_SECRET, data.getAgentSecret());
    }
    if (data.isFieldSet(NXCObjectModificationData.TRUSTED_NODES)) {
        final long[] nodes = data.getTrustedNodes();
        msg.setFieldInt32(NXCPCodes.VID_NUM_TRUSTED_NODES, nodes.length);
        msg.setField(NXCPCodes.VID_TRUSTED_NODES, nodes);
    }
    if (data.isFieldSet(NXCObjectModificationData.SNMP_VERSION)) {
        msg.setFieldInt16(NXCPCodes.VID_SNMP_VERSION, data.getSnmpVersion());
    }
    if (data.isFieldSet(NXCObjectModificationData.SNMP_AUTH)) {
        msg.setField(NXCPCodes.VID_SNMP_AUTH_OBJECT, data.getSnmpAuthName());
        msg.setField(NXCPCodes.VID_SNMP_AUTH_PASSWORD, data.getSnmpAuthPassword());
        msg.setField(NXCPCodes.VID_SNMP_PRIV_PASSWORD, data.getSnmpPrivPassword());
        int methods = data.getSnmpAuthMethod() | (data.getSnmpPrivMethod() << 8);
        msg.setFieldInt16(NXCPCodes.VID_SNMP_USM_METHODS, methods);
    }
    if (data.isFieldSet(NXCObjectModificationData.SNMP_PROXY)) {
        msg.setFieldInt32(NXCPCodes.VID_SNMP_PROXY, (int) data.getSnmpProxy());
    }
    if (data.isFieldSet(NXCObjectModificationData.SNMP_PORT)) {
        msg.setFieldInt16(NXCPCodes.VID_SNMP_PORT, data.getSnmpPort());
    }
    if (data.isFieldSet(NXCObjectModificationData.ICMP_PROXY)) {
        msg.setFieldInt32(NXCPCodes.VID_ICMP_PROXY, (int) data.getIcmpProxy());
    }
    if (data.isFieldSet(NXCObjectModificationData.GEOLOCATION)) {
        final GeoLocation gl = data.getGeolocation();
        msg.setFieldInt16(NXCPCodes.VID_GEOLOCATION_TYPE, gl.getType());
        msg.setField(NXCPCodes.VID_LATITUDE, gl.getLatitude());
        msg.setField(NXCPCodes.VID_LONGITUDE, gl.getLongitude());
        msg.setFieldInt16(NXCPCodes.VID_ACCURACY, gl.getAccuracy());
        if (gl.getTimestamp() != null) {
            msg.setFieldInt64(NXCPCodes.VID_GEOLOCATION_TIMESTAMP, gl.getTimestamp().getTime() / 1000);
        }
    }
    if (data.isFieldSet(NXCObjectModificationData.MAP_LAYOUT)) {
        msg.setFieldInt16(NXCPCodes.VID_LAYOUT, data.getMapLayout().getValue());
    }
    if (data.isFieldSet(NXCObjectModificationData.MAP_BACKGROUND)) {
        msg.setField(NXCPCodes.VID_BACKGROUND, data.getMapBackground());
        msg.setField(NXCPCodes.VID_BACKGROUND_LATITUDE, data.getMapBackgroundLocation().getLatitude());
        msg.setField(NXCPCodes.VID_BACKGROUND_LONGITUDE, data.getMapBackgroundLocation().getLongitude());
        msg.setFieldInt16(NXCPCodes.VID_BACKGROUND_ZOOM, data.getMapBackgroundZoom());
        msg.setFieldInt32(NXCPCodes.VID_BACKGROUND_COLOR, data.getMapBackgroundColor());
    }
    if (data.isFieldSet(NXCObjectModificationData.IMAGE)) {
        msg.setField(NXCPCodes.VID_IMAGE, data.getImage());
    }
    if (data.isFieldSet(NXCObjectModificationData.MAP_CONTENT)) {
        msg.setFieldInt32(NXCPCodes.VID_NUM_ELEMENTS, data.getMapElements().size());
        long varId = NXCPCodes.VID_ELEMENT_LIST_BASE;
        for (NetworkMapElement e : data.getMapElements()) {
            e.fillMessage(msg, varId);
            varId += 100;
        }
        msg.setFieldInt32(NXCPCodes.VID_NUM_LINKS, data.getMapLinks().size());
        varId = NXCPCodes.VID_LINK_LIST_BASE;
        for (NetworkMapLink l : data.getMapLinks()) {
            l.fillMessage(msg, varId);
            varId += 20;
        }
    }
    if (data.isFieldSet(NXCObjectModificationData.COLUMN_COUNT)) {
        msg.setFieldInt16(NXCPCodes.VID_NUM_COLUMNS, data.getColumnCount());
    }
    if (data.isFieldSet(NXCObjectModificationData.DASHBOARD_ELEMENTS)) {
        msg.setFieldInt32(NXCPCodes.VID_NUM_ELEMENTS, data.getDashboardElements().size());
        long varId = NXCPCodes.VID_ELEMENT_LIST_BASE;
        for (DashboardElement e : data.getDashboardElements()) {
            e.fillMessage(msg, varId);
            varId += 10;
        }
    }
    if (data.isFieldSet(NXCObjectModificationData.URL_LIST)) {
        msg.setFieldInt32(NXCPCodes.VID_NUM_URLS, data.getUrls().size());
        long fieldId = NXCPCodes.VID_URL_LIST_BASE;
        for (ObjectUrl u : data.getUrls()) {
            u.fillMessage(msg, fieldId);
            fieldId += 10;
        }
    }
    if (data.isFieldSet(NXCObjectModificationData.SCRIPT)) {
        msg.setField(NXCPCodes.VID_SCRIPT, data.getScript());
    }
    if (data.isFieldSet(NXCObjectModificationData.ACTIVATION_EVENT)) {
        msg.setFieldInt32(NXCPCodes.VID_ACTIVATION_EVENT, data.getActivationEvent());
    }
    if (data.isFieldSet(NXCObjectModificationData.DEACTIVATION_EVENT)) {
        msg.setFieldInt32(NXCPCodes.VID_DEACTIVATION_EVENT, data.getDeactivationEvent());
    }
    if (data.isFieldSet(NXCObjectModificationData.SOURCE_OBJECT)) {
        msg.setFieldInt32(NXCPCodes.VID_SOURCE_OBJECT, (int) data.getSourceObject());
    }
    if (data.isFieldSet(NXCObjectModificationData.ACTIVE_STATUS)) {
        msg.setFieldInt16(NXCPCodes.VID_ACTIVE_STATUS, data.getActiveStatus());
    }
    if (data.isFieldSet(NXCObjectModificationData.INACTIVE_STATUS)) {
        msg.setFieldInt16(NXCPCodes.VID_INACTIVE_STATUS, data.getInactiveStatus());
    }
    if (data.isFieldSet(NXCObjectModificationData.DCI_LIST)) {
        List<ConditionDciInfo> dciList = data.getDciList();
        msg.setFieldInt32(NXCPCodes.VID_NUM_ITEMS, dciList.size());
        long varId = NXCPCodes.VID_DCI_LIST_BASE;
        for (ConditionDciInfo dci : dciList) {
            msg.setFieldInt32(varId++, (int) dci.getDciId());
            msg.setFieldInt32(varId++, (int) dci.getNodeId());
            msg.setFieldInt16(varId++, dci.getFunction());
            msg.setFieldInt16(varId++, dci.getPolls());
            varId += 6;
        }
    }
    if (data.isFieldSet(NXCObjectModificationData.DRILL_DOWN_OBJECT_ID)) {
        msg.setFieldInt32(NXCPCodes.VID_DRILL_DOWN_OBJECT_ID, (int) data.getDrillDownObjectId());
    }
    if (data.isFieldSet(NXCObjectModificationData.SERVICE_TYPE)) {
        msg.setFieldInt16(NXCPCodes.VID_SERVICE_TYPE, data.getServiceType());
    }
    if (data.isFieldSet(NXCObjectModificationData.IP_ADDRESS)) {
        msg.setField(NXCPCodes.VID_IP_ADDRESS, data.getIpAddress());
    }
    if (data.isFieldSet(NXCObjectModificationData.IP_PROTOCOL)) {
        msg.setFieldInt16(NXCPCodes.VID_IP_PROTO, data.getIpProtocol());
    }
    if (data.isFieldSet(NXCObjectModificationData.IP_PORT)) {
        msg.setFieldInt16(NXCPCodes.VID_IP_PORT, data.getIpPort());
    }
    if (data.isFieldSet(NXCObjectModificationData.POLLER_NODE)) {
        msg.setFieldInt32(NXCPCodes.VID_POLLER_NODE_ID, (int) data.getPollerNode());
    }
    if (data.isFieldSet(NXCObjectModificationData.REQUIRED_POLLS)) {
        msg.setFieldInt16(NXCPCodes.VID_REQUIRED_POLLS, data.getRequiredPolls());
    }
    if (data.isFieldSet(NXCObjectModificationData.REQUEST)) {
        msg.setField(NXCPCodes.VID_SERVICE_REQUEST, data.getRequest());
    }
    if (data.isFieldSet(NXCObjectModificationData.RESPONSE)) {
        msg.setField(NXCPCodes.VID_SERVICE_RESPONSE, data.getResponse());
    }
    if (data.isFieldSet(NXCObjectModificationData.OBJECT_FLAGS)) {
        msg.setFieldInt32(NXCPCodes.VID_FLAGS, data.getObjectFlags());
        msg.setFieldInt32(NXCPCodes.VID_FLAGS_MASK, data.getObjectFlagsMask());
    }
    if (data.isFieldSet(NXCObjectModificationData.IFXTABLE_POLICY)) {
        msg.setFieldInt16(NXCPCodes.VID_USE_IFXTABLE, data.getIfXTablePolicy());
    }
    if (data.isFieldSet(NXCObjectModificationData.REPORT_DEFINITION)) {
        msg.setField(NXCPCodes.VID_REPORT_DEFINITION, data.getReportDefinition());
    }
    if (data.isFieldSet(NXCObjectModificationData.CLUSTER_RESOURCES)) {
        msg.setFieldInt32(NXCPCodes.VID_NUM_RESOURCES, data.getResourceList().size());
        long varId = NXCPCodes.VID_RESOURCE_LIST_BASE;
        for (ClusterResource r : data.getResourceList()) {
            msg.setFieldInt32(varId++, (int) r.getId());
            msg.setField(varId++, r.getName());
            msg.setField(varId++, r.getVirtualAddress());
            varId += 7;
        }
    }
    if (data.isFieldSet(NXCObjectModificationData.CLUSTER_NETWORKS)) {
        int count = data.getNetworkList().size();
        msg.setFieldInt32(NXCPCodes.VID_NUM_SYNC_SUBNETS, count);
        long varId = NXCPCodes.VID_SYNC_SUBNETS_BASE;
        for (InetAddressEx n : data.getNetworkList()) {
            msg.setField(varId++, n);
        }
    }
    if (data.isFieldSet(NXCObjectModificationData.PRIMARY_NAME)) {
        msg.setField(NXCPCodes.VID_PRIMARY_NAME, data.getPrimaryName());
    }
    if (data.isFieldSet(NXCObjectModificationData.STATUS_CALCULATION)) {
        msg.setFieldInt16(NXCPCodes.VID_STATUS_CALCULATION_ALG, data.getStatusCalculationMethod());
        msg.setFieldInt16(NXCPCodes.VID_STATUS_PROPAGATION_ALG, data.getStatusPropagationMethod());
        msg.setFieldInt16(NXCPCodes.VID_FIXED_STATUS, data.getFixedPropagatedStatus().getValue());
        msg.setFieldInt16(NXCPCodes.VID_STATUS_SHIFT, data.getStatusShift());
        ObjectStatus[] transformation = data.getStatusTransformation();
        msg.setFieldInt16(NXCPCodes.VID_STATUS_TRANSLATION_1, transformation[0].getValue());
        msg.setFieldInt16(NXCPCodes.VID_STATUS_TRANSLATION_2, transformation[1].getValue());
        msg.setFieldInt16(NXCPCodes.VID_STATUS_TRANSLATION_3, transformation[2].getValue());
        msg.setFieldInt16(NXCPCodes.VID_STATUS_TRANSLATION_4, transformation[3].getValue());
        msg.setFieldInt16(NXCPCodes.VID_STATUS_SINGLE_THRESHOLD, data.getStatusSingleThreshold());
        int[] thresholds = data.getStatusThresholds();
        msg.setFieldInt16(NXCPCodes.VID_STATUS_THRESHOLD_1, thresholds[0]);
        msg.setFieldInt16(NXCPCodes.VID_STATUS_THRESHOLD_2, thresholds[1]);
        msg.setFieldInt16(NXCPCodes.VID_STATUS_THRESHOLD_3, thresholds[2]);
        msg.setFieldInt16(NXCPCodes.VID_STATUS_THRESHOLD_4, thresholds[3]);
    }
    if (data.isFieldSet(NXCObjectModificationData.EXPECTED_STATE)) {
        msg.setFieldInt16(NXCPCodes.VID_EXPECTED_STATE, data.getExpectedState());
    }
    if (data.isFieldSet(NXCObjectModificationData.LINK_COLOR)) {
        msg.setFieldInt32(NXCPCodes.VID_LINK_COLOR, data.getLinkColor());
    }
    if (data.isFieldSet(NXCObjectModificationData.CONNECTION_ROUTING)) {
        msg.setFieldInt16(NXCPCodes.VID_LINK_ROUTING, data.getConnectionRouting());
    }
    if (data.isFieldSet(NXCObjectModificationData.DISCOVERY_RADIUS)) {
        msg.setFieldInt32(NXCPCodes.VID_DISCOVERY_RADIUS, data.getDiscoveryRadius());
    }
    if (data.isFieldSet(NXCObjectModificationData.HEIGHT)) {
        msg.setFieldInt16(NXCPCodes.VID_HEIGHT, data.getHeight());
    }
    if (data.isFieldSet(NXCObjectModificationData.RACK_NUMB_SCHEME)) {
        msg.setField(NXCPCodes.VID_TOP_BOTTOM, data.isRackNumberingTopBottom());
    }
    if (data.isFieldSet(NXCObjectModificationData.PEER_GATEWAY)) {
        msg.setFieldInt32(NXCPCodes.VID_PEER_GATEWAY, (int) data.getPeerGatewayId());
    }
    if (data.isFieldSet(NXCObjectModificationData.VPN_NETWORKS)) {
        long fieldId = NXCPCodes.VID_VPN_NETWORK_BASE;
        msg.setFieldInt32(NXCPCodes.VID_NUM_LOCAL_NETS, data.getLocalNetworks().size());
        for (InetAddressEx a : data.getLocalNetworks()) {
            msg.setField(fieldId++, a);
        }
        msg.setFieldInt32(NXCPCodes.VID_NUM_REMOTE_NETS, data.getRemoteNetworks().size());
        for (InetAddressEx a : data.getRemoteNetworks()) {
            msg.setField(fieldId++, a);
        }
    }
    if (data.isFieldSet(NXCObjectModificationData.POSTAL_ADDRESS)) {
        data.getPostalAddress().fillMessage(msg);
    }
    if (data.isFieldSet(NXCObjectModificationData.AGENT_CACHE_MODE)) {
        msg.setFieldInt16(NXCPCodes.VID_AGENT_CACHE_MODE, data.getAgentCacheMode().getValue());
    }
    if (data.isFieldSet(NXCObjectModificationData.AGENT_COMPRESSION_MODE)) {
        msg.setFieldInt16(NXCPCodes.VID_AGENT_COMPRESSION_MODE, data.getAgentCompressionMode().getValue());
    }
    if (data.isFieldSet(NXCObjectModificationData.MAPOBJ_DISP_MODE)) {
        msg.setFieldInt16(NXCPCodes.VID_DISPLAY_MODE, data.getMapObjectDisplayMode().getValue());
    }
    if (data.isFieldSet(NXCObjectModificationData.RACK_PLACEMENT)) {
        msg.setFieldInt32(NXCPCodes.VID_RACK_ID, (int) data.getRackId());
        msg.setField(NXCPCodes.VID_RACK_IMAGE_FRONT, data.getFrontRackImage());
        msg.setField(NXCPCodes.VID_RACK_IMAGE_REAR, data.getRearRackImage());
        msg.setFieldInt16(NXCPCodes.VID_RACK_POSITION, data.getRackPosition());
        msg.setFieldInt16(NXCPCodes.VID_RACK_HEIGHT, data.getRackHeight());
        msg.setFieldInt16(NXCPCodes.VID_RACK_ORIENTATION, data.getRackOrientation().getValue());
    }
    if (data.isFieldSet(NXCObjectModificationData.DASHBOARD_LIST)) {
        msg.setField(NXCPCodes.VID_DASHBOARDS, data.getDashboards());
    }
    if (data.isFieldSet(NXCObjectModificationData.CHASSIS_ID)) {
        msg.setFieldInt32(NXCPCodes.VID_CHASSIS_ID, (int) data.getChassisId());
    }
    if (data.isFieldSet(NXCObjectModificationData.CONTROLLER_ID)) {
        msg.setFieldInt32(NXCPCodes.VID_CONTROLLER_ID, (int) data.getControllerId());
    }
    if (data.isFieldSet(NXCObjectModificationData.SSH_PROXY)) {
        msg.setFieldInt32(NXCPCodes.VID_SSH_PROXY, (int) data.getSshProxy());
    }
    if (data.isFieldSet(NXCObjectModificationData.SSH_LOGIN)) {
        msg.setField(NXCPCodes.VID_SSH_LOGIN, data.getSshLogin());
    }
    if (data.isFieldSet(NXCObjectModificationData.SSH_PASSWORD)) {
        msg.setField(NXCPCodes.VID_SSH_PASSWORD, data.getSshPassword());
    }
    if (data.isFieldSet(NXCObjectModificationData.ZONE_PROXY)) {
        msg.setFieldInt32(NXCPCodes.VID_ZONE_PROXY, (int) data.getZoneProxy());
    }
    if (data.isFieldSet(NXCObjectModificationData.SEED_OBJECTS)) {
        msg.setField(NXCPCodes.VID_SEED_OBJECTS, data.getSeedObjectIds());
    }
    if (data.isFieldSet(NXCObjectModificationData.MAC_ADDRESS)) {
        msg.setField(NXCPCodes.VID_MAC_ADDR, data.getMacAddress());
    }
    if (data.isFieldSet(NXCObjectModificationData.DEVICE_CLASS)) {
        msg.setFieldInt32(NXCPCodes.VID_DEVICE_CLASS, data.getDeviceClass());
    }
    if (data.isFieldSet(NXCObjectModificationData.VENDOR)) {
        msg.setField(NXCPCodes.VID_VENDOR, data.getVendor());
    }
    if (data.isFieldSet(NXCObjectModificationData.SERIAL_NUMBER)) {
        msg.setField(NXCPCodes.VID_SERIAL_NUMBER, data.getSerialNumber());
    }
    if (data.isFieldSet(NXCObjectModificationData.DEVICE_ADDRESS)) {
        msg.setField(NXCPCodes.VID_DEVICE_ADDRESS, data.getDeviceAddress());
    }
    if (data.isFieldSet(NXCObjectModificationData.META_TYPE)) {
        msg.setField(NXCPCodes.VID_META_TYPE, data.getMetaType());
    }
    if (data.isFieldSet(NXCObjectModificationData.SENSOR_PROXY)) {
        msg.setFieldInt32(NXCPCodes.VID_SENSOR_PROXY, (int) data.getSensorProxy());
    }
    if (data.isFieldSet(NXCObjectModificationData.XML_CONFIG)) {
        msg.setField(NXCPCodes.VID_XML_CONFIG, data.getXmlConfig());
    }
    if (data.isFieldSet(NXCObjectModificationData.SNMP_PORT_LIST)) {
        msg.setFieldInt32(NXCPCodes.VID_ZONE_SNMP_PORT_COUNT, data.getSnmpPorts().size());
        for (int i = 0; i < data.getSnmpPorts().size(); i++) {
            msg.setField(NXCPCodes.VID_ZONE_SNMP_PORT_LIST_BASE + i, data.getSnmpPorts().get(i));
        }
    }
    if (data.isFieldSet(NXCObjectModificationData.PASSIVE_ELEMENTS)) {
        msg.setField(NXCPCodes.VID_PASSIVE_ELEMENTS, data.getPassiveElements());
    }
    if (data.isFieldSet(NXCObjectModificationData.RESPONSIBLE_USERS)) {
        Long[] users = data.getResponsibleUsers().toArray(new Long[data.getResponsibleUsers().size()]);
        msg.setField(NXCPCodes.VID_RESPONSIBLE_USERS, users);
    }
    modifyCustomObject(data, userData, msg);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ConditionDciInfo(org.netxms.client.datacollection.ConditionDciInfo) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint) DashboardElement(org.netxms.client.dashboards.DashboardElement) ClusterResource(org.netxms.client.objects.ClusterResource) ObjectStatus(org.netxms.client.constants.ObjectStatus) InetAddressEx(org.netxms.base.InetAddressEx) NetworkMapElement(org.netxms.client.maps.elements.NetworkMapElement) AtomicLong(java.util.concurrent.atomic.AtomicLong) GeoLocation(org.netxms.base.GeoLocation) NetworkMapLink(org.netxms.client.maps.NetworkMapLink)

Example 2 with ClusterResource

use of org.netxms.client.objects.ClusterResource in project netxms by netxms.

the class ClusterResourceListComparator method compare.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    final ClusterResource r1 = (ClusterResource) e1;
    final ClusterResource r2 = (ClusterResource) e2;
    // $NON-NLS-1$
    final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
    int result;
    switch(column) {
        case ClusterTab.COLUMN_NAME:
            result = r1.getName().compareToIgnoreCase(r2.getName());
            break;
        case ClusterTab.COLUMN_VIP:
            byte[] addr1 = r1.getVirtualAddress().getAddress();
            byte[] addr2 = r2.getVirtualAddress().getAddress();
            result = 0;
            for (int i = 0; (i < addr1.length) && (result == 0); i++) {
                result = addr1[i] - addr2[i];
            }
            break;
        case ClusterTab.COLUMN_OWNER:
            result = getOwnerName(r1).compareToIgnoreCase(getOwnerName(r2));
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) ClusterResource(org.netxms.client.objects.ClusterResource)

Example 3 with ClusterResource

use of org.netxms.client.objects.ClusterResource in project netxms by netxms.

the class ClusterResources method editResource.

/**
 * Edit currently selected resource
 */
private void editResource() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    ClusterResource r = (ClusterResource) selection.getFirstElement();
    EditClusterResourceDialog dlg = new EditClusterResourceDialog(getShell(), r);
    if (dlg.open() == Window.OK) {
        r.setName(dlg.getName());
        r.setVirtualAddress(dlg.getAddress());
        viewer.update(r, null);
        isModified = true;
    }
}
Also used : EditClusterResourceDialog(org.netxms.ui.eclipse.objectmanager.dialogs.EditClusterResourceDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ClusterResource(org.netxms.client.objects.ClusterResource)

Example 4 with ClusterResource

use of org.netxms.client.objects.ClusterResource in project netxms by netxms.

the class ClusterResources method addResource.

/**
 * Add new cluster resource
 */
private void addResource() {
    EditClusterResourceDialog dlg = new EditClusterResourceDialog(getShell(), null);
    if (dlg.open() == Window.OK) {
        // Find free resource ID
        long id = 1;
        for (ClusterResource r : resources) {
            if (r.getId() >= id)
                id = r.getId() + 1;
        }
        ClusterResource r = new ClusterResource(id, dlg.getName(), dlg.getAddress());
        resources.add(r);
        viewer.setInput(resources.toArray());
        viewer.setSelection(new StructuredSelection(r));
        isModified = true;
    }
}
Also used : EditClusterResourceDialog(org.netxms.ui.eclipse.objectmanager.dialogs.EditClusterResourceDialog) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ClusterResource(org.netxms.client.objects.ClusterResource)

Example 5 with ClusterResource

use of org.netxms.client.objects.ClusterResource in project netxms by netxms.

the class ClusterTab method addOwnedResources.

/**
 * @param id
 * @param objectId
 * @param resources
 */
private void addOwnedResources(NetworkMapPage page, long rootElementId, long objectId, List<ClusterResource> resources) {
    long elementId = rootElementId * 100000;
    for (ClusterResource r : resources) {
        if (r.getCurrentOwner() == objectId) {
            page.addElement(new NetworkMapResource(elementId, NetworkMapResource.CLUSTER_RESOURCE, r));
            page.addLink(new NetworkMapLink(0, rootElementId, elementId));
            elementId++;
        }
    }
}
Also used : NetworkMapResource(org.netxms.client.maps.elements.NetworkMapResource) NetworkMapLink(org.netxms.client.maps.NetworkMapLink) ClusterResource(org.netxms.client.objects.ClusterResource)

Aggregations

ClusterResource (org.netxms.client.objects.ClusterResource)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Button (org.eclipse.swt.widgets.Button)3 Composite (org.eclipse.swt.widgets.Composite)3 RowLayout (org.eclipse.swt.layout.RowLayout)2 Group (org.eclipse.swt.widgets.Group)2 NXCSession (org.netxms.client.NXCSession)2 NetworkMapLink (org.netxms.client.maps.NetworkMapLink)2 AbstractNode (org.netxms.client.objects.AbstractNode)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 Cluster (org.netxms.client.objects.Cluster)2 EditClusterResourceDialog (org.netxms.ui.eclipse.objectmanager.dialogs.EditClusterResourceDialog)2 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1