Merge branch 'master' of ssh://git.cloud.com/var/lib/git/cloudstack-oss

This commit is contained in:
Chiradeep Vittal 2010-08-24 11:24:05 -07:00
commit 6d6b74fdfa
55 changed files with 868 additions and 213 deletions

View File

@ -3,6 +3,8 @@
*/ */
package com.cloud.acl; package com.cloud.acl;
import java.security.acl.NotOwnerException;
import com.cloud.domain.PartOf; import com.cloud.domain.PartOf;
import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.PermissionDeniedException;
import com.cloud.user.Account; import com.cloud.user.Account;
@ -23,7 +25,7 @@ public interface SecurityChecker extends Adapter {
* @return true if access allowed. false if this adapter cannot authenticate ownership. * @return true if access allowed. false if this adapter cannot authenticate ownership.
* @throws PermissionDeniedException if this adapter is suppose to authenticate ownership and the check failed. * @throws PermissionDeniedException if this adapter is suppose to authenticate ownership and the check failed.
*/ */
boolean checkOwnership(Account account, OwnedBy object) throws PermissionDeniedException; boolean checkOwnership(Account account, OwnedBy object) throws NotOwnerException;
/** /**
* Checks if the user belongs to an account that owns the object. * Checks if the user belongs to an account that owns the object.
@ -33,7 +35,7 @@ public interface SecurityChecker extends Adapter {
* @return true if access allowed. false if this adapter cannot authenticate ownership. * @return true if access allowed. false if this adapter cannot authenticate ownership.
* @throws PermissionDeniedException if this adapter is suppose to authenticate ownership and the check failed. * @throws PermissionDeniedException if this adapter is suppose to authenticate ownership and the check failed.
*/ */
boolean checkOwnership(User user, OwnedBy object) throws PermissionDeniedException; boolean checkOwnership(User user, OwnedBy object) throws NotOwnerException;
/** /**
* Checks if the account can access the object. * Checks if the account can access the object.

View File

@ -0,0 +1,16 @@
/**
*
*/
package com.cloud.exception;
import com.cloud.utils.SerialVersionUID;
public class ConflictingNetworkSettingsException extends Exception {
private static final long serialVersionUID = SerialVersionUID.ConflictingNetworkSettingException;
public ConflictingNetworkSettingsException() {
super();
}
}

View File

@ -0,0 +1,26 @@
/**
*
*/
package com.cloud.network;
import com.cloud.network.Network.BroadcastDomainType;
import com.cloud.network.Network.Mode;
import com.cloud.network.Network.TrafficType;
import com.cloud.user.OwnedBy;
public interface NetworkProfile extends OwnedBy {
long getId();
Mode getMode();
BroadcastDomainType getBroadcastDomainType();
TrafficType getTrafficType();
String getGateway();
String getCidr();
void setCidr(String cidr);
}

View File

@ -0,0 +1,25 @@
/**
*
*/
package com.cloud.network;
import java.util.Collection;
import java.util.List;
import com.cloud.exception.ConflictingNetworkSettingsException;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.user.Account;
import com.cloud.utils.component.Adapter;
import com.cloud.vm.VirtualMachine;
/**
* NetworkProfiler takes the list of network offerings requested and figures
* out what are the additional network profiles that are needed to add
* to the account in order to support this network.
*
*/
public interface NetworkProfiler extends Adapter {
List<? extends NetworkProfile> convert(Collection<? extends NetworkOffering> networkOfferings, Account owner);
boolean check(VirtualMachine vm, ServiceOffering serviceOffering, Collection<? extends NetworkProfile> networkProfiles) throws ConflictingNetworkSettingsException;
}

View File

@ -17,16 +17,18 @@
*/ */
package com.cloud.offering; package com.cloud.offering;
import com.cloud.network.Network.TrafficType;
/** /**
* Describes network offering * Describes network offering
* *
*/ */
public interface NetworkOffering { public interface NetworkOffering {
public enum GuestIpType { public enum GuestIpType {
Virtualized, Virtualized,
DirectSingle, DirectSingle,
DirectDual DirectDual
} }
long getId(); long getId();
@ -60,4 +62,6 @@ public interface NetworkOffering {
* @return concurrent connections to be supported. * @return concurrent connections to be supported.
*/ */
Integer getConcurrentConnections(); Integer getConcurrentConnections();
TrafficType getTrafficType();
} }

View File

@ -22,13 +22,7 @@ package com.cloud.offering;
* offered. * offered.
*/ */
public interface ServiceOffering { public interface ServiceOffering {
public enum GuestIpType { /**
Virtualized,
DirectSingle,
DirectDual
}
/**
* @return user readable description * @return user readable description
*/ */
String getName(); String getName();
@ -66,7 +60,7 @@ public interface ServiceOffering {
/** /**
* @return the type of IP address to allocate as the primary ip address to a guest * @return the type of IP address to allocate as the primary ip address to a guest
*/ */
GuestIpType getGuestIpType(); NetworkOffering.GuestIpType getGuestIpType();
/** /**
* @return whether or not the service offering requires local storage * @return whether or not the service offering requires local storage

View File

@ -37,6 +37,9 @@ public interface Volume extends PartOf, OwnedBy, BasedOn {
Destroyed Destroyed
} }
enum SourceType {
Snapshot,DiskOffering,Template,Blank
}
/** /**
* @return the volume name * @return the volume name
*/ */
@ -75,4 +78,12 @@ public interface Volume extends PartOf, OwnedBy, BasedOn {
Long getPoolId(); Long getPoolId();
State getState(); State getState();
SourceType getSourceType();
void setSourceType(SourceType sourceType);
void setSourceId(Long sourceId);
Long getSourceId();
} }

View File

@ -1,18 +0,0 @@
/**
*
*/
package com.cloud.vm;
import java.util.Collection;
import java.util.List;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.user.Account;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.Adapter;
public interface NetworkProfiler extends Adapter {
Ternary<VmCharacteristics, List<NetworkCharacteristics>, List<DiskCharacteristics>> convert(VirtualMachine vm, ServiceOffering serviceOffering, List<NetworkOffering> networkOfferings, Collection<DiskOffering> diskOfferings, Account owner);
}

View File

@ -149,6 +149,7 @@
<adapters key="com.cloud.resource.Discoverer"> <adapters key="com.cloud.resource.Discoverer">
<adapter name="SecondaryStorage" class="com.cloud.storage.secondary.SecondaryStorageDiscoverer"/> <adapter name="SecondaryStorage" class="com.cloud.storage.secondary.SecondaryStorageDiscoverer"/>
<adapter name="XCP Agent" class="com.cloud.hypervisor.xen.discoverer.XcpServerDiscoverer"/>
<adapter name="KVM Agent" class="com.cloud.hypervisor.kvm.discoverer.KvmServerDiscoverer"/> <adapter name="KVM Agent" class="com.cloud.hypervisor.kvm.discoverer.KvmServerDiscoverer"/>
</adapters> </adapters>

View File

@ -3491,9 +3491,25 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
protected String callHostPlugin(String plugin, String cmd, String... params) { protected String callHostPlugin(String plugin, String cmd, String... params) {
Map<String, String> args = new HashMap<String, String>(); Map<String, String> args = new HashMap<String, String>();
Session slaveSession = null;
Connection slaveConn = null;
try { try {
Connection conn = getConnection(); URL slaveUrl = null;
Host host = Host.getByUuid(conn, _host.uuid); try {
slaveUrl = new URL("http://" + _host.ip);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
slaveConn = new Connection(slaveUrl, 10);
slaveSession = Session.slaveLocalLoginWithPassword(slaveConn, _username, _password);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Slave logon successful. session= " + slaveSession);
}
Host host = Host.getByUuid(slaveConn, _host.uuid);
for (int i = 0; i < params.length; i += 2) { for (int i = 0; i < params.length; i += 2) {
args.put(params[i], params[i + 1]); args.put(params[i], params[i + 1]);
} }
@ -3502,7 +3518,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args));
} }
String result = host.callPlugin(conn, plugin, cmd, args); String result = host.callPlugin(slaveConn, plugin, cmd, args);
if (s_logger.isTraceEnabled()) { if (s_logger.isTraceEnabled()) {
s_logger.trace("callHostPlugin Result: " + result); s_logger.trace("callHostPlugin Result: " + result);
} }
@ -3511,6 +3527,13 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString()); s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString());
} catch (XmlRpcException e) { } catch (XmlRpcException e) {
s_logger.debug("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage()); s_logger.debug("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage());
} finally {
if( slaveSession != null) {
try {
slaveSession.localLogout(slaveConn);
} catch (Exception e) {
}
}
} }
return null; return null;
} }
@ -3980,6 +4003,10 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
} }
} }
protected boolean can_bridge_firewall() {
return false;
}
protected boolean getHostInfo() throws IllegalArgumentException{ protected boolean getHostInfo() throws IllegalArgumentException{
Connection conn = getConnection(); Connection conn = getConnection();
@ -3998,7 +4025,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
return false; return false;
} }
_canBridgeFirewall = Boolean.valueOf(callHostPlugin("vmops", "can_bridge_firewall", "host_uuid", _host.uuid)); _canBridgeFirewall = can_bridge_firewall();
Nic privateNic = getLocalNetwork(conn, name); Nic privateNic = getLocalNetwork(conn, name);
if (privateNic == null) { if (privateNic == null) {
@ -4008,6 +4035,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
s_logger.warn("Unable to determine the private network for host " + _host.ip); s_logger.warn("Unable to determine the private network for host " + _host.ip);
return false; return false;
} }
_privateNetworkName = name;
privateNic = getLocalNetwork(conn, name); privateNic = getLocalNetwork(conn, name);
if (privateNic == null) { if (privateNic == null) {
s_logger.warn("Unable to get private network " + name); s_logger.warn("Unable to get private network " + name);
@ -4026,6 +4054,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
} }
} else { } else {
guestNic = privateNic; guestNic = privateNic;
_guestNetworkName = _privateNetworkName;
} }
_host.guestNetwork = guestNic.nr.uuid; _host.guestNetwork = guestNic.nr.uuid;
_host.guestPif = guestNic.pr.uuid; _host.guestPif = guestNic.pr.uuid;
@ -4039,6 +4068,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
} }
} else { } else {
publicNic = guestNic; publicNic = guestNic;
_publicNetworkName = _guestNetworkName;
} }
_host.publicPif = publicNic.pr.uuid; _host.publicPif = publicNic.pr.uuid;
_host.publicNetwork = publicNic.nr.uuid; _host.publicNetwork = publicNic.nr.uuid;
@ -4061,6 +4091,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
_host.storagePif2 = storageNic2.pr.uuid; _host.storagePif2 = storageNic2.pr.uuid;
s_logger.info("Private Network is " + _privateNetworkName + " for host " + _host.ip); s_logger.info("Private Network is " + _privateNetworkName + " for host " + _host.ip);
s_logger.info("Guest Network is " + _guestNetworkName + " for host " + _host.ip);
s_logger.info("Public Network is " + _publicNetworkName + " for host " + _host.ip); s_logger.info("Public Network is " + _publicNetworkName + " for host " + _host.ip);
s_logger.info("Storage Network 1 is " + _storageNetworkName1 + " for host " + _host.ip); s_logger.info("Storage Network 1 is " + _storageNetworkName1 + " for host " + _host.ip);
s_logger.info("Storage Network 2 is " + _storageNetworkName2 + " for host " + _host.ip); s_logger.info("Storage Network 2 is " + _storageNetworkName2 + " for host " + _host.ip);

View File

@ -0,0 +1,55 @@
/**
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.hypervisor.xen.resource;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import com.cloud.hypervisor.xen.resource.CitrixResourceBase;
import com.xensource.xenapi.VM;
import com.cloud.resource.ServerResource;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Types.XenAPIException;
@Local(value=ServerResource.class)
public class XenServerResource extends CitrixResourceBase {
private static final Logger s_logger = Logger.getLogger(XenServerResource.class);
public XenServerResource() {
super();
}
@Override
protected String getGuestOsType(String stdType) {
return stdType;
}
@Override
protected void setMemory(Connection conn, VM vm, long memsize) throws XmlRpcException, XenAPIException {
vm.setMemoryLimits(conn, memsize, memsize, memsize, memsize);
}
@Override
protected String getPatchPath() {
return "scripts/vm/hypervisor/xenserver/xenserver56";
}
}

View File

@ -17,6 +17,8 @@
*/ */
package com.cloud.offerings; package com.cloud.offerings;
import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
@ -26,11 +28,18 @@ import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import com.cloud.network.Network.TrafficType;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.utils.db.GenericDao;
@Entity @Entity
@Table(name="network_offerings") @Table(name="network_offerings")
public class NetworkOfferingVO implements NetworkOffering { public class NetworkOfferingVO implements NetworkOffering {
public final static String SystemVmPublicNetwork = "System-Vm-Public-Network";
public final static String SystemVmGuestNetwork = "System-Vm-Guest-Network";
public final static String SystemVmLinkLocalNetwork = "System-Vm-LinkLocal-Network";
public final static String SystemVmManagementNetwork = "System-Vm-Management-Network";
@Id @Id
@GeneratedValue(strategy=GenerationType.IDENTITY) @GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id") @Column(name="id")
@ -42,10 +51,10 @@ public class NetworkOfferingVO implements NetworkOffering {
@Column(name="display_text") @Column(name="display_text")
String displayText; String displayText;
@Column(name="rate") @Column(name="nw_rate")
Integer rateMbps; Integer rateMbps;
@Column(name="multicast_rate") @Column(name="mc_rate")
Integer multicastRateMbps; Integer multicastRateMbps;
@Column(name="concurrent_connections") @Column(name="concurrent_connections")
@ -55,6 +64,19 @@ public class NetworkOfferingVO implements NetworkOffering {
@Enumerated(value=EnumType.STRING) @Enumerated(value=EnumType.STRING)
GuestIpType guestIpType; GuestIpType guestIpType;
@Column(name="traffic_type")
@Enumerated(value=EnumType.STRING)
TrafficType trafficType;
@Column(name="system_only")
boolean systemOnly;
@Column(name=GenericDao.REMOVED_COLUMN)
Date removed;
@Column(name=GenericDao.CREATED_COLUMN)
Date created;
@Override @Override
public String getDisplayText() { public String getDisplayText() {
return displayText; return displayText;
@ -70,6 +92,11 @@ public class NetworkOfferingVO implements NetworkOffering {
return id; return id;
} }
@Override
public TrafficType getTrafficType() {
return trafficType;
}
@Override @Override
public Integer getMulticastRateMbps() { public Integer getMulticastRateMbps() {
return multicastRateMbps; return multicastRateMbps;
@ -85,16 +112,16 @@ public class NetworkOfferingVO implements NetworkOffering {
return rateMbps; return rateMbps;
} }
public NetworkOfferingVO() { public Date getCreated() {
return created;
} }
public NetworkOfferingVO(String name, String displayText, GuestIpType type, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections) { public boolean isSystemOnly() {
this.name = name; return systemOnly;
this.displayText = displayText; }
this.guestIpType = type;
this.rateMbps = rateMbps; public Date getRemoved() {
this.multicastRateMbps = multicastRateMbps; return removed;
this.concurrentConnections = concurrentConnections;
} }
@Override @Override
@ -102,4 +129,27 @@ public class NetworkOfferingVO implements NetworkOffering {
return concurrentConnections; return concurrentConnections;
} }
public NetworkOfferingVO() {
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, GuestIpType type, boolean systemOnly, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections) {
this.name = name;
this.displayText = displayText;
this.guestIpType = type;
this.rateMbps = rateMbps;
this.multicastRateMbps = multicastRateMbps;
this.concurrentConnections = concurrentConnections;
this.trafficType = trafficType;
this.systemOnly = systemOnly;
}
/**
* Network Offering for all system vms.
* @param name
* @param trafficType
* @param type
*/
public NetworkOfferingVO(String name, TrafficType trafficType, GuestIpType type) {
this(name, "System Offering for " + name, trafficType, type, true, null, null, null);
}
} }

View File

@ -27,6 +27,7 @@ import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering; import com.cloud.offering.ServiceOffering;
import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.DiskOfferingVO;
@ -55,13 +56,13 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
@Column(name="guest_ip_type") @Column(name="guest_ip_type")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private GuestIpType guestIpType; private NetworkOffering.GuestIpType guestIpType;
protected ServiceOfferingVO() { protected ServiceOfferingVO() {
super(); super();
} }
public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags) { public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, NetworkOffering.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags) {
super(name, displayText, false, tags, recreatable, useLocalStorage); super(name, displayText, false, tags, recreatable, useLocalStorage);
this.cpu = cpu; this.cpu = cpu;
this.ramSize = ramSize; this.ramSize = ramSize;
@ -135,11 +136,11 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
return multicastRateMbps; return multicastRateMbps;
} }
public void setGuestIpType(GuestIpType guestIpType) { public void setGuestIpType(NetworkOffering.GuestIpType guestIpType) {
this.guestIpType = guestIpType; this.guestIpType = guestIpType;
} }
public GuestIpType getGuestIpType() { public NetworkOffering.GuestIpType getGuestIpType() {
return guestIpType; return guestIpType;
} }
} }

View File

@ -195,7 +195,7 @@ public abstract class StorageResource extends ServerResourceBase implements Serv
String path = rootdiskFolder + File.separator + "rootdisk"; String path = rootdiskFolder + File.separator + "rootdisk";
long totalSize = getVolumeSize(path); long totalSize = getVolumeSize(path);
VolumeVO vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), rootdiskFolder, path, totalSize, Volume.VolumeType.ROOT); VolumeVO vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), rootdiskFolder, path, totalSize, Volume.VolumeType.ROOT);
vols.add(vol); vols.add(vol);
// Get the datadisk volume // Get the datadisk volume
@ -203,7 +203,7 @@ public abstract class StorageResource extends ServerResourceBase implements Serv
path = datadiskFolder + File.separator + datadiskName; path = datadiskFolder + File.separator + datadiskName;
totalSize = getVolumeSize(path); totalSize = getVolumeSize(path);
vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), datadiskFolder, path, totalSize, Volume.VolumeType.DATADISK); vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), datadiskFolder, path, totalSize, Volume.VolumeType.DATADISK);
vols.add(vol); vols.add(vol);
} }
@ -216,7 +216,7 @@ public abstract class StorageResource extends ServerResourceBase implements Serv
String path = getVolumeName(imagePath, null); String path = getVolumeName(imagePath, null);
long totalSize = getVolumeSize(path); long totalSize = getVolumeSize(path);
VolumeVO vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.ROOT); VolumeVO vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.ROOT);
vols.add(vol); vols.add(vol);
@ -225,7 +225,7 @@ public abstract class StorageResource extends ServerResourceBase implements Serv
totalSize = getVolumeSize(path); totalSize = getVolumeSize(path);
vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.DATADISK); vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.DATADISK);
vols.add(vol); vols.add(vol);
} }

View File

@ -149,6 +149,13 @@ public class VolumeVO implements Volume {
@Enumerated(value=EnumType.STRING) @Enumerated(value=EnumType.STRING)
private State state; private State state;
@Column(name="source_type")
@Enumerated(value=EnumType.STRING)
Volume.SourceType sourceType;
@Column(name="source_id")
Long sourceId;
/** /**
* Constructor for data disk. * Constructor for data disk.
* @param type * @param type
@ -178,8 +185,7 @@ public class VolumeVO implements Volume {
} }
// Real Constructor // Real Constructor
public VolumeVO(long id, VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) { public VolumeVO(VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) {
this.id = id;
this.volumeType = type; this.volumeType = type;
this.name = name; this.name = name;
this.dataCenterId = dcId; this.dataCenterId = dcId;
@ -212,8 +218,7 @@ public class VolumeVO implements Volume {
} }
public VolumeVO(Long id, String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, Volume.VolumeType vType) { public VolumeVO(String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, Volume.VolumeType vType) {
this.id = id;
this.name = name; this.name = name;
this.accountId = accountId; this.accountId = accountId;
this.domainId = domainId; this.domainId = domainId;
@ -510,4 +515,24 @@ public class VolumeVO implements Volume {
public String toString() { public String toString() {
return new StringBuilder("Vol[").append(id).append("|vm=").append(instanceId).append("|").append(volumeType).append("]").toString(); return new StringBuilder("Vol[").append(id).append("|vm=").append(instanceId).append("|").append(volumeType).append("]").toString();
} }
@Override
public SourceType getSourceType() {
return this.sourceType;
}
@Override
public void setSourceType(SourceType sourceType) {
this.sourceType = sourceType;
}
@Override
public void setSourceId(Long sourceId){
this.sourceId = sourceId;
}
@Override
public Long getSourceId(){
return this.sourceId;
}
} }

View File

@ -94,6 +94,14 @@ public class ConsoleProxyVO extends VMInstanceVO implements ConsoleProxy {
@Transient @Transient
private int port; private int port;
/**
* Correct constructor to use.
*/
public ConsoleProxyVO(long id, String name, long templateId, long guestOSId, long dataCenterId, int activeSession) {
super(id, name, name, Type.ConsoleProxy, templateId, guestOSId, false);
this.activeSession = activeSession;
}
public ConsoleProxyVO( public ConsoleProxyVO(
long id, long id,
String name, String name,

View File

@ -24,7 +24,7 @@ import javax.ejb.Local;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.offering.ServiceOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.ComponentLocator;
@ -279,7 +279,7 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
SearchCriteria<UserVmVO> sc = AccountDataCenterVirtualSearch.create(); SearchCriteria<UserVmVO> sc = AccountDataCenterVirtualSearch.create();
sc.setParameters("account", accountId); sc.setParameters("account", accountId);
sc.setParameters("dc", dcId); sc.setParameters("dc", dcId);
sc.setJoinParameters("offeringSearch", "guestIpType", ServiceOffering.GuestIpType.Virtualized); sc.setJoinParameters("offeringSearch", "guestIpType", NetworkOffering.GuestIpType.Virtualized);
return listActiveBy(sc); return listActiveBy(sc);
} }

View File

@ -7,14 +7,8 @@ import time
import logging import logging
logging.basicConfig(filename='/tmp/xapilog',level=logging.DEBUG) logging.basicConfig(filename='/tmp/xapilog',level=logging.DEBUG)
def get_xapi_session(): def get_stats(session, collect_host_stats, consolidation_function, interval, start_time):
xapi = XenAPI.xapi_local();
xapi.login_with_password("","")
return xapi._session
def get_stats(collect_host_stats, consolidation_function, interval, start_time):
try: try:
session = get_xapi_session()
if collect_host_stats == "true" : if collect_host_stats == "true" :
url = "http://localhost/rrd_updates?" url = "http://localhost/rrd_updates?"

View File

@ -4,6 +4,7 @@
import os, sys, time import os, sys, time
import XenAPIPlugin import XenAPIPlugin
import XenAPI
sys.path.append("/opt/xensource/sm/") sys.path.append("/opt/xensource/sm/")
import SR, VDI, SRCommand, util, lvutil import SR, VDI, SRCommand, util, lvutil
from util import CommandException from util import CommandException
@ -35,13 +36,20 @@ def echo(fn):
return res return res
return wrapped return wrapped
def get_xapi_session():
xapi = XenAPI.xapi_local();
xapi.login_with_password("","")
return xapi._session
@echo @echo
def gethostvmstats(session, args): def gethostvmstats(session, args):
collect_host_stats = args['collectHostStats'] collect_host_stats = args['collectHostStats']
consolidation_function = args['consolidationFunction'] consolidation_function = args['consolidationFunction']
interval = args['interval'] interval = args['interval']
start_time = args['startTime'] start_time = args['startTime']
result = hostvmstats.get_stats(collect_host_stats, consolidation_function, interval, start_time) session = get_xapi_session()
result = hostvmstats.get_stats(session, collect_host_stats, consolidation_function, interval, start_time)
return result return result
@echo @echo
@ -454,7 +462,9 @@ def heartbeat(session, args):
txt='fail' txt='fail'
return txt return txt
def get_private_nic(session, args): def get_private_nic( args):
session = get_xapi_session()
vms = session.xenapi.VM.get_all()
host_uuid = args.get('host_uuid') host_uuid = args.get('host_uuid')
host = session.xenapi.host.get_by_uuid(host_uuid) host = session.xenapi.host.get_by_uuid(host_uuid)
piflist = session.xenapi.host.get_PIFs(host) piflist = session.xenapi.host.get_PIFs(host)
@ -481,7 +491,7 @@ def can_bridge_firewall(session, args):
util.pread2(['iptables', '-D', 'FORWARD', '-j', 'RH-Firewall-1-INPUT']) util.pread2(['iptables', '-D', 'FORWARD', '-j', 'RH-Firewall-1-INPUT'])
except: except:
util.SMlog('Chain BRIDGE-FIREWALL already exists') util.SMlog('Chain BRIDGE-FIREWALL already exists')
privnic = get_private_nic(session, args) privnic = get_private_nic(args)
result = 'true' result = 'true'
try: try:
util.pread2(['/bin/bash', '-c', 'iptables -n -L FORWARD | grep BRIDGE-FIREWALL']) util.pread2(['/bin/bash', '-c', 'iptables -n -L FORWARD | grep BRIDGE-FIREWALL'])
@ -496,8 +506,8 @@ def can_bridge_firewall(session, args):
if not os.path.exists('/var/run/cloud'): if not os.path.exists('/var/run/cloud'):
os.makedirs('/var/run/cloud') os.makedirs('/var/run/cloud')
cleanup_rules_for_dead_vms(session) cleanup_rules_for_dead_vms()
cleanup_rules(session) cleanup_rules()
return result return result
@ -875,6 +885,8 @@ def get_rule_log_for_vm(session, vmName):
def get_rule_logs_for_vms(session, args): def get_rule_logs_for_vms(session, args):
host_uuid = args.pop('host_uuid') host_uuid = args.pop('host_uuid')
try: try:
session = get_xapi_session()
thishost = session.xenapi.host.get_by_uuid(host_uuid) thishost = session.xenapi.host.get_by_uuid(host_uuid)
hostrec = session.xenapi.host.get_record(thishost) hostrec = session.xenapi.host.get_record(thishost)
vms = hostrec.get('resident_VMs') vms = hostrec.get('resident_VMs')
@ -897,7 +909,9 @@ def get_rule_logs_for_vms(session, args):
return ";".join(result) return ";".join(result)
@echo @echo
def cleanup_rules_for_dead_vms(session): def cleanup_rules_for_dead_vms():
try:
session = get_xapi_session()
vms = session.xenapi.VM.get_all() vms = session.xenapi.VM.get_all()
cleaned = 0 cleaned = 0
for vm_name in [session.xenapi.VM.get_name_label(x) for x in vms]: for vm_name in [session.xenapi.VM.get_name_label(x) for x in vms]:
@ -913,9 +927,16 @@ def cleanup_rules_for_dead_vms(session):
cleaned = cleaned+1 cleaned = cleaned+1
util.SMlog("Cleaned up rules for " + str(cleaned) + " vms") util.SMlog("Cleaned up rules for " + str(cleaned) + " vms")
except:
util.SMlog("Failed to cleanup rules for dead vms!")
@echo @echo
def cleanup_rules(session): def cleanup_rules():
try:
session = get_xapi_session()
chainscmd = "iptables-save | grep '^:' | awk '{print $1}' | cut -d':' -f2" chainscmd = "iptables-save | grep '^:' | awk '{print $1}' | cut -d':' -f2"
chains = util.pread2(['/bin/bash', '-c', chainscmd]).split('\n') chains = util.pread2(['/bin/bash', '-c', chainscmd]).split('\n')
cleaned = 0 cleaned = 0
@ -942,6 +963,8 @@ def cleanup_rules(session):
destroy_network_rules_for_vm(session, {'vmName':vmname}) destroy_network_rules_for_vm(session, {'vmName':vmname})
util.SMlog("Cleaned up rules for " + str(len(cleanup)) + " chains") util.SMlog("Cleaned up rules for " + str(len(cleanup)) + " chains")
except:
util.SMlog("Failed to cleanup rules !")
@echo @echo
def check_rule_log_for_vm(vmName, vmID, vmIP, domID, signature, seqno): def check_rule_log_for_vm(vmName, vmID, vmIP, domID, signature, seqno):
@ -1005,6 +1028,8 @@ def remove_rule_log_for_vm(vmName):
@echo @echo
def network_rules(session, args): def network_rules(session, args):
try:
session = get_xapi_session()
vm_name = args.get('vmName') vm_name = args.get('vmName')
vmName = vm_name vmName = vm_name
vm_ip = args.get('vmIP') vm_ip = args.get('vmIP')
@ -1101,6 +1126,8 @@ def network_rules(session, args):
return 'false' return 'false'
return 'true' return 'true'
except:
util.SMlog("Failed to network rule !")

View File

@ -36,8 +36,9 @@ import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO; import com.cloud.dc.HostPodVO;
import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.HostPodDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offering.ServiceOffering; import com.cloud.offering.ServiceOffering;
import com.cloud.offering.ServiceOffering.GuestIpType;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.VolumeVO; import com.cloud.storage.VolumeVO;
@ -253,14 +254,14 @@ public class UserConcentratedAllocator implements PodAllocator {
so = _offeringDao.findById(userVm.getServiceOfferingId()); so = _offeringDao.findById(userVm.getServiceOfferingId());
} else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) { } else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) {
so = new ServiceOfferingVO("Fake Offering For DomP", 1, so = new ServiceOfferingVO("Fake Offering For DomP", 1,
_proxyRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) { } else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) {
so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} else if(vm.getType() == VirtualMachine.Type.DomainRouter) { } else if(vm.getType() == VirtualMachine.Type.DomainRouter) {
so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} else { } else {
assert(false) : "Unsupported system vm type"; assert(false) : "Unsupported system vm type";
so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} }
if(capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) { if(capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) {

View File

@ -337,6 +337,8 @@ public abstract class BaseCmd {
STATE("state", BaseCmd.TYPE_STRING, "state"), STATE("state", BaseCmd.TYPE_STRING, "state"),
STOPPED_VMS("stoppedvms", BaseCmd.TYPE_LONG, "stoppedvms"), STOPPED_VMS("stoppedvms", BaseCmd.TYPE_LONG, "stoppedvms"),
STORAGE("storage", BaseCmd.TYPE_LONG, "storage"), STORAGE("storage", BaseCmd.TYPE_LONG, "storage"),
SOURCE_ID("sourceid", BaseCmd.TYPE_LONG, "sourceid"),
SOURCE_TYPE("sourcetype",BaseCmd.TYPE_STRING,"sourcetype"),
STORAGE_TYPE("storagetype", BaseCmd.TYPE_STRING, "storageType"), STORAGE_TYPE("storagetype", BaseCmd.TYPE_STRING, "storageType"),
SUCCESS("success", BaseCmd.TYPE_BOOLEAN, "success"), SUCCESS("success", BaseCmd.TYPE_BOOLEAN, "success"),
SUM_ACROSS_ZONE("sumacrosszone", BaseCmd.TYPE_BOOLEAN, "sumAcrossZone"), SUM_ACROSS_ZONE("sumacrosszone", BaseCmd.TYPE_BOOLEAN, "sumAcrossZone"),

View File

@ -26,7 +26,8 @@ import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd; import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException; import com.cloud.api.ServerApiException;
import com.cloud.offering.ServiceOffering.GuestIpType; import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.user.User; import com.cloud.user.User;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
@ -142,7 +143,7 @@ public class CreateServiceOfferingCmd extends BaseCmd{
storageType = offering.getUseLocalStorage() ? "local" : "shared"; storageType = offering.getUseLocalStorage() ? "local" : "shared";
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType)); returnValues.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.OFFER_HA.getName(), offering.getOfferHA())); returnValues.add(new Pair<String, Object>(BaseCmd.Properties.OFFER_HA.getName(), offering.getOfferHA()));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName(), (offering.getGuestIpType().equals(GuestIpType.Virtualized)))); returnValues.add(new Pair<String, Object>(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName(), (offering.getGuestIpType().equals(NetworkOffering.GuestIpType.Virtualized))));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), offering.getTags())); returnValues.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), offering.getTags()));
} }
return returnValues; return returnValues;

View File

@ -26,7 +26,8 @@ import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd; import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException; import com.cloud.api.ServerApiException;
import com.cloud.offering.ServiceOffering.GuestIpType; import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.server.Criteria; import com.cloud.server.Criteria;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.user.Account; import com.cloud.user.Account;
@ -123,7 +124,7 @@ public class ListServiceOfferingsCmd extends BaseCmd {
String storageType = offering.getUseLocalStorage() ? "local" : "shared"; String storageType = offering.getUseLocalStorage() ? "local" : "shared";
offeringData.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType)); offeringData.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType));
offeringData.add(new Pair<String, Object>(BaseCmd.Properties.OFFER_HA.getName(), offering.getOfferHA())); offeringData.add(new Pair<String, Object>(BaseCmd.Properties.OFFER_HA.getName(), offering.getOfferHA()));
offeringData.add(new Pair<String, Object>(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName(), (offering.getGuestIpType().equals(GuestIpType.Virtualized)))); offeringData.add(new Pair<String, Object>(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName(), (offering.getGuestIpType().equals(NetworkOffering.GuestIpType.Virtualized))));
offeringData.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), (offering.getTags()))); offeringData.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), (offering.getTags())));
soTag[i++] = offeringData; soTag[i++] = offeringData;

View File

@ -223,6 +223,8 @@ public class ListVolumesCmd extends BaseCmd{
Long poolId = volume.getPoolId(); Long poolId = volume.getPoolId();
String poolName = (poolId == null) ? "none" : getManagementServer().findPoolById(poolId).getName(); String poolName = (poolId == null) ? "none" : getManagementServer().findPoolById(poolId).getName();
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE.getName(), poolName)); volumeData.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE.getName(), poolName));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.SOURCE_ID.getName(),volume.getSourceId()));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.SOURCE_TYPE.getName(),volume.getSourceType().toString()));
vTag[i++] = volumeData; vTag[i++] = volumeData;
} }

View File

@ -26,7 +26,8 @@ import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd; import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException; import com.cloud.api.ServerApiException;
import com.cloud.offering.ServiceOffering.GuestIpType; import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.user.User; import com.cloud.user.User;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
@ -95,7 +96,7 @@ public class UpdateServiceOfferingCmd extends BaseCmd{
String storageType = offering.getUseLocalStorage() ? "local" : "shared"; String storageType = offering.getUseLocalStorage() ? "local" : "shared";
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType)); returnValues.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.OFFER_HA.getName(), offering.getOfferHA())); returnValues.add(new Pair<String, Object>(BaseCmd.Properties.OFFER_HA.getName(), offering.getOfferHA()));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName(), (offering.getGuestIpType().equals(GuestIpType.Virtualized)))); returnValues.add(new Pair<String, Object>(BaseCmd.Properties.USE_VIRTUAL_NETWORK.getName(), (offering.getGuestIpType().equals(NetworkOffering.GuestIpType.Virtualized))));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), offering.getTags())); returnValues.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), offering.getTags()));
} else { } else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update service offering " + offeringId); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update service offering " + offeringId);

View File

@ -52,7 +52,8 @@ import com.cloud.event.dao.EventDao;
import com.cloud.exception.InternalErrorException; import com.cloud.exception.InternalErrorException;
import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressDao;
import com.cloud.offering.ServiceOffering.GuestIpType; import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.DiskOfferingVO;
@ -799,7 +800,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr));
int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
GuestIpType guestIpType = useVirtualNetwork ? GuestIpType.Virtualized : GuestIpType.DirectSingle; NetworkOffering.GuestIpType guestIpType = useVirtualNetwork ? NetworkOffering.GuestIpType.Virtualized : NetworkOffering.GuestIpType.DirectSingle;
tags = cleanupTags(tags); tags = cleanupTags(tags);
ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, guestIpType, localStorageRequired, false, tags); ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, guestIpType, localStorageRequired, false, tags);
@ -833,7 +834,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
} }
if (useVirtualNetwork != null) { if (useVirtualNetwork != null) {
GuestIpType guestIpType = useVirtualNetwork ? GuestIpType.Virtualized : GuestIpType.DirectSingle; NetworkOffering.GuestIpType guestIpType = useVirtualNetwork ? NetworkOffering.GuestIpType.Virtualized : NetworkOffering.GuestIpType.DirectSingle;
offering.setGuestIpType(guestIpType); offering.setGuestIpType(guestIpType);
} }
@ -848,7 +849,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
if (_serviceOfferingDao.update(serviceOfferingId, offering)) { if (_serviceOfferingDao.update(serviceOfferingId, offering)) {
offering = _serviceOfferingDao.findById(serviceOfferingId); offering = _serviceOfferingDao.findById(serviceOfferingId);
saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully updated service offering with name: " + offering.getName() + ".", "soId=" + offering.getId(), "name=" + offering.getName(), saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully updated service offering with name: " + offering.getName() + ".", "soId=" + offering.getId(), "name=" + offering.getName(),
"displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == GuestIpType.Virtualized), "tags=" + offering.getTags()); "displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized), "tags=" + offering.getTags());
return offering; return offering;
} else { } else {
return null; return null;
@ -891,7 +892,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
if (_serviceOfferingDao.remove(serviceOfferingId)) { if (_serviceOfferingDao.remove(serviceOfferingId)) {
saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully deleted service offering with name: " + offering.getName(), "soId=" + serviceOfferingId, "name=" + offering.getName(), saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully deleted service offering with name: " + offering.getName(), "soId=" + serviceOfferingId, "name=" + offering.getName(),
"displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == GuestIpType.Virtualized)); "displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized));
return true; return true;
} else { } else {
return false; return false;

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
@ -96,8 +97,11 @@ import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
import com.cloud.maid.StackMaid; import com.cloud.maid.StackMaid;
import com.cloud.network.IpAddrAllocator; import com.cloud.network.IpAddrAllocator;
import com.cloud.network.IpAddrAllocator.networkInfo; import com.cloud.network.IpAddrAllocator.networkInfo;
import com.cloud.network.Network.TrafficType;
import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressDao;
import com.cloud.offering.ServiceOffering.GuestIpType; import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.StorageManager; import com.cloud.storage.StorageManager;
@ -110,6 +114,7 @@ import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.dao.VMTemplateHostDao;
import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.dao.VolumeDao;
import com.cloud.user.Account; import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountVO; import com.cloud.user.AccountVO;
import com.cloud.user.User; import com.cloud.user.User;
import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.AccountDao;
@ -134,6 +139,7 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Event; import com.cloud.vm.VirtualMachine.Event;
import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.VirtualMachineName; import com.cloud.vm.VirtualMachineName;
import com.cloud.vm.VmManager;
import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.ConsoleProxyDao;
import com.cloud.vm.dao.VMInstanceDao; import com.cloud.vm.dao.VMInstanceDao;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -217,11 +223,13 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
private StorageManager _storageMgr; private StorageManager _storageMgr;
@Inject @Inject
private HighAvailabilityManager _haMgr; private HighAvailabilityManager _haMgr;
@Inject AccountManager _accountMgr;
@Inject @Inject
private EventDao _eventDao; private EventDao _eventDao;
@Inject @Inject
ServiceOfferingDao _offeringDao; ServiceOfferingDao _offeringDao;
@Inject
NetworkOfferingDao _networkOfferingDao;
private IpAddrAllocator _IpAllocator; private IpAddrAllocator _IpAllocator;
private ConsoleProxyListener _listener; private ConsoleProxyListener _listener;
@ -229,9 +237,16 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
private ServiceOfferingVO _serviceOffering; private ServiceOfferingVO _serviceOffering;
private VMTemplateVO _template; private VMTemplateVO _template;
NetworkOfferingVO _publicNetworkOffering;
NetworkOfferingVO _managementNetworkOffering;
NetworkOfferingVO _linkLocalNetworkOffering;
@Inject @Inject
private AsyncJobManager _asyncMgr; private AsyncJobManager _asyncMgr;
@Inject
private VmManager _vmMgr;
private final ScheduledExecutorService _capacityScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("CP-Scan")); private final ScheduledExecutorService _capacityScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("CP-Scan"));
private final ExecutorService _requestHandlerScheduler = Executors.newCachedThreadPool(new NamedThreadFactory("Request-handler")); private final ExecutorService _requestHandlerScheduler = Executors.newCachedThreadPool(new NamedThreadFactory("Request-handler"));
@ -989,6 +1004,111 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
} }
} }
@DB
protected Map<String, Object> createProxyInstance2(long dataCenterId) {
long id = _consoleProxyDao.getNextInSequence(Long.class, "id");
String name = VirtualMachineName.getConsoleProxyName(id, _instance);
ConsoleProxyVO proxy = new ConsoleProxyVO(id, name, _template.getId(), _template.getGuestOSId(), dataCenterId, 0);
proxy = _consoleProxyDao.persist(proxy);
ArrayList<NetworkOfferingVO> networkOfferings = new ArrayList<NetworkOfferingVO>(3);
networkOfferings.add(_managementNetworkOffering);
networkOfferings.add(_linkLocalNetworkOffering);
networkOfferings.add(_publicNetworkOffering);
_vmMgr.allocate(proxy, _serviceOffering, null, networkOfferings, null, null, null, _accountMgr.getSystemAccount());
Map<String, Object> context = new HashMap<String, Object>();
String publicIpAddress = null;
return null;
/*
Transaction txn = Transaction.currentTxn();
try {
DataCenterVO dc = _dcDao.findById(dataCenterId);
assert (dc != null);
context.put("dc", dc);
// this will basically allocate the pod based on data center id as
// we use system user id here
Set<Long> avoidPods = new HashSet<Long>();
Pair<HostPodVO, Long> pod = null;
networkInfo publicIpAndVlan = null;
// About MAC address allocation
// MAC address used by User VM is inherited from DomR MAC address,
// with the least 16 bits overrided. to avoid
// potential conflicts, domP will mask bit 31
//
String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(dataCenterId, (1L << 31));
String privateMacAddress = macAddresses[0];
String publicMacAddress = macAddresses[1];
macAddresses = _dcDao.getNextAvailableMacAddressPair(dataCenterId, (1L << 31));
String guestMacAddress = macAddresses[0];
while ((pod = _agentMgr.findPod(_template, _serviceOffering, dc, Account.ACCOUNT_ID_SYSTEM, avoidPods)) != null) {
publicIpAndVlan = allocPublicIpAddress(dataCenterId, pod.first().getId(), publicMacAddress);
if (publicIpAndVlan == null) {
s_logger.warn("Unable to allocate public IP address for console proxy vm in data center : " + dataCenterId + ", pod="
+ pod.first().getId());
avoidPods.add(pod.first().getId());
} else {
break;
}
}
if (pod == null || publicIpAndVlan == null) {
s_logger.warn("Unable to allocate pod for console proxy vm in data center : " + dataCenterId);
context.put("proxyVmId", (long) 0);
return context;
}
long id = _consoleProxyDao.getNextInSequence(Long.class, "id");
context.put("publicIpAddress", publicIpAndVlan._ipAddr);
context.put("pod", pod);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Pod allocated " + pod.first().getName());
}
String cidrNetmask = NetUtils.getCidrNetmask(pod.first().getCidrSize());
// Find the VLAN ID, VLAN gateway, and VLAN netmask for
// publicIpAddress
publicIpAddress = publicIpAndVlan._ipAddr;
String vlanGateway = publicIpAndVlan._gateWay;
String vlanNetmask = publicIpAndVlan._netMask;
txn.start();
ConsoleProxyVO proxy;
String name = VirtualMachineName.getConsoleProxyName(id, _instance).intern();
proxy = new ConsoleProxyVO(id, name, guestMacAddress, null, NetUtils.getLinkLocalNetMask(), privateMacAddress, null, cidrNetmask,
_template.getId(), _template.getGuestOSId(), publicMacAddress, publicIpAddress, vlanNetmask, publicIpAndVlan._vlanDbId,
publicIpAndVlan._vlanid, pod.first().getId(), dataCenterId, vlanGateway, null, dc.getDns1(), dc.getDns2(), _domain,
_proxyRamSize, 0);
proxy.setLastHostId(pod.second());
proxy = _consoleProxyDao.persist(proxy);
long proxyVmId = proxy.getId();
final EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_PROXY_CREATE);
event.setLevel(EventVO.LEVEL_INFO);
event.setDescription("New console proxy created - " + proxy.getName());
_eventDao.persist(event);
txn.commit();
context.put("proxyVmId", proxyVmId);
return context;
} catch (Throwable e) {
s_logger.error("Unexpected exception : ", e);
context.put("proxyVmId", (long) 0);
return context;
}*/
}
@DB @DB
protected ConsoleProxyVO allocProxyStorage(long dataCenterId, long proxyVmId) { protected ConsoleProxyVO allocProxyStorage(long dataCenterId, long proxyVmId) {
ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId); ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
@ -2224,7 +2344,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
} }
boolean useLocalStorage = Boolean.parseBoolean((String) params.get(Config.SystemVMUseLocalStorage.key())); boolean useLocalStorage = Boolean.parseBoolean((String) params.get(Config.SystemVMUseLocalStorage.key()));
_serviceOffering = new ServiceOfferingVO("Fake Offering For DomP", 1, _proxyRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, _serviceOffering = new ServiceOfferingVO("Fake Offering For DomP", 1, _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized,
useLocalStorage, true, null); useLocalStorage, true, null);
_serviceOffering.setUniqueName("Cloud.com-ConsoleProxy"); _serviceOffering.setUniqueName("Cloud.com-ConsoleProxy");
_serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering);
@ -2233,6 +2353,13 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
throw new ConfigurationException("Unable to find the template for console proxy VMs"); throw new ConfigurationException("Unable to find the template for console proxy VMs");
} }
_publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmPublicNetwork, TrafficType.Public, null);
_publicNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_publicNetworkOffering);
_managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmManagementNetwork, TrafficType.Management, null);
_managementNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_managementNetworkOffering);
_linkLocalNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmLinkLocalNetwork, TrafficType.LinkLocal, null);
_linkLocalNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_linkLocalNetworkOffering);
_capacityScanScheduler.scheduleAtFixedRate(getCapacityScanTask(), STARTUP_DELAY, _capacityScanInterval, TimeUnit.MILLISECONDS); _capacityScanScheduler.scheduleAtFixedRate(getCapacityScanTask(), STARTUP_DELAY, _capacityScanInterval, TimeUnit.MILLISECONDS);
if (s_logger.isInfoEnabled()) if (s_logger.isInfoEnabled())

View File

@ -99,8 +99,8 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
String password) throws DiscoveryException { String password) throws DiscoveryException {
Map<KvmDummyResourceBase, Map<String, String>> resources = new HashMap<KvmDummyResourceBase, Map<String, String>>(); Map<KvmDummyResourceBase, Map<String, String>> resources = new HashMap<KvmDummyResourceBase, Map<String, String>>();
Map<String, String> details = new HashMap<String, String>(); Map<String, String> details = new HashMap<String, String>();
if (!uri.getScheme().equals("http")) { if (!uri.getScheme().equals("kvm")) {
String msg = "urlString is not http so we're not taking care of the discovery for this: " + uri; String msg = "urlString is not kvm so we're not taking care of the discovery for this: " + uri;
s_logger.debug(msg); s_logger.debug(msg);
return null; return null;
} }

View File

@ -53,6 +53,7 @@ import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.xen.resource.CitrixResourceBase; import com.cloud.hypervisor.xen.resource.CitrixResourceBase;
import com.cloud.hypervisor.xen.resource.XcpServerResource; import com.cloud.hypervisor.xen.resource.XcpServerResource;
import com.cloud.hypervisor.xen.resource.XenServerConnectionPool; import com.cloud.hypervisor.xen.resource.XenServerConnectionPool;
import com.cloud.hypervisor.xen.resource.XenServerResource;
import com.cloud.resource.Discoverer; import com.cloud.resource.Discoverer;
import com.cloud.resource.DiscovererBase; import com.cloud.resource.DiscovererBase;
import com.cloud.resource.ServerResource; import com.cloud.resource.ServerResource;
@ -172,13 +173,8 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
continue; continue;
} }
CitrixResourceBase resource = createServerResource(dcId, podId, record);
if (!checkServer(conn, dcId, podId, host, record)) {
continue;
}
s_logger.info("Found host " + record.hostname + " ip=" + record.address + " product version=" + prodVersion); s_logger.info("Found host " + record.hostname + " ip=" + record.address + " product version=" + prodVersion);
CitrixResourceBase resource = createServerResource(record);
Map<String, String> details = new HashMap<String, String>(); Map<String, String> details = new HashMap<String, String>();
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
@ -380,21 +376,20 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
return true; return true;
} }
protected boolean checkServer(Connection conn, long dcId, Long podId, Host host, Host.Record record) { protected CitrixResourceBase createServerResource(long dcId, Long podId, Host.Record record) {
String prodBrand = record.softwareVersion.get("product_brand").trim(); String prodBrand = record.softwareVersion.get("product_brand").trim();
String prodVersion = record.softwareVersion.get("product_version").trim(); String prodVersion = record.softwareVersion.get("product_version").trim();
if(!prodBrand.equals("XenCloudPlatform") || !prodVersion.equals("0.1.1")) { if(prodBrand.equals("XenCloudPlatform") && prodVersion.equals("0.1.1"))
String msg = "Only support XCP 0.1.1, but this one is " + prodBrand + " " + prodVersion; return new XcpServerResource();
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
throw new RuntimeException(msg);
}
return true;
}
protected CitrixResourceBase createServerResource(Host.Record record) { if(prodBrand.equals("XenServer") && prodVersion.equals("5.6.0"))
return new XcpServerResource(); return new XenServerResource();
String msg = "Only support XCP 0.1.1 and Xerver 5.6.0, but this one is " + prodBrand + " " + prodVersion;
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
throw new RuntimeException(msg);
} }
protected void serverConfig() { protected void serverConfig() {

View File

@ -38,7 +38,8 @@ import com.cloud.host.Host;
import com.cloud.host.HostVO; import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDao;
import com.cloud.migration.DiskOffering21VO.Type; import com.cloud.migration.DiskOffering21VO.Type;
import com.cloud.offering.ServiceOffering.GuestIpType; import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.storage.StoragePoolVO; import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.VolumeVO; import com.cloud.storage.VolumeVO;
import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StoragePoolType;
@ -305,7 +306,7 @@ public class Db20to21MigrationUtil {
_configDao.getValue(Config.ConsoleProxyRamSize.key()), _configDao.getValue(Config.ConsoleProxyRamSize.key()),
ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE); ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE);
ServiceOffering21VO soConsoleProxy = new ServiceOffering21VO("Fake Offering For DomP", 1, ServiceOffering21VO soConsoleProxy = new ServiceOffering21VO("Fake Offering For DomP", 1,
proxyRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized,
useLocalStorage, true, null); useLocalStorage, true, null);
soConsoleProxy.setId(seq++); soConsoleProxy.setId(seq++);
soConsoleProxy.setUniqueName("Cloud.com-ConsoleProxy"); soConsoleProxy.setUniqueName("Cloud.com-ConsoleProxy");
@ -316,7 +317,7 @@ public class Db20to21MigrationUtil {
_configDao.getValue(Config.SecStorageVmRamSize.key()), _configDao.getValue(Config.SecStorageVmRamSize.key()),
SecondaryStorageVmManager.DEFAULT_SS_VM_RAMSIZE); SecondaryStorageVmManager.DEFAULT_SS_VM_RAMSIZE);
ServiceOffering21VO soSecondaryVm = new ServiceOffering21VO("Fake Offering For Secondary Storage VM", 1, ServiceOffering21VO soSecondaryVm = new ServiceOffering21VO("Fake Offering For Secondary Storage VM", 1,
secStorageVmRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, useLocalStorage, true, null); secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, useLocalStorage, true, null);
soSecondaryVm.setId(seq++); soSecondaryVm.setId(seq++);
soSecondaryVm.setUniqueName("Cloud.com-SecondaryStorage"); soSecondaryVm.setUniqueName("Cloud.com-SecondaryStorage");
soSecondaryVm = _serviceOffering21Dao.persist(soSecondaryVm); soSecondaryVm = _serviceOffering21Dao.persist(soSecondaryVm);
@ -324,7 +325,7 @@ public class Db20to21MigrationUtil {
int routerRamSize = NumbersUtil.parseInt(_configDao.getValue("router.ram.size"), 128); int routerRamSize = NumbersUtil.parseInt(_configDao.getValue("router.ram.size"), 128);
ServiceOffering21VO soDomainRouter = new ServiceOffering21VO("Fake Offering For DomR", 1, ServiceOffering21VO soDomainRouter = new ServiceOffering21VO("Fake Offering For DomR", 1,
routerRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, useLocalStorage, true, null); routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, useLocalStorage, true, null);
soDomainRouter.setId(seq++); soDomainRouter.setId(seq++);
soDomainRouter.setUniqueName("Cloud.Com-SoftwareRouter"); soDomainRouter.setUniqueName("Cloud.Com-SoftwareRouter");
soDomainRouter = _serviceOffering21Dao.persist(soDomainRouter); soDomainRouter = _serviceOffering21Dao.persist(soDomainRouter);

View File

@ -11,7 +11,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import com.cloud.offering.ServiceOffering.GuestIpType; import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
@Entity @Entity
@ -51,7 +52,7 @@ public class ServiceOffering20VO {
@Column(name="guest_ip_type") @Column(name="guest_ip_type")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private GuestIpType guestIpType = GuestIpType.Virtualized; private NetworkOffering.GuestIpType guestIpType = NetworkOffering.GuestIpType.Virtualized;
@Column(name="use_local_storage") @Column(name="use_local_storage")
private boolean useLocalStorage; private boolean useLocalStorage;
@ -66,10 +67,10 @@ public class ServiceOffering20VO {
} }
public ServiceOffering20VO(Long id, String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, boolean localStorageRequired) { public ServiceOffering20VO(Long id, String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, boolean localStorageRequired) {
this(id, name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, displayText, GuestIpType.Virtualized, localStorageRequired); this(id, name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, displayText, NetworkOffering.GuestIpType.Virtualized, localStorageRequired);
} }
public ServiceOffering20VO(Long id, String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, GuestIpType guestIpType, boolean useLocalStorage) { public ServiceOffering20VO(Long id, String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, NetworkOffering.GuestIpType guestIpType, boolean useLocalStorage) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.cpu = cpu; this.cpu = cpu;
@ -167,11 +168,11 @@ public class ServiceOffering20VO {
return multicastRateMbps; return multicastRateMbps;
} }
public void setGuestIpType(GuestIpType guestIpType) { public void setGuestIpType(NetworkOffering.GuestIpType guestIpType) {
this.guestIpType = guestIpType; this.guestIpType = guestIpType;
} }
public GuestIpType getGuestIpType() { public NetworkOffering.GuestIpType getGuestIpType() {
return guestIpType; return guestIpType;
} }

View File

@ -9,6 +9,7 @@ import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering; import com.cloud.offering.ServiceOffering;
@Entity @Entity
@ -36,13 +37,13 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe
@Column(name="guest_ip_type") @Column(name="guest_ip_type")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private GuestIpType guestIpType; private NetworkOffering.GuestIpType guestIpType;
protected ServiceOffering21VO() { protected ServiceOffering21VO() {
super(); super();
} }
public ServiceOffering21VO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags) { public ServiceOffering21VO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, NetworkOffering.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags) {
super(name, displayText, false, tags, recreatable, useLocalStorage); super(name, displayText, false, tags, recreatable, useLocalStorage);
this.cpu = cpu; this.cpu = cpu;
this.ramSize = ramSize; this.ramSize = ramSize;
@ -116,11 +117,11 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe
return multicastRateMbps; return multicastRateMbps;
} }
public void setGuestIpType(GuestIpType guestIpType) { public void setGuestIpType(NetworkOffering.GuestIpType guestIpType) {
this.guestIpType = guestIpType; this.guestIpType = guestIpType;
} }
public GuestIpType getGuestIpType() { public NetworkOffering.GuestIpType getGuestIpType() {
return guestIpType; return guestIpType;
} }
} }

View File

@ -98,11 +98,15 @@ import com.cloud.host.Host;
import com.cloud.host.HostVO; import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor;
import com.cloud.network.Network.TrafficType;
import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.FirewallRulesDao;
import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.LoadBalancerDao; import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.dao.SecurityGroupVMMapDao; import com.cloud.network.dao.SecurityGroupVMMapDao;
import com.cloud.offering.ServiceOffering.GuestIpType; import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.StorageManager; import com.cloud.storage.StorageManager;
@ -125,6 +129,7 @@ import com.cloud.user.dao.UserStatisticsDao;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils; import com.cloud.utils.StringUtils;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Inject; import com.cloud.utils.component.Inject;
import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.concurrency.NamedThreadFactory;
@ -186,8 +191,10 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
@Inject AsyncJobManager _asyncMgr; @Inject AsyncJobManager _asyncMgr;
@Inject StoragePoolDao _storagePoolDao = null; @Inject StoragePoolDao _storagePoolDao = null;
@Inject ServiceOfferingDao _serviceOfferingDao = null; @Inject ServiceOfferingDao _serviceOfferingDao = null;
@Inject @Inject UserStatisticsDao _statsDao = null;
private UserStatisticsDao _statsDao; @Inject NetworkOfferingDao _networkOfferingDao = null;
Adapters<NetworkProfiler> _networkProfilers;
long _routerTemplateId = -1; long _routerTemplateId = -1;
int _routerRamSize; int _routerRamSize;
@ -198,6 +205,10 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
int _routerCleanupInterval = 3600; int _routerCleanupInterval = 3600;
int _routerStatsInterval = 300; int _routerStatsInterval = 300;
private ServiceOfferingVO _offering; private ServiceOfferingVO _offering;
private NetworkOfferingVO _managementNetworkOffering;
private NetworkOfferingVO _publicNetworkOffering;
private NetworkOfferingVO _linkLocalNetworkOffering;
private NetworkOfferingVO _guestNetworkOffering;
private VMTemplateVO _template; private VMTemplateVO _template;
ScheduledExecutorService _executor; ScheduledExecutorService _executor;
@ -207,6 +218,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
return destroyRouter(router.getId()); return destroyRouter(router.getId());
} }
@Override
public boolean sendSshKeysToHost(Long hostId, String pubKey, String prvKey) { public boolean sendSshKeysToHost(Long hostId, String pubKey, String prvKey) {
ModifySshKeysCommand cmd = new ModifySshKeysCommand(pubKey, prvKey); ModifySshKeysCommand cmd = new ModifySshKeysCommand(pubKey, prvKey);
final Answer answer = _agentMgr.easySend(hostId, cmd); final Answer answer = _agentMgr.easySend(hostId, cmd);
@ -219,7 +231,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
@Override @DB @Override @DB
public String assignSourceNatIpAddress(AccountVO account, final DataCenterVO dc, final String domain, final ServiceOfferingVO serviceOffering, long startEventId) throws ResourceAllocationException { public String assignSourceNatIpAddress(AccountVO account, final DataCenterVO dc, final String domain, final ServiceOfferingVO serviceOffering, long startEventId) throws ResourceAllocationException {
if (serviceOffering.getGuestIpType() == GuestIpType.DirectDual || serviceOffering.getGuestIpType() == GuestIpType.DirectSingle) { if (serviceOffering.getGuestIpType() == NetworkOffering.GuestIpType.DirectDual || serviceOffering.getGuestIpType() == NetworkOffering.GuestIpType.DirectSingle) {
return null; return null;
} }
final long dcId = dc.getId(); final long dcId = dc.getId();
@ -354,6 +366,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
} }
} }
@Override
@DB @DB
public DomainRouterVO createDhcpServerForDirectlyAttachedGuests(long userId, long accountId, DataCenterVO dc, HostPodVO pod, Long candidateHost, VlanVO guestVlan) throws ConcurrentOperationException{ public DomainRouterVO createDhcpServerForDirectlyAttachedGuests(long userId, long accountId, DataCenterVO dc, HostPodVO pod, Long candidateHost, VlanVO guestVlan) throws ConcurrentOperationException{
@ -1492,6 +1505,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
} }
} }
@Override
public List<FirewallRuleVO> updatePortForwardingRules(final List<FirewallRuleVO> fwRules, final DomainRouterVO router, Long hostId ){ public List<FirewallRuleVO> updatePortForwardingRules(final List<FirewallRuleVO> fwRules, final DomainRouterVO router, Long hostId ){
final List<FirewallRuleVO> fwdRules = new ArrayList<FirewallRuleVO>(); final List<FirewallRuleVO> fwdRules = new ArrayList<FirewallRuleVO>();
final List<FirewallRuleVO> result = new ArrayList<FirewallRuleVO>(); final List<FirewallRuleVO> result = new ArrayList<FirewallRuleVO>();
@ -1734,6 +1748,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
return _routerDao.listByHostId(hostId); return _routerDao.listByHostId(hostId);
} }
@Override
public boolean updateLoadBalancerRules(final List<FirewallRuleVO> fwRules, final DomainRouterVO router, Long hostId) { public boolean updateLoadBalancerRules(final List<FirewallRuleVO> fwRules, final DomainRouterVO router, Long hostId) {
for (FirewallRuleVO rule : fwRules) { for (FirewallRuleVO rule : fwRules) {
@ -1764,6 +1779,8 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterMonitor")); _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterMonitor"));
final ComponentLocator locator = ComponentLocator.getCurrentLocator(); final ComponentLocator locator = ComponentLocator.getCurrentLocator();
_networkProfilers = locator.getAdapters(NetworkProfiler.class);
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params); final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
_routerTemplateId = NumbersUtil.parseInt(configs.get("router.template.id"), 1); _routerTemplateId = NumbersUtil.parseInt(configs.get("router.template.id"), 1);
@ -1806,7 +1823,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
_haMgr.registerHandler(VirtualMachine.Type.DomainRouter, this); _haMgr.registerHandler(VirtualMachine.Type.DomainRouter, this);
boolean useLocalStorage = Boolean.parseBoolean((String)params.get(Config.SystemVMUseLocalStorage.key())); boolean useLocalStorage = Boolean.parseBoolean((String)params.get(Config.SystemVMUseLocalStorage.key()));
_offering = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, useLocalStorage, true, null); _offering = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, useLocalStorage, true, null);
_offering.setUniqueName("Cloud.Com-SoftwareRouter"); _offering.setUniqueName("Cloud.Com-SoftwareRouter");
_offering = _serviceOfferingDao.persistSystemServiceOffering(_offering); _offering = _serviceOfferingDao.persistSystemServiceOffering(_offering);
_template = _templateDao.findById(_routerTemplateId); _template = _templateDao.findById(_routerTemplateId);
@ -1814,6 +1831,19 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
throw new ConfigurationException("Unable to find the template for the router: " + _routerTemplateId); throw new ConfigurationException("Unable to find the template for the router: " + _routerTemplateId);
} }
_publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmPublicNetwork, TrafficType.Public, null);
_publicNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_publicNetworkOffering);
_managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmManagementNetwork, TrafficType.Management, null);
_managementNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_managementNetworkOffering);
_linkLocalNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmLinkLocalNetwork, TrafficType.LinkLocal, null);
_linkLocalNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_linkLocalNetworkOffering);
_guestNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmGuestNetwork, TrafficType.Guest, GuestIpType.Virtualized);
_guestNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_guestNetworkOffering);
// FIXME: Obviously Virtualized is not the only guest network. How do we determine which one to use?
s_logger.info("Network Manager is configured."); s_logger.info("Network Manager is configured.");
return true; return true;
@ -1826,6 +1856,15 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
@Override @Override
public boolean start() { public boolean start() {
List<NetworkOfferingVO> offerings = new ArrayList<NetworkOfferingVO>(4);
offerings.add(_publicNetworkOffering);
offerings.add(_guestNetworkOffering);
offerings.add(_linkLocalNetworkOffering);
offerings.add(_managementNetworkOffering);
for (NetworkProfiler profiler : _networkProfilers) {
List<? extends NetworkProfile> profiles = profiler.convert(offerings, _accountMgr.getSystemAccount());
}
_executor.scheduleAtFixedRate(new RouterCleanupTask(), _routerCleanupInterval, _routerCleanupInterval, TimeUnit.SECONDS); _executor.scheduleAtFixedRate(new RouterCleanupTask(), _routerCleanupInterval, _routerCleanupInterval, TimeUnit.SECONDS);
_executor.scheduleAtFixedRate(new NetworkUsageTask(), _routerStatsInterval, _routerStatsInterval, TimeUnit.SECONDS); _executor.scheduleAtFixedRate(new NetworkUsageTask(), _routerStatsInterval, _routerStatsInterval, TimeUnit.SECONDS);
return true; return true;
@ -2133,6 +2172,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
public RouterCleanupTask() { public RouterCleanupTask() {
} }
@Override
public void run() { public void run() {
try { try {
final List<Long> ids = _routerDao.findLonelyRouters(); final List<Long> ids = _routerDao.findLonelyRouters();
@ -2298,6 +2338,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
public NetworkUsageTask() { public NetworkUsageTask() {
} }
@Override
public void run() { public void run() {
final List<DomainRouterVO> routers = _routerDao.listUpByHostId(null); final List<DomainRouterVO> routers = _routerDao.listUpByHostId(null);
s_logger.debug("Found " + routers.size() + " running routers. "); s_logger.debug("Found " + routers.size() + " running routers. ");

View File

@ -36,7 +36,7 @@ import com.cloud.user.OwnedBy;
* *
*/ */
@Entity @Entity
@Table(name="network_profile") @Table(name="network_profiles")
public class NetworkProfileVO implements OwnedBy { public class NetworkProfileVO implements OwnedBy {
@Id @Id
@GeneratedValue(strategy=GenerationType.IDENTITY) @GeneratedValue(strategy=GenerationType.IDENTITY)
@ -57,6 +57,9 @@ public class NetworkProfileVO implements OwnedBy {
@Enumerated(value=EnumType.STRING) @Enumerated(value=EnumType.STRING)
TrafficType trafficType; TrafficType trafficType;
@Column(name="vlanIds")
String vlanIds;
@Column(name="gateway") @Column(name="gateway")
String gateway; String gateway;
@ -66,12 +69,15 @@ public class NetworkProfileVO implements OwnedBy {
public NetworkProfileVO() { public NetworkProfileVO() {
} }
public long getId() { public NetworkProfileVO(long accountId, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType) {
return id; this.accountId = accountId;
this.trafficType = trafficType;
this.mode = mode;
this.broadcastDomainType = broadcastDomainType;
} }
public void setId(long id) { public long getId() {
this.id = id; return id;
} }
public Mode getMode() { public Mode getMode() {
@ -122,4 +128,5 @@ public class NetworkProfileVO implements OwnedBy {
public void setCidr(String cidr) { public void setCidr(String cidr) {
this.cidr = cidr; this.cidr = cidr;
} }
} }

View File

@ -0,0 +1,41 @@
/**
*
*/
package com.cloud.network;
import java.util.Collection;
import java.util.List;
import javax.ejb.Local;
import com.cloud.exception.ConflictingNetworkSettingsException;
import com.cloud.network.dao.NetworkProfileDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.user.Account;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.Inject;
import com.cloud.vm.VirtualMachine;
@Local(value=NetworkProfiler.class)
public class NetworkProfilerImpl extends AdapterBase implements NetworkProfiler {
@Inject protected NetworkProfileDao _profileDao;
protected NetworkProfilerImpl() {
super();
}
@Override
public List<? extends NetworkProfile> convert(Collection<? extends NetworkOffering> networkOfferings, Account owner) {
for (NetworkOffering offering : networkOfferings) {
}
return null;
}
@Override
public boolean check(VirtualMachine vm, ServiceOffering serviceOffering, Collection<? extends NetworkProfile> networkProfiles) throws ConflictingNetworkSettingsException {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -19,11 +19,29 @@ package com.cloud.network.dao;
import javax.ejb.Local; import javax.ejb.Local;
import com.cloud.network.Network.Mode;
import com.cloud.network.Network.TrafficType;
import com.cloud.network.NetworkProfileVO; import com.cloud.network.NetworkProfileVO;
import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@Local(value=NetworkProfileDao.class) @Local(value=NetworkProfileDao.class)
public class NetworkProfileDaoImpl extends GenericDaoBase<NetworkProfileVO, Long> { public class NetworkProfileDaoImpl extends GenericDaoBase<NetworkProfileVO, Long> implements NetworkProfileDao {
final SearchBuilder<NetworkProfileVO> ProfileSearch;
protected NetworkProfileDaoImpl() { protected NetworkProfileDaoImpl() {
super();
ProfileSearch = createSearchBuilder();
ProfileSearch.and("account", ProfileSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
ProfileSearch.and("trafficType", ProfileSearch.entity().getTrafficType(), SearchCriteria.Op.EQ);
ProfileSearch.and("cidr", ProfileSearch.entity().getCidr(), SearchCriteria.Op.EQ);
ProfileSearch.and("broadcastType", ProfileSearch.entity().getBroadcastDomainType(), SearchCriteria.Op.EQ);
}
public NetworkProfileVO findBy(TrafficType trafficType, Mode mode, long accountId) {
return null;
} }
} }

View File

@ -0,0 +1,31 @@
/**
*
*/
package com.cloud.offerings.dao;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.utils.db.GenericDao;
/**
* NetworkOfferingDao deals with searches and operations done on the
* network_offering table.
*
*/
public interface NetworkOfferingDao extends GenericDao<NetworkOfferingVO, Long> {
/**
* Returns the network offering that matches the name.
* @param name name
* @return NetworkOfferingVO
*/
NetworkOfferingVO findByName(String name);
/**
* Persists the system network offering by checking the name. If it
* is already there, then it returns the correct one in the database.
* If not, then it persists it into the database.
*
* @param offering network offering to persist if not in the database.
* @return NetworkOfferingVO backed by a row in the database
*/
NetworkOfferingVO persistSystemNetworkOffering(NetworkOfferingVO offering);
}

View File

@ -0,0 +1,51 @@
/**
*
*/
package com.cloud.offerings.dao;
import javax.ejb.Local;
import javax.persistence.EntityExistsException;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@Local(value=NetworkOfferingDao.class)
public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Long> implements NetworkOfferingDao {
SearchBuilder<NetworkOfferingVO> NameSearch;
protected NetworkOfferingDaoImpl() {
super();
NameSearch = createSearchBuilder();
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
NameSearch.done();
}
@Override
public NetworkOfferingVO findByName(String name) {
SearchCriteria<NetworkOfferingVO> sc = NameSearch.create();
sc.setParameters("name", name);
return findOneActiveBy(sc);
}
@Override
public NetworkOfferingVO persistSystemNetworkOffering(NetworkOfferingVO offering) {
assert offering.getName() != null : "how are you going to find this later if you don't set it?";
NetworkOfferingVO vo = findByName(offering.getName());
if (vo != null) {
return vo;
}
try {
vo = persist(offering);
return vo;
} catch (EntityExistsException e) {
// Assume it's conflict on unique name from two different management servers.
return findByName(offering.getName());
}
}
}

View File

@ -174,8 +174,9 @@ import com.cloud.network.security.NetworkGroupManager;
import com.cloud.network.security.NetworkGroupRulesVO; import com.cloud.network.security.NetworkGroupRulesVO;
import com.cloud.network.security.NetworkGroupVO; import com.cloud.network.security.NetworkGroupVO;
import com.cloud.network.security.dao.NetworkGroupDao; import com.cloud.network.security.dao.NetworkGroupDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offering.ServiceOffering; import com.cloud.offering.ServiceOffering;
import com.cloud.offering.ServiceOffering.GuestIpType;
import com.cloud.serializer.GsonHelper; import com.cloud.serializer.GsonHelper;
import com.cloud.server.auth.UserAuthenticator; import com.cloud.server.auth.UserAuthenticator;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
@ -2275,7 +2276,7 @@ public class ManagementServerImpl implements ManagementServer {
throw rae; throw rae;
} }
} else { } else {
if (offering.getGuestIpType() == GuestIpType.Virtualized) { if (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized) {
try { try {
externalIp = _networkMgr.assignSourceNatIpAddress(account, dc, domain, offering, startEventId); externalIp = _networkMgr.assignSourceNatIpAddress(account, dc, domain, offering, startEventId);
} catch (ResourceAllocationException rae) { } catch (ResourceAllocationException rae) {
@ -2484,12 +2485,12 @@ public class ManagementServerImpl implements ManagementServer {
} }
} }
if (offering.getGuestIpType() != GuestIpType.Virtualized) { if (offering.getGuestIpType() != NetworkOffering.GuestIpType.Virtualized) {
_networkGroupMgr.createDefaultNetworkGroup(accountId); _networkGroupMgr.createDefaultNetworkGroup(accountId);
} }
if (networkGroups != null) { if (networkGroups != null) {
if (offering.getGuestIpType() == GuestIpType.Virtualized) { if (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized) {
throw new InvalidParameterValueException("Network groups are not compatible with service offering " + offering.getName()); throw new InvalidParameterValueException("Network groups are not compatible with service offering " + offering.getName());
} }
Set<String> nameSet = new HashSet<String>(); //handle duplicate names -- allowed Set<String> nameSet = new HashSet<String>(); //handle duplicate names -- allowed
@ -2502,7 +2503,7 @@ public class ManagementServerImpl implements ManagementServer {
} }
} else { //create a default group if necessary } else { //create a default group if necessary
if (offering.getGuestIpType() != GuestIpType.Virtualized && _networkGroupsEnabled) { if (offering.getGuestIpType() != NetworkOffering.GuestIpType.Virtualized && _networkGroupsEnabled) {
networkGroups = new String[]{NetworkGroupManager.DEFAULT_GROUP_NAME}; networkGroups = new String[]{NetworkGroupManager.DEFAULT_GROUP_NAME};
} }
} }
@ -2932,7 +2933,7 @@ public class ManagementServerImpl implements ManagementServer {
// sanity check that the vm can be applied to the load balancer // sanity check that the vm can be applied to the load balancer
ServiceOfferingVO offering = _offeringsDao.findById(userVm.getServiceOfferingId()); ServiceOfferingVO offering = _offeringsDao.findById(userVm.getServiceOfferingId());
if ((offering == null) || !GuestIpType.Virtualized.equals(offering.getGuestIpType())) { if ((offering == null) || !NetworkOffering.GuestIpType.Virtualized.equals(offering.getGuestIpType())) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to apply port forwarding service to virtual machine " + userVm.toString() + ", bad network type (" + ((offering == null) ? "null" : offering.getGuestIpType()) + ")"); s_logger.debug("Unable to apply port forwarding service to virtual machine " + userVm.toString() + ", bad network type (" + ((offering == null) ? "null" : offering.getGuestIpType()) + ")");
} }
@ -3362,7 +3363,7 @@ public class ManagementServerImpl implements ManagementServer {
private FirewallRuleVO createFirewallRule(long userId, String ipAddress, UserVm userVm, String publicPort, String privatePort, String protocol, Long securityGroupId) throws NetworkRuleConflictException { private FirewallRuleVO createFirewallRule(long userId, String ipAddress, UserVm userVm, String publicPort, String privatePort, String protocol, Long securityGroupId) throws NetworkRuleConflictException {
// sanity check that the vm can be applied to the load balancer // sanity check that the vm can be applied to the load balancer
ServiceOfferingVO offering = _offeringsDao.findById(userVm.getServiceOfferingId()); ServiceOfferingVO offering = _offeringsDao.findById(userVm.getServiceOfferingId());
if ((offering == null) || !GuestIpType.Virtualized.equals(offering.getGuestIpType())) { if ((offering == null) || !NetworkOffering.GuestIpType.Virtualized.equals(offering.getGuestIpType())) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to create port forwarding rule (" + protocol + ":" + publicPort + "->" + privatePort+ ") for virtual machine " + userVm.toString() + ", bad network type (" + ((offering == null) ? "null" : offering.getGuestIpType()) + ")"); s_logger.debug("Unable to create port forwarding rule (" + protocol + ":" + publicPort + "->" + privatePort+ ") for virtual machine " + userVm.toString() + ", bad network type (" + ((offering == null) ? "null" : offering.getGuestIpType()) + ")");
} }
@ -7211,7 +7212,7 @@ public class ManagementServerImpl implements ManagementServer {
} else { } else {
// sanity check that the vm can be applied to the load balancer // sanity check that the vm can be applied to the load balancer
ServiceOfferingVO offering = _offeringsDao.findById(userVm.getServiceOfferingId()); ServiceOfferingVO offering = _offeringsDao.findById(userVm.getServiceOfferingId());
if ((offering == null) || !GuestIpType.Virtualized.equals(offering.getGuestIpType())) { if ((offering == null) || !NetworkOffering.GuestIpType.Virtualized.equals(offering.getGuestIpType())) {
// we previously added these instanceIds to the loadBalancerVMMap, so remove them here as we are rejecting the API request // we previously added these instanceIds to the loadBalancerVMMap, so remove them here as we are rejecting the API request
// without actually modifying the load balancer // without actually modifying the load balancer
_loadBalancerVMMapDao.remove(loadBalancerId, instanceIds, Boolean.TRUE); _loadBalancerVMMapDao.remove(loadBalancerId, instanceIds, Boolean.TRUE);

View File

@ -102,6 +102,7 @@ import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.Volume.MirrorState; import com.cloud.storage.Volume.MirrorState;
import com.cloud.storage.Volume.SourceType;
import com.cloud.storage.Volume.VolumeType; import com.cloud.storage.Volume.VolumeType;
import com.cloud.storage.allocator.StoragePoolAllocator; import com.cloud.storage.allocator.StoragePoolAllocator;
import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.DiskOfferingDao;
@ -233,7 +234,7 @@ public class StorageManagerImpl implements StorageManager {
long deviceId = 0; long deviceId = 0;
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
txn.start(); txn.start();
rootVol = new VolumeVO(rootDisk.getVolumeId(), VolumeType.ROOT, rootDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), rootDisk.getDiskOfferingId(), rootDisk.getSize()); rootVol = new VolumeVO(VolumeType.ROOT, rootDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), rootDisk.getDiskOfferingId(), rootDisk.getSize());
if (rootDisk.getTemplateId() != null) { if (rootDisk.getTemplateId() != null) {
rootVol.setTemplateId(rootDisk.getTemplateId()); rootVol.setTemplateId(rootDisk.getTemplateId());
} }
@ -242,7 +243,7 @@ public class StorageManagerImpl implements StorageManager {
rootVol = _volsDao.persist(rootVol); rootVol = _volsDao.persist(rootVol);
vols.add(rootVol); vols.add(rootVol);
for (DiskCharacteristics dataDisk : dataDisks) { for (DiskCharacteristics dataDisk : dataDisks) {
dataVol = new VolumeVO(dataDisk.getVolumeId(), VolumeType.DATADISK, dataDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), dataDisk.getDiskOfferingId(), dataDisk.getSize()); dataVol = new VolumeVO(VolumeType.DATADISK, dataDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), dataDisk.getDiskOfferingId(), dataDisk.getSize());
dataVol.setDeviceId(deviceId++); dataVol.setDeviceId(deviceId++);
dataVol.setInstanceId(vm.getId()); dataVol.setInstanceId(vm.getId());
dataVol = _volsDao.persist(dataVol); dataVol = _volsDao.persist(dataVol);
@ -484,7 +485,7 @@ public class StorageManagerImpl implements StorageManager {
// Create the Volume object and save it so that we can return it to the user // Create the Volume object and save it so that we can return it to the user
Account account = _accountDao.findById(accountId); Account account = _accountDao.findById(accountId);
VolumeVO volume = new VolumeVO(null, userSpecifiedName, -1, -1, -1, -1, new Long(-1), null, null, 0, Volume.VolumeType.DATADISK); VolumeVO volume = new VolumeVO(userSpecifiedName, -1, -1, -1, -1, new Long(-1), null, null, 0, Volume.VolumeType.DATADISK);
volume.setPoolId(null); volume.setPoolId(null);
volume.setDataCenterId(dc.getId()); volume.setDataCenterId(dc.getId());
volume.setPodId(null); volume.setPodId(null);
@ -499,6 +500,8 @@ public class StorageManagerImpl implements StorageManager {
volume.setInstanceId(null); volume.setInstanceId(null);
volume.setUpdated(new Date()); volume.setUpdated(new Date());
volume.setStatus(AsyncInstanceCreateStatus.Creating); volume.setStatus(AsyncInstanceCreateStatus.Creating);
volume.setSourceType(SourceType.Snapshot);
volume.setSourceId(snapshot.getId());
volume = _volsDao.persist(volume); volume = _volsDao.persist(volume);
volumeId = volume.getId(); volumeId = volume.getId();
@ -853,18 +856,24 @@ public class StorageManagerImpl implements StorageManager {
if (Storage.ImageFormat.ISO == template.getFormat()) { if (Storage.ImageFormat.ISO == template.getFormat()) {
rootVol = new VolumeVO(VolumeType.ROOT, vm.getId(), vm.getInstanceName() + "-ROOT", dc.getId(), pod.getId(), account.getId(), account.getDomainId(),(size>0)? size : diskOffering.getDiskSizeInBytes()); rootVol = new VolumeVO(VolumeType.ROOT, vm.getId(), vm.getInstanceName() + "-ROOT", dc.getId(), pod.getId(), account.getId(), account.getDomainId(),(size>0)? size : diskOffering.getDiskSizeInBytes());
rootVol.setDiskOfferingId(diskOffering.getId()); rootVol.setDiskOfferingId(diskOffering.getId());
rootVol.setSourceType(SourceType.Template);
rootVol.setSourceId(template.getId());
rootVol.setDeviceId(0l); rootVol.setDeviceId(0l);
rootVol = _volsDao.persist(rootVol); rootVol = _volsDao.persist(rootVol);
} else { } else {
rootVol = new VolumeVO(VolumeType.ROOT, vm.getId(), template.getId(), vm.getInstanceName() + "-ROOT", dc.getId(), pod.getId(), account.getId(), account.getDomainId(), offering.isRecreatable()); rootVol = new VolumeVO(VolumeType.ROOT, vm.getId(), template.getId(), vm.getInstanceName() + "-ROOT", dc.getId(), pod.getId(), account.getId(), account.getDomainId(), offering.isRecreatable());
rootVol.setDiskOfferingId(offering.getId()); rootVol.setDiskOfferingId(offering.getId());
rootVol.setTemplateId(template.getId()); rootVol.setTemplateId(template.getId());
rootVol.setSourceId(template.getId());
rootVol.setSourceType(SourceType.Template);
rootVol.setDeviceId(0l); rootVol.setDeviceId(0l);
rootVol = _volsDao.persist(rootVol); rootVol = _volsDao.persist(rootVol);
if (diskOffering != null && diskOffering.getDiskSizeInBytes() > 0) { if (diskOffering != null && diskOffering.getDiskSizeInBytes() > 0) {
dataVol = new VolumeVO(VolumeType.DATADISK, vm.getId(), vm.getInstanceName() + "-DATA", dc.getId(), pod.getId(), account.getId(), account.getDomainId(), (size>0)? size : diskOffering.getDiskSizeInBytes()); dataVol = new VolumeVO(VolumeType.DATADISK, vm.getId(), vm.getInstanceName() + "-DATA", dc.getId(), pod.getId(), account.getId(), account.getDomainId(), (size>0)? size : diskOffering.getDiskSizeInBytes());
dataVol.setDiskOfferingId(diskOffering.getId()); dataVol.setDiskOfferingId(diskOffering.getId());
dataVol.setSourceType(SourceType.DiskOffering);
dataVol.setSourceId(diskOffering.getId());
dataVol.setDeviceId(1l); dataVol.setDeviceId(1l);
dataVol = _volsDao.persist(dataVol); dataVol = _volsDao.persist(dataVol);
} }
@ -1572,7 +1581,7 @@ public class StorageManagerImpl implements StorageManager {
// Create the Volume object and save it so that we can return it to the user // Create the Volume object and save it so that we can return it to the user
Account account = _accountDao.findById(accountId); Account account = _accountDao.findById(accountId);
VolumeVO volume = new VolumeVO(null, userSpecifiedName, -1, -1, -1, -1, new Long(-1), null, null, 0, Volume.VolumeType.DATADISK); VolumeVO volume = new VolumeVO(userSpecifiedName, -1, -1, -1, -1, new Long(-1), null, null, 0, Volume.VolumeType.DATADISK);
volume.setPoolId(null); volume.setPoolId(null);
volume.setDataCenterId(dc.getId()); volume.setDataCenterId(dc.getId());
volume.setPodId(null); volume.setPodId(null);
@ -1585,6 +1594,8 @@ public class StorageManagerImpl implements StorageManager {
volume.setUpdated(new Date()); volume.setUpdated(new Date());
volume.setStatus(AsyncInstanceCreateStatus.Creating); volume.setStatus(AsyncInstanceCreateStatus.Creating);
volume.setDomainId(account.getDomainId()); volume.setDomainId(account.getDomainId());
volume.setSourceId(diskOffering.getId());
volume.setSourceType(SourceType.DiskOffering);
volume = _volsDao.persist(volume); volume = _volsDao.persist(volume);
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor(); AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();

View File

@ -32,8 +32,9 @@ import com.cloud.capacity.dao.CapacityDao;
import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO; import com.cloud.dc.HostPodVO;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offering.ServiceOffering; import com.cloud.offering.ServiceOffering;
import com.cloud.offering.ServiceOffering.GuestIpType;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.StoragePool; import com.cloud.storage.StoragePool;
@ -146,14 +147,14 @@ public class LocalStoragePoolAllocator extends FirstFitStoragePoolAllocator {
so = _offeringDao.findById(userVm.getServiceOfferingId()); so = _offeringDao.findById(userVm.getServiceOfferingId());
} else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) { } else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) {
so = new ServiceOfferingVO("Fake Offering For DomP", 1, so = new ServiceOfferingVO("Fake Offering For DomP", 1,
_proxyRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) { } else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) {
so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} else if(vm.getType() == VirtualMachine.Type.DomainRouter) { } else if(vm.getType() == VirtualMachine.Type.DomainRouter) {
so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} else { } else {
assert(false) : "Unsupported system vm type"; assert(false) : "Unsupported system vm type";
so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} }
long usedMemory = calcHostAllocatedCpuMemoryCapacity(vmOnHost, CapacityVO.CAPACITY_TYPE_MEMORY); long usedMemory = calcHostAllocatedCpuMemoryCapacity(vmOnHost, CapacityVO.CAPACITY_TYPE_MEMORY);
@ -243,14 +244,14 @@ public class LocalStoragePoolAllocator extends FirstFitStoragePoolAllocator {
so = _offeringDao.findById(userVm.getServiceOfferingId()); so = _offeringDao.findById(userVm.getServiceOfferingId());
} else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) { } else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) {
so = new ServiceOfferingVO("Fake Offering For DomP", 1, so = new ServiceOfferingVO("Fake Offering For DomP", 1,
_proxyRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) { } else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) {
so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} else if(vm.getType() == VirtualMachine.Type.DomainRouter) { } else if(vm.getType() == VirtualMachine.Type.DomainRouter) {
so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} else { } else {
assert(false) : "Unsupported system vm type"; assert(false) : "Unsupported system vm type";
so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, GuestIpType.Virtualized, false, true, null); so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null);
} }
if(capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) { if(capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) {

View File

@ -86,7 +86,8 @@ import com.cloud.network.IpAddrAllocator;
import com.cloud.network.NetworkManager; import com.cloud.network.NetworkManager;
import com.cloud.network.IpAddrAllocator.networkInfo; import com.cloud.network.IpAddrAllocator.networkInfo;
import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressDao;
import com.cloud.offering.ServiceOffering.GuestIpType; import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.StorageManager; import com.cloud.storage.StorageManager;
@ -1365,7 +1366,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
} }
boolean useLocalStorage = Boolean.parseBoolean((String)params.get(Config.SystemVMUseLocalStorage.key())); boolean useLocalStorage = Boolean.parseBoolean((String)params.get(Config.SystemVMUseLocalStorage.key()));
_serviceOffering = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, GuestIpType.Virtualized, useLocalStorage, true, null); _serviceOffering = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, useLocalStorage, true, null);
_serviceOffering.setUniqueName("Cloud.com-SecondaryStorage"); _serviceOffering.setUniqueName("Cloud.com-SecondaryStorage");
_serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering);
_template = _templateDao.findConsoleProxyTemplate(); _template = _templateDao.findConsoleProxyTemplate();

View File

@ -49,7 +49,8 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
import com.cloud.offering.ServiceOffering.GuestIpType; import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDaoImpl; import com.cloud.service.dao.ServiceOfferingDaoImpl;
import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.DiskOfferingVO;
@ -720,11 +721,11 @@ public class DatabaseConfig {
boolean ha = Boolean.parseBoolean(_currentObjectParams.get("enableHA")); boolean ha = Boolean.parseBoolean(_currentObjectParams.get("enableHA"));
boolean mirroring = Boolean.parseBoolean(_currentObjectParams.get("mirrored")); boolean mirroring = Boolean.parseBoolean(_currentObjectParams.get("mirrored"));
String guestIpType = _currentObjectParams.get("guestIpType"); String guestIpType = _currentObjectParams.get("guestIpType");
GuestIpType type = null; NetworkOffering.GuestIpType type = null;
if (guestIpType == null) { if (guestIpType == null) {
type = GuestIpType.Virtualized; type = NetworkOffering.GuestIpType.Virtualized;
} else { } else {
type = GuestIpType.valueOf(guestIpType); type = NetworkOffering.GuestIpType.valueOf(guestIpType);
} }
boolean useLocalStorage; boolean useLocalStorage;

View File

@ -33,9 +33,7 @@ import com.cloud.configuration.dao.ResourceLimitDao;
import com.cloud.domain.DomainVO; import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao; import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.InvalidParameterValueException;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.component.Inject; import com.cloud.utils.component.Inject;
import com.cloud.utils.db.Filter; import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.GlobalLock;
@ -48,8 +46,6 @@ public class AccountManagerImpl implements AccountManager {
private String _name; private String _name;
@Inject private AccountDao _accountDao; @Inject private AccountDao _accountDao;
@Inject private DomainDao _domainDao; @Inject private DomainDao _domainDao;
@Inject private UserDao _userDao;
@Inject private VMTemplateDao _templateDao;
@Inject private ResourceLimitDao _resourceLimitDao; @Inject private ResourceLimitDao _resourceLimitDao;
@Inject private ResourceCountDao _resourceCountDao; @Inject private ResourceCountDao _resourceCountDao;
private final GlobalLock m_resourceCountLock = GlobalLock.getInternLock("resource.count"); private final GlobalLock m_resourceCountLock = GlobalLock.getInternLock("resource.count");

View File

@ -21,6 +21,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ejb.Local; import javax.ejb.Local;
import javax.naming.ConfigurationException;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.network.NetworkManager; import com.cloud.network.NetworkManager;
@ -33,9 +34,11 @@ import com.cloud.utils.component.Inject;
@Local(value=VmManager.class) @Local(value=VmManager.class)
public class MauriceMoss implements VmManager { public class MauriceMoss implements VmManager {
String _name;
@Inject private StorageManager _storageMgr; @Inject private StorageManager _storageMgr;
@Inject private NetworkManager _networkMgr; @Inject private NetworkManager _networkMgr;
@Override
public VMInstanceVO allocate(VMInstanceVO vm, public VMInstanceVO allocate(VMInstanceVO vm,
ServiceOfferingVO serviceOffering, ServiceOfferingVO serviceOffering,
Long rootSize, Long rootSize,
@ -46,6 +49,7 @@ public class MauriceMoss implements VmManager {
return null; return null;
} }
@Override
public VMInstanceVO allocate(VMInstanceVO vm, public VMInstanceVO allocate(VMInstanceVO vm,
ServiceOfferingVO serviceOffering, ServiceOfferingVO serviceOffering,
Long rootSize, Long rootSize,
@ -70,16 +74,27 @@ public class MauriceMoss implements VmManager {
} }
@Override @Override
public void start() { public boolean start() {
// TODO Auto-generated method stub return true;
} }
@Override @Override
public void stop() { public boolean stop() {
// TODO Auto-generated method stub return true;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
return true;
}
@Override
public String getName() {
return _name;
} }
protected MauriceMoss() { protected MauriceMoss() {
} }
} }

View File

@ -120,8 +120,9 @@ import com.cloud.network.dao.SecurityGroupDao;
import com.cloud.network.dao.SecurityGroupVMMapDao; import com.cloud.network.dao.SecurityGroupVMMapDao;
import com.cloud.network.security.NetworkGroupManager; import com.cloud.network.security.NetworkGroupManager;
import com.cloud.network.security.NetworkGroupVO; import com.cloud.network.security.NetworkGroupVO;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offering.ServiceOffering; import com.cloud.offering.ServiceOffering;
import com.cloud.offering.ServiceOffering.GuestIpType;
import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.service.dao.ServiceOfferingDao;
@ -1176,7 +1177,7 @@ public class UserVmManagerImpl implements UserVmManager {
public void releaseGuestIpAddress(UserVmVO userVm) { public void releaseGuestIpAddress(UserVmVO userVm) {
ServiceOffering offering = _offeringDao.findById(userVm.getServiceOfferingId()); ServiceOffering offering = _offeringDao.findById(userVm.getServiceOfferingId());
if (offering.getGuestIpType() != GuestIpType.Virtualized) { if (offering.getGuestIpType() != NetworkOffering.GuestIpType.Virtualized) {
IPAddressVO guestIP = (userVm.getGuestIpAddress() == null) ? null : _ipAddressDao.findById(userVm.getGuestIpAddress()); IPAddressVO guestIP = (userVm.getGuestIpAddress() == null) ? null : _ipAddressDao.findById(userVm.getGuestIpAddress());
if (guestIP != null && guestIP.getAllocated() != null) { if (guestIP != null && guestIP.getAllocated() != null) {
_ipAddressDao.unassignIpAddress(userVm.getGuestIpAddress()); _ipAddressDao.unassignIpAddress(userVm.getGuestIpAddress());

View File

@ -25,11 +25,12 @@ import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.DiskOfferingVO;
import com.cloud.user.AccountVO; import com.cloud.user.AccountVO;
import com.cloud.utils.component.Manager;
/** /**
* Manages allocating resources to vms. * Manages allocating resources to vms.
*/ */
public interface VmManager { public interface VmManager extends Manager {
VMInstanceVO allocate(VMInstanceVO vm, VMInstanceVO allocate(VMInstanceVO vm,
ServiceOfferingVO serviceOffering, ServiceOfferingVO serviceOffering,
@ -51,10 +52,6 @@ public interface VmManager {
void create(VmCharacteristics vm, List<DiskCharacteristics> disks, List<NetworkCharacteristics> networks); void create(VmCharacteristics vm, List<DiskCharacteristics> disks, List<NetworkCharacteristics> networks);
void start();
void stop();
void destroy(); void destroy();
} }

View File

@ -114,12 +114,16 @@ CREATE TABLE `cloud`.`nics` (
CREATE TABLE `cloud`.`network_offerings` ( CREATE TABLE `cloud`.`network_offerings` (
`id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id', `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id',
`name` varchar(64) NOT NULL COMMENT 'network offering', `name` varchar(64) NOT NULL unique COMMENT 'network offering',
`type` varchar(32) NOT NULL COMMENT 'type of network', `type` varchar(32) NOT NULL COMMENT 'type of network',
`display_text` varchar(255) NOT NULL COMMENT 'text to display to users', `display_text` varchar(255) NOT NULL COMMENT 'text to display to users',
`nw_rate` smallint unsigned default 200 COMMENT 'network rate throttle mbits/s', `nw_rate` smallint unsigned COMMENT 'network rate throttle mbits/s',
`mc_rate` smallint unsigned default 10 COMMENT 'mcast rate throttle mbits/s', `mc_rate` smallint unsigned COMMENT 'mcast rate throttle mbits/s',
`concurrent_connections` smallint unsigned COMMENT 'concurrent connections supported on this network', `concurrent_connections` int(10) unsigned COMMENT 'concurrent connections supported on this network',
`traffic_type` varchar(32) NOT NULL COMMENT 'traffic type carried on this network',
`created` datetime NOT NULL COMMENT 'time the entry was created',
`removed` datetime DEFAULT NULL COMMENT 'time the entry was removed',
`system_only` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Is this network offering for system use only',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -250,6 +254,8 @@ CREATE TABLE `cloud`.`volumes` (
`removed` datetime COMMENT 'Date removed. not null if removed', `removed` datetime COMMENT 'Date removed. not null if removed',
`status` varchar(32) COMMENT 'Async API volume creation status', `status` varchar(32) COMMENT 'Async API volume creation status',
`state` varchar(32) COMMENT 'State machine', `state` varchar(32) COMMENT 'State machine',
`source_id` bigint unsigned COMMENT 'id for the source',
`source_type` varchar(32) COMMENT 'source from which the volume is created -- snapshot, diskoffering, template, blank',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -7,3 +7,5 @@ ALTER TABLE `cloud`.`data_center` MODIFY COLUMN `guest_network_cidr` varchar(18)
ALTER TABLE `cloud`.`resource_count` ADD COLUMN `domain_id` bigint unsigned; -- add the new column ALTER TABLE `cloud`.`resource_count` ADD COLUMN `domain_id` bigint unsigned; -- add the new column
ALTER TABLE `cloud`.`resource_count` MODIFY COLUMN `account_id` bigint unsigned; -- modify the column to allow NULL values ALTER TABLE `cloud`.`resource_count` MODIFY COLUMN `account_id` bigint unsigned; -- modify the column to allow NULL values
ALTER TABLE `cloud`.`storage_pool` add COLUMN STATUS varchar(32) not null; -- new status column for maintenance mode support for primary storage ALTER TABLE `cloud`.`storage_pool` add COLUMN STATUS varchar(32) not null; -- new status column for maintenance mode support for primary storage
ALTER TABLE `cloud`.`volumes` ADD COLUMN `source_id` bigint unsigned; -- id for the source
ALTER TABLE `cloud`.`volumes` ADD COLUMN `source_type` varchar(32); --source from which the volume is created i.e. snapshot, diskoffering, template, blank

View File

@ -26,7 +26,7 @@ import java.util.Iterator;
* *
* Why the heck didn't Iterator extend from Enumeration, I will probably never know. Tell me Lee Boyton! * Why the heck didn't Iterator extend from Enumeration, I will probably never know. Tell me Lee Boyton!
**/ **/
public class EnumerationImpl<T> implements Enumeration<T> { public class EnumerationImpl<T> implements Enumeration<T>, Iterator<T> {
Iterator<T> _it; Iterator<T> _it;
// Can't use this. // Can't use this.
@ -37,11 +37,28 @@ public class EnumerationImpl<T> implements Enumeration<T> {
_it = it; _it = it;
} }
@Override
public boolean hasMoreElements() { public boolean hasMoreElements() {
return _it.hasNext(); return _it.hasNext();
} }
@Override
public T nextElement() { public T nextElement() {
return _it.next(); return _it.next();
} }
@Override
public boolean hasNext() {
return _it.hasNext();
}
@Override
public T next() {
return _it.next();
}
@Override
public void remove() {
throw new UnsupportedOperationException("Enumerations do not support remove operation");
}
} }

View File

@ -55,4 +55,5 @@ public interface SerialVersionUID {
public static final long StorageUnavailableException = Base | 0x19; public static final long StorageUnavailableException = Base | 0x19;
public static final long InfficientVirtualNetworkCapacityException = Base | 0x1a; public static final long InfficientVirtualNetworkCapacityException = Base | 0x1a;
public static final long DiscoveryException = Base | 0x1b; public static final long DiscoveryException = Base | 0x1b;
public static final long ConflictingNetworkSettingException = Base | 0x1c;
} }

View File

@ -18,6 +18,7 @@
package com.cloud.utils.component; package com.cloud.utils.component;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Iterator;
import java.util.List; import java.util.List;
import com.cloud.utils.EnumerationImpl; import com.cloud.utils.EnumerationImpl;
@ -30,7 +31,7 @@ import com.cloud.utils.EnumerationImpl;
* the iterator even during dynamic reloading. * the iterator even during dynamic reloading.
* *
**/ **/
public class Adapters<T extends Adapter> { public class Adapters<T extends Adapter> implements Iterable<T> {
private List<T> _adapters; private List<T> _adapters;
protected String _name; protected String _name;
@ -52,6 +53,11 @@ public class Adapters<T extends Adapter> {
return new EnumerationImpl<T>(_adapters.iterator()); return new EnumerationImpl<T>(_adapters.iterator());
} }
@Override
public Iterator<T> iterator() {
return new EnumerationImpl<T>(_adapters.iterator());
}
protected List<T> get() { protected List<T> get() {
return _adapters; return _adapters;
} }

View File

@ -45,8 +45,11 @@ import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.TableGenerator; import javax.persistence.TableGenerator;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.Factory; import net.sf.cglib.proxy.Factory;
import net.sf.cglib.proxy.NoOp;
import net.sf.ehcache.Cache; import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element; import net.sf.ehcache.Element;
@ -126,8 +129,11 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
protected final Map<Pair<String, String>, Attribute> _allColumns; protected final Map<Pair<String, String>, Attribute> _allColumns;
protected Enhancer _enhancer; protected Enhancer _enhancer;
protected Factory _factory; protected Factory _factory;
protected Enhancer _searchEnhancer;
protected int _timeoutSeconds; protected int _timeoutSeconds;
protected final static CallbackFilter s_callbackFilter = new UpdateFilter();
protected static final String FOR_UPDATE_CLAUSE = " FOR UPDATE "; protected static final String FOR_UPDATE_CLAUSE = " FOR UPDATE ";
protected static final String SHARE_MODE_CLAUSE = " LOCK IN SHARE MODE"; protected static final String SHARE_MODE_CLAUSE = " LOCK IN SHARE MODE";
protected static final String SELECT_LAST_INSERT_ID_SQL = "SELECT LAST_INSERT_ID()"; protected static final String SELECT_LAST_INSERT_ID_SQL = "SELECT LAST_INSERT_ID()";
@ -157,9 +163,10 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
return dao; return dao;
} }
@Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <J> GenericSearchBuilder<T, J> createSearchBuilder(Class<J> resultType) { public <J> GenericSearchBuilder<T, J> createSearchBuilder(Class<J> resultType) {
final T entity = (T)_enhancer.create(); final T entity = (T)_searchEnhancer.create();
final Factory factory = (Factory)entity; final Factory factory = (Factory)entity;
GenericSearchBuilder<T, J> builder = new GenericSearchBuilder<T, J>(entity, resultType, _allAttributes); GenericSearchBuilder<T, J> builder = new GenericSearchBuilder<T, J>(entity, resultType, _allAttributes);
factory.setCallback(0, builder); factory.setCallback(0, builder);
@ -210,11 +217,18 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
_tgs.put(tg.name(), tg); _tgs.put(tg.name(), tg);
} }
Callback[] callbacks = new Callback[] { NoOp.INSTANCE, new UpdateBuilder(_allAttributes) };
_enhancer = new Enhancer(); _enhancer = new Enhancer();
_enhancer.setSuperclass(_entityBeanType); _enhancer.setSuperclass(_entityBeanType);
_enhancer.setCallback(new UpdateBuilder(_allAttributes)); _enhancer.setCallbackFilter(s_callbackFilter);
_enhancer.setCallbacks(callbacks);
_factory = (Factory)_enhancer.create(); _factory = (Factory)_enhancer.create();
_searchEnhancer = new Enhancer();
_searchEnhancer.setSuperclass(_entityBeanType);
_searchEnhancer.setCallback(new UpdateBuilder(_allAttributes));
if (s_logger.isTraceEnabled()) { if (s_logger.isTraceEnabled()) {
s_logger.trace("Select SQL: " + _partialSelectSql.first().toString()); s_logger.trace("Select SQL: " + _partialSelectSql.first().toString());
s_logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql")); s_logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql"));
@ -235,8 +249,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
@Override @DB(txn=false) @Override @DB(txn=false)
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T createForUpdate(final ID id) { public T createForUpdate(final ID id) {
final T entity = (T)_enhancer.create(); final T entity = (T)_factory.newInstance(new Callback[] {NoOp.INSTANCE, new UpdateBuilder(_allAttributes)});
final Factory factory = (Factory)entity;
if (id != null) { if (id != null) {
try { try {
_idField.set(entity, id); _idField.set(entity, id);
@ -244,7 +257,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
} catch (final IllegalAccessException e) { } catch (final IllegalAccessException e) {
} }
} }
factory.setCallback(0, new UpdateBuilder(_allAttributes));
return entity; return entity;
} }
@ -254,7 +266,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
} }
@Override @Override
@SuppressWarnings("unchecked")
public <K> K getNextInSequence(final Class<K> clazz, final String name) { public <K> K getNextInSequence(final Class<K> clazz, final String name) {
final TableGenerator tg = _tgs.get(name); final TableGenerator tg = _tgs.get(name);
assert (tg != null) : "Couldn't find Table generator using " + name; assert (tg != null) : "Couldn't find Table generator using " + name;
@ -285,6 +296,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
return searchAll(sc, filter, lock, cache); return searchAll(sc, filter, lock, cache);
} }
@Override
public List<T> searchAll(SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache) { public List<T> searchAll(SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache) {
String clause = sc != null ? sc.getWhereClause() : null; String clause = sc != null ? sc.getWhereClause() : null;
if (clause != null && clause.length() == 0) { if (clause != null && clause.length() == 0) {
@ -377,7 +389,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
final Transaction txn = Transaction.currentTxn(); final Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = s_initStmt; PreparedStatement pstmt = s_initStmt;
final List<T> result = new ArrayList<T>();
try { try {
pstmt = txn.prepareAutoCloseStatement(sql); pstmt = txn.prepareAutoCloseStatement(sql);
int i = 0; int i = 0;
@ -398,7 +409,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
} }
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
SelectType st = sc.getSelectType(); SelectType st = sc.getSelectType();
ResultSetMetaData md = rs.getMetaData();
ArrayList<M> results = new ArrayList<M>(); ArrayList<M> results = new ArrayList<M>();
List<Field> fields = sc.getSelectFields(); List<Field> fields = sc.getSelectFields();
while (rs.next()) { while (rs.next()) {
@ -505,8 +515,8 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
final Enumerated enumerated = field.getAnnotation(Enumerated.class); final Enumerated enumerated = field.getAnnotation(Enumerated.class);
final EnumType enumType = (enumerated == null) ? EnumType.STRING : enumerated.value(); final EnumType enumType = (enumerated == null) ? EnumType.STRING : enumerated.value();
final Enum[] enums = (Enum[])field.getType().getEnumConstants(); final Enum<?>[] enums = (Enum<?>[])field.getType().getEnumConstants();
for (final Enum e : enums) { for (final Enum<?> e : enums) {
if ((enumType == EnumType.STRING && e.name().equalsIgnoreCase(rs.getString(index))) || if ((enumType == EnumType.STRING && e.name().equalsIgnoreCase(rs.getString(index))) ||
(enumType == EnumType.ORDINAL && e.ordinal() == rs.getInt(index))) { (enumType == EnumType.ORDINAL && e.ordinal() == rs.getInt(index))) {
field.set(entity, e); field.set(entity, e);
@ -626,7 +636,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
@DB(txn=false) @DB(txn=false)
protected int update(final ID id, final UpdateBuilder ub) { protected int update(final ID id, final UpdateBuilder ub) {
SearchCriteria sc = createSearchCriteria(); SearchCriteria<T> sc = createSearchCriteria();
sc.addAnd(_idAttributes.get(_table)[0], SearchCriteria.Op.EQ, id); sc.addAnd(_idAttributes.get(_table)[0], SearchCriteria.Op.EQ, id);
int rowsUpdated = update(ub, sc, null); int rowsUpdated = update(ub, sc, null);
if (_cache != null) { if (_cache != null) {
@ -761,7 +771,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
} }
@Override @DB(txn=false) @Override @DB(txn=false)
@SuppressWarnings("unchecked")
public T findById(final ID id, boolean fresh) { public T findById(final ID id, boolean fresh) {
if(!fresh) if(!fresh)
return findById(id); return findById(id);
@ -801,6 +810,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
return acquire(id, _timeoutSeconds); return acquire(id, _timeoutSeconds);
} }
@Override
public T acquire(final ID id, int seconds) { public T acquire(final ID id, int seconds) {
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
T t = null; T t = null;
@ -941,6 +951,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
} }
// FIXME: Does not work for joins. // FIXME: Does not work for joins.
@Override
public int delete(final SearchCriteria<T> sc) { public int delete(final SearchCriteria<T> sc) {
final StringBuilder str = new StringBuilder("DELETE FROM "); final StringBuilder str = new StringBuilder("DELETE FROM ");
str.append(_table); str.append(_table);
@ -1176,7 +1187,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
if (type == EnumType.STRING) { if (type == EnumType.STRING) {
pstmt.setString(j, value == null ? null : value.toString()); pstmt.setString(j, value == null ? null : value.toString());
} else if (type == EnumType.ORDINAL) { } else if (type == EnumType.ORDINAL) {
pstmt.setInt(j, value == null ? null : ((Enum)value).ordinal()); pstmt.setInt(j, value == null ? null : ((Enum<?>)value).ordinal());
} }
} else if (attr.field.getType() == byte[].class) { } else if (attr.field.getType() == byte[].class) {
pstmt.setBytes(j, (byte[])value); pstmt.setBytes(j, (byte[])value);
@ -1204,7 +1215,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
@SuppressWarnings("unchecked") @DB(txn=false) @SuppressWarnings("unchecked") @DB(txn=false)
protected T toEntityBean(final ResultSet result, final boolean cache) throws SQLException { protected T toEntityBean(final ResultSet result, final boolean cache) throws SQLException {
final T entity = (T)_factory.newInstance(new UpdateBuilder(_allAttributes)); final T entity = (T)_factory.newInstance(new Callback[] {NoOp.INSTANCE, new UpdateBuilder(_allAttributes)});
toEntityBean(result, entity); toEntityBean(result, entity);
@ -1341,13 +1352,13 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
public static <T> UpdateBuilder getUpdateBuilder(final T entityObject) { public static <T> UpdateBuilder getUpdateBuilder(final T entityObject) {
final Factory factory = (Factory)entityObject; final Factory factory = (Factory)entityObject;
assert(factory != null); assert(factory != null);
return (UpdateBuilder)factory.getCallback(0); return (UpdateBuilder)factory.getCallback(1);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @DB(txn=false) @Override @DB(txn=false)
public SearchBuilder<T> createSearchBuilder() { public SearchBuilder<T> createSearchBuilder() {
final T entity = (T)_enhancer.create(); final T entity = (T)_searchEnhancer.create();
final Factory factory = (Factory)entity; final Factory factory = (Factory)entity;
SearchBuilder<T> builder = new SearchBuilder<T>(entity, _allAttributes); SearchBuilder<T> builder = new SearchBuilder<T>(entity, _allAttributes);
factory.setCallback(0, builder); factory.setCallback(0, builder);

View File

@ -18,16 +18,13 @@
package com.cloud.utils.db; package com.cloud.utils.db;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy; import net.sf.cglib.proxy.MethodProxy;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary; import com.cloud.utils.Ternary;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
@ -40,6 +37,7 @@ public class UpdateBuilder implements MethodInterceptor {
_changes = new HashMap<String, Ternary<Attribute, Boolean, Object>>(); _changes = new HashMap<String, Ternary<Attribute, Boolean, Object>>();
} }
@Override
public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
String name = method.getName(); String name = method.getName();
if (name.startsWith("set")) { if (name.startsWith("set")) {
@ -125,7 +123,6 @@ public class UpdateBuilder implements MethodInterceptor {
} }
public StringBuilder toSql(String tables) { public StringBuilder toSql(String tables) {
List<Pair<Attribute, Object>> setters = new ArrayList<Pair<Attribute, Object>>();
if (_changes.isEmpty()) { if (_changes.isEmpty()) {
return null; return null;
} }

View File

@ -0,0 +1,16 @@
/**
*
*/
package com.cloud.utils.db;
import java.lang.reflect.Method;
import net.sf.cglib.proxy.CallbackFilter;
public class UpdateFilter implements CallbackFilter {
@Override
public int accept(Method method) {
String name = method.getName();
return (name.startsWith("set") || name.startsWith("incr") || name.startsWith("decr")) ? 1 : 0;
}
}