CLOUDSTACK-9252: Remove static dependencies, refactor

This commit is contained in:
nvazquez 2016-02-01 12:56:04 -08:00
parent 76dc2705b7
commit cc50c20b4b
13 changed files with 195 additions and 70 deletions

View File

@ -29,7 +29,7 @@
<bean id="templateServiceImpl"
class="org.apache.cloudstack.storage.image.TemplateServiceImpl"
depends-on="dataObjectManagerImpl, dataStoreManagerImpl, dataMotionServiceImpl, objectInDataStoreManagerImpl, defaultEndPointSelector, templateDataFactoryImpl" />
depends-on="dataObjectManagerImpl, dataStoreManagerImpl, dataMotionServiceImpl, objectInDataStoreManagerImpl, defaultEndPointSelector, templateDataFactoryImpl, imageStoreDetailsUtilImpl" />
<bean id="templateDataFactoryImpl"
class="org.apache.cloudstack.storage.image.TemplateDataFactoryImpl" />
@ -38,6 +38,8 @@
class="org.apache.cloudstack.storage.image.datastore.ImageStoreHelper" />
<bean id="imageFormatHelper"
class="org.apache.cloudstack.storage.image.format.ImageFormatHelper" />
<bean id="imageStoreDetailsUtilImpl"
class="com.cloud.storage.ImageStoreDetailsUtilImpl" />
<bean id="imageStoreProviderMgr"
class="org.apache.cloudstack.storage.image.manager.ImageStoreProviderManagerImpl" />

View File

@ -136,6 +136,8 @@ public class TemplateServiceImpl implements TemplateService {
ConfigurationDao _configDao;
@Inject
StorageCacheManager _cacheMgr;
@Inject
ImageStoreDetailsUtil _imageStoreDetailsUtil;
class TemplateOpContext<T> extends AsyncRpcContext<T> {
final TemplateObject template;
@ -565,7 +567,7 @@ public class TemplateServiceImpl implements TemplateService {
}
private Map<String, TemplateProp> listTemplate(DataStore ssStore) {
ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO(), ImageStoreDetailsUtil.getNfsVersion(ssStore.getId()));
ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO(), _imageStoreDetailsUtil.getNfsVersion(ssStore.getId()));
EndPoint ep = _epSelector.select(ssStore);
Answer answer = null;
if (ep == null) {

View File

@ -46,7 +46,6 @@ import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
import org.apache.cloudstack.utils.identity.ManagementServerNode;
import com.cloud.agent.AgentManager;
@ -170,7 +169,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
@Inject
private ClusterManager _clusterMgr;
@Inject
private ImageStoreDetailsDao _imageDetailsStoreDao;
private ImageStoreDetailsUtil _imageStoreDetailsUtil;
private String _mountParent;
private StorageLayer _storage;
@ -554,7 +553,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
@Override
public void prepareSecondaryStorageStore(String storageUrl, Long storeId) {
String mountPoint = getMountPoint(storageUrl, ImageStoreDetailsUtil.getNfsVersion(storeId));
String mountPoint = getMountPoint(storageUrl, _imageStoreDetailsUtil.getNfsVersion(storeId));
GlobalLock lock = GlobalLock.getInternLock("prepare.systemvm");
try {

View File

@ -29,6 +29,8 @@ import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import com.vmware.vim25.FileInfo;
@ -93,6 +95,10 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.snapshot.VMSnapshot;
public class VmwareStorageManagerImpl implements VmwareStorageManager {
@Inject
ImageStoreDetailsUtil _imageStoreDetailsUtil;
@Override
public boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCommand cmd) {
DataTO data = cmd.getData();
@ -157,7 +163,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
String secStorageUrl = nfsStore.getUrl();
assert (secStorageUrl != null);
String installPath = template.getPath();
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, ImageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, _imageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
String installFullPath = secondaryMountPoint + "/" + installPath;
try {
if (installFullPath.endsWith(".ova")) {
@ -195,7 +201,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
String installPath = volume.getPath();
int index = installPath.lastIndexOf(File.separator);
String volumeUuid = installPath.substring(index + 1);
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, ImageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, _imageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
//The real volume path
String volumePath = installPath + File.separator + volumeUuid + ".ova";
String installFullPath = secondaryMountPoint + "/" + installPath;

View File

@ -33,6 +33,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@ -110,6 +112,10 @@ import com.cloud.vm.VirtualMachine.PowerState;
import com.cloud.vm.VmDetailConstants;
public class VmwareStorageProcessor implements StorageProcessor {
@Inject
ImageStoreDetailsUtil _imageStoreDetailsUtil;
private static final Logger s_logger = Logger.getLogger(VmwareStorageProcessor.class);
private static final int DEFAULT_NFS_PORT = 2049;
@ -317,7 +323,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
if (managed) {
VirtualMachineMO vmMo = copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, templateInfo.first(), templateInfo.second(),
managedStoragePoolRootVolumeName, false, ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
managedStoragePoolRootVolumeName, false, _imageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
vmMo.unregisterVm();
@ -334,7 +340,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
}
else {
copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, templateInfo.first(), templateInfo.second(),
templateUuidName, true, ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
templateUuidName, true, _imageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
}
} else {
s_logger.info("Template " + templateInfo.second() + " has already been setup, skip the template setup process in primary storage");
@ -579,8 +585,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
}
}
Pair<String, String> result = copyVolumeFromSecStorage(hyperHost, srcVolume.getPath(), new DatastoreMO(context, morDatastore), srcStore.getUrl(), (long)cmd.getWait() * 1000, ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
deleteVolumeDirOnSecondaryStorage(result.first(), srcStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(uuid));
Pair<String, String> result = copyVolumeFromSecStorage(hyperHost, srcVolume.getPath(), new DatastoreMO(context, morDatastore), srcStore.getUrl(), (long)cmd.getWait() * 1000, _imageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
deleteVolumeDirOnSecondaryStorage(result.first(), srcStore.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(uuid));
VolumeObjectTO newVolume = new VolumeObjectTO();
newVolume.setPath(result.second());
return new CopyCmdAnswer(newVolume);
@ -638,7 +644,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
vmMo.createSnapshot(exportName, "Temporary snapshot for copy-volume command", false, false);
exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, destVolumePath, exportName, hostService.getWorkerName(hyperHost.getContext(), cmd, 1),
ImageStoreDetailsUtil.getNfsVersionByUuid(cmd.getDestTO().getDataStore().getUuid()));
_imageStoreDetailsUtil.getNfsVersionByUuid(cmd.getDestTO().getDataStore().getUuid()));
return new Pair<String, String>(destVolumePath, exportName);
} finally {
@ -840,7 +846,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
Ternary<String, Long, Long> result =
createTemplateFromVolume(vmMo, template.getPath(), template.getId(), template.getName(), secondaryStoragePoolURL, volumePath,
hostService.getWorkerName(context, cmd, 0), ImageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
hostService.getWorkerName(context, cmd, 0), _imageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(result.first());
@ -1032,7 +1038,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
NfsTO nfsSvr = (NfsTO)imageStore;
Ternary<String, Long, Long> result = createTemplateFromSnapshot(template.getPath(), uniqeName, nfsSvr.getUrl(), snapshot.getPath(), template.getId(), (long)cmd.getWait() * 1000,
ImageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
_imageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(result.first());
@ -1175,7 +1181,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
throw new Exception("Failed to take snapshot " + srcSnapshot.getName() + " on vm: " + vmName);
}
String nfsVersion = ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid());
String nfsVersion = _imageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid());
backupResult =
backupSnapshotToSecondaryStorage(vmMo, destSnapshot.getPath(), srcSnapshot.getVolume().getPath(), snapshotUuid, secondaryStorageUrl,
prevSnapshotUuid, prevBackupUuid, hostService.getWorkerName(context, cmd, 1), nfsVersion);
@ -2252,7 +2258,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
backedUpSnapshotUuid = backedUpSnapshotUuid.replace(".ovf", "");
}
DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secondaryStorageUrl, backupPath, backedUpSnapshotUuid, (long)cmd.getWait() * 1000, ImageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secondaryStorageUrl, backupPath, backedUpSnapshotUuid, (long)cmd.getWait() * 1000, _imageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(newVolumeName);

View File

@ -20,6 +20,8 @@ package com.cloud.storage.resource;
import java.io.File;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
import org.apache.cloudstack.storage.command.CopyCommand;
@ -40,6 +42,10 @@ import com.cloud.storage.DataStoreRole;
import com.cloud.storage.ImageStoreDetailsUtil;
public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemCommandHandlerBase {
@Inject
ImageStoreDetailsUtil _imageStoreDetailsUtil;
private static final Logger s_logger = Logger.getLogger(VmwareStorageSubsystemCommandHandler.class);
private VmwareStorageManager storageManager;
private PremiumSecondaryStorageResource storageResource;
@ -78,7 +84,7 @@ public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemComman
}
}
String nfsVersion = ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid());
String nfsVersion = _imageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid());
if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole() == DataStoreRole.Image) {
//need to take extra processing for vmware, such as packing to ova, before sending to S3
if (srcData.getObjectType() == DataObjectType.VOLUME) {

View File

@ -28,6 +28,7 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.user.User;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
@ -48,12 +49,12 @@ import org.springframework.core.type.filter.TypeFilter;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
import org.apache.cloudstack.test.utils.SpringUtils;
@ -87,6 +88,7 @@ import com.cloud.org.Cluster.ClusterType;
import com.cloud.org.Managed.ManagedState;
import com.cloud.secstorage.CommandExecLogDao;
import com.cloud.server.ConfigurationServer;
import com.cloud.storage.ImageStoreDetailsUtil;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountService;
@ -131,6 +133,9 @@ public class VmwareDatacenterApiUnitTest {
@Inject
AccountManager _acctMgr;
@Inject
ImageStoreDetailsUtil _imageStoreDetailsUtil;
long zoneId;
long podId;
long clusterId;
@ -225,6 +230,8 @@ public class VmwareDatacenterApiUnitTest {
Mockito.when(addCmd.getPassword()).thenReturn(password);
Mockito.when(addCmd.getName()).thenReturn(vmwareDcName);
Mockito.when(removeCmd.getZoneId()).thenReturn(1L);
Mockito.when(_imageStoreDetailsUtil.getNfsVersion(Mockito.anyLong())).thenReturn(null);
Mockito.when(_imageStoreDetailsUtil.getNfsVersionByUuid(Mockito.anyString())).thenReturn(null);
}
@After
@ -433,7 +440,17 @@ public class VmwareDatacenterApiUnitTest {
}
@Bean
public ImageStoreDetailsDao imageStoreDetailsDao(){
public ImageStoreDetailsUtil imageStoreDetailsUtil() {
return Mockito.mock(ImageStoreDetailsUtil.class);
}
@Bean
public ImageStoreDao imageStoreDao() {
return Mockito.mock(ImageStoreDao.class);
}
@Bean
public ImageStoreDetailsDao imageStoreDetailsDao() {
return Mockito.mock(ImageStoreDetailsDao.class);
}

View File

@ -43,7 +43,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.utils.graphite.GraphiteClient;
@ -200,7 +199,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
@Inject
private HostGpuGroupsDao _hostGpuGroupsDao;
@Inject
private ImageStoreDetailsDao _imageStoreDetailsDao;
ImageStoreDetailsUtil _imageStoreDetailsUtil;
private ConcurrentHashMap<Long, HostStats> _hostStats = new ConcurrentHashMap<Long, HostStats>();
private final ConcurrentHashMap<Long, VmStats> _VmStats = new ConcurrentHashMap<Long, VmStats>();
@ -718,7 +717,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
continue;
}
GetStorageStatsCommand command = new GetStorageStatsCommand(store.getTO(), ImageStoreDetailsUtil.getNfsVersion(store.getId()));
GetStorageStatsCommand command = new GetStorageStatsCommand(store.getTO(), _imageStoreDetailsUtil.getNfsVersion(store.getId()));
EndPoint ssAhost = _epSelector.select(store);
if (ssAhost == null) {
s_logger.debug("There is no secondary storage VM for secondary storage host " + store.getName());

View File

@ -16,20 +16,10 @@
// under the License.
package com.cloud.storage;
import java.util.Map;
import com.cloud.utils.component.Manager;
import javax.inject.Inject;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
public class ImageStoreDetailsUtil {
@Inject
private static ImageStoreDao imageStoreDao;
@Inject
private static ImageStoreDetailsDao imageStoreDetailsDao;
public interface ImageStoreDetailsUtil extends Manager {
/**
* Obtain NFS protocol version (if provided) for a store id.<br/>
@ -38,22 +28,14 @@ public class ImageStoreDetailsUtil {
* @return {@code null} if {@code nfs.version} is not found for storeId <br/>
* {@code X} if {@code nfs.version} is found found for storeId
*/
public static String getNfsVersion(long storeId) {
String nfsVersion = null;
if (imageStoreDetailsDao.getDetails(storeId) != null){
Map<String, String> storeDetails = imageStoreDetailsDao.getDetails(storeId);
if (storeDetails != null && storeDetails.containsKey("nfs.version")){
nfsVersion = storeDetails.get("nfs.version");
}
}
return nfsVersion;
}
public String getNfsVersion(long storeId);
public static String getNfsVersionByUuid(String storeUuid){
ImageStoreVO imageStore = imageStoreDao.findByUuid(storeUuid);
if (imageStore != null){
return getNfsVersion(imageStore.getId());
}
return null;
}
/**
* Obtain NFS protocol version (if provided) for a store uuid.<br/>
* It can be set by adding an entry in {@code image_store_details} table, providing {@code name=nfs.version} and {@code value=X} (e.g. 3)
* @param storeId image store id
* @return {@code null} if {@code nfs.version} is not found for storeUuid <br/>
* {@code X} if {@code nfs.version} is found found for storeUuid
*/
public String getNfsVersionByUuid(String storeUuid);
}

View File

@ -0,0 +1,97 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage;
import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
import org.springframework.stereotype.Component;
@Component
public class ImageStoreDetailsUtilImpl implements ImageStoreDetailsUtil {
@Inject
private ImageStoreDao imageStoreDao;
@Inject
private ImageStoreDetailsDao imageStoreDetailsDao;
public String getNfsVersion(long storeId) {
String nfsVersion = null;
if (imageStoreDetailsDao.getDetails(storeId) != null){
Map<String, String> storeDetails = imageStoreDetailsDao.getDetails(storeId);
if (storeDetails != null && storeDetails.containsKey("nfs.version")){
nfsVersion = storeDetails.get("nfs.version");
}
}
return nfsVersion;
}
public String getNfsVersionByUuid(String storeUuid){
ImageStoreVO imageStore = imageStoreDao.findByUuid(storeUuid);
if (imageStore != null){
return getNfsVersion(imageStore.getId());
}
return null;
}
@Override
public String getName() {
return null;
}
@Override
public void setName(String name) {
}
@Override
public void setConfigParams(Map<String, Object> params) {
}
@Override
public Map<String, Object> getConfigParams() {
return null;
}
@Override
public int getRunLevel() {
return 0;
}
@Override
public void setRunLevel(int level) {
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
return false;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return false;
}
}

View File

@ -240,6 +240,8 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
TemplateDataStoreDao _tmplStoreDao;
@Inject
VolumeDataStoreDao _volumeStoreDao;
@Inject
ImageStoreDetailsUtil _imageStoreDetailsUtil;
private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL;
private int _secStorageVmMtuSize;
@ -311,7 +313,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs);
}
setupCmd.setNfsVersion(ImageStoreDetailsUtil.getNfsVersion(ssStore.getId()));
setupCmd.setNfsVersion(_imageStoreDetailsUtil.getNfsVersion(ssStore.getId()));
//template/volume file upload key
String postUploadKey = _configDao.getValue(Config.SSVMPSK.key());

View File

@ -146,7 +146,7 @@ import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.resource.ServerResourceBase;
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.ImageStoreDetailsUtil;
import com.cloud.storage.ImageStoreDetailsUtilImpl;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageLayer;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
@ -174,6 +174,9 @@ import org.joda.time.format.ISODateTimeFormat;
public class NfsSecondaryStorageResource extends ServerResourceBase implements SecondaryStorageResource {
@Inject
ImageStoreDetailsUtilImpl _imageStoreDetailsUtil;
private static final Logger s_logger = Logger.getLogger(NfsSecondaryStorageResource.class);
private static final String TEMPLATE_ROOT_DIR = "template/tmpl";
@ -368,7 +371,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
final String storagePath = destImageStore.getUrl();
final String destPath = destData.getPath();
try {
String downloadPath = determineStorageTemplatePath(storagePath, destPath, ImageStoreDetailsUtil.getNfsVersionByUuid(destImageStore.getUuid()));
String downloadPath = determineStorageTemplatePath(storagePath, destPath, _imageStoreDetailsUtil.getNfsVersionByUuid(destImageStore.getUuid()));
final File downloadDirectory = _storage.getFile(downloadPath);
if (downloadDirectory.exists()) {
@ -395,7 +398,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
try {
String downloadPath = determineStorageTemplatePath(storagePath, destPath, ImageStoreDetailsUtil.getNfsVersionByUuid(destImageStore.getUuid()));
String downloadPath = determineStorageTemplatePath(storagePath, destPath, _imageStoreDetailsUtil.getNfsVersionByUuid(destImageStore.getUuid()));
final File downloadDirectory = _storage.getFile(downloadPath);
if (downloadDirectory.exists()) {
@ -428,7 +431,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData,
NfsTO destDataStore) {
String srcMountPoint = getRootDir(srcDataStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
String srcMountPoint = getRootDir(srcDataStore.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
String snapshotPath = srcData.getPath();
int index = snapshotPath.lastIndexOf("/");
String snapshotName = snapshotPath.substring(index + 1);
@ -438,7 +441,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
snapshotPath = snapshotPath.substring(0, index);
snapshotPath = srcMountPoint + File.separator + snapshotPath;
String destMountPoint = getRootDir(destDataStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(destDataStore.getUuid()));
String destMountPoint = getRootDir(destDataStore.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(destDataStore.getUuid()));
String destPath = destMountPoint + File.separator + destData.getPath();
String errMsg = null;
@ -496,8 +499,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
if (srcData.getHypervisorType() == HypervisorType.XenServer) {
return copySnapshotToTemplateFromNfsToNfsXenserver(cmd, srcData, srcDataStore, destData, destDataStore);
} else if (srcData.getHypervisorType() == HypervisorType.KVM) {
File srcFile = getFile(srcData.getPath(), srcDataStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
File destFile = getFile(destData.getPath(), destDataStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(destDataStore.getUuid()));
File srcFile = getFile(srcData.getPath(), srcDataStore.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
File destFile = getFile(destData.getPath(), destDataStore.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(destDataStore.getUuid()));
VolumeObjectTO volumeObjectTO = srcData.getVolume();
ImageFormat srcFormat = null;
@ -614,7 +617,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
}
s_logger.debug("starting copy template to swift");
DataTO newTemplate = answer.getNewData();
File templateFile = getFile(newTemplate.getPath(), ((NfsTO)srcDataStore).getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
File templateFile = getFile(newTemplate.getPath(), ((NfsTO)srcDataStore).getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
SwiftTO swift = (SwiftTO)destDataStore;
String containterName = SwiftUtil.getContainerName(destData.getObjectType().toString(), destData.getId());
String swiftPath = SwiftUtil.putObject(swift, templateFile, containterName, templateFile.getName());
@ -736,7 +739,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
throw new CloudRuntimeException("Failed to get url: " + url);
}
String nfsMountPath = getRootDir(nfs.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(nfs.getUuid()));
String nfsMountPath = getRootDir(nfs.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(nfs.getUuid()));
String filePath = nfsMountPath + File.separator + path;
File directory = new File(filePath);
@ -901,7 +904,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
final S3TO s3 = (S3TO)destDataStore;
try {
final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath(), ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath(), _imageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath + " to upload to S3.");
@ -1114,7 +1117,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
if (dstore instanceof NfsTO) {
NfsTO nfs = (NfsTO)dstore;
String relativeSnapshotPath = cmd.getDirectory();
String parent = getRootDir(nfs.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
String parent = getRootDir(nfs.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
if (relativeSnapshotPath.startsWith(File.separator)) {
relativeSnapshotPath = relativeSnapshotPath.substring(1);
@ -1192,7 +1195,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
return new Answer(cmd, false, "can't handle non nfs data store");
}
NfsTO nfsStore = (NfsTO)store;
String parent = getRootDir(nfsStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(store.getUuid()));
String parent = getRootDir(nfsStore.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(store.getUuid()));
if (relativeTemplatePath.startsWith(File.separator)) {
relativeTemplatePath = relativeTemplatePath.substring(1);
@ -1413,7 +1416,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
DataStoreTO dstore = obj.getDataStore();
if (dstore instanceof NfsTO) {
NfsTO nfs = (NfsTO)dstore;
String parent = getRootDir(nfs.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
String parent = getRootDir(nfs.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
if (!parent.endsWith(File.separator)) {
parent += File.separator;
}
@ -1606,7 +1609,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
}
DataStoreTO store = cmd.getDataStore();
if (store instanceof NfsTO) {
String root = getRootDir(cmd.getSecUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(store.getUuid()));
String root = getRootDir(cmd.getSecUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(store.getUuid()));
Map<Long, TemplateProp> templateInfos = _dlMgr.gatherVolumeInfo(root);
return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
} else if (store instanceof S3TO) {
@ -1775,7 +1778,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
if (dstore instanceof NfsTO) {
NfsTO nfs = (NfsTO)dstore;
String relativeTemplatePath = obj.getPath();
String parent = getRootDir(nfs.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
String parent = getRootDir(nfs.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
if (relativeTemplatePath.startsWith(File.separator)) {
relativeTemplatePath = relativeTemplatePath.substring(1);
@ -1879,7 +1882,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
if (dstore instanceof NfsTO) {
NfsTO nfs = (NfsTO)dstore;
String relativeVolumePath = obj.getPath();
String parent = getRootDir(nfs.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
String parent = getRootDir(nfs.getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
if (relativeVolumePath.startsWith(File.separator)) {
relativeVolumePath = relativeVolumePath.substring(1);

View File

@ -38,6 +38,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.storage.command.DownloadCommand;
@ -53,7 +54,7 @@ import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.agent.api.to.S3TO;
import com.cloud.exception.InternalErrorException;
import com.cloud.storage.ImageStoreDetailsUtil;
import com.cloud.storage.ImageStoreDetailsUtilImpl;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageLayer;
import com.cloud.storage.VMTemplateHostVO;
@ -90,6 +91,9 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
StorageLayer _storage;
public Map<String, Processor> _processors;
@Inject
ImageStoreDetailsUtilImpl _imageStoreDetailsUtil;
public class Completion implements DownloadCompleteCallback {
private final String jobId;
@ -709,7 +713,7 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
String installPathPrefix = cmd.getInstallPath();
// for NFS, we need to get mounted path
if (dstore instanceof NfsTO) {
installPathPrefix = resource.getRootDir(((NfsTO)dstore).getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid())) + File.separator + installPathPrefix;
installPathPrefix = resource.getRootDir(((NfsTO)dstore).getUrl(), _imageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid())) + File.separator + installPathPrefix;
}
String user = null;
String password = null;