mirror of https://github.com/apache/jclouds.git
Merge pull request #304 from andreisavu/configuration-api
Global Configuration API
This commit is contained in:
commit
15621101da
|
@ -21,6 +21,8 @@ package org.jclouds.cloudstack;
|
|||
import org.jclouds.cloudstack.features.GlobalAccountAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalCapacityAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalConfigurationAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalConfigurationClient;
|
||||
import org.jclouds.cloudstack.features.GlobalHostAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalStoragePoolAsyncClient;
|
||||
|
@ -90,4 +92,11 @@ public interface CloudStackGlobalAsyncClient extends CloudStackDomainAsyncClient
|
|||
*/
|
||||
@Delegate
|
||||
GlobalUsageAsyncClient getUsageClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Configuration
|
||||
*/
|
||||
@Delegate
|
||||
@Override
|
||||
GlobalConfigurationAsyncClient getConfigurationClient();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.jclouds.cloudstack.features.GlobalAccountClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertClient;
|
||||
import org.jclouds.cloudstack.features.GlobalCapacityClient;
|
||||
import org.jclouds.cloudstack.features.GlobalConfigurationClient;
|
||||
import org.jclouds.cloudstack.features.GlobalHostClient;
|
||||
import org.jclouds.cloudstack.features.GlobalOfferingClient;
|
||||
import org.jclouds.cloudstack.features.GlobalStoragePoolClient;
|
||||
|
@ -94,4 +95,11 @@ public interface CloudStackGlobalClient extends CloudStackDomainClient {
|
|||
*/
|
||||
@Delegate
|
||||
GlobalUsageClient getUsageClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Configuration
|
||||
*/
|
||||
@Delegate
|
||||
@Override
|
||||
GlobalConfigurationClient getConfigurationClient();
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ import org.jclouds.cloudstack.features.GlobalAlertAsyncClient;
|
|||
import org.jclouds.cloudstack.features.GlobalAlertClient;
|
||||
import org.jclouds.cloudstack.features.GlobalCapacityAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalCapacityClient;
|
||||
import org.jclouds.cloudstack.features.GlobalConfigurationAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalConfigurationClient;
|
||||
import org.jclouds.cloudstack.features.GlobalHostAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalHostClient;
|
||||
import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient;
|
||||
|
@ -138,6 +140,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
|
|||
.put(GuestOSClient.class, GuestOSAsyncClient.class)//
|
||||
.put(HypervisorClient.class, HypervisorAsyncClient.class)//
|
||||
.put(ConfigurationClient.class, ConfigurationAsyncClient.class)//
|
||||
.put(GlobalConfigurationClient.class, GlobalConfigurationAsyncClient.class)//
|
||||
.put(AccountClient.class, AccountAsyncClient.class)//
|
||||
.put(DomainAccountClient.class, DomainAccountAsyncClient.class)//
|
||||
.put(DomainUserClient.class, DomainUserAsyncClient.class)//
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.cloudstack.domain;
|
||||
|
||||
/**
|
||||
* Representation of the API configuration entry response
|
||||
*
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
public class ConfigurationEntry implements Comparable<ConfigurationEntry> {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String category;
|
||||
private String description;
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
public Builder category(String category) {
|
||||
this.category = category;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder value(String value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfigurationEntry build() {
|
||||
return new ConfigurationEntry(category, description, name, value);
|
||||
}
|
||||
}
|
||||
|
||||
// for deserialization
|
||||
ConfigurationEntry() {
|
||||
}
|
||||
|
||||
private String category;
|
||||
private String description;
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
public ConfigurationEntry(String category, String description, String name, String value) {
|
||||
this.category = category;
|
||||
this.description = description;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ConfigurationEntry arg0) {
|
||||
return name.compareTo(arg0.getName());
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ConfigurationEntry that = (ConfigurationEntry) o;
|
||||
|
||||
if (category != null ? !category.equals(that.category) : that.category != null)
|
||||
return false;
|
||||
if (description != null ? !description.equals(that.description) : that.description != null)
|
||||
return false;
|
||||
if (name != null ? !name.equals(that.name) : that.name != null)
|
||||
return false;
|
||||
if (value != null ? !value.equals(that.value) : that.value != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = category != null ? category.hashCode() : 0;
|
||||
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConfigurationEntry{" +
|
||||
"category='" + category + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", value='" + value + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.cloudstack.features;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to CloudStack Configuration features available to Global
|
||||
* Admin users.
|
||||
*
|
||||
* @author Andrei Savu
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html"
|
||||
* />
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface GlobalConfigurationAsyncClient extends ConfigurationAsyncClient {
|
||||
|
||||
/**
|
||||
* @see GlobalConfigurationClient#listConfigurationEntries
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listConfigurations")
|
||||
@SelectJson("configuration")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@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);
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.cloudstack.features;
|
||||
|
||||
import org.jclouds.cloudstack.domain.ConfigurationEntry;
|
||||
import org.jclouds.cloudstack.options.ListConfigurationEntriesOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack Configuration features available to Global
|
||||
* Admin users.
|
||||
*
|
||||
* @author Andrei Savu
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html"
|
||||
* />
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface GlobalConfigurationClient extends ConfigurationClient {
|
||||
|
||||
/**
|
||||
* List all configuration entries
|
||||
*
|
||||
* @param options
|
||||
* result set filtering options
|
||||
* @return
|
||||
* a set of entries or empty
|
||||
*/
|
||||
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);
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.cloudstack.options;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Options used to control what configuration entries are returned
|
||||
*
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/global_admin/listConfigurations.html"
|
||||
* />
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
public class ListConfigurationEntriesOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListConfigurationEntriesOptions NONE = new ListConfigurationEntriesOptions();
|
||||
|
||||
/**
|
||||
* @param category
|
||||
* list by category name
|
||||
*/
|
||||
public ListConfigurationEntriesOptions category(String category) {
|
||||
this.queryParameters.replaceValues("category", ImmutableSet.of(category));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param keyword
|
||||
* list by keyword
|
||||
*/
|
||||
public ListConfigurationEntriesOptions keyword(String keyword) {
|
||||
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* list by entry name
|
||||
*/
|
||||
public ListConfigurationEntriesOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListConfigurationEntriesOptions page(long page) {
|
||||
this.queryParameters.replaceValues("page", ImmutableSet.of(page + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListConfigurationEntriesOptions pageSize(long pageSize) {
|
||||
this.queryParameters.replaceValues("pagesize", ImmutableSet.of(pageSize + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListConfigurationEntriesOptions#category
|
||||
*/
|
||||
public static ListConfigurationEntriesOptions category(String category) {
|
||||
ListConfigurationEntriesOptions options = new ListConfigurationEntriesOptions();
|
||||
return options.category(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListConfigurationEntriesOptions#keyword
|
||||
*/
|
||||
public static ListConfigurationEntriesOptions keyword(String keyword) {
|
||||
ListConfigurationEntriesOptions options = new ListConfigurationEntriesOptions();
|
||||
return options.keyword(keyword);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListConfigurationEntriesOptions#name
|
||||
*/
|
||||
public static ListConfigurationEntriesOptions name(String name) {
|
||||
ListConfigurationEntriesOptions options = new ListConfigurationEntriesOptions();
|
||||
return options.name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListConfigurationEntriesOptions#page
|
||||
*/
|
||||
public static ListConfigurationEntriesOptions page(long page) {
|
||||
ListConfigurationEntriesOptions options = new ListConfigurationEntriesOptions();
|
||||
return options.page(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListConfigurationEntriesOptions#pageSize
|
||||
*/
|
||||
public static ListConfigurationEntriesOptions pageSize(long pageSize) {
|
||||
ListConfigurationEntriesOptions options = new ListConfigurationEntriesOptions();
|
||||
return options.pageSize(pageSize);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.cloudstack.features;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.CloudStackContext;
|
||||
import org.jclouds.cloudstack.CloudStackGlobalClient;
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.ConfigurationEntry;
|
||||
import org.jclouds.cloudstack.domain.FirewallRule;
|
||||
import org.jclouds.cloudstack.domain.PortForwardingRule;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.BaseRestClientExpectTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Test the CloudStack GlobalConfigurationClient
|
||||
*
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@Test(groups = "unit", testName = "GlobalConfigurationClientExpectTest")
|
||||
public class GlobalConfigurationClientExpectTest extends BaseCloudStackRestClientExpectTest<GlobalConfigurationClient> {
|
||||
|
||||
@Test
|
||||
public void testListConfigurationEntriesWhenResponseIs2xx() {
|
||||
GlobalConfigurationClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&" +
|
||||
"command=listConfigurations&apiKey=identity&signature=FUQCDbc4TH2S%2B7ExDgrOCqKI2bw%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(200)
|
||||
.payload(payloadFromResource("/listconfigurationsresponse.json"))
|
||||
.build());
|
||||
|
||||
assertEquals(client.listConfigurationEntries(),
|
||||
ImmutableSet.of(
|
||||
ConfigurationEntry.builder().category("Advanced").name("account.cleanup.interval").value("86400")
|
||||
.description("The interval (in seconds) between cleanup for removed accounts").build(),
|
||||
ConfigurationEntry.builder().category("Advanced").name("agent.lb.enabled").value("true")
|
||||
.description("If agent load balancing enabled in cluster setup").build()
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListConfigurationEntriesEmptyOn404() {
|
||||
GlobalConfigurationClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&" +
|
||||
"command=listConfigurations&apiKey=identity&signature=FUQCDbc4TH2S%2B7ExDgrOCqKI2bw%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(404)
|
||||
.build());
|
||||
|
||||
assertEquals(client.listConfigurationEntries(), ImmutableSet.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConfigurationEntryWhenResponseIs2xx() {
|
||||
GlobalConfigurationClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&" +
|
||||
"command=updateConfiguration&name=expunge.delay&value=11&" +
|
||||
"apiKey=identity&signature=I2yG35EhfgIXYObeLfU3cvf%2BPeE%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(200)
|
||||
.payload(payloadFromResource("/updateconfigurationsresponse.json"))
|
||||
.build());
|
||||
|
||||
assertEquals(client.updateConfigurationEntry("expunge.delay", "11"),
|
||||
ConfigurationEntry.builder().category("Advanced").name("expunge.delay").value("11")
|
||||
.description("Determines how long (in seconds) to wait before actually expunging " +
|
||||
"destroyed vm. The default value = the default value of expunge.interval").build()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConfigurationEntryNullOn404() {
|
||||
GlobalConfigurationClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&" +
|
||||
"command=updateConfiguration&name=expunge.delay&value=11&" +
|
||||
"apiKey=identity&signature=I2yG35EhfgIXYObeLfU3cvf%2BPeE%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(404)
|
||||
.build());
|
||||
|
||||
assertNull(client.updateConfigurationEntry("expunge.delay", "11"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GlobalConfigurationClient clientFrom(CloudStackContext context) {
|
||||
return context.getGlobalContext().getApi().getConfigurationClient();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.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;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GlobalConfigurationClient}
|
||||
*
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "GlobalConfigurationClientLiveTest")
|
||||
public class GlobalConfigurationClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
@Test
|
||||
public void testListConfigurationEntries() {
|
||||
assert globalAdminEnabled;
|
||||
|
||||
Set<ConfigurationEntry> entries = globalAdminClient
|
||||
.getConfigurationClient().listConfigurationEntries();
|
||||
|
||||
Set<String> categories = Sets.newHashSet();
|
||||
for (ConfigurationEntry entry : entries) {
|
||||
checkConfigurationEntry(entry);
|
||||
categories.add(entry.getCategory());
|
||||
}
|
||||
|
||||
assert categories.containsAll(ImmutableSet.<Object>of("Network", "Advanced", "Premium",
|
||||
"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);
|
||||
}
|
||||
|
||||
private void checkConfigurationEntry(ConfigurationEntry entry) {
|
||||
assertEquals(entry, getEntryByName(globalAdminClient.getConfigurationClient()
|
||||
.listConfigurationEntries(name(entry.getName())), 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());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.cloudstack.parse;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.jclouds.cloudstack.config.CloudStackParserModule;
|
||||
import org.jclouds.cloudstack.domain.ConfigurationEntry;
|
||||
import org.jclouds.cloudstack.domain.FirewallRule;
|
||||
import org.jclouds.json.BaseSetParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListConfigurationEntriesResponseTest extends BaseSetParserTest<ConfigurationEntry> {
|
||||
|
||||
@Override
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new CloudStackParserModule(), new GsonModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/listconfigurationsresponse.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("configuration")
|
||||
public Set<ConfigurationEntry> expected() {
|
||||
return ImmutableSet.of(
|
||||
ConfigurationEntry.builder().category("Advanced").name("account.cleanup.interval").value("86400")
|
||||
.description("The interval (in seconds) between cleanup for removed accounts").build(),
|
||||
ConfigurationEntry.builder().category("Advanced").name("agent.lb.enabled").value("true")
|
||||
.description("If agent load balancing enabled in cluster setup").build()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{ "listconfigurationsresponse" : { "count":2 ,"configuration" : [
|
||||
{"category":"Advanced","name":"account.cleanup.interval","value":"86400","description":"The interval (in seconds) between cleanup for removed accounts"},
|
||||
{"category":"Advanced","name":"agent.lb.enabled","value":"true","description":"If agent load balancing enabled in cluster setup"}]
|
||||
}}
|
|
@ -0,0 +1,2 @@
|
|||
{ "updateconfigurationresponse" : { "configuration" :
|
||||
{"category":"Advanced","name":"expunge.delay","value":"11","description":"Determines how long (in seconds) to wait before actually expunging destroyed vm. The default value = the default value of expunge.interval"} } }
|
Loading…
Reference in New Issue