mirror of https://github.com/apache/jclouds.git
Implemented Domain API for Domain Admin
This commit is contained in:
parent
ea81b058a4
commit
e608674f93
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.cloudstack;
|
||||
|
||||
import org.jclouds.cloudstack.features.DomainAccountAsyncClient;
|
||||
import org.jclouds.cloudstack.features.DomainDomainAsyncClient;
|
||||
import org.jclouds.cloudstack.features.DomainLimitAsyncClient;
|
||||
import org.jclouds.cloudstack.features.DomainUserAsyncClient;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
@ -55,4 +56,10 @@ public interface CloudStackDomainAsyncClient extends CloudStackAsyncClient {
|
|||
@Delegate
|
||||
DomainUserAsyncClient getUserClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Domains
|
||||
*/
|
||||
@Delegate
|
||||
DomainDomainAsyncClient getDomainClient();
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudstack;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.features.DomainAccountClient;
|
||||
import org.jclouds.cloudstack.features.DomainDomainClient;
|
||||
import org.jclouds.cloudstack.features.DomainLimitClient;
|
||||
import org.jclouds.cloudstack.features.DomainUserClient;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
@ -58,4 +59,10 @@ public interface CloudStackDomainClient extends CloudStackClient {
|
|||
*/
|
||||
@Delegate
|
||||
DomainUserClient getUserClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Domains
|
||||
*/
|
||||
@Delegate
|
||||
DomainDomainClient getDomainClient();
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ import org.jclouds.cloudstack.features.ConfigurationAsyncClient;
|
|||
import org.jclouds.cloudstack.features.ConfigurationClient;
|
||||
import org.jclouds.cloudstack.features.DomainAccountAsyncClient;
|
||||
import org.jclouds.cloudstack.features.DomainAccountClient;
|
||||
import org.jclouds.cloudstack.features.DomainDomainAsyncClient;
|
||||
import org.jclouds.cloudstack.features.DomainDomainClient;
|
||||
import org.jclouds.cloudstack.features.DomainLimitAsyncClient;
|
||||
import org.jclouds.cloudstack.features.DomainLimitClient;
|
||||
import org.jclouds.cloudstack.features.DomainUserAsyncClient;
|
||||
|
@ -144,6 +146,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
|
|||
.put(AccountClient.class, AccountAsyncClient.class)//
|
||||
.put(DomainAccountClient.class, DomainAccountAsyncClient.class)//
|
||||
.put(DomainUserClient.class, DomainUserAsyncClient.class)//
|
||||
.put(DomainDomainClient.class, DomainDomainAsyncClient.class)//
|
||||
.put(GlobalAccountClient.class, GlobalAccountAsyncClient.class)//
|
||||
.put(GlobalUserClient.class, GlobalUserAsyncClient.class)//
|
||||
.put(EventClient.class, EventAsyncClient.class)//
|
||||
|
|
|
@ -0,0 +1,192 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Representation of the API domain response
|
||||
*
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
public class Domain implements Comparable<Domain> {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private long id;
|
||||
private boolean hasChild;
|
||||
private long level;
|
||||
private String name;
|
||||
private String networkDomain;
|
||||
private long parentDomainId;
|
||||
private String parentDomainName;
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hasChild(boolean hasChild) {
|
||||
this.hasChild = hasChild;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder level(long level) {
|
||||
this.level = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder networkDomain(String networkDomain) {
|
||||
this.networkDomain = networkDomain;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parentDomainId(long parentDomainId) {
|
||||
this.parentDomainId = parentDomainId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parentDomainName(String parentDomainName) {
|
||||
this.parentDomainName = parentDomainName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Domain build() {
|
||||
return new Domain(id, hasChild, level, name, networkDomain,
|
||||
parentDomainId, parentDomainName);
|
||||
}
|
||||
}
|
||||
|
||||
// for deserialization
|
||||
Domain() {
|
||||
}
|
||||
|
||||
private long id;
|
||||
@SerializedName("haschild")
|
||||
private boolean hasChild;
|
||||
private long level;
|
||||
private String name;
|
||||
@SerializedName("networkdomain")
|
||||
private String networkDomain;
|
||||
@SerializedName("parentdomainid")
|
||||
private long parentDomainId;
|
||||
@SerializedName("parentdomainname")
|
||||
private String parentDomainName;
|
||||
|
||||
public Domain(long id, boolean hasChild, long level, String name, String networkDomain,
|
||||
long parentDomainId, String parentDomainName) {
|
||||
this.id = id;
|
||||
this.hasChild = hasChild;
|
||||
this.level = level;
|
||||
this.name = name;
|
||||
this.networkDomain = networkDomain;
|
||||
this.parentDomainId = parentDomainId;
|
||||
this.parentDomainName = parentDomainName;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean hasChild() {
|
||||
return hasChild;
|
||||
}
|
||||
|
||||
public long getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getNetworkDomain() {
|
||||
return networkDomain;
|
||||
}
|
||||
|
||||
public long getParentDomainId() {
|
||||
return parentDomainId;
|
||||
}
|
||||
|
||||
public String getParentDomainName() {
|
||||
return parentDomainName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Domain domain = (Domain) o;
|
||||
|
||||
if (hasChild != domain.hasChild) return false;
|
||||
if (id != domain.id) return false;
|
||||
if (level != domain.level) return false;
|
||||
if (parentDomainId != domain.parentDomainId) return false;
|
||||
if (name != null ? !name.equals(domain.name) : domain.name != null)
|
||||
return false;
|
||||
if (networkDomain != null ? !networkDomain.equals(domain.networkDomain) : domain.networkDomain != null)
|
||||
return false;
|
||||
if (parentDomainName != null ? !parentDomainName.equals(domain.parentDomainName) : domain.parentDomainName != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) (id ^ (id >>> 32));
|
||||
result = 31 * result + (hasChild ? 1 : 0);
|
||||
result = 31 * result + (int) (level ^ (level >>> 32));
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (networkDomain != null ? networkDomain.hashCode() : 0);
|
||||
result = 31 * result + (int) (parentDomainId ^ (parentDomainId >>> 32));
|
||||
result = 31 * result + (parentDomainName != null ? parentDomainName.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Domain{" +
|
||||
"id=" + id +
|
||||
", hasChild=" + hasChild +
|
||||
", level=" + level +
|
||||
", name='" + name + '\'' +
|
||||
", networkDomain='" + networkDomain + '\'' +
|
||||
", parentDomainId=" + parentDomainId +
|
||||
", parentDomainName='" + parentDomainName + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Domain arg0) {
|
||||
return new Long(id).compareTo(arg0.getId());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* 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.Domain;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListDomainChildrenOptions;
|
||||
import org.jclouds.cloudstack.options.ListDomainsOptions;
|
||||
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 Domain features available to Domain
|
||||
* Admin users.
|
||||
*
|
||||
* @author Andrei Savu
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Domain_Admin.html"
|
||||
* />
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface DomainDomainAsyncClient {
|
||||
|
||||
/**
|
||||
* @see DomainDomainClient#listDomains
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listDomains")
|
||||
@SelectJson("domain")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Domain>> listDomains(ListDomainsOptions... options);
|
||||
|
||||
/**
|
||||
* @see DomainDomainClient#getDomainById
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listDomains")
|
||||
@SelectJson("domain")
|
||||
@OnlyElement
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Domain> getDomainById(@QueryParam("id") long domainId);
|
||||
|
||||
/**
|
||||
* @see DomainDomainClient#listDomainChildren
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listDomainChildren")
|
||||
@SelectJson("domain")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Domain>> listDomainChildren(ListDomainChildrenOptions... options);
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* 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.Domain;
|
||||
import org.jclouds.cloudstack.options.ListDomainChildrenOptions;
|
||||
import org.jclouds.cloudstack.options.ListDomainsOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack Domain features available to Domain
|
||||
* Admin users.
|
||||
*
|
||||
* @author Andrei Savu
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Domain_Admin.html"
|
||||
* />
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface DomainDomainClient {
|
||||
|
||||
/**
|
||||
* List domains with detailed information
|
||||
*
|
||||
* @param options
|
||||
* list filtering optional arguments
|
||||
* @return
|
||||
* set of domain instances or empty
|
||||
*/
|
||||
Set<Domain> listDomains(ListDomainsOptions... options);
|
||||
|
||||
/**
|
||||
* Get a domain by ID
|
||||
*
|
||||
* @param domainId
|
||||
* domain ID
|
||||
* @return
|
||||
* domain instance or null
|
||||
*/
|
||||
Domain getDomainById(long domainId);
|
||||
|
||||
/**
|
||||
* Lists all children domains belonging to a specified domain
|
||||
*
|
||||
* @param options
|
||||
* list filtering optional arguments
|
||||
* @return
|
||||
* set of domain instances or empty
|
||||
*/
|
||||
Set<Domain> listDomainChildren(ListDomainChildrenOptions... options);
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* 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 domain children are returned
|
||||
*
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/domain_admin/listDomains.html"
|
||||
* />
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
public class ListDomainChildrenOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListDomainChildrenOptions NONE = new ListDomainChildrenOptions();
|
||||
|
||||
/**
|
||||
* @param parentDomainId
|
||||
* firewall rule ID
|
||||
*/
|
||||
public ListDomainChildrenOptions parentDomainId(long parentDomainId) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(parentDomainId + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isRecursive
|
||||
* to return the entire tree, use the value "true". To return
|
||||
* the first level children, use the value "false".
|
||||
*/
|
||||
public ListDomainChildrenOptions isRecursive(boolean isRecursive) {
|
||||
this.queryParameters.replaceValues("isrecursive", ImmutableSet.of(isRecursive + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param keyword
|
||||
* list by keyword
|
||||
*/
|
||||
public ListDomainChildrenOptions keyword(String keyword) {
|
||||
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* list by domain name
|
||||
*/
|
||||
public ListDomainChildrenOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListDomainChildrenOptions page(long page) {
|
||||
this.queryParameters.replaceValues("page", ImmutableSet.of(page + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListDomainChildrenOptions pageSize(long pageSize) {
|
||||
this.queryParameters.replaceValues("pagesize", ImmutableSet.of(pageSize + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListDomainChildrenOptions#parentDomainId
|
||||
*/
|
||||
public static ListDomainChildrenOptions parentDomainId(long parentDomainId) {
|
||||
ListDomainChildrenOptions options = new ListDomainChildrenOptions();
|
||||
return options.parentDomainId(parentDomainId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainChildrenOptions#isRecursive
|
||||
*/
|
||||
public static ListDomainChildrenOptions isRecursive(boolean isRecursive) {
|
||||
ListDomainChildrenOptions options = new ListDomainChildrenOptions();
|
||||
return options.isRecursive(isRecursive);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainChildrenOptions#keyword
|
||||
*/
|
||||
public static ListDomainChildrenOptions keyword(String keyword) {
|
||||
ListDomainChildrenOptions options = new ListDomainChildrenOptions();
|
||||
return options.keyword(keyword);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainChildrenOptions#name
|
||||
*/
|
||||
public static ListDomainChildrenOptions name(String name) {
|
||||
ListDomainChildrenOptions options = new ListDomainChildrenOptions();
|
||||
return options.name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainChildrenOptions#page
|
||||
*/
|
||||
public static ListDomainChildrenOptions page(long page) {
|
||||
ListDomainChildrenOptions options = new ListDomainChildrenOptions();
|
||||
return options.page(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainChildrenOptions#pageSize
|
||||
*/
|
||||
public static ListDomainChildrenOptions pageSize(long pageSize) {
|
||||
ListDomainChildrenOptions options = new ListDomainChildrenOptions();
|
||||
return options.pageSize(pageSize);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* 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 domains are returned
|
||||
*
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/domain_admin/listDomains.html"
|
||||
* />
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
public class ListDomainsOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListDomainsOptions NONE = new ListDomainsOptions();
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* firewall rule ID
|
||||
*/
|
||||
public ListDomainsOptions id(long id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param keyword
|
||||
* list by keyword
|
||||
*/
|
||||
public ListDomainsOptions keyword(String keyword) {
|
||||
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param level
|
||||
* list by domain level
|
||||
*/
|
||||
public ListDomainsOptions level(long level) {
|
||||
this.queryParameters.replaceValues("level", ImmutableSet.of(level + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* list by domain name
|
||||
*/
|
||||
public ListDomainsOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListDomainsOptions page(long page) {
|
||||
this.queryParameters.replaceValues("page", ImmutableSet.of(page + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListDomainsOptions pageSize(long pageSize) {
|
||||
this.queryParameters.replaceValues("pagesize", ImmutableSet.of(pageSize + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListDomainsOptions#id
|
||||
*/
|
||||
public static ListDomainsOptions id(long id) {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainsOptions#keyword
|
||||
*/
|
||||
public static ListDomainsOptions keyword(String keyword) {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
return options.keyword(keyword);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainsOptions#level
|
||||
*/
|
||||
public static ListDomainsOptions level(long level) {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
return options.level(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainsOptions#name
|
||||
*/
|
||||
public static ListDomainsOptions name(String name) {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
return options.name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainsOptions#page
|
||||
*/
|
||||
public static ListDomainsOptions page(long page) {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
return options.page(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDomainsOptions#pageSize
|
||||
*/
|
||||
public static ListDomainsOptions pageSize(long pageSize) {
|
||||
ListDomainsOptions options = new ListDomainsOptions();
|
||||
return options.pageSize(pageSize);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
/**
|
||||
* 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.CloudStackContext;
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.Domain;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.cloudstack.options.ListDomainChildrenOptions;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.cloudstack.options.ListDomainChildrenOptions.Builder.parentDomainId;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Test the CloudStack DomainDomainClient
|
||||
*
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@Test(groups = "unit", testName = "DomainDomainClientExpectTest")
|
||||
public class DomainDomainClientExpectTest extends BaseCloudStackRestClientExpectTest<DomainDomainClient> {
|
||||
|
||||
public void testListDomainsWhenResponseIs2xx() {
|
||||
DomainDomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&" +
|
||||
"command=listDomains&apiKey=identity&signature=MmzRB%2FpKlYyWy7kE3IMXrg4BUtk%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(200)
|
||||
.payload(payloadFromResource("/listdomainsresponse.json"))
|
||||
.build());
|
||||
|
||||
assertEquals(client.listDomains(),
|
||||
ImmutableSet.of(
|
||||
Domain.builder().id(1L).name("ROOT").level(0).hasChild(true).build(),
|
||||
Domain.builder().id(2L).name("jclouds1").level(1).parentDomainId(1)
|
||||
.parentDomainName("ROOT").hasChild(false).build()
|
||||
));
|
||||
}
|
||||
|
||||
public void testListDomainsWhenResponseIs404() {
|
||||
DomainDomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&" +
|
||||
"command=listDomains&apiKey=identity&signature=MmzRB%2FpKlYyWy7kE3IMXrg4BUtk%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(404)
|
||||
.build());
|
||||
|
||||
assertEquals(client.listDomains(), ImmutableSet.of());
|
||||
}
|
||||
|
||||
public void testGetDomainWhenResponseIs2xx() {
|
||||
DomainDomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&" +
|
||||
"command=listDomains&id=1&apiKey=identity&signature=emQKWkVhospRkaUzjKljME2rW0k%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(200)
|
||||
.payload(payloadFromResource("/getdomainresponse.json"))
|
||||
.build());
|
||||
|
||||
assertEquals(client.getDomainById(1),
|
||||
Domain.builder().id(1L).name("ROOT").level(0).hasChild(true).build());
|
||||
}
|
||||
|
||||
public void testGetDomainWhenResponseIs404() {
|
||||
DomainDomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&" +
|
||||
"command=listDomains&id=1&apiKey=identity&signature=emQKWkVhospRkaUzjKljME2rW0k%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(404)
|
||||
.build());
|
||||
|
||||
assertNull(client.getDomainById(1));
|
||||
}
|
||||
|
||||
public void testListDomainChildrenWhenResponseIs2xx() {
|
||||
DomainDomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&" +
|
||||
"command=listDomainChildren&id=1&isrecursive=true&apiKey=identity&signature=bDMSkjme8k0ANUPm4YiTYKe2N88%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(200)
|
||||
.payload(payloadFromResource("/listdomainchildrenresponse.json"))
|
||||
.build());
|
||||
|
||||
assertEquals(client.listDomainChildren(parentDomainId(1).isRecursive(true)),
|
||||
ImmutableSet.of(
|
||||
Domain.builder().id(2L).name("jclouds1").level(1).parentDomainId(1)
|
||||
.parentDomainName("ROOT").hasChild(false).build(),
|
||||
Domain.builder().id(3L).name("jclouds2").level(1).parentDomainId(1)
|
||||
.parentDomainName("ROOT").hasChild(false).build()
|
||||
));
|
||||
}
|
||||
|
||||
public void testListDomainChildrenWhenResponseIs404() {
|
||||
DomainDomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&" +
|
||||
"command=listDomainChildren&id=1&isrecursive=true&apiKey=identity&" +
|
||||
"signature=bDMSkjme8k0ANUPm4YiTYKe2N88%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(404)
|
||||
.build());
|
||||
|
||||
assertEquals(client.listDomainChildren(parentDomainId(1).isRecursive(true)), ImmutableSet.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DomainDomainClient clientFrom(CloudStackContext context) {
|
||||
return context.getDomainContext().getApi().getDomainClient();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
* 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.Predicate;
|
||||
import org.jclouds.cloudstack.domain.Domain;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static org.jclouds.cloudstack.options.ListDomainChildrenOptions.Builder.parentDomainId;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code DomainDomainClient}
|
||||
*
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "DomainDomainClientLiveTest")
|
||||
public class DomainDomainClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
@Test
|
||||
public void testListDomains() {
|
||||
assert domainAdminEnabled;
|
||||
|
||||
Set<Domain> allDomains = domainAdminClient.getDomainClient().listDomains();
|
||||
|
||||
Domain root = find(allDomains, withName("ROOT"));
|
||||
assertEquals(root, domainAdminClient.getDomainClient().getDomainById(root.getId()));
|
||||
assertEquals(root.getLevel(), 0);
|
||||
assertEquals(root.getParentDomainId(), 0);
|
||||
assertNull(root.getParentDomainName());
|
||||
if (allDomains.size() > 0) {
|
||||
assertTrue(root.hasChild());
|
||||
}
|
||||
|
||||
for (Domain domain : allDomains) {
|
||||
checkDomain(domain, allDomains);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListDomainChildren() {
|
||||
assert domainAdminEnabled;
|
||||
|
||||
Set<Domain> allDomains = domainAdminClient.getDomainClient().listDomains();
|
||||
Domain root = find(allDomains, withName("ROOT"));
|
||||
|
||||
Set<Domain> children = domainAdminClient.getDomainClient()
|
||||
.listDomainChildren(parentDomainId(root.getId()).isRecursive(true));
|
||||
assertEquals(allDomains.size() - 1, children.size());
|
||||
|
||||
for (Domain domain : children) {
|
||||
checkDomain(domain, allDomains);
|
||||
}
|
||||
}
|
||||
|
||||
private Predicate<Domain> withName(final String name) {
|
||||
return new Predicate<Domain>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable Domain domain) {
|
||||
return domain != null && domain.getName().equals(name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void checkDomain(Domain domain, Set<Domain> allDomains) {
|
||||
assert domain.getId() > 0 : domain;
|
||||
if (domain.getParentDomainName() != null) {
|
||||
Domain parent = find(allDomains, withName(domain.getParentDomainName()));
|
||||
assertEquals(parent.getId(), domain.getParentDomainId());
|
||||
assertTrue(parent.hasChild());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* 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.Domain;
|
||||
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 ListDomainsResponseTest extends BaseSetParserTest<Domain> {
|
||||
|
||||
@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 "/listdomainsresponse.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("domain")
|
||||
public Set<Domain> expected() {
|
||||
return ImmutableSet.of(
|
||||
Domain.builder().id(1L).name("ROOT").level(0).hasChild(true).build(),
|
||||
Domain.builder().id(2L).name("jclouds1").level(1).parentDomainId(1)
|
||||
.parentDomainName("ROOT").hasChild(false).build()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
{ "listdomainsresponse" : { "count":1 ,"domain" : [
|
||||
{"id":1,"name":"ROOT","level":0,"haschild":true} ] } }
|
|
@ -0,0 +1,3 @@
|
|||
{ "listdomainchildrenresponse" : { "count":2 ,"domain" : [
|
||||
{"id":2,"name":"jclouds1","level":1,"parentdomainid":1,"parentdomainname":"ROOT","haschild":false},
|
||||
{"id":3,"name":"jclouds2","level":1,"parentdomainid":1,"parentdomainname":"ROOT","haschild":false} ] } }
|
|
@ -0,0 +1,3 @@
|
|||
{ "listdomainsresponse" : { "count":2 ,"domain" : [
|
||||
{"id":1,"name":"ROOT","level":0,"haschild":true},
|
||||
{"id":2,"name":"jclouds1","level":1,"parentdomainid":1,"parentdomainname":"ROOT","haschild":false} ] } }
|
Loading…
Reference in New Issue