mirror of https://github.com/apache/jclouds.git
Implemented update & create configuration APIs
This commit is contained in:
parent
de9691cccb
commit
00e7657a09
|
@ -23,13 +23,16 @@ import org.jclouds.cloudstack.domain.ConfigurationEntry;
|
|||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListConfigurationEntriesOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -56,4 +59,29 @@ public interface GlobalConfigurationAsyncClient extends ConfigurationAsyncClient
|
|||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<ConfigurationEntry>> listConfigurationEntries(ListConfigurationEntriesOptions... options);
|
||||
|
||||
/**
|
||||
* @see GlobalConfigurationClient#updateConfigurationEntry
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "updateConfiguration")
|
||||
@SelectJson("configuration")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<ConfigurationEntry> updateConfigurationEntry(
|
||||
@QueryParam("name") String name, @QueryParam("value") String value);
|
||||
|
||||
|
||||
/**
|
||||
* @see GlobalConfigurationClient#createConfigurationEntry
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "createConfiguration")
|
||||
@SelectJson("configuration")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<ConfigurationEntry> createConfigurationEntry(@QueryParam("category")String category,
|
||||
@QueryParam("component") String component, @QueryParam("instance") String instance,
|
||||
@QueryParam("name") String name, @QueryParam("description") String description,
|
||||
@QueryParam("value") String value);
|
||||
|
||||
}
|
||||
|
|
|
@ -47,4 +47,36 @@ public interface GlobalConfigurationClient extends ConfigurationClient {
|
|||
*/
|
||||
Set<ConfigurationEntry> listConfigurationEntries(ListConfigurationEntriesOptions... options);
|
||||
|
||||
/**
|
||||
* Update a configuration entry
|
||||
*
|
||||
* @param name
|
||||
* the name of the configuration
|
||||
* @param value
|
||||
* the value of the configuration
|
||||
* @return
|
||||
* the updated configuration value
|
||||
*/
|
||||
ConfigurationEntry updateConfigurationEntry(String name, String value);
|
||||
|
||||
/**
|
||||
* Create a new configuration value
|
||||
*
|
||||
* @param category
|
||||
* the component category
|
||||
* @param component
|
||||
* the component of the configuration
|
||||
* @param instance
|
||||
* the instance of the configuration
|
||||
* @param name
|
||||
* the name of the configuration
|
||||
* @param description
|
||||
* the description of the configuration
|
||||
* @param value
|
||||
* the value of the configuration
|
||||
* @return
|
||||
*/
|
||||
ConfigurationEntry createConfigurationEntry(String category, String component,
|
||||
String instance, String name, String description, String value );
|
||||
|
||||
}
|
||||
|
|
|
@ -18,13 +18,22 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.cloudstack.domain.ConfigurationEntry;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.collections.Sets;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static org.jclouds.cloudstack.options.ListConfigurationEntriesOptions.Builder.name;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GlobalConfigurationClient}
|
||||
*
|
||||
|
@ -41,7 +50,7 @@ public class GlobalConfigurationClientLiveTest extends BaseCloudStackClientLiveT
|
|||
.getConfigurationClient().listConfigurationEntries();
|
||||
|
||||
Set<String> categories = Sets.newHashSet();
|
||||
for(ConfigurationEntry entry : entries) {
|
||||
for (ConfigurationEntry entry : entries) {
|
||||
checkConfigurationEntry(entry);
|
||||
categories.add(entry.getCategory());
|
||||
}
|
||||
|
@ -50,9 +59,55 @@ public class GlobalConfigurationClientLiveTest extends BaseCloudStackClientLiveT
|
|||
"Storage", "Usage", "Snapshots", "Account Defaults", "Console Proxy", "Alert"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConfigurationEntry() {
|
||||
assert globalAdminEnabled;
|
||||
|
||||
Set<ConfigurationEntry> entries = globalAdminClient
|
||||
.getConfigurationClient().listConfigurationEntries();
|
||||
|
||||
long expungeDelay = Long.parseLong(getValueByName(entries, "expunge.delay"));
|
||||
assert expungeDelay > 0;
|
||||
|
||||
globalAdminClient.getConfigurationClient()
|
||||
.updateConfigurationEntry("expunge.delay", "" + (expungeDelay + 1));
|
||||
|
||||
long newDelay = Long.parseLong(getOnlyElement(globalAdminClient.getConfigurationClient()
|
||||
.listConfigurationEntries(name("expunge.delay"))).getValue());
|
||||
assertEquals(newDelay, expungeDelay + 1);
|
||||
|
||||
globalAdminClient.getConfigurationClient()
|
||||
.updateConfigurationEntry("expunge.delay", "" + expungeDelay);
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testCreateConfigurationEntry() {
|
||||
assert globalAdminEnabled;
|
||||
|
||||
ConfigurationEntry result = globalAdminClient.getConfigurationClient()
|
||||
.createConfigurationEntry("Advanced", "component",
|
||||
"instance", prefix + "-jclouds", "description", "jclouds");
|
||||
checkConfigurationEntry(result);
|
||||
}
|
||||
|
||||
private void checkConfigurationEntry(ConfigurationEntry entry) {
|
||||
assertEquals(entry, getEntryByName(globalAdminClient.getConfigurationClient()
|
||||
.listConfigurationEntries(), entry.getName()));
|
||||
assert entry.getCategory() != null : entry;
|
||||
assert entry.getDescription() != null : entry;
|
||||
assert entry.getName() != null : entry;
|
||||
}
|
||||
|
||||
private String getValueByName(Set<ConfigurationEntry> entries, String name) {
|
||||
return getEntryByName(entries, name).getValue();
|
||||
}
|
||||
|
||||
private ConfigurationEntry getEntryByName(Set<ConfigurationEntry> entries, final String name) {
|
||||
return Iterables.find(entries, new Predicate<ConfigurationEntry>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable ConfigurationEntry entry) {
|
||||
return entry != null && Objects.equal(name, entry.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue