Search in sources :

Example 6 with StringMap

use of com.linkedin.data.template.StringMap in project incubator-gobblin by apache.

the class FlowConfigTest method testCreateBadTemplateUri.

@Test
public void testCreateBadTemplateUri() throws Exception {
    Map<String, String> flowProperties = Maps.newHashMap();
    flowProperties.put("param1", "value1");
    FlowConfig flowConfig = new FlowConfig().setId(new FlowId().setFlowGroup(TEST_GROUP_NAME).setFlowName(TEST_FLOW_NAME)).setTemplateUris("FILE://bad/uri").setSchedule(new Schedule().setCronSchedule(TEST_SCHEDULE).setRunImmediately(true)).setProperties(new StringMap(flowProperties));
    try {
        _client.createFlowConfig(flowConfig);
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.S_422_UNPROCESSABLE_ENTITY.getCode());
        return;
    }
    Assert.fail("Get should have gotten a 422 error");
}
Also used : StringMap(com.linkedin.data.template.StringMap) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 7 with StringMap

use of com.linkedin.data.template.StringMap in project incubator-gobblin by apache.

the class FlowConfigTest method testBadUpdate.

@Test
public void testBadUpdate() throws Exception {
    Map<String, String> flowProperties = Maps.newHashMap();
    flowProperties.put("param1", "value1b");
    flowProperties.put("param2", "value2b");
    FlowConfig flowConfig = new FlowConfig().setId(new FlowId().setFlowGroup(TEST_DUMMY_GROUP_NAME).setFlowName(TEST_DUMMY_FLOW_NAME)).setTemplateUris(TEST_TEMPLATE_URI).setSchedule(new Schedule().setCronSchedule(TEST_SCHEDULE)).setProperties(new StringMap(flowProperties));
    try {
        _client.updateFlowConfig(flowConfig);
    } catch (RestLiResponseException e) {
        Assert.fail("Bad update should pass without complaining that the spec does not exists.");
    }
}
Also used : StringMap(com.linkedin.data.template.StringMap) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 8 with StringMap

use of com.linkedin.data.template.StringMap in project incubator-gobblin by apache.

the class PoliciesResource method get.

@Override
public Policy get(String resourceId) {
    try {
        ThrottlingPolicy throttlingPolicy = (ThrottlingPolicy) this.broker.getSharedResource(new ThrottlingPolicyFactory(), new SharedLimiterKey(resourceId));
        Policy restliPolicy = new Policy();
        restliPolicy.setPolicyName(throttlingPolicy.getClass().getSimpleName());
        restliPolicy.setResource(resourceId);
        restliPolicy.setParameters(new StringMap(throttlingPolicy.getParameters()));
        restliPolicy.setPolicyDetails(throttlingPolicy.getDescription());
        MetricContext resourceContext = (MetricContext) broker.getSharedResource(new MetricContextFactory(), new SubTaggedMetricContextKey(resourceId, ImmutableMap.of(RESOURCE_ID_TAG, resourceId)));
        StringMap metrics = new StringMap();
        for (Map.Entry<String, Meter> meter : resourceContext.getMeters().entrySet()) {
            metrics.put(meter.getKey(), Double.toString(meter.getValue().getOneMinuteRate()));
        }
        restliPolicy.setMetrics(metrics);
        return restliPolicy;
    } catch (NotConfiguredException nce) {
        throw new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Policy not found for resource " + resourceId);
    }
}
Also used : NotConfiguredException(org.apache.gobblin.broker.iface.NotConfiguredException) StringMap(com.linkedin.data.template.StringMap) Meter(com.codahale.metrics.Meter) SubTaggedMetricContextKey(org.apache.gobblin.metrics.broker.SubTaggedMetricContextKey) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) MetricContext(org.apache.gobblin.metrics.MetricContext) MetricContextFactory(org.apache.gobblin.metrics.broker.MetricContextFactory) SharedLimiterKey(org.apache.gobblin.util.limiter.broker.SharedLimiterKey) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) StringMap(com.linkedin.data.template.StringMap)

Example 9 with StringMap

use of com.linkedin.data.template.StringMap in project incubator-gobblin by apache.

the class TaskState method toTaskExecutionInfo.

/**
 * Convert this {@link TaskState} instance to a {@link TaskExecutionInfo} instance.
 *
 * @return a {@link TaskExecutionInfo} instance
 */
public TaskExecutionInfo toTaskExecutionInfo() {
    TaskExecutionInfo taskExecutionInfo = new TaskExecutionInfo();
    taskExecutionInfo.setJobId(this.jobId);
    taskExecutionInfo.setTaskId(this.taskId);
    if (this.startTime > 0) {
        taskExecutionInfo.setStartTime(this.startTime);
    }
    if (this.endTime > 0) {
        taskExecutionInfo.setEndTime(this.endTime);
    }
    taskExecutionInfo.setDuration(this.duration);
    taskExecutionInfo.setState(TaskStateEnum.valueOf(getWorkingState().name()));
    if (this.contains(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY)) {
        taskExecutionInfo.setFailureException(this.getProp(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY));
    }
    taskExecutionInfo.setHighWatermark(this.getHighWaterMark());
    // Add extract/table information
    Table table = new Table();
    Extract extract = this.getExtract();
    table.setNamespace(extract.getNamespace());
    table.setName(extract.getTable());
    if (extract.hasType()) {
        table.setType(TableTypeEnum.valueOf(extract.getType().name()));
    }
    taskExecutionInfo.setTable(table);
    // Add task metrics
    TaskMetrics taskMetrics = TaskMetrics.get(this);
    MetricArray metricArray = new MetricArray();
    for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : taskMetrics.getMetricContext().getCounters().entrySet()) {
        Metric counter = new Metric();
        counter.setGroup(MetricGroup.TASK.name());
        counter.setName(entry.getKey());
        counter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.COUNTER.name()));
        counter.setValue(Long.toString(((Counter) entry.getValue()).getCount()));
        metricArray.add(counter);
    }
    for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : taskMetrics.getMetricContext().getMeters().entrySet()) {
        Metric meter = new Metric();
        meter.setGroup(MetricGroup.TASK.name());
        meter.setName(entry.getKey());
        meter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.METER.name()));
        meter.setValue(Double.toString(((Meter) entry.getValue()).getMeanRate()));
        metricArray.add(meter);
    }
    for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : taskMetrics.getMetricContext().getGauges().entrySet()) {
        Metric gauge = new Metric();
        gauge.setGroup(MetricGroup.TASK.name());
        gauge.setName(entry.getKey());
        gauge.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.GAUGE.name()));
        gauge.setValue(((Gauge<?>) entry.getValue()).getValue().toString());
        metricArray.add(gauge);
    }
    taskExecutionInfo.setMetrics(metricArray);
    // Add task properties
    Map<String, String> taskProperties = Maps.newHashMap();
    for (String name : this.getPropertyNames()) {
        String value = this.getProp(name);
        if (!Strings.isNullOrEmpty(value))
            taskProperties.put(name, value);
    }
    taskExecutionInfo.setTaskProperties(new StringMap(taskProperties));
    return taskExecutionInfo;
}
Also used : StringMap(com.linkedin.data.template.StringMap) Table(org.apache.gobblin.rest.Table) Meter(com.codahale.metrics.Meter) Extract(org.apache.gobblin.source.workunit.Extract) Gauge(com.codahale.metrics.Gauge) Counter(com.codahale.metrics.Counter) TaskExecutionInfo(org.apache.gobblin.rest.TaskExecutionInfo) TaskMetrics(org.apache.gobblin.runtime.util.TaskMetrics) MetricArray(org.apache.gobblin.rest.MetricArray) Metric(org.apache.gobblin.rest.Metric) Map(java.util.Map) StringMap(com.linkedin.data.template.StringMap)

Example 10 with StringMap

use of com.linkedin.data.template.StringMap in project incubator-gobblin by apache.

the class JobState method toJobExecutionInfo.

/**
 * Convert this {@link JobState} instance to a {@link JobExecutionInfo} instance.
 *
 * @return a {@link JobExecutionInfo} instance
 */
public JobExecutionInfo toJobExecutionInfo() {
    JobExecutionInfo jobExecutionInfo = new JobExecutionInfo();
    jobExecutionInfo.setJobName(this.jobName);
    jobExecutionInfo.setJobId(this.jobId);
    if (this.startTime > 0) {
        jobExecutionInfo.setStartTime(this.startTime);
    }
    if (this.endTime > 0) {
        jobExecutionInfo.setEndTime(this.endTime);
    }
    jobExecutionInfo.setDuration(this.duration);
    jobExecutionInfo.setState(JobStateEnum.valueOf(this.state.name()));
    jobExecutionInfo.setLaunchedTasks(this.taskCount);
    jobExecutionInfo.setCompletedTasks(this.getCompletedTasks());
    jobExecutionInfo.setLauncherType(getLauncherType());
    if (getTrackingURL().isPresent()) {
        jobExecutionInfo.setTrackingUrl(getTrackingURL().get());
    }
    // Add task execution information
    TaskExecutionInfoArray taskExecutionInfos = new TaskExecutionInfoArray();
    for (TaskState taskState : this.getTaskStates()) {
        taskExecutionInfos.add(taskState.toTaskExecutionInfo());
    }
    jobExecutionInfo.setTaskExecutions(taskExecutionInfos);
    // Add job metrics
    JobMetrics jobMetrics = JobMetrics.get(this);
    MetricArray metricArray = new MetricArray();
    for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : jobMetrics.getMetricContext().getCounters().entrySet()) {
        Metric counter = new Metric();
        counter.setGroup(MetricGroup.JOB.name());
        counter.setName(entry.getKey());
        counter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.COUNTER.name()));
        counter.setValue(Long.toString(((Counter) entry.getValue()).getCount()));
        metricArray.add(counter);
    }
    for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : jobMetrics.getMetricContext().getMeters().entrySet()) {
        Metric meter = new Metric();
        meter.setGroup(MetricGroup.JOB.name());
        meter.setName(entry.getKey());
        meter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.METER.name()));
        meter.setValue(Double.toString(((Meter) entry.getValue()).getMeanRate()));
        metricArray.add(meter);
    }
    for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : jobMetrics.getMetricContext().getGauges().entrySet()) {
        Metric gauge = new Metric();
        gauge.setGroup(MetricGroup.JOB.name());
        gauge.setName(entry.getKey());
        gauge.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.GAUGE.name()));
        gauge.setValue(((Gauge<?>) entry.getValue()).getValue().toString());
        metricArray.add(gauge);
    }
    jobExecutionInfo.setMetrics(metricArray);
    // Add job properties
    Map<String, String> jobProperties = Maps.newHashMap();
    for (String name : this.getPropertyNames()) {
        String value = this.getProp(name);
        if (!Strings.isNullOrEmpty(value)) {
            jobProperties.put(name, value);
        }
    }
    jobExecutionInfo.setJobProperties(new StringMap(jobProperties));
    return jobExecutionInfo;
}
Also used : StringMap(com.linkedin.data.template.StringMap) Meter(com.codahale.metrics.Meter) TaskExecutionInfoArray(org.apache.gobblin.rest.TaskExecutionInfoArray) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo) JobMetrics(org.apache.gobblin.runtime.util.JobMetrics) Gauge(com.codahale.metrics.Gauge) Counter(com.codahale.metrics.Counter) MetricArray(org.apache.gobblin.rest.MetricArray) Metric(org.apache.gobblin.rest.Metric) Map(java.util.Map) StringMap(com.linkedin.data.template.StringMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

StringMap (com.linkedin.data.template.StringMap)47 Test (org.testng.annotations.Test)26 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)9 FlowConfig (org.apache.gobblin.service.FlowConfig)9 FlowId (org.apache.gobblin.service.FlowId)9 Schedule (org.apache.gobblin.service.Schedule)9 Map (java.util.Map)8 IndividualRequest (com.linkedin.restli.common.multiplexer.IndividualRequest)6 IndividualRequestMap (com.linkedin.restli.common.multiplexer.IndividualRequestMap)5 TaskExecutionInfo (org.apache.gobblin.rest.TaskExecutionInfo)5 ByteString (com.linkedin.data.ByteString)4 DataMap (com.linkedin.data.DataMap)4 Meter (com.codahale.metrics.Meter)3 RestRequest (com.linkedin.r2.message.rest.RestRequest)3 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)3 PreparedStatement (java.sql.PreparedStatement)3 AbstractMap (java.util.AbstractMap)3 JobExecutionInfo (org.apache.gobblin.rest.JobExecutionInfo)3 Metric (org.apache.gobblin.rest.Metric)3 MetricArray (org.apache.gobblin.rest.MetricArray)3