Search in sources :

Example 11 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode in project opennms by OpenNMS.

the class VmwareImporter method createRequisitionNode.

/**
 * Creates a requisition node for the given managed entity and type.
 *
 * @param ipAddresses   the set of Ip addresses
 * @param managedEntity the managed entity
 * @return the generated requisition node
 */
private RequisitionNode createRequisitionNode(Set<String> ipAddresses, ManagedEntity managedEntity, int apiVersion, VmwareViJavaAccess vmwareViJavaAccess) {
    RequisitionNode requisitionNode = new RequisitionNode();
    // Setting the node label
    requisitionNode.setNodeLabel(managedEntity.getName());
    // Foreign Id consisting of managed entity Id
    requisitionNode.setForeignId(managedEntity.getMOR().getVal());
    /*
         * Original version:
         *
         * Foreign Id consisting of VMware management server's hostname and managed entity id
         *
         * requisitionNode.setForeignId(m_hostname + "/" + managedEntity.getMOR().getVal());
         */
    logger.debug("Start primary interface search for managed entity '{}' (ID: {})", managedEntity.getName(), managedEntity.getMOR().getVal());
    if (managedEntity instanceof VirtualMachine) {
        boolean firstInterface = true;
        // add all given interfaces
        for (String ipAddress : ipAddresses) {
            try {
                if ((request.isPersistIPv4() && InetAddressUtils.isIPv4Address(ipAddress)) || (request.isPersistIPv6() && InetAddressUtils.isIPv6Address(ipAddress))) {
                    InetAddress inetAddress = InetAddress.getByName(ipAddress);
                    if (!inetAddress.isLoopbackAddress()) {
                        RequisitionInterface requisitionInterface = new RequisitionInterface();
                        requisitionInterface.setIpAddr(ipAddress);
                        // the first one will be primary
                        if (firstInterface) {
                            requisitionInterface.setSnmpPrimary(PrimaryType.PRIMARY);
                            for (String service : request.getVirtualMachineServices()) {
                                requisitionInterface.insertMonitoredService(new RequisitionMonitoredService(service.trim()));
                            }
                            firstInterface = false;
                        } else {
                            requisitionInterface.setSnmpPrimary(PrimaryType.SECONDARY);
                        }
                        requisitionInterface.setManaged(Boolean.TRUE);
                        requisitionInterface.setStatus(Integer.valueOf(1));
                        requisitionNode.putInterface(requisitionInterface);
                    }
                }
            } catch (UnknownHostException unknownHostException) {
                logger.warn("Invalid IP address '{}'", unknownHostException.getMessage());
            }
        }
    } else {
        if (managedEntity instanceof HostSystem) {
            boolean reachableInterfaceFound = false, firstInterface = true;
            List<RequisitionInterface> requisitionInterfaceList = new ArrayList<>();
            RequisitionInterface primaryInterfaceCandidate = null;
            // add all given interfaces
            for (String ipAddress : ipAddresses) {
                try {
                    if ((request.isPersistIPv4() && InetAddressUtils.isIPv4Address(ipAddress)) || (request.isPersistIPv6() && InetAddressUtils.isIPv6Address(ipAddress))) {
                        InetAddress inetAddress = InetAddress.getByName(ipAddress);
                        if (!inetAddress.isLoopbackAddress()) {
                            RequisitionInterface requisitionInterface = new RequisitionInterface();
                            requisitionInterface.setIpAddr(ipAddress);
                            if (firstInterface) {
                                primaryInterfaceCandidate = requisitionInterface;
                                firstInterface = false;
                            }
                            if (!reachableInterfaceFound && reachableCimService(vmwareViJavaAccess, (HostSystem) managedEntity, ipAddress)) {
                                primaryInterfaceCandidate = requisitionInterface;
                                reachableInterfaceFound = true;
                            }
                            requisitionInterface.setManaged(Boolean.TRUE);
                            requisitionInterface.setStatus(Integer.valueOf(1));
                            requisitionInterface.setSnmpPrimary(PrimaryType.SECONDARY);
                            requisitionInterfaceList.add(requisitionInterface);
                        }
                    }
                } catch (UnknownHostException unknownHostException) {
                    logger.warn("Invalid IP address '{}'", unknownHostException.getMessage());
                }
            }
            if (primaryInterfaceCandidate != null) {
                if (reachableInterfaceFound) {
                    logger.warn("Found reachable primary interface '{}'", primaryInterfaceCandidate.getIpAddr());
                } else {
                    logger.warn("Only non-reachable interfaces found, using first one for primary interface '{}'", primaryInterfaceCandidate.getIpAddr());
                }
                primaryInterfaceCandidate.setSnmpPrimary(PrimaryType.PRIMARY);
                for (String service : request.getHostSystemServices()) {
                    if (reachableInterfaceFound || !"VMwareCim-HostSystem".equals(service)) {
                        primaryInterfaceCandidate.insertMonitoredService(new RequisitionMonitoredService(service.trim()));
                    }
                }
            } else {
                logger.warn("No primary interface found");
            }
            for (RequisitionInterface requisitionInterface : requisitionInterfaceList) {
                requisitionNode.putInterface(requisitionInterface);
            }
        } else {
            logger.error("Undefined type of managedEntity '{}'", managedEntity.getMOR().getType());
            return null;
        }
    }
    /*
         * For now we use displaycategory, notifycategory and pollercategory for storing
         * the vcenter Ip address, the username and the password
         */
    String powerState = "unknown";
    final StringBuilder vmwareTopologyInfo = new StringBuilder();
    // putting parents to topology information
    ManagedEntity parentEntity = managedEntity.getParent();
    do {
        if (vmwareTopologyInfo.length() > 0) {
            vmwareTopologyInfo.append(", ");
        }
        try {
            if (parentEntity != null && parentEntity.getMOR() != null) {
                vmwareTopologyInfo.append(parentEntity.getMOR().getVal() + "/" + URLEncoder.encode(parentEntity.getName(), StandardCharsets.UTF_8.name()));
            } else {
                logger.warn("Can't add topologyInformation because either the parentEntity or the MOR is null for " + managedEntity.getName());
            }
        } catch (UnsupportedEncodingException e) {
            logger.warn("Unsupported encoding '{}'", e.getMessage());
        }
        parentEntity = parentEntity == null ? null : parentEntity.getParent();
    } while (parentEntity != null);
    if (managedEntity instanceof HostSystem) {
        HostSystem hostSystem = (HostSystem) managedEntity;
        HostRuntimeInfo hostRuntimeInfo = hostSystem.getRuntime();
        if (hostRuntimeInfo == null) {
            logger.debug("hostRuntimeInfo=null");
        } else {
            HostSystemPowerState hostSystemPowerState = hostRuntimeInfo.getPowerState();
            if (hostSystemPowerState == null) {
                logger.debug("hostSystemPowerState=null");
            } else {
                powerState = hostSystemPowerState.toString();
            }
        }
        try {
            if (request.isTopologyDatastores()) {
                for (Datastore datastore : hostSystem.getDatastores()) {
                    if (vmwareTopologyInfo.length() > 0) {
                        vmwareTopologyInfo.append(", ");
                    }
                    try {
                        vmwareTopologyInfo.append(datastore.getMOR().getVal() + "/" + URLEncoder.encode(datastore.getSummary().getName(), StandardCharsets.UTF_8.name()));
                    } catch (UnsupportedEncodingException e) {
                        logger.warn("Unsupported encoding '{}'", e.getMessage());
                    }
                }
            }
        } catch (RemoteException e) {
            logger.warn("Cannot retrieve datastores for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
        }
        try {
            if (request.isTopologyNetworks()) {
                for (Network network : hostSystem.getNetworks()) {
                    if (vmwareTopologyInfo.length() > 0) {
                        vmwareTopologyInfo.append(", ");
                    }
                    try {
                        if (network instanceof DistributedVirtualPortgroup ? request.isTopologyPortGroups() : true) {
                            vmwareTopologyInfo.append(network.getMOR().getVal() + "/" + URLEncoder.encode(network.getSummary().getName(), StandardCharsets.UTF_8.name()));
                        }
                    } catch (UnsupportedEncodingException e) {
                        logger.warn("Unsupported encoding '{}'", e.getMessage());
                    }
                }
            }
        } catch (RemoteException e) {
            logger.warn("Cannot retrieve networks for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
        }
    } else {
        if (managedEntity instanceof VirtualMachine) {
            VirtualMachine virtualMachine = (VirtualMachine) managedEntity;
            VirtualMachineRuntimeInfo virtualMachineRuntimeInfo = virtualMachine.getRuntime();
            if (virtualMachineRuntimeInfo == null) {
                logger.debug("virtualMachineRuntimeInfo=null");
            } else {
                VirtualMachinePowerState virtualMachinePowerState = virtualMachineRuntimeInfo.getPowerState();
                if (virtualMachinePowerState == null) {
                    logger.debug("virtualMachinePowerState=null");
                } else {
                    powerState = virtualMachinePowerState.toString();
                }
            }
            try {
                if (request.isTopologyDatastores()) {
                    for (Datastore datastore : virtualMachine.getDatastores()) {
                        if (vmwareTopologyInfo.length() > 0) {
                            vmwareTopologyInfo.append(", ");
                        }
                        try {
                            vmwareTopologyInfo.append(datastore.getMOR().getVal() + "/" + URLEncoder.encode(datastore.getSummary().getName(), StandardCharsets.UTF_8.name()));
                        } catch (UnsupportedEncodingException e) {
                            logger.warn("Unsupported encoding '{}'", e.getMessage());
                        }
                    }
                }
            } catch (RemoteException e) {
                logger.warn("Cannot retrieve datastores for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
            }
            try {
                if (request.isTopologyNetworks()) {
                    for (Network network : virtualMachine.getNetworks()) {
                        if (vmwareTopologyInfo.length() > 0) {
                            vmwareTopologyInfo.append(", ");
                        }
                        try {
                            if (network instanceof DistributedVirtualPortgroup ? request.isTopologyPortGroups() : true) {
                                vmwareTopologyInfo.append(network.getMOR().getVal() + "/" + URLEncoder.encode(network.getSummary().getName(), StandardCharsets.UTF_8.name()));
                            }
                        } catch (UnsupportedEncodingException e) {
                            logger.warn("Unsupported encoding '{}'", e.getMessage());
                        }
                    }
                }
            } catch (RemoteException e) {
                logger.warn("Cannot retrieve networks for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
            }
            if (vmwareTopologyInfo.length() > 0) {
                vmwareTopologyInfo.append(", ");
            }
            try {
                if (m_hostSystemMap.get(virtualMachine.getRuntime().getHost().getVal()) != null) {
                    vmwareTopologyInfo.append(virtualMachine.getRuntime().getHost().getVal() + "/" + URLEncoder.encode(m_hostSystemMap.get(virtualMachine.getRuntime().getHost().getVal()), StandardCharsets.UTF_8.name()));
                } else {
                    logger.warn("Problem building topology information for virtual machine '{}' with power state '{}' running on host system '{}'", virtualMachine.getMOR().getVal(), powerState, virtualMachine.getRuntime().getHost().getVal());
                }
            } catch (UnsupportedEncodingException e) {
                logger.warn("Unsupported encoding '{}'", e.getMessage());
            }
        } else {
            logger.error("Undefined type of managedEntity '{}'", managedEntity.getMOR().getType());
            return null;
        }
    }
    RequisitionAsset requisitionAssetHostname = new RequisitionAsset("vmwareManagementServer", request.getHostname());
    requisitionNode.putAsset(requisitionAssetHostname);
    RequisitionAsset requisitionAssetType = new RequisitionAsset("vmwareManagedEntityType", (managedEntity instanceof HostSystem ? "HostSystem" : "VirtualMachine"));
    requisitionNode.putAsset(requisitionAssetType);
    RequisitionAsset requisitionAssetId = new RequisitionAsset("vmwareManagedObjectId", managedEntity.getMOR().getVal());
    requisitionNode.putAsset(requisitionAssetId);
    RequisitionAsset requisitionAssetTopologyInfo = new RequisitionAsset("vmwareTopologyInfo", vmwareTopologyInfo.toString());
    requisitionNode.putAsset(requisitionAssetTopologyInfo);
    RequisitionAsset requisitionAssetState = new RequisitionAsset("vmwareState", powerState);
    requisitionNode.putAsset(requisitionAssetState);
    requisitionNode.putCategory(new RequisitionCategory("VMware" + apiVersion));
    return requisitionNode;
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) HostRuntimeInfo(com.vmware.vim25.HostRuntimeInfo) UnknownHostException(java.net.UnknownHostException) VirtualMachineRuntimeInfo(com.vmware.vim25.VirtualMachineRuntimeInfo) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService) HostSystemPowerState(com.vmware.vim25.HostSystemPowerState) RequisitionAsset(org.opennms.netmgt.provision.persist.requisition.RequisitionAsset) DistributedVirtualPortgroup(com.vmware.vim25.mo.DistributedVirtualPortgroup) VirtualMachinePowerState(com.vmware.vim25.VirtualMachinePowerState) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) Datastore(com.vmware.vim25.mo.Datastore) Network(com.vmware.vim25.mo.Network) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) HostSystem(com.vmware.vim25.mo.HostSystem) RemoteException(java.rmi.RemoteException) InetAddress(java.net.InetAddress) VirtualMachine(com.vmware.vim25.mo.VirtualMachine)

Example 12 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode in project opennms by OpenNMS.

the class VmwareImporter method iterateHostSystems.

/**
 * Iterates through the host systems and adds them to the requisition object.
 *
 * @param vmwareViJavaAccess the access/connection to use
 */
private void iterateHostSystems(VmwareViJavaAccess vmwareViJavaAccess, int apiVersion) {
    ManagedEntity[] managedEntities = null;
    logger.debug("Starting to iterate Host Systems on VMware host {} ...", request.getHostname());
    try {
        managedEntities = vmwareViJavaAccess.searchManagedEntities("HostSystem");
    } catch (RemoteException e) {
        logger.error("Error iterating Host Systems on VMware host {}", request.getHostname());
        logger.error("Exception thrown while iterating for Host Systems: ", e);
    }
    if (managedEntities != null) {
        Arrays.stream(managedEntities).map(m -> (HostSystem) m).forEach(hostSystem -> {
            synchronized (m_hostSystemMap) {
                m_hostSystemMap.put(hostSystem.getMOR().getVal(), hostSystem.getName());
            }
        });
        final ExecutorService executor = Executors.newFixedThreadPool(Math.min(managedEntities.length, 10));
        final List<CompletableFuture<Optional<RequisitionNode>>> completableFutures = Arrays.stream(managedEntities).map(managedEntity -> (HostSystem) managedEntity).filter(hostSystem -> checkHostPowerState(hostSystem)).filter(hostSystem -> checkForAttribute(hostSystem)).map(hostSystem -> CompletableFuture.supplyAsync(() -> {
            logger.debug("Adding Host System '{}' (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal());
            TreeSet<String> ipAddresses = vmwareViJavaAccess.getHostSystemIpAddresses(hostSystem);
            logger.debug("Found {} IP addresses for Host System '{}' (ID: {}): {}", ipAddresses.size(), hostSystem.getName(), hostSystem.getMOR().getVal(), ipAddresses);
            RequisitionNode node = createRequisitionNode(ipAddresses, hostSystem, apiVersion, vmwareViJavaAccess);
            try {
                node.putAsset(new RequisitionAsset("cpu", hostSystem.getHardware().getCpuInfo().getNumCpuCores() + " cores"));
            } catch (Exception e) {
                logger.debug("Can't find CPU information for '{}' (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal());
            }
            try {
                node.putAsset(new RequisitionAsset("ram", Math.round(hostSystem.getHardware().getMemorySize() / 1000000f) + " MB"));
            } catch (Exception e) {
                logger.debug("Can't find Memory information for '{}' (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal());
            }
            return request.isPersistHosts() ? Optional.of(node) : Optional.<RequisitionNode>empty();
        }, executor)).collect(Collectors.toList());
        completableFutures.stream().map(CompletableFuture::join).filter(Optional::isPresent).forEach(m -> {
            synchronized (m_requisition) {
                m_requisition.insertNode(m.get());
            }
        });
        executor.shutdown();
    }
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) HostSystem(com.vmware.vim25.mo.HostSystem) LoggerFactory(org.slf4j.LoggerFactory) InetAddress(java.net.InetAddress) CIMException(org.sblim.wbem.cim.CIMException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Map(java.util.Map) HostSystemPowerState(com.vmware.vim25.HostSystemPowerState) DistributedVirtualPortgroup(com.vmware.vim25.mo.DistributedVirtualPortgroup) CIMObject(org.sblim.wbem.cim.CIMObject) HostRuntimeInfo(com.vmware.vim25.HostRuntimeInfo) VmwareViJavaAccess(org.opennms.protocols.vmware.VmwareViJavaAccess) VirtualMachinePowerState(com.vmware.vim25.VirtualMachinePowerState) Set(java.util.Set) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) RemoteException(java.rmi.RemoteException) Objects(java.util.Objects) List(java.util.List) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue) VirtualMachine(com.vmware.vim25.mo.VirtualMachine) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) Optional(java.util.Optional) Network(com.vmware.vim25.mo.Network) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequisitionAsset(org.opennms.netmgt.provision.persist.requisition.RequisitionAsset) Datastore(com.vmware.vim25.mo.Datastore) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ManagedEntity(com.vmware.vim25.mo.ManagedEntity) VirtualMachineRuntimeInfo(com.vmware.vim25.VirtualMachineRuntimeInfo) PrimaryType(org.opennms.netmgt.model.PrimaryType) ConnectException(java.net.ConnectException) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CustomFieldDef(com.vmware.vim25.CustomFieldDef) URLEncoder(java.net.URLEncoder) TreeMap(java.util.TreeMap) CustomFieldValue(com.vmware.vim25.CustomFieldValue) InetAddressUtils(org.apache.http.conn.util.InetAddressUtils) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionAsset(org.opennms.netmgt.provision.persist.requisition.RequisitionAsset) CIMException(org.sblim.wbem.cim.CIMException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CompletableFuture(java.util.concurrent.CompletableFuture) HostSystem(com.vmware.vim25.mo.HostSystem) ExecutorService(java.util.concurrent.ExecutorService) RemoteException(java.rmi.RemoteException)

Example 13 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode in project opennms by OpenNMS.

the class VmwareImporter method iterateVirtualMachines.

/**
 * Iterates through the virtual machines and adds them to the requisition object.
 *
 * @param vmwareViJavaAccess the access/connection to use
 */
private void iterateVirtualMachines(VmwareViJavaAccess vmwareViJavaAccess, int apiVersion) {
    ManagedEntity[] managedEntities = null;
    logger.debug("Starting to iterate Virtual Machines on VMware host {} ...", request.getHostname());
    try {
        managedEntities = vmwareViJavaAccess.searchManagedEntities("VirtualMachine");
    } catch (RemoteException e) {
        logger.error("Error iterating Virtual Machines on VMware host {}", request.getHostname());
        logger.error("Exception thrown while iterating for Virtual Machines: ", e);
    }
    if (managedEntities != null) {
        final ExecutorService executor = Executors.newFixedThreadPool(Math.min(managedEntities.length, 10));
        final List<CompletableFuture<Optional<RequisitionNode>>> completableFutures = Arrays.stream(managedEntities).map(managedEntity -> (VirtualMachine) managedEntity).filter(virtualMachine -> checkVMPowerState(virtualMachine)).filter(virtualMachine -> checkForAttribute(virtualMachine)).map(virtualMachine -> CompletableFuture.supplyAsync(() -> {
            logger.debug("Adding Virtual Machine '{}' (ID: {})", virtualMachine.getName(), virtualMachine.getMOR().getVal());
            TreeSet<String> ipAddresses = vmwareViJavaAccess.getVirtualMachineIpAddresses(virtualMachine);
            logger.debug("Found {} IP addresses for Virtual Machine '{}' (ID: {}): {}", ipAddresses.size(), virtualMachine.getName(), virtualMachine.getMOR().getVal(), ipAddresses);
            RequisitionNode node = createRequisitionNode(ipAddresses, virtualMachine, apiVersion, vmwareViJavaAccess);
            if (virtualMachine.getGuest().getGuestFullName() != null) {
                node.putAsset(new RequisitionAsset("operatingSystem", virtualMachine.getGuest().getGuestFullName()));
            }
            try {
                node.putAsset(new RequisitionAsset("cpu", virtualMachine.getConfig().getHardware().getNumCPU() + " vCPU"));
            } catch (Exception e) {
                logger.debug("Can't find CPU information for {} (ID: {})", virtualMachine.getName(), virtualMachine.getMOR().getVal());
            }
            try {
                node.putAsset(new RequisitionAsset("ram", virtualMachine.getConfig().getHardware().getMemoryMB() + " MB"));
            } catch (Exception e) {
                logger.debug("Can't find Memory information for {} (ID: {})", virtualMachine.getName(), virtualMachine.getMOR().getVal());
            }
            return request.isPersistVMs() ? Optional.of(node) : Optional.<RequisitionNode>empty();
        }, executor)).collect(Collectors.toList());
        completableFutures.stream().map(CompletableFuture::join).filter(Optional::isPresent).forEach(m -> {
            synchronized (m_requisition) {
                m_requisition.insertNode(m.get());
            }
        });
        executor.shutdown();
    }
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) HostSystem(com.vmware.vim25.mo.HostSystem) LoggerFactory(org.slf4j.LoggerFactory) InetAddress(java.net.InetAddress) CIMException(org.sblim.wbem.cim.CIMException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Map(java.util.Map) HostSystemPowerState(com.vmware.vim25.HostSystemPowerState) DistributedVirtualPortgroup(com.vmware.vim25.mo.DistributedVirtualPortgroup) CIMObject(org.sblim.wbem.cim.CIMObject) HostRuntimeInfo(com.vmware.vim25.HostRuntimeInfo) VmwareViJavaAccess(org.opennms.protocols.vmware.VmwareViJavaAccess) VirtualMachinePowerState(com.vmware.vim25.VirtualMachinePowerState) Set(java.util.Set) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) RemoteException(java.rmi.RemoteException) Objects(java.util.Objects) List(java.util.List) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue) VirtualMachine(com.vmware.vim25.mo.VirtualMachine) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) Optional(java.util.Optional) Network(com.vmware.vim25.mo.Network) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequisitionAsset(org.opennms.netmgt.provision.persist.requisition.RequisitionAsset) Datastore(com.vmware.vim25.mo.Datastore) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ManagedEntity(com.vmware.vim25.mo.ManagedEntity) VirtualMachineRuntimeInfo(com.vmware.vim25.VirtualMachineRuntimeInfo) PrimaryType(org.opennms.netmgt.model.PrimaryType) ConnectException(java.net.ConnectException) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CustomFieldDef(com.vmware.vim25.CustomFieldDef) URLEncoder(java.net.URLEncoder) TreeMap(java.util.TreeMap) CustomFieldValue(com.vmware.vim25.CustomFieldValue) InetAddressUtils(org.apache.http.conn.util.InetAddressUtils) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutorService(java.util.concurrent.ExecutorService) RemoteException(java.rmi.RemoteException) RequisitionAsset(org.opennms.netmgt.provision.persist.requisition.RequisitionAsset) CIMException(org.sblim.wbem.cim.CIMException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 14 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode in project opennms by OpenNMS.

the class ProvisionServiceIT method dwLoadRequisition.

/**
 * This test should be set to Ignore until a DNS server can be integrated into unit tests
 *
 * @throws MalformedURLException
 */
@Test
@Ignore
public void dwLoadRequisition() throws MalformedURLException {
    String nodeLabel = "localhost";
    int nhash = nodeLabel.hashCode();
    int chash = "localhost".hashCode();
    Assert.assertEquals(nhash, chash);
    Resource resource = new UrlResource("dns://localhost/localhost");
    Requisition r = m_provService.loadRequisition(resource);
    Assert.assertNotNull(r);
    Assert.assertEquals(1, r.getNodeCount());
    String foreignId = String.valueOf("localhost".hashCode());
    RequisitionNode node = r.getNode(foreignId);
    Assert.assertNotNull(node);
    RequisitionInterface inf = node.getInterface("127.0.0.1");
    Assert.assertNotNull(inf);
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode in project opennms by OpenNMS.

the class CsvRequisitionParser method createOrUpdateRequistion.

private static void createOrUpdateRequistion(RequisitionData rd) throws UnknownHostException {
    Requisition r = null;
    RequisitionNode rn = new RequisitionNode();
    String foreignSource = rd.getForeignSource();
    r = m_fsr.getRequisition(foreignSource);
    if (r == null) {
        r = new Requisition(foreignSource);
    }
    System.err.println("Creating/Updating requistion: " + foreignSource);
    r.updateDateStamp();
    RequisitionMonitoredServiceCollection services = new RequisitionMonitoredServiceCollection();
    for (String svc : m_serviceList) {
        services.add(new RequisitionMonitoredService(svc));
    }
    RequisitionInterface iface = new RequisitionInterface();
    iface.setDescr("mgmt-if");
    iface.setIpAddr(rd.getPrimaryIp());
    iface.setManaged(true);
    iface.setSnmpPrimary(PrimaryType.PRIMARY);
    iface.setStatus(Integer.valueOf(1));
    iface.setMonitoredServices(services.getObjects());
    RequisitionInterfaceCollection ric = new RequisitionInterfaceCollection();
    ric.add(iface);
    // add categories requisition level categories
    RequisitionCategoryCollection rcc = new RequisitionCategoryCollection();
    if (m_categoryList != null && m_categoryList.size() > 0) {
        for (String cat : m_categoryList) {
            rcc.add(new RequisitionCategory(cat));
        }
    }
    // add categories already on the node to the requisition
    if (rd.getCategories() != null) {
        for (String cat : rd.getCategories()) {
            rcc.add(new RequisitionCategory(cat));
        }
    }
    rn.setBuilding(foreignSource);
    if (rcc.size() >= 1) {
        rn.setCategories(rcc.getObjects());
    }
    rn.setForeignId(rd.getForeignId());
    rn.setInterfaces(ric.getObjects());
    String nodeLabel = rd.getNodeLabel();
    if (m_resolveIps) {
        InetAddress addr = InetAddress.getByName(rd.getPrimaryIp());
        nodeLabel = addr.getCanonicalHostName();
    }
    rn.setNodeLabel(nodeLabel);
    // r.insertNode(rn);
    r.putNode(rn);
    m_fsr.save(r);
}
Also used : RequisitionCategoryCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionCategoryCollection) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionMonitoredServiceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredServiceCollection) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) RequisitionInterfaceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection) InetAddress(java.net.InetAddress) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)

Aggregations

RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)20 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)15 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)14 RequisitionMonitoredService (org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)7 Test (org.junit.Test)6 RequisitionCategory (org.opennms.netmgt.provision.persist.requisition.RequisitionCategory)6 ArrayList (java.util.ArrayList)5 InetAddress (java.net.InetAddress)4 RequisitionAsset (org.opennms.netmgt.provision.persist.requisition.RequisitionAsset)4 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)3 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)3 VirtualMachinePowerState (com.vmware.vim25.VirtualMachinePowerState)3 VirtualMachineRuntimeInfo (com.vmware.vim25.VirtualMachineRuntimeInfo)3 Datastore (com.vmware.vim25.mo.Datastore)3 DistributedVirtualPortgroup (com.vmware.vim25.mo.DistributedVirtualPortgroup)3 HostSystem (com.vmware.vim25.mo.HostSystem)3 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)3 Network (com.vmware.vim25.mo.Network)3 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3