Moved the server related methods to a separate service

This commit is contained in:
Alex Yarmula 2010-02-26 22:23:15 -08:00
parent 23a1435417
commit b88b6beb9f
13 changed files with 214 additions and 175 deletions

View File

@ -1,77 +1,15 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.
* ====================================================================
*/
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.gogrid;
import com.google.common.util.concurrent.ListenableFuture;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
import org.jclouds.rest.annotations.*;
import java.util.Set;
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
import com.google.inject.ImplementedBy;
import org.jclouds.gogrid.internal.GoGridAsyncClientImpl;
import org.jclouds.gogrid.services.GridServerClient;
/**
* Provides asynchronous access to GoGrid via their REST API.
* <p/>
*
* @see GoGridClient
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API" />
* @author Adrian Cole
* @author Oleksiy Yarmula
*/
@Endpoint(GoGrid.class)
@RequestFilters(SharedKeyLiteAuthentication.class)
@QueryParams(keys = VERSION, values = "1.3")
@ImplementedBy(GoGridAsyncClientImpl.class)
public interface GoGridAsyncClient {
@GET
@ResponseParser(ParseServerListFromJsonResponse.class)
@Path("/grid/server/list")
ListenableFuture<Set<Server>> getServerList();
GridServerClient getServerClient();
}

View File

@ -1,47 +1,16 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.gogrid;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.gogrid.domain.Server;
import com.google.inject.ImplementedBy;
import org.jclouds.gogrid.internal.GoGridClientImpl;
import org.jclouds.gogrid.services.GridServerClient;
/**
* Provides synchronous access to GoGrid.
* <p/>
*
* @see GoGridAsyncClient
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API" />
*
* @author Adrian Cole
* @author Oleksiy Yarmula
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
@ImplementedBy(GoGridClientImpl.class)
public interface GoGridClient {
Set<Server> getServerList();
GridServerClient getServerClient();
}

View File

@ -1,21 +1,3 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.
* ====================================================================
*/
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
@ -46,8 +28,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import java.util.Properties;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.GoGridAsyncClient;
import org.jclouds.rest.RestContextBuilder;
import org.jclouds.gogrid.config.GoGridContextModule;
import org.jclouds.gogrid.config.GoGridRestClientModule;

View File

@ -25,6 +25,8 @@ package org.jclouds.gogrid;
import java.util.Properties;
import org.jclouds.gogrid.services.GridServerAsyncClient;
import org.jclouds.gogrid.services.GridServerClient;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContext;
@ -32,7 +34,7 @@ import org.jclouds.rest.RestContext;
import com.google.inject.Module;
/**
* Creates {@link RestContext} for {@link GoGridClient} instances based on the most commonly
* Creates {@link RestContext} for {@link GridServerClient} instances based on the most commonly
* requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
@ -45,8 +47,8 @@ import com.google.inject.Module;
* @author Oleksiy Yarmula
*
* @see RestContext
* @see GoGridClient
* @see GoGridAsyncClient
* @see GridServerClient
* @see GridServerAsyncClient
*/
public class GoGridContextFactory {

View File

@ -45,21 +45,17 @@ import java.lang.reflect.Type;
import java.net.URI;
import java.util.Date;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import com.google.gson.*;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
import org.jclouds.gogrid.GoGridAsyncClient;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.gogrid.GoGrid;
import org.jclouds.gogrid.GoGridAsyncClient;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.reference.GoGridConstants;
import com.google.inject.AbstractModule;

View File

@ -41,28 +41,26 @@
*/
package org.jclouds.gogrid.config;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.text.DateFormat;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import com.google.common.base.Supplier;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp;
import org.jclouds.gogrid.GoGridAsyncClient;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.services.GridServerAsyncClient;
import org.jclouds.gogrid.services.GridServerClient;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.gogrid.GoGrid;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.GoGridAsyncClient;
import org.jclouds.gogrid.reference.GoGridConstants;
import com.google.inject.AbstractModule;
@ -88,15 +86,15 @@ public class GoGridRestClientModule extends AbstractModule {
@Provides
@Singleton
protected GoGridAsyncClient provideClient(RestClientFactory factory) {
return factory.create(GoGridAsyncClient.class);
protected GridServerAsyncClient provideServerClient(RestClientFactory factory) {
return factory.create(GridServerAsyncClient.class);
}
@Provides
@Singleton
public GoGridClient provideClient(GoGridAsyncClient client) throws IllegalArgumentException,
public GridServerClient provideServerClient(GridServerAsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(GoGridClient.class, client);
return SyncProxy.create(GridServerClient.class, client);
}
@Provides
@ -118,8 +116,7 @@ public class GoGridRestClientModule extends AbstractModule {
@Provides
@TimeStamp
Supplier<Long> provideTimeStampCache(
@Named(PROPERTY_GOGRID_SESSIONINTERVAL) long seconds,
final DateService dateService) {
@Named(PROPERTY_GOGRID_SESSIONINTERVAL) long seconds) {
return new ExpirableSupplier<Long>(new Supplier<Long>() {
public Long get() {
return System.currentTimeMillis() / 1000;

View File

@ -0,0 +1,25 @@
package org.jclouds.gogrid.internal;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.jclouds.gogrid.GoGridAsyncClient;
import org.jclouds.gogrid.services.GridServerClient;
/**
* @author Oleksiy Yarmula
*/
@Singleton
public class GoGridAsyncClientImpl implements GoGridAsyncClient {
private GridServerClient gridServerClient;
@Inject
public GoGridAsyncClientImpl(GridServerClient gridServerClient) {
this.gridServerClient = gridServerClient;
}
@Override
public GridServerClient getServerClient() {
return gridServerClient;
}
}

View File

@ -0,0 +1,25 @@
package org.jclouds.gogrid.internal;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.services.GridServerClient;
/**
* @author Oleksiy Yarmula
*/
@Singleton
public class GoGridClientImpl implements GoGridClient {
private GridServerClient gridServerClient;
@Inject
public GoGridClientImpl(GridServerClient gridServerClient) {
this.gridServerClient = gridServerClient;
}
@Override
public GridServerClient getServerClient() {
return gridServerClient;
}
}

View File

@ -0,0 +1,78 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.
* ====================================================================
*/
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.gogrid.services;
import com.google.common.util.concurrent.ListenableFuture;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.jclouds.gogrid.GoGrid;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
import org.jclouds.rest.annotations.*;
import java.util.Set;
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
/**
* Provides asynchronous access to GoGrid via their REST API.
* <p/>
*
* @see GridServerClient
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API" />
* @author Adrian Cole
* @author Oleksiy Yarmula
*/
@Endpoint(GoGrid.class)
@RequestFilters(SharedKeyLiteAuthentication.class)
@QueryParams(keys = VERSION, values = "1.3")
public interface GridServerAsyncClient {
@GET
@ResponseParser(ParseServerListFromJsonResponse.class)
@Path("/grid/server/list")
ListenableFuture<Set<Server>> getServerList();
}

View File

@ -0,0 +1,47 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.gogrid.services;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.gogrid.domain.Server;
/**
* Provides synchronous access to GoGrid.
* <p/>
*
* @see GridServerAsyncClient
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API" />
*
* @author Adrian Cole
* @author Oleksiy Yarmula
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface GridServerClient {
Set<Server> getServerList();
}

View File

@ -51,9 +51,8 @@ import java.net.URI;
import javax.inject.Singleton;
import com.google.common.collect.Iterables;
import org.jclouds.date.TimeStamp;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.gogrid.services.GridServerAsyncClient;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest;
@ -75,12 +74,12 @@ import com.google.inject.TypeLiteral;
* @author Oleksiy Yarmula
*/
@Test(groups = "unit", testName = "gogrid.GoGridAsyncClientTest")
public class GoGridAsyncClientTest extends RestClientTest<GoGridAsyncClient> {
public class GoGridAsyncClientTest extends RestClientTest<GridServerAsyncClient> {
@Test
public void testGetServerList() throws SecurityException, NoSuchMethodException, IOException {
Method method = GoGridAsyncClient.class.getMethod("getServerList");
GeneratedHttpRequest<GoGridAsyncClient> httpRequest = processor.createRequest(method);
Method method = GridServerAsyncClient.class.getMethod("getServerList");
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?v=1.3 HTTP/1.1");
assertHeadersEqual(httpRequest, "");
@ -102,14 +101,14 @@ public class GoGridAsyncClientTest extends RestClientTest<GoGridAsyncClient> {
}
@Override
protected void checkFilters(GeneratedHttpRequest<GoGridAsyncClient> httpMethod) {
protected void checkFilters(GeneratedHttpRequest<GridServerAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<GoGridAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<GoGridAsyncClient>>() {
protected TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>>() {
};
}

View File

@ -40,20 +40,20 @@ import java.util.Set;
@Test(groups = "live", testName = "gogrid.GoGridClientLiveTest")
public class GoGridClientLiveTest {
private GoGridClient connection;
private GoGridClient client;
@BeforeGroups(groups = { "live" })
public void setupClient() {
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
connection = GoGridContextFactory.createContext(user, password, new Log4JLoggingModule())
client = GoGridContextFactory.createContext(user, password, new Log4JLoggingModule())
.getApi();
}
@Test
public void testGetServerList() {
Set<Server> response = connection.getServerList();
Set<Server> response = client.getServerClient().getServerList();
assert (response.size() > 0);
}

View File

@ -1,21 +1,3 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.
* ====================================================================
*/
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
@ -49,7 +31,8 @@ import java.util.List;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.gogrid.services.GridServerAsyncClient;
import org.jclouds.gogrid.services.GridServerClient;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.gogrid.config.GoGridRestClientModule;