Search in sources :

Example 1 with Uri

use of com.yahoo.vespa.hosted.controller.restapi.Uri in project vespa by vespa-engine.

the class DeploymentApiHandler method toSlime.

private void toSlime(Cursor object, Application application, HttpRequest request) {
    object.setString("tenant", application.id().tenant().value());
    object.setString("application", application.id().application().value());
    object.setString("instance", application.id().instance().value());
    object.setString("url", new Uri(request.getUri()).withPath("/application/v4/tenant/" + application.id().tenant().value() + "/application/" + application.id().application().value()).toString());
    object.setString("upgradePolicy", toString(application.deploymentSpec().upgradePolicy()));
}
Also used : Uri(com.yahoo.vespa.hosted.controller.restapi.Uri)

Example 2 with Uri

use of com.yahoo.vespa.hosted.controller.restapi.Uri in project vespa by vespa-engine.

the class ServiceApiResponse method rewriteIfUrl.

private String rewriteIfUrl(String urlOrAnyString, Uri requestUri) {
    if (urlOrAnyString == null)
        return null;
    String hostPattern = "(" + String.join("|", configServerURIs.stream().map(URI::toString).map(s -> s.substring(0, s.length() - 1)).map(Pattern::quote).toArray(String[]::new)) + ")";
    String remoteServicePath = "/serviceview/" + "v1/tenant/" + application.tenant().value() + "/application/" + application.application().value() + "/environment/" + zone.environment().value() + "/region/" + zone.region().value() + "/instance/" + application.instance() + "/service/";
    Pattern remoteServiceResourcePattern = Pattern.compile("^(" + hostPattern + Pattern.quote(remoteServicePath) + ")");
    Matcher matcher = remoteServiceResourcePattern.matcher(urlOrAnyString);
    if (matcher.find()) {
        String proxiedPath = urlOrAnyString.substring(matcher.group().length());
        return requestUri.append(proxiedPath).toString();
    } else {
        // not a service url
        return urlOrAnyString;
    }
}
Also used : OutputStream(java.io.OutputStream) Cursor(com.yahoo.slime.Cursor) ApplicationId(com.yahoo.config.provision.ApplicationId) Slime(com.yahoo.slime.Slime) IOException(java.io.IOException) ApplicationView(com.yahoo.vespa.serviceview.bindings.ApplicationView) List(java.util.List) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) Matcher(java.util.regex.Matcher) ServiceView(com.yahoo.vespa.serviceview.bindings.ServiceView) JsonFormat(com.yahoo.slime.JsonFormat) Uri(com.yahoo.vespa.hosted.controller.restapi.Uri) Map(java.util.Map) ClusterView(com.yahoo.vespa.serviceview.bindings.ClusterView) URI(java.net.URI) Pattern(java.util.regex.Pattern) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) URI(java.net.URI)

Aggregations

Uri (com.yahoo.vespa.hosted.controller.restapi.Uri)2 ApplicationId (com.yahoo.config.provision.ApplicationId)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 Cursor (com.yahoo.slime.Cursor)1 JsonFormat (com.yahoo.slime.JsonFormat)1 Slime (com.yahoo.slime.Slime)1 ZoneId (com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId)1 ApplicationView (com.yahoo.vespa.serviceview.bindings.ApplicationView)1 ClusterView (com.yahoo.vespa.serviceview.bindings.ClusterView)1 ServiceView (com.yahoo.vespa.serviceview.bindings.ServiceView)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 List (java.util.List)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1