mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Incremental checkin
This commit is contained in:
parent
9da6d89837
commit
fcdeb5a97d
@ -48,7 +48,7 @@ public abstract class BaseCmd {
|
||||
}
|
||||
|
||||
public enum Manager {
|
||||
AccountManager, AgentManager, ConfigManager, ManagementServer, NetworkGroupManager, NetworkManager, StorageManager, UserVmManager
|
||||
AccountManager, AgentManager, ConfigManager, ManagementServer, NetworkGroupManager, NetworkManager, StorageManager, UserVmManager, SnapshotManager
|
||||
}
|
||||
|
||||
// FIXME: Extract these out into a separate file
|
||||
|
||||
@ -24,17 +24,20 @@ import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public class DeleteSnapshotCmd extends BaseCmd {
|
||||
|
||||
@Implementation(method="deleteSnapshot", manager=Manager.SnapshotManager)
|
||||
public class DeleteSnapshotCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(DeleteSnapshotCmd.class.getName());
|
||||
private static final String s_name = "deletesnapshotresponse";
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
|
||||
@ -128,5 +131,11 @@ public class DeleteSnapshotCmd extends BaseCmd {
|
||||
} catch (Exception ex) {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error deleting snapshot " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResponse() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ package com.cloud.storage.snapshot;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.commands.CreateSnapshotPolicyCmd;
|
||||
import com.cloud.api.commands.DeleteSnapshotCmd;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
@ -93,7 +94,7 @@ public interface SnapshotManager extends Manager {
|
||||
* If no other policies are assigned it calls destroy snapshot.
|
||||
* This will be used for manual snapshots too.
|
||||
*/
|
||||
boolean deleteSnapshot(long userId, long snapshotId, long policyId);
|
||||
boolean deleteSnapshot(DeleteSnapshotCmd cmd);
|
||||
|
||||
/**
|
||||
* Creates a policy with specified schedule. maxSnaps specifies the number of most recent snapshots that are to be retained.
|
||||
|
||||
@ -40,9 +40,11 @@ import com.cloud.agent.api.ValidateSnapshotAnswer;
|
||||
import com.cloud.agent.api.ValidateSnapshotCommand;
|
||||
import com.cloud.agent.manager.AgentManager;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.commands.CreateSnapshotCmd;
|
||||
import com.cloud.api.commands.CreateSnapshotPolicyCmd;
|
||||
import com.cloud.api.commands.CreateVolumeCmd;
|
||||
import com.cloud.api.commands.DeleteSnapshotCmd;
|
||||
import com.cloud.async.AsyncJobExecutor;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
@ -85,6 +87,7 @@ import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
import com.cloud.storage.dao.VMTemplatePoolDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.User;
|
||||
@ -771,9 +774,62 @@ public class SnapshotManagerImpl implements SnapshotManager {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected Long checkAccountPermissions(Map<String, Object> params,
|
||||
long targetAccountId,
|
||||
long targetDomainId,
|
||||
String targetDesc,
|
||||
long targetId)
|
||||
throws ServerApiException
|
||||
{
|
||||
Long accountId = null;
|
||||
|
||||
Account account = getAccount(params);
|
||||
if (account != null)
|
||||
{
|
||||
if (!isAdmin(account.getType()))
|
||||
{
|
||||
if (account.getId().longValue() != targetAccountId)
|
||||
{
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find a " + targetDesc + " with id " + targetId + " for this account");
|
||||
}
|
||||
}
|
||||
else if (!getManagementServer().isChildDomain(account.getDomainId(), targetDomainId))
|
||||
{
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to perform operation for " + targetDesc + " with id " + targetId + ", permission denied.");
|
||||
}
|
||||
accountId = account.getId();
|
||||
}
|
||||
|
||||
return accountId;
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public boolean deleteSnapshot(long userId, long snapshotId, long policyId) {
|
||||
public boolean deleteSnapshot(DeleteSnapshotCmd cmd) {
|
||||
|
||||
Account account = (Account)UserContext.current().getAccountObject();
|
||||
Long userId = UserContext.current().getUserId();
|
||||
Long snapshotId = cmd.getId();
|
||||
|
||||
//Verify parameters
|
||||
Snapshot snapshotCheck = _snapshotDao.findById(snapshotId.longValue());
|
||||
if (snapshotCheck == null) {
|
||||
throw new ServerApiException (BaseCmd.SNAPSHOT_INVALID_PARAM_ERROR, "unable to find a snapshot with id " + snapshotId);
|
||||
}
|
||||
|
||||
// If an account was passed in, make sure that it matches the account of the snapshot
|
||||
Account snapshotOwner = _accountDao.findById(snapshotCheck.getAccountId());
|
||||
if (snapshotOwner == null) {
|
||||
throw new ServerApiException(BaseCmd.SNAPSHOT_INVALID_PARAM_ERROR, "Snapshot id " + snapshotId + " does not have a valid account");
|
||||
}
|
||||
checkAccountPermissions(params, snapshotOwner.getId(), snapshotOwner.getDomainId(), "snapshot", snapshotId);
|
||||
|
||||
//If command is executed via 8096 port, set userId to the id of System account (1)
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(1);
|
||||
}
|
||||
|
||||
|
||||
s_logger.debug("Calling deleteSnapshot for snapshotId: " + snapshotId + " and policyId " + policyId);
|
||||
long prevSnapshotId = 0;
|
||||
SnapshotVO nextSnapshot = null;
|
||||
|
||||
@ -32,6 +32,8 @@ import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.storage.DownloadAnswer;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
||||
import com.cloud.agent.manager.AgentManager;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.configuration.ResourceCount.ResourceType;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
@ -114,7 +116,91 @@ public class TemplateManagerImpl implements TemplateManager {
|
||||
|
||||
@Override
|
||||
public Long create(long userId, Long zoneId, String name, String displayText, boolean isPublic, boolean featured, ImageFormat format, FileSystem fs, URI url, String chksum, boolean requiresHvm, int bits, boolean enablePassword, long guestOSId, boolean bootable) {
|
||||
Long id = _tmpltDao.getNextInSequence(Long.class, "id");
|
||||
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
String name = (String)params.get(BaseCmd.Properties.NAME.getName());
|
||||
String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
|
||||
Integer bits = (Integer)params.get(BaseCmd.Properties.BITS.getName());
|
||||
Boolean passwordEnabled = (Boolean)params.get(BaseCmd.Properties.PASSWORD_ENABLED.getName());
|
||||
Boolean requiresHVM = (Boolean)params.get(BaseCmd.Properties.REQUIRES_HVM.getName());
|
||||
String url = (String)params.get(BaseCmd.Properties.URL.getName());
|
||||
Boolean isPublic = (Boolean)params.get(BaseCmd.Properties.IS_PUBLIC.getName());
|
||||
Boolean featured = (Boolean)params.get(BaseCmd.Properties.IS_FEATURED.getName());
|
||||
String format = (String)params.get(BaseCmd.Properties.FORMAT.getName());
|
||||
Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
|
||||
Long zoneId = (Long) params.get(BaseCmd.Properties.ZONE_ID.getName());
|
||||
|
||||
//parameters verification
|
||||
if (bits == null) {
|
||||
bits = Integer.valueOf(64);
|
||||
}
|
||||
if (passwordEnabled == null) {
|
||||
passwordEnabled = false;
|
||||
}
|
||||
if (requiresHVM == null) {
|
||||
requiresHVM = true;
|
||||
}
|
||||
if (isPublic == null) {
|
||||
isPublic = Boolean.FALSE;
|
||||
}
|
||||
|
||||
if (zoneId.longValue() == -1) {
|
||||
zoneId = null;
|
||||
}
|
||||
|
||||
long accountId = 1L; // default to system account
|
||||
if (account != null) {
|
||||
accountId = account.getId().longValue();
|
||||
}
|
||||
|
||||
Account accountObj;
|
||||
if (account == null) {
|
||||
accountObj = getManagementServer().findAccountById(accountId);
|
||||
} else {
|
||||
accountObj = account;
|
||||
}
|
||||
|
||||
boolean isAdmin = (accountObj.getType() == Account.ACCOUNT_TYPE_ADMIN);
|
||||
|
||||
if (!isAdmin && zoneId == null) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid zone Id.");
|
||||
}
|
||||
|
||||
if(url.toLowerCase().contains("file://")){
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "File:// type urls are currently unsupported");
|
||||
}
|
||||
|
||||
if((!url.toLowerCase().endsWith("vhd"))&&(!url.toLowerCase().endsWith("vhd.zip"))
|
||||
&&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz")
|
||||
&&(!url.toLowerCase().endsWith("qcow2"))&&(!url.toLowerCase().endsWith("qcow2.zip"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2.bz2"))&&(!url.toLowerCase().endsWith("qcow2.gz")))){
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid "+format.toLowerCase());
|
||||
}
|
||||
|
||||
boolean allowPublicUserTemplates = Boolean.parseBoolean(getManagementServer().getConfigurationValue("allow.public.user.templates"));
|
||||
if (!isAdmin && !allowPublicUserTemplates && isPublic) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Only private templates can be created.");
|
||||
}
|
||||
|
||||
if (!isAdmin || featured == null) {
|
||||
featured = Boolean.FALSE;
|
||||
}
|
||||
|
||||
//If command is executed via 8096 port, set userId to the id of System account (1)
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Long id = _tmpltDao.getNextInSequence(Long.class, "id");
|
||||
|
||||
UserVO user = _userDao.findById(userId);
|
||||
long accountId = user.getAccountId();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user