Search in sources :

Example 1 with Tuple2

use of com.yahoo.collections.Tuple2 in project vespa by vespa-engine.

the class ApplicationPackageXmlFilesValidator method validateRouting.

private void validateRouting(SchemaValidator validator, Tuple2<File, String> directory) throws IOException {
    File dir = directory.first;
    if (!dir.isDirectory())
        return;
    String directoryName = directory.second;
    for (File f : dir.listFiles(xmlFilter)) {
        if (f.isDirectory())
            validateRouting(validator, new Tuple2<>(f, directoryName + File.separator + f.getName()));
        else
            validator.validate(f, directoryName + File.separator + f.getName());
    }
}
Also used : Tuple2(com.yahoo.collections.Tuple2) File(java.io.File)

Example 2 with Tuple2

use of com.yahoo.collections.Tuple2 in project vespa by vespa-engine.

the class Feeder method newRemoveMessage.

private Tuple2<String, Message> newRemoveMessage(Operation op, String operationId) {
    DocumentRemove remove = new DocumentRemove(op.getRemove());
    remove.setCondition(op.getCondition());
    Message msg = new RemoveDocumentMessage(remove);
    String id = (operationId == null) ? remove.getId().toString() : operationId;
    return new Tuple2<>(id, msg);
}
Also used : RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) DocumentRemove(com.yahoo.document.DocumentRemove) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) Tuple2(com.yahoo.collections.Tuple2) Utf8String(com.yahoo.text.Utf8String)

Example 3 with Tuple2

use of com.yahoo.collections.Tuple2 in project vespa by vespa-engine.

the class JsonReaderTestCase method testArithmeticOperators.

@SuppressWarnings({ "cast", "unchecked", "rawtypes" })
@Test
public final void testArithmeticOperators() throws IOException {
    Tuple2[] operations = new Tuple2[] { new Tuple2<String, Operator>(UPDATE_DECREMENT, ArithmeticValueUpdate.Operator.SUB), new Tuple2<String, Operator>(UPDATE_DIVIDE, ArithmeticValueUpdate.Operator.DIV), new Tuple2<String, Operator>(UPDATE_INCREMENT, ArithmeticValueUpdate.Operator.ADD), new Tuple2<String, Operator>(UPDATE_MULTIPLY, ArithmeticValueUpdate.Operator.MUL) };
    for (Tuple2<String, Operator> operator : operations) {
        DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testset::whee\"," + " \"fields\": { " + "\"actualset\": {" + " \"match\": {" + " \"element\": \"person\"," + " \"" + (String) operator.first + "\": 13}}}}");
        Map<String, Tuple2<Number, Operator>> matches = new HashMap<>();
        FieldUpdate x = doc.getFieldUpdate("actualset");
        for (ValueUpdate v : x.getValueUpdates()) {
            MapValueUpdate adder = (MapValueUpdate) v;
            final String key = ((StringFieldValue) adder.getValue()).getString();
            Operator op = ((ArithmeticValueUpdate) adder.getUpdate()).getOperator();
            Number n = ((ArithmeticValueUpdate) adder.getUpdate()).getOperand();
            matches.put(key, new Tuple2<>(n, op));
        }
        assertEquals(1, matches.size());
        final String o = "person";
        assertSame(operator.second, matches.get(o).second);
        assertEquals(Double.valueOf(13), matches.get(o).first);
    }
}
Also used : Operator(com.yahoo.document.update.ArithmeticValueUpdate.Operator) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) HashMap(java.util.HashMap) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) ClearValueUpdate(com.yahoo.document.update.ClearValueUpdate) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Tuple2(com.yahoo.collections.Tuple2) FieldUpdate(com.yahoo.document.update.FieldUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) Test(org.junit.Test)

Example 4 with Tuple2

use of com.yahoo.collections.Tuple2 in project vespa by vespa-engine.

the class LoadTester method readDefs.

private Map<ConfigDefinitionKey, Tuple2<String, String[]>> readDefs(String defPath) throws IOException {
    Map<ConfigDefinitionKey, Tuple2<String, String[]>> ret = new HashMap<>();
    if (defPath == null)
        return ret;
    File defDir = new File(defPath);
    if (!defDir.isDirectory()) {
        System.out.println("# Given def file dir is not a directory: " + defDir.getPath() + " , will not send def contents in requests.");
        return ret;
    }
    final File[] files = defDir.listFiles();
    if (files == null) {
        System.out.println("# Given def file dir has no files: " + defDir.getPath() + " , will not send def contents in requests.");
        return ret;
    }
    for (File f : files) {
        String name = f.getName();
        if (!name.endsWith(".def"))
            continue;
        String[] splitted = name.split("\\.");
        if (splitted.length < 2)
            continue;
        String nam = splitted[splitted.length - 2];
        String contents = IOUtils.readFile(f);
        ConfigDefinitionKey key = ConfigUtils.createConfigDefinitionKeyFromDefContent(nam, Utf8.toBytes(contents));
        ret.put(key, new Tuple2<>(ConfigUtils.getDefMd5(Arrays.asList(contents.split("\n"))), contents.split("\n")));
    }
    System.out.println("#  Read " + ret.size() + " def files from " + defDir.getPath());
    return ret;
}
Also used : Tuple2(com.yahoo.collections.Tuple2) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey)

Example 5 with Tuple2

use of com.yahoo.collections.Tuple2 in project vespa by vespa-engine.

the class Feeder method newErrorMessage.

private Tuple2<String, Message> newErrorMessage(String operationId, Exception e) {
    Message m = new FeedErrorMessage(operationId);
    Tuple2<String, Message> msg = new Tuple2<>(operationId, m);
    Hop hop = new Hop();
    hop.addDirective(new ErrorDirective(Exceptions.toMessageString(e)));
    Route route = new Route();
    route.addHop(hop);
    m.setRoute(route);
    return msg;
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) Tuple2(com.yahoo.collections.Tuple2) Hop(com.yahoo.messagebus.routing.Hop) Utf8String(com.yahoo.text.Utf8String) ErrorDirective(com.yahoo.messagebus.routing.ErrorDirective) Route(com.yahoo.messagebus.routing.Route)

Aggregations

Tuple2 (com.yahoo.collections.Tuple2)11 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)4 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)4 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)4 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)4 Message (com.yahoo.messagebus.Message)4 Utf8String (com.yahoo.text.Utf8String)4 DocumentUpdate (com.yahoo.document.DocumentUpdate)3 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)3 Test (org.junit.Test)3 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)2 FieldUpdate (com.yahoo.document.update.FieldUpdate)2 MapValueUpdate (com.yahoo.document.update.MapValueUpdate)2 ArrayList (java.util.ArrayList)2 Version (com.yahoo.component.Version)1 CompressionType (com.yahoo.compress.CompressionType)1 Call (com.yahoo.docproc.Call)1 CallStack (com.yahoo.docproc.CallStack)1 DocumentProcessor (com.yahoo.docproc.DocumentProcessor)1 HandledProcessingException (com.yahoo.docproc.HandledProcessingException)1