Search in sources :

Example 1 with ClusterDef

use of com.yahoo.vespaclient.ClusterDef in project vespa by vespa-engine.

the class VisitSearcher method getVisitorParameters.

public VisitorParameters getVisitorParameters(Query query, Result result) throws Exception {
    String documentSelection = query.properties().getString("visit.selection");
    if (documentSelection == null) {
        documentSelection = "";
    }
    VisitorParameters params = new VisitorParameters(documentSelection);
    params.setMaxBucketsPerVisitor(query.properties().getInteger("visit.maxBucketsPerVisitor", 1));
    params.setMaxPending(query.properties().getInteger("visit.maxPendingMessagesPerVisitor", 32));
    params.setMaxFirstPassHits(query.properties().getInteger("visit.approxMaxDocs", 1));
    params.setMaxTotalHits(query.properties().getInteger("visit.approxMaxDocs", 1));
    params.setThrottlePolicy(new StaticThrottlePolicy().setMaxPendingCount(query.properties().getInteger("visit.maxPendingVisitors", 1)));
    params.setToTimestamp(query.properties().getLong("visit.toTimestamp", 0L));
    params.setFromTimestamp(query.properties().getLong("visit.fromTimestamp", 0L));
    String pri = query.properties().getString("visit.priority");
    if (pri != null) {
        params.setPriority(DocumentProtocol.Priority.valueOf(pri));
    }
    if (query.properties().getBoolean("visit.visitInconsistentBuckets")) {
        params.visitInconsistentBuckets(true);
    }
    String ordering = query.properties().getString("visit.order");
    if (!"ascending".equalsIgnoreCase(ordering)) {
        params.setVisitorOrdering(VisitorOrdering.ASCENDING);
    } else {
        params.setVisitorOrdering(VisitorOrdering.DESCENDING);
    }
    String remoteCluster = query.properties().getString("visit.dataHandler");
    if (remoteCluster != null) {
        params.setRemoteDataHandler(remoteCluster);
    } else {
        params.setLocalDataHandler(new HitDataHandler(result, query.properties().getBoolean("populatehitfields", false)));
    }
    String fieldSet = query.properties().getString("visit.fieldSet");
    if (fieldSet != null) {
        params.fieldSet(fieldSet);
    }
    String continuation = query.properties().getString("visit.continuation");
    if (continuation != null) {
        params.setResumeToken(ContinuationHit.getToken(continuation));
    }
    params.setVisitRemoves(query.properties().getBoolean("visit.visitRemoves"));
    MessagePropertyProcessor.PropertySetter propertySetter;
    propertySetter = context.getPropertyProcessor().buildPropertySetter(query.getHttpRequest());
    propertySetter.process(params);
    if (context.getClusterList().getStorageClusters().size() == 0) {
        throw new IllegalArgumentException("No content clusters have been defined");
    }
    String route = query.properties().getString("visit.cluster");
    ClusterDef found = null;
    if (route != null) {
        String names = "";
        for (ClusterDef c : context.getClusterList().getStorageClusters()) {
            if (c.getName().equals(route)) {
                found = c;
            }
            if (!names.isEmpty()) {
                names += ", ";
            }
            names += c.getName();
        }
        if (found == null) {
            throw new IllegalArgumentException("Your vespa cluster contains the storage clusters " + names + ", not " + route + ". Please select a valid vespa cluster.");
        }
    } else if (context.getClusterList().getStorageClusters().size() == 1) {
        found = context.getClusterList().getStorageClusters().get(0);
    } else {
        throw new IllegalArgumentException("Multiple content clusters are defined, select one using the \"visit.cluster\" option");
    }
    params.setRoute("[Storage:cluster=" + found.getName() + ";clusterconfigid=" + found.getConfigId() + "]");
    return params;
}
Also used : ClusterDef(com.yahoo.vespaclient.ClusterDef) StaticThrottlePolicy(com.yahoo.messagebus.StaticThrottlePolicy) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor)

Example 2 with ClusterDef

use of com.yahoo.vespaclient.ClusterDef in project vespa by vespa-engine.

the class OperationHandlerImplTest method oneClusterPresentNotMatching.

@Test(expected = RestApiException.class)
public void oneClusterPresentNotMatching() throws RestApiException {
    List<ClusterDef> clusterDef = new ArrayList<>();
    clusterDef.add(new ClusterDef("foo", "configId"));
    OperationHandlerImpl.resolveClusterDef(Optional.of("cluster"), clusterDef);
}
Also used : ClusterDef(com.yahoo.vespaclient.ClusterDef) Test(org.junit.Test)

Example 3 with ClusterDef

use of com.yahoo.vespaclient.ClusterDef in project vespa by vespa-engine.

the class OperationHandlerImplTest method unknown_target_cluster_throws_exception.

@Test()
public void unknown_target_cluster_throws_exception() throws RestApiException, IOException {
    List<ClusterDef> clusterDef = new ArrayList<>();
    clusterDef.add(new ClusterDef("foo2", "configId2"));
    clusterDef.add(new ClusterDef("foo", "configId"));
    clusterDef.add(new ClusterDef("foo3", "configId2"));
    try {
        OperationHandlerImpl.resolveClusterDef(Optional.of("wrong"), clusterDef);
    } catch (RestApiException e) {
        String errorMsg = renderRestApiExceptionAsString(e);
        assertThat(errorMsg, is("{\"errors\":[{\"description\":" + "\"MISSING_CLUSTER Your vespa cluster contains the content clusters foo2 (configId2), foo (configId)," + " foo3 (configId2),  not wrong. Please select a valid vespa cluster.\",\"id\":-9}]}"));
        return;
    }
    fail("Expected exception");
}
Also used : ClusterDef(com.yahoo.vespaclient.ClusterDef) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 4 with ClusterDef

use of com.yahoo.vespaclient.ClusterDef in project vespa by vespa-engine.

the class VespaFeedHandlerTestCase method testRemoveUser.

@Test
public void testRemoveUser() throws Exception {
    setup(null);
    context.getClusterList().getStorageClusters().add(new ClusterDef("storage", "storage/cluster.storage"));
    Result res = testRequest(HttpRequest.createTestRequest("removelocation?user=1234", com.yahoo.jdisc.http.HttpRequest.Method.PUT));
    assertEquals(1, res.messages.size());
    {
        Message m = res.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_REMOVELOCATION, m.getType());
        String selection = ((RemoveLocationMessage) m).getDocumentSelection();
        assertEquals("storage", m.getRoute().toString());
        assertEquals("id.user=1234", selection);
    }
}
Also used : ClusterDef(com.yahoo.vespaclient.ClusterDef) Test(org.junit.Test)

Example 5 with ClusterDef

use of com.yahoo.vespaclient.ClusterDef in project vespa by vespa-engine.

the class VespaFeedHandlerTestCase method testRemoveSelection.

@Test
public void testRemoveSelection() throws Exception {
    setup(null);
    context.getClusterList().getStorageClusters().add(new ClusterDef("storage", "storage/cluster.storage"));
    Result res = testRequest(HttpRequest.createTestRequest("removelocation?selection=id.user=1234", com.yahoo.jdisc.http.HttpRequest.Method.PUT));
    assertEquals(1, res.messages.size());
    {
        Message m = res.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_REMOVELOCATION, m.getType());
        String selection = ((RemoveLocationMessage) m).getDocumentSelection();
        assertEquals("id.user=1234", selection);
    }
}
Also used : ClusterDef(com.yahoo.vespaclient.ClusterDef) Test(org.junit.Test)

Aggregations

ClusterDef (com.yahoo.vespaclient.ClusterDef)19 Test (org.junit.Test)16 ClusterList (com.yahoo.vespaclient.ClusterList)7 ArrayList (java.util.ArrayList)5 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)1 StaticThrottlePolicy (com.yahoo.messagebus.StaticThrottlePolicy)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1