Skip to content

Commit

Permalink
Enhanced admin services by adding account and billing support classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
David R Young committed Jun 25, 2014
1 parent f1572f7 commit 06e8dfb
Show file tree
Hide file tree
Showing 12 changed files with 1,158 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/org/dasein/cloud/admin/AbstractAdminServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,24 @@ public PrepaymentSupport getPrepaymentSupport() {
public boolean hasPrepaymentSupport() {
return (getPrepaymentSupport() != null);
}

@Override
public AccountSupport getAccountSupport() {
return null;
}

@Override
public boolean hasAccountSupport() {
return (getAccountSupport() != null);
}

@Override
public BillingSupport getBillingSupport() {
return null;
}

@Override
public boolean hasBillingSupport() {
return (getBillingSupport() != null);
}
}
202 changes: 202 additions & 0 deletions src/main/java/org/dasein/cloud/admin/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
package org.dasein.cloud.admin;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nonnull;

import org.dasein.cloud.Tag;
import org.dasein.cloud.dc.DataCenter;

/**
* <p>
* An account container within a cloud. For clouds that support account
* hierarchies, accounts can be stacked using parentId.
* </p>
*
* @author David R Young (david.young@centurylink.com)
*/
public class Account {
private String accountId;
private AccountState state;
private String parentId;
private DataCenter primaryDataCenter;
private String name;
private String address1;
private String address2;
private String city;
private String stateProvince;
private String postalCode;
private String country;
private String telephoneNumber;
private String faxNumber;
private String timezone;
private Map<String, String> tags;
private String currency;

public Account() {
}

@Override
public boolean equals(Object ob) {
if (ob == null) {
return false;
}
if (ob == this) {
return true;
}
if (!getClass().getName().equals(ob.getClass().getName())) {
return false;
}
Account other = (Account) ob;

return getAccountId().equals(other.getAccountId());
}

public String getAccountId() {
return accountId;
}

public void setAccountId(String accountId) {
this.accountId = accountId;
}

public String getParentId() {
return parentId;
}

public void setParentId(String parentId) {
this.parentId = parentId;
}

public DataCenter getPrimaryDataCenter() {
return primaryDataCenter;
}

public void setPrimaryDataCenter(DataCenter primaryDataCenter) {
this.primaryDataCenter = primaryDataCenter;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAddress1() {
return address1;
}

public void setAddress1(String address1) {
this.address1 = address1;
}

public String getAddress2() {
return address2;
}

public void setAddress2(String address2) {
this.address2 = address2;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getStateProvince() {
return stateProvince;
}

public void setStateProvince(String stateProvince) {
this.stateProvince = stateProvince;
}

public String getPostalCode() {
return postalCode;
}

public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public String getTelephoneNumber() {
return telephoneNumber;
}

public void setTelephoneNumber(String telephoneNumber) {
this.telephoneNumber = telephoneNumber;
}

public String getFaxNumber() {
return faxNumber;
}

public void setFaxNumber(String faxNumber) {
this.faxNumber = faxNumber;
}

public String getTimezone() {
return timezone;
}

public void setTimezone(String timezone) {
this.timezone = timezone;
}

public synchronized Map<String, String> getTags() {
if (tags == null) {
tags = new HashMap<String, String>();
}
return tags;
}

public void setTag(@Nonnull String key, @Nonnull String value) {
if (tags == null) {
tags = new HashMap<String, String>();
}
tags.put(key, value);
}

public synchronized void setTags(Map<String, String> properties) {
getTags().clear();
getTags().putAll(properties);
}

public void addTag(Tag t) {
addTag(t.getKey(), t.getValue());
}

public void addTag(String key, String value) {
getTags().put(key, value);
}

public AccountState getState() {
return state;
}

public void setState(AccountState state) {
this.state = state;
}

public String getCurrency() {
return currency;
}

public void setCurrency(String currency) {
this.currency = currency;
}
}
115 changes: 115 additions & 0 deletions src/main/java/org/dasein/cloud/admin/AccountCapabilities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package org.dasein.cloud.admin;

import java.util.Locale;

import javax.annotation.Nonnull;

import org.dasein.cloud.Capabilities;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
import org.dasein.cloud.Requirement;

/**
* Describes the capabilities for accounts and account hierarchies within a
* cloud.
*
* @author David R Young (david.young@centurylink.com)
*/
public interface AccountCapabilities extends Capabilities {

/**
* Indicates whether or not sub accounts can be created for this cloud using
* a {@link AccountSupport#create(String)} call.
*
* @return true if sub accounts can be created, false if otherwise
* @throws CloudException
* the cloud provider encountered an error while processing the
* request
* @throws InternalException
* a Dasein Cloud error occurred while processing the request
*/
public boolean canCreate() throws InternalException, CloudException;

/**
* Indicates whether or not the cloud allows the input of a user-defined
* account identifier to be used during the account creation process.
* {@link org.dasein.cloud.Requirement#REQUIRED} means that an account id
* must be created by the caller and supplied;
* {@link org.dasein.cloud.Requirement#OPTIONAL} means that it may or may
* not be provided; {@link org.dasein.cloud.Requirement#NONE} means that no
* account id may be provided.
*
* @return the requirement associated with a supplied user-defined account
* identifier
* @throws org.dasein.cloud.InternalException
* an error occurred within the Dasein Cloud implementation
* @throws org.dasein.cloud.CloudException
* an error occurred with the cloud provide
*/
public @Nonnull
Requirement identifyAccountIdRequirement() throws InternalException, CloudException;

/**
* Indicates whether or not sub accounts can be deleted for this cloud using
* a {@link AccountSupport#delete(String)} call.
*
* @return true if sub accounts can be deleted, false if otherwise
* @throws CloudException
* the cloud provider encountered an error while processing the
* request
* @throws InternalException
* a Dasein Cloud error occurred while processing the request
*/
public boolean canDelete() throws InternalException, CloudException;

/**
* Indicates whether or not details on an account can be updated for this
* cloud using an {@link AccountSupport#update(String)} call.
*
* @return true if account details can be updated, false if otherwise
* @throws InternalException
* an error occurred within the Dasein Cloud API implementation
* @throws CloudException
* an error occurred within the cloud provider
*/
public boolean canUpdate() throws InternalException, CloudException;

/**
* Indicates whether or not an account in the specified state can be the
* target of an {@link AccountSupport#enable(String)} call.
*
* @param fromState
* the state in which the theoretical account exists
* @return true if an account can be enabled, false if otherwise
* @throws InternalException
* an error occurred within the Dasein Cloud API implementation
* @throws CloudException
* an error occurred within the cloud provider
*/
public boolean canEnable(AccountState fromState) throws InternalException, CloudException;

/**
* Indicates whether or not an account in the specified state can be the
* target of an {@link AccountSupport#suspend(String)} call.
*
* @param fromState
* the state in which the theoretical account exists
* @return true if an account can be suspended, false if otherwise
* @throws InternalException
* an error occurred within the Dasein Cloud API implementation
* @throws CloudException
* an error occurred within the cloud provider
*/
public boolean canSuspend(AccountState fromState) throws InternalException, CloudException;

/**
* Assists UIs by providing the cloud-specific term for an account in the
* cloud.
*
* @param locale
* the locale for which the term should be translated
* @return the provider-specific term for an account
*/
public @Nonnull
String getProviderTermForAccount(Locale locale);
}
5 changes: 5 additions & 0 deletions src/main/java/org/dasein/cloud/admin/AccountState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.dasein.cloud.admin;

public enum AccountState {
ACTIVE, SUSPENDED, TRIAL, INACTIVE;
}

0 comments on commit 06e8dfb

Please sign in to comment.