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;
}
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);
}
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);
}
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());
}
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();
}
});
}
Aggregations