diff --git a/build/.project b/build/.project
new file mode 100644
index 00000000000..3daec4ee567
--- /dev/null
+++ b/build/.project
@@ -0,0 +1,11 @@
+
+
+ build
+
+
+
+
+
+
+
+
diff --git a/server/src/com/cloud/api/commands/.gitignore b/server/src/com/cloud/api/commands/.gitignore
new file mode 100644
index 00000000000..4ef5c9c90a8
--- /dev/null
+++ b/server/src/com/cloud/api/commands/.gitignore
@@ -0,0 +1,3 @@
+/AddConfigCmd.java
+/UpdateZoneCmd.java
+/UpdateZoneCmd.java
diff --git a/server/src/com/cloud/api/commands/UpdateZoneCmd.java b/server/src/com/cloud/api/commands/UpdateZoneCmd.java
index 3861daf069e..fd3acb1e67a 100644
--- a/server/src/com/cloud/api/commands/UpdateZoneCmd.java
+++ b/server/src/com/cloud/api/commands/UpdateZoneCmd.java
@@ -18,37 +18,22 @@
package com.cloud.api.commands;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
+import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.Manager;
import com.cloud.dc.DataCenterVO;
-import com.cloud.user.User;
-import com.cloud.utils.Pair;
+import com.cloud.serializer.Param;
+import com.cloud.serializer.SerializerHelper;
+@Implementation(method="updateZone", manager=Manager.ConfigManager)
public class UpdateZoneCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(UpdateZoneCmd.class.getName());
private static final String s_name = "updatezoneresponse";
- private static final List> s_properties = new ArrayList>();
-
- static {
- s_properties.add(new Pair(BaseCmd.Properties.DNS1, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.DNS2, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.GUEST_CIDR_ADDRESS, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.TRUE));
- s_properties.add(new Pair(BaseCmd.Properties.INTERNAL_DNS1, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.INTERNAL_DNS2, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.NAME, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.VNET, Boolean.FALSE));
-
- s_properties.add(new Pair(BaseCmd.Properties.USER_ID, Boolean.FALSE));
- }
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
@@ -117,60 +102,155 @@ public class UpdateZoneCmd extends BaseCmd {
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
+
+
+ private DataCenterVO responseObject = null;
+
@Override
public String getName() {
return s_name;
}
+
@Override
- public List> getProperties() {
- return s_properties;
+ public String getResponse()
+ {
+ UpdateZoneResponse response = new UpdateZoneResponse();
+ if (responseObject != null) {
+ response.setStatus("true");
+ response.setDisplayText("Successfully updated zone");
+ response.setId(responseObject.getId());
+ response.setGuestCidrAddress(responseObject.getGuestNetworkCidr());
+ response.setDns1(responseObject.getDns1());
+ response.setDns2(responseObject.getDns2());
+ response.setInternalDns1(responseObject.getInternalDns1());
+ response.setInternalDns2(responseObject.getInternalDns2());
+ response.setZoneName(responseObject.getName());
+ response.setVnet(responseObject.getVnet());
+ }
+ else
+ {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update zone; internal error.");
+ }
+
+ return SerializerHelper.toSerializedString(responseObject);
}
+
+ public void setResponseObject(DataCenterVO zone) {
+ responseObject = zone;
+ }
+ // helper class for the response object
+ private class UpdateZoneResponse
+ {
+ @Param(name="status")
+ private String status;
- @Override
- public List> execute(Map params) {
- Long zoneId = (Long) params.get(BaseCmd.Properties.ID.getName());
- String zoneName = (String) params.get(BaseCmd.Properties.NAME.getName());
- String dns1 = (String) params.get(BaseCmd.Properties.DNS1.getName());
- String dns2 = (String) params.get(BaseCmd.Properties.DNS2.getName());
- String dns3 = (String) params.get(BaseCmd.Properties.INTERNAL_DNS1.getName());
- String dns4 = (String) params.get(BaseCmd.Properties.INTERNAL_DNS2.getName());
- String vnet = (String) params.get(BaseCmd.Properties.VNET.getName());
- String guestCidr = (String) params.get(BaseCmd.Properties.GUEST_CIDR_ADDRESS.getName());
- Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
-
- if (userId == null) {
- userId = Long.valueOf(User.UID_SYSTEM);
- }
-
- //verify input parameters
- DataCenterVO zone = getManagementServer().findDataCenterById(zoneId);
- if (zone == null) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find zone by id " + zoneId);
- }
-
- if (zoneName == null) {
- zoneName = zone.getName();
- }
+ @Param(name="displaytext")
+ private String displayText;
- DataCenterVO updatedZone = null;
-
- try {
- updatedZone = getManagementServer().editZone(userId, zoneId, zoneName, dns1, dns2, dns3, dns4, vnet,guestCidr);
- } catch (Exception ex) {
- s_logger.error("Exception updating zone", ex);
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
- }
-
- List> returnValues = new ArrayList>();
+ @Param(name="dns1")
+ private String dns1;
- if (updatedZone == null) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update zone; internal error.");
- } else {
- returnValues.add(new Pair(BaseCmd.Properties.SUCCESS.getName(), "true"));
- returnValues.add(new Pair(BaseCmd.Properties.DISPLAY_TEXT.getName(), "Successfully updated zone."));
+ @Param(name="dns2")
+ private String dns2;
+
+ @Param(name="guestcidraddress")
+ private String guestCidrAddress;
+
+ @Param(name="id")
+ private Long id;
+
+ @Param(name="internaldns1")
+ private String internalDns1;
+
+ @Param(name="internaldns2")
+ private String internalDns2;
+
+ @Param(name="zonename")
+ private String zoneName;
+
+ @Param(name="vnet")
+ private String vnet;
+
+ public String getGuestCidrAddress() {
+ return guestCidrAddress;
+ }
+
+ public void setGuestCidrAddress(String guestCidrAddress) {
+ this.guestCidrAddress = guestCidrAddress;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getInternalDns1() {
+ return internalDns1;
+ }
+
+ public void setInternalDns1(String internalDns1) {
+ this.internalDns1 = internalDns1;
+ }
+
+ public String getInternalDns2() {
+ return internalDns2;
+ }
+
+ public void setInternalDns2(String internalDns2) {
+ this.internalDns2 = internalDns2;
+ }
+
+ public String getZoneName() {
+ return zoneName;
+ }
+
+ public void setZoneName(String zoneName) {
+ this.zoneName = zoneName;
+ }
+
+ public String getVnet() {
+ return vnet;
+ }
+
+ public void setVnet(String vnet) {
+ this.vnet = vnet;
+ }
+
+ public String getDns1() {
+ return dns1;
+ }
+
+ public void setDns1(String dns1) {
+ this.dns1 = dns1;
+ }
+
+ public String getDns2() {
+ return dns2;
+ }
+
+ public void setDns2(String dns2) {
+ this.dns2 = dns2;
+ }
+
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ public void setDisplayText(String displayText) {
+ this.displayText = displayText;
}
- return returnValues;
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
}
}
diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java
index ad923e7c15d..3f3c76f9722 100644
--- a/server/src/com/cloud/configuration/ConfigurationManager.java
+++ b/server/src/com/cloud/configuration/ConfigurationManager.java
@@ -20,6 +20,7 @@ package com.cloud.configuration;
import java.util.List;
import com.cloud.api.commands.CreateDiskOfferingCmd;
+import com.cloud.api.commands.UpdateZoneCmd;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.Vlan.VlanType;
@@ -150,18 +151,10 @@ public interface ConfigurationManager extends Manager {
/**
* Edits a zone in the database. Will not allow you to edit DNS values if there are VMs in the specified zone.
- * @param userId
- * @param zoneId
- * @param newZoneName
- * @param dns1
- * @param dns2
- * @param dns3
- * @param dns4
- * @param vnetRange
- * @return Zone
- * @return guestCidr
+ * @param UpdateZoneCmd
+ * @return Updated zone
*/
- DataCenterVO editZone(long userId, long zoneId, String newZoneName, String dns1, String dns2, String dns3, String dns4, String vnetRange, String guestCidr) throws InvalidParameterValueException, InternalErrorException;
+ DataCenterVO editZone(UpdateZoneCmd cmd) throws InvalidParameterValueException, InternalErrorException;
/**
* Deletes a zone from the database. Will not allow you to delete zones that are being used anywhere in the system.
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 96422fc9854..7aa975befeb 100644
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -31,7 +31,10 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
+import com.cloud.api.BaseCmd;
+import com.cloud.api.ServerApiException;
import com.cloud.api.commands.CreateDiskOfferingCmd;
+import com.cloud.api.commands.UpdateZoneCmd;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.AccountVlanMapVO;
import com.cloud.dc.DataCenterVO;
@@ -59,6 +62,8 @@ import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.UserContext;
import com.cloud.user.UserVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
@@ -667,7 +672,32 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
}
@Override
- public DataCenterVO editZone(long userId, long zoneId, String newZoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr) throws InvalidParameterValueException, InternalErrorException {
+ public DataCenterVO editZone(UpdateZoneCmd cmd) throws InvalidParameterValueException, InternalErrorException
+ {
+ //Parameter validation as from execute() method in V1
+ Long zoneId = cmd.getId();
+ String zoneName = cmd.getZoneName();
+ String dns1 = cmd.getDns1();
+ String dns2 = cmd.getDns2();
+ String internalDns1 = cmd.getInternalDns1();
+ String internalDns2 = cmd.getInternalDns2();
+ String vnetRange = cmd.getVnet();
+ String guestCidr = cmd.getGuestCidrAddress();
+ Long userId = UserContext.current().getUserId();
+
+ if (userId == null) {
+ userId = Long.valueOf(User.UID_SYSTEM);
+ }
+
+ DataCenterVO zone = _zoneDao.findById(zoneId);
+ if (zone == null) {
+ throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find zone by id " + zoneId);
+ }
+
+ if (zoneName == null) {
+ zoneName = zone.getName();
+ }
+
// Make sure the zone exists
if (!validZone(zoneId)) {
throw new InvalidParameterValueException("A zone with ID: " + zoneId + " does not exist.");
@@ -702,13 +732,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
}
}
- //5. Reached here, hence editable
-
- DataCenterVO zone = _zoneDao.findById(zoneId);
+ //5. Reached here, hence editable
+ DataCenterVO zoneHandle = _zoneDao.findById(zoneId);
String oldZoneName = zone.getName();
- if (newZoneName == null) {
- newZoneName = oldZoneName;
+ if (zoneName == null) {
+ zoneName = oldZoneName;
}
if (dns1 == null) {
@@ -723,10 +752,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
if(guestCidr == null)
guestCidr = zone.getGuestNetworkCidr();
- boolean checkForDuplicates = !newZoneName.equals(oldZoneName);
- checkZoneParameters(newZoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates);
+ boolean checkForDuplicates = !zoneName.equals(oldZoneName);
+ checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates);
- zone.setName(newZoneName);
+ zone.setName(zoneName);
zone.setDns1(dns1);
zone.setDns2(dns2);
zone.setInternalDns1(internalDns1);