Search in sources :

Example 36 with StringMap

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

the class DatabaseJobHistoryStoreV101 method addPropertiesToTasks.

private void addPropertiesToTasks(Connection connection, JobExecutionQuery query, Filter tableFilter, Map<String, Map<String, TaskExecutionInfo>> taskExecutionInfos) throws SQLException {
    if (taskExecutionInfos.size() > 0) {
        Set<String> propertyKeys = null;
        if (query.hasTaskProperties()) {
            propertyKeys = Sets.newHashSet(Iterables.filter(Arrays.asList(query.getTaskProperties().split(",")), new Predicate<String>() {

                @Override
                public boolean apply(String input) {
                    return !Strings.isNullOrEmpty(input);
                }
            }));
        }
        if (propertyKeys == null || propertyKeys.size() > 0) {
            String template = String.format(TASK_PROPERTY_QUERY_STATEMENT_TEMPLATE, getInPredicate(taskExecutionInfos.size()));
            if (propertyKeys != null && propertyKeys.size() > 0) {
                template += String.format("AND property_key IN (%s)", getInPredicate(propertyKeys.size()));
            }
            if (tableFilter.isPresent()) {
                template += " AND t." + tableFilter;
            }
            int index = 1;
            try (PreparedStatement taskPropertiesQueryStatement = connection.prepareStatement(template)) {
                for (String jobId : taskExecutionInfos.keySet()) {
                    taskPropertiesQueryStatement.setString(index++, jobId);
                }
                if (propertyKeys != null && propertyKeys.size() > 0) {
                    for (String propertyKey : propertyKeys) {
                        taskPropertiesQueryStatement.setString(index++, propertyKey);
                    }
                }
                if (tableFilter.isPresent()) {
                    tableFilter.addParameters(taskPropertiesQueryStatement, index);
                }
                try (ResultSet taskPropertiesRs = taskPropertiesQueryStatement.executeQuery()) {
                    while (taskPropertiesRs.next()) {
                        String jobId = taskPropertiesRs.getString("job_id");
                        String taskId = taskPropertiesRs.getString("task_id");
                        TaskExecutionInfo taskExecutionInfo = taskExecutionInfos.get(jobId).get(taskId);
                        StringMap taskProperties = taskExecutionInfo.getTaskProperties(GetMode.NULL);
                        if (taskProperties == null) {
                            taskProperties = new StringMap();
                            taskExecutionInfo.setTaskProperties(taskProperties);
                        }
                        Map.Entry<String, String> property = resultSetToProperty(taskPropertiesRs);
                        if (propertyKeys == null || propertyKeys.contains(property.getKey())) {
                            taskProperties.put(property.getKey(), property.getValue());
                        }
                    }
                }
            }
        }
    }
}
Also used : StringMap(com.linkedin.data.template.StringMap) TaskExecutionInfo(org.apache.gobblin.rest.TaskExecutionInfo) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Map(java.util.Map) StringMap(com.linkedin.data.template.StringMap) AbstractMap(java.util.AbstractMap)

Example 37 with StringMap

use of com.linkedin.data.template.StringMap in project rest.li by linkedin.

the class MultiplexerTestBase method fakeIndividualRequest.

protected static IndividualRequest fakeIndividualRequest(String url, Map<String, IndividualRequest> dependentCalls) {
    IndividualRequest request = new IndividualRequest();
    request.setMethod(HttpMethod.GET.name());
    request.setHeaders(new StringMap(HEADERS));
    request.setRelativeUrl(url);
    request.setDependentRequests(new IndividualRequestMap(dependentCalls));
    return request;
}
Also used : IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) StringMap(com.linkedin.data.template.StringMap)

Example 38 with StringMap

use of com.linkedin.data.template.StringMap in project rest.li by linkedin.

the class MultiplexedRequestBuilder method toIndividualRequest.

private static IndividualRequest toIndividualRequest(Request<?> request, IndividualRequestMap dependantRequests) throws RestLiEncodingException {
    // TODO: Hardcoding RESTLI_PROTOCOL_2_0_0 for now. We need to refactor this code later to get protocol version using the mechanism similar to
    // RestClient.getProtocolVersionForService()
    ProtocolVersion protocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion();
    String relativeUrl = getRelativeUrl(request, protocolVersion);
    IndividualRequest individualRequest = new IndividualRequest();
    individualRequest.setRelativeUrl(relativeUrl);
    individualRequest.setMethod(request.getMethod().getHttpMethod().name());
    individualRequest.setHeaders(new StringMap(request.getHeaders()));
    List<HttpCookie> cookies = request.getCookies();
    if (cookies != null && !cookies.isEmpty()) {
        throw new IllegalArgumentException(String.format("Cookies for individual request '%s' MUST be added at the envelope request level", relativeUrl));
    }
    individualRequest.setBody(getBody(request, protocolVersion), SetMode.IGNORE_NULL);
    individualRequest.setDependentRequests(dependantRequests);
    return individualRequest;
}
Also used : IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) StringMap(com.linkedin.data.template.StringMap) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) HttpCookie(java.net.HttpCookie)

Example 39 with StringMap

use of com.linkedin.data.template.StringMap in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testInvoke_testComplexParameters.

@Test
public void testInvoke_testComplexParameters() throws Exception {
    ResourceModel accountsResourceModel = buildResourceModel(TwitterAccountsResource.class);
    ResourceMethodDescriptor methodDescriptor;
    TwitterAccountsResource accountsResource;
    // #1 no defaults provided
    methodDescriptor = accountsResourceModel.findActionMethod("closeAccounts", ResourceLevel.COLLECTION);
    accountsResource = getMockResource(TwitterAccountsResource.class);
    StringArray emailAddresses = new StringArray("bob@test.linkedin.com", "joe@test.linkedin.com");
    EasyMock.expect(accountsResource.closeAccounts(eq(emailAddresses), eq(true), eq((StringMap) null))).andReturn((new StringMap())).once();
    String jsonEntityBody = RestLiTestHelper.doubleQuote("{'emailAddresses': ['bob@test.linkedin.com', 'joe@test.linkedin.com'], 'someFlag': true}");
    checkInvocation(accountsResource, methodDescriptor, "POST", version, "/accounts?action=closeAccounts", jsonEntityBody);
}
Also used : StringMap(com.linkedin.data.template.StringMap) StringArray(com.linkedin.data.template.StringArray) TwitterAccountsResource(com.linkedin.restli.server.twitter.TwitterAccountsResource) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 40 with StringMap

use of com.linkedin.data.template.StringMap in project rest.li by linkedin.

the class TestRestLiResponseHandler method testPartialRestResponse.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusActionDataPartial")
public void testPartialRestResponse(AcceptTypeData acceptTypeData, String response1, String response2, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
    final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
    RestLiResponse response;
    RoutingResult routingResult1 = buildRoutingResultAction(Status.class, request, acceptTypeData.acceptHeaders);
    // #1 simple record template
    response = buildPartialRestResponse(request, routingResult1, buildStatusRecord());
    checkResponse(response, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
    assertEquals(response.getEntity().toString(), response1);
    // #2 DataTemplate response
    StringMap map = new StringMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    RoutingResult routingResult2 = buildRoutingResultAction(StringMap.class, request, acceptTypeData.acceptHeaders);
    response = buildPartialRestResponse(request, routingResult2, map);
    checkResponse(response, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
    // Obtain the maps necessary for comparison
    final DataMap actualMap;
    final DataMap expectedMap;
    actualMap = response.getDataMap();
    expectedMap = JACKSON_DATA_CODEC.stringToMap(response2);
    assertEquals(actualMap, expectedMap);
    RoutingResult routingResult3 = buildRoutingResultAction(Void.TYPE, request, acceptTypeData.acceptHeaders);
    // #3 empty response
    response = buildPartialRestResponse(request, routingResult3, null);
    checkResponse(response, HttpStatus.S_200_OK, 1, false, false, errorResponseHeaderName);
    assertEquals(response.getEntity(), null);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) StringMap(com.linkedin.data.template.StringMap) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestLiResponse(com.linkedin.restli.internal.server.response.RestLiResponse) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

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