diff --git a/gogrid/src/main/java/org/jclouds/gogrid/GoGridAsyncClient.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridAsyncClient.java index 2482a6bd04..1b090e3625 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/GoGridAsyncClient.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridAsyncClient.java @@ -1,77 +1,15 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * - * ==================================================================== - * 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. - *

- * - * @see GoGridClient - * @see - * @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> getServerList(); + GridServerClient getServerClient(); } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/GoGridClient.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridClient.java index 0428f68bd3..703455192c 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/GoGridClient.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridClient.java @@ -1,47 +1,16 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - *

- * - * @see GoGridAsyncClient - * @see - * - * @author Adrian Cole * @author Oleksiy Yarmula */ -@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +@ImplementedBy(GoGridClientImpl.class) + public interface GoGridClient { - Set getServerList(); + GridServerClient getServerClient(); } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java index 59987938a6..5d32c416ee 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java @@ -1,21 +1,3 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. @@ -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; diff --git a/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextFactory.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextFactory.java index bc4fd5f002..0d2f5d5a9e 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextFactory.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextFactory.java @@ -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. *

* 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 { diff --git a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java index b303e9ebb1..b509129bca 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java @@ -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; diff --git a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java index 21628a49d0..5f44211ea9 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java @@ -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 provideTimeStampCache( - @Named(PROPERTY_GOGRID_SESSIONINTERVAL) long seconds, - final DateService dateService) { + @Named(PROPERTY_GOGRID_SESSIONINTERVAL) long seconds) { return new ExpirableSupplier(new Supplier() { public Long get() { return System.currentTimeMillis() / 1000; diff --git a/gogrid/src/main/java/org/jclouds/gogrid/internal/GoGridAsyncClientImpl.java b/gogrid/src/main/java/org/jclouds/gogrid/internal/GoGridAsyncClientImpl.java new file mode 100644 index 0000000000..a1cccc060f --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/internal/GoGridAsyncClientImpl.java @@ -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; + } +} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/internal/GoGridClientImpl.java b/gogrid/src/main/java/org/jclouds/gogrid/internal/GoGridClientImpl.java new file mode 100644 index 0000000000..8673b36e9d --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/internal/GoGridClientImpl.java @@ -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; + } +} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerAsyncClient.java b/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerAsyncClient.java new file mode 100644 index 0000000000..b84414d667 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerAsyncClient.java @@ -0,0 +1,78 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * + * ==================================================================== + * 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. + *

+ * + * @see GridServerClient + * @see + * @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> getServerList(); + +} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerClient.java b/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerClient.java new file mode 100644 index 0000000000..d475cbe716 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerClient.java @@ -0,0 +1,47 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + *

+ * + * @see GridServerAsyncClient + * @see + * + * @author Adrian Cole + * @author Oleksiy Yarmula + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface GridServerClient { + + Set getServerList(); + +} diff --git a/gogrid/src/test/java/org/jclouds/gogrid/GoGridAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/GoGridAsyncClientTest.java index 4ce68f3a42..a90dae8ccf 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/GoGridAsyncClientTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/GoGridAsyncClientTest.java @@ -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 { +public class GoGridAsyncClientTest extends RestClientTest { @Test public void testGetServerList() throws SecurityException, NoSuchMethodException, IOException { - Method method = GoGridAsyncClient.class.getMethod("getServerList"); - GeneratedHttpRequest httpRequest = processor.createRequest(method); + Method method = GridServerAsyncClient.class.getMethod("getServerList"); + GeneratedHttpRequest 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 { } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { + protected void checkFilters(GeneratedHttpRequest httpMethod) { assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); } @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { }; } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/GoGridClientLiveTest.java b/gogrid/src/test/java/org/jclouds/gogrid/GoGridClientLiveTest.java index c39eef0105..5731038357 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/GoGridClientLiveTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/GoGridClientLiveTest.java @@ -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 response = connection.getServerList(); + Set response = client.getServerClient().getServerList(); assert (response.size() > 0); } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/GoGridContextBuilderTest.java b/gogrid/src/test/java/org/jclouds/gogrid/GoGridContextBuilderTest.java index 64a8397b07..796bfea46b 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/GoGridContextBuilderTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/GoGridContextBuilderTest.java @@ -1,21 +1,3 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. @@ -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;