Search in sources :

Example 11 with Inspector

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

the class ApplicationSerializer method fromSlime.

// ------------------ Deserialization
public Application fromSlime(Slime slime) {
    Inspector root = slime.get();
    ApplicationId id = ApplicationId.fromSerializedForm(root.field(idField).asString());
    DeploymentSpec deploymentSpec = DeploymentSpec.fromXml(root.field(deploymentSpecField).asString(), false);
    ValidationOverrides validationOverrides = ValidationOverrides.fromXml(root.field(validationOverridesField).asString());
    List<Deployment> deployments = deploymentsFromSlime(root.field(deploymentsField));
    DeploymentJobs deploymentJobs = deploymentJobsFromSlime(root.field(deploymentJobsField));
    Change deploying = changeFromSlime(root.field(deployingField));
    Change outstandingChange = changeFromSlime(root.field(outstandingChangeField));
    Optional<IssueId> ownershipIssueId = optionalString(root.field(ownershipIssueIdField)).map(IssueId::from);
    ApplicationMetrics metrics = new ApplicationMetrics(root.field(queryQualityField).asDouble(), root.field(writeQualityField).asDouble());
    Optional<RotationId> rotation = rotationFromSlime(root.field(rotationField));
    return new Application(id, deploymentSpec, validationOverrides, deployments, deploymentJobs, deploying, outstandingChange, ownershipIssueId, metrics, rotation);
}
Also used : Deployment(com.yahoo.vespa.hosted.controller.application.Deployment) Change(com.yahoo.vespa.hosted.controller.application.Change) DeploymentSpec(com.yahoo.config.application.api.DeploymentSpec) DeploymentJobs(com.yahoo.vespa.hosted.controller.application.DeploymentJobs) Inspector(com.yahoo.slime.Inspector) IssueId(com.yahoo.vespa.hosted.controller.api.integration.organization.IssueId) ApplicationId(com.yahoo.config.provision.ApplicationId) ValidationOverrides(com.yahoo.config.application.api.ValidationOverrides) ApplicationMetrics(com.yahoo.vespa.hosted.controller.api.integration.MetricsService.ApplicationMetrics) RotationId(com.yahoo.vespa.hosted.controller.rotation.RotationId) Application(com.yahoo.vespa.hosted.controller.Application)

Example 12 with Inspector

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

the class ApplicationApiHandler method deploy.

private HttpResponse deploy(String tenantName, String applicationName, String instanceName, String environment, String region, HttpRequest request) {
    ApplicationId applicationId = ApplicationId.from(tenantName, applicationName, instanceName);
    ZoneId zone = ZoneId.from(environment, region);
    Map<String, byte[]> dataParts = new MultipartParser().parse(request);
    if (!dataParts.containsKey("deployOptions"))
        return ErrorResponse.badRequest("Missing required form part 'deployOptions'");
    Inspector deployOptions = SlimeUtils.jsonToSlime(dataParts.get("deployOptions")).get();
    Optional<ApplicationPackage> applicationPackage = Optional.ofNullable(dataParts.get("applicationZip")).map(ApplicationPackage::new);
    verifyApplicationIdentityConfiguration(tenantName, applicationPackage);
    // TODO: get rid of the json object
    DeployOptions deployOptionsJsonClass = new DeployOptions(screwdriverBuildJobFromSlime(deployOptions.field("screwdriverBuildJob")), optional("vespaVersion", deployOptions).map(Version::new), deployOptions.field("ignoreValidationErrors").asBool(), deployOptions.field("deployCurrentVersion").asBool());
    ActivateResult result = controller.applications().deployApplication(applicationId, zone, applicationPackage, deployOptionsJsonClass);
    return new SlimeJsonResponse(toSlime(result));
}
Also used : DeployOptions(com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions) ActivateResult(com.yahoo.vespa.hosted.controller.api.ActivateResult) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) Inspector(com.yahoo.slime.Inspector) ApplicationId(com.yahoo.config.provision.ApplicationId) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage)

Example 13 with Inspector

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

the class JobQueueSerializer method fromJson.

public Deque<ApplicationId> fromJson(byte[] data) {
    Inspector inspector = SlimeUtils.jsonToSlime(data).get();
    Deque<ApplicationId> queue = new ArrayDeque<>();
    inspector.traverse((ArrayTraverser) (index, value) -> queue.addLast(ApplicationId.fromSerializedForm(value.asString())));
    return queue;
}
Also used : HashSet(java.util.HashSet) Cursor(com.yahoo.slime.Cursor) List(java.util.List) Inspector(com.yahoo.slime.Inspector) ApplicationId(com.yahoo.config.provision.ApplicationId) SlimeUtils(com.yahoo.vespa.config.SlimeUtils) ArrayTraverser(com.yahoo.slime.ArrayTraverser) Slime(com.yahoo.slime.Slime) Set(java.util.Set) IOException(java.io.IOException) ArrayDeque(java.util.ArrayDeque) Deque(java.util.Deque) Inspector(com.yahoo.slime.Inspector) ApplicationId(com.yahoo.config.provision.ApplicationId) ArrayDeque(java.util.ArrayDeque)

Example 14 with Inspector

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

the class StringSetSerializer method fromJson.

public Set<String> fromJson(byte[] data) {
    Inspector inspector = SlimeUtils.jsonToSlime(data).get();
    Set<String> stringSet = new HashSet<>();
    inspector.traverse((ArrayTraverser) (index, name) -> stringSet.add(name.asString()));
    return stringSet;
}
Also used : HashSet(java.util.HashSet) Cursor(com.yahoo.slime.Cursor) Inspector(com.yahoo.slime.Inspector) SlimeUtils(com.yahoo.vespa.config.SlimeUtils) ArrayTraverser(com.yahoo.slime.ArrayTraverser) Slime(com.yahoo.slime.Slime) Set(java.util.Set) IOException(java.io.IOException) Inspector(com.yahoo.slime.Inspector) HashSet(java.util.HashSet)

Example 15 with Inspector

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

the class Maintainer method main.

public static void main(String[] args) {
    LogSetup.initVespaLogging("node-maintainer");
    if (args.length != 1) {
        throw new RuntimeException("Expected only 1 argument - a JSON list of maintainer jobs to execute");
    }
    Inspector object = SlimeUtils.jsonToSlime(args[0].getBytes()).get();
    if (object.type() != Type.ARRAY) {
        throw new IllegalArgumentException("Expected a list of maintainer jobs to execute");
    }
    // Variable must be effectively final to be used in lambda expression
    AtomicInteger numberOfJobsFailed = new AtomicInteger(0);
    object.traverse((ArrayTraverser) (int i, Inspector item) -> {
        try {
            String type = getFieldOrFail(item, "type").asString();
            Inspector arguments = getFieldOrFail(item, "arguments");
            parseMaintenanceJob(type, arguments);
        } catch (Exception e) {
            System.err.println("Failed executing job: " + item.toString());
            e.printStackTrace();
            numberOfJobsFailed.incrementAndGet();
        }
    });
    if (numberOfJobsFailed.get() > 0) {
        System.err.println(numberOfJobsFailed.get() + " of jobs has failed");
        System.exit(1);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Inspector(com.yahoo.slime.Inspector) IOException(java.io.IOException)

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