You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ml...@apache.org on 2013/01/10 01:48:37 UTC
[12/52] [partial] Summary: Fixes for api_refactoring
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java
new file mode 100644
index 0000000..65df48e
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java
@@ -0,0 +1,106 @@
+// 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.vpc;
+
+import org.apache.cloudstack.api.*;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.response.VpcOfferingResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.network.vpc.VpcOffering;
+import com.cloud.user.Account;
+
+@APICommand(name = "updateVPCOffering", description="Updates VPC offering", responseObject=VpcOfferingResponse.class)
+public class UpdateVPCOfferingCmd extends BaseAsyncCmd{
+ public static final Logger s_logger = Logger.getLogger(UpdateVPCOfferingCmd.class.getName());
+ private static final String _name = "updatevpcofferingresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = VpcOfferingResponse.class,
+ description="the id of the VPC offering")
+ private Long id;
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the VPC offering")
+ private String vpcOffName;
+
+ @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the VPC offering")
+ private String displayText;
+
+ @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="update state for the VPC offering; " +
+ "supported states - Enabled/Disabled")
+ private String state;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getVpcOfferingName() {
+ return vpcOffName;
+ }
+
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+ @Override
+ public String getCommandName() {
+ return _name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public void execute(){
+ VpcOffering result = _vpcService.updateVpcOffering(getId(), getVpcOfferingName(), getDisplayText(), getState());
+ if (result != null) {
+ VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update VPC offering");
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_VPC_OFFERING_UPDATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Updating VPC offering id=" + getId();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java
new file mode 100644
index 0000000..e49f243
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java
@@ -0,0 +1,162 @@
+// 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.zone;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+import com.cloud.dc.DataCenter;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@APICommand(name = "createZone", description="Creates a Zone.", responseObject=ZoneResponse.class)
+public class CreateZoneCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateZoneCmd.class.getName());
+
+ private static final String s_name = "createzoneresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.DNS1, type=CommandType.STRING, required=true, description="the first DNS for the Zone")
+ private String dns1;
+
+ @Parameter(name=ApiConstants.DNS2, type=CommandType.STRING, description="the second DNS for the Zone")
+ private String dns2;
+
+ @Parameter(name=ApiConstants.GUEST_CIDR_ADDRESS, type=CommandType.STRING, description="the guest CIDR address for the Zone")
+ private String guestCidrAddress;
+
+ @Parameter(name=ApiConstants.INTERNAL_DNS1, type=CommandType.STRING, required=true, description="the first internal DNS for the Zone")
+ private String internalDns1;
+
+ @Parameter(name=ApiConstants.INTERNAL_DNS2, type=CommandType.STRING, description="the second internal DNS for the Zone")
+ private String internalDns2;
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the Zone")
+ private String zoneName;
+
+ @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="Network domain name for the networks in the zone")
+ private String domain;
+
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType=DomainResponse.class,
+ description="the ID of the containing domain, null for public zones")
+ private Long domainId;
+
+ @Parameter(name=ApiConstants.NETWORK_TYPE, type=CommandType.STRING, required=true, description="network type of the zone, can be Basic or Advanced")
+ private String networkType;
+
+ @Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this Zone for allocation of new resources")
+ private String allocationState;
+
+ @Parameter(name=ApiConstants.SECURITY_GROUP_EANBLED, type=CommandType.BOOLEAN, description="true if network is security group enabled, false otherwise")
+ private Boolean securitygroupenabled;
+
+ @Parameter(name=ApiConstants.LOCAL_STORAGE_ENABLED, type=CommandType.BOOLEAN, description="true if local storage offering enabled, false otherwise")
+ private Boolean localStorageEnabled;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getDns1() {
+ return dns1;
+ }
+
+ public String getDns2() {
+ return dns2;
+ }
+
+ public String getGuestCidrAddress() {
+ return guestCidrAddress;
+ }
+
+ public String getInternalDns1() {
+ return internalDns1;
+ }
+
+ public String getInternalDns2() {
+ return internalDns2;
+ }
+
+ public String getZoneName() {
+ return zoneName;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public Long getDomainId(){
+ return domainId;
+ }
+
+ public String getNetworkType(){
+ return networkType;
+ }
+
+ public String getAllocationState() {
+ return allocationState;
+ }
+
+ public Boolean getSecuritygroupenabled() {
+ if (securitygroupenabled == null) {
+ return false;
+ }
+ return securitygroupenabled;
+ }
+
+ public Boolean getLocalStorageEnabled() {
+ if (localStorageEnabled == null) {
+ return false;
+ }
+ return localStorageEnabled;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("Zone Name: "+getZoneName());
+ DataCenter result = _configService.createZone(this);
+ if (result != null){
+ ZoneResponse response = _responseGenerator.createZoneResponse(result,false);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a zone");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java
new file mode 100644
index 0000000..d09c7ff
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java
@@ -0,0 +1,77 @@
+// 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.zone;
+
+import org.apache.cloudstack.api.*;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@APICommand(name = "deleteZone", description="Deletes a Zone.", responseObject=SuccessResponse.class)
+public class DeleteZoneCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(DeleteZoneCmd.class.getName());
+
+ private static final String s_name = "deletezoneresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=ZoneResponse.class,
+ required=true, description="the ID of the Zone")
+ private Long id;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("Zone Id: "+getId());
+ boolean result = _configService.deleteZone(this);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete zone");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java
new file mode 100644
index 0000000..816befb
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java
@@ -0,0 +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.zone;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ApiConstants;
+import com.cloud.user.Account;
+import com.cloud.event.EventTypes;
+import com.cloud.async.AsyncJob;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.BaseCmd;
+
+@APICommand(name = "markDefaultZoneForAccount", description="Marks a default zone for this account", responseObject=AccountResponse.class, since="4.0")
+public class MarkDefaultZoneForAccountCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(MarkDefaultZoneForAccountCmd.class.getName());
+
+ private static final String s_name = "markdefaultzoneforaccountresponse";
+
+ /////////////////////////////////////////////////////
+ ////////////////API parameters //////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, entityType=AccountResponse.class,
+ required=true, description="Name of the account that is to be marked.")
+ private String accountName;
+
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType=DomainResponse.class,
+ required=true, description="Marks the account that belongs to the specified domain.")
+ private Long domainId;
+
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class,
+ required=true, description="The Zone ID with which the account is to be marked.")
+ private Long defaultZoneId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public Long getDefaultZoneId() {
+ return defaultZoneId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_ACCOUNT_MARK_DEFAULT_ZONE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Marking account with the default zone: " + getDefaultZoneId();
+ }
+
+ @Override
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.Account;
+ }
+
+ @Override
+ public void execute(){
+ Account result = _configService.markDefaultZone(getAccountName(),getDomainId(), getDefaultZoneId());
+ if (result != null) {
+ AccountResponse response = _responseGenerator.createAccountResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+ else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to mark the account with the default zone");
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java
new file mode 100644
index 0000000..0bfd1a3
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java
@@ -0,0 +1,170 @@
+// 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.zone;
+
+import java.util.List;
+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.ZoneResponse;
+import com.cloud.dc.DataCenter;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@APICommand(name = "updateZone", description="Updates a Zone.", responseObject=ZoneResponse.class)
+public class UpdateZoneCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(UpdateZoneCmd.class.getName());
+
+ private static final String s_name = "updatezoneresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.DNS1, type=CommandType.STRING, description="the first DNS for the Zone")
+ private String dns1;
+
+ @Parameter(name=ApiConstants.DNS2, type=CommandType.STRING, description="the second DNS for the Zone")
+ private String dns2;
+
+ @Parameter(name=ApiConstants.GUEST_CIDR_ADDRESS, type=CommandType.STRING, description="the guest CIDR address for the Zone")
+ private String guestCidrAddress;
+
+ @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=ZoneResponse.class,
+ required=true, description="the ID of the Zone")
+ private Long id;
+
+ @Parameter(name=ApiConstants.INTERNAL_DNS1, type=CommandType.STRING, description="the first internal DNS for the Zone")
+ private String internalDns1;
+
+ @Parameter(name=ApiConstants.INTERNAL_DNS2, type=CommandType.STRING, description="the second internal DNS for the Zone")
+ private String internalDns2;
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the Zone")
+ private String zoneName;
+
+ @Parameter(name=ApiConstants.IS_PUBLIC, type=CommandType.BOOLEAN, description="updates a private zone to public if set, but not vice-versa")
+ private Boolean isPublic;
+
+ @Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this cluster for allocation of new resources")
+ private String allocationState;
+
+ @Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="the details for the Zone")
+ private Map details;
+
+ @Parameter(name=ApiConstants.DHCP_PROVIDER, type=CommandType.STRING, description="the dhcp Provider for the Zone")
+ private String dhcpProvider;
+
+ @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="Network domain name for the networks in the zone; empty string will update domain with NULL value")
+ private String domain;
+
+ @Parameter(name=ApiConstants.DNS_SEARCH_ORDER, type=CommandType.LIST, collectionType = CommandType.STRING, description="the dns search order list")
+ private List<String> dnsSearchOrder;
+
+ @Parameter(name=ApiConstants.LOCAL_STORAGE_ENABLED, type=CommandType.BOOLEAN, description="true if local storage offering enabled, false otherwise")
+ private Boolean localStorageEnabled;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getDns1() {
+ return dns1;
+ }
+
+ public String getDns2() {
+ return dns2;
+ }
+
+ public String getGuestCidrAddress() {
+ return guestCidrAddress;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getInternalDns1() {
+ return internalDns1;
+ }
+
+ public String getInternalDns2() {
+ return internalDns2;
+ }
+
+ public String getZoneName() {
+ return zoneName;
+ }
+
+ public Boolean isPublic() {
+ return isPublic;
+ }
+
+ public String getAllocationState() {
+ return allocationState;
+ }
+
+ public Map getDetails() {
+ return details;
+ }
+
+ public String getDhcpProvider() {
+ return dhcpProvider;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public List<String> getDnsSearchOrder() {
+ return dnsSearchOrder;
+ }
+
+ public Boolean getLocalStorageEnabled() {
+ return localStorageEnabled;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("Zone Id: "+getId());
+ DataCenter result = _configService.editZone(this);
+ if (result != null) {
+ ZoneResponse response = _responseGenerator.createZoneResponse(result, false);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update zone; internal error.");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java
new file mode 100644
index 0000000..889c369
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java
@@ -0,0 +1,120 @@
+// 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.user.account;
+
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.response.ProjectResponse;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.projects.Project;
+import com.cloud.user.UserContext;
+
+
+@APICommand(name = "addAccountToProject", description="Adds acoount to a project", responseObject=SuccessResponse.class, since="3.0.0")
+public class AddAccountToProjectCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(AddAccountToProjectCmd.class.getName());
+
+ private static final String s_name = "addaccounttoprojectresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
+ required=true, description="id of the project to add the account to")
+ private Long projectId;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="name of the account to be added to the project")
+ private String accountName;
+
+ @Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, description="email to which invitation to the project is going to be sent")
+ private String email;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Long getProjectId() {
+ return projectId;
+ }
+
+
+ public String getEmail() {
+ return email;
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public void execute(){
+ if (accountName == null && email == null) {
+ throw new InvalidParameterValueException("Either accountName or email is required");
+ }
+
+ UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
+ boolean result = _projectService.addAccountToProject(getProjectId(), getAccountName(), getEmail());
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add account to the project");
+ }
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Project project= _projectService.getProject(getProjectId());
+ //verify input parameters
+ if (project == null) {
+ InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id");
+ ex.addProxyObject(project, getProjectId(), "projectId");
+ throw ex;
+ }
+
+ return _projectService.getProjectOwner(getProjectId()).getId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_PROJECT_ACCOUNT_ADD;
+ }
+
+ @Override
+ public String getEventDescription() {
+ if (accountName != null) {
+ return "Adding account " + getAccountName() + " to project: " + getProjectId();
+ } else {
+ return "Sending invitation to email " + email + " to join project: " + getProjectId();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java
new file mode 100644
index 0000000..f9e967a
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java
@@ -0,0 +1,104 @@
+// 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.user.account;
+
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.command.user.project.DeleteProjectCmd;
+import org.apache.cloudstack.api.response.ProjectResponse;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.projects.Project;
+import com.cloud.user.UserContext;
+
+@APICommand(name = "deleteAccountFromProject", description="Deletes account from the project", responseObject=SuccessResponse.class, since="3.0.0")
+public class DeleteAccountFromProjectCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(DeleteProjectCmd.class.getName());
+
+ private static final String s_name = "deleteaccountfromprojectresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
+ required=true, description="id of the project to remove the account from")
+ private Long projectId;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="name of the account to be removed from the project")
+ private String accountName;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getProjectId() {
+ return projectId;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
+ boolean result = _projectService.deleteAccountFromProject(projectId, accountName);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete account from the project");
+ }
+ }
+
+
+ @Override
+ public long getEntityOwnerId() {
+ Project project= _projectService.getProject(projectId);
+ //verify input parameters
+ if (project == null) {
+ throw new InvalidParameterValueException("Unable to find project by id " + projectId);
+ }
+
+ return _projectService.getProjectOwner(projectId).getId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Removing account " + accountName + " from project: " + projectId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java b/api/src/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java
new file mode 100644
index 0000000..f679a5a
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java
@@ -0,0 +1,100 @@
+// 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.user.account;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.UserResponse;
+
+import com.cloud.user.Account;
+import com.cloud.utils.Pair;
+
+@APICommand(name = "listAccounts", description="Lists accounts and provides detailed account information for listed accounts", responseObject=AccountResponse.class)
+public class ListAccountsCmd extends BaseListDomainResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName());
+ private static final String s_name = "listaccountsresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ACCOUNT_TYPE, type=CommandType.LONG, description="list accounts by account type. Valid account types are 1 (admin), 2 (domain-admin), and 0 (user).")
+ private Long accountType;
+
+ @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = AccountResponse.class,
+ description="list account by account ID")
+ private Long id;
+
+ @Parameter(name=ApiConstants.IS_CLEANUP_REQUIRED, type=CommandType.BOOLEAN, description="list accounts by cleanuprequred attribute (values are true or false)")
+ private Boolean cleanupRequired;
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list account by account name")
+ private String searchName;
+
+ @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list accounts by state. Valid states are enabled, disabled, and locked.")
+ private String state;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getAccountType() {
+ return accountType;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public Boolean isCleanupRequired() {
+ return cleanupRequired;
+ }
+
+ public String getSearchName() {
+ return searchName;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute(){
+ ListResponse<AccountResponse> response = _queryService.searchForAccounts(this);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java b/api/src/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java
new file mode 100644
index 0000000..2c279db
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java
@@ -0,0 +1,93 @@
+// 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.user.account;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.ProjectAccountResponse;
+import org.apache.cloudstack.api.response.ProjectResponse;
+
+import com.cloud.user.Account;
+
+@APICommand(name = "listProjectAccounts", description="Lists project's accounts", responseObject=ProjectResponse.class, since="3.0.0")
+public class ListProjectAccountsCmd extends BaseListCmd {
+ public static final Logger s_logger = Logger.getLogger(ListProjectAccountsCmd.class.getName());
+
+ private static final String s_name = "listprojectaccountsresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
+ required=true, description="id of the project")
+ private Long projectId;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="list accounts of the project by account name")
+ private String accountName;
+
+ @Parameter(name=ApiConstants.ROLE, type=CommandType.STRING, description="list accounts of the project by role")
+ private String role;
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+
+ public Long getProjectId() {
+ return projectId;
+ }
+
+
+ public String getRole() {
+ return role;
+ }
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ //TODO - return project entity ownerId
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public void execute(){
+ ListResponse<ProjectAccountResponse> response = _queryService.listProjectAccounts(this);
+ response.setResponseName(getCommandName());
+
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java
new file mode 100644
index 0000000..7d4e44b
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java
@@ -0,0 +1,274 @@
+// 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.user.address;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.IPAddressResponse;
+import org.apache.cloudstack.api.response.ProjectResponse;
+import org.apache.cloudstack.api.response.NetworkResponse;
+import org.apache.cloudstack.api.response.VpcResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.DataCenter.NetworkType;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.IpAddress;
+import com.cloud.network.Network;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@APICommand(name = "associateIpAddress", description="Acquires and associates a public IP to an account.", responseObject=IPAddressResponse.class)
+public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
+ public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmd.class.getName());
+ private static final String s_name = "associateipaddressresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING,
+ description="the account to associate with this IP address")
+ private String accountName;
+
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class,
+ description="the ID of the domain to associate with this IP address")
+ private Long domainId;
+
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
+ description="the ID of the availability zone you want to acquire an public IP address from")
+ private Long zoneId;
+
+ @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.UUID, entityType = NetworkResponse.class,
+ description="The network this ip address should be associated to.")
+ private Long networkId;
+
+ @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
+ description="Deploy vm for the project")
+ private Long projectId;
+
+ @Parameter(name=ApiConstants.VPC_ID, type=CommandType.UUID, entityType = VpcResponse.class,
+ description="the VPC you want the ip address to " +
+ "be associated with")
+ private Long vpcId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "user_ip_address";
+ }
+
+ public String getAccountName() {
+ if (accountName != null) {
+ return accountName;
+ }
+ return UserContext.current().getCaller().getAccountName();
+ }
+
+ public long getDomainId() {
+ if (domainId != null) {
+ return domainId;
+ }
+ return UserContext.current().getCaller().getDomainId();
+ }
+
+ private long getZoneId() {
+ if (zoneId != null) {
+ return zoneId;
+ } else if (vpcId != null) {
+ Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
+ if (vpc != null) {
+ return vpc.getZoneId();
+ }
+ } else if (networkId != null) {
+ Network ntwk = _entityMgr.findById(Network.class, networkId);
+ if (ntwk != null) {
+ return ntwk.getDataCenterId();
+ }
+ }
+
+ throw new InvalidParameterValueException("Unable to figure out zone to assign ip to");
+ }
+
+ public Long getVpcId() {
+ return vpcId;
+ }
+
+ public Long getNetworkId() {
+ if (vpcId != null) {
+ return null;
+ }
+
+ if (networkId != null) {
+ return networkId;
+ }
+ Long zoneId = getZoneId();
+
+ if (zoneId == null) {
+ return null;
+ }
+
+ DataCenter zone = _configService.getZone(zoneId);
+ if (zone.getNetworkType() == NetworkType.Advanced) {
+ List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(),
+ _accountService.getAccount(getEntityOwnerId()));
+ if (networks.size() == 0) {
+ String domain = _domainService.getDomain(getDomainId()).getName();
+ throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain +
+ " doesn't have virtual networks in zone=" + zone.getName());
+ }
+
+ if (networks.size() < 1) {
+ throw new InvalidParameterValueException("Account doesn't have any Isolated networks in the zone");
+ } else if (networks.size() > 1) {
+ throw new InvalidParameterValueException("Account has more than one Isolated network in the zone");
+ }
+
+ return networks.get(0).getId();
+ } else {
+ Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId);
+ if (defaultGuestNetwork == null) {
+ throw new InvalidParameterValueException("Unable to find a default Guest network for account " +
+ getAccountName() + " in domain id=" + getDomainId());
+ } else {
+ return defaultGuestNetwork.getId();
+ }
+ }
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Account caller = UserContext.current().getCaller();
+ if (accountName != null && domainId != null) {
+ Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
+ return account.getId();
+ } else if (networkId != null){
+ Network network = _networkService.getNetwork(networkId);
+ return network.getAccountId();
+ } else if (vpcId != null) {
+ Vpc vpc = _vpcService.getVpc(getVpcId());
+ if (vpc == null) {
+ throw new InvalidParameterValueException("Can't find Enabled vpc by id specified");
+ }
+ return vpc.getAccountId();
+ }
+
+ return caller.getAccountId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_NET_IP_ASSIGN;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "associating ip to network id: " + getNetworkId() + " in zone " + getZoneId();
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public static String getResultObjectName() {
+ return "addressinfo";
+ }
+
+ @Override
+ public void create() throws ResourceAllocationException{
+ try {
+ IpAddress ip = _networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNetworkId());
+
+ if (ip != null) {
+ this.setEntityId(ip.getId());
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to allocate ip address");
+ }
+ } catch (ConcurrentOperationException ex) {
+ s_logger.warn("Exception: ", ex);
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
+ } catch (InsufficientAddressCapacityException ex) {
+ s_logger.info(ex);
+ s_logger.trace(ex);
+ throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
+ }
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException, ResourceAllocationException,
+ ConcurrentOperationException, InsufficientCapacityException {
+ UserContext.current().setEventDetails("Ip Id: " + getEntityId());
+
+ IpAddress result = null;
+
+ if (getVpcId() != null) {
+ result = _vpcService.associateIPToVpc(getEntityId(), getVpcId());
+ } else if (getNetworkId() != null) {
+ result = _networkService.associateIPToNetwork(getEntityId(), getNetworkId());
+ }
+
+ if (result != null) {
+ IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(result);
+ ipResponse.setResponseName(getCommandName());
+ this.setResponseObject(ipResponse);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to assign ip address");
+ }
+ }
+
+
+ @Override
+ public String getSyncObjType() {
+ return BaseAsyncCmd.networkSyncObject;
+ }
+
+ @Override
+ public Long getSyncObjId() {
+ return getNetworkId();
+ }
+
+ @Override
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.IpAddress;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java
new file mode 100644
index 0000000..20ccd89
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java
@@ -0,0 +1,138 @@
+// 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.user.address;
+
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.IPAddressResponse;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.network.IpAddress;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@APICommand(name = "disassociateIpAddress", description="Disassociates an ip address from the account.", responseObject=SuccessResponse.class)
+public class DisassociateIPAddrCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(DisassociateIPAddrCmd.class.getName());
+
+ private static final String s_name = "disassociateipaddressresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ID, type=CommandType.UUID,entityType = IPAddressResponse.class,
+ required=true, description="the id of the public ip address" +
+ " to disassociate")
+ private Long id;
+
+ // unexposed parameter needed for events logging
+ @Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.UUID, entityType = AccountResponse.class,
+ expose=false)
+ private Long ownerId;
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getIpAddressId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute() throws InsufficientAddressCapacityException{
+ UserContext.current().setEventDetails("Ip Id: " + getIpAddressId());
+ boolean result = _networkService.releaseIpAddress(getIpAddressId());
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disassociate ip address");
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_NET_IP_RELEASE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return ("Disassociating ip address with id=" + id);
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ if (ownerId == null) {
+ IpAddress ip = getIpAddress(id);
+ if (ip == null) {
+ throw new InvalidParameterValueException("Unable to find ip address by id=" + id);
+ }
+ ownerId = ip.getAccountId();
+ }
+
+ if (ownerId == null) {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+ return ownerId;
+ }
+
+ @Override
+ public String getSyncObjType() {
+ return BaseAsyncCmd.networkSyncObject;
+ }
+
+ @Override
+ public Long getSyncObjId() {
+ IpAddress ip = getIpAddress(id);
+ return ip.getAssociatedWithNetworkId();
+ }
+
+ private IpAddress getIpAddress(long id) {
+ IpAddress ip = _entityMgr.findById(IpAddress.class, id);
+
+ if (ip == null) {
+ throw new InvalidParameterValueException("Unable to find ip address by id=" + id);
+ } else {
+ return ip;
+ }
+ }
+
+ @Override
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.IpAddress;
+ }
+
+ @Override
+ public Long getInstanceId() {
+ return getIpAddressId();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java b/api/src/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
new file mode 100644
index 0000000..06b08da
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
@@ -0,0 +1,182 @@
+// 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.user.address;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.IPAddressResponse;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
+import org.apache.cloudstack.api.response.NetworkResponse;
+import org.apache.cloudstack.api.response.VlanIpRangeResponse;
+import org.apache.cloudstack.api.response.VpcResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.network.IpAddress;
+import com.cloud.utils.Pair;
+
+@APICommand(name = "listPublicIpAddresses", description="Lists all public ip addresses", responseObject=IPAddressResponse.class)
+public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmd.class.getName());
+
+ private static final String s_name = "listpublicipaddressesresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ALLOCATED_ONLY, type=CommandType.BOOLEAN, description="limits search results to allocated public IP addresses")
+ private Boolean allocatedOnly;
+
+ @Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="the virtual network for the IP address")
+ private Boolean forVirtualNetwork;
+
+ @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = IPAddressResponse.class,
+ description="lists ip address by id")
+ private Long id;
+
+ @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="lists the specified IP address")
+ private String ipAddress;
+
+ @Parameter(name=ApiConstants.VLAN_ID, type=CommandType.UUID, entityType = VlanIpRangeResponse.class,
+ description="lists all public IP addresses by VLAN ID")
+ private Long vlanId;
+
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
+ description="lists all public IP addresses by Zone ID")
+ private Long zoneId;
+
+ @Parameter(name=ApiConstants.FOR_LOAD_BALANCING, type=CommandType.BOOLEAN, description="list only ips used for load balancing")
+ private Boolean forLoadBalancing;
+
+ @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.UUID, entityType = PhysicalNetworkResponse.class,
+ description="lists all public IP addresses by physical network id")
+ private Long physicalNetworkId;
+
+ @Parameter(name=ApiConstants.ASSOCIATED_NETWORK_ID, type=CommandType.UUID, entityType = NetworkResponse.class,
+ description="lists all public IP addresses associated to the network specified")
+ private Long associatedNetworkId;
+
+ @Parameter(name=ApiConstants.IS_SOURCE_NAT, type=CommandType.BOOLEAN, description="list only source nat ip addresses")
+ private Boolean isSourceNat;
+
+ @Parameter(name=ApiConstants.IS_STATIC_NAT, type=CommandType.BOOLEAN, description="list only static nat ip addresses")
+ private Boolean isStaticNat;
+
+ @Parameter(name=ApiConstants.VPC_ID, type=CommandType.UUID, entityType = VpcResponse.class,
+ description="List ips belonging to the VPC")
+ private Long vpcId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+ public Long getId() {
+ return id;
+ }
+
+ public Boolean isAllocatedOnly() {
+ return allocatedOnly;
+ }
+
+ public Boolean isForVirtualNetwork() {
+ return forVirtualNetwork;
+ }
+
+ public String getIpAddress() {
+ return ipAddress;
+ }
+
+ public Long getVlanId() {
+ return vlanId;
+ }
+
+ public Long getZoneId() {
+ return zoneId;
+ }
+
+ public Long getPhysicalNetworkId() {
+ return physicalNetworkId;
+ }
+
+ public Long getAssociatedNetworkId() {
+ return associatedNetworkId;
+ }
+
+ public Boolean getIsSourceNat() {
+ return isSourceNat;
+ }
+
+ public Boolean getIsStaticNat() {
+ return isStaticNat;
+ }
+
+ public Long getVpcId() {
+ return vpcId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute(){
+ Pair<List<? extends IpAddress>, Integer> result = _mgr.searchForIPAddresses(this);
+ ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
+ List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
+ for (IpAddress ipAddress : result.first()) {
+ IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ipAddress);
+ ipResponse.setObjectName("publicipaddress");
+ ipAddrResponses.add(ipResponse);
+ }
+
+ response.setResponses(ipAddrResponses, result.second());
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.IpAddress;
+ }
+
+
+ public Boolean isForLoadBalancing() {
+ return forLoadBalancing;
+ }
+
+ public Boolean getAllocatedOnly() {
+ return allocatedOnly;
+ }
+
+ public Boolean getForVirtualNetwork() {
+ return forVirtualNetwork;
+ }
+
+ public Boolean getForLoadBalancing() {
+ return forLoadBalancing;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java
new file mode 100644
index 0000000..db3aaa6
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java
@@ -0,0 +1,166 @@
+// 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.user.autoscale;
+
+import java.util.List;
+
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.response.ConditionResponse;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.domain.Domain;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.network.as.AutoScalePolicy;
+import com.cloud.network.as.Condition;
+import com.cloud.user.Account;
+
+@APICommand(name = "createAutoScalePolicy", description = "Creates an autoscale policy for a provision or deprovision action, the action is taken when the all the conditions evaluates to true for the specified duration. The policy is in effect once it is attached to a autscale vm group.", responseObject = AutoScalePolicyResponse.class)
+public class CreateAutoScalePolicyCmd extends BaseAsyncCreateCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateAutoScalePolicyCmd.class.getName());
+
+ private static final String s_name = "autoscalepolicyresponse";
+
+ // ///////////////////////////////////////////////////
+ // ////////////// API parameters /////////////////////
+ // ///////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.ACTION, type = CommandType.STRING, required = true, description = "the action to be executed if all the conditions evaluate to true for the specified duration.")
+ private String action;
+
+ @Parameter(name = ApiConstants.DURATION, type = CommandType.INTEGER, required = true, description = "the duration for which the conditions have to be true before action is taken")
+ private int duration;
+
+ @Parameter(name = ApiConstants.QUIETTIME, type = CommandType.INTEGER, description = "the cool down period for which the policy should not be evaluated after the action has been taken")
+ private Integer quietTime;
+
+ @Parameter(name = ApiConstants.CONDITION_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = ConditionResponse.class,
+ required = true, description = "the list of IDs of the conditions that are being evaluated on every interval")
+ private List<Long> conditionIds;
+
+ // ///////////////////////////////////////////////////
+ // ///////////////// Accessors ///////////////////////
+ // ///////////////////////////////////////////////////
+
+ private Long conditionDomainId;
+ private Long conditionAccountId;
+
+ @Override
+ public String getEntityTable() {
+ return "autoscale_policies";
+ }
+
+ public int getDuration() {
+ return duration;
+ }
+
+ public Integer getQuietTime() {
+ return quietTime;
+ }
+
+ public String getAction() {
+ return action;
+ }
+
+ public List<Long> getConditionIds() {
+ return conditionIds;
+ }
+
+ // ///////////////////////////////////////////////////
+ // ///////////// API Implementation///////////////////
+ // ///////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public static String getResultObjectName() {
+ return "autoscalepolicy";
+ }
+
+ public long getAccountId()
+ {
+ if (conditionAccountId == null)
+ getEntityOwnerId();
+ return conditionAccountId;
+ }
+
+ public long getDomainId()
+ {
+ if (conditionDomainId == null) {
+ getEntityOwnerId();
+ }
+
+ return conditionDomainId;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ if (conditionAccountId != null) {
+ return conditionAccountId;
+ }
+ long conditionId = getConditionIds().get(0);
+ Condition condition = _entityMgr.findById(Condition.class, conditionId);
+ if(condition == null) {
+ // it is an invalid condition, return system acccount, error will be thrown later.
+ conditionDomainId = Domain.ROOT_DOMAIN;
+ conditionAccountId = Account.ACCOUNT_ID_SYSTEM;
+ } else {
+ conditionDomainId = condition.getDomainId();
+ conditionAccountId = condition.getAccountId();
+ }
+
+ return conditionAccountId;
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_AUTOSCALEPOLICY_CREATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "creating AutoScale Policy";
+ }
+
+ @Override
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.AutoScalePolicy;
+ }
+
+ @Override
+ public void execute() {
+ AutoScalePolicy result = _entityMgr.findById(AutoScalePolicy.class, getEntityId());
+ AutoScalePolicyResponse response = _responseGenerator.createAutoScalePolicyResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+
+ @Override
+ public void create() throws ResourceAllocationException {
+ AutoScalePolicy result = _autoScaleService.createAutoScalePolicy(this);
+ if (result != null) {
+ this.setEntityId(result.getId());
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create AutoScale Policy");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java
new file mode 100644
index 0000000..6297888
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java
@@ -0,0 +1,192 @@
+// 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.user.autoscale;
+
+import java.util.List;
+
+import org.apache.cloudstack.api.*;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
+import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
+import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
+import org.apache.cloudstack.api.response.FirewallRuleResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.network.as.AutoScaleVmGroup;
+import com.cloud.network.rules.LoadBalancer;
+
+@APICommand(name = "createAutoScaleVmGroup", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = AutoScaleVmGroupResponse.class)
+public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateAutoScaleVmGroupCmd.class.getName());
+
+ private static final String s_name = "autoscalevmgroupresponse";
+
+ // ///////////////////////////////////////////////////
+ // ////////////// API parameters /////////////////////
+ // ///////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.LBID, type = CommandType.UUID, entityType = FirewallRuleResponse.class,
+ required = true, description = "the ID of the load balancer rule")
+ private long lbRuleId;
+
+ @Parameter(name = ApiConstants.MIN_MEMBERS, type = CommandType.INTEGER, required = true, description = "the minimum number of members in the vmgroup, the number of instances in the vm group will be equal to or more than this number.")
+ private int minMembers;
+
+ @Parameter(name = ApiConstants.MAX_MEMBERS, type = CommandType.INTEGER, required = true, description = "the maximum number of members in the vmgroup, The number of instances in the vm group will be equal to or less than this number.")
+ private int maxMembers;
+
+ @Parameter(name = ApiConstants.INTERVAL, type = CommandType.INTEGER, description = "the frequency at which the conditions have to be evaluated")
+ private Integer interval;
+
+ @Parameter(name = ApiConstants.SCALEUP_POLICY_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AutoScalePolicyResponse.class,
+ required = true, description = "list of scaleup autoscale policies")
+ private List<Long> scaleUpPolicyIds;
+
+ @Parameter(name = ApiConstants.SCALEDOWN_POLICY_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AutoScalePolicyResponse.class,
+ required = true, description = "list of scaledown autoscale policies")
+ private List<Long> scaleDownPolicyIds;
+
+ @Parameter(name = ApiConstants.VMPROFILE_ID, type = CommandType.UUID, entityType = AutoScaleVmProfileResponse.class,
+ required = true, description = "the autoscale profile that contains information about the vms in the vm group.")
+ private long profileId;
+
+ // ///////////////////////////////////////////////////
+ // ///////////////// Accessors ///////////////////////
+ // ///////////////////////////////////////////////////
+
+ @Override
+ public String getEntityTable() {
+ return "autoscale_vmgroups";
+ }
+
+ public int getMinMembers() {
+ return minMembers;
+ }
+
+ public int getMaxMembers() {
+ return maxMembers;
+ }
+
+ public Integer getInterval() {
+ return interval;
+ }
+
+ public long getProfileId() {
+ return profileId;
+ }
+
+ public List<Long> getScaleUpPolicyIds() {
+ return scaleUpPolicyIds;
+ }
+
+ public List<Long> getScaleDownPolicyIds() {
+ return scaleDownPolicyIds;
+ }
+
+ public long getLbRuleId() {
+ return lbRuleId;
+ }
+
+ // ///////////////////////////////////////////////////
+ // ///////////// API Implementation///////////////////
+ // ///////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public static String getResultObjectName() {
+ return "autoscalevmgroup";
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getLbRuleId());
+ if (lb == null) {
+ throw new InvalidParameterValueException("Unable to find loadbalancer by lbRuleId");
+ }
+ return lb.getAccountId();
+ }
+
+ public void setLbRuleId(Long lbRuleId) {
+ this.lbRuleId = lbRuleId;
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_AUTOSCALEVMGROUP_CREATE;
+ }
+
+ @Override
+ public String getCreateEventType() {
+ return EventTypes.EVENT_AUTOSCALEVMGROUP_CREATE;
+ }
+
+ @Override
+ public String getCreateEventDescription() {
+ return "creating AutoScale Vm Group";
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "configuring AutoScale Vm Group. Vm Group Id: " + getEntityId();
+ }
+
+ @Override
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.AutoScaleVmGroup;
+ }
+
+ @Override
+ public void create() throws ResourceAllocationException {
+ AutoScaleVmGroup result = _autoScaleService.createAutoScaleVmGroup(this);
+ if (result != null) {
+ this.setEntityId(result.getId());
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Autoscale Vm Group");
+ }
+ }
+
+ @Override
+ public void execute() {
+ boolean success = false;
+ AutoScaleVmGroup vmGroup = null;
+ try
+ {
+ success = _autoScaleService.configureAutoScaleVmGroup(this);
+ if (success) {
+ vmGroup = _entityMgr.findById(AutoScaleVmGroup.class, getEntityId());
+ AutoScaleVmGroupResponse responseObject = _responseGenerator.createAutoScaleVmGroupResponse(vmGroup);
+ setResponseObject(responseObject);
+ responseObject.setResponseName(getCommandName());
+ }
+ } catch (Exception ex) {
+ // TODO what will happen if Resource Layer fails in a step inbetween
+ s_logger.warn("Failed to create autoscale vm group", ex);
+ } finally {
+ if (!success || vmGroup == null) {
+ _autoScaleService.deleteAutoScaleVmGroup(getEntityId());
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Autoscale Vm Group");
+ }
+ }
+ }
+}