diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index 990d0415022..6131031d3c6 100755 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -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"; diff --git a/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java b/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java index 1b2415dfb4e..e1b4d70ed60 100644 --- a/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java @@ -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() { diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index 8c0b81fdb60..b7444d8ab49 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -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); diff --git a/server/src/com/cloud/uuididentity/UUIDManagerImpl.java b/server/src/com/cloud/uuididentity/UUIDManagerImpl.java index a1d14523749..995dbcdcc7c 100644 --- a/server/src/com/cloud/uuididentity/UUIDManagerImpl.java +++ b/server/src/com/cloud/uuididentity/UUIDManagerImpl.java @@ -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 void checkUuidSimple(String uuid, Class entityType) { + + if (uuid == null) + return; + // check format if (!IsUuidFormat(uuid)) throw new InvalidParameterValueException("UUID: " + uuid + " doesn't follow the UUID format"); diff --git a/utils/src/com/cloud/utils/db/UUIDManager.java b/utils/src/com/cloud/utils/db/UUIDManager.java index ae759bc004d..cac18769213 100644 --- a/utils/src/com/cloud/utils/db/UUIDManager.java +++ b/utils/src/com/cloud/utils/db/UUIDManager.java @@ -37,4 +37,12 @@ public interface UUIDManager { * . */ void checkUuid(String uuid, Class entityType); + + /** + * Checks the uuid for correct format, uniqueness, without checking permissions + * @param uuid uuid to check + * @param entityType the type of entity + * . + */ + void checkUuidSimple(String uuid, Class entityType); }