Bug 12777 - Add storage network configuration into CloudStack

new API: ListTafficTypeImplementors
This commit is contained in:
frank 2012-01-05 16:12:02 -08:00
parent 51dc4aff80
commit ec7c22f5c7
18 changed files with 253 additions and 24 deletions

View File

@ -320,6 +320,7 @@ public class ApiConstants {
public static final String RESTART_REQUIRED = "restartrequired";
public static final String ALLOW_USER_CREATE_PROJECTS = "allowusercreateprojects";
public static final String CONSERVE_MODE = "conservemode";
public static final String TRAFFIC_TYPE_IMPLEMENTOR = "traffictypeimplementor";
public enum HostDetails {
all, capacity, events, stats, min;

View File

@ -28,6 +28,7 @@ import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import com.cloud.api.response.TrafficTypeImplementorResponse;
import com.cloud.configuration.ConfigurationService;
import com.cloud.consoleproxy.ConsoleProxyService;
import com.cloud.dao.EntityManager;

View File

@ -0,0 +1,69 @@
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.TrafficTypeImplementorResponse;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Networks.TrafficType;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
@Implementation(description="Lists implementors of implementor of a network traffic type or implementors of all network traffic types", responseObject=TrafficTypeImplementorResponse.class)
public class ListTafficTypeImplementorsCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListTafficTypeImplementorsCmd.class);
private static final String _name = "listtraffictypeimplementorsresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="Optional. The network traffic type, if specified, return its implementor. Otherwise, return all traffic types with their implementor")
private String trafficType;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getTrafficType() {
return trafficType;
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
ResourceAllocationException {
List<Pair<TrafficType, String>> results = _networkService.listTrafficTypeImplementor(this);
ListResponse<TrafficTypeImplementorResponse> response = new ListResponse<TrafficTypeImplementorResponse>();
List<TrafficTypeImplementorResponse> responses= new ArrayList<TrafficTypeImplementorResponse>();
for (Pair<TrafficType, String> r : results) {
TrafficTypeImplementorResponse p = new TrafficTypeImplementorResponse();
p.setTrafficType(r.first().toString());
p.setImplementor(r.second());
responses.add(p);
}
response.setResponses(responses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public String getCommandName() {
return _name;
}
}

View File

@ -86,6 +86,4 @@ public class ListTrafficTypesCmd extends BaseListCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -6,17 +6,15 @@ import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseListCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.StorageNetworkIpRangeResponse;
import com.cloud.dc.StorageNetworkIpRange;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceAllocationException;
@ -24,7 +22,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
@Implementation(description="List a storage network IP range.", responseObject=StorageNetworkIpRangeResponse.class)
public class listStorageNetworkIpRangeCmd extends BaseAsyncCmd {
public class listStorageNetworkIpRangeCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(listStorageNetworkIpRangeCmd.class);
String s_name = "liststoragenetworkiprangeresponse";
@ -60,16 +58,6 @@ public class listStorageNetworkIpRangeCmd extends BaseAsyncCmd {
public Long getZoneId() {
return zoneId;
}
@Override
public String getEventType() {
return EventTypes.EVENT_STORAGE_IP_RANGE_LIST;
}
@Override
public String getEventDescription() {
return "List storage network IP range";
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,

View File

@ -0,0 +1,21 @@
package com.cloud.api.response;
import com.cloud.api.ApiConstants;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
public class TrafficTypeImplementorResponse extends BaseResponse {
@SerializedName(ApiConstants.TRAFFIC_TYPE) @Param(description="network traffic type")
private String trafficType;
@SerializedName(ApiConstants.TRAFFIC_TYPE_IMPLEMENTOR) @Param(description="implementor of network traffic type")
private String implementor;
public void setTrafficType(String type) {
this.trafficType = type;
}
public void setImplementor(String impl) {
this.implementor = impl;
}
}

View File

@ -172,7 +172,6 @@ public class EventTypes {
public static final String EVENT_STORAGE_IP_RANGE_CREATE = "STORAGE.IP.RANGE.CREATE";
public static final String EVENT_STORAGE_IP_RANGE_DELETE = "STORAGE.IP.RANGE.DELETE";
public static final String EVENT_STORAGE_IP_RANGE_LIST = "STORAGE.IP.RANGE.LIST";
// Configuration Table
public static final String EVENT_CONFIGURATION_VALUE_EDIT = "CONFIGURATION.VALUE.EDIT";

4
api/src/com/cloud/network/NetworkService.java Normal file → Executable file
View File

@ -24,6 +24,7 @@ import java.util.Set;
import com.cloud.api.commands.AssociateIPAddrCmd;
import com.cloud.api.commands.CreateNetworkCmd;
import com.cloud.api.commands.ListNetworksCmd;
import com.cloud.api.commands.ListTafficTypeImplementorsCmd;
import com.cloud.api.commands.RestartNetworkCmd;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
@ -36,6 +37,7 @@ import com.cloud.network.Network.Service;
import com.cloud.network.Networks.TrafficType;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.utils.Pair;
public interface NetworkService {
@ -129,4 +131,6 @@ public interface NetworkService {
PhysicalNetwork getDefaultPhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType);
Network getExclusiveGuestNetwork(long zoneId);
List<Pair<TrafficType, String>> listTrafficTypeImplementor(ListTafficTypeImplementorsCmd cmd);
}

View File

@ -99,6 +99,7 @@ public class Networks {
* Different types of network traffic in the data center.
*/
public enum TrafficType {
None,
Public,
Guest,
Storage,
@ -115,6 +116,23 @@ public class Networks {
return false;
}
public static TrafficType getTrafficType(String type) {
if (type.equals("Public")) {
return Public;
} else if (type.endsWith("Guest")) {
return Guest;
} else if (type.endsWith("Storage")) {
return Storage;
} else if (type.endsWith("Management")) {
return Management;
} else if (type.endsWith("Control")) {
return Control;
} else if (type.endsWith("Vpn")) {
return Vpn;
} else {
return None;
}
}
};
public enum IsolationType {

5
api/src/com/cloud/network/guru/NetworkGuru.java Normal file → Executable file
View File

@ -28,6 +28,7 @@ import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.Network;
import com.cloud.network.NetworkProfile;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.utils.component.Adapter;
@ -229,4 +230,8 @@ public interface NetworkGuru extends Adapter {
boolean trash(Network network, NetworkOffering offering, Account owner);
void updateNetworkProfile(NetworkProfile networkProfile);
TrafficType[] getSupportedTrafficType();
boolean isMyTrafficType(TrafficType type);
}

View File

@ -58,6 +58,7 @@ import com.cloud.alert.AlertManager;
import com.cloud.api.commands.AssociateIPAddrCmd;
import com.cloud.api.commands.CreateNetworkCmd;
import com.cloud.api.commands.ListNetworksCmd;
import com.cloud.api.commands.ListTafficTypeImplementorsCmd;
import com.cloud.api.commands.RestartNetworkCmd;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.configuration.Config;
@ -5646,4 +5647,24 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
return canIpUsedForConserveService(publicIp, service);
}
@Override
public List<Pair<TrafficType, String>> listTrafficTypeImplementor(ListTafficTypeImplementorsCmd cmd) {
String type = cmd.getTrafficType();
List<Pair<TrafficType, String>> results = new ArrayList<Pair<TrafficType, String>>();
if (type != null) {
for (NetworkGuru guru : _networkGurus) {
if (guru.isMyTrafficType(TrafficType.getTrafficType(type))) {
results.add(new Pair<TrafficType, String>(TrafficType.getTrafficType(type), guru.getName()));
break;
}
}
} else {
for (NetworkGuru guru : _networkGurus) {
results.add(new Pair<TrafficType, String>(TrafficType.getTrafficType(type), guru.getName()));
}
}
return results;
}
}

View File

@ -41,10 +41,12 @@ import com.cloud.network.NetworkProfile;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.AddressFormat;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.IsolationType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
@ -63,8 +65,25 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
String _cidr;
String _gateway;
private static final TrafficType[] _trafficTypes = {TrafficType.Control};
@Override
public boolean isMyTrafficType(TrafficType type) {
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
}
@Override
public TrafficType[] getSupportedTrafficType() {
return _trafficTypes;
}
protected boolean canHandle(NetworkOffering offering) {
if (offering.isSystemOnly() && offering.getTrafficType() == TrafficType.Control) {
if (offering.isSystemOnly() && isMyTrafficType(offering.getTrafficType())) {
return true;
} else {
s_logger.trace("We only care about System only Control network");

View File

@ -74,10 +74,27 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
IPAddressDao _ipAddressDao;
@Inject
NetworkOfferingDao _networkOfferingDao;
private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
@Override
public boolean isMyTrafficType(TrafficType type) {
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
}
@Override
public TrafficType[] getSupportedTrafficType() {
return _trafficTypes;
}
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
// this guru handles only Guest networks in Advance zone with source nat service disabled
if (dc.getNetworkType() == NetworkType.Advanced && !_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)&& offering.getTrafficType() == TrafficType.Guest) {
if (dc.getNetworkType() == NetworkType.Advanced && !_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)&& isMyTrafficType(offering.getTrafficType())) {
return true;
} else {
s_logger.trace("We only take care of Guest Direct networks");

View File

@ -79,7 +79,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
@Override
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
// this guru handles system Direct pod based network
if (dc.getNetworkType() == NetworkType.Basic && offering.getTrafficType() == TrafficType.Guest) {
if (dc.getNetworkType() == NetworkType.Basic && isMyTrafficType(offering.getTrafficType())) {
return true;
} else {
s_logger.trace("We only take care of Guest Direct Pod based networks");

View File

@ -78,16 +78,33 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
protected NetworkDao _networkDao;
Random _rand = new Random(System.currentTimeMillis());
private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
String _defaultGateway;
String _defaultCidr;
protected GuestNetworkGuru() {
super();
}
@Override
public boolean isMyTrafficType(TrafficType type) {
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
}
@Override
public TrafficType[] getSupportedTrafficType() {
return _trafficTypes;
}
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
// This guru handles only Guest Isolated network that supports Source nat service
if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Guest && offering.getGuestType() == Network.GuestType.Isolated && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)) {
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == Network.GuestType.Isolated && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)) {
return true;
} else {
s_logger.trace("We only take care of Guest networks with service " + Service.SourceNat + " enabled in zone of type " + NetworkType.Advanced);

View File

@ -61,12 +61,29 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
@Inject DataCenterDao _dcDao;
@Inject StorageNetworkManager _sNwMgr;
Random _rand = new Random(System.currentTimeMillis());
private static final TrafficType[] _trafficTypes = {TrafficType.Management, TrafficType.Storage};
@Override
public boolean isMyTrafficType(TrafficType type) {
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
}
@Override
public TrafficType[] getSupportedTrafficType() {
return _trafficTypes;
}
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
TrafficType type = offering.getTrafficType();
if (type != TrafficType.Management && type != TrafficType.Storage) {
if (!isMyTrafficType(type)) {
return null;
}

View File

@ -74,8 +74,25 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
@Inject
IPAddressDao _ipAddressDao;
private static final TrafficType[] _trafficTypes = {TrafficType.Public};
@Override
public boolean isMyTrafficType(TrafficType type) {
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
}
@Override
public TrafficType[] getSupportedTrafficType() {
return _trafficTypes;
}
protected boolean canHandle(NetworkOffering offering) {
return offering.getTrafficType() == TrafficType.Public && offering.isSystemOnly();
return isMyTrafficType(offering.getTrafficType()) && offering.isSystemOnly();
}
@Override

View File

@ -40,8 +40,25 @@ public class StorageNetworkGuru extends AdapterBase implements NetworkGuru {
super();
}
private static final TrafficType[] _trafficTypes = {TrafficType.Storage};
@Override
public boolean isMyTrafficType(TrafficType type) {
for (TrafficType t : _trafficTypes) {
if (t == type) {
return true;
}
}
return false;
}
@Override
public TrafficType[] getSupportedTrafficType() {
return _trafficTypes;
}
protected boolean canHandle(NetworkOffering offering) {
if (offering.getTrafficType() == TrafficType.Storage && offering.isSystemOnly()) {
if (isMyTrafficType(offering.getTrafficType()) && offering.isSystemOnly()) {
if (_sNwMgr.isStorageIpRangeAvailable()) {
return true;
} else {