Search in sources :

Example 21 with StringValue

use of com.yahoo.jrt.StringValue in project vespa by vespa-engine.

the class FileServer method serveFile.

private void serveFile(String fileReference, Request request, Receiver receiver) {
    FileApiErrorCodes result;
    try {
        log.log(LogLevel.DEBUG, () -> "Received request for reference '" + fileReference + "' from " + request.target());
        result = hasFile(fileReference) ? FileApiErrorCodes.OK : FileApiErrorCodes.NOT_FOUND;
        if (result == FileApiErrorCodes.OK) {
            startFileServing(fileReference, receiver);
        } else {
            // This is to avoid config servers asking each other for a file that does not exist
            if (request.parameters().size() == 1 || request.parameters().get(1).asInt32() == 0) {
                log.log(LogLevel.DEBUG, "File not found, downloading from another source");
                downloader.getFile(new FileReferenceDownload(new FileReference(fileReference), false));
            } else {
                log.log(LogLevel.DEBUG, "File not found, will not download from another source since request came from another config server");
                result = FileApiErrorCodes.NOT_FOUND;
            }
        }
    } catch (IllegalArgumentException e) {
        result = FileApiErrorCodes.NOT_FOUND;
        log.warning("Failed serving file reference '" + fileReference + "', request was from " + request.target() + ", with error " + e.toString());
    }
    request.returnValues().add(new Int32Value(result.getCode())).add(new StringValue(result.getDescription()));
    request.returnRequest();
}
Also used : FileReferenceDownload(com.yahoo.vespa.filedistribution.FileReferenceDownload) Int32Value(com.yahoo.jrt.Int32Value) FileReference(com.yahoo.config.FileReference) CompressedFileReference(com.yahoo.vespa.filedistribution.CompressedFileReference) StringValue(com.yahoo.jrt.StringValue)

Example 22 with StringValue

use of com.yahoo.jrt.StringValue in project vespa by vespa-engine.

the class OutputSearchChain method invoke.

public void invoke(Request request) {
    try {
        SearchHandler searchHandler = SearcherUtils.getSearchHandler();
        SearchChainRegistry searchChainRegistry = searchHandler.getSearchChainRegistry();
        SearchChain searchChain = getSearchChain(searchChainRegistry, getSearchChainName(request));
        SearchChainTextRepresentation textRepresentation = new SearchChainTextRepresentation(searchChain, searchChainRegistry);
        request.returnValues().add(new StringValue(textRepresentation.toString()));
    } catch (Exception e) {
        request.setError(1000, Exceptions.toMessageString(e));
    }
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) SearchChain(com.yahoo.search.searchchain.SearchChain) StringValue(com.yahoo.jrt.StringValue)

Example 23 with StringValue

use of com.yahoo.jrt.StringValue in project vespa by vespa-engine.

the class Register method handleUpdate.

/**
 * Invoked by the update task.
 */
private void handleUpdate() {
    if (reqDone) {
        reqDone = false;
        boolean logOnSuccess = false;
        synchronized (this) {
            if (req.methodName().equals(UNREGISTER_METHOD_NAME)) {
                logOnSuccess = true;
                // Why is this remove() here and not in unregisterName? Because at that time there may be
                // an in-flight request for the registration of name, and in case handleUpdate() would
                // anyway have to have special code for handling a removed name, e.g. testing for name
                // being in names which is O(N).
                lastRegisterSucceeded.remove(name);
            } else {
                final Boolean lastSucceeded = lastRegisterSucceeded.get(name);
                if (lastSucceeded == null || lastSucceeded != !req.isError()) {
                    logOnSuccess = true;
                    lastRegisterSucceeded.put(name, !req.isError());
                }
            }
        }
        if (req.isError()) {
            if (req.errorCode() != ErrorCode.METHOD_FAILED) {
                log.log(Level.INFO, logMessagePrefix() + " failed, will disconnect: " + req.errorMessage() + " (code " + req.errorCode() + ")");
                target.close();
                target = null;
            } else {
                log.log(Level.WARNING, logMessagePrefix() + " failed: " + req.errorMessage());
            }
        } else {
            log.log(logOnSuccess ? Level.INFO : Level.FINE, logMessagePrefix() + " completed successfully");
            backOff.reset();
        }
        req = null;
        name = null;
    }
    if (req != null) {
        log.log(Level.FINEST, "req in progress");
        // current request still in progress
        return;
    }
    if (target != null && !slobroks.contains(currSlobrok)) {
        log.log(Level.INFO, "RPC server " + mySpec + ": Slobrok server " + currSlobrok + " removed, will disconnect");
        target.close();
        target = null;
    }
    if (target == null) {
        currSlobrok = slobroks.nextSlobrokSpec();
        if (currSlobrok == null) {
            double delay = backOff.get();
            Level level = backOff.shouldWarn(delay) ? Level.WARNING : Level.FINE;
            log.log(level, "RPC server " + mySpec + ": All Slobrok servers tried, will retry in " + delay + " seconds: " + slobroks);
            updateTask.schedule(delay);
            return;
        }
        lastRegisterSucceeded.clear();
        target = orb.connect(new Spec(currSlobrok));
        String namesString = null;
        final boolean logFine = log.isLoggable(Level.FINE);
        synchronized (this) {
            if (logFine) {
                // 'names' must only be accessed in a synchronized(this) block
                namesString = names.toString();
            }
            pending.clear();
            pending.addAll(names);
        }
        if (logFine) {
            log.log(Level.FINE, "RPC server " + mySpec + ": Connect to Slobrok server " + currSlobrok + " and reregister all Slobrok names: " + namesString);
        }
    }
    synchronized (this) {
        if (unreg.size() > 0) {
            name = unreg.remove(unreg.size() - 1);
            req = new Request(UNREGISTER_METHOD_NAME);
        } else if (pending.size() > 0) {
            name = pending.remove(pending.size() - 1);
            req = new Request(REGISTER_METHOD_NAME);
        } else {
            pending.addAll(names);
            log.log(Level.FINE, "RPC server " + mySpec + ": Reregister all Slobrok names in 30 seconds: " + names);
            updateTask.schedule(30.0);
            return;
        }
    }
    req.parameters().add(new StringValue(name));
    req.parameters().add(new StringValue(mySpec));
    log.log(Level.FINE, logMessagePrefix() + " now");
    target.invokeAsync(req, 35.0, reqWait);
}
Also used : Request(com.yahoo.jrt.Request) Level(java.util.logging.Level) Spec(com.yahoo.jrt.Spec) StringValue(com.yahoo.jrt.StringValue)

Example 24 with StringValue

use of com.yahoo.jrt.StringValue in project vespa by vespa-engine.

the class RPCSendV1 method createResponse.

@Override
protected void createResponse(Values ret, Reply reply, Version version, byte[] payload) {
    int[] eCodes = new int[reply.getNumErrors()];
    String[] eMessages = new String[reply.getNumErrors()];
    String[] eServices = new String[reply.getNumErrors()];
    for (int i = 0; i < reply.getNumErrors(); ++i) {
        Error error = reply.getError(i);
        eCodes[i] = error.getCode();
        eMessages[i] = error.getMessage();
        eServices[i] = error.getService() != null ? error.getService() : "";
    }
    ret.add(new StringValue(version.toString()));
    ret.add(new DoubleValue(reply.getRetryDelay()));
    ret.add(new Int32Array(eCodes));
    ret.add(new StringArray(eMessages));
    ret.add(new StringArray(eServices));
    ret.add(new StringValue(reply.getProtocol()));
    ret.add(new DataValue(payload));
    ret.add(new StringValue(reply.getTrace().getRoot() != null ? reply.getTrace().getRoot().encode() : ""));
}
Also used : Int32Array(com.yahoo.jrt.Int32Array) StringArray(com.yahoo.jrt.StringArray) DoubleValue(com.yahoo.jrt.DoubleValue) DataValue(com.yahoo.jrt.DataValue) Error(com.yahoo.messagebus.Error) StringValue(com.yahoo.jrt.StringValue)

Aggregations

StringValue (com.yahoo.jrt.StringValue)24 Request (com.yahoo.jrt.Request)14 Spec (com.yahoo.jrt.Spec)8 Supervisor (com.yahoo.jrt.Supervisor)7 Target (com.yahoo.jrt.Target)7 Transport (com.yahoo.jrt.Transport)7 Test (org.junit.Test)7 Int32Value (com.yahoo.jrt.Int32Value)5 NodeState (com.yahoo.vdslib.state.NodeState)4 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)3 Node (com.yahoo.vdslib.state.Node)3 UnknownHostException (java.net.UnknownHostException)3 FileReference (com.yahoo.config.FileReference)2 DataValue (com.yahoo.jrt.DataValue)2 ListenFailedException (com.yahoo.jrt.ListenFailedException)2 StringArray (com.yahoo.jrt.StringArray)2 Distribution (com.yahoo.vdslib.distribution.Distribution)2 TreeSet (java.util.TreeSet)2 DoubleValue (com.yahoo.jrt.DoubleValue)1 Int32Array (com.yahoo.jrt.Int32Array)1