Search in sources :

Example 31 with AbstractID

use of org.apache.flink.util.AbstractID in project flink by apache.

the class DataSet method count.

/**
 * Convenience method to get the count (number of elements) of a DataSet.
 *
 * @return A long integer that represents the number of elements in the data set.
 */
public long count() throws Exception {
    final String id = new AbstractID().toString();
    output(new Utils.CountHelper<T>(id)).name("count()");
    JobExecutionResult res = getExecutionEnvironment().execute();
    return res.<Long>getAccumulatorResult(id);
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) AbstractID(org.apache.flink.util.AbstractID)

Example 32 with AbstractID

use of org.apache.flink.util.AbstractID in project flink by apache.

the class PrometheusPushGatewayReporterFactory method createMetricReporter.

@Override
public PrometheusPushGatewayReporter createMetricReporter(Properties properties) {
    MetricConfig metricConfig = (MetricConfig) properties;
    String host = metricConfig.getString(HOST.key(), HOST.defaultValue());
    int port = metricConfig.getInteger(PORT.key(), PORT.defaultValue());
    String configuredJobName = metricConfig.getString(JOB_NAME.key(), JOB_NAME.defaultValue());
    boolean randomSuffix = metricConfig.getBoolean(RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue());
    boolean deleteOnShutdown = metricConfig.getBoolean(DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue());
    Map<String, String> groupingKey = parseGroupingKey(metricConfig.getString(GROUPING_KEY.key(), GROUPING_KEY.defaultValue()));
    String hostUrlConfig = metricConfig.getString(HOST_URL.key(), HOST_URL.defaultValue());
    final String hostUrl;
    if (!StringUtils.isNullOrWhitespaceOnly(hostUrlConfig)) {
        hostUrl = hostUrlConfig;
    } else {
        if (StringUtils.isNullOrWhitespaceOnly(host) || port < 1) {
            throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port);
        } else {
            hostUrl = "http://" + host + ":" + port;
        }
    }
    String jobName = configuredJobName;
    if (randomSuffix) {
        jobName = configuredJobName + new AbstractID();
    }
    LOG.info("Configured PrometheusPushGatewayReporter with {hostUrl:{}, jobName:{}, randomJobNameSuffix:{}, deleteOnShutdown:{}, groupingKey:{}}", hostUrl, jobName, randomSuffix, deleteOnShutdown, groupingKey);
    try {
        return new PrometheusPushGatewayReporter(new URL(hostUrl), jobName, groupingKey, deleteOnShutdown);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) MalformedURLException(java.net.MalformedURLException) AbstractID(org.apache.flink.util.AbstractID) HOST_URL(org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterOptions.HOST_URL) URL(java.net.URL)

Example 33 with AbstractID

use of org.apache.flink.util.AbstractID in project flink by apache.

the class TaskManagerGroupTest method testCloseClosesAll.

@Test
public void testCloseClosesAll() throws IOException {
    final TaskManagerMetricGroup group = TaskManagerMetricGroup.createTaskManagerMetricGroup(registry, "localhost", new ResourceID(new AbstractID().toString()));
    final JobID jid1 = new JobID();
    final JobID jid2 = new JobID();
    final String jobName1 = "testjob";
    final String jobName2 = "anotherJob";
    final JobVertexID vertex11 = new JobVertexID();
    final JobVertexID vertex12 = new JobVertexID();
    final JobVertexID vertex21 = new JobVertexID();
    final ExecutionAttemptID execution11 = new ExecutionAttemptID();
    final ExecutionAttemptID execution12 = new ExecutionAttemptID();
    final ExecutionAttemptID execution21 = new ExecutionAttemptID();
    TaskMetricGroup tmGroup11 = group.addJob(jid1, jobName1).addTask(vertex11, execution11, "test", 17, 0);
    TaskMetricGroup tmGroup12 = group.addJob(jid1, jobName1).addTask(vertex12, execution12, "test", 13, 1);
    TaskMetricGroup tmGroup21 = group.addJob(jid2, jobName2).addTask(vertex21, execution21, "test", 7, 1);
    group.close();
    assertTrue(tmGroup11.isClosed());
    assertTrue(tmGroup12.isClosed());
    assertTrue(tmGroup21.isClosed());
}
Also used : ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) AbstractID(org.apache.flink.util.AbstractID) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

AbstractID (org.apache.flink.util.AbstractID)33 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)10 Assert (org.junit.Assert)10 Arrays (java.util.Arrays)9 Collection (java.util.Collection)9 JobID (org.apache.flink.api.common.JobID)9 Types (org.apache.flink.api.common.typeinfo.Types)9 EmbeddedRocksDBStateBackend (org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend)9 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)9 StateBackend (org.apache.flink.runtime.state.StateBackend)9 HashMapStateBackend (org.apache.flink.runtime.state.hashmap.HashMapStateBackend)9 DataStream (org.apache.flink.streaming.api.datastream.DataStream)9 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)9 Iterator (java.util.Iterator)8 Optional (java.util.Optional)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 AggregateFunction (org.apache.flink.api.common.functions.AggregateFunction)8