use of org.cloudfoundry.promregator.scanner.ResolvedTarget in project promregator by promregator.
the class CFMultiDiscoverer method discover.
/**
* performs the discovery based on the configured set of targets in the configuration, (pre-)filtering the returned set applying the filter criteria supplied.
* The instances discovered are automatically registered at this Discoverer
* @param applicationIdFilter the (pre-)filter based on ApplicationIds, allowing to early filter the list of instances to discover
* @param instanceFilter the (pre-)filter based on the Instance instance, allowing to filter the lost if instances to discover
* @return the list of Instances which were discovered (and registered).
*/
@Nullable
public List<Instance> discover(@Nullable Predicate<? super String> applicationIdFilter, @Nullable Predicate<? super Instance> instanceFilter) {
log.debug(String.format("We have %d targets configured", this.promregatorConfiguration.getTargets().size()));
List<ResolvedTarget> resolvedTargets = this.targetResolver.resolveTargets(this.promregatorConfiguration.getTargets());
if (resolvedTargets == null) {
log.warn("Target resolved was unable to resolve configured targets");
return Collections.emptyList();
}
log.debug(String.format("Raw list contains %d resolved targets", resolvedTargets.size()));
List<Instance> instanceList = this.appInstanceScanner.determineInstancesFromTargets(resolvedTargets, applicationIdFilter, instanceFilter);
if (instanceList == null) {
log.warn("Instance Scanner unable to determine instances from provided targets");
return Collections.emptyList();
}
log.debug(String.format("Raw list contains %d instances", instanceList.size()));
// ensure that the instances are registered / touched properly
for (Instance instance : instanceList) {
this.registerInstance(instance);
}
return instanceList;
}
use of org.cloudfoundry.promregator.scanner.ResolvedTarget in project promregator by promregator.
the class MockedMetricsEndpointSpringApplication method appInstanceScanner.
@Bean
public AppInstanceScanner appInstanceScanner() {
return new AppInstanceScanner() {
@Override
public List<Instance> determineInstancesFromTargets(List<ResolvedTarget> targets, @Nullable Predicate<? super String> applicationIdFilter, @Nullable Predicate<? super Instance> instanceFilter) {
LinkedList<Instance> result = new LinkedList<>();
ResolvedTarget t = new ResolvedTarget();
t.setOrgName("unittestorg");
t.setSpaceName("unittestspace");
t.setApplicationName("unittestapp");
t.setPath("/path");
t.setProtocol("https");
result.add(new Instance(t, "faedbb0a-2273-4cb4-a659-bd31331f7daf:0", "http://localhost:1234", false));
result.add(new Instance(t, "faedbb0a-2273-4cb4-a659-bd31331f7daf:1", "http://localhost:1234", false));
t = new ResolvedTarget();
t.setOrgName("unittestorg");
t.setSpaceName("unittestspace");
t.setApplicationName("unittestapp2");
t.setPath("/otherpath");
t.setProtocol("http");
result.add(new Instance(t, "1142a717-e27d-4028-89d8-b42a0c973300:0", "http://localhost:1235", false));
if (applicationIdFilter != null) {
for (Iterator<Instance> it = result.iterator(); it.hasNext(); ) {
Instance instance = it.next();
if (!applicationIdFilter.test(instance.getApplicationId()))
it.remove();
}
}
if (instanceFilter != null) {
for (Iterator<Instance> it = result.iterator(); it.hasNext(); ) {
Instance instance = it.next();
if (!instanceFilter.test(instance))
it.remove();
}
}
return result;
}
};
}
Aggregations