CLOUDSTACK-4111: Prompt "Acquire New IP - Cross Zones - YES/NO" wizard

only when there is portable IP range added at region level.

region response will now have details if portable IP service is enabled
or not. Portable IP service for a region is turned off by default. when
adming adds a portable ip range portable ip service is enabled for the
region.
This commit is contained in:
Murali Reddy 2013-08-12 18:09:13 +05:30
parent 78abebae28
commit 5cff9bd2e6
6 changed files with 67 additions and 10 deletions

View File

@ -35,6 +35,12 @@ public class RegionResponse extends BaseResponse {
@SerializedName(ApiConstants.END_POINT) @Param(description="the end point of the region")
private String endPoint;
@SerializedName("gslbserviceenabled") @Param(description="true if GSLB service is enabled in the region, false otherwise")
private boolean gslbServiceEnabled;
@SerializedName("portableipserviceenabled") @Param(description="true if security groups support is enabled, false otherwise")
private boolean portableipServiceEnabled;
public Integer getId() {
return id;
}
@ -59,4 +65,11 @@ public class RegionResponse extends BaseResponse {
this.endPoint = endPoint;
}
}
public void setGslbServiceEnabled(boolean gslbServiceEnabled) {
this.gslbServiceEnabled = gslbServiceEnabled;
}
public void setPortableipServiceEnabled(boolean portableipServiceEnabled) {
this.portableipServiceEnabled = portableipServiceEnabled;
}
}

View File

@ -31,10 +31,11 @@ public interface Region {
public void setName(String name);
public String getEndPoint();
public boolean checkIfServiceEnabled(Service service);
public void enableService(Service service);
/**
* A region level service, is a service that constitute services across one or more zones in the region or a service
* made available to all the zones in the region.
@ -45,6 +46,7 @@ public interface Region {
private static List<Service> regionServices = new ArrayList<Service>();
public static final Service Gslb = new Service("Gslb");
public static final Service PortableIp = new Service("PortableIp");
public Service(String name ) {
this.name = name;

View File

@ -35,7 +35,12 @@ public class RegionVO implements Region{
@Column(name="end_point")
private String endPoint;
@Column(name="gslb_service_enabled")
private boolean gslbEnabled;
@Column(name="portableip_service_enabled")
private boolean portableipEnabled;
public boolean getGslbEnabled() {
return gslbEnabled;
@ -45,9 +50,6 @@ public class RegionVO implements Region{
this.gslbEnabled = gslbEnabled;
}
@Column(name="gslb_service_enabled")
private boolean gslbEnabled;
public RegionVO() {
}
@ -78,10 +80,35 @@ public class RegionVO implements Region{
this.endPoint = endPoint;
}
@Override
public boolean checkIfServiceEnabled(Service service) {
return gslbEnabled;
if (Service.Gslb.equals(service)) {
return gslbEnabled;
} else if (Service.PortableIp.equals(service)) {
return portableipEnabled;
} else {
assert false: "Unknown Region level Service";
return false;
}
}
@Override
public void enableService(org.apache.cloudstack.region.Region.Service service) {
if (Service.Gslb.equals(service)) {
this.gslbEnabled = true;
} else if (Service.PortableIp.equals(service)) {
this.portableipEnabled = true;
} else {
assert false: "Unknown Region level Service";
return;
}
}
public boolean getPortableipEnabled() {
return portableipEnabled;
}
public void setPortableipEnabled(boolean portableipEnabled) {
this.portableipEnabled = portableipEnabled;
}
}

View File

@ -2837,6 +2837,8 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setName(region.getName());
response.setEndPoint(region.getEndPoint());
response.setObjectName("region");
response.setGslbServiceEnabled(region.checkIfServiceEnabled(Region.Service.Gslb));
response.setPortableipServiceEnabled(region.checkIfServiceEnabled(Region.Service.PortableIp));
return response;
}

View File

@ -80,6 +80,7 @@ import org.apache.cloudstack.region.PortableIpRangeDao;
import org.apache.cloudstack.region.PortableIpRangeVO;
import org.apache.cloudstack.region.PortableIpVO;
import org.apache.cloudstack.region.Region;
import org.apache.cloudstack.region.RegionVO;
import org.apache.cloudstack.region.dao.RegionDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
@ -4974,7 +4975,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
String netmask = cmd.getNetmask();
String vlanId = cmd.getVlan();
Region region = _regionDao.findById(regionId);
RegionVO region = _regionDao.findById(regionId);
if (region == null) {
throw new InvalidParameterValueException("Invalid region ID: " + regionId);
}
@ -5033,6 +5034,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
startIpLong++;
}
// implicitly enable portable IP service for the region
region.setPortableipEnabled(true);
_regionDao.update(region.getId(), region);
txn.commit();
portableIpLock.unlock();
return portableIpRange;
@ -5044,6 +5049,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
eventDescription = "deleting portable ip range", async = false)
public boolean deletePortableIpRange(DeletePortableIpRangeCmd cmd) {
long rangeId = cmd.getId();
PortableIpRangeVO portableIpRange = _portableIpRangeDao.findById(rangeId);
if (portableIpRange == null) {
throw new InvalidParameterValueException("Please specify a valid portable IP range id.");
@ -5056,12 +5062,17 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (fullIpRange != null && freeIpRange != null) {
if (fullIpRange.size() == freeIpRange.size()) {
_portableIpRangeDao.expunge(portableIpRange.getId());
List<PortableIpRangeVO> pipranges = _portableIpRangeDao.listAll();
if (pipranges == null || pipranges.isEmpty()) {
RegionVO region = _regionDao.findById(portableIpRange.getRegionId());
region.setPortableipEnabled(false);
_regionDao.update(region.getId(), region);
}
return true;
} else {
throw new InvalidParameterValueException("Can't delete portable IP range as there are IP's assigned.");
}
}
return false;
}

View File

@ -516,6 +516,8 @@ CREATE VIEW `cloud`.`event_view` AS
left join
`cloud`.`event` eve ON event.start_id = eve.id;
ALTER TABLE `cloud`.`region` ADD COLUMN `portableip_service_enabled` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Is Portable IP service enalbed in the Region';
ALTER TABLE `cloud`.`region` ADD COLUMN `gslb_service_enabled` tinyint(1) unsigned NOT NULL DEFAULT 1 COMMENT 'Is GSLB service enalbed in the Region';
ALTER TABLE `cloud`.`external_load_balancer_devices` ADD COLUMN `is_gslb_provider` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if load balancer appliance is acting as gslb service provider in the zone';