use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.
the class VmwareRequisitionProvider method getRequest.
@Override
public VmwareImportRequest getRequest(Map<String, String> parameters) {
// Generate a request using the parameter map
final VmwareImportRequest request = new VmwareImportRequest(parameters);
if (StringUtils.isBlank(request.getUsername()) || StringUtils.isBlank(request.getPassword())) {
// No credentials were specified in the parameter map, attempt to look these up
final Map<String, VmwareServer> serverMap = vmwareConfigDao.getServerMap();
final VmwareServer vmwareServer = serverMap.get(request.getHostname());
if (vmwareServer != null) {
// We found a corresponding entry - copy the credentials to the request
request.setUsername(vmwareServer.getUsername());
request.setPassword(vmwareServer.getPassword());
}
}
// Lookup the existing requisition, and store it in the request
final Requisition existingRequisition = getExistingRequisition(request.getForeignSource());
request.setExistingRequisition(existingRequisition);
return request;
}
use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.
the class VmwareImporter method getRequisition.
public Requisition getRequisition() {
logger.debug("Getting existing requisition (if any) for VMware management server {}", request.getHostname());
Requisition curReq = request.getExistingRequisition();
logger.debug("Building new requisition for VMware management server {}", request.getHostname());
Requisition newReq = buildVMwareRequisition();
logger.debug("Finished building new requisition for VMware management server {}", request.getHostname());
if (curReq == null) {
if (newReq == null) {
// FIXME Is this correct ? This is the old behavior
newReq = new Requisition(request.getForeignSource());
}
} else {
if (newReq == null) {
// If there is a requisition and the vCenter is not responding for some reason, it is better to use the old requisition,
// instead of returning an empty one, which can cause the lost of all the nodes from the DB.
newReq = curReq;
} else {
// The VMWare related assets and categories will be preserved.
for (RequisitionNode newNode : newReq.getNodes()) {
for (RequisitionNode curNode : curReq.getNodes()) {
if (newNode.getForeignId().equals(curNode.getForeignId())) {
// Add existing custom assets
for (RequisitionAsset asset : curNode.getAssets()) {
if (!asset.getName().startsWith("vmware")) {
newNode.putAsset(asset);
}
}
// Add existing custom categories
for (RequisitionCategory cat : curNode.getCategories()) {
if (!cat.getName().startsWith("VMWare")) {
newNode.putCategory(cat);
}
}
/*
* For each interface on the new requisition,
* - Retrieve the list of custom services from the corresponding interface on the existing requisition,
* matching the interface by the IP address
* - If the list of services is not empty, add them to the new interface
*/
for (RequisitionInterface intf : curNode.getInterfaces()) {
List<RequisitionMonitoredService> services = getManualyConfiguredServices(intf);
if (!services.isEmpty()) {
RequisitionInterface newIntf = getRequisitionInterface(newNode, intf.getIpAddr());
if (newIntf != null) {
newIntf.getMonitoredServices().addAll(services);
}
}
}
}
}
}
}
}
return newReq;
}
use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.
the class HandlerTest method dwOpenConnectionURL.
@Test
@Ignore
public void dwOpenConnectionURL() throws IOException {
URL url = new URL(DNS_URL);
UrlResource resource = new UrlResource(url);
MockForeignSourceRepository fsr = new MockForeignSourceRepository();
Requisition r = fsr.importResourceRequisition(resource);
Assert.assertTrue("Number of nodes in Model Import > 1", 1 == r.getNodeCount());
Assert.assertTrue("NodeLabel isn't localhost", "localhost".equals(r.getNodes().get(0).getNodeLabel()));
Assert.assertTrue("127.0.0.1".equals(r.getNodes().get(0).getInterfaces().get(0).getIpAddr()));
}
use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.
the class RequisitionUrlConnection method getInputStream.
@Override
public InputStream getInputStream() throws IOException {
try {
final Requisition requisition = getClient().requisition().withRequisitionProviderType(type).withParameters(parameters).execute().get();
if (requisition == null) {
throw new IOException(String.format("Invalid (null) requisition was returned by the provider for type '%s'", type));
}
// The XmlHandler is not thread safe
// Marshaling is quick, so we opt to use a single instance of the handler
// instead of using thread-local variables
final String requisitionXml;
synchronized (s_xmlHandler) {
requisitionXml = s_xmlHandler.marshal(requisition);
}
return new ByteArrayInputStream(requisitionXml.getBytes());
} catch (ExecutionException | InterruptedException e) {
throw new IOException(e);
}
}
use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.
the class RequisitionUrlConnectionTest method canRetrieveRequisition.
@Test
public void canRetrieveRequisition() throws Exception {
Requisition expectedRequisition = new Requisition();
LocationAwareRequisitionClient client = mock(LocationAwareRequisitionClient.class, RETURNS_DEEP_STUBS);
when(client.requisition().withRequisitionProviderType("test").withParameters(any()).execute().get()).thenReturn(expectedRequisition);
try {
RequisitionUrlConnection.setClient(client);
final String requisitionAsStr = urlToString("requisition://test/");
Requisition actualRequisition = JaxbUtils.unmarshal(Requisition.class, requisitionAsStr);
assertEquals(expectedRequisition, actualRequisition);
} finally {
RequisitionUrlConnection.setClient(null);
}
}
Aggregations