Search in sources :

Example 21 with Inspector

use of com.yahoo.slime.Inspector in project vespa by vespa-engine.

the class ControllerApiHandler method configureUpgrader.

private HttpResponse configureUpgrader(HttpRequest request) {
    String upgradesPerMinuteField = "upgradesPerMinute";
    String confidenceOverrideField = "confidenceOverride";
    byte[] jsonBytes = toJsonBytes(request.getData());
    Inspector inspect = SlimeUtils.jsonToSlime(jsonBytes).get();
    Upgrader upgrader = maintenance.upgrader();
    if (inspect.field(upgradesPerMinuteField).valid()) {
        upgrader.setUpgradesPerMinute(inspect.field(upgradesPerMinuteField).asDouble());
    } else {
        return ErrorResponse.badRequest("No such modifiable field(s)");
    }
    return new UpgraderResponse(maintenance.upgrader());
}
Also used : Upgrader(com.yahoo.vespa.hosted.controller.maintenance.Upgrader) Inspector(com.yahoo.slime.Inspector)

Example 22 with Inspector

use of com.yahoo.slime.Inspector in project vespa by vespa-engine.

the class RPCSendV2 method createReply.

@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
    CompressionType compression = CompressionType.valueOf(ret.get(3).asInt8());
    byte[] slimeBytes = compressor.decompress(ret.get(5).asData(), compression, ret.get(4).asInt32());
    Slime slime = BinaryFormat.decode(slimeBytes);
    Inspector root = slime.get();
    Version version = new Version(root.field(VERSION_F).asString());
    byte[] payload = root.field(BLOB_F).asData();
    // Make sure that the owner understands the protocol.
    Reply reply = null;
    Error error = null;
    if (payload.length > 0) {
        Object retval = decode(new Utf8Array(root.field(PROTOCOL_F).asUtf8()), version, payload);
        if (retval instanceof Reply) {
            reply = (Reply) retval;
        } else {
            error = (Error) retval;
        }
    }
    if (reply == null) {
        reply = new EmptyReply();
    }
    if (error != null) {
        reply.addError(error);
    }
    reply.setRetryDelay(root.field(RETRYDELAY_F).asDouble());
    Inspector errors = root.field(ERRORS_F);
    for (int i = 0; i < errors.entries(); i++) {
        Inspector e = errors.entry(i);
        String service = e.field(SERVICE_F).asString();
        reply.addError(new Error((int) e.field(CODE_F).asLong(), e.field(MSG_F).asString(), (service != null && service.length() > 0) ? service : serviceName));
    }
    if (trace.getLevel() > 0) {
        trace.getRoot().addChild(TraceNode.decode(root.field(TRACE_F).asString()));
    }
    return reply;
}
Also used : Version(com.yahoo.component.Version) Inspector(com.yahoo.slime.Inspector) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) Slime(com.yahoo.slime.Slime) CompressionType(com.yahoo.compress.CompressionType) Utf8Array(com.yahoo.text.Utf8Array) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 23 with Inspector

use of com.yahoo.slime.Inspector in project vespa by vespa-engine.

the class RPCSendV2 method toParams.

protected Params toParams(Values args) {
    CompressionType compression = CompressionType.valueOf(args.get(3).asInt8());
    byte[] slimeBytes = compressor.decompress(args.get(5).asData(), compression, args.get(4).asInt32());
    Slime slime = BinaryFormat.decode(slimeBytes);
    Inspector root = slime.get();
    Params p = new Params();
    p.version = new Version(root.field(VERSION_F).asString());
    p.route = root.field(ROUTE_F).asString();
    p.session = root.field(SESSION_F).asString();
    p.retryEnabled = root.field(USERETRY_F).asBool();
    p.retry = (int) root.field(RETRY_F).asLong();
    p.timeRemaining = root.field(TIMEREMAINING_F).asLong();
    p.protocolName = new Utf8Array(Utf8.toBytes(root.field(PROTOCOL_F).asString()));
    p.payload = root.field(BLOB_F).asData();
    p.traceLevel = (int) root.field(TRACELEVEL_F).asLong();
    return p;
}
Also used : Version(com.yahoo.component.Version) Inspector(com.yahoo.slime.Inspector) Slime(com.yahoo.slime.Slime) CompressionType(com.yahoo.compress.CompressionType) Utf8Array(com.yahoo.text.Utf8Array)

Example 24 with Inspector

use of com.yahoo.slime.Inspector in project vespa by vespa-engine.

the class Maintainer method parseDeleteFilesJob.

private static void parseDeleteFilesJob(Inspector arguments) {
    Path basePath = Paths.get(getFieldOrFail(arguments, "basePath").asString());
    Duration maxAge = Duration.ofSeconds(getFieldOrFail(arguments, "maxAgeSeconds").asLong());
    Optional<String> fileNameRegex = SlimeUtils.optionalString(arguments.field("fileNameRegex"));
    boolean recursive = getFieldOrFail(arguments, "recursive").asBool();
    try {
        FileHelper.deleteFiles(basePath, maxAge, fileNameRegex, recursive);
    } catch (IOException e) {
        throw new RuntimeException("Failed deleting files under " + basePath.toAbsolutePath() + fileNameRegex.map(regex -> ", matching '" + regex + "'").orElse("") + ", " + (recursive ? "" : "not ") + "recursively" + " and older than " + maxAge, e);
    }
}
Also used : Path(java.nio.file.Path) Inspector(com.yahoo.slime.Inspector) ArrayTraverser(com.yahoo.slime.ArrayTraverser) IOException(java.io.IOException) HashMap(java.util.HashMap) RequestConfig(org.apache.http.client.config.RequestConfig) ProcessExecuter(com.yahoo.system.ProcessExecuter) SlimeUtils(com.yahoo.vespa.config.SlimeUtils) HttpClient(org.apache.http.client.HttpClient) Paths(java.nio.file.Paths) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) Optional(java.util.Optional) Type(com.yahoo.slime.Type) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) Path(java.nio.file.Path) LogSetup(com.yahoo.log.LogSetup) Duration(java.time.Duration) IOException(java.io.IOException)

Example 25 with Inspector

use of com.yahoo.slime.Inspector in project vespa by vespa-engine.

the class ApplicationSerializer method changeFromSlime.

private Change changeFromSlime(Inspector object) {
    if (!object.valid())
        return Change.empty();
    Inspector versionFieldValue = object.field(versionField);
    Change change = Change.empty();
    if (versionFieldValue.valid())
        change = Change.of(Version.fromString(versionFieldValue.asString()));
    if (object.field(applicationBuildNumberField).valid())
        change = change.with(applicationVersionFromSlime(object));
    if (// A deploy object with no fields -> unknown application change
    !change.isPresent())
        change = Change.empty();
    return change;
}
Also used : Inspector(com.yahoo.slime.Inspector) Change(com.yahoo.vespa.hosted.controller.application.Change)

Aggregations

Inspector (com.yahoo.slime.Inspector)27 ArrayTraverser (com.yahoo.slime.ArrayTraverser)10 Slime (com.yahoo.slime.Slime)10 IOException (java.io.IOException)6 Cursor (com.yahoo.slime.Cursor)4 SlimeUtils (com.yahoo.vespa.config.SlimeUtils)4 CompressionType (com.yahoo.compress.CompressionType)3 ApplicationId (com.yahoo.config.provision.ApplicationId)3 JsonDecoder (com.yahoo.slime.JsonDecoder)3 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)3 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Version (com.yahoo.component.Version)2 ObjectTraverser (com.yahoo.slime.ObjectTraverser)2 Utf8Array (com.yahoo.text.Utf8Array)2 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)2 Change (com.yahoo.vespa.hosted.controller.application.Change)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2