VPC: when add guest network to VPC, verify that the list of network services is within the list of services supported by VPC offering

This commit is contained in:
Alena Prokharchyk 2012-06-28 17:13:07 -07:00
parent 24772bcb4e
commit 377b03acde
5 changed files with 31 additions and 3 deletions

View File

@ -45,7 +45,7 @@ public class ListNetworkACLsCmd extends BaseListProjectAndAccountResourcesCmd {
private Long id;
@IdentityMapper(entityTableName="networks")
@Parameter(name=ApiConstants.NETWORK, type=CommandType.LONG, description="list network ACLs by network Id")
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="list network ACLs by network Id")
private Long networkId;
@Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="list network ACLs by traffic type - Ingress or Egress")

View File

@ -35,7 +35,7 @@ public class VpcResponse extends BaseResponse implements ControlledEntityRespons
@SerializedName(ApiConstants.DISPLAY_TEXT) @Param(description="an alternate display text of the VPC.")
private String displayText;
@SerializedName(ApiConstants.STATE) @Param(description="state of the VPC. Can be Disabled/Enabled")
@SerializedName(ApiConstants.STATE) @Param(description="state of the VPC. Can be Inactive/Enabled")
private String state;
@SerializedName(ApiConstants.ZONE_ID) @Param(description="zone id of the vpc")

View File

@ -31,4 +31,7 @@ public interface VpcOfferingServiceMapDao extends GenericDao<VpcOfferingServiceM
* @return
*/
boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service[] services);
List<String> listServicesForVpcOffering(long vpcOfferingId);
}

View File

@ -18,11 +18,12 @@ import javax.ejb.Local;
import com.cloud.network.Network.Service;
import com.cloud.network.vpc.VpcOfferingServiceMapVO;
import com.cloud.offerings.NetworkOfferingServiceMapVO;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
/**
* @author Alena Prokharchyk
@ -32,6 +33,7 @@ import com.cloud.utils.db.SearchCriteria;
public class VpcOfferingServiceMapDaoImpl extends GenericDaoBase<VpcOfferingServiceMapVO, Long> implements VpcOfferingServiceMapDao{
final SearchBuilder<VpcOfferingServiceMapVO> AllFieldsSearch;
final SearchBuilder<VpcOfferingServiceMapVO> MultipleServicesSearch;
final GenericSearchBuilder<VpcOfferingServiceMapVO, String> ServicesSearch;
protected VpcOfferingServiceMapDaoImpl() {
@ -48,6 +50,11 @@ public class VpcOfferingServiceMapDaoImpl extends GenericDaoBase<VpcOfferingServ
MultipleServicesSearch.and("service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN);
MultipleServicesSearch.and("provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ);
MultipleServicesSearch.done();
ServicesSearch = createSearchBuilder(String.class);
ServicesSearch.and("offeringId", ServicesSearch.entity().getVpcOfferingId(), SearchCriteria.Op.EQ);
ServicesSearch.select(null, Func.DISTINCT, ServicesSearch.entity().getService());
ServicesSearch.done();
}
@Override
@ -87,4 +94,11 @@ public class VpcOfferingServiceMapDaoImpl extends GenericDaoBase<VpcOfferingServ
return false;
}
@Override
public List<String> listServicesForVpcOffering(long offId) {
SearchCriteria<String> sc = ServicesSearch.create();;
sc.setParameters("offeringId", offId);
return customSearch(sc, null);
}
}

View File

@ -65,6 +65,7 @@ import com.cloud.network.vpc.Dao.VpcGatewayDao;
import com.cloud.network.vpc.Dao.VpcOfferingDao;
import com.cloud.network.vpc.Dao.VpcOfferingServiceMapDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.org.Grouping;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.user.Account;
@ -126,6 +127,8 @@ public class VpcManagerImpl implements VpcManager, Manager{
PrivateIpDao _privateIpDao;
@Inject
StaticRouteDao _staticRouteDao;
@Inject
NetworkOfferingServiceMapDao _ntwkOffServiceDao ;
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("VpcChecker"));
@ -875,6 +878,14 @@ public class VpcManagerImpl implements VpcManager, Manager{
throw new InvalidParameterValueException("Only networks with conserve mode Off can belong to VPC");
}
//9) list supported services should be within VPC supported services
List<String> ntwkOffServices = _ntwkOffServiceDao.listServicesForNetworkOffering(guestNtwkOff.getId());
List<String> vpcOffServices = _vpcOffSvcMapDao.listServicesForVpcOffering(vpc.getVpcOfferingId());
if (!vpcOffServices.containsAll(ntwkOffServices)) {
throw new InvalidParameterValueException("VPC doesn't support some of the services specified in the network offering");
}
} finally {
s_logger.debug("Releasing lock for " + locked);
_vpcDao.releaseFromLockTable(locked.getId());