mirror of https://github.com/apache/cloudstack.git
bug 10803: using updatehost api to change secondary storage url, the url need to be nfs://host/path format
status 10803: resolved fixed
This commit is contained in:
parent
121850bcb5
commit
3f7ce01f28
|
|
@ -52,6 +52,9 @@ public class UpdateHostCmd extends BaseCmd {
|
|||
|
||||
@Parameter(name=ApiConstants.HOST_TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="list of tags to be added to the host")
|
||||
private List<String> hostTags;
|
||||
|
||||
@Parameter(name=ApiConstants.URL, type=CommandType.STRING, description="the new uri for the secondary storage: nfs://host/path")
|
||||
private String url;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -72,6 +75,10 @@ public class UpdateHostCmd extends BaseCmd {
|
|||
public List<String> getHostTags() {
|
||||
return hostTags;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import com.cloud.exception.PermissionDeniedException;
|
|||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceInUseException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.host.Host;
|
||||
|
||||
public interface StorageService {
|
||||
/**
|
||||
|
|
@ -107,4 +108,5 @@ public interface StorageService {
|
|||
public StoragePool getStoragePool(long id);
|
||||
|
||||
Volume migrateVolume(Long volumeId, Long storagePoolId) throws ConcurrentOperationException;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -957,6 +957,11 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
}
|
||||
_hostTagsDao.persist(hostId, hostTags);
|
||||
}
|
||||
|
||||
String url = cmd.getUrl();
|
||||
if (url != null) {
|
||||
_storageMgr.updateSecondaryStorage(cmd.getId(), cmd.getUrl());
|
||||
}
|
||||
|
||||
HostVO updatedHost = _hostDao.findById(hostId);
|
||||
return updatedHost;
|
||||
|
|
|
|||
|
|
@ -220,4 +220,6 @@ public interface StorageManager extends Manager {
|
|||
|
||||
VolumeVO allocateDuplicateVolume(VolumeVO oldVol, Long templateId);
|
||||
|
||||
Host updateSecondaryStorage(long secStorageId, String newUrl);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@ import com.cloud.user.dao.UserDao;
|
|||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.UriUtils;
|
||||
import com.cloud.utils.component.Adapters;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.Inject;
|
||||
|
|
@ -3184,4 +3185,47 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Host updateSecondaryStorage(long secStorageId, String newUrl) {
|
||||
HostVO secHost = _hostDao.findById(secStorageId);
|
||||
if (secHost == null) {
|
||||
throw new InvalidParameterValueException("Can not find out the secondary storage id: " + secStorageId);
|
||||
}
|
||||
|
||||
if (secHost.getType() != Host.Type.SecondaryStorage) {
|
||||
throw new InvalidParameterValueException("host: " + secStorageId + " is not a secondary storage");
|
||||
}
|
||||
|
||||
URI uri = null;
|
||||
try {
|
||||
uri = new URI(UriUtils.encodeURIComponent(newUrl));
|
||||
if (uri.getScheme() == null) {
|
||||
throw new InvalidParameterValueException("uri.scheme is null " + newUrl + ", add nfs:// as a prefix");
|
||||
} else if (uri.getScheme().equalsIgnoreCase("nfs")) {
|
||||
if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) {
|
||||
throw new InvalidParameterValueException("Your host and/or path is wrong. Make sure it's of the format nfs://hostname/path");
|
||||
}
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
throw new InvalidParameterValueException(newUrl + " is not a valid uri");
|
||||
}
|
||||
|
||||
String oldUrl = secHost.getStorageUrl();
|
||||
|
||||
URI oldUri = null;
|
||||
try {
|
||||
oldUri = new URI(UriUtils.encodeURIComponent(oldUrl));
|
||||
if (!oldUri.getScheme().equalsIgnoreCase(uri.getScheme())) {
|
||||
throw new InvalidParameterValueException("can not change old scheme:" + oldUri.getScheme() + " to " + uri.getScheme());
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
s_logger.debug("Failed to get uri from " + oldUrl);
|
||||
}
|
||||
|
||||
secHost.setStorageUrl(newUrl);
|
||||
secHost.setGuid(newUrl);
|
||||
secHost.setName(newUrl);
|
||||
_hostDao.update(secHost.getId(), secHost);
|
||||
return secHost;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue