added jobs and ip services; more test; single live test

This commit is contained in:
Alex Yarmula 2010-02-28 17:17:53 -08:00
parent ddc1a30b55
commit 4892b843d8
54 changed files with 2486 additions and 159 deletions

View File

@ -56,6 +56,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import com.google.common.collect.*;
import org.jclouds.PropertiesBuilder;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.DateService;
@ -105,11 +106,6 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
@ -820,6 +816,30 @@ public class RestAnnotationProcessorTest {
assertEquals(query, "x-amz-copy-source=/robot");
}
@Test
public void testParseQueryToMapSingleParam() {
Multimap<String, String> parsedMap = RestAnnotationProcessor.parseQueryToMap("v=1.3");
assert parsedMap.keySet().size() == 1 : "Expected 1 key, found: " + parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") :
"Expected the value for 'v' to be '1.3', found: " + valueForV;
}
@Test
public void testParseQueryToMapMultiParam() {
Multimap<String, String> parsedMap = RestAnnotationProcessor.parseQueryToMap("v=1.3&sig=123");
assert parsedMap.keySet().size() == 2 : "Expected 2 keys, found: " + parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
assert parsedMap.keySet().contains("sig") : "Expected sig to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") :
"Expected the value for 'v' to be '1.3', found: " + valueForV;
String valueForSig = Iterables.getOnlyElement(parsedMap.get("sig"));
assert valueForSig.equals("123") :
"Expected the value for 'v' to be '123', found: " + valueForSig;
}
@Endpoint(Localhost.class)
private interface TestMapMatrixParams {
@POST

View File

@ -1,8 +1,33 @@
/**
*
* 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.inject.ImplementedBy;
import org.jclouds.gogrid.internal.GoGridAsyncClientImpl;
import org.jclouds.gogrid.services.GridServerClient;
import org.jclouds.gogrid.services.GridIpAsyncClient;
import org.jclouds.gogrid.services.GridJobAsyncClient;
import org.jclouds.gogrid.services.GridServerAsyncClient;
/**
* @author Oleksiy Yarmula
@ -10,6 +35,19 @@ import org.jclouds.gogrid.services.GridServerClient;
@ImplementedBy(GoGridAsyncClientImpl.class)
public interface GoGridAsyncClient {
GridServerClient getServerClient();
/**
* @see GoGridClient#getServerServices()
*/
GridServerAsyncClient getServerServices();
/**
* @see GoGridClient#getJobServices()
*/
GridJobAsyncClient getJobServices();
/**
* @see GoGridClient#getIpServices()
*/
GridIpAsyncClient getIpServices();
}

View File

@ -1,7 +1,32 @@
/**
*
* 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.inject.ImplementedBy;
import org.jclouds.gogrid.internal.GoGridClientImpl;
import org.jclouds.gogrid.services.GridIpClient;
import org.jclouds.gogrid.services.GridJobClient;
import org.jclouds.gogrid.services.GridServerClient;
/**
@ -11,6 +36,22 @@ import org.jclouds.gogrid.services.GridServerClient;
public interface GoGridClient {
GridServerClient getServerClient();
/**
* Returns methods, related to managing servers
* @return serverServices
*/
GridServerClient getServerServices();
/**
* Returns methods, related to retrieving jobs
* @return jobServices
*/
GridJobClient getJobServices();
/**
* Returns methods, related to retrieving IP addresses
* @return ipServices
*/
GridIpClient getIpServices();
}

View File

@ -1,3 +1,26 @@
/**
*
* 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 org.jclouds.gogrid.domain.internal.ErrorResponse;

View File

@ -1,3 +1,26 @@
/**
*
* 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.binders;
import org.jclouds.http.HttpRequest;
@ -14,7 +37,7 @@ import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY;
*
* @author Oleksiy Yarmula
*/
public class BindIdsToQueryParams implements Binder {
public class BindIdsToQueryParams implements Binder {
/**
* Binds the ids to query parameters. The pattern, as

View File

@ -1,3 +1,26 @@
/**
*
* 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.binders;
import org.jclouds.http.HttpRequest;
@ -44,7 +67,4 @@ public class BindNamesToQueryParams implements Binder {
}
}
}

View File

@ -0,0 +1,54 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.binders;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
/**
*
* @see org.jclouds.gogrid.services.GridJobClient#getJobsForObjectName(String)
*
* @author Oleksiy Yarmula
*/
public class BindObjectNameToGetJobsRequestQueryParams implements Binder {
/**
* Maps the object's name to the
* input of <a href="http://wiki.gogrid.com/wiki/index.php/API:grid.job.list/>.
*/
@Override
public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input is null") instanceof String,
"this binder is only valid for String arguments");
String serverName = (String) input;
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
generatedRequest.addQueryParam(OBJECT_KEY, serverName);
}
}

View File

@ -55,8 +55,7 @@ import org.jclouds.date.TimeStamp;
import org.jclouds.gogrid.GoGridAsyncClient;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.handlers.GoGridErrorHandler;
import org.jclouds.gogrid.services.GridServerAsyncClient;
import org.jclouds.gogrid.services.GridServerClient;
import org.jclouds.gogrid.services.*;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
@ -102,6 +101,32 @@ public class GoGridRestClientModule extends AbstractModule {
return SyncProxy.create(GridServerClient.class, client);
}
@Provides
@Singleton
protected GridJobAsyncClient provideJobClient(RestClientFactory factory) {
return factory.create(GridJobAsyncClient.class);
}
@Provides
@Singleton
public GridJobClient provideJobClient(GridJobAsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(GridJobClient.class, client);
}
@Provides
@Singleton
protected GridIpAsyncClient provideIpClient(RestClientFactory factory) {
return factory.create(GridIpAsyncClient.class);
}
@Provides
@Singleton
public GridIpClient provideIpClient(GridIpAsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(GridIpClient.class, client);
}
@Provides
@Singleton
@GoGrid

View File

@ -1,3 +1,26 @@
/**
*
* 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.domain;
/**

View File

@ -1,3 +1,26 @@
/**
*
* 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.domain;
/**

View File

@ -1,15 +1,41 @@
/**
*
* 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.domain;
import com.google.common.primitives.Longs;
import com.google.gson.annotations.SerializedName;
/**
* @author Oleksiy Yarmula
*/
public class Ip {
public class Ip implements Comparable<Ip> {
private long id;
private String ip;
private String subnet;
@SerializedName("public")
private boolean isPublic;
private Option state;
@ -72,4 +98,20 @@ public class Ip {
result = 31 * result + (state != null ? state.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Ip{" +
"id=" + id +
", ip='" + ip + '\'' +
", subnet='" + subnet + '\'' +
", isPublic=" + isPublic +
", state=" + state +
'}';
}
@Override
public int compareTo(Ip o) {
return Longs.compare(id, o.getId());
}
}

View File

@ -0,0 +1,32 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.domain;
import com.google.common.base.CaseFormat;
/**
* @author Oleksiy Yarmula
*/
public enum IpState {
UNASSIGNED, ASSIGNED;
public String toString() {
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()));
}
}

View File

@ -0,0 +1,42 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.domain;
/**
* @author Oleksiy Yarmula
*/
public enum IpType {
PRIVATE("Private"),
PRIVATE_2("Private 2"),
PUBLIC("Public"),
PUBLIC_2("Public 2"),
PUBLIC_3("Public 3"),
PUBLIC_4("Public 4");
final String name;
IpType(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}

View File

@ -0,0 +1,161 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.domain;
import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.Longs;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* Represents any job in GoGrid system
* (jobs include server creation, stopping, etc)
*
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API:Job_(Object)" />
* @author Oleksiy Yarmula
*/
public class Job implements Comparable<Job> {
private long id;
private Option command;
@SerializedName("objecttype")
private Option objectType;
@SerializedName("createdon")
private Date createdOn;
@SerializedName("lastupdatedon")
private Date lastUpdatedOn;
@SerializedName("currentstate")
private Option currentState;
private int attempts;
private String owner;
private List<JobState> history;
@SerializedName("detail") /*NOTE: as of Feb 28, 10,
there is a contradiction b/w the name in
documentation (details) and actual param
name (detail)*/
private Map<String, String> details;
/**
* A no-args constructor is required for deserialization
*/
public Job() {
}
public Job(long id, Option command, Option objectType,
Date createdOn, Date lastUpdatedOn, Option currentState,
int attempts, String owner, List<JobState> history,
Map<String, String> details) {
this.id = id;
this.command = command;
this.objectType = objectType;
this.createdOn = createdOn;
this.lastUpdatedOn = lastUpdatedOn;
this.currentState = currentState;
this.attempts = attempts;
this.owner = owner;
this.history = history;
this.details = details;
}
public long getId() {
return id;
}
public Option getCommand() {
return command;
}
public Option getObjectType() {
return objectType;
}
public Date getCreatedOn() {
return createdOn;
}
public Date getLastUpdatedOn() {
return lastUpdatedOn;
}
public Option getCurrentState() {
return currentState;
}
public int getAttempts() {
return attempts;
}
public String getOwner() {
return owner;
}
public List<JobState> getHistory() {
return history;
}
public Map<String, String> getDetails() {
return details;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Job job = (Job) o;
if (attempts != job.attempts) return false;
if (id != job.id) return false;
if (command != null ? !command.equals(job.command) : job.command != null) return false;
if (createdOn != null ? !createdOn.equals(job.createdOn) : job.createdOn != null) return false;
if (currentState != null ? !currentState.equals(job.currentState) : job.currentState != null) return false;
if (details != null ? !details.equals(job.details) : job.details != null) return false;
if (history != null ? !history.equals(job.history) : job.history != null) return false;
if (lastUpdatedOn != null ? !lastUpdatedOn.equals(job.lastUpdatedOn) : job.lastUpdatedOn != null) return false;
if (objectType != null ? !objectType.equals(job.objectType) : job.objectType != null) return false;
if (owner != null ? !owner.equals(job.owner) : job.owner != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (command != null ? command.hashCode() : 0);
result = 31 * result + (objectType != null ? objectType.hashCode() : 0);
result = 31 * result + (createdOn != null ? createdOn.hashCode() : 0);
result = 31 * result + (lastUpdatedOn != null ? lastUpdatedOn.hashCode() : 0);
result = 31 * result + (currentState != null ? currentState.hashCode() : 0);
result = 31 * result + attempts;
result = 31 * result + (owner != null ? owner.hashCode() : 0);
result = 31 * result + (history != null ? history.hashCode() : 0);
result = 31 * result + (details != null ? details.hashCode() : 0);
return result;
}
@Override
public int compareTo(Job o) {
if(createdOn != null && o.getCreatedOn() != null)
return Longs.compare(createdOn.getTime(), o.getCreatedOn().getTime());
return Longs.compare(id, o.getId());
}
}

View File

@ -0,0 +1,93 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.domain;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
/**
* State of a job.
*
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API:Job_State_(Object)"/>
*
* @author Oleksiy Yarmula
*/
public class JobState {
private long id;
@SerializedName("updatedon")
private Date updatedOn;
private Option state;
private String note;
/**
* A no-args constructor is required for deserialization
*/
public JobState() {
}
public JobState(long id, Date updatedOn, Option state, String note) {
this.id = id;
this.updatedOn = updatedOn;
this.state = state;
this.note = note;
}
public long getId() {
return id;
}
public Date getUpdatedOn() {
return updatedOn;
}
public Option getState() {
return state;
}
public String getNote() {
return note;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JobState jobState = (JobState) o;
if (id != jobState.id) return false;
if (note != null ? !note.equals(jobState.note) : jobState.note != null) return false;
if (state != null ? !state.equals(jobState.state) : jobState.state != null) return false;
if (updatedOn != null ? !updatedOn.equals(jobState.updatedOn) : jobState.updatedOn != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (updatedOn != null ? updatedOn.hashCode() : 0);
result = 31 * result + (state != null ? state.hashCode() : 0);
result = 31 * result + (note != null ? note.hashCode() : 0);
return result;
}
}

View File

@ -1,3 +1,26 @@
/**
*
* 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.domain;
/**

View File

@ -1,3 +1,26 @@
/**
*
* 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.domain;
import com.google.common.base.CaseFormat;

View File

@ -1,3 +1,26 @@
/**
*
* 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.domain;
import com.google.common.primitives.Longs;
@ -121,4 +144,20 @@ public class Server implements Comparable<Server> {
public int compareTo(Server o) {
return Longs.compare(id, o.getId());
}
@Override
public String toString() {
return "Server{" +
"id=" + id +
", isSandbox=" + isSandbox +
", name='" + name + '\'' +
", description='" + description + '\'' +
", state=" + state +
", type=" + type +
", ram=" + ram +
", os=" + os +
", ip=" + ip +
", image=" + image +
'}';
}
}

View File

@ -1,3 +1,26 @@
/**
*
* 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.domain;
import com.google.common.collect.ImmutableList;

View File

@ -1,3 +1,26 @@
/**
*
* 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.domain.internal;
import com.google.gson.annotations.SerializedName;

View File

@ -1,3 +1,26 @@
/**
*
* 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.domain.internal;
import java.util.SortedSet;

View File

@ -1,3 +1,26 @@
/**
*
* 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.filters;
import com.google.common.base.Throwables;

View File

@ -1,3 +1,26 @@
/**
*
* 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.functions;
import com.google.common.collect.Iterables;
@ -16,6 +39,9 @@ import java.lang.reflect.Type;
import static com.google.common.base.Preconditions.checkState;
/**
* Parses {@link org.jclouds.gogrid.domain.internal.ErrorResponse
* error response} from a json string.
*
* @author Oleksiy Yarmula
*/
@Singleton

View File

@ -0,0 +1,58 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.functions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.gogrid.domain.Ip;
import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
import org.jclouds.http.functions.ParseJson;
import javax.inject.Inject;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.SortedSet;
/**
* Parses {@link org.jclouds.gogrid.domain.Ip ips} from a json string.
*
* @author Oleksiy Yarmula
*/
public class ParseIpListFromJsonResponse extends ParseJson<SortedSet<Ip>> {
@Inject
public ParseIpListFromJsonResponse(Gson gson) {
super(gson);
}
public SortedSet<Ip> apply(InputStream stream) {
Type setType = new TypeToken<GenericResponseContainer<Ip>>() {
}.getType();
GenericResponseContainer<Ip> response;
try {
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
return response.getList();
}
}

View File

@ -0,0 +1,57 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.functions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
import org.jclouds.http.functions.ParseJson;
import javax.inject.Inject;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.SortedSet;
/**
* Parses {@link org.jclouds.gogrid.domain.Job jobs} from a json string.
*
* @author Oleksiy Yarmula
*/
public class ParseJobListFromJsonResponse extends ParseJson<SortedSet<Job>> {
@Inject
public ParseJobListFromJsonResponse(Gson gson) {
super(gson);
}
public SortedSet<Job> apply(InputStream stream) {
Type setType = new TypeToken<GenericResponseContainer<Job>>() {
}.getType();
GenericResponseContainer<Job> response;
try {
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
return response.getList();
}
}

View File

@ -1,19 +1,42 @@
/**
*
* 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.functions;
import com.google.common.collect.Iterables;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
import org.jclouds.http.functions.ParseJson;
import javax.inject.Inject;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.SortedSet;
/**
* Parses a single {@link Server} from a json string.
*
* This class delegates parsing to {@link ParseServerListFromJsonResponse}.
*
* @author Oleksiy Yarmula
*/
public class ParseServerFromJsonResponse extends ParseJson<Server> {
@ -24,14 +47,7 @@ public class ParseServerFromJsonResponse extends ParseJson<Server> {
}
public Server apply(InputStream stream) {
Type setType = new TypeToken<GenericResponseContainer<Server>>() {
}.getType();
GenericResponseContainer<Server> response;
try {
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
return Iterables.getOnlyElement(response.getList());
SortedSet<Server> allServers = new ParseServerListFromJsonResponse(gson).apply(stream);
return Iterables.getOnlyElement(allServers);
}
}

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>
@ -59,7 +41,7 @@ import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
/**
* This parses {@link Server servers} from a json string.
* Parses {@link Server servers} from a json string.
*
* @author Adrian Cole
*/

View File

@ -1,3 +1,26 @@
/**
*
* 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.handlers;
import com.google.common.io.Closeables;
@ -31,7 +54,6 @@ public class GoGridErrorHandler implements HttpErrorHandler {
Exception exception;
ErrorResponse error = parseErrorFromContentOrNull(response.getContent());
switch (response.getStatusCode()) {
//more cases to be added
default:
exception = error != null ?
new GoGridResponseException(command, response, error) :

View File

@ -1,9 +1,32 @@
/**
*
* 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.internal;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.jclouds.gogrid.GoGridAsyncClient;
import org.jclouds.gogrid.services.GridServerClient;
import org.jclouds.gogrid.services.*;
/**
* @author Oleksiy Yarmula
@ -11,15 +34,30 @@ import org.jclouds.gogrid.services.GridServerClient;
@Singleton
public class GoGridAsyncClientImpl implements GoGridAsyncClient {
private GridServerClient gridServerClient;
private GridServerAsyncClient gridServerAsyncClient;
private GridJobAsyncClient gridJobAsyncClient;
private GridIpAsyncClient gridIpAsyncClient;
@Inject
public GoGridAsyncClientImpl(GridServerClient gridServerClient) {
this.gridServerClient = gridServerClient;
public GoGridAsyncClientImpl(GridServerAsyncClient gridServerClient,
GridJobAsyncClient gridJobAsyncClient,
GridIpAsyncClient gridIpAsyncClient) {
this.gridServerAsyncClient = gridServerClient;
this.gridJobAsyncClient = gridJobAsyncClient;
this.gridIpAsyncClient = gridIpAsyncClient;
}
@Override
public GridServerClient getServerClient() {
return gridServerClient;
public GridServerAsyncClient getServerServices() {
return gridServerAsyncClient;
}
@Override
public GridJobAsyncClient getJobServices() {
return gridJobAsyncClient;
}
public GridIpAsyncClient getIpServices() {
return gridIpAsyncClient;
}
}

View File

@ -1,8 +1,33 @@
/**
*
* 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.internal;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.services.GridIpClient;
import org.jclouds.gogrid.services.GridJobClient;
import org.jclouds.gogrid.services.GridServerClient;
/**
@ -12,14 +37,30 @@ import org.jclouds.gogrid.services.GridServerClient;
public class GoGridClientImpl implements GoGridClient {
private GridServerClient gridServerClient;
private GridJobClient gridJobClient;
private GridIpClient gridIpClient;
@Inject
public GoGridClientImpl(GridServerClient gridServerClient) {
public GoGridClientImpl(GridServerClient gridServerClient,
GridJobClient gridJobClient,
GridIpClient gridIpClient) {
this.gridServerClient = gridServerClient;
this.gridJobClient = gridJobClient;
this.gridIpClient = gridIpClient;
}
@Override
public GridServerClient getServerClient() {
public GridServerClient getServerServices() {
return gridServerClient;
}
@Override
public GridJobClient getJobServices() {
return gridJobClient;
}
@Override
public GridIpClient getIpServices() {
return gridIpClient;
}
}

View File

@ -1,3 +1,26 @@
/**
*
* 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.options;
import org.jclouds.http.options.BaseHttpRequestOptions;

View File

@ -0,0 +1,64 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.options;
import org.jclouds.gogrid.domain.IpState;
import org.jclouds.gogrid.domain.IpType;
import org.jclouds.http.options.BaseHttpRequestOptions;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
/**
* @author Oleksiy Yarmula
*/
public class GetIpListOptions extends BaseHttpRequestOptions {
public static final GetIpListOptions NONE = new GetIpListOptions();
public GetIpListOptions onlyAssigned() {
checkState(!queryParameters.containsKey(IP_STATE_KEY), "Can't have multiple values for whether IP is assigned");
queryParameters.put(IP_STATE_KEY, IpState.ASSIGNED.toString());
return this;
}
public GetIpListOptions onlyUnassigned() {
checkState(!queryParameters.containsKey(IP_STATE_KEY), "Can't have multiple values for whether IP is assigned");
queryParameters.put(IP_STATE_KEY, IpState.UNASSIGNED.toString());
return this;
}
public GetIpListOptions onlyWithType(IpType type) {
checkState(!queryParameters.containsKey(IP_TYPE_KEY), "Can't have multiple values for ip type limit");
queryParameters.put(IP_TYPE_KEY, type.toString());
return this;
}
public static class Builder {
public GetIpListOptions create() {
return new GetIpListOptions();
}
public GetIpListOptions limitToType(IpType type) {
return new GetIpListOptions().onlyWithType(type);
}
}
}

View File

@ -0,0 +1,90 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.options;
import org.jclouds.http.options.BaseHttpRequestOptions;
import java.util.Date;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
/**
* @author Oleksiy Yarmula
*/
public class GetJobListOptions extends BaseHttpRequestOptions {
public static final GetJobListOptions NONE = new GetJobListOptions();
public GetJobListOptions maxItemsNumber(Integer maxNumber) {
checkState(!queryParameters.containsKey(MAX_NUMBER_KEY), "Can't have duplicate parameter of max returned items");
queryParameters.put(MAX_NUMBER_KEY, maxNumber.toString());
return this;
}
public GetJobListOptions withStartDate(Date startDate) {
checkState(!queryParameters.containsKey(START_DATE_KEY), "Can't have duplicate start date for filtering");
queryParameters.put(START_DATE_KEY, String.valueOf(startDate.getTime()));
return this;
}
public GetJobListOptions withEndDate(Date endDate) {
checkState(!queryParameters.containsKey(END_DATE_KEY), "Can't have duplicate end date for filtering");
queryParameters.put(END_DATE_KEY, String.valueOf(endDate.getTime()));
return this;
}
public GetJobListOptions withOwner(String owner) {
checkState(!queryParameters.containsKey(OWNER_KEY), "Can't have duplicate owner name for filtering");
queryParameters.put(OWNER_KEY, owner);
return this;
}
public GetJobListOptions onlyForState(String jobState) {
checkState(!queryParameters.containsKey(JOB_STATE_KEY), "Can't have duplicate job state for filtering");
queryParameters.put(JOB_STATE_KEY, jobState);
return this;
}
public GetJobListOptions onlyForObjectType(String objectType) {
checkState(!queryParameters.containsKey(JOB_OBJECT_TYPE_KEY), "Can't have duplicate object type for filtering");
queryParameters.put(JOB_OBJECT_TYPE_KEY, objectType);
return this;
}
public GetJobListOptions onlyForObjectName(String objectName) {
checkState(!queryParameters.containsKey(OBJECT_KEY), "Can't have duplicate object name for filtering");
queryParameters.put(OBJECT_KEY, objectName);
return this;
}
public static class Builder {
public GetJobListOptions create() {
return new GetJobListOptions();
}
public GetJobListOptions latestJobForServerByName(String serverName) {
return new GetJobListOptions().
maxItemsNumber(1).
onlyForObjectType("VirtualServer").
onlyForObjectName(serverName);
}
}
}

View File

@ -1,3 +1,26 @@
/**
*
* 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.options;
import org.jclouds.http.options.BaseHttpRequestOptions;

View File

@ -0,0 +1,67 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.predicates;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.options.GetJobListOptions;
import org.jclouds.gogrid.services.GridJobClient;
import org.jclouds.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Singleton;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Checks if the latest job for the server is in "Succeeded" state.
* To achieve meaningful results, this must be run in a sequential
* environment when a server has only one job related to it at a time.
*
* The passed server instance must not be null and must have a name.
*
* @author Oleksiy Yarmula
*/
@Singleton
public class ServerLatestJobCompleted implements Predicate<Server> {
protected GridJobClient jobClient;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public ServerLatestJobCompleted(GridJobClient jobClient) {
this.jobClient = jobClient;
}
@Override
public boolean apply(Server server) {
checkNotNull(server, "Server must be a valid instance");
checkNotNull(server.getName(), "Server must be a valid name");
GetJobListOptions jobOptions = new GetJobListOptions.Builder().
latestJobForServerByName(server.getName());
Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(jobOptions));
return "Succeeded".equals(latestJob.getCurrentState().getName());
}
}

View File

@ -1,3 +1,26 @@
/**
*
* 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.reference;
/**

View File

@ -1,3 +1,26 @@
/**
*
* 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.reference;
/**
@ -19,4 +42,19 @@ public interface GoGridQueryParams {
public static final String DESCRIPTION_KEY = "server.ram";
public static final String POWER_KEY = "power";
public static final String MAX_NUMBER_KEY = "num_items";
public static final String START_DATE_KEY = "startdate";
public static final String END_DATE_KEY = "enddate";
public static final String OWNER_KEY = "owner";
public static final String JOB_STATE_KEY = "job.state";
public static final String JOB_OBJECT_TYPE_KEY = "job.objecttype";
public static final String OBJECT_KEY = "object";
public static final String IP_STATE_KEY = "ip.state";
public static final String IP_TYPE_KEY = "ip.type";
}

View File

@ -0,0 +1,76 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.services;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.gogrid.GoGrid;
import org.jclouds.gogrid.domain.Ip;
import org.jclouds.gogrid.domain.IpState;
import org.jclouds.gogrid.domain.IpType;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.gogrid.functions.ParseIpListFromJsonResponse;
import org.jclouds.gogrid.options.GetIpListOptions;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import java.util.Set;
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_STATE_KEY;
/**
* @author Oleksiy Yarmula
*/
@Endpoint(GoGrid.class)
@RequestFilters(SharedKeyLiteAuthentication.class)
@QueryParams(keys = VERSION, values = "1.3")
public interface GridIpAsyncClient {
/**
* @see GridIpClient#getIpList(org.jclouds.gogrid.options.GetIpListOptions...)
*/
@GET
@ResponseParser(ParseIpListFromJsonResponse.class)
@Path("/grid/ip/list")
ListenableFuture<Set<Ip>> getIpList(GetIpListOptions... options);
/**
* @see org.jclouds.gogrid.services.GridIpClient#getUnassignedIpList()
*/
@GET
@ResponseParser(ParseIpListFromJsonResponse.class)
@Path("/grid/ip/list")
@QueryParams(keys = IP_STATE_KEY, values = "Unassigned")
ListenableFuture<Set<Ip>> getUnassignedIpList();
/**
* @see org.jclouds.gogrid.services.GridIpClient#getAssignedIpList()
*/
@GET
@ResponseParser(ParseIpListFromJsonResponse.class)
@Path("/grid/ip/list")
@QueryParams(keys = IP_STATE_KEY, values = "Assigned")
ListenableFuture<Set<Ip>> getAssignedIpList();
}

View File

@ -0,0 +1,53 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.services;
import org.jclouds.concurrent.Timeout;
import org.jclouds.gogrid.domain.Ip;
import org.jclouds.gogrid.options.GetIpListOptions;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* @author Oleksiy Yarmula
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface GridIpClient {
/**
* Returns all IPs in the system
* that match the options
* @param options options to narrow the search down
* @return IPs found by the search
*/
Set<Ip> getIpList(GetIpListOptions... options);
/**
* Returns the list of unassigned IPs
* @return unassigned IPs
*/
Set<Ip> getUnassignedIpList();
/**
* Returns the list of assigned IPs
* @return assigned IPs
*/
Set<Ip> getAssignedIpList();
}

View File

@ -0,0 +1,71 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.services;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.gogrid.GoGrid;
import org.jclouds.gogrid.binders.BindIdsToQueryParams;
import org.jclouds.gogrid.binders.BindObjectNameToGetJobsRequestQueryParams;
import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.gogrid.functions.ParseJobListFromJsonResponse;
import org.jclouds.gogrid.options.GetJobListOptions;
import org.jclouds.rest.annotations.*;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import java.util.Set;
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
/**
* @author Oleksiy Yarmula
*/
@Endpoint(GoGrid.class)
@RequestFilters(SharedKeyLiteAuthentication.class)
@QueryParams(keys = VERSION, values = "1.3")
public interface GridJobAsyncClient {
/**
* @see GridJobClient#getJobList(org.jclouds.gogrid.options.GetJobListOptions...)
*/
@GET
@ResponseParser(ParseJobListFromJsonResponse.class)
@Path("/grid/job/list")
ListenableFuture<Set<Job>> getJobList(GetJobListOptions... options);
/**
* @see GridJobClient#getJobsForObjectName(String)
*/
@GET
@ResponseParser(ParseJobListFromJsonResponse.class)
@Path("/grid/job/list")
ListenableFuture<Set<Job>> getJobsForObjectName(
@BinderParam(BindObjectNameToGetJobsRequestQueryParams.class) String objectName);
/**
* @see GridJobClient#getJobsById(Long...)
*/
@GET
@ResponseParser(ParseJobListFromJsonResponse.class)
@Path("/grid/job/get")
ListenableFuture<Set<Job>> getJobsById(@BinderParam(BindIdsToQueryParams.class) Long... ids);
}

View File

@ -0,0 +1,76 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.services;
import org.jclouds.concurrent.Timeout;
import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.options.GetJobListOptions;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Manages the customer's jobs.
*
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API#Job_Methods" />
*
* @author Oleksiy Yarmula
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface GridJobClient {
/**
* Returns all jobs found.
* The resulting set may be narrowed
* down by providing {@link GetJobListOptions}.
*
* By default, the result is <=100 items from
* the date range of 4 weeks ago to now.
*
* NOTE: this method results in a big
* volume of data in response
*
* @return
* jobs found by request
*/
Set<Job> getJobList(GetJobListOptions... options);
/**
* Returns jobs found for an object with a provided name.
*
* Usually, in GoGrid a name will uniquely identify the object,
* or, as the docs state, some API methods will cause errors.
*
* @param serverName name of the object
* @return found jobs for the object
*/
Set<Job> getJobsForObjectName(String serverName);
/**
* Returns jobs for the corresponding id(s).
*
* NOTE: there is a 1:1 relation between a
* job and its ID.
*
* @param ids ids for the jobs
* @return jobs found by the ids
*/
Set<Job> getJobsById(Long... ids);
}

View File

@ -60,21 +60,33 @@ import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
@QueryParams(keys = VERSION, values = "1.3")
public interface GridServerAsyncClient {
/**
* @see GridServerClient#getServerList(org.jclouds.gogrid.options.GetServerListOptions...)
*/
@GET
@ResponseParser(ParseServerListFromJsonResponse.class)
@Path("/grid/server/list")
ListenableFuture<Set<Server>> getServerList(GetServerListOptions... getServerListOptions);
/**
* @see GridServerClient#getServersByName(String...)
*/
@GET
@ResponseParser(ParseServerListFromJsonResponse.class)
@Path("/grid/server/get")
ListenableFuture<Set<Server>> getServersByName(@BinderParam(BindNamesToQueryParams.class) String... names);
/**
* @see GridServerClient#getServersById(Long...)
*/
@GET
@ResponseParser(ParseServerListFromJsonResponse.class)
@Path("/grid/server/get")
ListenableFuture<Set<Server>> getServersById(@BinderParam(BindIdsToQueryParams.class) Long... ids);
/**
* @see GridServerClient#addServer(String, String, String, String, org.jclouds.gogrid.options.AddServerOptions...)
*/
@GET
@ResponseParser(ParseServerFromJsonResponse.class)
@Path("/grid/server/add")
@ -84,17 +96,26 @@ public interface GridServerAsyncClient {
@QueryParam(IP_KEY) String ip,
AddServerOptions... addServerOptions);
/**
* @see GridServerClient#power(String, org.jclouds.gogrid.domain.PowerCommand)
*/
@GET
@ResponseParser(ParseServerFromJsonResponse.class)
@Path("/grid/server/power")
ListenableFuture<Server> power(@QueryParam(SERVER_ID_OR_NAME_KEY) String idOrName,
@QueryParam(POWER_KEY) PowerCommand power);
/**
* @see GridServerClient#deleteById(Long)
*/
@GET
@ResponseParser(ParseServerFromJsonResponse.class)
@Path("/grid/server/delete")
ListenableFuture<Server> deleteById(@QueryParam(ID_KEY) Long id);
/**
* @see GridServerClient#deleteByName(String)
*/
@GET
@ResponseParser(ParseServerFromJsonResponse.class)
@Path("/grid/server/delete")

View File

@ -46,7 +46,7 @@ import org.jclouds.gogrid.options.GetServerListOptions;
public interface GridServerClient {
/**
* Retrieves the list of all servers.
* Returns the list of all servers.
*
* The result can be narrowed down by providing the options.
* @param getServerListOptions options to narrow down the result
@ -55,7 +55,7 @@ public interface GridServerClient {
Set<Server> getServerList(GetServerListOptions... getServerListOptions);
/**
* Retrieves the server(s) by unique name(s).
* Returns the server(s) by unique name(s).
*
* Given a name or a set of names, finds one or
* multiple servers.
@ -65,7 +65,7 @@ public interface GridServerClient {
Set<Server> getServersByName(String... names);
/**
* Retrieves the server(s) by unique id(s).
* Returns the server(s) by unique id(s).
*
* Given an id or a set of ids, finds one or
* multiple servers.

View File

@ -1,3 +1,26 @@
/**
*
* 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.util;
/**

View File

@ -0,0 +1,183 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid;
import com.google.common.collect.Iterables;
import org.jclouds.gogrid.domain.Ip;
import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.domain.PowerCommand;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.RetryablePredicate;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.util.*;
import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertNotNull;
import static java.lang.String.format;
/**
* End to end live test for GoGrid
*
* @author Oleksiy Yarmula
*/
@Test(groups = "live", testName = "gogrid.GoGridLiveTest")
public class GoGridLiveTest {
private GoGridClient client;
private RetryablePredicate<Server> latestJobCompleted;
/**
* Keeps track of the servers, created during the tests,
* to remove them after all tests complete
*/
private List<String> serversToDeleteAfterTheTests = new ArrayList<String>();
@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");
client = GoGridContextFactory.createContext(user, password, new Log4JLoggingModule())
.getApi();
latestJobCompleted = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client.getJobServices()),
240, 15, TimeUnit.SECONDS);
}
/**
* Tests server start, reboot and deletion.
* Also verifies IP services and job services.
*/
@Test(enabled=false)
public void testServerLifecycle() {
int serverCountBeforeTest = client.getServerServices().getServerList().size();
final String nameOfServer = "ServerCreated" + String.valueOf(new Date().getTime()).substring(8);
serversToDeleteAfterTheTests.add(nameOfServer);
Set<Ip> availableIps = client.getIpServices().getUnassignedIpList();
Ip availableIp = Iterables.getLast(availableIps);
Server createdServer = client.getServerServices().addServer(nameOfServer,
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
"1",
availableIp.getIp());
assertNotNull(createdServer);
assert latestJobCompleted.apply(createdServer);
//get server by name
Set<Server> response = client.getServerServices().getServersByName(nameOfServer);
assert (response.size() == 1);
//restart the server
client.getServerServices().power(nameOfServer, PowerCommand.RESTART);
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
assert("RestartVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName()));
assert latestJobCompleted.apply(createdServer);
int serverCountAfterAddingOneServer = client.getServerServices().getServerList().size();
assert serverCountAfterAddingOneServer == serverCountBeforeTest + 1 :
"There should be +1 increase in the number of servers since the test started";
//delete the server
client.getServerServices().deleteByName(nameOfServer);
jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
assert("DeleteVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName()));
assert latestJobCompleted.apply(createdServer);
int serverCountAfterDeletingTheServer = client.getServerServices().getServerList().size();
assert serverCountAfterDeletingTheServer == serverCountBeforeTest :
"There should be the same # of servers as since the test started";
//make sure that IP is put back to "unassigned"
assert client.getIpServices().getUnassignedIpList().contains(availableIp);
}
/**
* Starts a servers, verifies that jobs are created correctly and
* an be retrieved from the job services
*/
@Test(/*dependsOnMethods = "testServerLifecycle", */ enabled=false)
public void testJobs() {
final String nameOfServer = "ServerCreated" + String.valueOf(new Date().getTime()).substring(8);
serversToDeleteAfterTheTests.add(nameOfServer);
Set<Ip> availableIps = client.getIpServices().getUnassignedIpList();
Server createdServer = client.getServerServices().addServer(nameOfServer,
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
"1",
Iterables.getLast(availableIps).getIp());
assert latestJobCompleted.apply(createdServer);
//restart the server
client.getServerServices().power(nameOfServer, PowerCommand.RESTART);
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
Job latestJob = Iterables.getLast(jobs);
Long latestJobId = latestJob.getId();
Job latestJobFetched = Iterables.getOnlyElement(client.getJobServices().getJobsById(latestJobId));
assert latestJob.equals(latestJobFetched) : "Job and its reprentation found by ID don't match";
List<Long> idsOfAllJobs = new ArrayList<Long>();
for(Job job : jobs) {
idsOfAllJobs.add(job.getId());
}
Set<Job> jobsFetched = client.getJobServices().getJobsById(idsOfAllJobs.toArray(new Long[jobs.size()]));
assert jobsFetched.size() == jobs.size() : format("Number of jobs fetched by ids doesn't match the number of jobs " +
"requested. Requested/expected: %d. Found: %d.",
jobs.size(), jobsFetched.size());
//delete the server
client.getServerServices().deleteByName(nameOfServer);
}
/**
* In case anything went wrong during the tests, removes the objects
* created in the tests.
*/
@AfterTest
public void cleanup() {
for(String serverName : serversToDeleteAfterTheTests) {
try {
client.getServerServices().deleteByName(serverName);
} catch(Exception e) {
// it's already been deleted - proceed
}
}
}
}

View File

@ -0,0 +1,48 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.binders;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.Test;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
/**
* Tests that id bindings are proper for request
*
* @author Oleksiy Yarmula
*/
public class BindIdsToQueryParamsTest {
@Test
public void testBinding() {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
Long[] input = {123L, 456L};
BindIdsToQueryParams binder = new BindIdsToQueryParams();
request.addQueryParam("id", "123");
request.addQueryParam("id", "456");
replay(request);
binder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,49 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.binders;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.Test;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
/**
* Tests that name bindings are proper for request
*
* @author Oleksiy Yarmula
*/
public class BindNamesToQueryParamsTest {
@Test
public void testBinding() {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
String[] input = {"hello", "world"};
BindNamesToQueryParams binder = new BindNamesToQueryParams();
request.addQueryParam("name", "hello");
request.addQueryParam("name", "world");
replay(request);
binder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,60 @@
/**
*
* 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.functions;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.gogrid.config.GoGridContextModule;
import org.jclouds.gogrid.domain.internal.ErrorResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.net.UnknownHostException;
/**
* @author Oleksiy Yarmula
*/
public class ParseErrorFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
super.configure();
}
});
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
ParseErrorFromJsonResponse parser = new ParseErrorFromJsonResponse(i
.getInstance(Gson.class));
ErrorResponse response = parser.apply(is);
assert "No object found that matches your input criteria.".equals(response.getMessage());
assert "IllegalArgumentException".equals(response.getErrorCode());
}
}

View File

@ -26,7 +26,6 @@ package org.jclouds.gogrid.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Date;
@ -36,11 +35,8 @@ import com.google.common.collect.Iterables;
import org.jclouds.gogrid.config.GoGridContextModule;
import org.jclouds.gogrid.domain.*;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.date.DateService;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -60,7 +56,6 @@ public class ParseStatusesFromJsonResponseTest {
super.configure();
}
});
DateService dateService = new SimpleDateFormatDateService();
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_get_server_list.json");
@ -76,7 +71,7 @@ public class ParseStatusesFromJsonResponseTest {
webServer,
new Option(1L, "512MB", "Server with 512MB RAM"),
centOs,
new Ip(1313079L, "204.51.240.178", "204.51.240.176/255.255.255.240", false,
new Ip(1313079L, "204.51.240.178", "204.51.240.176/255.255.255.240", true,
new Option(2L, "Assigned", "IP is reserved or in use")),
new ServerImage(1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
"BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery",

View File

@ -1,3 +1,26 @@
/**
*
* 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.handlers;
import static org.testng.Assert.*;

View File

@ -1,3 +1,26 @@
/**
*
* 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.mock;
import org.jclouds.http.HttpCommand;

View File

@ -0,0 +1,142 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.services;
import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import org.jclouds.encryption.EncryptionService;
import org.jclouds.gogrid.GoGrid;
import org.jclouds.gogrid.domain.IpType;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.gogrid.functions.ParseIpListFromJsonResponse;
import org.jclouds.gogrid.functions.ParseJobListFromJsonResponse;
import org.jclouds.gogrid.options.GetIpListOptions;
import org.jclouds.gogrid.options.GetJobListOptions;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import javax.inject.Singleton;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Date;
import static org.testng.Assert.assertEquals;
/**
* @author Oleksiy Yarmula
*/
public class GridIpAsyncClientTest extends RestClientTest<GridIpAsyncClient> {
@Test
public void testGetIpListWithOptions() throws NoSuchMethodException, IOException {
Method method = GridIpAsyncClient.class.getMethod("getIpList", GetIpListOptions[].class);
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method,
new GetIpListOptions().onlyUnassigned().onlyWithType(IpType.PUBLIC));
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&" +
"ip.type=Public HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&" +
"ip.type=Public&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
"HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null);
}
@Test
public void testGetAssignedIpList() throws NoSuchMethodException, IOException {
Method method = GridIpAsyncClient.class.getMethod("getAssignedIpList");
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned&" +
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
"HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null);
}
@Override
protected void checkFilters(GeneratedHttpRequest<GridIpAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<GridIpAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<GridIpAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
URI.create("https://api.gogrid.com/api"));
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
}
@Provides
@Singleton
public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService)
throws UnsupportedEncodingException {
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
}
};
}
}

View File

@ -0,0 +1,171 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.gogrid.services;
import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import org.jclouds.encryption.EncryptionService;
import org.jclouds.gogrid.GoGrid;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.gogrid.functions.ParseJobListFromJsonResponse;
import org.jclouds.gogrid.options.GetJobListOptions;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import javax.inject.Singleton;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Date;
import static org.testng.Assert.assertEquals;
/**
* @author Oleksiy Yarmula
*/
public class GridJobAsyncClientTest extends RestClientTest<GridJobAsyncClient> {
@Test
public void testGetJobListWithOptions() throws NoSuchMethodException, IOException {
Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class);
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
new GetJobListOptions.Builder().
create().
withStartDate(new Date(1267385381770L)));
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770 HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770&" +
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
"HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null);
}
@Test
public void testGetJobsForServerName() throws NoSuchMethodException, IOException {
Method method = GridJobAsyncClient.class.getMethod("getJobsForObjectName", String.class);
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
"MyServer");
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&" +
"object=MyServer HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&" +
"object=MyServer&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
"HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null);
}
@Test
public void testGetJobsById() throws NoSuchMethodException, IOException {
Method method = GridJobAsyncClient.class.getMethod("getJobsById", Long[].class);
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
123L, 456L);
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/job/get?v=1.3&" +
"id=123&id=456 HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/job/get?v=1.3&" +
"id=123&id=456&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
"HTTP/1.1");
assertHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null);
}
@Override
protected void checkFilters(GeneratedHttpRequest<GridJobAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<GridJobAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<GridJobAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
URI.create("https://api.gogrid.com/api"));
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
}
@Provides
@Singleton
public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService)
throws UnsupportedEncodingException {
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
}
};
}
}

View File

@ -1,92 +0,0 @@
/**
*
* 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 static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.GoGridContextFactory;
import org.jclouds.gogrid.domain.PowerCommand;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.util.Set;
import static org.testng.Assert.assertNotNull;
/**
* Tests behavior of {@code GoGridClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "gogrid.GoGridClientLiveTest")
public class GridServerClientLiveTest {
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");
client = GoGridContextFactory.createContext(user, password, new Log4JLoggingModule())
.getApi();
}
@Test
public void testGetServerList() {
Set<Server> response = client.getServerClient().getServerList();
assert (response.size() > 0);
}
@Test
public void testGetServerByName() {
Set<Server> response = client.getServerClient().getServersByName("PowerServer", "AnotherTestServer");
assert (response.size() > 0);
}
@Test
public void testGetServerById() {
Set<Server> response = client.getServerClient().getServersById(75245L, 75523L);
assert (response.size() > 0);
}
@Test
public void testAddServer() {
Server createdServer = client.getServerClient().addServer("ServerCreatedFromAPI",
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
"1",
"204.51.240.189");
assertNotNull(createdServer);
}
@Test
public void testRestart() {
Server createdServer = client.getServerClient().power("PowerServer", PowerCommand.RESTART);
assertNotNull(createdServer);
}
}