mirror of https://github.com/apache/jclouds.git
gce - kernels api
This commit is contained in:
parent
cd401757fc
commit
62d6e44027
|
@ -20,6 +20,7 @@ package org.jclouds.googlecompute;
|
|||
|
||||
import com.google.common.annotations.Beta;
|
||||
import org.jclouds.googlecompute.features.DiskApi;
|
||||
import org.jclouds.googlecompute.features.KernelApi;
|
||||
import org.jclouds.googlecompute.features.OperationApi;
|
||||
import org.jclouds.googlecompute.features.ProjectApi;
|
||||
import org.jclouds.googlecompute.features.ZoneApi;
|
||||
|
@ -48,6 +49,15 @@ public interface GoogleComputeApi {
|
|||
@Path("/projects/{project}")
|
||||
DiskApi getDiskApiForProject(@PathParam("project") String projectName);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Kernel features
|
||||
*
|
||||
* @param projectName the name of the project
|
||||
*/
|
||||
@Delegate
|
||||
@Path("/projects/{project}")
|
||||
KernelApi getKernelApiForProject(@PathParam("project") String projectName);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Project features
|
||||
*/
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.googlecompute;
|
|||
|
||||
import com.google.common.annotations.Beta;
|
||||
import org.jclouds.googlecompute.features.DiskAsyncApi;
|
||||
import org.jclouds.googlecompute.features.KernelAsyncApi;
|
||||
import org.jclouds.googlecompute.features.OperationAsyncApi;
|
||||
import org.jclouds.googlecompute.features.ProjectAsyncApi;
|
||||
import org.jclouds.googlecompute.features.ZoneAsyncApi;
|
||||
|
@ -47,6 +48,15 @@ public interface GoogleComputeAsyncApi {
|
|||
@Path("/projects/{project}")
|
||||
DiskAsyncApi getDiskApiForProject(@PathParam("project") String projectName);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Kernel features
|
||||
*
|
||||
* @param projectName the name of the project
|
||||
*/
|
||||
@Delegate
|
||||
@Path("/projects/{project}")
|
||||
KernelAsyncApi getKernelApiForProject(@PathParam("project") String projectName);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Project features
|
||||
*/
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.jclouds.googlecompute.GoogleComputeAsyncApi;
|
|||
import org.jclouds.googlecompute.domain.Operation;
|
||||
import org.jclouds.googlecompute.features.DiskApi;
|
||||
import org.jclouds.googlecompute.features.DiskAsyncApi;
|
||||
import org.jclouds.googlecompute.features.KernelApi;
|
||||
import org.jclouds.googlecompute.features.KernelAsyncApi;
|
||||
import org.jclouds.googlecompute.features.OperationApi;
|
||||
import org.jclouds.googlecompute.features.OperationAsyncApi;
|
||||
import org.jclouds.googlecompute.features.ProjectApi;
|
||||
|
@ -61,6 +63,7 @@ import static com.google.common.base.Preconditions.checkState;
|
|||
public class GoogleComputeRestClientModule extends RestClientModule<GoogleComputeApi, GoogleComputeAsyncApi> {
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>>builder()
|
||||
.put(DiskApi.class, DiskAsyncApi.class)
|
||||
.put(KernelApi.class, KernelAsyncApi.class)
|
||||
.put(OperationApi.class, OperationAsyncApi.class)
|
||||
.put(ProjectApi.class, ProjectAsyncApi.class)
|
||||
.put(ZoneApi.class, ZoneAsyncApi.class)
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.googlecompute.domain;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
import static com.google.common.base.Optional.fromNullable;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Represents a kernel.
|
||||
*
|
||||
* @author David Alves
|
||||
* @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/kernels"/>
|
||||
*/
|
||||
@Beta
|
||||
public final class Kernel extends Resource {
|
||||
|
||||
@ConstructorProperties({
|
||||
"id", "creationTimestamp", "selfLink", "name", "description"
|
||||
})
|
||||
private Kernel(String id, Date creationTimestamp, URI selfLink, String name, String description) {
|
||||
super(Kind.KERNEL, checkNotNull(id, "id of %s", name), fromNullable(creationTimestamp),
|
||||
checkNotNull(selfLink, "selfLink of %s", name), checkNotNull(name, "name"),
|
||||
fromNullable(description));
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromKernel(this);
|
||||
}
|
||||
|
||||
public static final class Builder extends Resource.Builder<Builder> {
|
||||
|
||||
@Override
|
||||
protected Builder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Kernel build() {
|
||||
return new Kernel(super.id, super.creationTimestamp, super.selfLink, super.name,
|
||||
super.description);
|
||||
}
|
||||
|
||||
public Builder fromKernel(Kernel in) {
|
||||
return super.fromResource(in);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.googlecompute.features;
|
||||
|
||||
import org.jclouds.collect.PagedIterable;
|
||||
import org.jclouds.googlecompute.domain.Kernel;
|
||||
import org.jclouds.googlecompute.domain.ListPage;
|
||||
import org.jclouds.googlecompute.options.ListOptions;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to MachineTypes via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @author David Alves
|
||||
* @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/kernels"/>
|
||||
*/
|
||||
public interface KernelApi {
|
||||
|
||||
/**
|
||||
* Returns the specified kernel resource
|
||||
*
|
||||
* @param kernelName name of the kernel resource to return.
|
||||
* @return If successful, this method returns a Kernel resource
|
||||
*/
|
||||
public Kernel get(String kernelName);
|
||||
|
||||
/**
|
||||
* @see KernelApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions)
|
||||
*/
|
||||
public ListPage<Kernel> listFirstPage();
|
||||
|
||||
/**
|
||||
* @see KernelApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions)
|
||||
*/
|
||||
public ListPage<Kernel> listAtMarker(@Nullable String marker);
|
||||
|
||||
/**
|
||||
* Retrieves the list of kernel resources available to the specified project.
|
||||
* By default the list as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has not
|
||||
* been set.
|
||||
*
|
||||
* @param marker marks the beginning of the next list page
|
||||
* @param listOptions listing options
|
||||
* @return a page of the list
|
||||
* @see ListOptions
|
||||
* @see org.jclouds.googlecompute.domain.ListPage
|
||||
*/
|
||||
public ListPage<Kernel> listAtMarker(String marker, ListOptions listOptions);
|
||||
|
||||
/**
|
||||
* @see KernelApi#list(org.jclouds.googlecompute.options.ListOptions)
|
||||
*/
|
||||
public PagedIterable<Kernel> list();
|
||||
|
||||
/**
|
||||
* A paged version of KernelApi#list()
|
||||
*
|
||||
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
|
||||
* @see PagedIterable
|
||||
* @see KernelApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions)
|
||||
*/
|
||||
public PagedIterable<Kernel> list(ListOptions listOptions);
|
||||
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.googlecompute.features;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.collect.PagedIterable;
|
||||
import org.jclouds.googlecompute.domain.Kernel;
|
||||
import org.jclouds.googlecompute.domain.ListPage;
|
||||
import org.jclouds.googlecompute.functions.internal.ParseKernels;
|
||||
import org.jclouds.googlecompute.options.ListOptions;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.oauth.v2.config.OAuthScopes;
|
||||
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
import org.jclouds.rest.annotations.Transform;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import static org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
|
||||
import static org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
|
||||
import static org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import static org.jclouds.googlecompute.GoogleComputeConstants.COMPUTE_READONLY_SCOPE;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Kernels via their REST API.
|
||||
*
|
||||
* @author David Alves
|
||||
*/
|
||||
@SkipEncoding({'/', '='})
|
||||
@RequestFilters(OAuthAuthenticator.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface KernelAsyncApi {
|
||||
|
||||
/**
|
||||
* @see KernelApi#get(String)
|
||||
*/
|
||||
@GET
|
||||
@Path("/kernels/{kernel}")
|
||||
@OAuthScopes(COMPUTE_READONLY_SCOPE)
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
ListenableFuture<Kernel> get(@PathParam("kernel") String kernelName);
|
||||
|
||||
/**
|
||||
* @see KernelApi#listFirstPage()
|
||||
*/
|
||||
@GET
|
||||
@Path("/kernels")
|
||||
@OAuthScopes(COMPUTE_READONLY_SCOPE)
|
||||
@ResponseParser(ParseKernels.class)
|
||||
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
|
||||
ListenableFuture<ListPage<Kernel>> listFirstPage();
|
||||
|
||||
/**
|
||||
* @see KernelApi#listAtMarker(String)
|
||||
*/
|
||||
@GET
|
||||
@Path("/kernels")
|
||||
@OAuthScopes(COMPUTE_READONLY_SCOPE)
|
||||
@ResponseParser(ParseKernels.class)
|
||||
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
|
||||
ListenableFuture<ListPage<Kernel>> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
|
||||
|
||||
/**
|
||||
* @see KernelApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions)
|
||||
*/
|
||||
@GET
|
||||
@Path("/kernels")
|
||||
@OAuthScopes(COMPUTE_READONLY_SCOPE)
|
||||
@ResponseParser(ParseKernels.class)
|
||||
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
|
||||
ListenableFuture<ListPage<Kernel>> listAtMarker(@QueryParam("pageToken") @Nullable String marker,
|
||||
ListOptions listOptions);
|
||||
|
||||
/**
|
||||
* @see org.jclouds.googlecompute.features.KernelApi#list()
|
||||
*/
|
||||
@GET
|
||||
@Path("/kernels")
|
||||
@OAuthScopes(COMPUTE_READONLY_SCOPE)
|
||||
@ResponseParser(ParseKernels.class)
|
||||
@Transform(ParseKernels.ToPagedIterable.class)
|
||||
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends PagedIterable<Kernel>> list();
|
||||
|
||||
/**
|
||||
* @see KernelApi#list(org.jclouds.googlecompute.options.ListOptions)
|
||||
*/
|
||||
@GET
|
||||
@Path("/kernels")
|
||||
@OAuthScopes(COMPUTE_READONLY_SCOPE)
|
||||
@ResponseParser(ParseKernels.class)
|
||||
@Transform(ParseKernels.ToPagedIterable.class)
|
||||
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends PagedIterable<Kernel>> list(ListOptions listOptions);
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.googlecompute.functions.internal;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.collect.IterableWithMarker;
|
||||
import org.jclouds.googlecompute.GoogleComputeApi;
|
||||
import org.jclouds.googlecompute.domain.Kernel;
|
||||
import org.jclouds.googlecompute.domain.ListPage;
|
||||
import org.jclouds.googlecompute.options.ListOptions;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.json.Json;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author David Alves
|
||||
*/
|
||||
public class ParseKernels extends ParseJson<ListPage<Kernel>> {
|
||||
|
||||
@Inject
|
||||
public ParseKernels(Json json) {
|
||||
super(json, new TypeLiteral<ListPage<Kernel>>() {});
|
||||
}
|
||||
|
||||
public static class ToPagedIterable extends BaseToPagedIterable<Kernel, ToPagedIterable> {
|
||||
|
||||
private final GoogleComputeApi api;
|
||||
|
||||
@Inject
|
||||
protected ToPagedIterable(GoogleComputeApi api) {
|
||||
this.api = checkNotNull(api, "api");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function<Object, IterableWithMarker<Kernel>> fetchNextPage(final String projectName,
|
||||
final String marker,
|
||||
final ListOptions options) {
|
||||
return new Function<Object, IterableWithMarker<Kernel>>() {
|
||||
|
||||
@Override
|
||||
public IterableWithMarker<Kernel> apply(Object input) {
|
||||
return api.getKernelApiForProject(projectName).listAtMarker(marker, options);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.googlecompute.features;
|
||||
|
||||
import org.jclouds.googlecompute.GoogleComputeApi;
|
||||
import org.jclouds.googlecompute.internal.BaseGoogleComputeExpectTest;
|
||||
import org.jclouds.googlecompute.parse.ParseKernelListTest;
|
||||
import org.jclouds.googlecompute.parse.ParseKernelTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.jclouds.googlecompute.GoogleComputeConstants.COMPUTE_READONLY_SCOPE;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author David Alves
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class KernelApiExpectTest extends BaseGoogleComputeExpectTest<GoogleComputeApi> {
|
||||
|
||||
public void testGetKernelResponseIs2xx() throws Exception {
|
||||
HttpRequest get = HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint("https://www.googleapis" +
|
||||
".com/compute/v1beta13/projects/myproject/kernels/12941177846308850718")
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("Authorization", "Bearer " + TOKEN).build();
|
||||
|
||||
HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResource("/kernel.json")).build();
|
||||
|
||||
KernelApi kernelApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
|
||||
TOKEN_RESPONSE, get, operationResponse).getKernelApiForProject("myproject");
|
||||
|
||||
assertEquals(kernelApi.get("12941177846308850718"),
|
||||
new ParseKernelTest().expected());
|
||||
}
|
||||
|
||||
public void testGetKernelResponseIs4xx() throws Exception {
|
||||
HttpRequest get = HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint("https://www.googleapis" +
|
||||
".com/compute/v1beta13/projects/myproject/kernels/12941177846308850718")
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("Authorization", "Bearer " + TOKEN).build();
|
||||
|
||||
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
KernelApi kernelApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
|
||||
TOKEN_RESPONSE, get, operationResponse).getKernelApiForProject("myproject");
|
||||
|
||||
assertNull(kernelApi.get("12941177846308850718"));
|
||||
}
|
||||
|
||||
public void testListKernelNoOptionsResponseIs2xx() throws Exception {
|
||||
HttpRequest list = HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint("https://www.googleapis" +
|
||||
".com/compute/v1beta13/projects/myproject/kernels")
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("Authorization", "Bearer " + TOKEN).build();
|
||||
|
||||
HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResource("/kernel_list.json")).build();
|
||||
|
||||
KernelApi kernelApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
|
||||
TOKEN_RESPONSE, list, operationResponse).getKernelApiForProject("myproject");
|
||||
|
||||
assertEquals(kernelApi.listFirstPage().toString(),
|
||||
new ParseKernelListTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testListKernelsResponseIs4xx() {
|
||||
HttpRequest list = HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint("https://www.googleapis" +
|
||||
".com/compute/v1beta13/projects/myproject/kernels")
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("Authorization", "Bearer " + TOKEN).build();
|
||||
|
||||
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
KernelApi kernelApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
|
||||
TOKEN_RESPONSE, list, operationResponse).getKernelApiForProject("myproject");
|
||||
|
||||
assertTrue(kernelApi.list().concat().isEmpty());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.googlecompute.features;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jclouds.collect.IterableWithMarker;
|
||||
import org.jclouds.collect.PagedIterable;
|
||||
import org.jclouds.googlecompute.domain.Kernel;
|
||||
import org.jclouds.googlecompute.internal.BaseGoogleComputeApiLiveTest;
|
||||
import org.jclouds.googlecompute.options.ListOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertSame;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author David Alves
|
||||
*/
|
||||
public class KernelApiLiveTest extends BaseGoogleComputeApiLiveTest {
|
||||
|
||||
private Kernel kernel;
|
||||
|
||||
private KernelApi api() {
|
||||
return context.getApi().getKernelApiForProject("google");
|
||||
}
|
||||
|
||||
@Test(groups = "live")
|
||||
public void testListKernel() {
|
||||
|
||||
PagedIterable<Kernel> kernels = api().list(new ListOptions.Builder()
|
||||
.maxResults(1));
|
||||
|
||||
Iterator<IterableWithMarker<Kernel>> pageIterator = kernels.iterator();
|
||||
assertTrue(pageIterator.hasNext());
|
||||
|
||||
IterableWithMarker<Kernel> singlePageIterator = pageIterator.next();
|
||||
List<Kernel> kernelAsList = Lists.newArrayList(singlePageIterator);
|
||||
|
||||
assertSame(kernelAsList.size(), 1);
|
||||
|
||||
this.kernel = Iterables.getOnlyElement(kernelAsList);
|
||||
}
|
||||
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testListKernel")
|
||||
public void testGetKernel() {
|
||||
Kernel kernel = api().get(this.kernel.getName());
|
||||
assertNotNull(kernel);
|
||||
assertKernelEquals(kernel, this.kernel);
|
||||
}
|
||||
|
||||
private void assertKernelEquals(Kernel result, Kernel expected) {
|
||||
assertEquals(result.getName(), expected.getName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.googlecompute.parse;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.googlecompute.domain.Kernel;
|
||||
import org.jclouds.googlecompute.domain.ListPage;
|
||||
import org.jclouds.googlecompute.domain.Resource;
|
||||
import org.jclouds.googlecompute.internal.BaseGoogleComputeParseTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author David Alves
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ParseKernelListTest extends BaseGoogleComputeParseTest<ListPage<Kernel>> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/kernel_list.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public ListPage<Kernel> expected() {
|
||||
return ListPage.<Kernel>builder()
|
||||
.kind(Resource.Kind.KERNEL_LIST)
|
||||
.id("projects/google/kernels")
|
||||
.selfLink(URI.create("https://www.googleapis.com/compute/v1beta13/projects/google/kernels"))
|
||||
.items(ImmutableSet.of(
|
||||
Kernel.builder()
|
||||
.id("12941177846308850718")
|
||||
.creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse
|
||||
("2012-07-16T21:42:16.950"))
|
||||
.selfLink(URI.create("https://www.googleapis" +
|
||||
".com/compute/v1beta13/projects/google/kernels/gce-20110524"))
|
||||
.name("gce-20110524")
|
||||
.description("DEPRECATED. Created Tue, 24 May 2011 00:48:22 +0000").build(),
|
||||
Kernel.builder()
|
||||
.id("12941177983348179280")
|
||||
.creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse
|
||||
("2012-07-16T21:42:31.166"))
|
||||
.selfLink(URI.create("https://www.googleapis" +
|
||||
".com/compute/v1beta13/projects/google/kernels/gce-20110728"))
|
||||
.name("gce-20110728")
|
||||
.description("DEPRECATED. Created Thu, 28 Jul 2011 16:44:38 +0000").build()
|
||||
)).build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.googlecompute.parse;
|
||||
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.googlecompute.domain.Kernel;
|
||||
import org.jclouds.googlecompute.internal.BaseGoogleComputeParseTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author David Alves
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ParseKernelTest extends BaseGoogleComputeParseTest<Kernel> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/kernel.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Kernel expected() {
|
||||
return Kernel.builder()
|
||||
.id("12941177846308850718")
|
||||
.creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-07-16T21:42:16.950"))
|
||||
.selfLink(URI.create("https://www.googleapis.com/compute/v1beta13/projects/google/kernels/gce-20110524"))
|
||||
.name("gce-20110524")
|
||||
.description("DEPRECATED. Created Tue, 24 May 2011 00:48:22 +0000")
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"kind": "compute#kernel",
|
||||
"id": "12941177846308850718",
|
||||
"creationTimestamp": "2012-07-16T21:42:16.950",
|
||||
"selfLink": "https://www.googleapis.com/compute/v1beta13/projects/google/kernels/gce-20110524",
|
||||
"name": "gce-20110524",
|
||||
"description": "DEPRECATED. Created Tue, 24 May 2011 00:48:22 +0000"
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"kind": "compute#kernelList",
|
||||
"id": "projects/google/kernels",
|
||||
"selfLink": "https://www.googleapis.com/compute/v1beta13/projects/google/kernels",
|
||||
"items": [
|
||||
{
|
||||
"kind": "compute#kernel",
|
||||
"id": "12941177846308850718",
|
||||
"creationTimestamp": "2012-07-16T21:42:16.950",
|
||||
"selfLink": "https://www.googleapis.com/compute/v1beta13/projects/google/kernels/gce-20110524",
|
||||
"name": "gce-20110524",
|
||||
"description": "DEPRECATED. Created Tue, 24 May 2011 00:48:22 +0000"
|
||||
},
|
||||
{
|
||||
"kind": "compute#kernel",
|
||||
"id": "12941177983348179280",
|
||||
"creationTimestamp": "2012-07-16T21:42:31.166",
|
||||
"selfLink": "https://www.googleapis.com/compute/v1beta13/projects/google/kernels/gce-20110728",
|
||||
"name": "gce-20110728",
|
||||
"description": "DEPRECATED. Created Thu, 28 Jul 2011 16:44:38 +0000"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue