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