Skip to content
Permalink
Browse files
JCLOUDS-384 This makes autoscale and trove be consistent with other j…
…clouds APIs by renaming get*ApiFor* calls.
  • Loading branch information
zack-shoylev committed Nov 20, 2013
1 parent c0d9b1c commit 70e9ce8c1c5d2c0438a6d063316989859265dd34
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 145 deletions.
@@ -48,37 +48,37 @@ public interface TroveApi extends Closeable{
@Provides
@Zone
Set<String> getConfiguredZones();

/**
* Provides access to Flavor features.
*/
@Delegate
FlavorApi getFlavorApiForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);

/**
* Provides access to Instance features.
*/
@Delegate
InstanceApi getInstanceApiForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);

/**
* Provides access to User features.
*/
@Delegate
@Path("/instances/{instanceId}")
UserApi getUserApiForInstanceInZone(@PathParam("instanceId") String instanceId,
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
UserApi getUserApiForZoneAndInstance(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone,
@PathParam("instanceId") String instanceId);

/**
* Provides access to Database features.
*/
@Delegate
@Path("/instances/{instanceId}")
DatabaseApi getDatabaseApiForInstanceInZone(@PathParam("instanceId") String instanceId,
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
DatabaseApi getDatabaseApiForZoneAndInstance(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone,
@PathParam("instanceId") String instanceId);

/**
* Provides the Tenant.
*/
@@ -45,13 +45,13 @@ public void testCreateDatabaseSimple() {
responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint)
.method("POST")
.payload(payloadFromResourceWithContentType("/database_create_simple_request.json", MediaType.APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(202).build() // response
).getDatabaseApiForInstanceInZone("instanceId-1234-5678","RegionOne");

boolean result = api.create("testingdb");
assertTrue(result);
.payload(payloadFromResourceWithContentType("/database_create_simple_request.json", MediaType.APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(202).build() // response
).getDatabaseApiForZoneAndInstance("RegionOne", "instanceId-1234-5678");

boolean result = api.create("testingdb");
assertTrue(result);
}

public void testCreateDatabaseSimpleFail() {
@@ -61,13 +61,13 @@ public void testCreateDatabaseSimpleFail() {
responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint)
.method("POST")
.payload(payloadFromResourceWithContentType("/database_create_simple_request.json", MediaType.APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(404).build() // response
).getDatabaseApiForInstanceInZone("instanceId-1234-5678","RegionOne");

boolean result = api.create("testingdb");
assertFalse(result);
.payload(payloadFromResourceWithContentType("/database_create_simple_request.json", MediaType.APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(404).build() // response
).getDatabaseApiForZoneAndInstance("RegionOne", "instanceId-1234-5678");

boolean result = api.create("testingdb");
assertFalse(result);
}

public void testCreateDatabase() {
@@ -77,13 +77,13 @@ public void testCreateDatabase() {
responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint)
.method("POST")
.payload(payloadFromResourceWithContentType("/database_create_request.json", MediaType.APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(202).build() // response
).getDatabaseApiForInstanceInZone("instanceId-1234-5678","RegionOne");

boolean result = api.create("testingdb", "utf8", "utf8_general_ci");
assertTrue(result);
.payload(payloadFromResourceWithContentType("/database_create_request.json", MediaType.APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(202).build() // response
).getDatabaseApiForZoneAndInstance("RegionOne", "instanceId-1234-5678");

boolean result = api.create("testingdb", "utf8", "utf8_general_ci");
assertTrue(result);
}

public void testCreateDatabaseFail() {
@@ -93,13 +93,13 @@ public void testCreateDatabaseFail() {
responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint)
.method("POST")
.payload(payloadFromResourceWithContentType("/database_create_request.json", MediaType.APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(404).build() // response
).getDatabaseApiForInstanceInZone("instanceId-1234-5678","RegionOne");

boolean result = api.create("testingdb", "utf8", "utf8_general_ci");
assertFalse(result);
.payload(payloadFromResourceWithContentType("/database_create_request.json", MediaType.APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(404).build() // response
).getDatabaseApiForZoneAndInstance("RegionOne", "instanceId-1234-5678");

boolean result = api.create("testingdb", "utf8", "utf8_general_ci");
assertFalse(result);
}

public void testDeleteDatabase() {
@@ -108,13 +108,13 @@ public void testDeleteDatabase() {
keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint)
.method("DELETE")
.build(),
HttpResponse.builder().statusCode(202).build() // response
).getDatabaseApiForInstanceInZone("instanceId-1234-5678","RegionOne");
boolean result = api.delete("db1");
assertTrue(result);
.method("DELETE")
.build(),
HttpResponse.builder().statusCode(202).build() // response
).getDatabaseApiForZoneAndInstance("RegionOne", "instanceId-1234-5678");

boolean result = api.delete("db1");
assertTrue(result);
}

public void testDeleteDatabaseFail() {
@@ -123,39 +123,39 @@ public void testDeleteDatabaseFail() {
keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint)
.method("DELETE")
.build(),
HttpResponse.builder().statusCode(404).build() // response
).getDatabaseApiForInstanceInZone("instanceId-1234-5678","RegionOne");
boolean result = api.delete("db1");
assertFalse(result);
.method("DELETE")
.build(),
HttpResponse.builder().statusCode(404).build() // response
).getDatabaseApiForZoneAndInstance("RegionOne", "instanceId-1234-5678");

boolean result = api.delete("db1");
assertFalse(result);
}

public void testListDatabases() {
URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/databases");
DatabaseApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/database_list.json")).build()
).getDatabaseApiForInstanceInZone("instanceId-1234-5678","RegionOne");

List<String> databases = api.list().toList();
assertEquals(databases.size(), 5);
responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/database_list.json")).build()
).getDatabaseApiForZoneAndInstance("RegionOne", "instanceId-1234-5678");

List<String> databases = api.list().toList();
assertEquals(databases.size(), 5);
assertEquals(databases.iterator().next(), "anotherdb");
}

public void testListDatabasesFail() {
URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/databases");
DatabaseApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(404).payload(payloadFromResource("/database_list.json")).build()
).getDatabaseApiForInstanceInZone("instanceId-1234-5678","RegionOne");

Set<String> databases = api.list().toSet();
assertTrue(databases.isEmpty());
responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(404).payload(payloadFromResource("/database_list.json")).build()
).getDatabaseApiForZoneAndInstance("RegionOne", "instanceId-1234-5678");

Set<String> databases = api.list().toSet();
assertTrue(databases.isEmpty());
}
}
@@ -55,9 +55,9 @@ public void setup() {
instanceList.add(first);
instanceList.add(second);
instancesToDelete.put(zone, instanceList);
DatabaseApi databaseApiFirst = api.getDatabaseApiForInstanceInZone(first.getId(), zone);
DatabaseApi databaseApiSecond = api.getDatabaseApiForInstanceInZone(second.getId(), zone);

DatabaseApi databaseApiFirst = api.getDatabaseApiForZoneAndInstance(zone, first.getId());
DatabaseApi databaseApiSecond = api.getDatabaseApiForZoneAndInstance(zone, second.getId());
databaseApiFirst.create("livetest_db1");
databaseApiFirst.create("livetest_db2");
databaseApiSecond.create("livetest_db3");
@@ -83,7 +83,7 @@ public void testListDatabases() {
InstanceApi instanceApi = api.getInstanceApiForZone(zone);
assertTrue(instanceApi.list().size() >= 2);
for(Instance instance : instancesToDelete.get(zone)) {
DatabaseApi databaseApi = api.getDatabaseApiForInstanceInZone(instance.getId(), zone);
DatabaseApi databaseApi = api.getDatabaseApiForZoneAndInstance(zone, instance.getId());
if(!instance.getName().contains("database_testing"))continue;
assertTrue(databaseApi.list().size() >=1);
for(String database : databaseApi.list()){
@@ -92,14 +92,14 @@ public void testListDatabases() {
}
}
}

@Test
public void testDeleteDatabases() {
for (String zone : api.getConfiguredZones()) {
InstanceApi instanceApi = api.getInstanceApiForZone(zone);
assertTrue(instanceApi.list().size() >= 2);
for(Instance instance : instancesToDelete.get(zone)) {
DatabaseApi databaseApi = api.getDatabaseApiForInstanceInZone(instance.getId(), zone);
DatabaseApi databaseApi = api.getDatabaseApiForZoneAndInstance(zone, instance.getId());
if(!instance.getName().contains("database_testing"))continue;
assertTrue(databaseApi.list().size() >=1);
for(String database : databaseApi.list()){

0 comments on commit 70e9ce8

Please sign in to comment.