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());
}
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);
}
Aggregations