diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java index b04ca6c2d9b..9c9c751335c 100644 --- a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java +++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java @@ -198,7 +198,9 @@ public class TemplateObject implements TemplateInfo { templateStoreRef.setDownloadPercent(100); templateStoreRef.setDownloadState(Status.DOWNLOADED); templateStoreRef.setSize(newTemplate.getSize()); - templateStoreRef.setPhysicalSize(newTemplate.getPhysicalSize()); + if (newTemplate.getPhysicalSize() != null) { + templateStoreRef.setPhysicalSize(newTemplate.getPhysicalSize()); + } templateStoreDao.update(templateStoreRef.getId(), templateStoreRef); if (this.getDataStore().getRole() == DataStoreRole.Image) { VMTemplateVO templateVO = this.imageDao.findById(this.getId()); diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index fd282592149..aa4aa523b92 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -155,7 +155,7 @@ import com.cloud.vm.dao.VMInstanceDao; // @Local(value = { ConsoleProxyManager.class, ConsoleProxyService.class }) public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxyManager, - VirtualMachineGuru, SystemVmLoadScanHandler, ResourceStateAdapter { +VirtualMachineGuru, SystemVmLoadScanHandler, ResourceStateAdapter { private static final Logger s_logger = Logger.getLogger(ConsoleProxyManagerImpl.class); private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30 seconds @@ -558,7 +558,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy // For VMs that are in Stopping, Starting, Migrating state, let client to wait by returning null // as sooner or later, Starting/Migrating state will be transited to Running and Stopping will be transited -// to + // to // Stopped to allow // Starting of it s_logger.warn("Console proxy is not in correct state to be started: " + proxy.getState()); @@ -661,7 +661,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId); template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor); if (template == null) { - throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId); + throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId); } Map context = createProxyInstance(dataCenterId, template); @@ -707,18 +707,18 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } defaultNetwork = networks.get(0); } else { - TrafficType defaultTrafficType = TrafficType.Public; - if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) { - defaultTrafficType = TrafficType.Guest; - } - List defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType); + TrafficType defaultTrafficType = TrafficType.Public; + if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) { + defaultTrafficType = TrafficType.Guest; + } + List defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType); // api should never allow this situation to happen - if (defaultNetworks.size() != 1) { + if (defaultNetworks.size() != 1) { throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " - + defaultTrafficType + " when expect to find 1"); + + defaultTrafficType + " when expect to find 1"); } - defaultNetwork = defaultNetworks.get(0); + defaultNetwork = defaultNetworks.get(0); } List offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork); @@ -951,7 +951,13 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId); if (zoneHostInfo != null && isZoneHostReady(zoneHostInfo)) { VMTemplateVO template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any); - TemplateDataStoreVO templateHostRef = _vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dataCenterId, + if (template == null) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("System vm template is not ready at data center " + dataCenterId + ", wait until it is ready to launch console proxy vm"); + } + return false; + } + TemplateDataStoreVO templateHostRef = this._vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dataCenterId, Status.DOWNLOADED); if (templateHostRef != null) { @@ -1282,8 +1288,9 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy String cpvmSrvcOffIdStr = configs.get(Config.ConsoleProxyServiceOffering.key()); if (cpvmSrvcOffIdStr != null) { DiskOffering diskOffering = _diskOfferingDao.findByUuid(cpvmSrvcOffIdStr); - if (diskOffering == null) + if (diskOffering == null) { diskOffering = _diskOfferingDao.findById(Long.parseLong(cpvmSrvcOffIdStr)); + } if (diskOffering != null) { _serviceOffering = _offeringDao.findById(diskOffering.getId()); } else { @@ -1517,7 +1524,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy @Override public void onScanStart() { // to reduce possible number of DB queries for capacity scan, we run following aggregated queries in preparation -// stage + // stage _zoneHostInfoMap = getZoneHostInfo(); _zoneProxyCountMap = new HashMap(); diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index fef41d8cc3c..99aad9cc40a 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -252,7 +252,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar private final GlobalLock _allocLock = GlobalLock.getInternLock(getAllocLockName()); public SecondaryStorageManagerImpl() { - _ssvmMgr = this; + _ssvmMgr = this; } @Override @@ -296,16 +296,18 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } List ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId)); - for( DataStore ssStore : ssStores ) { - if (!(ssStore.getTO() instanceof NfsTO )) - continue; // only do this for Nfs + for( DataStore ssStore : ssStores ) { + if (!(ssStore.getTO() instanceof NfsTO )) + { + continue; // only do this for Nfs + } String secUrl = ssStore.getUri(); SecStorageSetupCommand setupCmd = null; if (!_useSSlCopy) { - setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null); + setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null); } else { - Certificates certs = _keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME); - setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs); + Certificates certs = _keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME); + setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs); } Answer answer = _agentMgr.easySend(ssHostId, setupCmd); @@ -348,7 +350,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } } } - */ + */ return true; } @@ -423,9 +425,9 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar sc.addAnd(sc.getEntity().getStatus(), Op.IN, com.cloud.host.Status.Up, com.cloud.host.Status.Connecting); List ssvms = sc.list(); for (HostVO ssvm : ssvms) { - if (ssvm.getId() == ssAHostId) { - continue; - } + if (ssvm.getId() == ssAHostId) { + continue; + } Answer answer = _agentMgr.easySend(ssvm.getId(), thiscpc); if (answer != null && answer.getResult()) { if (s_logger.isDebugEnabled()) { @@ -441,10 +443,10 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar SecStorageFirewallCfgCommand allSSVMIpList = new SecStorageFirewallCfgCommand(false); for (HostVO ssvm : ssvms) { - if (ssvm.getId() == ssAHostId) { - continue; - } - allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF); + if (ssvm.getId() == ssAHostId) { + continue; + } + allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF); } Answer answer = _agentMgr.easySend(ssAHostId, allSSVMIpList); @@ -537,16 +539,16 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } defaultNetwork = networks.get(0); } else { - TrafficType defaultTrafficType = TrafficType.Public; + TrafficType defaultTrafficType = TrafficType.Public; - if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) { - defaultTrafficType = TrafficType.Guest; - } - List defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType); + if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) { + defaultTrafficType = TrafficType.Guest; + } + List defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType); // api should never allow this situation to happen - if (defaultNetworks.size() != 1) { + if (defaultNetworks.size() != 1) { throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " - + defaultTrafficType + " when expect to find 1"); + + defaultTrafficType + " when expect to find 1"); } defaultNetwork = defaultNetworks.get(0); } @@ -557,7 +559,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); try { - networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), defaultNic)); + networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), defaultNic)); for (NetworkOffering offering : offerings) { networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null)); } @@ -593,8 +595,9 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar private SecondaryStorageVmAllocator getCurrentAllocator() { // for now, only one adapter is supported - if(_ssVmAllocators.size() > 0) - return _ssVmAllocators.get(0); + if(_ssVmAllocators.size() > 0) { + return _ssVmAllocators.get(0); + } return null; } @@ -663,8 +666,9 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar if (_allocLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { secStorageVm = startNew(dataCenterId, role); - for (UploadVO upload :_uploadDao.listAll()) + for (UploadVO upload :_uploadDao.listAll()) { _uploadDao.expunge(upload.getId()); + } } finally { _allocLock.unlock(); } @@ -722,7 +726,9 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar if (zoneHostInfo != null && (zoneHostInfo.getFlags() & RunningHostInfoAgregator.ZoneHostInfo.ROUTING_HOST_MASK) != 0) { VMTemplateVO template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any); if (template == null) { - s_logger.debug("No hypervisor host added in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm"); + if (s_logger.isDebugEnabled()) { + s_logger.debug("System vm template is not ready at data center " + dataCenterId + ", wait until it is ready to launch secondary storage vm"); + } return false; } @@ -841,8 +847,8 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar throw new ConfigurationException(msg); } } else { - int ramSize = NumbersUtil.parseInt(_configDao.getValue("ssvm.ram.size"), DEFAULT_SS_VM_RAMSIZE); - int cpuFreq = NumbersUtil.parseInt(_configDao.getValue("ssvm.cpu.mhz"), DEFAULT_SS_VM_CPUMHZ); + int ramSize = NumbersUtil.parseInt(_configDao.getValue("ssvm.ram.size"), DEFAULT_SS_VM_RAMSIZE); + int cpuFreq = NumbersUtil.parseInt(_configDao.getValue("ssvm.cpu.mhz"), DEFAULT_SS_VM_CPUMHZ); _useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); _serviceOffering = new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, ramSize, cpuFreq, null, null, false, null, _useLocalStorage, true, null, true, VirtualMachine.Type.SecondaryStorageVm, true); _serviceOffering.setUniqueName(ServiceOffering.ssvmDefaultOffUniqueName); @@ -863,27 +869,27 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar _httpProxy = configs.get(Config.SecStorageProxy.key()); if (_httpProxy != null) { - boolean valid = true; - String errMsg = null; - try { - URI uri = new URI(_httpProxy); - if (!"http".equalsIgnoreCase(uri.getScheme())) { - errMsg = "Only support http proxy"; - valid = false; - } else if (uri.getHost() == null) { - errMsg = "host can not be null"; - valid = false; - } else if (uri.getPort() == -1) { - _httpProxy = _httpProxy + ":3128"; - } - } catch (URISyntaxException e) { - errMsg = e.toString(); - } finally { - if (!valid) { - s_logger.debug("ssvm http proxy " + _httpProxy + " is invalid: " + errMsg); - throw new ConfigurationException("ssvm http proxy " + _httpProxy + "is invalid: " + errMsg); - } - } + boolean valid = true; + String errMsg = null; + try { + URI uri = new URI(_httpProxy); + if (!"http".equalsIgnoreCase(uri.getScheme())) { + errMsg = "Only support http proxy"; + valid = false; + } else if (uri.getHost() == null) { + errMsg = "host can not be null"; + valid = false; + } else if (uri.getPort() == -1) { + _httpProxy = _httpProxy + ":3128"; + } + } catch (URISyntaxException e) { + errMsg = e.toString(); + } finally { + if (!valid) { + s_logger.debug("ssvm http proxy " + _httpProxy + " is invalid: " + errMsg); + throw new ConfigurationException("ssvm http proxy " + _httpProxy + "is invalid: " + errMsg); + } + } } if (s_logger.isInfoEnabled()) { s_logger.info("Secondary storage vm Manager is configured."); @@ -1040,7 +1046,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) { - buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password")); + buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password")); } for (NicProfile nic : profile.getNics()) { @@ -1066,9 +1072,9 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } else if (nic.getTrafficType() == TrafficType.Public) { buf.append(" public.network.device=").append("eth").append(deviceId); } else if (nic.getTrafficType() == TrafficType.Storage) { - buf.append(" storageip=").append(nic.getIp4Address()); - buf.append(" storagenetmask=").append(nic.getNetmask()); - buf.append(" storagegateway=").append(nic.getGateway()); + buf.append(" storageip=").append(nic.getIp4Address()); + buf.append(" storagenetmask=").append(nic.getNetmask()); + buf.append(" storagegateway=").append(nic.getGateway()); } } @@ -1272,24 +1278,24 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar public void onScanEnd() { } - @Override + @Override public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { - /* Called when Secondary Storage VM connected */ - StartupCommand firstCmd = cmd[0]; - if (!(firstCmd instanceof StartupSecondaryStorageCommand)) { - return null; - } + /* Called when Secondary Storage VM connected */ + StartupCommand firstCmd = cmd[0]; + if (!(firstCmd instanceof StartupSecondaryStorageCommand)) { + return null; + } - host.setType( com.cloud.host.Host.Type.SecondaryStorageVM); - return host; + host.setType( com.cloud.host.Host.Type.SecondaryStorageVM); + return host; } - @Override + @Override public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map details, List hostTags) { - // Used to be Called when add secondary storage on UI through DummySecondaryStorageResource to update that host entry for Secondary Storage. - // Now since we move secondary storage from host table, this code is not needed to be invoked anymore. - /* + // Used to be Called when add secondary storage on UI through DummySecondaryStorageResource to update that host entry for Secondary Storage. + // Now since we move secondary storage from host table, this code is not needed to be invoked anymore. + /* StartupCommand firstCmd = startup[0]; if (!(firstCmd instanceof StartupStorageCommand)) { return null; @@ -1329,30 +1335,30 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar host.setStorageUrl(ssCmd.getNfsShare()); } } - */ - return null; // no need to handle this event anymore since secondary storage is not in host table anymore. + */ + return null; // no need to handle this event anymore since secondary storage is not in host table anymore. } - @Override + @Override public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException { - // Since secondary storage is moved out of host table, this class should not handle delete secondary storage anymore. + // Since secondary storage is moved out of host table, this class should not handle delete secondary storage anymore. return null; } - @Override + @Override public List listUpAndConnectingSecondaryStorageVmHost(Long dcId) { - SearchCriteriaService sc = SearchCriteria2.create(HostVO.class); + SearchCriteriaService sc = SearchCriteria2.create(HostVO.class); if (dcId != null) { sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId); } sc.addAnd(sc.getEntity().getState(), Op.IN, com.cloud.host.Status.Up, com.cloud.host.Status.Connecting); - sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.SecondaryStorageVM); - return sc.list(); + sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.SecondaryStorageVM); + return sc.list(); } - @Override + @Override public HostVO pickSsvmHost(HostVO ssHost) { if( ssHost.getType() == Host.Type.LocalSecondaryStorage ) { return ssHost; @@ -1368,8 +1374,8 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar return null; } - @Override - public void prepareStop(VirtualMachineProfile profile) { + @Override + public void prepareStop(VirtualMachineProfile profile) { - } + } } diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index f2b40f2f134..30d0ff78f1a 100755 --- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -1239,20 +1239,29 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S DataStoreTO dstore = obj.getDataStore(); if (dstore instanceof NfsTO) { NfsTO nfs = (NfsTO) dstore; - String snapshotPath = obj.getPath(); - if (snapshotPath.startsWith(File.separator)) { - snapshotPath = snapshotPath.substring(1); - } - int index = snapshotPath.lastIndexOf("/"); - String snapshotName = snapshotPath.substring(index + 1); - snapshotPath = snapshotPath.substring(0, index); - String parent = getRootDir(nfs.getUrl()); if (!parent.endsWith(File.separator)) { parent += File.separator; } + String snapshotPath = obj.getPath(); + if (snapshotPath.startsWith(File.separator)) { + snapshotPath = snapshotPath.substring(1); + } + // check if the passed snapshot path is a directory or not. For ImageCache, path is stored as a directory instead of + // snapshot file name. If so, since backupSnapshot process has already deleted snapshot in cache, so we just do nothing + // and return true. + String fullSnapPath = parent + snapshotPath; + File snapDir = new File(fullSnapPath); + if (snapDir.exists() && snapDir.isDirectory()) { + s_logger.debug("snapshot path " + snapshotPath + " is a directory, already deleted during backup snapshot, so no need to delete"); + return new Answer(cmd, true, null); + } + // passed snapshot path is a snapshot file path, then get snapshot directory first + int index = snapshotPath.lastIndexOf("/"); + String snapshotName = snapshotPath.substring(index + 1); + snapshotPath = snapshotPath.substring(0, index); String absoluteSnapshotPath = parent + snapshotPath; - // check if directory exists + // check if snapshot directory exists File snapshotDir = new File(absoluteSnapshotPath); String details = null; if (!snapshotDir.exists()) {