CLOUDSTACK-6785: changed async job param injectedjobid to customjobid and check for unique/uuid

This commit is contained in:
Marcus Sorensen 2014-05-27 15:21:14 -06:00
parent 2a5bf65c78
commit 96055058b0
5 changed files with 28 additions and 3 deletions

View File

@ -64,6 +64,7 @@ public class ApiConstants {
public static final String CUSTOMIZED = "customized";
public static final String CUSTOMIZED_IOPS = "customizediops";
public static final String CUSTOM_ID = "customid";
public static final String CUSTOM_JOB_ID = "customjobid";
public static final String MIN_IOPS = "miniops";
public static final String MAX_IOPS = "maxiops";
public static final String HYPERVISOR_SNAPSHOT_RESERVE = "hypervisorsnapshotreserve";

View File

@ -36,7 +36,7 @@ public abstract class BaseAsyncCmd extends BaseCmd {
@Parameter(name = "starteventid", type = CommandType.LONG)
private Long startEventId;
@Parameter(name= "injectedjobid", type = CommandType.STRING)
@Parameter(name = ApiConstants.CUSTOM_JOB_ID , type = CommandType.STRING)
private String injectedJobId;
public String getInjectedJobId() {

View File

@ -168,6 +168,7 @@ import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.db.UUIDManager;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.exception.ExceptionProxyObject;
@ -195,7 +196,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
private DomainManager _domainMgr;
@Inject
private DomainDao _domainDao;
@Inject
private UUIDManager _uuidMgr;
@Inject
private AsyncJobManager _asyncMgr;
@Inject
@ -659,10 +661,15 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
params.put("ctxDetails", ApiGsonHelper.getBuilder().create().toJson(ctx.getContextParameters()));
Long instanceId = (objectId == null) ? asyncCmd.getInstanceId() : objectId;
// users can provide the job id they want to use, so log as it is a uuid and is unique
String injectedJobId = asyncCmd.getInjectedJobId();
_uuidMgr.checkUuidSimple(injectedJobId, AsyncJob.class);
AsyncJobVO job = new AsyncJobVO("", callerUserId, caller.getId(), cmdObj.getClass().getName(),
ApiGsonHelper.getBuilder().create().toJson(params), instanceId,
asyncCmd.getInstanceType() != null ? asyncCmd.getInstanceType().toString() : null,
asyncCmd.getInjectedJobId());
injectedJobId);
job.setDispatcher(_asyncDispatcher.getName());
final long jobId = _asyncMgr.submitAsyncJob(job);

View File

@ -54,6 +54,15 @@ public class UUIDManagerImpl implements UUIDManager {
throw new PermissionDeniedException("Please check your permissions, you are not allowed to create/update custom id");
}
checkUuidSimple(uuid, entityType);
}
@Override
public <T> void checkUuidSimple(String uuid, Class<T> entityType) {
if (uuid == null)
return;
// check format
if (!IsUuidFormat(uuid))
throw new InvalidParameterValueException("UUID: " + uuid + " doesn't follow the UUID format");

View File

@ -37,4 +37,12 @@ public interface UUIDManager {
* .
*/
<T> void checkUuid(String uuid, Class<T> entityType);
/**
* Checks the uuid for correct format, uniqueness, without checking permissions
* @param uuid uuid to check
* @param entityType the type of entity
* .
*/
<T> void checkUuidSimple(String uuid, Class<T> entityType);
}