Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9852FE0B3 for ; Mon, 28 Jan 2013 12:23:09 +0000 (UTC) Received: (qmail 94658 invoked by uid 500); 28 Jan 2013 12:22:59 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 94238 invoked by uid 500); 28 Jan 2013 12:22:56 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 92594 invoked by uid 99); 28 Jan 2013 12:22:51 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Jan 2013 12:22:51 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 808B58263EE; Mon, 28 Jan 2013 12:22:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kishan@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [42/50] [abbrv] Apply API refactoring changes. Make changes to Regions API to work with new code Message-Id: <20130128122251.808B58263EE@tyr.zones.apache.org> Date: Mon, 28 Jan 2013 12:22:51 +0000 (UTC) http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f57d925/api/src/com/cloud/domain/Domain.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f57d925/api/src/com/cloud/user/Account.java ---------------------------------------------------------------------- diff --cc api/src/com/cloud/user/Account.java index d7d67ac,a5b3e87..e65e017 --- a/api/src/com/cloud/user/Account.java +++ b/api/src/com/cloud/user/Account.java @@@ -59,10 -60,7 +60,10 @@@ public interface Account extends Contro public Date getRemoved(); public String getNetworkDomain(); - + public Long getDefaultZoneId(); - + + public int getRegionId(); + + public String getUuid(); } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f57d925/api/src/com/cloud/user/AccountService.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f57d925/api/src/com/cloud/user/DomainService.java ---------------------------------------------------------------------- diff --cc api/src/com/cloud/user/DomainService.java index e2221b6,cd20060..1d207e7 --- a/api/src/com/cloud/user/DomainService.java +++ b/api/src/com/cloud/user/DomainService.java @@@ -40,27 -42,10 +42,27 @@@ public interface DomainService boolean deleteDomain(long domainId, Boolean cleanup); - List searchForDomains(ListDomainsCmd cmd) + Pair, Integer> searchForDomains(ListDomainsCmd cmd) throws PermissionDeniedException; - List searchForDomainChildren(ListDomainChildrenCmd cmd) + Pair, Integer> searchForDomainChildren(ListDomainChildrenCmd cmd) throws PermissionDeniedException; + /** + * update an existing domain + * + * @param cmd + * - the command containing domainId and new domainName + * @return Domain object if the command succeeded + */ + Domain updateDomain(UpdateDomainCmd cmd); + + /** + * find the domain by its path + * + * @param domainPath + * the path to use to lookup a domain + * @return domainVO the domain with the matching path, or null if no domain with the given path exists + */ + Domain findDomainByPath(String domainPath); } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f57d925/api/src/com/cloud/user/User.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f57d925/api/src/org/apache/cloudstack/api/ApiConstants.java ---------------------------------------------------------------------- diff --cc api/src/org/apache/cloudstack/api/ApiConstants.java index 0000000,58a7831..e787ce2 mode 000000,100644..100644 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@@ -1,0 -1,449 +1,452 @@@ + // Licensed to the Apache Software Foundation (ASF) under one + // or more contributor license agreements. See the NOTICE file + // distributed with this work for additional information + // regarding copyright ownership. The ASF 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.apache.cloudstack.api; + + import org.omg.CORBA.PUBLIC_MEMBER; + + public class ApiConstants { + public static final String ACCOUNT = "account"; + public static final String ACCOUNTS = "accounts"; + public static final String ACCOUNT_TYPE = "accounttype"; + public static final String ACCOUNT_ID = "accountid"; + public static final String ALGORITHM = "algorithm"; + public static final String ALLOCATED_ONLY = "allocatedonly"; + public static final String API_KEY = "userapikey"; + public static final String APPLIED = "applied"; + public static final String AVAILABLE = "available"; + public static final String BITS = "bits"; + public static final String BOOTABLE = "bootable"; + public static final String BIND_DN = "binddn"; + public static final String BIND_PASSWORD = "bindpass"; + public static final String CATEGORY = "category"; + public static final String CERTIFICATE = "certificate"; + public static final String PRIVATE_KEY = "privatekey"; + public static final String DOMAIN_SUFFIX = "domainsuffix"; + public static final String DNS_SEARCH_ORDER = "dnssearchorder"; + public static final String CIDR = "cidr"; + public static final String CIDR_LIST = "cidrlist"; + public static final String CLEANUP = "cleanup"; + public static final String CLUSTER_ID = "clusterid"; + public static final String CLUSTER_NAME = "clustername"; + public static final String CLUSTER_TYPE = "clustertype"; + public static final String COMPONENT = "component"; + public static final String CPU_NUMBER = "cpunumber"; + public static final String CPU_SPEED = "cpuspeed"; + public static final String CREATED = "created"; + public static final String CUSTOMIZED = "customized"; + public static final String DESCRIPTION = "description"; + public static final String DESTINATION_ZONE_ID = "destzoneid"; + public static final String DETAILS = "details"; + public static final String DEVICE_ID = "deviceid"; + public static final String DISK_OFFERING_ID = "diskofferingid"; + public static final String DISK_SIZE = "disksize"; + public static final String DISPLAY_NAME = "displayname"; + public static final String DISPLAY_TEXT = "displaytext"; + public static final String DNS1 = "dns1"; + public static final String DNS2 = "dns2"; + public static final String DOMAIN = "domain"; + public static final String DOMAIN_ID = "domainid"; + public static final String DURATION = "duration"; + public static final String EMAIL = "email"; + public static final String END_DATE = "enddate"; + public static final String END_IP = "endip"; + public static final String END_PORT = "endport"; + public static final String ENTRY_TIME = "entrytime"; + public static final String FETCH_LATEST = "fetchlatest"; + public static final String FIRSTNAME = "firstname"; + public static final String FORCED = "forced"; + public static final String FORCED_DESTROY_LOCAL_STORAGE = "forcedestroylocalstorage"; + public static final String FORMAT = "format"; + public static final String FOR_VIRTUAL_NETWORK = "forvirtualnetwork"; + public static final String GATEWAY = "gateway"; + public static final String GROUP = "group"; + public static final String GROUP_ID = "groupid"; + public static final String GUEST_CIDR_ADDRESS = "guestcidraddress"; + public static final String HA_ENABLE = "haenable"; + public static final String HOST_ID = "hostid"; + public static final String HOST_NAME = "hostname"; + public static final String HYPERVISOR = "hypervisor"; + public static final String INLINE = "inline"; + public static final String INSTANCE = "instance"; + public static final String ICMP_CODE = "icmpcode"; + public static final String ICMP_TYPE = "icmptype"; + public static final String ID = "id"; + public static final String IDS = "ids"; + public static final String INTERNAL_DNS1 = "internaldns1"; + public static final String INTERNAL_DNS2 = "internaldns2"; + public static final String INTERVAL_TYPE = "intervaltype"; + public static final String IP_ADDRESS = "ipaddress"; + public static final String IP_ADDRESS_ID = "ipaddressid"; + public static final String IS_ASYNC = "isasync"; + public static final String IP_AVAILABLE = "ipavailable"; + public static final String IP_LIMIT = "iplimit"; + public static final String IP_TOTAL = "iptotal"; + public static final String IS_CLEANUP_REQUIRED = "iscleanuprequired"; + public static final String IS_EXTRACTABLE = "isextractable"; + public static final String IS_FEATURED = "isfeatured"; + public static final String IS_PUBLIC = "ispublic"; + public static final String IS_READY = "isready"; + public static final String IS_RECURSIVE = "isrecursive"; + public static final String ISO_FILTER = "isofilter"; + public static final String ISO_GUEST_OS_NONE = "None"; + public static final String JOB_ID = "jobid"; + public static final String JOB_STATUS = "jobstatus"; + public static final String LASTNAME = "lastname"; + public static final String LEVEL = "level"; + public static final String LENGTH = "length"; + public static final String LIMIT_CPU_USE = "limitcpuuse"; + public static final String LOCK = "lock"; + public static final String LUN = "lun"; + public static final String LBID = "lbruleid"; + public static final String MAX = "max"; + public static final String MAX_SNAPS = "maxsnaps"; + public static final String MEMORY = "memory"; + public static final String MODE = "mode"; + public static final String NAME = "name"; + public static final String METHOD_NAME = "methodname"; + public static final String NETWORK_DOMAIN = "networkdomain"; + public static final String NETMASK = "netmask"; + public static final String NEW_NAME = "newname"; + public static final String NUM_RETRIES = "numretries"; + public static final String OFFER_HA = "offerha"; + public static final String IS_SYSTEM_OFFERING = "issystem"; + public static final String IS_DEFAULT_USE = "defaultuse"; + public static final String OP = "op"; + public static final String OS_CATEGORY_ID = "oscategoryid"; + public static final String OS_TYPE_ID = "ostypeid"; + public static final String PARAMS = "params"; + public static final String PARENT_DOMAIN_ID = "parentdomainid"; + public static final String PASSWORD = "password"; + public static final String NEW_PASSWORD = "new_password"; + public static final String PASSWORD_ENABLED = "passwordenabled"; + public static final String SSHKEY_ENABLED = "sshkeyenabled"; + public static final String PATH = "path"; + public static final String POD_ID = "podid"; + public static final String POD_IDS = "podids"; + public static final String POLICY_ID = "policyid"; + public static final String PORT = "port"; + public static final String PORTAL = "portal"; + public static final String PORT_FORWARDING_SERVICE_ID = "portforwardingserviceid"; + public static final String PRIVATE_INTERFACE = "privateinterface"; + public static final String PRIVATE_IP = "privateip"; + public static final String PRIVATE_PORT = "privateport"; + public static final String PRIVATE_START_PORT = "privateport"; + public static final String PRIVATE_END_PORT = "privateendport"; + public static final String PRIVATE_ZONE = "privatezone"; + public static final String PROTOCOL = "protocol"; + public static final String PUBLIC_INTERFACE = "publicinterface"; + public static final String PUBLIC_IP_ID = "publicipid"; + public static final String PUBLIC_IP = "publicip"; + public static final String PUBLIC_PORT = "publicport"; + public static final String PUBLIC_START_PORT = "publicport"; + public static final String PUBLIC_END_PORT = "publicendport"; + public static final String PUBLIC_ZONE = "publiczone"; + public static final String RECEIVED_BYTES = "receivedbytes"; + public static final String REQUIRES_HVM = "requireshvm"; + public static final String RESOURCE_TYPE = "resourcetype"; + public static final String RESPONSE = "response"; + public static final String QUERY_FILTER = "queryfilter"; + public static final String SCHEDULE = "schedule"; + public static final String SCOPE = "scope"; + public static final String SECRET_KEY = "usersecretkey"; + public static final String SINCE = "since"; + public static final String KEY = "key"; + public static final String SEARCH_BASE = "searchbase"; + public static final String SECURITY_GROUP_IDS = "securitygroupids"; + public static final String SECURITY_GROUP_NAMES = "securitygroupnames"; + public static final String SECURITY_GROUP_NAME = "securitygroupname"; + public static final String SECURITY_GROUP_ID = "securitygroupid"; + public static final String SENT = "sent"; + public static final String SENT_BYTES = "sentbytes"; + public static final String SERVICE_OFFERING_ID = "serviceofferingid"; + public static final String SHOW_CAPACITIES = "showcapacities"; + public static final String SIZE = "size"; + public static final String SNAPSHOT_ID = "snapshotid"; + public static final String SNAPSHOT_POLICY_ID = "snapshotpolicyid"; + public static final String SNAPSHOT_TYPE = "snapshottype"; + public static final String SOURCE_ZONE_ID = "sourcezoneid"; + public static final String START_DATE = "startdate"; + public static final String START_IP = "startip"; + public static final String START_PORT = "startport"; + public static final String STATE = "state"; + public static final String STATUS = "status"; + public static final String STORAGE_TYPE = "storagetype"; + public static final String SYSTEM_VM_TYPE = "systemvmtype"; + public static final String TAGS = "tags"; + public static final String TARGET_IQN = "targetiqn"; + public static final String TEMPLATE_FILTER = "templatefilter"; + public static final String TEMPLATE_ID = "templateid"; + public static final String ISO_ID = "isoid"; + public static final String TIMEOUT = "timeout"; + public static final String TIMEZONE = "timezone"; + public static final String TYPE = "type"; + public static final String TRUST_STORE = "truststore"; + public static final String TRUST_STORE_PASSWORD = "truststorepass"; + public static final String URL = "url"; + public static final String USAGE_INTERFACE = "usageinterface"; + public static final String USER_DATA = "userdata"; + public static final String USER_ID = "userid"; + public static final String USE_SSL = "ssl"; + public static final String USERNAME = "username"; + public static final String USER_SECURITY_GROUP_LIST = "usersecuritygrouplist"; + public static final String USE_VIRTUAL_NETWORK = "usevirtualnetwork"; + public static final String VALUE = "value"; + public static final String VIRTUAL_MACHINE_ID = "virtualmachineid"; + public static final String VIRTUAL_MACHINE_IDS = "virtualmachineids"; + public static final String VLAN = "vlan"; + public static final String VLAN_ID = "vlanid"; + public static final String VM_AVAILABLE = "vmavailable"; + public static final String VM_LIMIT = "vmlimit"; + public static final String VM_TOTAL = "vmtotal"; + public static final String VNET = "vnet"; + public static final String VOLUME_ID = "volumeid"; + public static final String ZONE_ID = "zoneid"; + public static final String ZONE_NAME = "zonename"; + public static final String NETWORK_TYPE = "networktype"; + public static final String PAGE = "page"; + public static final String PAGE_SIZE = "pagesize"; + public static final String COUNT = "count"; + public static final String TRAFFIC_TYPE = "traffictype"; + public static final String NETWORK_OFFERING_ID = "networkofferingid"; + public static final String NETWORK_IDS = "networkids"; + public static final String NETWORK_ID = "networkid"; + public static final String SPECIFY_VLAN = "specifyvlan"; + public static final String IS_DEFAULT = "isdefault"; + public static final String IS_SYSTEM = "issystem"; + public static final String AVAILABILITY = "availability"; + public static final String NETWORKRATE = "networkrate"; + public static final String HOST_TAGS = "hosttags"; + public static final String SSH_KEYPAIR = "keypair"; + public static final String HOST_CPU_CAPACITY = "hostcpucapacity"; + public static final String HOST_CPU_NUM = "hostcpunum"; + public static final String HOST_MEM_CAPACITY = "hostmemcapacity"; + public static final String HOST_MAC = "hostmac"; + public static final String HOST_TAG = "hosttag"; + public static final String PXE_SERVER_TYPE = "pxeservertype"; + public static final String LINMIN_USERNAME = "linminusername"; + public static final String LINMIN_PASSWORD = "linminpassword"; + public static final String LINMIN_APID = "linminapid"; + public static final String DHCP_SERVER_TYPE = "dhcpservertype"; + public static final String LINK_LOCAL_IP = "linklocalip"; + public static final String LINK_LOCAL_MAC_ADDRESS = "linklocalmacaddress"; + public static final String LINK_LOCAL_MAC_NETMASK = "linklocalnetmask"; + public static final String LINK_LOCAL_NETWORK_ID = "linklocalnetworkid"; + public static final String PRIVATE_MAC_ADDRESS = "privatemacaddress"; + public static final String PRIVATE_NETMASK = "privatenetmask"; + public static final String PRIVATE_NETWORK_ID = "privatenetworkid"; + public static final String ALLOCATION_STATE = "allocationstate"; + public static final String MANAGED_STATE = "managedstate"; + public static final String STORAGE_ID = "storageid"; + public static final String PING_STORAGE_SERVER_IP = "pingstorageserverip"; + public static final String PING_DIR = "pingdir"; + public static final String TFTP_DIR = "tftpdir"; + public static final String PING_CIFS_USERNAME = "pingcifsusername"; + public static final String PING_CIFS_PASSWORD = "pingcifspassword"; + public static final String CHECKSUM = "checksum"; + public static final String NETWORK_DEVICE_TYPE = "networkdevicetype"; + public static final String NETWORK_DEVICE_PARAMETER_LIST = "networkdeviceparameterlist"; + public static final String ZONE_TOKEN = "zonetoken"; + public static final String DHCP_PROVIDER = "dhcpprovider"; + public static final String RESULT = "success"; + public static final String LUN_ID = "lunId"; + public static final String IQN = "iqn"; + public static final String AGGREGATE_NAME = "aggregatename"; + public static final String POOL_NAME = "poolname"; + public static final String VOLUME_NAME = "volumename"; + public static final String SNAPSHOT_POLICY = "snapshotpolicy"; + public static final String SNAPSHOT_RESERVATION = "snapshotreservation"; + public static final String IP_NETWORK_LIST = "iptonetworklist"; + public static final String PARAM_LIST = "param"; + public static final String FOR_LOAD_BALANCING = "forloadbalancing"; + public static final String KEYBOARD = "keyboard"; + public static final String OPEN_FIREWALL = "openfirewall"; + public static final String TEMPLATE_TAG = "templatetag"; + public static final String HYPERVISOR_VERSION = "hypervisorversion"; + public static final String MAX_GUESTS_LIMIT = "maxguestslimit"; + public static final String PROJECT_ID = "projectid"; + public static final String PROJECT_IDS = "projectids"; + public static final String PROJECT = "project"; + public static final String ROLE = "role"; + public static final String USER = "user"; + public static final String ACTIVE_ONLY = "activeonly"; + public static final String TOKEN = "token"; + public static final String ACCEPT = "accept"; + public static final String SORT_KEY = "sortkey"; + public static final String ACCOUNT_DETAILS = "accountdetails"; + public static final String SERVICE_PROVIDER_LIST = "serviceproviderlist"; + public static final String SERVICE_CAPABILITY_LIST = "servicecapabilitylist"; + public static final String CAN_CHOOSE_SERVICE_CAPABILITY = "canchooseservicecapability"; + public static final String PROVIDER = "provider"; + public static final String NETWORK_SPEED = "networkspeed"; + public static final String BROADCAST_DOMAIN_RANGE = "broadcastdomainrange"; + public static final String ISOLATION_METHODS = "isolationmethods"; + public static final String PHYSICAL_NETWORK_ID = "physicalnetworkid"; + public static final String DEST_PHYSICAL_NETWORK_ID = "destinationphysicalnetworkid"; + public static final String ENABLED = "enabled"; + public static final String SERVICE_NAME = "servicename"; + public static final String DHCP_RANGE = "dhcprange"; + public static final String UUID = "uuid"; + public static final String SECURITY_GROUP_EANBLED = "securitygroupenabled"; + public static final String LOCAL_STORAGE_ENABLED = "localstorageenabled"; + public static final String GUEST_IP_TYPE = "guestiptype"; + public static final String XEN_NETWORK_LABEL = "xennetworklabel"; + public static final String KVM_NETWORK_LABEL = "kvmnetworklabel"; + public static final String VMWARE_NETWORK_LABEL = "vmwarenetworklabel"; + public static final String NETWORK_SERVICE_PROVIDER_ID = "nspid"; + public static final String SERVICE_LIST = "servicelist"; + public static final String CAN_ENABLE_INDIVIDUAL_SERVICE = "canenableindividualservice"; + public static final String SUPPORTED_SERVICES = "supportedservices"; + public static final String NSP_ID = "nspid"; + public static final String ACL_TYPE = "acltype"; + public static final String SUBDOMAIN_ACCESS = "subdomainaccess"; + public static final String LOAD_BALANCER_DEVICE_ID = "lbdeviceid"; + public static final String LOAD_BALANCER_DEVICE_NAME = "lbdevicename"; + public static final String LOAD_BALANCER_DEVICE_STATE = "lbdevicestate"; + public static final String LOAD_BALANCER_DEVICE_CAPACITY = "lbdevicecapacity"; + public static final String LOAD_BALANCER_DEVICE_DEDICATED = "lbdevicededicated"; + public static final String FIREWALL_DEVICE_ID = "fwdeviceid"; + public static final String FIREWALL_DEVICE_NAME = "fwdevicename"; + public static final String FIREWALL_DEVICE_STATE = "fwdevicestate"; + public static final String FIREWALL_DEVICE_CAPACITY = "fwdevicecapacity"; + public static final String FIREWALL_DEVICE_DEDICATED = "fwdevicededicated"; + public static final String SERVICE = "service"; + public static final String ASSOCIATED_NETWORK_ID = "associatednetworkid"; + public static final String ASSOCIATED_NETWORK_NAME = "associatednetworkname"; + public static final String SOURCE_NAT_SUPPORTED = "sourcenatsupported"; + public static final String RESOURCE_STATE = "resourcestate"; + public static final String PROJECT_INVITE_REQUIRED = "projectinviterequired"; + public static final String REQUIRED = "required"; + public static final String RESTART_REQUIRED = "restartrequired"; + public static final String ALLOW_USER_CREATE_PROJECTS = "allowusercreateprojects"; + public static final String CONSERVE_MODE = "conservemode"; + public static final String TRAFFIC_TYPE_IMPLEMENTOR = "traffictypeimplementor"; + public static final String KEYWORD = "keyword"; + public static final String LIST_ALL = "listall"; + public static final String SPECIFY_IP_RANGES = "specifyipranges"; + public static final String IS_SOURCE_NAT = "issourcenat"; + public static final String IS_STATIC_NAT = "isstaticnat"; + public static final String SORT_BY = "sortby"; + public static final String CHANGE_CIDR = "changecidr"; + public static final String PURPOSE = "purpose"; + public static final String IS_TAGGED = "istagged"; + public static final String INSTANCE_NAME = "instancename"; + public static final String START_VM = "startvm"; + public static final String HA_HOST = "hahost"; + public static final String CUSTOM_DISK_OFF_MAX_SIZE = "customdiskofferingmaxsize"; + public static final String DEFAULT_ZONE_ID = "defaultzoneid"; + public static final String GUID = "guid"; + + public static final String EXTERNAL_SWITCH_MGMT_DEVICE_ID = "vsmdeviceid"; + public static final String EXTERNAL_SWITCH_MGMT_DEVICE_NAME = "vsmdevicename"; + public static final String EXTERNAL_SWITCH_MGMT_DEVICE_STATE = "vsmdevicestate"; + // Would we need to have a capacity field for Cisco N1KV VSM? Max hosts managed by it perhaps? May remove this later. + public static final String EXTERNAL_SWITCH_MGMT_DEVICE_CAPACITY = "vsmdevicecapacity"; + public static final String CISCO_NEXUS_VSM_NAME = "vsmname"; + public static final String VSM_USERNAME = "vsmusername"; + public static final String VSM_PASSWORD = "vsmpassword"; + public static final String VSM_IPADDRESS = "vsmipaddress"; + public static final String VSM_MGMT_VLAN_ID = "vsmmgmtvlanid"; + public static final String VSM_PKT_VLAN_ID = "vsmpktvlanid"; + public static final String VSM_CTRL_VLAN_ID = "vsmctrlvlanid"; + public static final String VSM_STORAGE_VLAN_ID = "vsmstoragevlanid"; + public static final String VSM_DOMAIN_ID = "vsmdomainid"; + public static final String VSM_CONFIG_MODE = "vsmconfigmode"; + public static final String VSM_CONFIG_STATE = "vsmconfigstate"; + public static final String VSM_DEVICE_STATE = "vsmdevicestate"; + public static final String ADD_VSM_FLAG = "addvsmflag"; ++ public static final String END_POINT = "endpoint"; ++ public static final String REGION_ID = "regionid"; ++ public static final String IS_PROPAGATE = "ispropagate"; + public static final String VPC_OFF_ID = "vpcofferingid"; + public static final String NETWORK = "network"; + public static final String VPC_ID = "vpcid"; + public static final String GATEWAY_ID = "gatewayid"; + public static final String CAN_USE_FOR_DEPLOY = "canusefordeploy"; + public static final String RESOURCE_IDS = "resourceids"; + public static final String RESOURCE_ID = "resourceid"; + public static final String CUSTOMER = "customer"; + public static final String S2S_VPN_GATEWAY_ID = "s2svpngatewayid"; + public static final String S2S_CUSTOMER_GATEWAY_ID = "s2scustomergatewayid"; + public static final String IPSEC_PSK = "ipsecpsk"; + public static final String GUEST_IP = "guestip"; + public static final String REMOVED = "removed"; + public static final String IKE_POLICY = "ikepolicy"; + public static final String ESP_POLICY = "esppolicy"; + public static final String IKE_LIFETIME = "ikelifetime"; + public static final String ESP_LIFETIME = "esplifetime"; + public static final String DPD = "dpd"; + public static final String FOR_VPC = "forvpc"; + public static final String SHRINK_OK = "shrinkok"; + public static final String NICIRA_NVP_DEVICE_ID = "nvpdeviceid"; + public static final String NICIRA_NVP_TRANSPORT_ZONE_UUID = "transportzoneuuid"; + public static final String NICIRA_NVP_DEVICE_NAME = "niciradevicename"; + public static final String NICIRA_NVP_GATEWAYSERVICE_UUID = "l3gatewayserviceuuid"; + public static final String S3_ACCESS_KEY = "accesskey"; + public static final String S3_SECRET_KEY = "secretkey"; + public static final String S3_END_POINT = "endpoint"; + public static final String S3_BUCKET_NAME = "bucket"; + public static final String S3_HTTPS_FLAG = "usehttps"; + public static final String S3_CONNECTION_TIMEOUT = "connectiontimeout"; + public static final String S3_MAX_ERROR_RETRY = "maxerrorretry"; + public static final String S3_SOCKET_TIMEOUT = "sockettimeout"; + public static final String INCL_ZONES = "includezones"; + public static final String EXCL_ZONES = "excludezones"; + public static final String SOURCE = "source"; + public static final String COUNTER_ID = "counterid"; + public static final String AGGR_OPERATOR = "aggroperator"; + public static final String AGGR_FUNCTION = "aggrfunction"; + public static final String AGGR_VALUE = "aggrvalue"; + public static final String THRESHOLD = "threshold"; + public static final String RELATIONAL_OPERATOR = "relationaloperator"; + public static final String OTHER_DEPLOY_PARAMS = "otherdeployparams"; + public static final String MIN_MEMBERS = "minmembers"; + public static final String MAX_MEMBERS = "maxmembers"; + public static final String AUTOSCALE_VM_DESTROY_TIME = "destroyvmgraceperiod"; + public static final String VMPROFILE_ID = "vmprofileid"; + public static final String VMGROUP_ID = "vmgroupid"; + public static final String CS_URL = "csurl"; + public static final String SCALEUP_POLICY_IDS = "scaleuppolicyids"; + public static final String SCALEDOWN_POLICY_IDS = "scaledownpolicyids"; + public static final String SCALEUP_POLICIES = "scaleuppolicies"; + public static final String SCALEDOWN_POLICIES = "scaledownpolicies"; + public static final String INTERVAL = "interval"; + public static final String QUIETTIME = "quiettime"; + public static final String ACTION = "action"; + public static final String CONDITION_ID = "conditionid"; + public static final String CONDITION_IDS = "conditionids"; + public static final String COUNTERPARAM_LIST = "counterparam"; + public static final String AUTOSCALE_USER_ID = "autoscaleuserid"; + + public enum HostDetails { + all, capacity, events, stats, min; + } + + public enum VMDetails { + all, group, nics, stats, secgrp, tmpl, servoff, iso, volume, min; + } + + public enum LDAPParams { + hostname, port, usessl, queryfilter, searchbase, dn, passwd, truststore, truststorepass; + + @Override + public String toString() { + return "ldap." + name(); + } + } + + + } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f57d925/api/src/org/apache/cloudstack/api/BaseCmd.java ---------------------------------------------------------------------- diff --cc api/src/org/apache/cloudstack/api/BaseCmd.java index 0000000,ef72af9..c0d465f mode 000000,100644..100644 --- a/api/src/org/apache/cloudstack/api/BaseCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseCmd.java @@@ -1,0 -1,519 +1,522 @@@ + // Licensed to the Apache Software Foundation (ASF) under one + // or more contributor license agreements. See the NOTICE file + // distributed with this work for additional information + // regarding copyright ownership. The ASF 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.apache.cloudstack.api; + + import java.text.DateFormat; + import java.text.SimpleDateFormat; + import java.util.Date; + import java.util.HashMap; + import java.util.List; + import java.util.Map; + import java.util.regex.Pattern; + + import org.apache.cloudstack.query.QueryService; + import org.apache.log4j.Logger; + + import com.cloud.configuration.ConfigurationService; + import com.cloud.consoleproxy.ConsoleProxyService; + import com.cloud.dao.EntityManager; + import com.cloud.domain.Domain; + import com.cloud.exception.ConcurrentOperationException; + import com.cloud.exception.InsufficientCapacityException; + import com.cloud.exception.InvalidParameterValueException; + import com.cloud.exception.NetworkRuleConflictException; + import com.cloud.exception.PermissionDeniedException; + import com.cloud.exception.ResourceAllocationException; + import com.cloud.exception.ResourceUnavailableException; + import com.cloud.network.NetworkService; + import com.cloud.network.StorageNetworkService; + import com.cloud.network.VpcVirtualNetworkApplianceService; + import com.cloud.network.as.AutoScaleService; + import com.cloud.network.firewall.FirewallService; + import com.cloud.network.firewall.NetworkACLService; + import com.cloud.network.lb.LoadBalancingRulesService; + import com.cloud.network.rules.RulesService; + import com.cloud.network.security.SecurityGroupService; + import com.cloud.network.vpc.VpcService; + import com.cloud.network.vpn.RemoteAccessVpnService; + import com.cloud.network.vpn.Site2SiteVpnService; + import com.cloud.projects.Project; + import com.cloud.projects.ProjectService; ++import com.cloud.region.RegionService; + import com.cloud.resource.ResourceService; + import com.cloud.server.ManagementService; + import com.cloud.server.TaggedResourceService; + import com.cloud.storage.StorageService; + import com.cloud.storage.snapshot.SnapshotService; + import com.cloud.template.TemplateService; + import com.cloud.user.Account; + import com.cloud.user.AccountService; + import com.cloud.user.DomainService; + import com.cloud.user.ResourceLimitService; + import com.cloud.utils.Pair; + import com.cloud.utils.component.ComponentLocator; + import com.cloud.vm.BareMetalVmService; + import com.cloud.vm.UserVmService; + + public abstract class BaseCmd { + private static final Logger s_logger = Logger.getLogger(BaseCmd.class.getName()); + + public static final String USER_ERROR_MESSAGE = "Internal error executing command, please contact your system administrator"; + public static final int PROGRESS_INSTANCE_CREATED = 1; + + public static final String RESPONSE_TYPE_XML = "xml"; + public static final String RESPONSE_TYPE_JSON = "json"; + + public enum CommandType { + BOOLEAN, DATE, FLOAT, INTEGER, SHORT, LIST, LONG, OBJECT, MAP, STRING, TZDATE, UUID + } + + public static final DateFormat INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); + public static final DateFormat NEW_INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + public static Pattern newInputDateFormat = Pattern.compile("[\\d]+-[\\d]+-[\\d]+ [\\d]+:[\\d]+:[\\d]+"); + private static final DateFormat _outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + + private Object _responseObject = null; + private Map fullUrlParams; + + @Parameter(name = "response", type = CommandType.STRING) + private String responseType; + + public static ComponentLocator s_locator; + public static ConfigurationService _configService; + public static AccountService _accountService; + public static UserVmService _userVmService; + public static ManagementService _mgr; + public static StorageService _storageService; + public static ResourceService _resourceService; + public static NetworkService _networkService; + public static TemplateService _templateService; + public static SecurityGroupService _securityGroupService; + public static SnapshotService _snapshotService; + public static ConsoleProxyService _consoleProxyService; + public static VpcVirtualNetworkApplianceService _routerService; + public static ResponseGenerator _responseGenerator; + public static EntityManager _entityMgr; + public static RulesService _rulesService; + public static AutoScaleService _autoScaleService; + public static LoadBalancingRulesService _lbService; + public static RemoteAccessVpnService _ravService; + public static BareMetalVmService _bareMetalVmService; + public static ProjectService _projectService; + public static FirewallService _firewallService; + public static DomainService _domainService; + public static ResourceLimitService _resourceLimitService; + public static IdentityService _identityService; + public static StorageNetworkService _storageNetworkService; ++ public static RegionService _regionService; + public static TaggedResourceService _taggedResourceService; + public static VpcService _vpcService; + public static NetworkACLService _networkACLService; + public static Site2SiteVpnService _s2sVpnService; + + public static QueryService _queryService; + + public static void setComponents(ResponseGenerator generator) { + ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); + _mgr = (ManagementService) ComponentLocator.getComponent(ManagementService.Name); + _accountService = locator.getManager(AccountService.class); + _configService = locator.getManager(ConfigurationService.class); + _userVmService = locator.getManager(UserVmService.class); + _storageService = locator.getManager(StorageService.class); + _resourceService = locator.getManager(ResourceService.class); + _networkService = locator.getManager(NetworkService.class); + _templateService = locator.getManager(TemplateService.class); + _securityGroupService = locator.getManager(SecurityGroupService.class); + _snapshotService = locator.getManager(SnapshotService.class); + _consoleProxyService = locator.getManager(ConsoleProxyService.class); + _routerService = locator.getManager(VpcVirtualNetworkApplianceService.class); + _entityMgr = locator.getManager(EntityManager.class); + _rulesService = locator.getManager(RulesService.class); + _lbService = locator.getManager(LoadBalancingRulesService.class); + _autoScaleService = locator.getManager(AutoScaleService.class); + _ravService = locator.getManager(RemoteAccessVpnService.class); + _responseGenerator = generator; + _bareMetalVmService = locator.getManager(BareMetalVmService.class); + _projectService = locator.getManager(ProjectService.class); + _firewallService = locator.getManager(FirewallService.class); + _domainService = locator.getManager(DomainService.class); + _resourceLimitService = locator.getManager(ResourceLimitService.class); + _identityService = locator.getManager(IdentityService.class); + _storageNetworkService = locator.getManager(StorageNetworkService.class); ++ _regionService = locator.getManager(RegionService.class); + _taggedResourceService = locator.getManager(TaggedResourceService.class); + _vpcService = locator.getManager(VpcService.class); + _networkACLService = locator.getManager(NetworkACLService.class); + _s2sVpnService = locator.getManager(Site2SiteVpnService.class); + _queryService = locator.getManager(QueryService.class); + } + + public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException; + + public String getResponseType() { + if (responseType == null) { + return RESPONSE_TYPE_XML; + } + return responseType; + } + + public void setResponseType(String responseType) { + this.responseType = responseType; + } + + public abstract String getCommandName(); + + /** + * For commands the API framework needs to know the owner of the object being acted upon. This method is + * used to determine that information. + * + * @return the id of the account that owns the object being acted upon + */ + public abstract long getEntityOwnerId(); + + public Object getResponseObject() { + return _responseObject; + } + + public void setResponseObject(Object responseObject) { + _responseObject = responseObject; + } + + public ManagementService getMgmtServiceRef() { + return _mgr; + } + + public static String getDateString(Date date) { + if (date == null) { + return ""; + } + String formattedString = null; + synchronized (_outputFormat) { + formattedString = _outputFormat.format(date); + } + return formattedString; + } + + // FIXME: move this to a utils method so that maps can be unpacked and integer/long values can be appropriately cast + @SuppressWarnings({ "unchecked", "rawtypes" }) + public Map unpackParams(Map params) { + Map lowercaseParams = new HashMap(); + for (String key : params.keySet()) { + int arrayStartIndex = key.indexOf('['); + int arrayStartLastIndex = key.lastIndexOf('['); + if (arrayStartIndex != arrayStartLastIndex) { + throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + + "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup"); + } + + if (arrayStartIndex > 0) { + int arrayEndIndex = key.indexOf(']'); + int arrayEndLastIndex = key.lastIndexOf(']'); + if ((arrayEndIndex < arrayStartIndex) || (arrayEndIndex != arrayEndLastIndex)) { + // malformed parameter + throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + + "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup"); + } + + // Now that we have an array object, check for a field name in the case of a complex object + int fieldIndex = key.indexOf('.'); + String fieldName = null; + if (fieldIndex < arrayEndIndex) { + throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + + "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup"); + } else { + fieldName = key.substring(fieldIndex + 1); + } + + // parse the parameter name as the text before the first '[' character + String paramName = key.substring(0, arrayStartIndex); + paramName = paramName.toLowerCase(); + + Map mapArray = null; + Map mapValue = null; + String indexStr = key.substring(arrayStartIndex + 1, arrayEndIndex); + int index = 0; + boolean parsedIndex = false; + try { + if (indexStr != null) { + index = Integer.parseInt(indexStr); + parsedIndex = true; + } + } catch (NumberFormatException nfe) { + s_logger.warn("Invalid parameter " + key + " received, unable to parse object array, returning an error."); + } + + if (!parsedIndex) { + throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + + "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup"); + } + + Object value = lowercaseParams.get(paramName); + if (value == null) { + // for now, assume object array with sub fields + mapArray = new HashMap(); + mapValue = new HashMap(); + mapArray.put(Integer.valueOf(index), mapValue); + } else if (value instanceof Map) { + mapArray = (HashMap) value; + mapValue = mapArray.get(Integer.valueOf(index)); + if (mapValue == null) { + mapValue = new HashMap(); + mapArray.put(Integer.valueOf(index), mapValue); + } + } + + // we are ready to store the value for a particular field into the map for this object + mapValue.put(fieldName, params.get(key)); + + lowercaseParams.put(paramName, mapArray); + } else { + lowercaseParams.put(key.toLowerCase(), params.get(key)); + } + } + return lowercaseParams; + } + + public String buildResponse(ServerApiException apiException, String responseType) { + StringBuffer sb = new StringBuffer(); + if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { + // JSON response + sb.append("{ \"" + getCommandName() + "\" : { " + "\"@attributes\":{\"cloudstack-version\":\"" + _mgr.getVersion() + "\"},"); + sb.append("\"errorcode\" : \"" + apiException.getErrorCode() + "\", \"description\" : \"" + apiException.getDescription() + "\" } }"); + } else { + sb.append(""); + sb.append("<" + getCommandName() + ">"); + sb.append("" + apiException.getErrorCode() + ""); + sb.append("" + escapeXml(apiException.getDescription()) + ""); + sb.append(""); + } + return sb.toString(); + } + + public String buildResponse(List> tagList, String responseType) { + StringBuffer prefixSb = new StringBuffer(); + StringBuffer suffixSb = new StringBuffer(); + + // set up the return value with the name of the response + if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { + prefixSb.append("{ \"" + getCommandName() + "\" : { \"@attributes\":{\"cloudstack-version\":\"" + _mgr.getVersion() + "\"},"); + } else { + prefixSb.append(""); + prefixSb.append("<" + getCommandName() + " cloudstack-version=\"" + _mgr.getVersion() + "\">"); + } + + int i = 0; + for (Pair tagData : tagList) { + String tagName = tagData.first(); + Object tagValue = tagData.second(); + if (tagValue instanceof Object[]) { + Object[] subObjects = (Object[]) tagValue; + if (subObjects.length < 1) { + continue; + } + writeObjectArray(responseType, suffixSb, i++, tagName, subObjects); + } else { + writeNameValuePair(suffixSb, tagName, tagValue, responseType, i++); + } + } + + if (suffixSb.length() > 0) { + if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { // append comma only if we have some suffix else + // not as per strict Json syntax. + prefixSb.append(","); + } + prefixSb.append(suffixSb); + } + // close the response + if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { + prefixSb.append("} }"); + } else { + prefixSb.append(""); + } + return prefixSb.toString(); + } + + private void writeNameValuePair(StringBuffer sb, String tagName, Object tagValue, String responseType, int propertyCount) { + if (tagValue == null) { + return; + } + + if (tagValue instanceof Object[]) { + Object[] subObjects = (Object[]) tagValue; + if (subObjects.length < 1) { + return; + } + writeObjectArray(responseType, sb, propertyCount, tagName, subObjects); + } else { + if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { + String seperator = ((propertyCount > 0) ? ", " : ""); + sb.append(seperator + "\"" + tagName + "\" : \"" + escapeJSON(tagValue.toString()) + "\""); + } else { + sb.append("<" + tagName + ">" + escapeXml(tagValue.toString()) + ""); + } + } + } + + @SuppressWarnings("rawtypes") + private void writeObjectArray(String responseType, StringBuffer sb, int propertyCount, String tagName, Object[] subObjects) { + if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { + String separator = ((propertyCount > 0) ? ", " : ""); + sb.append(separator); + } + int j = 0; + for (Object subObject : subObjects) { + if (subObject instanceof List) { + List subObjList = (List) subObject; + writeSubObject(sb, tagName, subObjList, responseType, j++); + } + } + + if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { + sb.append("]"); + } + } + + @SuppressWarnings("rawtypes") + private void writeSubObject(StringBuffer sb, String tagName, List tagList, String responseType, int objectCount) { + if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { + sb.append(((objectCount == 0) ? "\"" + tagName + "\" : [ { " : ", { ")); + } else { + sb.append("<" + tagName + ">"); + } + + int i = 0; + for (Object tag : tagList) { + if (tag instanceof Pair) { + Pair nameValuePair = (Pair) tag; + writeNameValuePair(sb, (String) nameValuePair.first(), nameValuePair.second(), responseType, i++); + } + } + + if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { + sb.append("}"); + } else { + sb.append(""); + } + } + + /** + * Escape xml response set to false by default. API commands to override this method to allow escaping + */ + public boolean requireXmlEscape() { + return true; + } + + private String escapeXml(String xml) { + if (!requireXmlEscape()) { + return xml; + } + int iLen = xml.length(); + if (iLen == 0) { + return xml; + } + StringBuffer sOUT = new StringBuffer(iLen + 256); + int i = 0; + for (; i < iLen; i++) { + char c = xml.charAt(i); + if (c == '<') { + sOUT.append("<"); + } else if (c == '>') { + sOUT.append(">"); + } else if (c == '&') { + sOUT.append("&"); + } else if (c == '"') { + sOUT.append("""); + } else if (c == '\'') { + sOUT.append("'"); + } else { + sOUT.append(c); + } + } + return sOUT.toString(); + } + + private static String escapeJSON(String str) { + if (str == null) { + return str; + } + + return str.replace("\"", "\\\""); + } + + protected long getInstanceIdFromJobSuccessResult(String result) { + s_logger.debug("getInstanceIdFromJobSuccessResult not overridden in subclass " + this.getClass().getName()); + return 0; + } + + public static boolean isAdmin(short accountType) { + return ((accountType == Account.ACCOUNT_TYPE_ADMIN) || + (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) || + (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN)); + } + + public static boolean isRootAdmin(short accountType) { + return ((accountType == Account.ACCOUNT_TYPE_ADMIN)); + } + + public void setFullUrlParams(Map map) { + this.fullUrlParams = map; + } + + public Map getFullUrlParams() { + return this.fullUrlParams; + } + + public Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly) { + if (accountName != null) { + if (domainId == null) { + throw new InvalidParameterValueException("Account must be specified with domainId parameter"); + } + + Domain domain = _domainService.getDomain(domainId); + if (domain == null) { + throw new InvalidParameterValueException("Unable to find domain by id"); + } + + Account account = _accountService.getActiveAccountByName(accountName, domainId); + if (account != null && account.getType() != Account.ACCOUNT_TYPE_PROJECT) { + if (!enabledOnly || account.getState() == Account.State.enabled) { + return account.getId(); + } else { + throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() + " as it's no longer active"); + } + } else { + // idList is not used anywhere, so removed it now + //List idList = new ArrayList(); + //idList.add(new IdentityProxy("domain", domainId, "domainId")); + throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain with specified id"); + } + } + + if (projectId != null) { + Project project = _projectService.getProject(projectId); + if (project != null) { + if (!enabledOnly || project.getState() == Project.State.Active) { + return project.getProjectAccountId(); + } else { + PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active"); + ex.addProxyObject(project, projectId, "projectId"); + throw ex; + } + } else { + throw new InvalidParameterValueException("Unable to find project by id"); + } + } + return null; + } + } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f57d925/api/src/org/apache/cloudstack/api/ResponseGenerator.java ---------------------------------------------------------------------- diff --cc api/src/org/apache/cloudstack/api/ResponseGenerator.java index 0000000,63df4dc..d0be69c mode 000000,100644..100644 --- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java +++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java @@@ -1,0 -1,375 +1,387 @@@ + // Licensed to the Apache Software Foundation (ASF) under one + // or more contributor license agreements. See the NOTICE file + // distributed with this work for additional information + // regarding copyright ownership. The ASF 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.apache.cloudstack.api; + + import java.text.DecimalFormat; + import java.util.EnumSet; + import java.util.List; + + import org.apache.cloudstack.api.ApiConstants.HostDetails; + import org.apache.cloudstack.api.ApiConstants.VMDetails; + import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd; + import org.apache.cloudstack.api.response.AccountResponse; + import org.apache.cloudstack.api.response.AsyncJobResponse; + import org.apache.cloudstack.api.response.AutoScalePolicyResponse; + import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse; + import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse; + import org.apache.cloudstack.api.response.CapacityResponse; + import org.apache.cloudstack.api.response.ClusterResponse; + import org.apache.cloudstack.api.response.ConditionResponse; + import org.apache.cloudstack.api.response.ConfigurationResponse; + import org.apache.cloudstack.api.response.CounterResponse; + import org.apache.cloudstack.api.response.CreateCmdResponse; + import org.apache.cloudstack.api.response.DiskOfferingResponse; + import org.apache.cloudstack.api.response.DomainResponse; + import org.apache.cloudstack.api.response.DomainRouterResponse; + import org.apache.cloudstack.api.response.EventResponse; + import org.apache.cloudstack.api.response.ExtractResponse; + import org.apache.cloudstack.api.response.FirewallResponse; + import org.apache.cloudstack.api.response.FirewallRuleResponse; + import org.apache.cloudstack.api.response.GuestOSResponse; + import org.apache.cloudstack.api.response.HostResponse; + import org.apache.cloudstack.api.response.HypervisorCapabilitiesResponse; + import org.apache.cloudstack.api.response.IPAddressResponse; + import org.apache.cloudstack.api.response.InstanceGroupResponse; + import org.apache.cloudstack.api.response.IpForwardingRuleResponse; + import org.apache.cloudstack.api.response.LBStickinessResponse; + import org.apache.cloudstack.api.response.LDAPConfigResponse; + import org.apache.cloudstack.api.response.LoadBalancerResponse; + import org.apache.cloudstack.api.response.NetworkACLResponse; + import org.apache.cloudstack.api.response.NetworkOfferingResponse; + import org.apache.cloudstack.api.response.NetworkResponse; + import org.apache.cloudstack.api.response.PhysicalNetworkResponse; + import org.apache.cloudstack.api.response.PodResponse; + import org.apache.cloudstack.api.response.PrivateGatewayResponse; + import org.apache.cloudstack.api.response.ProjectAccountResponse; + import org.apache.cloudstack.api.response.ProjectInvitationResponse; + import org.apache.cloudstack.api.response.ProjectResponse; + import org.apache.cloudstack.api.response.ProviderResponse; + import org.apache.cloudstack.api.response.RemoteAccessVpnResponse; + import org.apache.cloudstack.api.response.ResourceCountResponse; + import org.apache.cloudstack.api.response.ResourceLimitResponse; + import org.apache.cloudstack.api.response.ResourceTagResponse; + import org.apache.cloudstack.api.response.SecurityGroupResponse; + import org.apache.cloudstack.api.response.ServiceOfferingResponse; + import org.apache.cloudstack.api.response.ServiceResponse; + import org.apache.cloudstack.api.response.Site2SiteCustomerGatewayResponse; + import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse; + import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse; + import org.apache.cloudstack.api.response.SnapshotPolicyResponse; + import org.apache.cloudstack.api.response.SnapshotResponse; + import org.apache.cloudstack.api.response.SnapshotScheduleResponse; + import org.apache.cloudstack.api.response.StaticRouteResponse; + import org.apache.cloudstack.api.response.StorageNetworkIpRangeResponse; + import org.apache.cloudstack.api.response.StoragePoolResponse; + import org.apache.cloudstack.api.response.SwiftResponse; + import org.apache.cloudstack.api.response.SystemVmInstanceResponse; + import org.apache.cloudstack.api.response.SystemVmResponse; + import org.apache.cloudstack.api.response.TemplatePermissionsResponse; + import org.apache.cloudstack.api.response.TemplateResponse; + import org.apache.cloudstack.api.response.TrafficTypeResponse; + import org.apache.cloudstack.api.response.UserResponse; + import org.apache.cloudstack.api.response.UserVmResponse; + import org.apache.cloudstack.api.response.VirtualRouterProviderResponse; + import org.apache.cloudstack.api.response.VlanIpRangeResponse; + import org.apache.cloudstack.api.response.VolumeResponse; + import org.apache.cloudstack.api.response.VpcOfferingResponse; + import org.apache.cloudstack.api.response.VpcResponse; + import org.apache.cloudstack.api.response.VpnUsersResponse; + import org.apache.cloudstack.api.response.ZoneResponse; + + import org.apache.cloudstack.api.response.S3Response; + ++import com.cloud.api.response.FindAccountResponse; ++import com.cloud.api.response.FindDomainResponse; ++import com.cloud.api.response.FindUserResponse; ++import com.cloud.api.response.RegionResponse; + import com.cloud.async.AsyncJob; + import com.cloud.capacity.Capacity; + import com.cloud.configuration.Configuration; + import com.cloud.configuration.ResourceCount; + import com.cloud.configuration.ResourceLimit; + import com.cloud.dc.DataCenter; + import com.cloud.dc.Pod; ++import com.cloud.region.Region; + import com.cloud.dc.StorageNetworkIpRange; + import com.cloud.dc.Vlan; + import com.cloud.domain.Domain; + import com.cloud.event.Event; + import com.cloud.host.Host; + import com.cloud.hypervisor.HypervisorCapabilities; + import com.cloud.network.IpAddress; + import com.cloud.network.Network; + import com.cloud.network.Network.Service; + import com.cloud.network.PhysicalNetwork; + import com.cloud.network.PhysicalNetworkServiceProvider; + import com.cloud.network.PhysicalNetworkTrafficType; + import com.cloud.network.RemoteAccessVpn; + import com.cloud.network.Site2SiteCustomerGateway; + import com.cloud.network.Site2SiteVpnConnection; + import com.cloud.network.Site2SiteVpnGateway; + import com.cloud.network.VirtualRouterProvider; + import com.cloud.network.VpnUser; + import com.cloud.network.as.AutoScalePolicy; + import com.cloud.network.as.AutoScaleVmGroup; + import com.cloud.network.as.AutoScaleVmProfile; + import com.cloud.network.as.Condition; + import com.cloud.network.as.Counter; + import com.cloud.network.router.VirtualRouter; + import com.cloud.network.rules.FirewallRule; + import com.cloud.network.rules.LoadBalancer; + import com.cloud.network.rules.PortForwardingRule; + import com.cloud.network.rules.StaticNatRule; + import com.cloud.network.rules.StickinessPolicy; + import com.cloud.network.security.SecurityGroup; + import com.cloud.network.security.SecurityRule; + import com.cloud.network.vpc.PrivateGateway; + import com.cloud.network.vpc.StaticRoute; + import com.cloud.network.vpc.Vpc; + import com.cloud.network.vpc.VpcOffering; + import com.cloud.offering.DiskOffering; + import com.cloud.offering.NetworkOffering; + import com.cloud.offering.ServiceOffering; + import com.cloud.org.Cluster; + import com.cloud.projects.Project; + import com.cloud.projects.ProjectAccount; + import com.cloud.projects.ProjectInvitation; + import com.cloud.server.ResourceTag; + import com.cloud.storage.GuestOS; + import com.cloud.storage.S3; + import com.cloud.storage.Snapshot; + import com.cloud.storage.StoragePool; + import com.cloud.storage.Swift; + import com.cloud.storage.Volume; + import com.cloud.storage.snapshot.SnapshotPolicy; + import com.cloud.storage.snapshot.SnapshotSchedule; + import com.cloud.template.VirtualMachineTemplate; + import com.cloud.user.Account; + import com.cloud.user.User; + import com.cloud.user.UserAccount; + import com.cloud.uservm.UserVm; + import com.cloud.vm.InstanceGroup; + import com.cloud.vm.VirtualMachine; + + public interface ResponseGenerator { + UserResponse createUserResponse(UserAccount user); + + AccountResponse createAccountResponse(Account account); + + DomainResponse createDomainResponse(Domain domain); + + DiskOfferingResponse createDiskOfferingResponse(DiskOffering offering); + + ResourceLimitResponse createResourceLimitResponse(ResourceLimit limit); + + ResourceCountResponse createResourceCountResponse(ResourceCount resourceCount); + + ServiceOfferingResponse createServiceOfferingResponse(ServiceOffering offering); + + ConfigurationResponse createConfigurationResponse(Configuration cfg); + + SnapshotResponse createSnapshotResponse(Snapshot snapshot); + + SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy); + + List createUserVmResponse(String objectName, UserVm... userVms); + + List createUserVmResponse(String objectName, EnumSet details, UserVm... userVms); + + SystemVmResponse createSystemVmResponse(VirtualMachine systemVM); + + DomainRouterResponse createDomainRouterResponse(VirtualRouter router); + + HostResponse createHostResponse(Host host, EnumSet details); + + HostResponse createHostResponse(Host host); + + VlanIpRangeResponse createVlanIpRangeResponse(Vlan vlan); + + IPAddressResponse createIPAddressResponse(IpAddress ipAddress); + + LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer); + + LBStickinessResponse createLBStickinessPolicyResponse(List stickinessPolicies, LoadBalancer lb); + + LBStickinessResponse createLBStickinessPolicyResponse(StickinessPolicy stickinessPolicy, LoadBalancer lb); + + PodResponse createPodResponse(Pod pod, Boolean showCapacities); + + ZoneResponse createZoneResponse(DataCenter dataCenter, Boolean showCapacities); + + VolumeResponse createVolumeResponse(Volume volume); + + InstanceGroupResponse createInstanceGroupResponse(InstanceGroup group); + + StoragePoolResponse createStoragePoolResponse(StoragePool pool); + + ClusterResponse createClusterResponse(Cluster cluster, Boolean showCapacities); + + FirewallRuleResponse createPortForwardingRuleResponse(PortForwardingRule fwRule); + + IpForwardingRuleResponse createIpForwardingRuleResponse(StaticNatRule fwRule); + + User findUserById(Long userId); + + UserVm findUserVmById(Long vmId); + + Volume findVolumeById(Long volumeId); + + Account findAccountByNameDomain(String accountName, Long domainId); + + VirtualMachineTemplate findTemplateById(Long templateId); + + Host findHostById(Long hostId); + + List createTemplateResponses(long templateId, long zoneId, boolean readyOnly); + + VpnUsersResponse createVpnUserResponse(VpnUser user); + + RemoteAccessVpnResponse createRemoteAccessVpnResponse(RemoteAccessVpn vpn); + + List createTemplateResponses(long templateId, Long zoneId, boolean readyOnly); + + List createTemplateResponses(long templateId, Long snapshotId, Long volumeId, boolean readyOnly); + + //ListResponse createSecurityGroupResponses(List networkGroups); + + SecurityGroupResponse createSecurityGroupResponseFromSecurityGroupRule(List SecurityRules); + + SecurityGroupResponse createSecurityGroupResponse(SecurityGroup group); + + ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode); + + String toSerializedString(CreateCmdResponse response, String responseType); + + AsyncJobResponse createAsyncJobResponse(AsyncJob job); + + EventResponse createEventResponse(Event event); + + //List createEventResponse(EventJoinVO... events); + + TemplateResponse createIsoResponse(VirtualMachineTemplate result); + + List createCapacityResponse(List result, DecimalFormat format); + + TemplatePermissionsResponse createTemplatePermissionsResponse(List accountNames, Long id, boolean isAdmin); + + AsyncJobResponse queryJobResult(QueryAsyncJobResultCmd cmd); + + NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering); + + NetworkResponse createNetworkResponse(Network network); + + UserResponse createUserResponse(User user); + + //List createUserResponse(UserAccountJoinVO... users); + + AccountResponse createUserAccountResponse(UserAccount user); + + Long getSecurityGroupId(String groupName, long accountId); + + List createIsoResponses(long isoId, Long zoneId, boolean readyOnly); + + ProjectResponse createProjectResponse(Project project); + + + List createIsoResponses(VirtualMachineTemplate iso, long zoneId, boolean readyOnly); + + List createTemplateResponses(long templateId, Long vmId); + + FirewallResponse createFirewallResponse(FirewallRule fwRule); + + HypervisorCapabilitiesResponse createHypervisorCapabilitiesResponse(HypervisorCapabilities hpvCapabilities); + + ProjectAccountResponse createProjectAccountResponse(ProjectAccount projectAccount); + + ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite); + + SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine systemVM); + + SwiftResponse createSwiftResponse(Swift swift); + + S3Response createS3Response(S3 result); + + PhysicalNetworkResponse createPhysicalNetworkResponse(PhysicalNetwork result); + + ServiceResponse createNetworkServiceResponse(Service service); + + ProviderResponse createNetworkServiceProviderResponse(PhysicalNetworkServiceProvider result); + + TrafficTypeResponse createTrafficTypeResponse(PhysicalNetworkTrafficType result); + + VirtualRouterProviderResponse createVirtualRouterProviderResponse(VirtualRouterProvider result); + + LDAPConfigResponse createLDAPConfigResponse(String hostname, Integer port, Boolean useSSL, String queryFilter, String baseSearch, String dn); + + StorageNetworkIpRangeResponse createStorageNetworkIpRangeResponse(StorageNetworkIpRange result); ++ ++ RegionResponse createRegionResponse(Region region); + + /** + * @param resourceTag + * @param keyValueOnly TODO + * @return + */ + ResourceTagResponse createResourceTagResponse(ResourceTag resourceTag, boolean keyValueOnly); + + + Site2SiteVpnGatewayResponse createSite2SiteVpnGatewayResponse(Site2SiteVpnGateway result); + + + /** + * @param offering + * @return + */ + VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering); + + /** + * @param vpc + * @return + */ + VpcResponse createVpcResponse(Vpc vpc); + + /** + * @param networkACL + * @return + */ + NetworkACLResponse createNetworkACLResponse(FirewallRule networkACL); + + /** + * @param result + * @return + */ + PrivateGatewayResponse createPrivateGatewayResponse(PrivateGateway result); + + /** + * @param result + * @return + */ + StaticRouteResponse createStaticRouteResponse(StaticRoute result); + + Site2SiteCustomerGatewayResponse createSite2SiteCustomerGatewayResponse(Site2SiteCustomerGateway result); + + Site2SiteVpnConnectionResponse createSite2SiteVpnConnectionResponse(Site2SiteVpnConnection result); + ++ FindUserResponse createFindUserResponse(User user); ++ ++ FindAccountResponse createFindAccountResponse(Account account); ++ ++ FindDomainResponse createFindDomainResponse(Domain domain); + CounterResponse createCounterResponse(Counter ctr); + + ConditionResponse createConditionResponse(Condition cndn); + + AutoScalePolicyResponse createAutoScalePolicyResponse(AutoScalePolicy policy); + + AutoScaleVmProfileResponse createAutoScaleVmProfileResponse(AutoScaleVmProfile profile); + + AutoScaleVmGroupResponse createAutoScaleVmGroupResponse(AutoScaleVmGroup vmGroup); + + GuestOSResponse createGuestOSResponse(GuestOS os); + + SnapshotScheduleResponse createSnapshotScheduleResponse(SnapshotSchedule sched); + } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f57d925/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java ---------------------------------------------------------------------- diff --cc api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java index 0000000,a13cf62..7c2f2d1 mode 000000,100644..100644 --- a/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java @@@ -1,0 -1,157 +1,183 @@@ + // Licensed to the Apache Software Foundation (ASF) under one + // or more contributor license agreements. See the NOTICE file + // distributed with this work for additional information + // regarding copyright ownership. The ASF 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.apache.cloudstack.api.command.admin.account; + + import java.util.Collection; + import java.util.Map; + + import org.apache.cloudstack.api.*; + import org.apache.log4j.Logger; + + import org.apache.cloudstack.api.APICommand; + import org.apache.cloudstack.api.response.AccountResponse; + import org.apache.cloudstack.api.response.DomainResponse; + import org.apache.cloudstack.api.response.UserResponse; + import com.cloud.user.Account; + import com.cloud.user.UserAccount; + import com.cloud.user.UserContext; + + @APICommand(name = "createAccount", description="Creates an account", responseObject=UserResponse.class) + public class CreateAccountCmd extends BaseCmd { + public static final Logger s_logger = Logger.getLogger(CreateAccountCmd.class.getName()); + + private static final String s_name = "createaccountresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="Creates the user under the specified account. If no account is specified, the username will be used as the account name.") + private String accountName; + + @Parameter(name=ApiConstants.ACCOUNT_TYPE, type=CommandType.SHORT, required=true, description="Type of the account. Specify 0 for user, 1 for root admin, and 2 for domain admin") + private Short accountType; + + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType=DomainResponse.class, + description="Creates the user under the specified domain.") + private Long domainId; + + @Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, required=true, description="email") + private String email; + + @Parameter(name=ApiConstants.FIRSTNAME, type=CommandType.STRING, required=true, description="firstname") + private String firstName; + + @Parameter(name=ApiConstants.LASTNAME, type=CommandType.STRING, required=true, description="lastname") + private String lastName; + + @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required=true, description="Hashed password (Default is MD5). If you wish to use any other hashing algorithm, you would need to write a custom authentication adapter See Docs section.") + private String password; + + @Parameter(name=ApiConstants.TIMEZONE, type=CommandType.STRING, description="Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.") + private String timeZone; + + @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required=true, description="Unique username.") + private String userName; + + @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="Network domain for the account's networks") + private String networkDomain; + + @Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters") + private Map details; ++ ++ //@Parameter(name = ApiConstants.REGION_DETAILS, type = CommandType.MAP, description = "details for account used to store region specific parameters") ++ //private Map regionDetails; ++ ++ @Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.STRING, description="Account UUID, required for adding account from another Region") ++ private String accountUUID; + ++ @Parameter(name=ApiConstants.USER_ID, type=CommandType.STRING, description="User UUID, required for adding account from another Region") ++ private String userUUID; ++ ++ @Parameter(name=ApiConstants.REGION_ID, type=CommandType.INTEGER, description="Id of the Region creating the account") ++ private Integer regionId; ++ ++ + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getAccountName() { + return accountName; + } + + public Short getAccountType() { + return accountType; + } + + public Long getDomainId() { + return domainId; + } + + public String getEmail() { + return email; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getPassword() { + return password; + } + + public String getTimeZone() { + return timeZone; + } + + public String getUsername() { + return userName; + } + + public String getNetworkDomain() { + return networkDomain; + } + + public Map getDetails() { + if (details == null || details.isEmpty()) { + return null; + } + + Collection paramsCollection = details.values(); + Map params = (Map) (paramsCollection.toArray())[0]; + return params; + } + ++ public String getAccountUUID() { ++ return accountUUID; ++ } ++ ++ public String getUserUUID() { ++ return userUUID; ++ } ++ ++ public Integer getRegionId() { ++ return regionId; ++ } ++ + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + - @Override ++ @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + UserContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId()); - UserAccount userAccount = _accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(), getDomainId(), getNetworkDomain(), getDetails()); ++ UserAccount userAccount = _accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(), getDomainId(), getNetworkDomain(), getDetails(), ++ getAccountUUID(), getUserUUID(), getRegionId()); + if (userAccount != null) { + AccountResponse response = _responseGenerator.createUserAccountResponse(userAccount); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a user account"); + } + } + } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f57d925/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java ---------------------------------------------------------------------- diff --cc api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java index 0000000,86ccb4b..c918655 mode 000000,100644..100644 --- a/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java @@@ -1,0 -1,102 +1,116 @@@ + // Licensed to the Apache Software Foundation (ASF) under one + // or more contributor license agreements. See the NOTICE file + // distributed with this work for additional information + // regarding copyright ownership. The ASF 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.apache.cloudstack.api.command.admin.account; + + import org.apache.cloudstack.api.*; + import org.apache.log4j.Logger; + + import org.apache.cloudstack.api.APICommand; + import org.apache.cloudstack.api.response.AccountResponse; + import org.apache.cloudstack.api.response.SuccessResponse; + import com.cloud.async.AsyncJob; + import com.cloud.event.EventTypes; + import com.cloud.user.Account; + import com.cloud.user.User; + import com.cloud.user.UserContext; + + @APICommand(name = "deleteAccount", description="Deletes a account, and all users associated with this account", responseObject=SuccessResponse.class) + public class DeleteAccountCmd extends BaseAsyncCmd { + public static final Logger s_logger = Logger.getLogger(DeleteAccountCmd.class.getName()); + private static final String s_name = "deleteaccountresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=AccountResponse.class, + required=true, description="Account id") + private Long id; + ++ @Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region") ++ private Boolean isPropagate; ++ + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + - public Long getId() { ++ ++ public Long getId() { + return id; + } ++ ++ public Boolean getIsPropagate() { ++ return isPropagate; ++ } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + public static String getStaticName() { + return s_name; + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller();// Let's give the caller here for event logging. + if (account != null) { + return account.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + + @Override + public String getEventType() { + return EventTypes.EVENT_ACCOUNT_DELETE; + } + + @Override + public String getEventDescription() { + User user = _responseGenerator.findUserById(getId()); + return (user != null ? ("deleting User " + user.getUsername() + " (id: " + user.getId() + ") and accountId = " + user.getAccountId()) : "user delete, but this user does not exist in the system"); + } + + @Override + public void execute(){ + UserContext.current().setEventDetails("Account Id: "+getId()); - boolean result = _accountService.deleteUserAccount(getId()); ++ boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false; ++ boolean result = false; ++ if(isPopagate){ ++ result = _accountService.deleteUserAccount(getId()); ++ } else { ++ result = _regionService.deleteUserAccount(getId()); ++ } + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete user account and all corresponding users"); + } + } + + @Override + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Account; + } + }