bug 12229: added restartRequired field to the network object

The value is set to true when shutdownResources or implementResources fail.
This commit is contained in:
Alena Prokharchyk 2011-12-09 15:36:04 -08:00
parent 56b5c5cf2a
commit 7ff1417cbb
10 changed files with 69 additions and 8 deletions

View File

@ -320,6 +320,7 @@ public class ApiConstants {
public static final String SOURCE_NAT_SUPPORTED = "sourcenatsupported";
public static final String RESOURCE_STATE = "resourcestate";
public static final String PROJECT_INVITE_REQUIRED = "projectinviterequired";
public static final String RESTART_REQUIRED = "restartrequired";
public enum HostDetails {
all, capacity, events, stats, min;

View File

@ -78,6 +78,9 @@ public class ListNetworksCmd extends BaseListCmd {
@Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, description="list network offerings supporting certain services")
private List<String> supportedServices;
@Parameter(name=ApiConstants.RESTART_REQUIRED, type=CommandType.BOOLEAN, description="list network offerings by restartRequired option")
private Boolean restartRequired;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -127,7 +130,11 @@ public class ListNetworksCmd extends BaseListCmd {
return supportedServices;
}
/////////////////////////////////////////////////////
public Boolean getRestartRequired() {
return restartRequired;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override

View File

@ -127,6 +127,9 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network id")
private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network");
@SerializedName(ApiConstants.RESTART_REQUIRED) @Param(description="true network requires restart")
private Boolean restartRequired;
public void setId(Long id) {
this.id.setValue(id);
}
@ -260,4 +263,8 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
public void setCidr(String cidr) {
this.cidr = cidr;
}
public void setRestartRequired(Boolean restartRequired) {
this.restartRequired = restartRequired;
}
}

View File

@ -288,4 +288,6 @@ public interface Network extends ControlledEntity {
ACLType getAclType();
boolean isSpecifiedCidr();
boolean isRestartRequired();
}

View File

@ -49,6 +49,7 @@ public class NetworkProfile implements Network {
private Long physicalNetworkId;
private ACLType aclType;
private boolean specifiedCidr;
private boolean restartRequired;
public NetworkProfile(Network network) {
this.id = network.getId();
@ -72,6 +73,7 @@ public class NetworkProfile implements Network {
this.physicalNetworkId = network.getPhysicalNetworkId();
this.aclType = network.getAclType();
this.specifiedCidr = network.isSpecifiedCidr();
this.restartRequired = network.isRestartRequired();
}
public String getDns1() {
@ -208,4 +210,10 @@ public class NetworkProfile implements Network {
this.specifiedCidr = specifiedCidr;
}
@Override
public boolean isRestartRequired() {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -2684,6 +2684,7 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setAclType(network.getAclType().toString());
}
response.setState(network.getState().toString());
response.setRestartRequired(network.isRestartRequired());
response.setRelated(network.getRelated());
response.setNetworkDomain(network.getNetworkDomain());

View File

@ -1359,6 +1359,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
implementNetworkElementsAndResources(dest, context, network, offering);
network.setState(Network.State.Implemented);
network.setRestartRequired(false);
_networksDao.update(network.getId(), network);
implemented.set(guru, network);
return implemented;
@ -2109,6 +2110,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
String path = null;
Long physicalNetworkId = cmd.getPhysicalNetworkId();
List<String> supportedServicesStr = cmd.getSupportedServices();
Boolean restartRequired= cmd.getRestartRequired();
//1) default is system to false if not specified
//2) reset parameter to false if it's specified by the regular user
@ -2198,17 +2200,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (isSystem == null || !isSystem) {
//Get domain level networks
if (domainId != null) {
networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks), searchFilter, domainId));
networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired), searchFilter, domainId));
} else if (permittedAccounts.isEmpty()){
networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks), searchFilter, path));
networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired), searchFilter, path));
}
//get account specific networks
if (!permittedAccounts.isEmpty()){
networksToReturn.addAll(listAccountSpecificNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks), searchFilter, permittedAccounts));
networksToReturn.addAll(listAccountSpecificNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired), searchFilter, permittedAccounts));
}
} else {
networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks), searchFilter);
networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired), searchFilter);
}
if (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !networksToReturn.isEmpty()) {
@ -2237,7 +2239,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId, String aclType, boolean skipProjectNetworks) {
private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId, String aclType, boolean skipProjectNetworks, Boolean restartRequired) {
SearchCriteria<NetworkVO> sc = sb.create();
if (isSystem != null) {
@ -2277,6 +2279,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (skipProjectNetworks) {
sc.setJoinParameters("accountSearch", "type", Account.ACCOUNT_TYPE_PROJECT);
}
if (restartRequired != null) {
sc.addAnd("restartRequired", SearchCriteria.Op.EQ, restartRequired);
}
return sc;
}
@ -2391,6 +2397,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
applyProfileToNetwork(network, profile);
network.setState(Network.State.Allocated);
network.setRestartRequired(false);
_networksDao.update(network.getId(), network);
_networksDao.clearCheckForGc(networkId);
@ -2685,6 +2692,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (!(network.getState() == Network.State.Implemented || network.getState() == Network.State.Setup)) {
throw new InvalidParameterValueException("Network is not in the right state to be restarted. Correct states are: " + Network.State.Implemented + ", " + Network.State.Setup);
}
//don't allow clenaup=true for the network in Basic zone
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic && cleanup) {
throw new InvalidParameterValueException("Cleanup can't be true when restart network in Basic zone");
}
_accountMgr.checkAccess(callerAccount, null, network);
@ -2731,6 +2744,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (!shutdownNetworkElementsAndResources(context, cleanup, network)) {
s_logger.debug("Failed to shutdown the network elements and resources as a part of network restart: " + network.getState());
setRestartRequired(network, true);
return false;
}
@ -2742,14 +2756,21 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
try {
implementNetworkElementsAndResources(dest, context, network, offering);
setRestartRequired(network, true);
} catch (Exception ex) {
s_logger.warn("Failed to implement network " + network + " elements and resources as a part of network restart due to ", ex);
return false;
}
setRestartRequired(network, false);
return true;
}
private void setRestartRequired(NetworkVO network, boolean restartRequired) {
s_logger.debug("Marking network " + network + " with restartRequired=" + restartRequired);
network.setRestartRequired(restartRequired);
_networksDao.update(network.getId(), network);
}
//This method re-programs the rules/ips for existing network
protected boolean reprogramNetworkRules(long networkId, Account caller, NetworkVO network) throws ResourceUnavailableException {

View File

@ -145,6 +145,9 @@ public class NetworkVO implements Network, Identity {
@Column(name="specified_cidr")
boolean specifiedCidr;
@Column(name="restart_required")
boolean restartRequired = false;
public NetworkVO() {
this.uuid = UUID.randomUUID().toString();
}
@ -474,4 +477,12 @@ public class NetworkVO implements Network, Identity {
this.specifiedCidr = specifiedCidr;
}
public void setRestartRequired(boolean restartRequired) {
this.restartRequired = restartRequired;
}
@Override
public boolean isRestartRequired() {
return restartRequired;
}
}

View File

@ -191,7 +191,8 @@ CREATE TABLE `cloud`.`networks` (
`network_domain` varchar(255) COMMENT 'domain',
`reservation_id` char(40) COMMENT 'reservation id',
`guest_type` char(32) COMMENT 'type of guest network that can be shared or isolated',
`specified_cidr` int(1) unsigned NOT NULL COMMENT '1 if the CIDR/gateway/vlan are specified in this network',
`specified_cidr` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if the CIDR/gateway/vlan are specified in this network',
`restart_required` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if restart is required for the network',
`created` datetime NOT NULL COMMENT 'date created',
`removed` datetime COMMENT 'date removed if not null',
PRIMARY KEY (`id`),

View File

@ -476,3 +476,5 @@ ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD COLUMN `physical_network_id` bigint u
ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD CONSTRAINT `fk_op_dc_vnet_alloc__physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE;
ALTER TABLE `cloud`.`user_ip_address` ADD COLUMN `physical_network_id` bigint unsigned NOT NULL COMMENT 'physical network id that this configuration is based on';
ALTER TABLE `cloud`.`user_ip_address` ADD CONSTRAINT `fk_user_ip_address__physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE;
ALTER TABLE `cloud`.`networks` ADD COLUMN `restart_required` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if restart is required for the network';