diff --git a/api/src/com/cloud/network/NetworkConfiguration.java b/api/src/com/cloud/network/NetworkConfiguration.java index 25d125bc878..afb1a437ba6 100644 --- a/api/src/com/cloud/network/NetworkConfiguration.java +++ b/api/src/com/cloud/network/NetworkConfiguration.java @@ -6,11 +6,10 @@ package com.cloud.network; import java.util.List; import java.util.Set; -import com.cloud.domain.PartOf; +import com.cloud.acl.ControlledEntity; import com.cloud.network.Network.BroadcastDomainType; import com.cloud.network.Network.Mode; import com.cloud.network.Network.TrafficType; -import com.cloud.user.OwnedBy; import com.cloud.utils.fsm.FiniteState; import com.cloud.utils.fsm.StateMachine; @@ -18,7 +17,7 @@ import com.cloud.utils.fsm.StateMachine; * A NetworkProfile defines the specifics of a network * owned by an account. */ -public interface NetworkConfiguration extends OwnedBy, PartOf { +public interface NetworkConfiguration extends ControlledEntity { enum Event { ImplementNetwork, DestroyNetwork; @@ -73,7 +72,7 @@ public interface NetworkConfiguration extends OwnedBy, PartOf { /** * @return id of the network profile. Null means the network profile is not from the database. */ - Long getId(); + long getId(); Mode getMode(); diff --git a/core/src/com/cloud/service/ServiceOfferingVO.java b/core/src/com/cloud/service/ServiceOfferingVO.java index d5d4b4d7ce6..d7983af7a9d 100644 --- a/core/src/com/cloud/service/ServiceOfferingVO.java +++ b/core/src/com/cloud/service/ServiceOfferingVO.java @@ -62,8 +62,8 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering super(); } - 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); + 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, boolean systemUse) { + super(name, displayText, false, tags, recreatable, useLocalStorage, systemUse); this.cpu = cpu; this.ramSize = ramSize; this.speed = speed; @@ -124,7 +124,8 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering this.rateMbps = rateMbps; } - public int getRateMbps() { + @Override + public int getRateMbps() { return rateMbps; } @@ -132,7 +133,8 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering this.multicastRateMbps = multicastRateMbps; } - public int getMulticastRateMbps() { + @Override + public int getMulticastRateMbps() { return multicastRateMbps; } @@ -140,7 +142,8 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering this.guestIpType = guestIpType; } - public NetworkOffering.GuestIpType getGuestIpType() { + @Override + public NetworkOffering.GuestIpType getGuestIpType() { return guestIpType; } } diff --git a/core/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java b/core/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java index d01f9384048..7d73f09161c 100644 --- a/core/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java +++ b/core/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java @@ -21,6 +21,7 @@ package com.cloud.service.dao; import java.util.List; import javax.ejb.Local; +import javax.persistence.EntityExistsException; import org.apache.log4j.Logger; @@ -29,7 +30,6 @@ import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.Transaction; @Local(value={ServiceOfferingDao.class}) @DB(txn=false) public class ServiceOfferingDaoImpl extends GenericDaoBase implements ServiceOfferingDao { @@ -41,7 +41,7 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase sc = UniqueNameSearch.create(); sc.setParameters("name", name); - List vos = searchIncludingRemoved(sc, null, null, false); + sc.setParameters("system", true); + List vos = search(sc, null, null, false); if (vos.size() == 0) { return null; } @@ -64,14 +65,9 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase details, boolean old) { + protected AgentAttache handleDirectConnect(ServerResource resource, StartupCommand[] startup, Map details, boolean old) throws ConnectionException { if (startup == null) { return null; } @@ -1043,7 +1043,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { return true; } - protected AgentAttache notifyMonitorsOfConnection(AgentAttache attache, final StartupCommand[] cmd) { + protected AgentAttache notifyMonitorsOfConnection(AgentAttache attache, final StartupCommand[] cmd) throws ConnectionException { long hostId = attache.getId(); HostVO host = _hostDao.findById(hostId); for (Pair monitor : _hostMonitors) { @@ -1057,11 +1057,12 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { if (e.isSetupError()) { s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage()); handleDisconnect(attache, Event.AgentDisconnected, false); + throw e; } else { s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage()); handleDisconnect(attache, Event.ShutdownRequested, false); + return attache; } - return null; } } } @@ -1181,12 +1182,11 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { } try { attache = handleDirectConnect(resource, cmds, details, old); - }catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { s_logger.warn("Unable to connect due to ", ex); throw ex; - } - catch (Exception e) { + } catch (Exception e) { s_logger.warn("Unable to connect due to ", e); } @@ -1788,7 +1788,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { return result; } - public AgentAttache handleConnect(final Link link, final StartupCommand[] startup) throws IllegalArgumentException { + public AgentAttache handleConnect(final Link link, final StartupCommand[] startup) throws IllegalArgumentException, ConnectionException { HostVO server = createHost(startup, null, null, false); if ( server == null ) { return null; @@ -2169,6 +2169,12 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { + request.toString() + " because of " + e.getMessage()); s_logger.warn("Unable to create attache for agent: " + request.toString(), e); response = new Response(request, new StartupAnswer((StartupCommand) cmd, e.getMessage()), _nodeId, -1); + } catch (ConnectionException e) { + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, 0, new Long(0), "Agent from " + startup.getPrivateIpAddress() + + " is unable to connect due to " + e.getMessage(), "Agent from " + startup.getPrivateIpAddress() + " is unable to connect with " + + request.toString() + " because of " + e.getMessage()); + s_logger.warn("Unable to create attache for agent: " + request.toString(), e); + response = new Response(request, new StartupAnswer((StartupCommand) cmd, e.getMessage()), _nodeId, -1); } catch (final CloudRuntimeException e) { _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, 0, new Long(0), "Agent from " + startup.getPrivateIpAddress() + " is unable to connect due to " + e.getMessage(), "Agent from " + startup.getPrivateIpAddress() + " is unable to connect with " diff --git a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java index 1b7147211df..48799318645 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java @@ -244,14 +244,14 @@ public class UserConcentratedAllocator implements PodAllocator { so = _offeringDao.findById(userVm.getServiceOfferingId()); } else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) { so = new ServiceOfferingVO("Fake Offering For DomP", 1, - _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null); + _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null, true); } else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) { - so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.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, true); } else if(vm.getType() == VirtualMachine.Type.DomainRouter) { - so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.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, true); } else { assert(false) : "Unsupported system vm type"; - so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, NetworkOffering.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, true); } if(capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) { diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 822a7cdee17..d518eed714e 100644 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -231,6 +231,8 @@ public class ApiDispatcher { throw new ServerApiException(BaseCmd.PARAM_ERROR, cause.getMessage()); } else if (cause instanceof PermissionDeniedException) { throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, cause.getMessage()); + } else if (cause instanceof ServerApiException) { + throw (ServerApiException)cause; } s_logger.warn("Exception executing method " + methodName + " for command " + cmd.getClass().getSimpleName(), ite); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Unable to execute method " + methodName + " for command " + cmd.getClass().getSimpleName() + ", internal error in the implementation."); diff --git a/server/src/com/cloud/api/commands/RebootSystemVmCmd.java b/server/src/com/cloud/api/commands/RebootSystemVmCmd.java index 6fdb823b045..b8efada7f95 100644 --- a/server/src/com/cloud/api/commands/RebootSystemVmCmd.java +++ b/server/src/com/cloud/api/commands/RebootSystemVmCmd.java @@ -20,14 +20,18 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; +import com.cloud.api.ApiDBUtils; import com.cloud.api.BaseAsyncCmd; import com.cloud.api.BaseCmd.Manager; import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.response.SuccessResponse; +import com.cloud.api.response.SystemVmResponse; import com.cloud.event.EventTypes; import com.cloud.user.Account; import com.cloud.user.UserContext; +import com.cloud.vm.ConsoleProxyVO; +import com.cloud.vm.SecondaryStorageVmVO; +import com.cloud.vm.VMInstanceVO; @Implementation(method="rebootSystemVM", manager=Manager.ManagementServer, description="Reboots a system VM.") public class RebootSystemVmCmd extends BaseAsyncCmd { @@ -80,10 +84,50 @@ public class RebootSystemVmCmd extends BaseAsyncCmd { } @Override @SuppressWarnings("unchecked") - public SuccessResponse getResponse() { - Boolean success = (Boolean)getResponseObject(); - SuccessResponse response = new SuccessResponse(); - response.setSuccess(success); + public SystemVmResponse getResponse() { + VMInstanceVO instance = (VMInstanceVO)getResponseObject(); + + SystemVmResponse response = new SystemVmResponse(); + response.setId(instance.getId()); + response.setName(instance.getName()); + response.setZoneId(instance.getDataCenterId()); + response.setZoneName(ApiDBUtils.findZoneById(instance.getDataCenterId()).getName()); + response.setPodId(instance.getPodId()); + response.setHostId(instance.getHostId()); + if (response.getHostId() != null) { + response.setHostName(ApiDBUtils.findHostById(instance.getHostId()).getName()); + } + + response.setPrivateIp(instance.getPrivateIpAddress()); + response.setPrivateMacAddress(instance.getPrivateMacAddress()); + response.setPrivateNetmask(instance.getPrivateNetmask()); + response.setTemplateId(instance.getTemplateId()); + response.setCreated(instance.getCreated()); + response.setState(instance.getState().toString()); + + if (instance instanceof SecondaryStorageVmVO) { + SecondaryStorageVmVO ssVm = (SecondaryStorageVmVO) instance; + response.setDns1(ssVm.getDns1()); + response.setDns2(ssVm.getDns2()); + response.setNetworkDomain(ssVm.getDomain()); + response.setGateway(ssVm.getGateway()); + + response.setPublicIp(ssVm.getPublicIpAddress()); + response.setPublicMacAddress(ssVm.getPublicMacAddress()); + response.setPublicNetmask(ssVm.getPublicNetmask()); + } else if (instance instanceof ConsoleProxyVO) { + ConsoleProxyVO proxy = (ConsoleProxyVO)instance; + response.setDns1(proxy.getDns1()); + response.setDns2(proxy.getDns2()); + response.setNetworkDomain(proxy.getDomain()); + response.setGateway(proxy.getGateway()); + + response.setPublicIp(proxy.getPublicIpAddress()); + response.setPublicMacAddress(proxy.getPublicMacAddress()); + response.setPublicNetmask(proxy.getPublicNetmask()); + response.setActiveViewerSessions(proxy.getActiveSession()); + } + response.setResponseName(getName()); return response; } diff --git a/server/src/com/cloud/async/executor/RebootConsoleProxyExecutor.java b/server/src/com/cloud/async/executor/RebootConsoleProxyExecutor.java index 72daedfb238..c0eccab5726 100644 --- a/server/src/com/cloud/async/executor/RebootConsoleProxyExecutor.java +++ b/server/src/com/cloud/async/executor/RebootConsoleProxyExecutor.java @@ -39,7 +39,7 @@ public class RebootConsoleProxyExecutor extends VMOperationExecutor { AsyncJobVO job = getJob(); ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer(); VMOperationParam param = gson.fromJson(job.getCmdInfo(), VMOperationParam.class); - + /* if(getSyncSource() == null) { asyncMgr.syncAsyncJobExecution(job, "ConsoleProxy", param.getVmId()); return true; @@ -58,7 +58,9 @@ public class RebootConsoleProxyExecutor extends VMOperationExecutor { e.getMessage()); } return true; - } + } + */ + return true; } public void processAnswer(VMOperationListener listener, long agentId, long seq, Answer answer) { diff --git a/server/src/com/cloud/async/executor/StopConsoleProxyExecutor.java b/server/src/com/cloud/async/executor/StopConsoleProxyExecutor.java index 311fd1b0612..e0a37614b54 100644 --- a/server/src/com/cloud/async/executor/StopConsoleProxyExecutor.java +++ b/server/src/com/cloud/async/executor/StopConsoleProxyExecutor.java @@ -39,7 +39,7 @@ public class StopConsoleProxyExecutor extends VMOperationExecutor { AsyncJobVO job = getJob(); ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer(); VMOperationParam param = gson.fromJson(job.getCmdInfo(), VMOperationParam.class); - + /* if(getSyncSource() == null) { asyncMgr.syncAsyncJobExecution(job, "ConsoleProxy", param.getVmId()); return true; @@ -58,7 +58,9 @@ public class StopConsoleProxyExecutor extends VMOperationExecutor { e.getMessage()); } return true; - } + } + */ + return true; } public void processAnswer(VMOperationListener listener, long agentId, long seq, Answer answer) { diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index ef13d04feee..6c01799e196 100644 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -182,6 +182,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { saveConfigurationEvent(userId, null, EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, "Successfully edited configuration value.", "name=" + name, "value=" + value); } + @Override public boolean updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException{ Long userId = UserContext.current().getUserId(); String name = cmd.getCfgName(); @@ -1076,7 +1077,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); NetworkOffering.GuestIpType guestIpType = useVirtualNetwork ? NetworkOffering.GuestIpType.Virtualized : NetworkOffering.GuestIpType.DirectSingle; 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, false); if ((offering = _serviceOfferingDao.persist(offering)) != null) { saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_CREATE, "Successfully created new service offering with name: " + name + ".", "soId=" + offering.getId(), "name=" + name, "numCPUs=" + cpu, "ram=" + ramSize, "cpuSpeed=" + speed, @@ -1087,6 +1088,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { } } + @Override public ServiceOfferingVO updateServiceOffering(UpdateServiceOfferingCmd cmd) { String displayText = cmd.getDisplayText(); Long id = cmd.getId(); @@ -1177,6 +1179,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { return createDiskOffering(domainId, name, description, numGibibytes, tags); } + @Override public DiskOfferingVO updateDiskOffering(UpdateDiskOfferingCmd cmd) throws InvalidParameterValueException{ Long diskOfferingId = cmd.getId(); String name = cmd.getName(); @@ -1222,6 +1225,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { } } + @Override public boolean deleteDiskOffering(DeleteDiskOfferingCmd cmd) throws InvalidParameterValueException{ Long diskOfferingId = cmd.getId(); @@ -1238,6 +1242,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { } } + @Override public boolean deleteServiceOffering(DeleteServiceOfferingCmd cmd) throws InvalidParameterValueException{ Long offeringId = cmd.getId(); @@ -1264,6 +1269,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { } } + @Override public String changePrivateIPRange(boolean add, long podId, String startIP, String endIP) throws InvalidParameterValueException { checkPrivateIpRangeErrors(podId, startIP, endIP); diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 08d2515e758..7e1156652ae 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -539,6 +539,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach } catch (ConcurrentOperationException e) { s_logger.warn("Exception while trying to start console proxy", e); return null; + } catch (ResourceUnavailableException e) { + s_logger.warn("Exception while trying to start console proxy", e); + return null; } } @@ -1486,6 +1489,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach s_logger.warn("insuffiient capacity", e); } catch (ConcurrentOperationException e) { s_logger.debug("Concurrent operation: " + e.getMessage()); + } catch (ResourceUnavailableException e) { + s_logger.debug("Concurrent operation: " + e.getMessage()); } } } @@ -2344,8 +2349,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); _networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); _multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); - _serviceOffering = new ServiceOfferingVO("Fake Offering For DomP", 1, _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, - useLocalStorage, true, null); + _serviceOffering = new ServiceOfferingVO("System Offering For Console Proxy", 1, _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, + useLocalStorage, true, null, true); _serviceOffering.setUniqueName("Cloud.com-ConsoleProxy"); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); _template = _templateDao.findConsoleProxyTemplate(); diff --git a/server/src/com/cloud/network/NetworkConfigurationVO.java b/server/src/com/cloud/network/NetworkConfigurationVO.java index 13c32de495e..d7b97eb22dd 100644 --- a/server/src/com/cloud/network/NetworkConfigurationVO.java +++ b/server/src/com/cloud/network/NetworkConfigurationVO.java @@ -111,12 +111,16 @@ public class NetworkConfigurationVO implements NetworkConfiguration { this.networkOfferingId = networkOfferingId; this.dataCenterId = dataCenterId; this.state = State.Allocated; + this.id = -1; } public NetworkConfigurationVO(long id, NetworkConfiguration that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related) { this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related); this.guruName = guruName; this.state = that.getState(); + if (state == null) { + state = State.Allocated; + } } /** @@ -134,6 +138,7 @@ public class NetworkConfigurationVO implements NetworkConfiguration { this.domainId = domainId; this.accountId = accountId; this.related = related; + this.id = id; } @Override @@ -151,7 +156,7 @@ public class NetworkConfigurationVO implements NetworkConfiguration { } @Override - public Long getId() { + public long getId() { return id; } @@ -223,6 +228,7 @@ public class NetworkConfigurationVO implements NetworkConfiguration { this.cidr = cidr; } + @Override public String getBroadcastUri() { return broadcastUri; } @@ -241,6 +247,7 @@ public class NetworkConfigurationVO implements NetworkConfiguration { return dataCenterId; } + @Override public String getDns() { return dns; } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 90c27bc4331..74cd58de7e2 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1630,7 +1630,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService { continue; } - if (config.getId() != null) { + if (config.getId() != -1) { if (config instanceof NetworkConfigurationVO) { configs.add((NetworkConfigurationVO)config); } else { @@ -2130,7 +2130,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService { Long loadBalancerId = cmd.getId(); String privatePort = cmd.getPrivatePort(); String algorithm = cmd.getAlgorithm(); - String name = cmd.getName(); + String name = cmd.getLoadBalancerName(); String description = cmd.getDescription(); Account account = UserContext.current().getAccount(); @@ -2148,7 +2148,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService { } } - Account lbOwner = _accountDao.findById(loadBalancer.getId()); + Account lbOwner = _accountDao.findById(loadBalancer.getAccountId()); if (lbOwner == null) { throw new InvalidParameterValueException("Unable to update load balancer rule, cannot find owning account"); } diff --git a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java index dff4271b733..51caec67080 100644 --- a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java +++ b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java @@ -1459,7 +1459,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); _networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); _multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); - _offering = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, useLocalStorage, true, null); + _offering = new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, useLocalStorage, true, null, true); _offering.setUniqueName("Cloud.Com-SoftwareRouter"); _offering = _serviceOfferingDao.persistSystemServiceOffering(_offering); _template = _templateDao.findRoutingTemplate(); diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 0713beef3c3..072dca0ef09 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -89,7 +89,8 @@ public class ConfigurationServerImpl implements ConfigurationServer { _domainDao = locator.getDao(DomainDao.class); } - public void persistDefaultValues() throws InvalidParameterValueException, InternalErrorException { + @Override + public void persistDefaultValues() throws InvalidParameterValueException, InternalErrorException { // Create system user and admin user saveUser(); @@ -653,7 +654,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); NetworkOffering.GuestIpType guestIpType = useVirtualNetwork ? NetworkOffering.GuestIpType.Virtualized : NetworkOffering.GuestIpType.DirectSingle; 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, false); if ((offering = _serviceOfferingDao.persist(offering)) != null) { return offering; diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index 8ac62e001f1..704f3f74456 100755 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -787,14 +787,14 @@ public interface ManagementServer { ConsoleProxyInfo getConsoleProxy(long dataCenterId, long userVmId); ConsoleProxyVO startConsoleProxy(long instanceId, long startEventId) throws InternalErrorException; - boolean stopConsoleProxy(long instanceId, long startEventId); - boolean rebootConsoleProxy(long instanceId, long startEventId); + ConsoleProxyVO stopConsoleProxy(long instanceId, long startEventId); + ConsoleProxyVO rebootConsoleProxy(long instanceId, long startEventId); String getConsoleAccessUrlRoot(long vmId); ConsoleProxyVO findConsoleProxyById(long instanceId); VMInstanceVO findSystemVMById(long instanceId); VMInstanceVO stopSystemVM(StopSystemVmCmd cmd); VMInstanceVO startSystemVM(StartSystemVMCmd cmd) throws InternalErrorException; - boolean rebootSystemVM(RebootSystemVmCmd cmd); + VMInstanceVO rebootSystemVM(RebootSystemVmCmd cmd); /** * Returns a configuration value with the specified name diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index dbd6b488b0b..a454904c77d 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -26,7 +26,6 @@ import java.net.URLEncoder; import java.net.UnknownHostException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.security.cert.Certificate; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -146,10 +145,8 @@ import com.cloud.async.AsyncJobResult; import com.cloud.async.AsyncJobVO; import com.cloud.async.BaseAsyncJobExecutor; import com.cloud.async.dao.AsyncJobDao; -import com.cloud.async.executor.ExtractJobResultObject; import com.cloud.capacity.CapacityVO; import com.cloud.capacity.dao.CapacityDao; -import com.cloud.certificate.CertificateVO; import com.cloud.certificate.dao.CertificateDao; import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; @@ -228,7 +225,6 @@ import com.cloud.storage.GuestOSCategoryVO; import com.cloud.storage.GuestOSVO; import com.cloud.storage.LaunchPermissionVO; import com.cloud.storage.Snapshot; -import com.cloud.storage.Upload; import com.cloud.storage.Snapshot.SnapshotType; import com.cloud.storage.SnapshotPolicyVO; import com.cloud.storage.SnapshotVO; @@ -238,6 +234,7 @@ import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePoolHostVO; import com.cloud.storage.StoragePoolVO; import com.cloud.storage.StorageStats; +import com.cloud.storage.Upload; import com.cloud.storage.Upload.Mode; import com.cloud.storage.Upload.Type; import com.cloud.storage.UploadVO; @@ -308,7 +305,6 @@ import com.cloud.vm.UserVmManager; import com.cloud.vm.UserVmVO; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachineName; import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.InstanceGroupDao; @@ -2781,6 +2777,7 @@ public class ManagementServerImpl implements ManagementServer { if (name != null) { sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); } + sc.addAnd("systemUse", SearchCriteria.Op.EQ, false); return _offeringsDao.search(sc, searchFilter); } @@ -4702,13 +4699,15 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public boolean stopConsoleProxy(long instanceId, long startEventId) { - return _consoleProxyMgr.stopProxy(instanceId, startEventId); + public ConsoleProxyVO stopConsoleProxy(long instanceId, long startEventId) { + _consoleProxyMgr.stopProxy(instanceId, startEventId); + return _consoleProxyDao.findById(instanceId); } @Override - public boolean rebootConsoleProxy(long instanceId, long startEventId) { - return _consoleProxyMgr.rebootProxy(instanceId, startEventId); + public ConsoleProxyVO rebootConsoleProxy(long instanceId, long startEventId) { + _consoleProxyMgr.rebootProxy(instanceId, startEventId); + return _consoleProxyDao.findById(instanceId); } @Override @@ -5193,7 +5192,7 @@ public class ManagementServerImpl implements ManagementServer { if (accountId != null) { sc.setParameters("accountId", accountId); } else if (domainId != null) { - DomainVO domain = _domainDao.findById((Long)domainId); + DomainVO domain = _domainDao.findById(domainId); SearchCriteria joinSearch = sc.getJoin("accountSearch"); joinSearch.setJoinParameters("domainSearch", "path", domain.getPath() + "%"); } @@ -6277,12 +6276,14 @@ public class ManagementServerImpl implements ManagementServer { return _secStorageVmMgr.startSecStorageVm(instanceId, startEventId); } - public boolean stopSecondaryStorageVm(long instanceId, long startEventId) { - return _secStorageVmMgr.stopSecStorageVm(instanceId, startEventId); + public SecondaryStorageVmVO stopSecondaryStorageVm(long instanceId, long startEventId) { + _secStorageVmMgr.stopSecStorageVm(instanceId, startEventId); + return _secStorageVmDao.findById(instanceId); } - public boolean rebootSecondaryStorageVm(long instanceId, long startEventId) { - return _secStorageVmMgr.rebootSecStorageVm(instanceId, startEventId); + public SecondaryStorageVmVO rebootSecondaryStorageVm(long instanceId, long startEventId) { + _secStorageVmMgr.rebootSecStorageVm(instanceId, startEventId); + return _secStorageVmDao.findById(instanceId); } public boolean destroySecondaryStorageVm(long instanceId, long startEventId) { @@ -6406,17 +6407,15 @@ public class ManagementServerImpl implements ManagementServer { // FIXME: We need to return the system VM from this method, so what do we do with the boolean response from stopConsoleProxy and stopSecondaryStorageVm? if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_STOP, "stopping console proxy with Id: "+id); - stopConsoleProxy(id, eventId); + return stopConsoleProxy(id, eventId); } else { long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP, "stopping secondary storage Vm Id: "+id); - stopSecondaryStorageVm(id, eventId); + return stopSecondaryStorageVm(id, eventId); } - - return systemVm; } @Override - public boolean rebootSystemVM(RebootSystemVmCmd cmd) { + public VMInstanceVO rebootSystemVM(RebootSystemVmCmd cmd) { VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(cmd.getId(), VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); if (systemVm == null) { diff --git a/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java index ed0b313c223..7fbd25a1e87 100644 --- a/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java +++ b/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java @@ -146,14 +146,14 @@ public class LocalStoragePoolAllocator extends FirstFitStoragePoolAllocator { so = _offeringDao.findById(userVm.getServiceOfferingId()); } else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) { so = new ServiceOfferingVO("Fake Offering For DomP", 1, - _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null); + _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null, true); } else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) { - so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.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, true); } else if(vm.getType() == VirtualMachine.Type.DomainRouter) { - so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.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, true); } else { assert(false) : "Unsupported system vm type"; - so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, NetworkOffering.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, false); } long usedMemory = calcHostAllocatedCpuMemoryCapacity(vmOnHost, CapacityVO.CAPACITY_TYPE_MEMORY); @@ -243,14 +243,14 @@ public class LocalStoragePoolAllocator extends FirstFitStoragePoolAllocator { so = _offeringDao.findById(userVm.getServiceOfferingId()); } else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) { so = new ServiceOfferingVO("Fake Offering For DomP", 1, - _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null); + _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, false, true, null, true); } else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) { - so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.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, true); } else if(vm.getType() == VirtualMachine.Type.DomainRouter) { - so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.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, true); } else { assert(false) : "Unsupported system vm type"; - so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, NetworkOffering.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, false); } if(capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) { diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 3bb5b1fde62..c3b51cb349f 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -1390,7 +1390,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); _networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); _multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); - _serviceOffering = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, useLocalStorage, true, null); + _serviceOffering = new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtualized, useLocalStorage, true, null, true); _serviceOffering.setUniqueName("Cloud.com-SecondaryStorage"); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); _template = _templateDao.findConsoleProxyTemplate(); diff --git a/server/src/com/cloud/test/DatabaseConfig.java b/server/src/com/cloud/test/DatabaseConfig.java index 828abf33f17..47bbcfc3540 100644 --- a/server/src/com/cloud/test/DatabaseConfig.java +++ b/server/src/com/cloud/test/DatabaseConfig.java @@ -751,7 +751,7 @@ public class DatabaseConfig { useLocalStorage = false; } - ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, nwRate, mcRate, ha, displayText, type, useLocalStorage, false, null); + ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, nwRate, mcRate, ha, displayText, type, useLocalStorage, false, null, false); ServiceOfferingDaoImpl dao = ComponentLocator.inject(ServiceOfferingDaoImpl.class); try { dao.persist(serviceOffering); diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 64b7d3f09e1..e589b3bd2ce 100644 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -591,16 +591,21 @@ public class AccountManagerImpl implements AccountManager { @Override public void checkAccess(Account caller, ControlledEntity... entities) { for (ControlledEntity entity : entities) { + boolean granted = false; for (SecurityChecker checker : _securityCheckers) { if (checker.checkAccess(caller, entity)) { if (s_logger.isDebugEnabled()) { s_logger.debug("Access to " + entity + " granted to " + caller + " by " + checker.getName()); } + granted = true; + break; } } - assert false : "How can all of the security checkers pass on checking this check?"; - throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to " + entity); + if (!granted) { + assert false : "How can all of the security checkers pass on checking this check: " + entity; + throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to " + entity); + } } } } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 3f2b97dff4d..e91c6994445 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -104,6 +104,9 @@ CREATE TABLE `cloud`.`network_configurations` ( `data_center_id` bigint unsigned NOT NULL COMMENT 'data center id that this configuration is used in', `guru_name` varchar(255) NOT NULL COMMENT 'who is responsible for this type of network configuration', `state` varchar(32) NOT NULL COMMENT 'what state is this configuration in', + `related` bigint unsigned NOT NULL COMMENT 'related to what other network configuration', + `domain_id` bigint unsigned NOT NULL COMMENT 'foreign key to domain id', + `account_id` bigint unsigned NOT NULL COMMENT 'owner of this network', `mac_address_seq` bigint unsigned DEFAULT 1 COMMENT 'mac address seq number', `dns` varchar(255) COMMENT 'comma separated DNS list', PRIMARY KEY (`id`) @@ -113,6 +116,7 @@ CREATE TABLE `cloud`.`account_network_ref` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', `account_id` bigint unsigned NOT NULL COMMENT 'account id', `network_configuration_id` bigint unsigned NOT NULL COMMENT 'network configuration id', + `is_owner` smallint(1) NOT NULL COMMENT 'is the owner of the network', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -859,7 +863,7 @@ CREATE TABLE `cloud`.`disk_offering` ( `id` bigint unsigned NOT NULL auto_increment, `domain_id` bigint unsigned, `name` varchar(255) NOT NULL, - `display_text` varchar(4096) NULL COMMENT 'Description text set by the admin for display purpose only', + `display_text` varchar(4096) NULL COMMENT 'Descrianaption text set by the admin for display purpose only', `disk_size` bigint unsigned NOT NULL COMMENT 'disk space in mbs', `mirrored` tinyint(1) unsigned NOT NULL DEFAULT 1 COMMENT 'Enable mirroring?', `type` varchar(32) COMMENT 'inheritted by who?', @@ -867,6 +871,7 @@ CREATE TABLE `cloud`.`disk_offering` ( `recreatable` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'The root disk is always recreatable', `use_local_storage` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Indicates whether local storage pools should be used', `unique_name` varchar(32) UNIQUE COMMENT 'unique name', + `system_use` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'is this offering for system used only', `removed` datetime COMMENT 'date removed', `created` datetime COMMENT 'date the disk offering was created', PRIMARY KEY (`id`) diff --git a/utils/src/com/cloud/utils/db/GenericDaoBase.java b/utils/src/com/cloud/utils/db/GenericDaoBase.java index c7afc81eac6..53df12503e4 100755 --- a/utils/src/com/cloud/utils/db/GenericDaoBase.java +++ b/utils/src/com/cloud/utils/db/GenericDaoBase.java @@ -693,7 +693,7 @@ public abstract class GenericDaoBase implements Gene ub.clear(); return result; } catch (final SQLException e) { - if (e.getSQLState().equals("23000")) { + if (e.getSQLState().equals("23000") && e.getErrorCode() == 1062) { throw new EntityExistsException("Entity already exists ", e); } final String sqlStr = pstmt.toString(); @@ -1129,7 +1129,7 @@ public abstract class GenericDaoBase implements Gene } txn.commit(); } catch (final SQLException e) { - if (e.getSQLState().equals("23000")) { + if (e.getSQLState().equals("23000") && e.getErrorCode() == 1062) { throw new EntityExistsException("Entity already exists: ", e); } else { final String sqlStr = pstmt.toString();