Search in sources :

Example 86 with Cursor

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

the class ApplicationApiHandler method getGlobalRotationOverride.

private HttpResponse getGlobalRotationOverride(String tenantName, String applicationName, String instanceName, String environment, String region) {
    DeploymentId deploymentId = new DeploymentId(ApplicationId.from(tenantName, applicationName, instanceName), ZoneId.from(environment, region));
    Slime slime = new Slime();
    Cursor c1 = slime.setObject().setArray("globalrotationoverride");
    try {
        Map<String, EndpointStatus> rotations = controller.applications().getGlobalRotationStatus(deploymentId);
        for (String rotation : rotations.keySet()) {
            EndpointStatus currentStatus = rotations.get(rotation);
            c1.addString(rotation);
            Cursor c2 = c1.addObject();
            c2.setString("status", currentStatus.getStatus().name());
            c2.setString("reason", currentStatus.getReason() == null ? "" : currentStatus.getReason());
            c2.setString("agent", currentStatus.getAgent() == null ? "" : currentStatus.getAgent());
            c2.setLong("timestamp", currentStatus.getEpoch());
        }
    } catch (IOException e) {
        return ErrorResponse.internalServerError("Unable to get rotation status: " + e.getMessage());
    }
    return new SlimeJsonResponse(slime);
}
Also used : EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) IOException(java.io.IOException) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 87 with Cursor

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

the class ApplicationApiHandler method athenzDomains.

private HttpResponse athenzDomains(HttpRequest request) {
    Slime slime = new Slime();
    Cursor response = slime.setObject();
    Cursor array = response.setArray("data");
    for (AthenzDomain athenzDomain : controller.getDomainList(request.getProperty("prefix"))) {
        array.addString(athenzDomain.getName());
    }
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) AthenzDomain(com.yahoo.vespa.athenz.api.AthenzDomain) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 88 with Cursor

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

the class ApplicationApiHandler method toSlime.

private Slime toSlime(ActivateResult result) {
    Slime slime = new Slime();
    Cursor object = slime.setObject();
    object.setString("revisionId", result.revisionId().id());
    object.setLong("applicationZipSize", result.applicationZipSizeBytes());
    Cursor logArray = object.setArray("prepareMessages");
    if (result.prepareResponse().log != null) {
        for (Log logMessage : result.prepareResponse().log) {
            Cursor logObject = logArray.addObject();
            logObject.setLong("time", logMessage.time);
            logObject.setString("level", logMessage.level);
            logObject.setString("message", logMessage.message);
        }
    }
    Cursor changeObject = object.setObject("configChangeActions");
    Cursor restartActionsArray = changeObject.setArray("restart");
    for (RestartAction restartAction : result.prepareResponse().configChangeActions.restartActions) {
        Cursor restartActionObject = restartActionsArray.addObject();
        restartActionObject.setString("clusterName", restartAction.clusterName);
        restartActionObject.setString("clusterType", restartAction.clusterType);
        restartActionObject.setString("serviceType", restartAction.serviceType);
        serviceInfosToSlime(restartAction.services, restartActionObject.setArray("services"));
        stringsToSlime(restartAction.messages, restartActionObject.setArray("messages"));
    }
    Cursor refeedActionsArray = changeObject.setArray("refeed");
    for (RefeedAction refeedAction : result.prepareResponse().configChangeActions.refeedActions) {
        Cursor refeedActionObject = refeedActionsArray.addObject();
        refeedActionObject.setString("name", refeedAction.name);
        refeedActionObject.setBool("allowed", refeedAction.allowed);
        refeedActionObject.setString("documentType", refeedAction.documentType);
        refeedActionObject.setString("clusterName", refeedAction.clusterName);
        serviceInfosToSlime(refeedAction.services, refeedActionObject.setArray("services"));
        stringsToSlime(refeedAction.messages, refeedActionObject.setArray("messages"));
    }
    return slime;
}
Also used : Log(com.yahoo.vespa.hosted.controller.api.integration.configserver.Log) RestartAction(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RestartAction) RefeedAction(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RefeedAction) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 89 with Cursor

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

the class ApplicationApiHandler method setRotationStatus.

private void setRotationStatus(Deployment deployment, Map<String, RotationStatus> healthStatus, Cursor object) {
    if (!deployment.zone().environment().equals(Environment.prod))
        return;
    Cursor bcpStatusObject = object.setObject("bcpStatus");
    bcpStatusObject.setString("rotationStatus", findRotationStatus(deployment, healthStatus).name());
}
Also used : Cursor(com.yahoo.slime.Cursor)

Example 90 with Cursor

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

the class ApplicationApiHandler method toSlime.

private void toSlime(Cursor response, DeploymentId deploymentId, Deployment deployment, HttpRequest request) {
    Cursor serviceUrlArray = response.setArray("serviceUrls");
    controller.applications().getDeploymentEndpoints(deploymentId).ifPresent(endpoints -> endpoints.forEach(endpoint -> serviceUrlArray.addString(endpoint.toString())));
    response.setString("nodes", withPath("/zone/v2/" + deploymentId.zoneId().environment() + "/" + deploymentId.zoneId().region() + "/nodes/v2/node/?&recursive=true&application=" + deploymentId.applicationId().tenant() + "." + deploymentId.applicationId().application() + "." + deploymentId.applicationId().instance(), request.getUri()).toString());
    controller.zoneRegistry().getLogServerUri(deploymentId).ifPresent(elkUrl -> response.setString("elkUrl", elkUrl.toString()));
    response.setString("yamasUrl", monitoringSystemUri(deploymentId).toString());
    response.setString("version", deployment.version().toFullString());
    response.setString("revision", deployment.applicationVersion().id());
    response.setLong("deployTimeEpochMs", deployment.at().toEpochMilli());
    controller.zoneRegistry().getDeploymentTimeToLive(deploymentId.zoneId()).ifPresent(deploymentTimeToLive -> response.setLong("expiryTimeEpochMs", deployment.at().plus(deploymentTimeToLive).toEpochMilli()));
    controller.applications().get(deploymentId.applicationId()).flatMap(application -> application.deploymentJobs().projectId()).ifPresent(i -> response.setString("screwdriverId", String.valueOf(i)));
    sourceRevisionToSlime(deployment.applicationVersion().source(), response);
    // Cost
    DeploymentCost appCost = deployment.calculateCost();
    Cursor costObject = response.setObject("cost");
    toSlime(appCost, costObject);
    // Metrics
    DeploymentMetrics metrics = deployment.metrics();
    Cursor metricsObject = response.setObject("metrics");
    metricsObject.setDouble("queriesPerSecond", metrics.queriesPerSecond());
    metricsObject.setDouble("writesPerSecond", metrics.writesPerSecond());
    metricsObject.setDouble("documentCount", metrics.documentCount());
    metricsObject.setDouble("queryLatencyMillis", metrics.queryLatencyMillis());
    metricsObject.setDouble("writeLatencyMillis", metrics.writeLatencyMillis());
}
Also used : AlreadyExistsException(com.yahoo.vespa.hosted.controller.AlreadyExistsException) EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) Inject(com.google.inject.Inject) URISyntaxException(java.net.URISyntaxException) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) Scanner(java.util.Scanner) DeploymentJobs(com.yahoo.vespa.hosted.controller.application.DeploymentJobs) ConfigServerException(com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException) RegionName(com.yahoo.config.provision.RegionName) TenantName(com.yahoo.config.provision.TenantName) ResourceResponse(com.yahoo.vespa.hosted.controller.restapi.ResourceResponse) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) ClusterUtilization(com.yahoo.vespa.hosted.controller.application.ClusterUtilization) Duration(java.time.Duration) Map(java.util.Map) LogLevel(com.yahoo.log.LogLevel) Path(com.yahoo.vespa.hosted.controller.restapi.Path) JobStatus(com.yahoo.vespa.hosted.controller.application.JobStatus) GitRevision(com.yahoo.vespa.hosted.controller.api.application.v4.model.GitRevision) ClusterCost(com.yahoo.vespa.hosted.controller.application.ClusterCost) BadRequestException(javax.ws.rs.BadRequestException) DeployOptions(com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions) URI(java.net.URI) DeploymentCost(com.yahoo.vespa.hosted.controller.application.DeploymentCost) ScrewdriverBuildJob(com.yahoo.vespa.hosted.controller.api.application.v4.model.ScrewdriverBuildJob) Exceptions(com.yahoo.yolean.Exceptions) AthenzDomain(com.yahoo.vespa.athenz.api.AthenzDomain) ImmutableSet(com.google.common.collect.ImmutableSet) Inspector(com.yahoo.slime.Inspector) NotExistsException(com.yahoo.vespa.hosted.controller.NotExistsException) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) ErrorResponse(com.yahoo.vespa.hosted.controller.restapi.ErrorResponse) RestartAction(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RestartAction) Property(com.yahoo.vespa.hosted.controller.api.identifiers.Property) ApplicationView(com.yahoo.vespa.serviceview.bindings.ApplicationView) Objects(java.util.Objects) ZmsException(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException) List(java.util.List) Principal(java.security.Principal) AthenzPrincipal(com.yahoo.vespa.athenz.api.AthenzPrincipal) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Optional(java.util.Optional) Deployment(com.yahoo.vespa.hosted.controller.application.Deployment) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Controller(com.yahoo.vespa.hosted.controller.Controller) Joiner(com.google.common.base.Joiner) Log(com.yahoo.vespa.hosted.controller.api.integration.configserver.Log) AthenzClientFactory(com.yahoo.vespa.hosted.controller.api.integration.athenz.AthenzClientFactory) GitRepository(com.yahoo.vespa.hosted.controller.api.identifiers.GitRepository) ApplicationName(com.yahoo.config.provision.ApplicationName) AthenzUser(com.yahoo.vespa.athenz.api.AthenzUser) Version(com.yahoo.component.Version) ApplicationId(com.yahoo.config.provision.ApplicationId) PropertyId(com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId) RefeedAction(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RefeedAction) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) Slime(com.yahoo.slime.Slime) AthenzIdentity(com.yahoo.vespa.athenz.api.AthenzIdentity) IOUtils(com.yahoo.io.IOUtils) NToken(com.yahoo.vespa.athenz.api.NToken) Level(java.util.logging.Level) DeploymentMetrics(com.yahoo.vespa.hosted.controller.application.DeploymentMetrics) ApplicationResource(com.yahoo.vespa.hosted.controller.api.application.v4.ApplicationResource) SlimeUtils(com.yahoo.vespa.config.SlimeUtils) Change(com.yahoo.vespa.hosted.controller.application.Change) TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) GitBranch(com.yahoo.vespa.hosted.controller.api.identifiers.GitBranch) ServiceInfo(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.ServiceInfo) SetBouncerPassthruHeaderFilter(com.yahoo.vespa.hosted.controller.restapi.filter.SetBouncerPassthruHeaderFilter) EnvironmentResource(com.yahoo.vespa.hosted.controller.api.application.v4.EnvironmentResource) TenantResource(com.yahoo.vespa.hosted.controller.api.application.v4.TenantResource) Application(com.yahoo.vespa.hosted.controller.Application) ActivateResult(com.yahoo.vespa.hosted.controller.api.ActivateResult) Cursor(com.yahoo.slime.Cursor) StringResponse(com.yahoo.vespa.hosted.controller.restapi.StringResponse) ForbiddenException(javax.ws.rs.ForbiddenException) Hostname(com.yahoo.vespa.hosted.controller.api.identifiers.Hostname) Environment(com.yahoo.config.provision.Environment) GitCommit(com.yahoo.vespa.hosted.controller.api.identifiers.GitCommit) HttpRequest(com.yahoo.container.jdisc.HttpRequest) SourceRevision(com.yahoo.vespa.hosted.controller.application.SourceRevision) IOException(java.io.IOException) MessageResponse(com.yahoo.vespa.hosted.controller.restapi.MessageResponse) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) LoggingRequestHandler(com.yahoo.container.jdisc.LoggingRequestHandler) User(com.yahoo.vespa.hosted.controller.api.integration.organization.User) UserId(com.yahoo.vespa.hosted.controller.api.identifiers.UserId) RotationStatus(com.yahoo.vespa.hosted.controller.api.integration.routing.RotationStatus) DeploymentSpec(com.yahoo.config.application.api.DeploymentSpec) DayOfWeek(java.time.DayOfWeek) ScrewdriverId(com.yahoo.vespa.hosted.controller.api.identifiers.ScrewdriverId) Collections(java.util.Collections) InputStream(java.io.InputStream) DeploymentMetrics(com.yahoo.vespa.hosted.controller.application.DeploymentMetrics) Cursor(com.yahoo.slime.Cursor) DeploymentCost(com.yahoo.vespa.hosted.controller.application.DeploymentCost)

Aggregations

Cursor (com.yahoo.slime.Cursor)112 Slime (com.yahoo.slime.Slime)79 Test (org.junit.Test)33 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 DefParser (com.yahoo.config.codegen.DefParser)15 InnerCNode (com.yahoo.config.codegen.InnerCNode)15 StringReader (java.io.StringReader)15 IOException (java.io.IOException)9 ApplicationId (com.yahoo.config.provision.ApplicationId)8 JsonFormat (com.yahoo.slime.JsonFormat)8 Application (com.yahoo.vespa.hosted.controller.Application)6 List (java.util.List)6 Map (java.util.Map)6 Inspector (com.yahoo.slime.Inspector)5 SlimeUtils (com.yahoo.vespa.config.SlimeUtils)5 Ignore (org.junit.Ignore)5 Version (com.yahoo.component.Version)4 RegionName (com.yahoo.config.provision.RegionName)4 TenantName (com.yahoo.config.provision.TenantName)4