Search in sources :

Example 1 with ExternalResourceInfo

use of org.apache.flink.api.common.externalresource.ExternalResourceInfo in project flink by apache.

the class ExternalResourceUtils method createStaticExternalResourceInfoProvider.

/**
 * Instantiate {@link StaticExternalResourceInfoProvider} for all of enabled external resources.
 */
@VisibleForTesting
static ExternalResourceInfoProvider createStaticExternalResourceInfoProvider(Map<String, Long> externalResourceAmountMap, Map<String, ExternalResourceDriver> externalResourceDrivers) {
    final Map<String, Set<? extends ExternalResourceInfo>> externalResources = new HashMap<>();
    for (Map.Entry<String, ExternalResourceDriver> externalResourceDriverEntry : externalResourceDrivers.entrySet()) {
        final String resourceName = externalResourceDriverEntry.getKey();
        final ExternalResourceDriver externalResourceDriver = externalResourceDriverEntry.getValue();
        if (externalResourceAmountMap.containsKey(resourceName)) {
            try {
                final Set<? extends ExternalResourceInfo> externalResourceInfos;
                externalResourceInfos = externalResourceDriver.retrieveResourceInfo(externalResourceAmountMap.get(resourceName));
                externalResources.put(resourceName, externalResourceInfos);
            } catch (Exception e) {
                LOG.warn("Failed to retrieve information of external resource {}.", resourceName, e);
            }
        } else {
            LOG.warn("Could not found legal amount configuration for {}.", resourceName);
        }
    }
    return new StaticExternalResourceInfoProvider(externalResources);
}
Also used : ExternalResourceInfo(org.apache.flink.api.common.externalresource.ExternalResourceInfo) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ExternalResourceDriver(org.apache.flink.api.common.externalresource.ExternalResourceDriver) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 ExternalResourceDriver (org.apache.flink.api.common.externalresource.ExternalResourceDriver)1 ExternalResourceInfo (org.apache.flink.api.common.externalresource.ExternalResourceInfo)1