Search in sources :

Example 1 with Route

use of com.google.cloud.compute.v1.Route in project GreenHouse by utsanjan.

the class StreamAllocation method findConnection.

private RealConnection findConnection(int connectTimeout, int readTimeout, int writeTimeout, int pingIntervalMillis, boolean connectionRetryEnabled) throws IOException {
    Socket toClose;
    Connection releasedConnection;
    boolean newRouteSelection;
    RouteSelector.Selection selection;
    boolean foundPooledConnection = false;
    RealConnection result = null;
    Route selectedRoute = null;
    synchronized (this.connectionPool) {
        if (this.released) {
            throw new IllegalStateException("released");
        } else if (this.codec != null) {
            throw new IllegalStateException("codec != null");
        } else if (!this.canceled) {
            Connection releasedConnection2 = this.connection;
            toClose = releaseIfNoNewStreams();
            if (this.connection != null) {
                result = this.connection;
                releasedConnection2 = null;
            }
            if (!this.reportedAcquired) {
                releasedConnection = null;
            } else {
                releasedConnection = releasedConnection2;
            }
            if (result == null) {
                Internal.instance.get(this.connectionPool, this.address, this, null);
                if (this.connection != null) {
                    foundPooledConnection = true;
                    result = this.connection;
                } else {
                    selectedRoute = this.route;
                }
            }
        } else {
            throw new IOException("Canceled");
        }
    }
    Util.closeQuietly(toClose);
    if (releasedConnection != null) {
        this.eventListener.connectionReleased(this.call, releasedConnection);
    }
    if (foundPooledConnection) {
        this.eventListener.connectionAcquired(this.call, result);
    }
    if (result != null) {
        return result;
    }
    if (selectedRoute != null || ((selection = this.routeSelection) != null && selection.hasNext())) {
        newRouteSelection = false;
    } else {
        this.routeSelection = this.routeSelector.next();
        newRouteSelection = true;
    }
    synchronized (this.connectionPool) {
        if (!this.canceled) {
            if (newRouteSelection) {
                List<Route> routes = this.routeSelection.getAll();
                int i = 0;
                int size = routes.size();
                while (true) {
                    if (i >= size) {
                        break;
                    }
                    Route route = routes.get(i);
                    Internal.instance.get(this.connectionPool, this.address, this, route);
                    if (this.connection != null) {
                        foundPooledConnection = true;
                        result = this.connection;
                        this.route = route;
                        break;
                    }
                    i++;
                }
            }
            if (!foundPooledConnection) {
                if (selectedRoute == null) {
                    selectedRoute = this.routeSelection.next();
                }
                this.route = selectedRoute;
                this.refusedStreamCount = 0;
                result = new RealConnection(this.connectionPool, selectedRoute);
                acquire(result, false);
            }
        } else {
            throw new IOException("Canceled");
        }
    }
    if (foundPooledConnection) {
        this.eventListener.connectionAcquired(this.call, result);
        return result;
    }
    result.connect(connectTimeout, readTimeout, writeTimeout, pingIntervalMillis, connectionRetryEnabled, this.call, this.eventListener);
    routeDatabase().connected(result.route());
    Socket socket = null;
    synchronized (this.connectionPool) {
        this.reportedAcquired = true;
        Internal.instance.put(this.connectionPool, result);
        if (result.isMultiplexed()) {
            socket = Internal.instance.deduplicate(this.connectionPool, this.address, this);
            result = this.connection;
        }
    }
    Util.closeQuietly(socket);
    this.eventListener.connectionAcquired(this.call, result);
    return result;
}
Also used : RouteSelector(okhttp3.internal.connection.RouteSelector) Connection(okhttp3.Connection) IOException(java.io.IOException) Socket(java.net.Socket) Route(okhttp3.Route)

Example 2 with Route

use of com.google.cloud.compute.v1.Route in project kubernetes-client by fabric8io.

the class RouteTest method testCreateOrReplace.

@Test
void testCreateOrReplace() {
    // Given
    Route route = new RouteBuilder().withNewMetadata().withName("helloworld-nodejs-red-blue1").withNamespace("test").endMetadata().withNewSpec().addNewTraffic().withConfigurationName("greeter").withPercent(100L).endTraffic().endSpec().build();
    server.expect().post().withPath("/apis/serving.knative.dev/v1/namespaces/test/routes").andReturn(HttpURLConnection.HTTP_CONFLICT, route).once();
    server.expect().get().withPath("/apis/serving.knative.dev/v1/namespaces/test/routes/helloworld-nodejs-red-blue1").andReturn(HttpURLConnection.HTTP_OK, route).times(2);
    server.expect().put().withPath("/apis/serving.knative.dev/v1/namespaces/test/routes/helloworld-nodejs-red-blue1").andReturn(HttpURLConnection.HTTP_OK, route).once();
    // When
    route = client.routes().createOrReplace(new RouteBuilder().withNewMetadata().withName("helloworld-nodejs-red-blue1").addToAnnotations("foo", "bar").withNamespace("test").endMetadata().withNewSpec().addNewTraffic().withConfigurationName("greeter").withPercent(100L).endTraffic().endSpec().build());
    // Then
    assertNotNull(route);
}
Also used : RouteBuilder(io.fabric8.knative.serving.v1.RouteBuilder) Route(io.fabric8.knative.serving.v1.Route) Test(org.junit.jupiter.api.Test)

Example 3 with Route

use of com.google.cloud.compute.v1.Route in project kubernetes-client by fabric8io.

the class RouteCrudTest method shouldDeleteARoute.

@Test
void shouldDeleteARoute() {
    // Given
    Route route3 = new RouteBuilder().withNewMetadata().withName("route3").endMetadata().build();
    client.routes().inNamespace("ns3").create(route3);
    // When
    Boolean deleted = client.routes().inNamespace("ns3").withName("route3").delete();
    // Then
    assertTrue(deleted);
}
Also used : RouteBuilder(io.fabric8.knative.serving.v1.RouteBuilder) Route(io.fabric8.knative.serving.v1.Route) Test(org.junit.jupiter.api.Test)

Example 4 with Route

use of com.google.cloud.compute.v1.Route in project java-compute by googleapis.

the class RoutesClientTest method listTest.

@Test
public void listTest() throws Exception {
    Route responsesElement = Route.newBuilder().build();
    RouteList expectedResponse = RouteList.newBuilder().setNextPageToken("").addAllItems(Arrays.asList(responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    ListPagedResponse pagedListResponse = client.list(project);
    List<Route> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getItemsList().get(0), resources.get(0));
    List<String> actualRequests = mockService.getRequestPaths();
    Assert.assertEquals(1, actualRequests.size());
    String apiClientHeaderKey = mockService.getRequestHeaders().get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()).iterator().next();
    Assert.assertTrue(GaxHttpJsonProperties.getDefaultApiClientHeaderPattern().matcher(apiClientHeaderKey).matches());
}
Also used : ListPagedResponse(com.google.cloud.compute.v1.RoutesClient.ListPagedResponse) Test(org.junit.Test)

Example 5 with Route

use of com.google.cloud.compute.v1.Route in project azure-sdk-for-java by Azure.

the class KeyVaultCredentials method applyCredentialsFilter.

@Override
public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) {
    clientBuilder.addInterceptor(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            HttpUrl url = chain.request().url();
            Map<String, String> challengeMap = cache.getCachedChallenge(url);
            if (challengeMap != null) {
                // Get the bearer token
                String credential = getAuthenticationCredentials(challengeMap);
                Request newRequest = chain.request().newBuilder().header(AUTHENTICATE, BEARER_TOKEP_REFIX + credential).build();
                return chain.proceed(newRequest);
            } else {
                // response
                return chain.proceed(chain.request());
            }
        }
    });
    // Caches the challenge for failed request and re-send the request with
    // access token.
    clientBuilder.authenticator(new Authenticator() {

        @Override
        public Request authenticate(Route route, Response response) throws IOException {
            // if challenge is not cached then extract and cache it
            String authenticateHeader = response.header(WWW_AUTHENTICATE);
            Map<String, String> challengeMap = extractChallenge(authenticateHeader, BEARER_TOKEP_REFIX);
            // Cache the challenge
            cache.addCachedChallenge(response.request().url(), challengeMap);
            // Get the bearer token from the callback by providing the
            // challenges
            String credential = getAuthenticationCredentials(challengeMap);
            if (credential == null) {
                return null;
            }
            // be cached anywhere in our code.
            return response.request().newBuilder().header(AUTHENTICATE, BEARER_TOKEP_REFIX + credential).build();
        }
    });
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) IOException(java.io.IOException) Interceptor(okhttp3.Interceptor) Map(java.util.Map) HashMap(java.util.HashMap) HttpUrl(okhttp3.HttpUrl) Authenticator(okhttp3.Authenticator) Route(okhttp3.Route)

Aggregations

Route (okhttp3.Route)30 Response (okhttp3.Response)16 Authenticator (okhttp3.Authenticator)14 Request (okhttp3.Request)12 IOException (java.io.IOException)10 OkHttpClient (okhttp3.OkHttpClient)10 InetSocketAddress (java.net.InetSocketAddress)9 Route (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route)9 Proxy (java.net.Proxy)7 Route (io.fabric8.knative.serving.v1.Route)6 RouteBuilder (io.fabric8.knative.serving.v1.RouteBuilder)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)6 KeyedInstanceIdentifier (org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)6 Address (okhttp3.Address)5 Connection (okhttp3.Connection)5 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)5 Identifier (org.opendaylight.yangtools.yang.binding.Identifier)5 Builder (okhttp3.OkHttpClient.Builder)4