Search in sources :

Example 6 with RpcTarget

use of org.opennms.core.rpc.api.RpcTarget in project opennms by OpenNMS.

the class RpcTargetHelperTest method usesNullLocationAndSystemIdWhenNothingIsSet.

@Test
public void usesNullLocationAndSystemIdWhenNothingIsSet() {
    final RpcTarget target = new RpcTargetHelper().target().build();
    assertThat(target.getLocation(), nullValue());
    assertThat(target.getSystemId(), nullValue());
}
Also used : RpcTarget(org.opennms.core.rpc.api.RpcTarget) Test(org.junit.Test)

Example 7 with RpcTarget

use of org.opennms.core.rpc.api.RpcTarget in project opennms by OpenNMS.

the class CollectorRequestBuilderImpl method execute.

@Override
public CompletableFuture<CollectionSet> execute() {
    if (serviceCollector == null) {
        throw new IllegalArgumentException("Collector or collector class name is required.");
    } else if (agent == null) {
        throw new IllegalArgumentException("Agent is required.");
    }
    final RpcTarget target = client.getRpcTargetHelper().target().withNodeId(agent.getNodeId()).withLocation(agent.getLocationName()).withSystemId(systemId).withServiceAttributes(attributes).withLocationOverride((s) -> serviceCollector.getEffectiveLocation(s)).build();
    CollectorRequestDTO request = new CollectorRequestDTO();
    request.setLocation(target.getLocation());
    request.setSystemId(target.getSystemId());
    request.setClassName(serviceCollector.getClass().getCanonicalName());
    request.setTimeToLiveMs(ttlInMs);
    // Retrieve the runtime attributes, which may include attributes
    // such as the agent details and other state related attributes
    // which should be included in the request
    final Map<String, Object> runtimeAttributes = serviceCollector.getRuntimeAttributes(agent, attributes);
    final Map<String, Object> allAttributes = new HashMap<>();
    allAttributes.putAll(attributes);
    allAttributes.putAll(runtimeAttributes);
    // Only marshal these if the request is being executed at another location.
    if (MonitoringLocationUtils.isDefaultLocationName(request.getLocation())) {
        // As-is
        request.setAgent(agent);
        request.addAttributes(allAttributes);
    } else {
        // Marshal
        request.setAgent(new CollectionAgentDTO(agent));
        final Map<String, String> marshaledParms = serviceCollector.marshalParameters(allAttributes);
        marshaledParms.forEach(request::addAttribute);
        request.setAttributesNeedUnmarshaling(true);
    }
    // Execute the request
    return client.getDelegate().execute(request).thenApply(CollectorResponseDTO::getCollectionSet);
}
Also used : ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) Objects(java.util.Objects) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) CollectorRequestBuilder(org.opennms.netmgt.collection.api.CollectorRequestBuilder) MonitoringLocationUtils(org.opennms.netmgt.dao.api.MonitoringLocationUtils) CollectionAgentDTO(org.opennms.netmgt.collection.dto.CollectionAgentDTO) Map(java.util.Map) RpcTarget(org.opennms.core.rpc.api.RpcTarget) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) HashMap(java.util.HashMap) CollectionAgentDTO(org.opennms.netmgt.collection.dto.CollectionAgentDTO) RpcTarget(org.opennms.core.rpc.api.RpcTarget)

Aggregations

RpcTarget (org.opennms.core.rpc.api.RpcTarget)7 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 Map (java.util.Map)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Objects (java.util.Objects)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Matchers.nullValue (org.hamcrest.Matchers.nullValue)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)1 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)1 CollectorRequestBuilder (org.opennms.netmgt.collection.api.CollectorRequestBuilder)1 ServiceCollector (org.opennms.netmgt.collection.api.ServiceCollector)1 CollectionAgentDTO (org.opennms.netmgt.collection.dto.CollectionAgentDTO)1